;#####################################################
; volumen boot record
;´der 1. partition, enthalten im mbr (0)
.equ mbr_offset = 0x0000
.equ vbr_address_offset = 0x01c6
;#####################################################
; boot sector
.equ bs_jmpboot = 0x00 ; char[3]
.equ bs_oemname = 0x03 ; char[8]
.equ bpb_bytespersec = 0x0b ; int
.equ bpb_secperclus = 0x0d ; char
.equ bpb_rsvdseccnt = 0x0e ; int
.equ bpb_numfats = 0x10 ; char
.equ bpb_rootentcnt = 0x11 ; int
.equ bpb_totsec16 = 0x13 ; int
.equ bpb_media = 0x15 ; char
.equ bpb_fatsz16 = 0x16 ; int
.equ bpb_secpertrk = 0x18 ; int
.equ bpb_numheads = 0x1a ; int
.equ bpb_hiddsec = 0x1c ; longint
.equ bpb_totsec32 = 0x20 ; longint
; fat12 and fat16
.equ bs_drivenumber = 0x24 ; int
.equ bs_reserved1 = 0x26 ; char
.equ bs_bootsig = 0x27 ; longint
.equ bs_volid = 0x2b ; char[11]
.equ bs_vollab = 0x36 ; char[8]
.equ bs_filsystype = 0x3e ; char[448]
.equ bs_exemarker = 0x1fe ; char[2]
;#####################################################
; ram
.equ ram_vbr_address = 0x150 ; word
.equ ram_fat_address = 0x152 ; word
.equ ram_root_address = 0x154 ; word
.equ ram_data_address = 0x156 ; word
.equ ram_sec_per_clus = 0x158 ; byte
.equ ram_reserved_sectors = 0x159 ; word
.equ ram_max_root_dir_ent = 0x15b ; word
fat_load_info:
; where is the VBR?
sts ram_address, null
sts ram_address+1, null
sts ram_address+2, null
rcall mmc_read_sector ; read mbr (offset = 0)
movi ram_vbr_address, ram_data + vbr_address_offset
movi ram_vbr_address+1, ram_data + vbr_address_offset+1
; where is the FAT?
movi ram_address, ram_vbr_address
movi ram_address+1, ram_vbr_address+1
sts ram_address+2, null
rcall mmc_read_sector ; read vbr
lds temp2, ram_vbr_address
lds temp3, ram_vbr_address+1
lds temp4, ram_data + bpb_rsvdseccnt
lds temp5, ram_data + bpb_rsvdseccnt+1
; reserved sectors + partition's start = fat
add temp2, temp4
adc temp3, temp5
sts ram_fat_address, temp2
sts ram_fat_address+1, temp3
; where is the ROOT DIRECTORY?
lds temp4, ram_data + bpb_fatsz16
lds temp5, ram_data + bpb_fatsz16+1
; fat address + (sec per fat *2) = root
lsl temp4
rol temp5
add temp2, temp4
adc temp3, temp5
sts ram_root_address, temp2
sts ram_root_address+1, temp3
; where begins the DATA?
; root + (max root dir ent * 32)/bytes per sec
; ==> root + (512*32)/512 = root + 32
ldi temp1, 32
add temp2, temp1
adc temp3, null
sts ram_data_address, temp2
sts ram_data_address+1, temp3
ret
Das ist alles an die Source von Ulrich Radig angelehnt, bzw. anfangs.
Da ich nicht immer verstanden hab, wasser da (in C) macht, hab ich
nochmal neu angefangen, selbst durchdachter.
Also: MBR ist Sektor 0.
Den lad ich mir.
Dann schau ich bei Offset 1BE (Anfang Partitionsinfo Part. 0) + 8 = 1C6
= Sektors between...
Die werden bei mir direkt als VBR-Adresse abgelegt.
Dann les ich den VBR aus (mit der vorher geholten Adresse).
Die FAT fängt dann an: VBR + Reserved_Sectors. Also lad ich mit die
Reserved Sectors udn addier die. Bei meiner 32er sinds nur 2.
Dann lad ich (immernoch aus dem VBR) sec per fat, sollte ich mal
nachschaun, was das ist. Wohl so wie Rufus das meint. Die x2 und auf
die FAT-Adresse drauf, das ergibt den Root.
Dannnn noch schaun, wieviel im Root maximal drin sein kann, sind
normalerweise 512 Einträge, das rechne ich auch wärend des kompilierens
(sonst halt aussem VBR holen) und jeder Eintrag hat 32byte:
512 * 32 / 512... 512 kürzt sich raus, bleiben 32 übrig.
32Sektoren Root-Directory, wird addiert. Da fangen deine Daten an.
dave