Bootloader instructions help

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
afdgdhfrtewdszs
Posts:18
Joined:Tue Feb 01, 2011 6:25 pm
Bootloader instructions help

Post by afdgdhfrtewdszs » Mon Oct 29, 2012 12:10 pm

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?

halofreak1990
Posts:92
Joined:Thu May 27, 2010 8:54 pm
Location:Netherlands

Re: Bootloader instructions help

Post by halofreak1990 » Mon Oct 29, 2012 2:25 pm

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.

afdgdhfrtewdszs
Posts:18
Joined:Tue Feb 01, 2011 6:25 pm

Re: Bootloader instructions help

Post by afdgdhfrtewdszs » Mon Oct 29, 2012 10:53 pm

Thanks for your help, here is the code:

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

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Bootloader instructions help

Post by Andyhhp » Tue Oct 30, 2012 1:22 am

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
Image

Post Reply