Move system calls to interrupts and rename the main system loop to shell.

This commit is contained in:
CrazyEttin 2021-06-18 21:59:45 +03:00
parent fc3a0bbbe9
commit 59d9c7e89d
11 changed files with 84 additions and 33 deletions

View File

@ -5,7 +5,8 @@ echo:
;Read a string
mov di, buffer
mov al, 0xff
call readln
mov ah, 0x3
int 0x21
;Check for an empty string
cmp byte [buffer], 0x0
@ -13,7 +14,8 @@ je .done
;Print the string
mov si, buffer
call println
mov ah, 0x2
int 0x21
.done:
ret

View File

@ -5,7 +5,8 @@ fileify:
;Read a string
mov di, buffer
mov al, 0xff
call readln
mov ah, 0x3
int 0x21
;Set SI and DI
mov si, buffer
@ -50,13 +51,15 @@ jmp .extloop
.error:
pop ax
mov si, .errormsg
call println
mov ah, 0x2
int 0x21
jmp .done
.print:
pop ax
mov si, .file
call println
mov ah, 0x2
int 0x21
.done:
ret

View File

@ -3,8 +3,9 @@
hello:
mov si, .hello
call println
mov ah, 0x2
int 0x21
ret
.hello db "Hello world!", 0x0
.hello db "Hello world!", 0x0

View File

@ -3,7 +3,8 @@
help:
mov si, .help
call println
mov ah, 0x2
int 0x21
ret

View File

@ -12,7 +12,8 @@ mov [.ascii], al
;Print the prefix
mov si, .prefix
call printstr
mov ah, 0x0
int 0x21
;Convert the scancode to a hex string
mov al, [.scan]
@ -27,7 +28,8 @@ call .byte2hex
;Print the keycode
mov si, .keycode
call println
mov ah, 0x2
int 0x21
ret

View File

@ -7,7 +7,8 @@ push si
;Print the newline
mov si, .newline
call printstr
mov ah, 0x0
int 0x21
;Load the initial registers from the stack
pop si

View File

@ -3,9 +3,10 @@
println:
;Print the string
call printstr
mov ah, 0x0
int 0x21
;Print a newline
call newline
ret
iret

View File

@ -23,4 +23,4 @@ jmp .loop
;Load the initial registers from the stack
pop ax
ret
iret

View File

@ -3,9 +3,10 @@
readln:
;Read the string
call readstr
mov ah, 0x1
int 0x21
;Print a newline
call newline
ret
iret

View File

@ -129,7 +129,7 @@ pop cx
pop bx
pop ax
ret
iret
;Move the cursor forward

View File

@ -3,14 +3,33 @@ ORG 0x500
jmp start
;Calls
%include "CMPSTR.INC"
;Interrupt handler
int0x20:
jmp shell
int0x21:
cmp ah, 0x0
je printstr
cmp ah, 0x1
je readstr
cmp ah, 0x2
je println
cmp ah, 0x3
je readln
iret
int0x22:
;To do: loading and saving files
iret
;System calls
%include "PRINTSTR.INC"
%include "READSTR.INC"
%include "NEWLINE.INC"
%include "PRINTLN.INC"
%include "READLN.INC"
;Internal calls
%include "CMPSTR.INC"
%include "NEWLINE.INC"
;Commands
%include "ECHO.INC"
%include "FILEIFY.INC"
@ -20,42 +39,61 @@ jmp start
start:
;Setup
;Set up the stack
cli
mov sp, stack
add sp, 0x100
sti
;Set up the interrupt vectors
;Interrupt 0x20
mov ax, int0x20
mov [0x80], ax
mov ax, 0x0
mov [0x82], ax
;Interrupt 0x21
mov ax, int0x21
mov [0x84], ax
mov ax, 0x0
mov [0x86], ax
;Interrupt 0x22
mov ax, int0x22
mov [0x88], ax
mov ax, 0x0
mov [0x8a], ax
;Print a welcome message
mov si, welcomemsg
call println
mov ah, 0x2
int 0x21
loop:
shell:
;Prompt for and read a command
;Print a prompt
mov si, prompt
call printstr
mov ah, 0x0
int 0x21
;Read a command
mov di, buffer
mov al, 0xff
call readln
mov ah, 0x3
int 0x21
;Identify and execute the command
exec:
;Check for no command
cmp byte [buffer], 0x0
je loop
je shell
.echo:
;Check
mov si, buffer
mov di, cmd.echo
call cmpstr
jnc .fileify
;jnc .hello
;Execute
call echo
jmp loop
jmp shell
.fileify:
;Check
mov si, buffer
@ -64,7 +102,7 @@ call cmpstr
jnc .hello
;Execute
call fileify
jmp loop
jmp shell
.hello:
;Check
mov si, buffer
@ -73,7 +111,7 @@ call cmpstr
jnc .help
;Execute
call hello
jmp loop
jmp shell
.help:
;Check
mov si, buffer
@ -82,7 +120,7 @@ call cmpstr
jnc .keycode
;Execute
call help
jmp loop
jmp shell
.keycode:
;Check
mov si, buffer
@ -91,11 +129,12 @@ call cmpstr
jnc .error
;Execute
call keycode
jmp loop
jmp shell
.error:
mov si, errormsg
call println
jmp loop
mov ah, 0x2
int 0x21
jmp shell
welcomemsg db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0