|
|
@@ -47,8 +47,6 @@ _start:
|
|
|
|
|
|
call load_ksetup
|
|
|
|
|
|
-.die: jmp .die
|
|
|
-
|
|
|
.set_vga:
|
|
|
; get mode info
|
|
|
mov ax, 0x4f01
|
|
|
@@ -57,7 +55,7 @@ _start:
|
|
|
|
|
|
int 0x10
|
|
|
|
|
|
-die: jc die
|
|
|
+ jc die
|
|
|
|
|
|
mov al,[es:di]
|
|
|
mov [VMODE], al
|
|
|
@@ -151,9 +149,9 @@ INODE_SIZE equ 32
|
|
|
FIRSTDATABLOCK equ 76
|
|
|
NEXT_INODE equ 80
|
|
|
|
|
|
-ZERO equ 84
|
|
|
+ZERO equ 84
|
|
|
|
|
|
-DENTRY_NAME equ 4
|
|
|
+DENTRY_NAME equ 4
|
|
|
|
|
|
|
|
|
load_ksetup:
|
|
|
@@ -183,22 +181,181 @@ load_ksetup:
|
|
|
add si, 128
|
|
|
cmp si, 0x6000
|
|
|
|
|
|
- je not_found
|
|
|
+ jae load_failed
|
|
|
jmp .cmp_loop
|
|
|
|
|
|
found:
|
|
|
mov di, found_msg
|
|
|
call print
|
|
|
|
|
|
-.die: hlt
|
|
|
- jmp .die
|
|
|
+.get_inode:
|
|
|
+ ; store its inode number in te eax
|
|
|
+ ; 6: the length of file name
|
|
|
+
|
|
|
+ mov ecx, [si - 6 - DENTRY_NAME]
|
|
|
+
|
|
|
+ ; and then read this inode (only read the first block of inodes)
|
|
|
+ mov eax, [0x7e00 + INODES_BN]
|
|
|
+ mov bx, 0x5000
|
|
|
+
|
|
|
+ call read_block
|
|
|
+
|
|
|
+ ; back up the inode nr, for .search_bim
|
|
|
+ mov edx, ecx
|
|
|
+
|
|
|
+ ; * sizeof(struct inode)
|
|
|
+ shl cx, 5
|
|
|
+
|
|
|
+ mov si, 0x5000
|
|
|
+ add si, cx
|
|
|
+
|
|
|
+ ; and get its size
|
|
|
+
|
|
|
+INO_INODE equ 0
|
|
|
+INO_PINODE equ 4
|
|
|
+INO_ACCESS equ 8
|
|
|
+INO_BLOCKSNR equ 9
|
|
|
+INO_UPSIZE equ 13
|
|
|
+INO_CTIME equ 17
|
|
|
+INO_WTIME equ 21
|
|
|
+INO_NLINKS equ 25
|
|
|
+INO_UID equ 26
|
|
|
+INO_GID equ 28
|
|
|
+INO_EACCESS equ 30
|
|
|
+
|
|
|
+ mov eax, [si + INO_BLOCKSNR]
|
|
|
+
|
|
|
+ cmp dword [si + INO_UPSIZE], 0
|
|
|
+
|
|
|
+ ; upsize is zero, so eax is blocks we need.
|
|
|
+ je .read_ksetup
|
|
|
+
|
|
|
+ ; okay, this is enough
|
|
|
+ inc eax
|
|
|
+
|
|
|
+.read_ksetup:
|
|
|
+ ; find in the bim (only first block, too)
|
|
|
+ ; first read the first block of bim to 0x5000
|
|
|
+
|
|
|
+ ; blocks need is in the eax, save it
|
|
|
+
|
|
|
+BIM_INODE equ 0
|
|
|
+BIM_THBLOCK equ 4
|
|
|
+
|
|
|
+ mov ecx, eax
|
|
|
+
|
|
|
+ mov eax, [0x7e00 + BIM_BN]
|
|
|
+ mov bx, 0x5000
|
|
|
+
|
|
|
+ call read_block
|
|
|
+
|
|
|
+ ; and start search
|
|
|
+ mov si, 0x5000
|
|
|
+
|
|
|
+ mov eax, ecx
|
|
|
+ xor ecx, ecx
|
|
|
+ ; the to address
|
|
|
+
|
|
|
+ ; and this is the address of kernel
|
|
|
+ xor bx, bx
|
|
|
+
|
|
|
+ push eax
|
|
|
+
|
|
|
+ mov ax, 0x0900
|
|
|
+ mov es, ax
|
|
|
+
|
|
|
+ pop eax
|
|
|
+
|
|
|
+.search_bim:
|
|
|
+ cmp ecx, eax
|
|
|
+
|
|
|
+ ; ecx is the blocks we loaded (also bim->th_block), eax is the blocks of this file
|
|
|
+ je .load_done
|
|
|
+
|
|
|
+ ; the inode of this file is edx
|
|
|
+ cmp edx, [si]
|
|
|
+
|
|
|
+ ; not match, search again
|
|
|
+ jne .search_again
|
|
|
+
|
|
|
+ cmp ecx, [si + BIM_THBLOCK]
|
|
|
+ jne .search_again
|
|
|
+
|
|
|
+
|
|
|
+.load_file:
|
|
|
+ ; only one block, and coutinue search
|
|
|
+ ; the block is the index of si (base is 0x5000), [si] is the inode
|
|
|
+
|
|
|
+ ; not this!!! loader must uses 32-bit registers, so we should save/restore
|
|
|
+ ; them in 32-bits
|
|
|
+ ; pushaw
|
|
|
+
|
|
|
+ push eax
|
|
|
+ push ecx
|
|
|
+ push edx
|
|
|
+ push ebx
|
|
|
+
|
|
|
+ push esp
|
|
|
+ push ebp
|
|
|
+ push esi
|
|
|
+ push edi
|
|
|
+
|
|
|
+ ; first get the block nr
|
|
|
+ xor eax, eax
|
|
|
+ mov ax, si
|
|
|
+
|
|
|
+ ; - base
|
|
|
+ sub eax, 0x5000
|
|
|
+
|
|
|
+ ; / 8, get the index
|
|
|
+ shr eax, 3
|
|
|
+
|
|
|
+ ; and += first_data_block, because bim start at this.
|
|
|
+ add eax, [0x7e00 + FIRSTDATABLOCK]
|
|
|
+
|
|
|
+ ; now eax is the real block nr of this file
|
|
|
+
|
|
|
+ ; read it!
|
|
|
+ ; bx is the address, we don't need change
|
|
|
+ call read_block
|
|
|
+
|
|
|
+ pop edi
|
|
|
+ pop esi
|
|
|
+ pop ebp
|
|
|
+ pop esp
|
|
|
+
|
|
|
+ pop ebx
|
|
|
+ pop edx
|
|
|
+ pop ecx
|
|
|
+ pop eax
|
|
|
+
|
|
|
+ add bx, 4096
|
|
|
+ inc ecx
|
|
|
+
|
|
|
+ add si, 8
|
|
|
+
|
|
|
+ jmp .search_bim
|
|
|
+
|
|
|
+.search_again:
|
|
|
+ ; the size of a bim entry
|
|
|
+ add si, 8
|
|
|
+ cmp si, 0x6000
|
|
|
+
|
|
|
+ jae load_failed
|
|
|
+ jmp .search_bim
|
|
|
+
|
|
|
+.load_done:
|
|
|
+ mov di, load_done_msg
|
|
|
+ call print
|
|
|
+
|
|
|
+ ret
|
|
|
|
|
|
-not_found:
|
|
|
- mov di, not_found_msg
|
|
|
+load_failed:
|
|
|
+ mov di, load_failed_msg
|
|
|
call print
|
|
|
|
|
|
-.die: hlt
|
|
|
- jmp .die
|
|
|
+die: hlt
|
|
|
+ jmp die
|
|
|
|
|
|
read_block:
|
|
|
push ax
|
|
|
@@ -210,13 +367,16 @@ read_block:
|
|
|
|
|
|
.loop:
|
|
|
call read_lba
|
|
|
- jc read_failed
|
|
|
|
|
|
inc eax
|
|
|
dec cx
|
|
|
|
|
|
add bx, 512
|
|
|
+ cmp bx, 0
|
|
|
+
|
|
|
+ je .go_on_es
|
|
|
|
|
|
+.cont:
|
|
|
cmp cx, 0
|
|
|
jne .loop
|
|
|
|
|
|
@@ -225,8 +385,29 @@ read_block:
|
|
|
|
|
|
ret
|
|
|
|
|
|
+.go_on_es:
|
|
|
+ ; update the es, and continue
|
|
|
+ push ax
|
|
|
+
|
|
|
+ mov ax, es
|
|
|
+ add ax, 512 / 16
|
|
|
+ mov es, ax
|
|
|
+
|
|
|
+ pop ax
|
|
|
+
|
|
|
+ jmp .cont
|
|
|
+
|
|
|
+
|
|
|
read_lba:
|
|
|
- pushaw
|
|
|
+ push eax
|
|
|
+ push ecx
|
|
|
+ push edx
|
|
|
+ push ebx
|
|
|
+
|
|
|
+ push esp
|
|
|
+ push ebp
|
|
|
+ push esi
|
|
|
+ push edi
|
|
|
|
|
|
push dword 0x0000
|
|
|
push dword eax
|
|
|
@@ -249,7 +430,17 @@ read_lba:
|
|
|
|
|
|
add sp, 16
|
|
|
|
|
|
- popaw
|
|
|
+ pop edi
|
|
|
+ pop esi
|
|
|
+ pop ebp
|
|
|
+ pop esp
|
|
|
+
|
|
|
+ pop ebx
|
|
|
+ pop edx
|
|
|
+ pop ecx
|
|
|
+ pop eax
|
|
|
+
|
|
|
+ jc read_failed
|
|
|
|
|
|
ret
|
|
|
|
|
|
@@ -257,7 +448,6 @@ read_failed:
|
|
|
mov di, read_failed_msg
|
|
|
call print
|
|
|
|
|
|
-.die: hlt
|
|
|
jmp die
|
|
|
|
|
|
|
|
|
@@ -372,14 +562,15 @@ init_prot:
|
|
|
|
|
|
; okay! now set segment registers and init long mode
|
|
|
|
|
|
- jmp code64:0x8000
|
|
|
+ jmp code64:0x9000
|
|
|
|
|
|
msg: db "welcome to XNIX Loader. ", 0x0d, 0x0a, 0x00
|
|
|
read_failed_msg: db "fatal: read disk failed. ", 0x0d, 0x0a, 0x00
|
|
|
fname: db "ksetup", 0x00
|
|
|
|
|
|
found_msg: db "found ksetup in the root. ", 0x0d, 0x0a, 0x00
|
|
|
-not_found_msg: db "ksetup not found. ", 0x0d, 0x0a, 0x00
|
|
|
+load_failed_msg: db "failed when trying to load ksetup. ", 0x0d, 0x0a, 0x00
|
|
|
+load_done_msg: db "load ksetup done. ", 0x0d, 0x0a, 0x00
|
|
|
|
|
|
alignb 16
|
|
|
|