OSDev.org

The Place to Start for Operating System Developers
It is currently Fri May 27, 2022 9:26 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Fri Jan 21, 2022 6:47 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
The Multiboot specifications include example code. Which part do you not understand?


The part I am mainly confused on (at least right now) is what the argument addr would be and how I would find out addr in the function cmain() in the Kernel example code found here: https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#Other-Multiboot-kernels.

I am sorry for all the confusion.


Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Fri Jan 21, 2022 6:51 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Caffeine wrote:
Octocontrabass wrote:
The Multiboot specifications include example code. Which part do you not understand?


The part I am mainly confused on (at least right now) is what the argument addr would be and how I would find out addr in the function cmain() in the Kernel example code found here: https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#Other-Multiboot-kernels.

I am sorry for all the confusion.


EDIT:
After doing some more reading, what I need to know is how to get the address of the multiboot header.


Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Fri Jan 21, 2022 7:21 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3839
When GRUB jumps to your kernel's entry point, the address is in the EBX register. You need to write assembly code that will take the address in EBX and put it somewhere so you can use it.

In the i386 psABI, parameters are passed to functions by pushing them on the stack. The example boot.S code pushes EBX onto the stack to pass the address as a parameter to the cmain function.


Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Fri Jan 21, 2022 8:07 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
When GRUB jumps to your kernel's entry point, the address is in the EBX register. You need to write assembly code that will take the address in EBX and put it somewhere so you can use it.

In the i386 psABI, parameters are passed to functions by pushing them on the stack. The example boot.S code pushes EBX onto the stack to pass the address as a parameter to the cmain function.


How do you push EBX onto the stack so the c function can see it? Sorry, I am a little lost. Here is my bootloader, I got it from a beginner tutorial to set up GRUB (But I forgot where it was). https://pastebin.com/ZcrGQ3q2

All I can find online is passing c functions to assembly, not the other way around.


Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Fri Jan 21, 2022 9:51 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3839
Caffeine wrote:
All I can find online is passing c functions to assembly, not the other way around.

The sample code in the Multiboot specification demonstrates how to call a C function from assembly.

There are also plenty of other examples out there. Perhaps you need to change the keywords you use when you search.

And it's a good idea to check the i386 psABI for the details.


Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Mon Jan 24, 2022 8:34 am 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
Caffeine wrote:
All I can find online is passing c functions to assembly, not the other way around.

The sample code in the Multiboot specification demonstrates how to call a C function from assembly.

There are also plenty of other examples out there. Perhaps you need to change the keywords you use when you search.

And it's a good idea to check the i386 psABI for the details.


I'll try this right now, thanks for your help!


Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Mon Jan 24, 2022 12:42 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
Caffeine wrote:
All I can find online is passing c functions to assembly, not the other way around.

The sample code in the Multiboot specification demonstrates how to call a C function from assembly.

There are also plenty of other examples out there. Perhaps you need to change the keywords you use when you search.

And it's a good idea to check the i386 psABI for the details.


Here is my bootloader, I am having issues getting the register. The screen is still empty: https://pastebin.com/ZcrGQ3q2

The change was made at line 94 where I added
Code:
push eax
.


Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Mon Jan 24, 2022 12:47 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3839
The pointer to the Multiboot information structure is in EBX, not EAX.


Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Mon Jan 24, 2022 3:21 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
The pointer to the Multiboot information structure is in EBX, not EAX.


I changed it to ebx but it still is not working. I am passing the address to the VGA driver and trying to plot a pixel at (100, 100) using this code:
Code:
void initializeVGA(unsigned long addr) {
    unsigned char* location = (unsigned char*)addr + (320 * 100 + 100);
    *location = 4;

}

But it still does not work.
Sorry for the beginner questions.


Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Mon Jan 24, 2022 3:42 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3839
The address is the address of the Multiboot information structure, not the address of the framebuffer. You need to parse the multiboot information structure to find the framebuffer address.

For example:
Code:
void example( uintptr_t addr )
{
    multiboot_info_t * mbi = (multiboot_info_t *)addr;
    uint8_t * framebuffer = (uint8_t *)mbi->framebuffer_addr;
    switch( mbi->framebuffer_bpp )
    {
        case 8:
            framebuffer[mbi->framebuffer_pitch * 100 + 1 * 100] = 4;
            break;
        case 15:
        case 16:
            framebuffer[mbi->framebuffer_pitch * 100 + 2 * 100] = 0xff;
            break;
        case 24:
            framebuffer[mbi->framebuffer_pitch * 100 + 3 * 100] = 0xff;
            break;
        case 32:
            framebuffer[mbi->framebuffer_pitch * 100 + 4 * 100] = 0xff;
            break;
        default:
            // error
            break;
    }
}


Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Mon Jan 24, 2022 5:03 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
The address is the address of the Multiboot information structure, not the address of the framebuffer. You need to parse the multiboot information structure to find the framebuffer address.

For example:
Code:
void example( uintptr_t addr )
{
    multiboot_info_t * mbi = (multiboot_info_t *)addr;
    uint8_t * framebuffer = (uint8_t *)mbi->framebuffer_addr;
    switch( mbi->framebuffer_bpp )
    {
        case 8:
            framebuffer[mbi->framebuffer_pitch * 100 + 1 * 100] = 4;
            break;
        case 15:
        case 16:
            framebuffer[mbi->framebuffer_pitch * 100 + 2 * 100] = 0xff;
            break;
        case 24:
            framebuffer[mbi->framebuffer_pitch * 100 + 3 * 100] = 0xff;
            break;
        case 32:
            framebuffer[mbi->framebuffer_pitch * 100 + 4 * 100] = 0xff;
            break;
        default:
            // error
            break;
    }
}


It works!! Thank you so much for your help!! One more question though, how do I change the color of the pixel? Do I change the hex values in the last few cases in the switch statement or is it something else?

Here is my code - this works:

Code:
unsigned int *framebuffer;
multiboot_info_t *mbi;

void initializeVGA(unsigned long addr) {
    mbi = (multiboot_info_t *)addr;  // Get the multiboot information from the address
    framebuffer = (unsigned int *)mbi->framebuffer_addr;  // Get the framebuffer address

}

void plotPixle(int x, int y, unsigned char color) {
    switch (mbi->framebuffer_bpp) {
    case 8:
        framebuffer[mbi->framebuffer_pitch * y + 1 * x] = 4;
        break;
    case 15:
        break;
    case 16:
        framebuffer[mbi->framebuffer_pitch * y + 2 * x] = 0xff;
        break;
    case 24:
        framebuffer[mbi->framebuffer_pitch * y + 3 * x] = 0xff;
        break;
    case 32:
        framebuffer[mbi->framebuffer_pitch * y + 4 * x] = 0xff;
        break;
    default:
        // error
        break;
    }

}


Last edited by Caffeine on Mon Jan 24, 2022 5:15 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Mon Jan 24, 2022 5:14 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3839
Yes, those hex values determine the color. However, this example code only sets one byte, and pixels are usually more than one byte. (Most common seems to be 32bpp, which is four bytes per pixel.)


Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Mon Jan 24, 2022 5:17 pm 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
Yes, those hex values determine the color. However, this example code only sets one byte, and pixels are usually more than one byte. (Most common seems to be 32bpp, which is four bytes per pixel.)


How should I set more than one byte?


Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Mon Jan 24, 2022 5:52 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 3839
Have you tried adding 1 to the array index to set the second byte?


Top
 Profile  
 
 Post subject: Re: I can't get my VGA driver to work
PostPosted: Tue Jan 25, 2022 11:45 am 
Offline
Member
Member

Joined: Mon Nov 15, 2021 9:48 pm
Posts: 79
Octocontrabass wrote:
Have you tried adding 1 to the array index to set the second byte?


Sorry, but I am a little confused as to how to do this. Again, sorry for the beginner questions.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot], Google [Bot], PetalBot [Bot] and 6 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group