Quote
... Can anyone give me some advice how i can verify what it loads into the memory? ...
You can check to make sure it loaded stage 2 by using a "stage 2 identifier," or something like that. I mean, the first two bytes of stage 2 can be an identifier that you check for before jumping to the stage 2 code; but note, though, that you would then have to jump to <stage 2 address> + 2, instead of <stage 2 address>, because of the 2-byte identifier. You could use a different size for the identifier, if you want, but 2 is what I used.
I did something like this, in my boot sector code:
ORG 0x7C00
USE16
jmp 0x00:start ;; The BIOS might either load this sector to 0x07C0:0x0000 or to 0x0000:0x7C00, but we want it to be a particular way, so we force 0x0000:0x7C00.
%define STAGE2_OFFSET 0x8000 ;; Where, in memory, stage 2 is supposed to be.
%define STAGE2_LOAD_SEGMENT 0x0800 ;; The segment we load stage 2 to.
%define STAGE2_LOAD_OFFSET 0x0000 ;; The offset we load stage 2 to.
;; The disk geometry for a 1.44 MB (1440 KB) floppy disk:
%define FLOPPY_HEADS 2
%define FLOPPY_TRACKS 80
%define FLOPPY_SECTORS 18
%define FLOPPY_BYTES 512
%define STAGE2_LOADS 7 ;; This means we want to load 7 tracks, besides the first track, from the boot disk.
boot_drive:
dw 0x00 ;; We initialize this to 0; we change this a little later.
start:
;; Set things up.
cli
xor ax, ax
mov es, ax
mov ds, ax
mov ss, ax
mov sp, 0x7BE0
sti
;; Save the drive number of the boot drive (you don't have to first copy it to AL; it's just I like it better that way).
mov al, dl
mov word [boot_drive], ax
;; Try to enable the A20 line using the BIOS service.
mov ax, 0x2401
int 0x15
jnc .load_stage2
;; In case the BIOS service does not work, do it using I/O ports.
in al, 0x92
or al, 0x02
out 0x92, al
;; Check if A20 is enabled.
call .check_a20
cmp al, 0
jz .load_stage2
.hang:
call b800
mov byte [es:bx+00], "h"
mov byte [es:bx+02], "h"
hlt
jmp .hang
.check_a20:
;; The idea, here, is to write to a memory location and check another memory location if the same value is there; if so, A20 is not enabled.
;; I mean, if we have only 2^16 (16-bit address) address space, then 0xFFFF:0x0510 would evaluate to physical address 0x0500; if, however,
;; the A20 line is enabled, then we would have 2^20 address space, so 0xFFFF:0x0510 would evaluate to some other physical address.
;; So if we write a value to 0x0500 and compare that value to the value at 0xFFFF:0x0510, then the result we get should tell us whether
;; A20 is enabled or disabled.
;; Note, though, that we don't use an address that is less than 0x0500, because the first 0x500 bytes of memory are
;; used by the BIOS and by the computer for important data that we don't want to overwrite; free memory starts
;; at 0x0500.
;; ... some code that checks to see if A20 is enabled ...
ret
.load_stage2:
;; ... some code ...
mov al, FLOPPY_SECTORS
int 0x13
jc .load_stage2_err
ret
.load_stage2_err:
;; Output "2e" (stage-2 load Error)
call b800
mov byte [es:bx+04], "2"
mov byte [es:bx+06], "e"
jmp .hang
.load_stage2_inv:
;; Output "IS" (Invalid Stage2)
call b800
mov byte [es:bx+04], "i"
mov byte [es:bx+06], "s"
jmp .hang
.load_stage2_finish:
;; Here we compare the first two bytes of what we loaded to the stage 2 signature, to make sure that it's really stage 2.
mov bx, STAGE2_OFFSET
cmp byte [bx+00], "S"
jnz .load_stage2_inv
cmp byte [bx+01], "2"
jnz .load_stage2_inv
;; Okay, the stuff we loaded passes the "stage 2 test."
xor ax, ax
mov ds, ax
mov es, ax
jmp 0x00:STAGE2_OFFSET + 2
b800:
mov ax, 0xB800
mov es, ax
xor bx, bx
ret
TIMES 510 - ($ - $$) DB 0x00
DW 0xAA55
And something like this for the stage 2 code:
ORG 0x8000
USE16
db "S2" ;; Stage 1 will check for this file identifier, so we want to include it, to tell stage 1 that this is a valid stage 2 start.
start:
;; ..... and the rest of the code .....
EDIT: Later on, you might need to use ATA or ATAPI or ...:
ATA PIO Mode - OSDev Wiki
Category:ATA - OSDev Wiki
ATAPI - OSDev Wiki