How to use VESA linear frame buffer

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.
SayedMohsen64
Posts: 16
Joined: Mon Jan 26, 2015 2:56 am

How to use VESA linear frame buffer

Post by SayedMohsen64 »

Hello.
I'm not a newbie. I've programmed OSes before, but I haven't done any programming in two years. Well, now I'm writing my OS from scratch. I have a custom boot loader that loads my 32-bit kernel. My OS will be graphical like Mac OS X, with no command-line at all. In my boot loader, I set the VESA mode and get the VESA mode info for the linear frame buffer. This is what my code looks like:

Code: Select all

setup_vesa:
	mov ax, 0x4F01
	mov cx, 8113h
	mov di, vesa_info
	int 0x10

	mov ax, 0x4F02
	mov bx, 8113h
	int 0x10

	jmp go_to_pmode

--- some more code for entering 32-bit mode ---

vesa_info:
	dw 0
	db 0
	db 0
	dw 0
	dw 0
	dw 0
	dw 0
	dd 0
	dw 0

	dw 0
	dw 0
	db 0
	db 0
	db 0
	db 0
	db 0
	db 0
	db 0
	db 0
	db 0

	db 0
	db 0
	db 0
	db 0
	db 0
	db 0
	db 0
	db 0
	db 0

	.linear_frame_buffer_start		dd 0
	dd 0
	dw 0
	times 206 db 0
Supposedly, vesa_info.linear_frame_buffer_start should contains the start of the frame buffer. In my kernel:

Code: Select all

mov edi, ebx             ; boot loader passes linear frame buffer start in EBX
mov ax, 0xFFFF
mov ecx, 0xEA600
rep stosw
This results in crashing Bochs and Qemu. Any help on how to use the VESA frame buffer? Thanks in advance!

- Sayed Mohsen
User avatar
Muazzam
Member
Member
Posts: 543
Joined: Mon Jun 16, 2014 5:59 am
Location: Shahpur, Layyah, Pakistan

Re: How to use VESA linear frame buffer

Post by Muazzam »

I have tested it in both qemu and bochs. I worked perfectly in both. I think there is bug in loading kernel or switching to protected mode.
SayedMohsen64
Posts: 16
Joined: Mon Jan 26, 2015 2:56 am

Re: How to use VESA linear frame buffer

Post by SayedMohsen64 »

muazzam wrote:I have tested it in both qemu and bochs. I worked perfectly in both. I think there is bug in loading kernel or switching to protected mode.
Have you tested this specific code? It crashes my Bochs and Qemu. :(
User avatar
Muazzam
Member
Member
Posts: 543
Joined: Mon Jun 16, 2014 5:59 am
Location: Shahpur, Layyah, Pakistan

Re: How to use VESA linear frame buffer

Post by Muazzam »

SayedMohsen64 wrote:
muazzam wrote:I have tested it in both qemu and bochs. I worked perfectly in both. I think there is bug in loading kernel or switching to protected mode.
Have you tested this specific code? It crashes my Bochs and Qemu. :(
Yes I have tested all code you provided.
SayedMohsen64
Posts: 16
Joined: Mon Jan 26, 2015 2:56 am

Re: How to use VESA linear frame buffer

Post by SayedMohsen64 »

muazzam wrote:Yes I have tested all code you provided.
This is what I get instead.. :(
And there is no bug in going to protected mode because if I take away the VESA code and have my kernel print a string in 32-bit mode, it prints and works fine. The bug is in my VESA code, it just doesn't like my specific PC.
Attachments
VESA not working.PNG
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: How to use VESA linear frame buffer

Post by BrightLight »

Your exact code works perfectly in Bochs, Qemu and VMware. I don't see why it doesn't work with you, all I did was copy the code into my other project, which is a 32-bit boot loader.
About your bootloader, it's VERY nice to see someone who has written a bootloader for my filesystem! :mrgreen: :D
You know your OS is advanced when you stop using the Intel programming guide as a reference.
SayedMohsen64
Posts: 16
Joined: Mon Jan 26, 2015 2:56 am

Re: How to use VESA linear frame buffer

Post by SayedMohsen64 »

omarrx024 wrote:About your bootloader, it's VERY nice to see someone who has written a bootloader for my filesystem! :mrgreen: :D
Yeah, your file system is very nice and comfortable! Really simple. You just need to finish up the missing parts of your specs and release it. :mrgreen:
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: How to use VESA linear frame buffer

Post by BrightLight »

SayedMohsen64 wrote:Yeah, your file system is very nice and comfortable! Really simple.
Isn't it surprising and weird that you finished a boot loader so quickly for a filesystem you're new to?
You know your OS is advanced when you stop using the Intel programming guide as a reference.
SayedMohsen64
Posts: 16
Joined: Mon Jan 26, 2015 2:56 am

Re: How to use VESA linear frame buffer

Post by SayedMohsen64 »

omarrx024 wrote:
SayedMohsen64 wrote:Yeah, your file system is very nice and comfortable! Really simple.
Isn't it surprising and weird that you finished a boot loader so quickly for a filesystem you're new to?
Heheheh, I used some of Vector OS code. I am allowed to, right? :P :twisted:
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: How to use VESA linear frame buffer

Post by BrightLight »

SayedMohsen64 wrote:Heheheh, I used some of Vector OS code. I am allowed to, right?
Of course, any one is allowed to. My GitHub repository clearly says that my project is GPL'd. :)
You know your OS is advanced when you stop using the Intel programming guide as a reference.
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: How to use VESA linear frame buffer

Post by alexfru »

SayedMohsen64 wrote:

Code: Select all

	setup_vesa:
	mov ax, 0x4F01
	mov cx, 8113h
	mov di, vesa_info
What's in ES here?
SayedMohsen64 wrote:

Code: Select all

	int 0x10

	mov ax, 0x4F02
	mov bx, 8113h
What's in ES:DI here?
SayedMohsen64 wrote:

Code: Select all

	int 0x10
Supposedly, vesa_info.linear_frame_buffer_start should contains the start of the frame buffer. In my kernel:

Code: Select all

	mov edi, ebx             ; boot loader passes linear frame buffer start in EBX
	mov ax, 0xFFFF
	mov ecx, 0xEA600
What's in EFLAGS.DF here?

0xEA600 = 800*600*2. Are you sure you don't want 800*600 = 0x75300?
SayedMohsen64 wrote:

Code: Select all

	rep stosw
Exactly how do you extract and pass the value of vesa_info.linear_frame_buffer_start?
SayedMohsen64
Posts: 16
Joined: Mon Jan 26, 2015 2:56 am

Re: How to use VESA linear frame buffer

Post by SayedMohsen64 »

alexfru wrote:
SayedMohsen64 wrote:

Code: Select all

	setup_vesa:
	mov ax, 0x4F01
	mov cx, 8113h
	mov di, vesa_info
What's in ES here?
ES is zero because I have the ORG statement at the beginning of my file.
alexfru wrote:
SayedMohsen64 wrote:

Code: Select all

	int 0x10

	mov ax, 0x4F02
	mov bx, 8113h
What's in ES:DI here?
Well, as the parameters for INT 10h function 0x4F02, ES:DI is undefined. So, ES:DI is whatever garbage was left from before.
alexfru wrote:
SayedMohsen64 wrote:

Code: Select all

	int 0x10
Supposedly, vesa_info.linear_frame_buffer_start should contains the start of the frame buffer. In my kernel:

Code: Select all

	mov edi, ebx             ; boot loader passes linear frame buffer start in EBX
	mov ax, 0xFFFF
	mov ecx, 0xEA600
What's in EFLAGS.DF here?
My EFLAGS.DF Is always clear. In any of my files after setting up a stack, I always do "cld".
alexfru wrote:0xEA600 = 800*600*2. Are you sure you don't want 800*600 = 0x75300?
This is just a test. At least if Bochs crashed from this, at least I would see a white screen first, I probably forget to divide it by two.
alexfru wrote:
SayedMohsen64 wrote:

Code: Select all

	rep stosw
Exactly how do you extract and pass the value of vesa_info.linear_frame_buffer_start?
I do this, before I give control to the kernel:

Code: Select all

	mov esi, vesa_info.linear_frame_buffer_start
	mov ebx, dword[esi]
	mov ax, [mem_blocks]
	mov dl, [bootdisk]
So when my kernel is executed, EBX contains the start of the linear frame buffer.
No worries, it works now in Qemu and VMware, but not in Bochs.
Icee
Member
Member
Posts: 100
Joined: Wed Jan 08, 2014 8:41 am
Location: Moscow, Russia

Re: How to use VESA linear frame buffer

Post by Icee »

SayedMohsen64 wrote:ES is zero because I have the ORG statement at the beginning of my file.
There's no connection between an ORG directive and segment register values.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: How to use VESA linear frame buffer

Post by BrightLight »

Icee wrote:
SayedMohsen64 wrote:ES is zero because I have the ORG statement at the beginning of my file.
There's no connection between an ORG directive and segment register values.
There definitely is a connection. Say we don't have an ORG statement, and we start at location 0x0. If we set segment registers to 0, instructions like LODSB, STOSB and other segment register-related stuff won't work properly. For example, if our string is at offset 0x100 in our file, and we have our file loaded to 0x5000, with segment registers to zero, with no ORG statement, 0:0x100 won't properly point to our string. So, DS and ES are related to ORG.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Bender
Member
Member
Posts: 449
Joined: Wed Aug 21, 2013 3:53 am
Libera.chat IRC: bender|
Location: Asia, Singapore

Re: How to use VESA linear frame buffer

Post by Bender »

omarrx024 wrote:
Icee wrote:
SayedMohsen64 wrote:ES is zero because I have the ORG statement at the beginning of my file.
There's no connection between an ORG directive and segment register values.
There definitely is a connection. Say we don't have an ORG statement, and we start at location 0x0. If we set segment registers to 0, instructions like LODSB, STOSB and other segment register-related stuff won't work properly. For example, if our string is at offset 0x100 in our file, and we have our file loaded to 0x5000, with segment registers to zero, with no ORG statement, 0:0x100 won't properly point to our string. So, DS and ES are related to ORG.
No, the ORG directive in any sane assembler would add the ORGed value while referencing an internal address.

For example,

Code: Select all

org 0x100
var: dw 1234
...
mov ax, var
Would translate to something like:

Code: Select all

org 0
var: dw 1234
...
mov ax, var
add ax, 0x100
It doesn't mess with segment registers.
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
Post Reply