1
0
Fork 0

Move the system stack to the end of the address space, make the shell ignore empty input, and tweak printstr and readstr a bit.

This commit is contained in:
CrazyEttin 2021-06-21 11:39:06 +03:00
parent 2e003c3198
commit 08f2d57bb2
6 changed files with 38 additions and 36 deletions

View File

@ -40,9 +40,11 @@ space and backspace keys move the cursor.
Programming
-----------
EttinOS has a flat address space of 64 KiB with the data, stack, and
extra segments set at the beginning of the RAM. Programs are loaded at
address 0x2000.
EttinOS has a flat address space of 64 KiB. The data, stack, and
extra segments are set at the beginning of the RAM and the system stack
at the end of the address space. Programs are loaded at address 0x2000.
The stack is reset back to the end of the address space after a program
has finished running.
System calls:
* Interrupt 0x20: Return to the shell.

View File

@ -60,8 +60,7 @@ mov ss, ax
mov es, ax
;Set up the stack
cli
mov sp, stack
add sp, 0x100
mov sp, 0x0
sti
;Store the boot drive number
mov [bootdrive], dl
@ -75,7 +74,7 @@ add ax, [bootsectors]
push ax
call calcsource
;Set the destination
mov si, 0x7f00
mov si, buffer
mov bx, si
;Set the size
push dx
@ -92,7 +91,7 @@ int 0x13
;Search the root for the system entry
;Set DI to the root
mov di, 0x7f00
mov di, buffer
;Initialise the search loop
mov cx, word [rootentries]
mov ax, 0x0
@ -106,7 +105,7 @@ rep cmpsb
je loadentry
;Set DI to the next entry
add ax, 0x20
mov di, 0x7f00
mov di, buffer
add di, ax
;Load CX from the stack
pop cx
@ -137,7 +136,7 @@ mov word [cluster], ax
mov ax, 0x1
call calcsource
;Set the destination
mov di, 0x7f00
mov di, buffer
mov bx, di
;Set the size
mov ax, [sectorsperfat]
@ -176,7 +175,7 @@ mov bx, 0x3
mul bx
mov bx, 0x2
div bx
mov si, 0x7f00
mov si, buffer
add si, ax
mov ax, word [ds:si]
or dx, dx
@ -198,8 +197,12 @@ mul word [clustersize]
add word [pointer], ax
jmp loadcluster
;Boot the system
;Clear the stack and boot the system
boot:
;Clear
pop cx
pop bx
;Boot
jmp 0x0:0x500
;Data
@ -236,4 +239,5 @@ times 0x1fe-($-$$) db 0x0
;Boot signature
dw 0xaa55
stack:
;File system buffer
buffer:

View File

@ -76,8 +76,7 @@ add ax, [.bootsectors]
push ax
call .calcsource
;Set the destination
mov si, stack
add si, 0x100
mov si, buffer
mov bx, si
;Set the size
push dx
@ -94,8 +93,7 @@ int 0x13
;Search the root for the file entry
;Set DI to the root
mov di, stack
add di, 0x100
mov di, buffer
;Initialise the search loop
mov cx, word [.rootentries]
mov ax, 0x0
@ -109,8 +107,7 @@ rep cmpsb
je .loadentry
;Set DI to the next entry
add ax, 0x20
mov di, stack
add di, 0x100
mov di, buffer
add di, ax
;Load CX from the stack
pop cx
@ -134,8 +131,7 @@ mov word [.cluster], ax
mov ax, 0x1
call .calcsource
;Set the destination
mov di, stack
add di, 0x100
mov di, buffer
mov bx, di
;Set the size
mov ax, [.sectorsperfat]
@ -174,8 +170,7 @@ mov bx, 0x3
mul bx
mov bx, 0x2
div bx
mov si, stack
add si, 0x100
mov si, buffer
add si, ax
mov ax, word [ds:si]
or dx, dx
@ -200,7 +195,7 @@ jmp .loadcluster
.clearcarry:
clc
;Clear left over values from the stack
;Clear the stack
.clearstack:
pop cx
pop bx
@ -215,7 +210,7 @@ pop cx
pop bx
pop ax
;Set AL to 0x1 if there was an error and to 0x0 otherwise
;Set AL to 0x1 if there was an error and to 0x0 otherwise and return
jc .setal
mov al, 0x0
iret

View File

@ -4,6 +4,7 @@ printstr:
;Store the initial registers in the stack
push ax
push si
;Print the string
.loop:
@ -21,6 +22,7 @@ jmp .loop
.done:
;Load the initial registers from the stack
pop si
pop ax
iret

View File

@ -7,6 +7,7 @@ push ax
push bx
push cx
push dx
push di
;Setup
;Store the input length in the stack
@ -124,6 +125,7 @@ jmp .findend
.done:
;Load the initial registers from the stack
pop di
pop dx
pop cx
pop bx

View File

@ -34,12 +34,6 @@ iret
start:
;Setup
;Set up the stack
cli
mov sp, stack
add sp, 0x100
sti
;Set up the interrupt vectors
;Interrupt 0x20 offset
mov ax, int0x20
@ -63,10 +57,9 @@ int 0x21
shell:
;Re-set up the stack
;Re-set the stack
cli
mov sp, stack
add sp, 0x100
mov sp, 0x0
sti
;Prompt for and read a command
@ -76,11 +69,14 @@ mov ah, 0x0
int 0x21
;Read
mov di, input
mov al, 0xff
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
@ -109,7 +105,7 @@ jmp shell
welcomemsg db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0
prompt db "> ", 0x0
errormsg db "Unknown command", 0x0
input times 0xff db 0x0
input times 0x4e db 0x0
crlf db 0xd, 0xa, 0x0
;Print a CRLF
@ -124,4 +120,5 @@ int 0x21
pop si
ret
stack:
;File system buffer
buffer: