int 10h vs 0xB8000

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
hwg
Posts: 22
Joined: Wed Nov 18, 2015 11:56 am
Libera.chat IRC: hwg

int 10h vs 0xB8000

Post 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.
Last edited by hwg on Tue Jul 12, 2016 8:37 am, edited 1 time in total.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: int 10h vs 0xB8000

Post 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.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
hwg
Posts: 22
Joined: Wed Nov 18, 2015 11:56 am
Libera.chat IRC: hwg

Re: int 10h vs 0xB8000

Post 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?
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: int 10h vs 0xB8000

Post 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.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
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: int 10h vs 0xB8000

Post 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.
"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 ]
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: int 10h vs 0xB8000

Post 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.
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: int 10h vs 0xB8000

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
aliceinchains
Posts: 14
Joined: Wed Aug 13, 2014 11:04 am

Re: int 10h vs 0xB8000

Post 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...
Post Reply