Code: Select all
typedef struct table {
unsigned char filename[8];
unsigned char extension[3];
unsigned char _reserved;
unsigned short start_sector;
unsigned short sector_count;
} table_t;
NOTE: I rewrote it in NASM for first and second stage boot loaders. The problem lies in load_file.
How do I rewrite my load_file function to parse 7 sectors of 16 bytes each?
Code: Select all
; =========================================================
; FILE.INC - File table and file loading.
; Date: 03/12/2020
; Author: Philip R. Simonson
; =========================================================
; no parameters
load_table:
mov ax, root_segment
mov es, ax
mov ax, 16
mov bx, word [iRootSize]
mul bx
mov bx, word [iSectSize]
xor dx, dx
div bx
mov cx, ax
mov ax, 1
xor bx, bx
.loop:
push ax
push bx
push cx
call read_sector
mov si, op_progress
call print_string
pop cx
pop bx
add bx, [iSectSize]
pop ax
inc ax
loopnz .loop
ret
; read file from disk.
; ===========================================
; ax = loaded table segment
; [es:bx] = location to read data to.
; cx = how many sectors to read.
; ===========================================
read_file:
push ax
push bx
push cx
call read_sector
pop cx
pop bx
add bx, [iSectSize]
pop ax
inc ax
loopnz read_file
ret
; call load table before this function.
; ===========================================
; ax = loaded table segment
; si = filename string
; ===========================================
load_file:
mov ax, root_segment
mov es, ax
xor bx, bx
.check:
mov al, [es:bx]
cmp al, 0x0
je .error
mov cx, 11
lea di, [es:bx]
mov si, filename
rep cmpsb
je .match
add bx, 16
jmp short .check
.match:
mov ax, word [es:bx+0x0c]
mov cx, word [es:bx+0x0e]
mov bx, load_segment
mov es, bx
xor bx, bx
call read_file
mov si, op_success
call print_string
mov ax, load_segment
mov ds, ax
mov es, ax
jmp load_segment:0x0000
ret
.error:
mov si, op_notfile
call print_string
ret
Here is the 7 sectors of my simple file system:
Code: Select all
00000200 73 74 61 67 65 32 20 20 62 69 6e 00 08 00 02 00 |stage2 bin.....|
00000210 6b 65 72 6e 65 6c 20 20 62 69 6e 00 0a 00 10 00 |kernel bin.....|
00000220 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001000
- Phil