Stage 1 Boot:
Code: Select all
;0x00000000 - 0x000003FF - Real Mode Interrupt Vector Table
;0x00000400 - 0x000004FF - BIOS Data Area
;0x00000500 - 0x00007BFF - Unused
;0x00007C00 - 0x00007DFF - Stage 1 Boot
;0x00007E00 - 0x0009FFFF - Unused <----- I will load Stage 2 Boot here, since this is free memory space :D
;0x000A0000 - 0x000BFFFF - Video RAM (VRAM) Memory
;0x000B0000 - 0x000B7777 - Monochrome Video Memory
;0x000B8000 - 0x000BFFFF - Color Video Memory
;0x000C0000 - 0x000C7FFF - Video ROM BIOS
;0x000C8000 - 0x000EFFFF - BIOS Shadow Area
;0x000F0000 - 0x000FFFFF - System BIOS
BITS 16
ORG 0x7C00
JMP main
%include "Utility.inc"
message1 DB "Stage 1 Boot",13,10,0
message2 DB "FAIL",13,10,0
diskAddressPacket:
size DB 16
reserved DB 0
numberOfSectors DW 1
bufferOffset DW 0x7E00
bufferSegment DW 0
startSector DQ 1
main:
XOR AX,AX
MOV DS,AX
MOV SI,message1
CALL String.print
.reset:
XOR AH,AH
INT 0x13
JC .reset
MOV AH,0x42
;BIOS has already put drive index to DL register.
MOV SI,diskAddressPacket
INT 0x13
JC .exit
JMP 0:0x7E00
.exit:
MOV SI,message2
CALL String.print
JMP $
TIMES 510 - ($ - $$) DB 0
DW 0xAA55 ;Boot Signature
Stage 2 Boot:
Code: Select all
BITS 16
ORG 0x7E00
JMP main
%include "Utility.inc"
message1 DB "Stage 2 Boot",13,10,0
main:
XOR AX,AX
MOV DS,AX
MOV SI,message1
CALL String.print
JMP $
Questions:
1. So AFAIK ORG directive is used to tell the compiler which offset to use for variables. In other words, now:
MOV SI,message1 = MOV SI,0x7C00+(some offset which was computed at the compile time)
Am I right about it?
2. What is going to happen if I will remove ORG directive at all? Will I have to utilize Segment Registers then? How would I reference variables then? (Just assume the case when you don't know where is your program)
3. What about Segment Registers in general? Do I have to set em up or just ignore, in case of Real Mode boot loader? (The DS was set up in this example just for string output... you have probably got it already)
4. And what about stack? Where is stack? I didn't specify anything about it in the program. Does BIOS setup SS and SP registers with some specific values after finding my boot loader?
5. Some additional information from debugging, because I'm a bit confused about it: