125 lines
1.7 KiB
NASM
125 lines
1.7 KiB
NASM
CPU 8086
|
|
ORG 0x500
|
|
|
|
jmp start
|
|
|
|
;Interrupt handler
|
|
;Return to the shell
|
|
int0x20:
|
|
jmp shell
|
|
;Input and output
|
|
int0x21:
|
|
cmp ah, 0x0
|
|
je printstr
|
|
cmp ah, 0x1
|
|
je readstr
|
|
cmp ah, 0x2
|
|
je println
|
|
cmp ah, 0x3
|
|
je readln
|
|
iret
|
|
;Disk operations
|
|
int0x22:
|
|
cmp ah, 0x0
|
|
je loadf
|
|
;To do: savef
|
|
iret
|
|
|
|
;System calls
|
|
%include "PRINTSTR.INC"
|
|
%include "READSTR.INC"
|
|
%include "PRINTLN.INC"
|
|
%include "READLN.INC"
|
|
%include "LOADF.INC"
|
|
|
|
start:
|
|
|
|
;Set up the interrupt vectors
|
|
;Interrupt 0x20 offset
|
|
mov ax, int0x20
|
|
mov [0x80], ax
|
|
;Interrupt 0x21 offset
|
|
mov ax, int0x21
|
|
mov [0x84], ax
|
|
;Interrupt 0x22 offset
|
|
mov ax, int0x22
|
|
mov [0x88], ax
|
|
;Segments
|
|
mov ax, 0x0
|
|
mov [0x82], ax
|
|
mov [0x86], ax
|
|
mov [0x8a], ax
|
|
|
|
;Print a welcome message
|
|
mov si, welcomemsg
|
|
mov ah, 0x2
|
|
int 0x21
|
|
|
|
shell:
|
|
|
|
;Re-set the stack
|
|
cli
|
|
mov sp, 0x0
|
|
sti
|
|
|
|
;Prompt for and read a command
|
|
;Print a prompt
|
|
mov si, prompt
|
|
mov ah, 0x0
|
|
int 0x21
|
|
;Read
|
|
mov di, input
|
|
mov al, 0x4e
|
|
mov ah, 0x3
|
|
int 0x21
|
|
|
|
;Load an execute the program
|
|
;Check for an empty command
|
|
cmp byte [input], 0x0
|
|
jz shell
|
|
;Load
|
|
mov bx, 0x2000
|
|
mov si, input
|
|
mov ah, 0x0
|
|
int 0x22
|
|
;Check for errors
|
|
cmp al, 0x1
|
|
je error
|
|
;Execute
|
|
jmp 0x2000
|
|
|
|
;Print an error message and return to the shell
|
|
error:
|
|
mov bh, 0x0
|
|
mov ah, 0x3
|
|
int 0x10
|
|
dec dh
|
|
mov ah, 0x2
|
|
int 0x10
|
|
mov si, errormsg
|
|
mov ah, 0x2
|
|
int 0x21
|
|
jmp shell
|
|
|
|
;Data
|
|
welcomemsg db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0
|
|
prompt db "> ", 0x0
|
|
errormsg db "Unknown command", 0x0
|
|
input times 0x4e db 0x0
|
|
crlf db 0xd, 0xa, 0x0
|
|
|
|
;Print a CRLF
|
|
printcrlf:
|
|
;Store the initial registers in the stack
|
|
push si
|
|
;Print the CRLF
|
|
mov si, crlf
|
|
mov ah, 0x0
|
|
int 0x21
|
|
;Load the initial registers from the stack
|
|
pop si
|
|
ret
|
|
|
|
;File system buffer
|
|
buffer:
|