Page 2 of 2

Re:Floppy Image File Setup / Load Sector

Posted: Sun Mar 13, 2005 2:50 am
by Cjmovie

Code: Select all

[BITS 16]
[ORG 0x7C00]
 
 jmp Start
 
Retry:
 mov si, msgProb
 call Message
 dec BYTE [nTrys]
 mov ah, BYTE [nTrys]
 or ah, ah
 jnz Load
 
Fail:
 mov si, msgFail
 call Message
 jmp $
 
Start:
 mov si, msgLoad
 call Message
 
Reset:
 mov ah, 0
 int 13h
 or ah, ah
 jnz Reset
  
 mov es, ax
 mov bx, 0x1000

Load:
 
 
 mov ah, 02h ;Function Read
 mov al, 01h ;Num to read
 mov ch, 01h ;Cylinder
 mov cl, BYTE [nNextSector] ;First Sect
 mov dh, 01h ;Head
 int 13h
 or ah, ah
 jnz Retry
 mov si, msgNext
 call Message
 inc BYTE [nNextSector]
 dec BYTE [nReadSector]
 mov ah, BYTE [nReadSector]
 add bx, 0200h ;512 byte farther
 or ah, ah
 jnz Load
 
 
 cli
 xor ax, ax
 mov ds, ax
 lgdt [gdt_main]
 
 mov eax, cr0
 or eax, 1
 mov cr0, eax
 
 jmp 08h:ClearPipe

Message:
 mov ah, 0x0E
 mov bh, 0x00
 mov bl, 0x07
 lodsb
 or al, al
 jz .Return
 int 0x10
 jmp Message
.Return
 ret

[BITS 32]
ClearPipe:
 mov ax, 10h
 mov ds, ax
 mov ss, ax
 
 mov esp, 090000h
 
 call 08h:01000h
 
 jmp $
 
%include "main.gdt"

nTrys       db 5
nReadSector db 10
nNextSector db 1
msgLoad     db "Loading Kernel", 13, 10, 0
msgNext     db ".", 0
msgFail     db "Kernel Load Failed.", 13, 10, 0
msgError    db 13,"Cannot load (S,C,H): ", 0
msgProb     db "Cannot load from media.", 13, 10, 0

Sector   db 0
Cylinder db 0
Head     db 0

times 510-($-$$) db 0
dw 0AA55h
Works but, err, doesn't work.
What I mean is, gives no errors, still 'runnin in bogus memory.

Notice I took your advice and added messages among other nifty features. This time all the code is my own, not a single copy+paste :).