Page 1 of 1
int 10h vs 0xB8000
Posted: Tue Jul 12, 2016 8:27 am
by hwg
Should I prefer the BIOS call or the MMIO method?
BIOS call:
Code: Select all
mov ah, 0Eh
mov al, '?'
mov bh, 00h
mov bl, 07h
int 10h
; pros:
; no manual managing of display
; BIOS function
; cons:
; less control
; BIOS function
MMIO method:
Code: Select all
uint8_t* vmem = 0xB8000;
vmem[0] = (uint8_t)'?';
vmem[1] = 0x07;
/*
* pros:
* more control
* higher level accessibility (no assembly)
* cons:
* manual management of cursor position and scrolling
* makes assumptions about memory
*/
The MMIO method requires more overhead in terms of code, e.g. cursor position and scrolling.
The BIOS method would require calling into assembly code or inline assembly.
Both methods are dependent on the x86{,-64} architecture.
Re: int 10h vs 0xB8000
Posted: Tue Jul 12, 2016 8:31 am
by BrightLight
Of course they depend on x86, because 0xB8000 is a VGA memory-mapped location, and the VGA was meant for PCs which use x86 CPUs.
The INT 0x10 functions are generally slow, and should be avoided as long as you're not in real mode. Accessing video memory directly is more code, but can be used in 32 and 64-bit modes.
BTW, accessing the video memory makes no assumptions about the memory, because you can configure the VGA planes and which memory is mapped where. But I think it's safe to say that 99.9% of color text modes map the memory at 0xB8000.
Re: int 10h vs 0xB8000
Posted: Tue Jul 12, 2016 8:48 am
by hwg
Ah, I thought as much. Once you have a video driver talking directly to the GPU, both of these methods become moot anyway, right?
Re: int 10h vs 0xB8000
Posted: Tue Jul 12, 2016 10:49 am
by BrightLight
hwg wrote:Ah, I thought as much. Once you have a video driver talking directly to the GPU, both of these methods become moot anyway, right?
GPU? I'm pretty sure no one needs GPU for text mode. The used memory is so little anyway that the GPU's acceleration features are useless, that is if any GPU even supports text mode acceleration.
EDIT: If you mean by GPU, graphics card, when you communicate directly with the VGA you can still use INT 0x10 and memory address 0xB8000.
Re: int 10h vs 0xB8000
Posted: Tue Jul 12, 2016 4:07 pm
by Combuster
hwg wrote:BIOS call:
(...)
MMIO method:
(...)
As written, there's a much simpler difference: the first piece works exclusively in real mode, the second works anywhere
but real mode.
Re: int 10h vs 0xB8000
Posted: Tue Jul 12, 2016 5:42 pm
by ggodw000
i did very basic 3-bit video driver using the MMIO it was slow as hell. There are still some bugs.
Int 10h might be easier to use but MMIO should give you more control.
Re: int 10h vs 0xB8000
Posted: Wed Jul 13, 2016 12:24 am
by Brendan
Hi,
hwg wrote:Should I prefer the BIOS call or the MMIO method?
Later during boot you shouldn't depend anything the firmware provides, so that you can easily add support for UEFI (or coreboot, OpenFirmware, and/or something like "kexec()" or "OS in embedded system ROM" or whatever else) by changing your boot loader and not changing any other part of the OS.
Early during boot you shouldn't make too many assumptions, and should use the firmware's "console output" (e.g. int 0x10 if firmware is BIOS) in case it's been redirected over network or something strange; and so that you can reliable display error messages if something goes wrong (e.g. "ERROR: failed to obtain a frame buffer").
Cheers,
Brendan
Re: int 10h vs 0xB8000
Posted: Wed Jul 13, 2016 9:21 pm
by aliceinchains
not sure how you would do it not in assembly but if you mov [ds:si], al it works in real mode. ie: assign ds b800 si your offset up to 3999 and al your char or color...