OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 12:33 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 57 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: Writing to the screen without BIOS
PostPosted: Thu May 27, 2021 10:44 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 21, 2020 9:51 am
Posts: 100
Location: Aboard the Enterprise
Babystep4 and 8 show how to write to the screen without BIOS interrupts in 16- and 32-bit real and protected modes, respectively. I am trying to write a 64-bit OS, and I want to avoid using BIOS interrupts as much as I can. Is there a way to write to the screen without BIOS in a 64-bit OS? Is there such thing as 64-bit protected mode?

Thanks

_________________
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Thu May 27, 2021 11:01 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
PavelCheckov wrote:
Is there a way to write to the screen without BIOS in a 64-bit OS?

Writing to the VGA text mode screen works the same regardless of CPU mode. I suggest you read more about VGA text mode if you don't understand the babystep code.

UEFI doesn't have VGA text mode, so if you want to support UEFI in the future you'll have to write new code to support a linear frame buffer. (You can also have a linear frame buffer with BIOS.)

PavelCheckov wrote:
Is there such thing as 64-bit protected mode?

It's called "long mode".


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Thu May 27, 2021 11:31 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 21, 2020 9:51 am
Posts: 100
Location: Aboard the Enterprise
Octocontrabass wrote:
Writing to the VGA text mode screen works the same regardless of CPU mode. I suggest you read more about VGA text mode if you don't understand the babystep code.

The only reason I ask is because it says that the code is for 32-bit protected mode. I was also hoping to use FHD as the default, which doesn't have text mode, or to my knoweledge, any tutorial.

Octocontrabass wrote:
UEFI doesn't have VGA text mode, so if you want to support UEFI in the future you'll have to write new code to support a linear frame buffer. (You can also have a linear frame buffer with BIOS.)

I was hoping to write my OS independent of a specific BIOS (e.g. UEFI).


Octocontrabass wrote:
It's called "long mode".

How do I enter long mode?

_________________
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Thu May 27, 2021 11:54 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
PavelCheckov wrote:
I was also hoping to use FHD as the default, which doesn't have text mode, or to my knoweledge, any tutorial.

So, you want a linear frame buffer. There's quite a bit of information on how to use one of those. Please ignore the page title - it was probably written before long mode existed.

PavelCheckov wrote:
I was hoping to write my OS independent of a specific BIOS (e.g. UEFI).

You want a linear frame buffer.

PavelCheckov wrote:
How do I enter long mode?

Let the bootloader do it for you.

...But, you can find an overview on the wiki in case your bootloader doesn't already do it. If you search, you'll probably find example code too.


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Sun Aug 15, 2021 10:34 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 21, 2020 9:51 am
Posts: 100
Location: Aboard the Enterprise
All the examples are for VGA, and I am still unclear how to write text to an XGA screen (via linear frame buffer).

_________________
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Sun Aug 15, 2021 1:08 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Which examples are you looking at? I provided a link to the wiki page that explains how to draw text to a linear frame buffer. It works the same for all linear frame buffers.


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Sun Aug 15, 2021 2:14 pm 
Offline
Member
Member
User avatar

Joined: Mon Sep 21, 2020 9:51 am
Posts: 100
Location: Aboard the Enterprise
I am looking at the link provided, but it appears to be for VGA and BIOS, however I am programming with XGA and UEFI.

_________________
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Sun Aug 15, 2021 2:25 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
The frame buffer provided by GOP works exactly the same as the frame buffer provided by VBE.


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Sun Aug 15, 2021 2:48 pm 
Offline
Member
Member
User avatar

Joined: Mon Sep 21, 2020 9:51 am
Posts: 100
Location: Aboard the Enterprise
How would I write a printf function with this?

_________________
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Sun Aug 15, 2021 3:07 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
You write a function to draw a single character to the screen. From then on, writing printf is exactly the same as if you were using BIOS calls to write characters to the screen.


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Mon Aug 16, 2021 11:37 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
PavelCheckov wrote:
How would I write a printf function with this?
To display a character, take a look at the example on PC Screen Font wiki page. You just repeat that code for every character and adjust the cursor position. A very very minimalistic string display example would be:
Code:
// PSF2 header
typedef struct {
    uint32_t magic;
    uint32_t version;
    uint32_t headersize;
    uint32_t flags;
    uint32_t numglyph;
    uint32_t bytesperglyph;
    uint32_t height;
    uint32_t width;
    uint8_t glyphs;
} __attribute__((packed)) psf2_t;
extern volatile unsigned char _binary_font_psf_start;

void puts(char *s)
{
    psf2_t *font = (psf2_t*)&_binary_font_psf_start;
    int x,y,kx=0,line,mask,offs;
    int bpl=(font->width+7)/8;
    while(*s) {
        unsigned char *glyph = (unsigned char*)&_binary_font_psf_start + font->headersize +
            (*s>0&&*s<font->numglyph?*s:0)*font->bytesperglyph;
        offs = (kx * (font->width+1) * 4);
        for(y=0;y<font->height;y++) {
            line=offs; mask=1<<(font->width-1);
            for(x=0;x<font->width;x++) {
                *((uint32_t*)(framebuffer_address+line))=((int)*glyph) & (mask)?0xFFFFFF:0;
                mask>>=1; line+=4;
            }
            *((uint32_t*)((uint64_t)&fb+line))=0; glyph+=bpl; offs+=framebuffer_scanline;
        }
        s++; kx++;
    }
}
As for the arguments, you should implement sprintf, construct the output buffer and pass that to this "puts" function.

You probably want more than this simple example, like handling newline characters, interpret UTF-8, proportional fonts etc. For these, you can find a ready-to-use, dependency free library, Scalable Screen Font. It has a minimalistic routine, comparable to the PC Screen Font example above, see ssfn_putc.

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Mon Aug 16, 2021 12:34 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
PavelCheckov wrote:
How would I write a printf function with this?

Basically, you write a routine that renders a font to screen (PC Screen Font is fine, just don't copy n' paste blindly, understand the code first before copying). After that, read up on the ISO C standard or POSIX specification about printf and how it works, and then write it.

Or, in the words of Bill Joy:
Quote:
It's very simple — you read the protocol and write the code

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Mon Aug 16, 2021 6:01 pm 
Offline
Member
Member
User avatar

Joined: Mon Sep 21, 2020 9:51 am
Posts: 100
Location: Aboard the Enterprise
Will this code work, modified for XGA, with GOP, even though it was written for VESA? (From the article on drawing in the linear frame buffer)

Code:
/* example for 320x200 VGA */
void putpixel(int pos_x, int pos_y, unsigned char VGA_COLOR)
{
    unsigned char* location = (unsigned char*)0xA0000 + 320 * pos_y + pos_x;
    *location = VGA_COLOR;
}


(https://wiki.osdev.org/Drawing_In_Protected_Mode)

_________________
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Mon Aug 16, 2021 6:21 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
That code was written for VGA, not VBE. Code written for VGA will not work with GOP. (GOP does not support indexed color modes.)
Actually, I read your post wrong. If you modify it, then yes, you can make it work. The article already has an example of one way you could modify it:

Code:
static void putpixel(unsigned char* screen, int x,int y, int color) {
    unsigned where = x*pixelwidth + y*pitch;
    screen[where] = color & 255;              // BLUE
    screen[where + 1] = (color >> 8) & 255;   // GREEN
    screen[where + 2] = (color >> 16) & 255;  // RED
}


Top
 Profile  
 
 Post subject: Re: Writing to the screen without BIOS
PostPosted: Tue Aug 17, 2021 7:18 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 21, 2020 9:51 am
Posts: 100
Location: Aboard the Enterprise
So, that code would work in GOP even thought it was meant for VESA? And truecolor?

_________________
USS Enterprise NCC-1701,
The Final Frontier,
Space,
The Universe

Live Long And Prosper

Slava Ukraini!
Слава Україні!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 57 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 104 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group