Page 1 of 1

Bootloader instructions help

Posted: Mon Oct 29, 2012 12:10 pm
by afdgdhfrtewdszs
Hello i don't understand why we need to disable interrupts(with cli), i thought using hlt(to halt the cpu would be enough). In addition why do we need to null ds and es?

Re: Bootloader instructions help

Posted: Mon Oct 29, 2012 2:25 pm
by halofreak1990
afdgdhfrtewdszs wrote:Hello i don't understand why we need to disable interrupts(with cli), i thought using hlt(to halt the cpu would be enough). In addition why do we need to null ds and es?
hlt halts the processor until the next interrupt

See why we need to disable interrupts? If we wouldn't use cli, then the cpu would continue running after the next interrupt, which could be anything.

On the question of nulling ds and es, could you post the relevent code where this happens? It's a little hard to explain various cases without the proper context.

Re: Bootloader instructions help

Posted: Mon Oct 29, 2012 10:53 pm
by afdgdhfrtewdszs
Thanks for your help, here is the code:

xor ax, ax
mov ds, ax
mov es, ax

Re: Bootloader instructions help

Posted: Tue Oct 30, 2012 1:22 am
by Andyhhp
In addition why do we need to null ds and es?
ds and es are used implicitly by several common operations which we would want to perform during boot.

In the example given, we are getting our running system into a consistant state. Depending on your nasm settings (the ORG statement), the chances are that your variables will be expecting ds set to 0, and having it non-0 would mean that any data reference you tried to use would be referenced other memory, rather than memory in the 512 bytes loaded by the BIOS.

~Andrew