This will be crucial for stage 3 loading the kernel, because we will need to
relocate each cluster to 0x100000 (or somewhere after that) manually, and we
can't just do that in the driver as it's also used by the VBR which does not run
in unreal mode.
; NOTE: Cluster chain might be the root directory or a file.
read_cluster_chain:
push eax
; NOTE: Cluster chain might be the root directory or a file.
read_cluster_chain:
push eax
+ push es
+ push di
+ .loop:
+ call read_cluster
+ cmp eax, 0xffffff7
+ jl .loop
+ pop di
+ pop es
+ pop eax
+ ret
+
+; eax - cluster number
+; es:di - where to load the cluster (incremented automatically)
+; RETURN: eax - next cluster number
+read_cluster:
push ebx
push ecx
push edx
push ebx
push ecx
push edx
.loop:
; get the first sector of the cluster to read
push eax
.loop:
; get the first sector of the cluster to read
push eax
; reminder for myself: EAX is FAT sector number, (E)BX is offset into FAT sector
; load the FAT sector we're looking for
; reminder for myself: EAX is FAT sector number, (E)BX is offset into FAT sector
; load the FAT sector we're looking for
push di
push ebx ; offset
push es ; we want to read at 0:1000, not STAGE3_SEGMENT:1000
push di
push ebx ; offset
push es ; we want to read at 0:1000, not STAGE3_SEGMENT:1000
pop ebx ; pop FAT offset back into EBX for cmp
mov eax, [di+bx]
pop di
pop ebx ; pop FAT offset back into EBX for cmp
mov eax, [di+bx]
pop di
- pop cx
- cmp eax, 0xffffff7
- jl .loop ; if cluster number is lower than the defective cluster value, we're not done
- ; TODO: perhaps check is it equal defective and error out in that case?
-.done:
ret
; es:di - where to load the sector(s)
ret
; es:di - where to load the sector(s)