From 59d9c7e89da4552120bbb34d23369a49e67ff570 Mon Sep 17 00:00:00 2001 From: CrazyEttin <> Date: Fri, 18 Jun 2021 21:59:45 +0300 Subject: [PATCH] Move system calls to interrupts and rename the main system loop to shell. --- src/ECHO.INC | 6 ++-- src/FILEIFY.INC | 9 ++++-- src/HELLO.INC | 5 ++-- src/HELP.INC | 3 +- src/KEYCODE.INC | 6 ++-- src/NEWLINE.INC | 3 +- src/PRINTLN.INC | 5 ++-- src/PRINTSTR.INC | 2 +- src/READLN.INC | 5 ++-- src/READSTR.INC | 2 +- src/SYSTEM.ASM | 71 +++++++++++++++++++++++++++++++++++++----------- 11 files changed, 84 insertions(+), 33 deletions(-) diff --git a/src/ECHO.INC b/src/ECHO.INC index ab1f9bf..9a4900e 100644 --- a/src/ECHO.INC +++ b/src/ECHO.INC @@ -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 diff --git a/src/FILEIFY.INC b/src/FILEIFY.INC index 5a945f6..28a6079 100644 --- a/src/FILEIFY.INC +++ b/src/FILEIFY.INC @@ -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 diff --git a/src/HELLO.INC b/src/HELLO.INC index b3f7133..7e0c973 100644 --- a/src/HELLO.INC +++ b/src/HELLO.INC @@ -3,8 +3,9 @@ hello: mov si, .hello -call println +mov ah, 0x2 +int 0x21 ret -.hello db "Hello world!", 0x0 \ No newline at end of file +.hello db "Hello world!", 0x0 diff --git a/src/HELP.INC b/src/HELP.INC index c504ed5..c344478 100644 --- a/src/HELP.INC +++ b/src/HELP.INC @@ -3,7 +3,8 @@ help: mov si, .help -call println +mov ah, 0x2 +int 0x21 ret diff --git a/src/KEYCODE.INC b/src/KEYCODE.INC index 8306bfa..a529793 100644 --- a/src/KEYCODE.INC +++ b/src/KEYCODE.INC @@ -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 diff --git a/src/NEWLINE.INC b/src/NEWLINE.INC index e56c024..bc88c22 100644 --- a/src/NEWLINE.INC +++ b/src/NEWLINE.INC @@ -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 diff --git a/src/PRINTLN.INC b/src/PRINTLN.INC index 96b555a..399409b 100644 --- a/src/PRINTLN.INC +++ b/src/PRINTLN.INC @@ -3,9 +3,10 @@ println: ;Print the string -call printstr +mov ah, 0x0 +int 0x21 ;Print a newline call newline -ret +iret diff --git a/src/PRINTSTR.INC b/src/PRINTSTR.INC index 67c534d..b21eead 100644 --- a/src/PRINTSTR.INC +++ b/src/PRINTSTR.INC @@ -23,4 +23,4 @@ jmp .loop ;Load the initial registers from the stack pop ax -ret +iret diff --git a/src/READLN.INC b/src/READLN.INC index f97dd46..cbb0b7b 100644 --- a/src/READLN.INC +++ b/src/READLN.INC @@ -3,9 +3,10 @@ readln: ;Read the string -call readstr +mov ah, 0x1 +int 0x21 ;Print a newline call newline -ret +iret diff --git a/src/READSTR.INC b/src/READSTR.INC index 3bb5fab..d826923 100644 --- a/src/READSTR.INC +++ b/src/READSTR.INC @@ -129,7 +129,7 @@ pop cx pop bx pop ax -ret +iret ;Move the cursor forward diff --git a/src/SYSTEM.ASM b/src/SYSTEM.ASM index 3063924..299103b 100644 --- a/src/SYSTEM.ASM +++ b/src/SYSTEM.ASM @@ -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