Implement file descriptor table and CON as file descriptor

This commit is contained in:
Nero 2020-06-28 19:00:49 +02:00
parent 65564b78af
commit f9b180ea57
3 changed files with 63 additions and 6 deletions

View File

@ -2,6 +2,8 @@
org 0x500
jmp 0:(init+0x7C00-$$)
%include "kernel/fd.asm"
%include "kernel/con.asm"
%include "inc/bpb.asm"
%include "inc/mbr.asm"
@ -217,10 +219,11 @@ intlp: movsw
stosw
loop intlp
; print banner to indicate we are booted
mov si, banner
mov ah, 9
int 0x21
; print banner
mov dx, banner
mov cx, 13
mov bx, 0
call con_write
call dnconv
mov al, dl

22
kernel/con.asm Normal file
View File

@ -0,0 +1,22 @@
con_ftab: dw con_read
dw con_write
con_read: stc
ret
con_write: push si
push bx
push cx
test cx, cx
jz .end
mov si, dx
mov ah, 0x0E
xor bx, bx
.loop: lodsb
int 0x10
loop .loop
pop cx
.end: pop bx
pop si
ret

32
kernel/fd.asm Normal file
View File

@ -0,0 +1,32 @@
%define fd_num 32
section .bss
fd_table: resb (0x10 * fd_num)
section .text
fd_to_ptr: push cx
mov cl, 4
sal bx, cl
add bx, fd_table
pop cx
ret
fd_read: cmp bx, fd_num
jnc fd_inv_hnd
call fd_to_ptr
; read ptr to ftab
mov bx, [bx]
; jmp to addr in ftab[0]
jmp [bx]
fd_write: cmp bx, fd_num
jnc fd_inv_hnd
call fd_to_ptr
mov bx, [bx]
jmp [bx+2]
fd_inv_hnd: mov ax, 6
stc
ret