section .text ; Set up segment registers mov sp, STACK_SEGMENT mov ss, sp mov sp, STACK_SIZE push word SCREEN_SEGMENT pop es push word 0 pop ds ; Install syscall handler mov [4 * SYSCALL_INTERRUPT], word syscallHandler mov [4 * SYSCALL_INTERRUPT + 2], cs cli ; Install timer handler mov [4 * (TIMER_IRQ + 8)], word timerHandler mov [4 * (TIMER_IRQ + 8) + 2], cs ; Install keyboard handler mov [4 * (KEYBOARD_IRQ + 8)], word keyboardHandler mov [4 * (KEYBOARD_IRQ + 8) + 2], cs sti ; Install FDC Handler mov [4 * (FDC_IRQ + 8)], word fdcIRQHandler mov [4 * (FDC_IRQ + 8) + 2], cs push cs pop ds ; Blank screen mov ax, SYSCALL_CLEAR_SCREEN int SYSCALL_INTERRUPT ; Say hello push word welcomeMessage_size push word welcomeMessage mov ax, SYSCALL_PRINT_STRING int SYSCALL_INTERRUPT add sp, 4 mov ax, SYSCALL_NEWLINE int SYSCALL_INTERRUPT ; Read data push ds pop ax shr ax, 12 push ax push ds pop ax shl ax, 4 add ax, dataBuffer push ax push word 1 push word 18 mov ax, SYSCALL_FLOPPY_READ int SYSCALL_INTERRUPT add sp, 8 ; Print data push word 14 push word dataBuffer mov ax, SYSCALL_PRINT_STRING int SYSCALL_INTERRUPT add sp, 4 mov ax, SYSCALL_NEWLINE int SYSCALL_INTERRUPT ; Read more data push ds pop ax shr ax, 12 push ax push ds pop ax shl ax, 4 add ax, dataBuffer push ax push word 1 push word 36 mov ax, SYSCALL_FLOPPY_READ int SYSCALL_INTERRUPT add sp, 8 ; And print it push word 10 push word dataBuffer mov ax, SYSCALL_PRINT_STRING int SYSCALL_INTERRUPT add sp, 4 mov ax, SYSCALL_NEWLINE int SYSCALL_INTERRUPT ; Say goodbye push word goodbyeMessage_size push word goodbyeMessage mov ax, SYSCALL_PRINT_STRING int SYSCALL_INTERRUPT add sp, 4 ; Hang jmp $ ;;;;;;;;;;;;; ; Functions ; ;;;;;;;;;;;;; bin2hex: push bp mov bp, sp mov ah, [bp + 4] xor al, al shr ax, 4 add ah, '0' cmp ah, '9' jbe .next add ah, 'a' - '9' - 1 .next: shr al, 4 add al, '0' cmp al, '9' jbe .end add al, 'a' - '9' - 1 .end: pop bp ret ;;;;;;;;;;;;;;;;;;;;;; ; Interrupt Handlers ; ;;;;;;;;;;;;;;;;;;;;;; ; ; Dispatch system calls ; syscallHandler: sti cmp ax, SYSCALL_INVALID jb .ok xor ax, ax ; Invoke unknown syscall handler .ok: mov bx, ax shl bx, 1 jmp near [cs:syscallTable + bx] ;;;;;;;; ; Data ; ;;;;;;;; section .data welcomeMessage db "Simple Kernel" welcomeMessage_size EQU $ - welcomeMessage goodbyeMessage db "All done!" goodbyeMessage_size EQU $ - goodbyeMessage doneMsg db "done" doneMsg_size EQU $ - doneMsg ;;;;;;;;;;;;;;;;;;;;;; ; Uninitialized data ; ;;;;;;;;;;;;;;;;;;;;;; section .bss _hex resb 2 dataBuffer resb 512 ;;;;;;;;;;; ; Modules ; ;;;;;;;;;;; %include "syscall.inc" %include "console.inc" %include "timer.inc" %include "dma.inc" %include "floppy.inc" ;;;;;;;;;;;;; ; Constants ; ;;;;;;;;;;;;; STACK_SEGMENT EQU 09000h ; Top of conventional memory STACK_SIZE EQU 0ffffh ; 64K - 1 bytes of stack SCREEN_SEGMENT EQU 0b800h SCREEN_COLS EQU 80 SCREEN_ROWS EQU 25