2021-06-10 15:16:14 +00:00
|
|
|
CPU 8086
|
2021-06-16 15:03:31 +00:00
|
|
|
ORG 0x500
|
2021-06-10 15:16:14 +00:00
|
|
|
|
2021-05-28 06:39:26 +00:00
|
|
|
jmp start
|
|
|
|
|
2021-06-18 18:59:45 +00:00
|
|
|
;Interrupt handler
|
2021-06-20 10:48:13 +00:00
|
|
|
;Return to the shell
|
2021-06-18 18:59:45 +00:00
|
|
|
int0x20:
|
|
|
|
jmp shell
|
2021-06-20 10:48:13 +00:00
|
|
|
;Input and output
|
2021-06-18 18:59:45 +00:00
|
|
|
int0x21:
|
|
|
|
cmp ah, 0x0
|
|
|
|
je printstr
|
|
|
|
cmp ah, 0x1
|
|
|
|
je readstr
|
|
|
|
cmp ah, 0x2
|
|
|
|
je println
|
|
|
|
cmp ah, 0x3
|
|
|
|
je readln
|
|
|
|
iret
|
2021-06-20 10:48:13 +00:00
|
|
|
;Disk operations
|
2021-06-18 18:59:45 +00:00
|
|
|
int0x22:
|
2021-06-20 10:48:13 +00:00
|
|
|
cmp ah, 0x0
|
|
|
|
je loadf
|
|
|
|
;To do: savef
|
2021-06-18 18:59:45 +00:00
|
|
|
iret
|
|
|
|
|
|
|
|
;System calls
|
2021-06-06 16:56:54 +00:00
|
|
|
%include "PRINTSTR.INC"
|
|
|
|
%include "READSTR.INC"
|
2021-06-16 19:00:45 +00:00
|
|
|
%include "PRINTLN.INC"
|
2021-06-06 16:56:54 +00:00
|
|
|
%include "READLN.INC"
|
2021-06-20 10:48:13 +00:00
|
|
|
%include "LOADF.INC"
|
2021-05-28 06:39:26 +00:00
|
|
|
|
|
|
|
start:
|
2021-05-26 17:43:46 +00:00
|
|
|
|
2021-06-18 18:59:45 +00:00
|
|
|
;Set up the interrupt vectors
|
2021-06-20 10:48:13 +00:00
|
|
|
;Interrupt 0x20 offset
|
2021-06-18 18:59:45 +00:00
|
|
|
mov ax, int0x20
|
|
|
|
mov [0x80], ax
|
2021-06-20 10:48:13 +00:00
|
|
|
;Interrupt 0x21 offset
|
2021-06-18 18:59:45 +00:00
|
|
|
mov ax, int0x21
|
|
|
|
mov [0x84], ax
|
2021-06-20 10:48:13 +00:00
|
|
|
;Interrupt 0x22 offset
|
2021-06-18 18:59:45 +00:00
|
|
|
mov ax, int0x22
|
|
|
|
mov [0x88], ax
|
2021-06-20 10:48:13 +00:00
|
|
|
;Segments
|
2021-06-18 18:59:45 +00:00
|
|
|
mov ax, 0x0
|
2021-06-20 10:48:13 +00:00
|
|
|
mov [0x82], ax
|
|
|
|
mov [0x86], ax
|
2021-06-18 18:59:45 +00:00
|
|
|
mov [0x8a], ax
|
2021-06-16 15:03:31 +00:00
|
|
|
|
2021-05-30 16:12:19 +00:00
|
|
|
;Print a welcome message
|
2021-06-16 22:03:00 +00:00
|
|
|
mov si, welcomemsg
|
2021-06-18 18:59:45 +00:00
|
|
|
mov ah, 0x2
|
|
|
|
int 0x21
|
2021-05-26 14:05:49 +00:00
|
|
|
|
2021-06-18 18:59:45 +00:00
|
|
|
shell:
|
2021-05-30 16:12:19 +00:00
|
|
|
|
2021-06-21 08:39:06 +00:00
|
|
|
;Re-set the stack
|
2021-06-20 10:48:13 +00:00
|
|
|
cli
|
2021-06-21 08:39:06 +00:00
|
|
|
mov sp, 0x0
|
2021-06-20 10:48:13 +00:00
|
|
|
sti
|
|
|
|
|
2021-06-16 15:03:31 +00:00
|
|
|
;Prompt for and read a command
|
2021-05-30 16:12:19 +00:00
|
|
|
;Print a prompt
|
2021-05-26 14:05:49 +00:00
|
|
|
mov si, prompt
|
2021-06-18 18:59:45 +00:00
|
|
|
mov ah, 0x0
|
|
|
|
int 0x21
|
2021-06-20 10:48:13 +00:00
|
|
|
;Read
|
|
|
|
mov di, input
|
2021-06-21 08:39:06 +00:00
|
|
|
mov al, 0x4e
|
2021-06-18 18:59:45 +00:00
|
|
|
mov ah, 0x3
|
|
|
|
int 0x21
|
2021-05-30 16:12:19 +00:00
|
|
|
|
2021-06-20 10:48:13 +00:00
|
|
|
;Load an execute the program
|
2021-06-21 08:39:06 +00:00
|
|
|
;Check for an empty command
|
|
|
|
cmp byte [input], 0x0
|
|
|
|
jz shell
|
2021-06-20 10:48:13 +00:00
|
|
|
;Load
|
|
|
|
mov bx, 0x2000
|
|
|
|
mov si, input
|
|
|
|
mov ah, 0x0
|
|
|
|
int 0x22
|
|
|
|
;Check for errors
|
|
|
|
cmp al, 0x1
|
|
|
|
je error
|
2021-06-01 18:31:20 +00:00
|
|
|
;Execute
|
2021-06-20 10:48:13 +00:00
|
|
|
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
|
2021-06-16 22:03:00 +00:00
|
|
|
mov si, errormsg
|
2021-06-18 18:59:45 +00:00
|
|
|
mov ah, 0x2
|
|
|
|
int 0x21
|
|
|
|
jmp shell
|
2021-05-26 17:15:44 +00:00
|
|
|
|
2021-06-20 10:48:13 +00:00
|
|
|
;Data
|
2021-06-16 22:03:00 +00:00
|
|
|
welcomemsg db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0
|
2021-06-20 10:48:13 +00:00
|
|
|
prompt db "> ", 0x0
|
|
|
|
errormsg db "Unknown command", 0x0
|
2021-06-21 08:39:06 +00:00
|
|
|
input times 0x4e db 0x0
|
2021-06-20 10:48:13 +00:00
|
|
|
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
|
2021-06-16 15:03:31 +00:00
|
|
|
|
2021-06-21 08:39:06 +00:00
|
|
|
;File system buffer
|
|
|
|
buffer:
|