BIOS calls and registers

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.
mallard
Member
Member
Posts: 280
Joined: Tue May 13, 2014 3:02 am
Location: Private, UK

Re: BIOS calls and registers

Post by mallard »

Any "MS-DOS compatible" OS is will require BIOS (or provide an emulation of one). Almost all DOS programs (and many parts of DOS itself) use BIOS services. DOS itself doesn't provide anything like a complete API for programming the PC and was designed to be used in conjunction with the BIOS. Even if the OS could be made BIOS-independent, there would be very few DOS applications that would run without it.

Basically, "DOS" without the BIOS would be almost completely useless.
Image
User avatar
elderK
Member
Member
Posts: 190
Joined: Mon Dec 11, 2006 10:54 am
Location: Dunedin, New Zealand
Contact:

Re: BIOS calls and registers

Post by elderK »

It seems the topic has run far off course.

To return to the original question: Are there any registers whose contents I can be sure will be preserved when utilizing a BIOS call?

RBIL doesn't mention what registers are preserved, etc, when describing E820. Naturally, I assume all the ones it doesn't mention as being altered or used by the call, are preserved.

But how sure can I be of that?
~K
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: BIOS calls and registers

Post by b.zaar »

elderK wrote:RBIL doesn't mention what registers are preserved
Every register not mentioned is preserved, SS & SP is saved by the int XX.

RBIL is the BIBLE about interrupts, if something is not mentioned there you'll have to search the BIOS source code directly.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: BIOS calls and registers

Post by Antti »

b.zaar wrote:Every register not mentioned is preserved
I would say it is not a good idea to trust that. I could write a code snippet like this:

Code: Select all

RandomByteVal equ 0x12
RandomAddrOff equ 0x1234
RandomAddrSeg equ 0x4321

ExampleCode:
    mov ax, RandomAddrSeg
    mov ds, ax
    cmp byte [RandomAddrOff], RandomByteVal

    jne SafeBranch
    call TurnOffTheSun          ; THIS MUST NOT BE CALLED!

SafeBranch:
I am almost sure the Sun is not turned off. Do I like to have this kind of code? No.
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: BIOS calls and registers

Post by b.zaar »

Antti wrote:
b.zaar wrote:Every register not mentioned is preserved
I would say it is not a good idea to trust that. I could write a code snippet like this:

Code: Select all

RandomByteVal equ 0x12
RandomAddrOff equ 0x1234
RandomAddrSeg equ 0x4321

ExampleCode:
    mov ax, RandomAddrSeg
    mov ds, ax
    cmp byte [RandomAddrOff], RandomByteVal

    jne SafeBranch
    call TurnOffTheSun          ; THIS MUST NOT BE CALLED!

SafeBranch:
I am almost sure the Sun is not turned off. Do I like to have this kind of code? No.
I'm not sure what your point is here? Where is the bios interrupt and which register did it corrupt?
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: BIOS calls and registers

Post by Antti »

b.zaar wrote:I'm not sure what your point is here? Where is the bios interrupt and which register did it corrupt?
The point was to show that code could be safe in practice. If you accept that quality level, then it is perfectly fine. Most of the programmers do that. Saying that all the registers not mentioned are preserved is not something that I would assume.

It is not too difficult to write code that does not care whether registers are preserved or not. I will assume that registers cs, ss, and sp are preserved if calling BIOS interrupt services.
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: BIOS calls and registers

Post by b.zaar »

Antti wrote:
The point was to show that code could be safe in practice. If you accept that quality level, then it is perfectly fine. Most of the programmers do that. Saying that all the registers not mentioned are preserved is not something that I would assume.

It is not too difficult to write code that does not care whether registers are preserved or not. I will assume that registers cs, ss, and sp are preserved if calling BIOS interrupt services.
The bios has been around a long time and I think if it couldn't be trusted there's a lot of software out there since 1981 that has been very lucky when using it.

Feel free to browse the bochs bios source code though

Bios shouldn't be trusted any less than dos, Amiga os, os/2 or even any c library you use.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
Post Reply