I am very interrested in OS-Developing and I have found this forum.
I have read a lot of Tutorials and now I am trying to write my bootsector but I have a problem.
The bootsector should enable the A20 Gate and load the kernel from a FAT12 Flobby.
Now I want to read the FAT-Table - I load it into the RAM but how can I read it from the RAM? And I have another problem, BOCHS show never the 'X' in hang.
Here is the code:
Code: Select all
[BITS 16]
[ORG 0]
%include "fat12bios.inc"
JMP 0x07C0:start
start:
CLI
MOV AX,CS
MOV DS,AX
MOV ES,AX
MOV SS,AX
MOV SP,0xFFFF
a20:
;...
STI
lodfat: ;LOAD THE FAT TABEL
MOV CX,[FATSize]
lodfattbl_loop:
MOV AX,[RsvdSecCnt] ;FAT_Start = RsvdSecCnt
ADD AX,[FATSize] ;Wenn man den Zweiten Sektor einlesem muss, muss...
SUB AX,CX ;...man diese Rechnung rechnen
MOV BX,0x0
CALL rseclba
LOOP lodfattbl_loop
;LOAD THE ROOT-ENTRY
MOV AX,32 ;(32*RootEntCnt + BytesPerSec–1) / BytesPerSec
MUL BYTE [RootEntCnt]
ADD AX,[BytesPerSec]
DEC AX
XOR DX,DX
DIV WORD [BytesPerSec]
MOV CX,AX
MOV DX,CX
lodroottbl_loop:
;Root-Directory-Startsektor = (FATSize * NumFATs) + ResvdSecCnt
MOV AX,[FATSize]
MUL BYTE [NumFATs]
ADD AX,[RsvdSecCnt]
;+Größe
ADD AX,DX
;-Noch zu erledigen
SUB AX,CX
MOV BX,0x0
CALL rseclba
LOOP lodroottbl_loop
hang:
MOV AH,0x0E
MOV AL,'X'
MOV BX,0
INT 0x10
JMP $
calls:
;Wartet auf den Tastatur-Controller
cwait:
IN AL,0x64
TEST AL,00000010b
JNZ cwait
RET
;Wartet auf den Chip
chipwait:
IN AL,0x64
TEST AL,00000001b
JZ chipwait
RET
;Liest einen Sektor über die LBA
;AX -> LBA
;ES:BX -> Segment:Offset
;LOAD A SECTOR AND CONVERTS LBA->CHS
rseclba:
PUSHA
PUSH BX
;Cylinder (LBA/SecPerTrack)/NumHeads
PUSH AX ;LBA sichern
XOR DX,DX
DIV WORD [SecPerTrack] ;DX:AX/SecPerTrack -> AX
XOR DX,DX
DIV WORD [NumHeads] ;DX:AX/NumHeads -> AX
POP BX ;LBA zurück
PUSH AX ;Cylinder sichern
XCHG AX,BX
;Head (LBA/SectorsPerTrack)%NumHeads
PUSH AX ;LBA sichern
XOR DX,DX
DIV WORD [SecPerTrack] ;DX:AX/SecPerTRack -> AX
XOR DX,DX
DIV WORD [NumHeads] ;DX:AX%NumHeads -> DX
POP AX ;LBA zurpck
PUSH DX ;Head sichern
;Sector (LBA%SectorsPerTrack)+1
XOR DX,DX
DIV WORD [SecPerTrack] ;DX:AX%SecPerTRack -> DX
INC DX
PUSH DX
read:
MOV AH,0x02 ;Funktion
MOV AL,1 ;Sektoren
POP CX ;Sektornr.
POP DX ;Head
SHR DX,4
MOV DL,0 ;Laufwerk
POP BX ;Cylinter - Temp
MOV CH,BL ;Cylinder
POP BX ;Offset
INT 0x13
JC read;Wenn Fehler (CF=1)
POPA
RET
vars:
TIMES 510-($-$$) DB 0
DW 0xAA55