Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
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/manua ... ot-kernels.
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/manua ... ot-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.
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.
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.
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.
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.
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?
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.
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.)
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.)