66 lines
1.3 KiB
NASM
66 lines
1.3 KiB
NASM
; TODO: Read FAT32 filesystem and load raw binary from path nightloader/stage_2.bin
|
|
|
|
FAT32_HEADER_ROOT_DIRECTORY_FAT_INDEX equ 0x2c
|
|
|
|
find_stage_2:
|
|
|
|
; Set extra-segment to the address where the Stage 2 - partition is located.
|
|
mov bx, 0x2000
|
|
mov es, bx
|
|
mov ds, bx
|
|
|
|
|
|
|
|
; PART 1: FIND THE STAGE 2 - FILE'S OFFSET IN THE PARTITION
|
|
|
|
; Read cluster size (in bytes) into dx
|
|
mov bx, 0x000b
|
|
mov ax, [bx]
|
|
add bx, 2
|
|
mov di, [bx]
|
|
mul di
|
|
mov dx, ax
|
|
|
|
; Read the root directory's first cluster's index into si:di (si: upper, di: lower)
|
|
mov bx, FAT32_HEADER_ROOT_DIRECTORY_FAT_INDEX
|
|
mov di, [bx]
|
|
add bx, 2
|
|
mov si, [bx]
|
|
|
|
push si
|
|
push di
|
|
|
|
; Put address of root directory into ds:bx
|
|
|
|
; Part 1: Get the overflow
|
|
; mov bx,
|
|
|
|
|
|
|
|
|
|
; Loop through the root directory's entries
|
|
.root_directory_loop: ; Loops through all the root directory's clusters
|
|
|
|
mov di, [bx]
|
|
add bx, 2
|
|
mov si, [bx]
|
|
|
|
|
|
|
|
; Test for the root directory's "Last Cluster" - marker.
|
|
mov ax, [bx]
|
|
; cmp
|
|
jmp .root_directory_loop
|
|
|
|
; Arguments:
|
|
; bx:
|
|
; Return Values:
|
|
; ax: The index of the FAT-entry in which the searched file was found.
|
|
find_file_in_directory:
|
|
|
|
|
|
|
|
|
|
|
|
|