[SOLVED] VBE Memory Model

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.
Post Reply
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

[SOLVED] VBE Memory Model

Post by xvedejas »

I've enabled VBE with GRUB 1.98 to video res 800x600x8. According to the given vbe mode info, the MemoryModel is 0xF0, which in the VBE specs is "To be defined by OEM". The machine is Qemu. I'm wondering what this means and how I can write a driver for it. Here are the values of all members of my vbe_mode_info struct:

Code: Select all

ModeAttributes: 0xFF53
WinAAttributes: 0x0
WinBAttributes: 0xF0
WinGranularity: 0xFF53
WinSize: 0xF000
WinASegment: 0xE2C3
WinBSegment: 0xF000
WinFuncPtr: 0xF000FF53
BytesPerScanLine: 0xFF53
XRes: 0xF000
YRes: 0xFF53
Xu8intSize: 0x0
Yu8intSize: 0xF0
NumberOfPlanes: 0x53
BitsPerPixel: 0xFF
NumberOfBanks: 0x0
MemoryModel: 0xF0
BankSize: 0x53
NumberOfImagePages: 0xFF
res1: 0x0
RedMaskSize: 0xF0
RedFieldPosition: 0xA5
GreenMaskSize: 0xFE
GreenFieldPosition: 0x0
BlueMaskSize: 0xF0
BlueFieldPosition: 0x87
RsvedMaskSize: 0xE9
RsvedFieldPosition: 0x0
PhysBasePtr: 0xF000E6E1
OffScreenMemOffset: 0xF000E6E1
OffScreenMemSize: 0xE6E1
You can get the specs by this link:

http://www.petesqbsite.com/sections/tut ... s/vbe3.pdf
Last edited by xvedejas on Thu Apr 29, 2010 6:50 am, edited 2 times in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: VBE Memory Model

Post by Combuster »

Did you notice that about everything else in that listing is bogus? framebuffers in the BIOS region? non-page-aligned addresses? negative resolutions?

I would have a look at how you get that data, I have the weird idea its the IVT contents you just showed us...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Re: VBE Memory Model

Post by xvedejas »

Here's how I get the information.

entry.asm, grub multiboot header

Code: Select all

header_magic equ 0x1BADB002
header_flags equ 7

align 4
mboot:
    ; This is the GRUB Multiboot header
    dd header_magic
    dd header_flags
    dd -(header_magic + header_flags) ; header checksum
    dd 0  ; unused
    dd 0  ; unused
    dd 0  ; unused
    dd 0  ; unused
    dd 0  ; unused
    dd 0  ; graphics mode type, 0 = gfx, 1 = text
    dd 800  ; width
    dd 600  ; height
    dd 8 ; depth, number of bits per pixel
mm.h, grub multiboot structure, obtained from pointer in initial ebx

Code: Select all

typedef struct
{
    u32int flags;            // 0
    u32int mem_lower;        // 4
    u32int mem_upper;        // 8
    u32int boot_device;      // 12
    string cmdline;          // 16
    u32int mods_count;       // 20
    u32int *mods_addr;       // 24
    u32int syms[4];          // 28, 32, 36, 40
    u32int mmap_length;      // 44
    mmap_field_t *mmap_addr; // 48
    u32int drives_length;    // 52
    u32int *drives_addr;     // 56
    u32int config_table;     // 60 
    string boot_loader_name; // 64
    u32int apm_table;
    u32int vbe_control_info;
    u32int vbe_mode_info;
    u32int vbe_mode;
    u32int vbe_interface_seg;
    u32int vbe_interface_off;
    u32int vbe_interface_len;
} multiboot_structure_t;
video.h, grub's VBE mode info structure obtained from multiboot_structure_t->vbe_mode_info

Code: Select all

typedef struct
{
	u16int ModeAttributes;
	u8int  WinAAttributes;
	u8int  WinBAttributes;
	u16int WinGranularity;
	u16int WinSize;
	u16int WinASegment;
	u16int WinBSegment;
	void  *WinFuncPtr;
	u16int BytesPerScanLine;
	u16int XRes;
	u16int YRes;
	u8int  Xu8intSize;
	u8int  Yu8intSize;
	u8int  NumberOfPlanes;
	u8int  BitsPerPixel;
	u8int  NumberOfBanks;
	u8int  MemoryModel;
	u8int  BankSize;
	u8int  NumberOfImagePages;
	u8int  res1;
	u8int  RedMaskSize;
	u8int  RedFieldPosition;
	u8int  GreenMaskSize;
	u8int  GreenFieldPosition;
	u8int  BlueMaskSize;
	u8int  BlueFieldPosition;
	u8int  RsvedMaskSize;
	u8int  RsvedFieldPosition;
	//VBE 2.0
	u32int *PhysBasePtr;
	u32int OffScreenMemOffset;
	u16int OffScreenMemSize;
	//VBE 2.1
	u16int LinbytesPerScanLine;
	u8int  BankNumberOfImagePages;
	u8int  LinNumberOfImagePages;
	u8int  LinRedMaskSize;
	u8int  LinRedFieldPosition;
	u8int  LingreenMaskSize;
	u8int  LinGreenFieldPosition;
	u8int  LinBlueMaskSize;
	u8int  LinBlueFieldPosition;
	u8int  LinRsvdMaskSize;
	u8int  LinRsvdFieldPosition;
	u8int  res2[194];
} vbeModeInfo_t;
video.c, printing out all the values

Code: Select all

void video_install(multiboot_structure_t *multiboot)
{
	// assert the presence of vbe info
	assert(multiboot->flags & bit(11));

	vbeModeInfo_t *vbeModeInfo = (vbeModeInfo_t*)multiboot->vbe_mode_info;

	print_serial("ModeAttributes: %x\n", vbeModeInfo->ModeAttributes);
	print_serial("WinAAttributes: %x\n", vbeModeInfo->WinAAttributes);
	print_serial("WinBAttributes: %x\n", vbeModeInfo->WinBAttributes);
	print_serial("WinGranularity: %x\n", vbeModeInfo->WinGranularity);
	print_serial("WinSize: %x\n", vbeModeInfo->WinSize);
	print_serial("WinASegment: %x\n", vbeModeInfo->WinASegment);
	print_serial("WinBSegment: %x\n", vbeModeInfo->WinBSegment);
	print_serial("WinFuncPtr: %x\n", vbeModeInfo->WinFuncPtr);
	print_serial("BytesPerScanLine: %x\n", vbeModeInfo->BytesPerScanLine);
	print_serial("XRes: %x\n", vbeModeInfo->XRes);
	print_serial("YRes: %x\n", vbeModeInfo->YRes);
	print_serial("Xu8intSize: %x\n", vbeModeInfo->Xu8intSize);
	print_serial("Yu8intSize: %x\n", vbeModeInfo->Yu8intSize);
	print_serial("NumberOfPlanes: %x\n", vbeModeInfo->NumberOfPlanes);
	print_serial("BitsPerPixel: %x\n", vbeModeInfo->BitsPerPixel);
	print_serial("NumberOfBanks: %x\n", vbeModeInfo->NumberOfBanks);
	print_serial("MemoryModel: %x\n", vbeModeInfo->MemoryModel);
	print_serial("BankSize: %x\n", vbeModeInfo->BankSize);
	print_serial("NumberOfImagePages: %x\n", vbeModeInfo->NumberOfImagePages);
	print_serial("res1: %x\n", vbeModeInfo->res1);
	print_serial("RedMaskSize: %x\n", vbeModeInfo->RedMaskSize);
	print_serial("RedFieldPosition: %x\n", vbeModeInfo->RedFieldPosition);
	print_serial("GreenMaskSize: %x\n", vbeModeInfo->GreenMaskSize);
	print_serial("GreenFieldPosition: %x\n", vbeModeInfo->GreenFieldPosition);
	print_serial("BlueMaskSize: %x\n", vbeModeInfo->BlueMaskSize);
	print_serial("BlueFieldPosition: %x\n", vbeModeInfo->BlueFieldPosition);
	print_serial("RsvedMaskSize: %x\n", vbeModeInfo->RsvedMaskSize);
	print_serial("RsvedFieldPosition: %x\n", vbeModeInfo->RsvedFieldPosition);
	print_serial("PhysBasePtr: %x\n", vbeModeInfo->PhysBasePtr);
	print_serial("OffScreenMemOffset: %x\n", vbeModeInfo->OffScreenMemOffset);
	print_serial("OffScreenMemSize: %x\n", vbeModeInfo->OffScreenMemSize);
}
Need anything else? I think this is all the relevent code. I know the multiboot_structure_t works because I successfully use its mmap_* fields in my memory manager.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: VBE Memory Model

Post by Combuster »

Obviously you didn't check for null pointers. (wasn't the IVT stored at address 0 :wink:)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Re: VBE Memory Model

Post by xvedejas »

*facepalm*

So how do I get the correct structure from GRUB?
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: VBE Memory Model

Post by thepowersgang »

There's a flag in the multiboot header that asks grub to pass you one.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
xvedejas
Member
Member
Posts: 168
Joined: Thu Jun 04, 2009 5:01 pm

Re: VBE Memory Model

Post by xvedejas »

thepowersgang wrote:There's a flag in the multiboot header that asks grub to pass you one.
Yeah, and it never did.

Doesn't matter, I fixed it now by looking at a new multiboot specification that I could only find in a bazaar repository. I told the maintainer to update the version on the gnu website.
Post Reply