Hi!
I wrote a primitive delay procedure that reads the BDA 0:0x046c. I use Bochs and I've noticed that during the POST process the value in memory is updated but once control passed to 0x7c00, the value is no longer updated (checked this with Bochs debugger). Is this a known issue or I'm missing something? Or perhaps this is legacy and is not a standard anymore in BIOS?
Thanks a lot!
Alexei
BDA 0:0x046c is not updated in Bochs
- BrightLight
- Member
- Posts: 901
- Joined: Sat Dec 27, 2014 9:11 am
- Location: Maadi, Cairo, Egypt
- Contact:
Re: BDA 0:0x046c is not updated in Bochs
When possible, you shouldn't depend on the BIOS for anything. In a boot loader, you should use the BIOS only for output, video modes, memory detection and disk access. When you need a proper delay function after you are in protected or long mode, you can use the PIT (or eventually the APIC and/or HPET). If you absolutely must use the BIOS for a delay function, try having a look at the time functions of interrupt 0x1A, as most fields in the BIOS data area are obsolete and I wouldn't trust them on any real HW.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Re: BDA 0:0x046c is not updated in Bochs
I absolutely agree with you! This delay was something that I've made quickly for temporary use.omarrx024 wrote:When possible, you shouldn't depend on the BIOS for anything. In a boot loader, you should use the BIOS only for output, video modes, memory detection and disk access. When you need a proper delay function after you are in protected or long mode, you can use the PIT (or eventually the APIC and/or HPET). If you absolutely must use the BIOS for a delay function, try having a look at the time functions of interrupt 0x1A, as most fields in the BIOS data area are obsolete and I wouldn't trust them on any real HW.
Thanks for your answer!
Re: BDA 0:0x046c is not updated in Bochs
Hi,
I'd assume that your code is "buggy". The PIT chip sends an IRQ to the master PIC chip, which sends an IRQ to the CPU if interrupts are enabled in the CPU, which causes CPU to use the IDT or IVT to find the associated interrupt handler, where the BIOS IRQ/interrupt handler increments the value at 0:0x046c. If you've touched anything in that chain then...
Cheers,
Brendan
I tested it on Bochs here and BDA 0:0x046c is updated after the BIOS passes control to 0x7C00.alexeikom wrote:I wrote a primitive delay procedure that reads the BDA 0:0x046c. I use Bochs and I've noticed that during the POST process the value in memory is updated but once control passed to 0x7c00, the value is no longer updated (checked this with Bochs debugger). Is this a known issue or I'm missing something? Or perhaps this is legacy and is not a standard anymore in BIOS?
I'd assume that your code is "buggy". The PIT chip sends an IRQ to the master PIC chip, which sends an IRQ to the CPU if interrupts are enabled in the CPU, which causes CPU to use the IDT or IVT to find the associated interrupt handler, where the BIOS IRQ/interrupt handler increments the value at 0:0x046c. If you've touched anything in that chain then...
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.
Re: BDA 0:0x046c is not updated in Bochs
Hi! I thought that either but then I checked it on real machine and it worked.Brendan wrote:Hi,
I tested it on Bochs here and BDA 0:0x046c is updated after the BIOS passes control to 0x7C00.alexeikom wrote:I wrote a primitive delay procedure that reads the BDA 0:0x046c. I use Bochs and I've noticed that during the POST process the value in memory is updated but once control passed to 0x7c00, the value is no longer updated (checked this with Bochs debugger). Is this a known issue or I'm missing something? Or perhaps this is legacy and is not a standard anymore in BIOS?
I'd assume that your code is "buggy"....
Cheers,
Brendan
Re: BDA 0:0x046c is not updated in Bochs
Hi,
My suggestion would be to test on Bochs using something like this:
The idea is that you put this as early as possible in your boot code and see if it waits forever, then shift it somewhere else and see if it waits forever, and keep shifting it like that using a kind of binary search pattern (e.g. each time, shift it to approximately half-way between where it was working last and where it stopped working last) to find the point in your code immediately before it stops working.
Cheers,
Brendan
So you're saying that your code is buggy, but the bug depends on something that might be different on different computers (like CPU features, or memory map, or timing, or the presence or absence of certain devices, or the initial contents of uninitialised RAM, or the initial contents of registers when BIOS passes control to your code, or how the firmware happens to use part of its BDA or EBDA that gets accidentally corrupted, or....), and so it's only a problem on some computers (e.g. Bochs and possibly millions of others) and not other computers (e.g. one real computer)?alexeikom wrote:Hi! I thought that either but then I checked it on real machine and it worked.Brendan wrote:I'd assume that your code is "buggy"....
My suggestion would be to test on Bochs using something like this:
Code: Select all
mov ax,[0x046C]
sti
.wait:
hlt
cmp [0x046C],ax
je .wait
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.
Re: BDA 0:0x046c is not updated in Bochs
Hi! Thanks for a great suggestion. I did the check and the code suggested by you worked everywhere! I then compared it to my code:Brendan wrote:Hi,
So you're saying that your code is buggy, but the bug depends on something that might be different on different computers (like CPU features, or memory map, or timing, or the presence or absence of certain devices, or the initial contents of uninitialised RAM, or the initial contents of registers when BIOS passes control to your code, or how the firmware happens to use part of its BDA or EBDA that gets accidentally corrupted, or....), and so it's only a problem on some computers (e.g. Bochs and possibly millions of others) and not other computers (e.g. one real computer)?alexeikom wrote:Hi! I thought that either but then I checked it on real machine and it worked.Brendan wrote:I'd assume that your code is "buggy"....
My suggestion would be to test on Bochs using something like this:
The idea is that you put this as early as possible in your boot code and see if it waits forever, then shift it somewhere else and see if it waits forever, and keep shifting it like that using a kind of binary search pattern (e.g. each time, shift it to approximately half-way between where it was working last and where it stopped working last) to find the point in your code immediately before it stops working.Code: Select all
mov ax,[0x046C] sti .wait: hlt cmp [0x046C],ax je .wait
Cheers,
Brendan
Code: Select all
push es
push ax
xor ax,ax
mov es,ax
mov ax,[es:0x046C]
inc ax
comp:
cmp ax,[es:0x046C]
jae comp
pop ax
pop es
ret