linux-assembly.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Marcin Kościelnicki" <markosc@interia.pl>
To: linux-assembly@vger.kernel.org
Subject: Re: grub thing
Date: Wed, 1 Mar 2006 15:42:50 +0100	[thread overview]
Message-ID: <200603011542.51608.markosc@interia.pl> (raw)
In-Reply-To: <20060301071033.0c9eb1d4.amerei@gmail.com>

> i'm looking at a disassembly of grub's stage 1. and i wanna know why it
> need's to CLI before setting up the environment??

It's because it sets the stack address -- otherwise, interrupt could occur 
between mov to ss and mov to sp, which would use invalid stack address and be 
lethal.

Also, it has NOTHING to do with lack of interrupt handlers -- BIOS has 
handlers for all interrupts needed for bootstrap, and the others are 
disabled. No bad thing can happen. In fact, it re-enables interrupts right 
after setting the stack (sti)

> i tried to interpret it 
> line by line and this is what i have so far
>
>  00007C4A  FA			cli			; disable interrupt
>  00007C4B  80CA80		or dl,0x80          ; correct boot drive byte
>  00007C4E  EA537C0000	jmp 0x0:0x7c53	; jmp to next inst
>  00007C53  31C0		xor ax,ax           ; zero ax
>  00007C55  8ED8		mov ds,ax		; zero data segment
>  00007C57  8ED0		mov ss,ax		; zero stack segment
>  00007C59  BC0020		mov sp,0x2000	; 8 kilobytes
>  00007C5C  FB			sti			; enable interrupt
>
> also, since the origin is at 0000:7c00h i figured that must imply that "mov
> sp, 0x2000" means that the stack starts at 0x7c00+0x2000 = 9c000 right?

No.

>  00007C57  8ED0		mov ss,ax		; zero stack segment
>  00007C59  BC0020		mov sp,0x2000	; 8 kilobytes

Here, ss==0 and sp==0x2000. Stack starts at ss*0x10+sp == 0x0*0x10+0x2000 == 
0x2000. Also, remember it grows down.

----------------------------------------------------------------------
Kliknij po wiecej! >>> http://link.interia.pl/f18ed


  parent reply	other threads:[~2006-03-01 14:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-22 21:26 nasm -f bin / Elf format Thiago Silva
2006-02-23  0:32 ` Brian Raiter
2006-03-01  7:10 ` grub thing Aleph One
2006-03-01 13:34   ` Ricardo Nabinger Sanchez
2006-03-02  6:49     ` Aleph One
2006-03-01 14:42   ` Marcin Kościelnicki [this message]
2006-03-01 18:08     ` Ricardo Nabinger Sanchez
2006-03-02  6:46     ` Aleph One

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200603011542.51608.markosc@interia.pl \
    --to=markosc@interia.pl \
    --cc=linux-assembly@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).