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
Where did I get this stack?
Re:Where did I get this stack?
Probably, anyway, to be "safe", set your stack yourself.Does the BIOS set up
a stack
Re:Where did I get this stack?
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.
Much safer to set SS/ESP to decent values yourself.
- Pype.Clicker
- 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?
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 ...