I am trying to write my own OS, I currently am trying to pass the video framebuffer address to my kernel so that I can start plotting pixels and etc. However, when I try and pass my arguments to my kernel entry the argument doesn't get passed.
I defined framebuffer like this:
framebuffer: dd 0
There might be a problem with the way I get the framebuffer or the way I store it so here is the way I got it:
First I get the first word of the address that is located in the 0x28th byte of the mode information structure and write it to [framebuffer]. Then I get the second word located in 0x2A. I know for a fact that the first word is 0x0000 and the second is 0xFD00 which makes sense because I am using qemu and qemu's framebuffer is located at 0xFD000000. So I write the first word to the second-word place of the framebuffer and the second word the first place in order to get 0xFD000000 in the framebuffer variable
mov bx, vbe_mode_structure+0x28 ; vbe_mode_structure+0x28 is the framebuffer address
;push word [bx] ;
;call print_hex_word ;
;add sp, 2 ;
mov ax, [bx] ;
mov word [framebuffer+1], ax ;
mov bx, vbe_mode_structure+0x2A ; vbe_mode_structure+0x2A is the framebuffer address
;push word [bx] ;
;call print_hex_word ;
;add sp, 2 ;
mov ax, [bx] ;
mov word [framebuffer], ax ;
Then I pass it as an argument to my kernel which I loaded to 0x1000
mov eax, framebuffer
push eax
call 0x1000
add esp, 4
Finally in my kernel I do the following and try to plot a pixel
push ebp
mov ebp, esp
mov eax, [ ebp + 8 ]
mov edi, [eax]
add edi, 0
mov al, 0xFF
stosb
pop ebp ; minimal cleanup
ret
jmp $
The pixel however does not appear. If I write 0xFD000000
instead of [eax]
I do get a blue pixel to appear in the top left corner of the screen.
The questions are:
What is wrong with the code?
Am I passing the parameters correctly
Should I be passing framebuffer as a parameter to the kernel in the first place? Is there a get-around?
Finally here are the entire project files in github: https://github.com/Danyy427/OSDEV4.git
Edit: I changed the argument passing code to the following
;mov eax, [framebuffer]
push dword [vbe_mode_structure+0x28]
call 0x1000
add esp, 4
and changed the reciever like this:
mov edi, [ebp+8] ;
mov al, 0xFF
stosb
I still don't get any pixel being plotted on top left corner.
Edit 2:
I mixed the low and high of the address the final code is:
mov bx, vbe_mode_structure+0x28 ; vbe_mode_structure+0x28 is the framebuffer address
;push word [bx] ;
;call print_hex_word ;
;add sp, 2 ;
mov ax, [bx] ;
mov word [framebuffer], ax ;
mov bx, vbe_mode_structure+0x2A ; vbe_mode_structure+0x2A is the framebuffer address
;push word [bx] ;
;call print_hex_word ;
;add sp, 2 ;
mov ax, [bx] ;
mov word [framebuffer+2], ax
and for the receiving part
mov ebp, esp
mov eax, [ ebp +8 ]
mov edi, eax
mov al, 0xFF
stosb
pop ebp ; minimal cleanup
ret
jmp $