Where did I get this stack?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
jinksys

Where did I get this stack?

Post 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
DennisCGc

Re:Where did I get this stack?

Post by DennisCGc »

Does the BIOS set up
a stack
Probably, anyway, to be "safe", set your stack yourself.
Curufir

Re:Where did I get this stack?

Post 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.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Where did I get this stack?

Post 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 ...
Post Reply