OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 9:41 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: VESA: requesting framebuffer with GRUB
PostPosted: Tue Feb 14, 2023 11:19 am 
Offline

Joined: Tue Jun 14, 2016 1:39 pm
Posts: 15
Hi everyone, I am a newbie with os dev programming. I was wondering a question about VESA mode. So let's say I have developed my own osdev experiment that has: gdt, and idt implemented, physical memory management, paging enabled, interrupts working and keyboard working. I'd like to move on, playing with a GRUB framebuffer address.

I read the wiki page about drawing in protected mode, and at the moment I """"""""implemented""""""""""" a really stupid way to get the VESA framebuffer address. In the file that manages the starting of the system (boot.S), I managed to request a framebuffer via multiboot structure (I do not know how, but GRUB understands if I ask mode 1024x768, 32bit depth).

I actually get a pointer (address: 0) and I can write on it and display some pixels. However as soon as I enable physical memory manager (or probably gdt), the framebuffer address is useless. I guess the space allocated for the screen by GRUB is totally overwritten by physical memory manager..

What would your procedure be to request a framebuffer from GRUB and then actually use it, considering I have enabled physical memory managment?

Code:
.set MAGIC, 0x1badb002
.set FLAGS, 7
.set CHECKSUM, -(MAGIC + FLAGS)
.set MODE_TYPE, 0
.set WIDTH, 1024  /* requested width */
.set HEIGHT, 768  /* requested height */
.set DEPTH, 32    /* requested bits per pixel BPP */

.set HEADER_ADDR, 0
.set LOAD_ADDR, 0
.set LOAD_END_ADDR, 0
.set BSS_END_ADDR, 0
.set ENTRY_ADDR, 0


and on the kernel:
Code:
int kernel_main(struct multiboot *m){
// m-->framebuffer_address;
}


Top
 Profile  
 
 Post subject: Re: VESA: requesting framebuffer with GRUB
PostPosted: Tue Feb 14, 2023 11:48 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
sernico wrote:
I actually get a pointer (address: 0) and I can write on it and display some pixels.

It's definitely not 0.

sernico wrote:
I guess the space allocated for the screen by GRUB is totally overwritten by physical memory manager..

It shouldn't be, since the framebuffer is not inside ordinary usable memory.

sernico wrote:
What would your procedure be to request a framebuffer from GRUB and then actually use it, considering I have enabled physical memory managment?

GRUB gives you the physical address of the framebuffer. You need to choose a virtual address, update the page tables for that virtual address to point to the framebuffer's physical address, and then use the virtual address to access the framebuffer.


Top
 Profile  
 
 Post subject: Re: VESA: requesting framebuffer with GRUB
PostPosted: Tue Feb 14, 2023 12:04 pm 
Offline

Joined: Tue Jun 14, 2016 1:39 pm
Posts: 15
I did not enable the virtual memory yet, at the moment my OS is 1:1 with physical memory. Thanks for the feedback though!


Top
 Profile  
 
 Post subject: Re: VESA: requesting framebuffer with GRUB
PostPosted: Tue Feb 14, 2023 12:21 pm 
Offline
Member
Member

Joined: Sat Feb 04, 2012 5:03 pm
Posts: 111
Would you be willing to post some info about your page tables?


Top
 Profile  
 
 Post subject: Re: VESA: requesting framebuffer with GRUB
PostPosted: Tue Feb 14, 2023 12:34 pm 
Offline

Joined: Tue Jun 14, 2016 1:39 pm
Posts: 15
I'm stupid, there was a sort of deadlock on heap memory (memset on -14 GB takes time... ;)). Sorry closing the thread.


Top
 Profile  
 
 Post subject: Re: VESA: requesting framebuffer with GRUB
PostPosted: Tue Feb 14, 2023 1:25 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
It’s really important that you should understand why no software should ever treat 0 as a valid value for a pointer. The fact that you think that multiboot gives you a 0 pointer to the frame buffer means that you are misinterpreting what it is telling you. That will certainly come back to bite you later.


Top
 Profile  
 
 Post subject: Re: VESA: requesting framebuffer with GRUB
PostPosted: Tue Feb 14, 2023 2:12 pm 
Offline

Joined: Tue Jun 14, 2016 1:39 pm
Posts: 15
Thanks iansjack. I investigated more and I also padded wrongly the structure of multiboot header. The value 0 was of a reserved field and thus my kernel had some problems. I totally agree on zero pointer, I just thought that framebuffer could be a sort of an exceptional case (but it's not!).

I'm going to implement more checks and asserts to ensure that my kernel can halt and report more clearly these problems.

By the way, OSDEV is amazing! I'm really thankful for this community.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 65 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