Page 1 of 1

Where did I get this stack?

Posted: Sun Jun 06, 2004 4:33 am
by jinksys
I wrote this bootsector that draws a small checkerboard pattern on
the screen. It works ok...but why does it not crash when it tries
to use a stack that (AFAIK) does not exist? Does the BIOS set up
a stack, or is this a fluke?

.code16

.globl _start
_start:

mov   $0x7c0,%ax
mov   %ax,%ds

movw   $0x13,%ax
int   $0x10

push   $0x0A000
pop   %es

xor   %di,%di

mov   $image,%si

movw   $63,%cx



write_loop:
lodsb
cmp   $0,%cx
jz   halt
cmp   $9,%al
jz   next_line
stosb
loop   write_loop

halt:      
   jmp halt   

next_line:
add   $320,%di
sub   $8,%di
dec %cx
jmp write_loop   

image:   
   .byte   0,15,0,15,0,15,0,15,9
   .byte   15,0,15,0,15,0,15,0,9
   .byte   0,15,0,15,0,15,0,15,9
   .byte   15,0,15,0,15,0,15,0,9
   .byte   0,15,0,15,0,15,0,15,9
   .byte   15,0,15,0,15,0,15,0,9
   .byte   0,15,0,15,0,15,0,15,9

.org   510,0
.byte   0x55,0xAA

Re:Where did I get this stack?

Posted: Sun Jun 06, 2004 5:10 am
by DennisCGc
Does the BIOS set up
a stack
Probably, anyway, to be "safe", set your stack yourself.

Re:Where did I get this stack?

Posted: Sun Jun 06, 2004 8:59 am
by Curufir
BIOS does set up a stack, it needs one to run its own code. Problem is that the location of that stack is different for the different BIOS, so by just using it blindly you could be writing data practically anywhere.

Much safer to set SS/ESP to decent values yourself.

Re:Where did I get this stack?

Posted: Sun Jun 06, 2004 3:41 pm
by Pype.Clicker
and moreover, the BIOS stack is relatively small (only suited for the POST). So i second everyone else: if you don't want to get the surprise of a PC not working with your bootsector, you're better setting up a stack of your own before starting calls to INT nn ...