Video mode used by BIOS

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
shahsunny712
Posts: 20
Joined: Wed Jan 29, 2014 11:57 am

Video mode used by BIOS

Post by shahsunny712 »

BIOS int 10h with AH=00h allows one to set the video mode (http://stanislavs.org/helppc/int_10-0.html).

What is the mode used by BIOS when it starts up ? Does it vary among different manufacturers ?

Also, how can one find out the current mode ?
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Video mode used by BIOS

Post by Antti »

When the control is given to your boot code, as far as I know, the mode "03h" seems to be considered as a standard one. It is a good question whether it varies or not. You can query the currently selected mode using INT 10h, AH=0Fh. A lot of code is written assuming that the video mode is a text-mode that can be accessed at physical memory address 0xB8000. I am therefore quite skeptical that you find a computer that uses some other mode but, however, I can not see why a computer could not use some other mode. Good code (tm) does not assume that any specific mode is set.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Video mode used by BIOS

Post by Brendan »

Hi,
shahsunny712 wrote:What is the mode used by BIOS when it starts up ? Does it vary among different manufacturers ?
Typically it's mode 0x03. If the computer is extremely ancient and has a monochrome monitor it's more likely to be mode 0x02. In all my time I have only ever seen one computer's BIOS that did anything different (an 80486 that used mode 0x12 instead).

However; you shouldn't assume that the BIOS starts your code. The BIOS can start someone else's code, which chain-loads someone else's code, which chain-loads something else, which... Any code that runs before your boot loader can change the video mode to anything.

For maximum reliability, don't assume. You could set the mode yourself; or you could ask the BIOS what the current mode is and only switch video modes if it's not what you want. For an example of the latter; here's the video initialisation code my own boot loaders use:

Code: Select all

;Video Initialization
;
;This code attempts to detect if a suitable video card is present and
; configure a default 80 * 25 text mode; and assumes the computer is headless
; if no suitable video card is found.
;______________________________________________________________________________

VIDEO_init:

;Detect If A Suitable Video Card Is Present
;______________________________________________________________________________

     mov ax,0x1A00                            ;ax = BIOS function number (Get Display Combination Code)
     stc                                      ;Paranoia, in case BIOS's dummy handler doesn't set the carry flag for unsupported functions
     int 0x10                                 ;Call BIOS function (Get Display Combination Code)
     cmp al,0x1A                              ;If AL != 0x1A, assume no video card is present
     jne .done                                ;If carry set, assume no video card is present
     mov byte [videoPresentFlag],1            ;Set "video card is present" flag

;Setup 80 * 25 Text Mode
;______________________________________________________________________________

;Check if we're already in 80*25 text mode

;Note: Ralph Brown's Interrupt List says that the byte at offset 0x22 in the table returned by this BIOS
;     function is "rows - 1". The first eight computers I tested it on disagreed and think the byte
;     at offset 0x22 is "rows". However, Bochs agrees with Ralph Brown's Interrupt List (and therefore
;     all other emulators that use the same VGA ROM code as Bochs would too). I don't think any video cards
;     support a "80 * 24" or "80 * 26" text mode, and I don't think it'd matter if they did, so we test for
;     both cases.

     mov ax,0x1B00                            ;ah = BIOS function number (Get Functionality/State Information), al = cleared (just in case)
     clr bx                                   ;bx = implementation type
     mov di,_SECTOR2_START                    ;es:di = address to store state information
     int 0x10                                 ;Call BIOS function (Get Functionality/State Information)
     cmp al,0x1B                              ;Was the function supported?
     jne .resetMode                           ; no, reset the video mode
     cmp word [di+0x04],0x03 | (80 << 8)      ;Is the current video mode "mode 0x03", and does it have 80 columns?
     jne .resetMode                           ; no, reset the video mode
     cmp byte [di+0x22],25                    ;Does the current video mode have 24 or 25 rows?
     je .gotMode                              ; yes, no reason to reset the video mode
     cmp byte [di+0x22],25 - 1                ;Does the current video mode have 24 or 25 rows?
     je .gotMode                              ; yes, no reason to reset the video mode

;Set 80*25 text mode

.resetMode:
     mov ax,0x0003                            ;ah = BIOS function number (Set Video Mode), al = video mode (0x03 = 80 * 25 text mode)
     int 0x10                                 ;Call BIOS function (Set Video Mode)
.gotMode:

;Disable the cursor (which should NEVER be displayed, unless the system is waiting for the user type text in)

     mov ah,0x01                              ;ah = BIOS function number (Set Text Mode Cursor Shape)
     mov cx,0x2D0E                            ;VGA cursor settings, bits 5 and 6 of CH disables cursor
     int 0x10                                 ;Call BIOS function (Set Text Mode Cursor Shape)

;Enable 16 background colours (and disable blinking)

     mov ax,0x1003                            ;ax = BIOS function number (Toggle Intensity/Blinking Bit)
     clr bx                                   ;bl = 00 (enable intensity), bh = cleared in case the BIOS is buggy
     int 0x10                                 ;Call BIOS function (Toggle Intensity/Blinking Bit)

;Get current display page number

     clr bx                                   ;Clear BX in case the BIOS is buggy
     mov ah,0x0F                              ;ah = BIOS function number (Get Current Video Mode)
     int 0x10                                 ;Call BIOS function (Get Current Video Mode)
     mov [displayPage],bh                     ;Set display page number

.done:
     ret
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.
shahsunny712
Posts: 20
Joined: Wed Jan 29, 2014 11:57 am

Re: Video mode used by BIOS

Post by shahsunny712 »

Thanks guys :)

And thanks Brendan for the code. Simple and self-explanatory !
rdos
Member
Member
Posts: 3306
Joined: Wed Oct 01, 2008 1:55 pm

Re: Video mode used by BIOS

Post by rdos »

All legacy BIOS boots start in video mode 3, with a text mode buffer at 0xB8000 (and on old systems, sometimes at 0xB0000 if it is a monochrome adapter). For UEFI, you have no idea. It could be anything. Even worse, UEFI could setup something that your OS cannot handle, and as you need to exit boot services before you start the OS, there is no fallback for this.
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: Video mode used by BIOS

Post by Combuster »

rdos wrote:All legacy BIOS boots start in video mode 3
Brendan wrote:Typically it's mode 0x03. If the computer is extremely ancient and has a monochrome monitor it's more likely to be mode 0x02. In all my time I have only ever seen one computer's BIOS that did anything different (an 80486 that used mode 0x12 instead).
Yup, rdos is back. :^o
Even worse, UEFI could setup something that your OS cannot handle
Therefore, GOP.
"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 ]
rdos
Member
Member
Posts: 3306
Joined: Wed Oct 01, 2008 1:55 pm

Re: Video mode used by BIOS

Post by rdos »

Combuster wrote:Therefore, GOP.
GOP is boot-only. Cannot be used by the OS to output information after the boot-process is completed.

In fact, UEFI forces some kind of collaboration between the EFI boot code and the OS loader and graphics driver. It requires an early screen-logger that is between loading the OS and the really competent user-mode graphics driver. All this is a huge step backwards. With the legacy BIOS, all you do is to write to 0xB8000, and it gets on-screen.
User avatar
Bender
Member
Member
Posts: 449
Joined: Wed Aug 21, 2013 3:53 am
Libera.chat IRC: bender|
Location: Asia, Singapore

Re: Video mode used by BIOS

Post by Bender »

rdos wrote:GOP is boot-only. Cannot be used by the OS to output information after the boot-process is completed.

In fact, UEFI forces some kind of collaboration between the EFI boot code and the OS loader and graphics driver. It requires an early screen-logger that is between loading the OS and the really competent user-mode graphics driver. All this is a huge step backwards. With the legacy BIOS, all you do is to write to 0xB8000, and it gets on-screen.
However you can,
Brendan wrote:
blm768 wrote:Is GOP available after ExitBootServices()?
No, but you can get information needed to use the frame buffer before calling ExitBootServices() and use that framebuffer after calling ExitBootServices().
Brendan wrote:
blm768 wrote:Ouch. I thought UEFI was supposed to make things easier. I guess I'll have to implement a framebuffer driver for each graphics card. (I'm not planning on messing with 2D acceleration; it's not worth the effort when most window managers are switching to OpenGL).
You don't need a frame-buffer driver for each card - you only need one frame-buffer driver.

The frame-buffer driver should only need to know the physical address of the frame buffer, the resolution, the pixel format and how many bytes between horizontal lines (and shouldn't need to know anything else, including what the video card is).

Also note that this also means that the same frame-buffer driver should work regardless of where this information came from (and the same frame buffer driver should work regardless of whether this information originally came from UEFI/GOP, UEFI/UGA, BIOS/VBE or something else).

The disadvantage is that there's no 2D or 3D acceleration, no hardware mouse pointer support, and no way to change video modes after boot. For these things you'd need native drivers for each card (and not a frame-buffer driver).
rdos wrote:All this is a huge step backwards.
Back...ward...s? You mean to say that classic BIOS was better? You don't want our PCs to boot like they
did 20 or 30 years ago or do you?
Btw why wake up an almost ( :?: ) dead thread?
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Video mode used by BIOS

Post by VolTeK »

Bender wrote:Btw why wake up an almost (face) dead thread?
How old is almost dead?
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Video mode used by BIOS

Post by Nable »

VolTeK wrote:How old is almost dead?
I think that this thread is dead not because of its age but because discussion is finished (comprehensive answers were given, so further replies won't bring anything good).
Maybe topicstarter should mark it as '[solved]'.
Post Reply