forked from crazyettin/EttinOS
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:
parent
2e003c3198
commit
08f2d57bb2
6 changed files with 38 additions and 36 deletions
|
@ -40,9 +40,11 @@ space and backspace keys move the cursor.
|
||||||
Programming
|
Programming
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
EttinOS has a flat address space of 64 KiB with the data, stack, and
|
EttinOS has a flat address space of 64 KiB. The data, stack, and
|
||||||
extra segments set at the beginning of the RAM. Programs are loaded at
|
extra segments are set at the beginning of the RAM and the system stack
|
||||||
address 0x2000.
|
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:
|
System calls:
|
||||||
* Interrupt 0x20: Return to the shell.
|
* Interrupt 0x20: Return to the shell.
|
||||||
|
|
22
src/BOOT.ASM
22
src/BOOT.ASM
|
@ -60,8 +60,7 @@ mov ss, ax
|
||||||
mov es, ax
|
mov es, ax
|
||||||
;Set up the stack
|
;Set up the stack
|
||||||
cli
|
cli
|
||||||
mov sp, stack
|
mov sp, 0x0
|
||||||
add sp, 0x100
|
|
||||||
sti
|
sti
|
||||||
;Store the boot drive number
|
;Store the boot drive number
|
||||||
mov [bootdrive], dl
|
mov [bootdrive], dl
|
||||||
|
@ -75,7 +74,7 @@ add ax, [bootsectors]
|
||||||
push ax
|
push ax
|
||||||
call calcsource
|
call calcsource
|
||||||
;Set the destination
|
;Set the destination
|
||||||
mov si, 0x7f00
|
mov si, buffer
|
||||||
mov bx, si
|
mov bx, si
|
||||||
;Set the size
|
;Set the size
|
||||||
push dx
|
push dx
|
||||||
|
@ -92,7 +91,7 @@ int 0x13
|
||||||
|
|
||||||
;Search the root for the system entry
|
;Search the root for the system entry
|
||||||
;Set DI to the root
|
;Set DI to the root
|
||||||
mov di, 0x7f00
|
mov di, buffer
|
||||||
;Initialise the search loop
|
;Initialise the search loop
|
||||||
mov cx, word [rootentries]
|
mov cx, word [rootentries]
|
||||||
mov ax, 0x0
|
mov ax, 0x0
|
||||||
|
@ -106,7 +105,7 @@ rep cmpsb
|
||||||
je loadentry
|
je loadentry
|
||||||
;Set DI to the next entry
|
;Set DI to the next entry
|
||||||
add ax, 0x20
|
add ax, 0x20
|
||||||
mov di, 0x7f00
|
mov di, buffer
|
||||||
add di, ax
|
add di, ax
|
||||||
;Load CX from the stack
|
;Load CX from the stack
|
||||||
pop cx
|
pop cx
|
||||||
|
@ -137,7 +136,7 @@ mov word [cluster], ax
|
||||||
mov ax, 0x1
|
mov ax, 0x1
|
||||||
call calcsource
|
call calcsource
|
||||||
;Set the destination
|
;Set the destination
|
||||||
mov di, 0x7f00
|
mov di, buffer
|
||||||
mov bx, di
|
mov bx, di
|
||||||
;Set the size
|
;Set the size
|
||||||
mov ax, [sectorsperfat]
|
mov ax, [sectorsperfat]
|
||||||
|
@ -176,7 +175,7 @@ mov bx, 0x3
|
||||||
mul bx
|
mul bx
|
||||||
mov bx, 0x2
|
mov bx, 0x2
|
||||||
div bx
|
div bx
|
||||||
mov si, 0x7f00
|
mov si, buffer
|
||||||
add si, ax
|
add si, ax
|
||||||
mov ax, word [ds:si]
|
mov ax, word [ds:si]
|
||||||
or dx, dx
|
or dx, dx
|
||||||
|
@ -198,8 +197,12 @@ mul word [clustersize]
|
||||||
add word [pointer], ax
|
add word [pointer], ax
|
||||||
jmp loadcluster
|
jmp loadcluster
|
||||||
|
|
||||||
;Boot the system
|
;Clear the stack and boot the system
|
||||||
boot:
|
boot:
|
||||||
|
;Clear
|
||||||
|
pop cx
|
||||||
|
pop bx
|
||||||
|
;Boot
|
||||||
jmp 0x0:0x500
|
jmp 0x0:0x500
|
||||||
|
|
||||||
;Data
|
;Data
|
||||||
|
@ -236,4 +239,5 @@ times 0x1fe-($-$$) db 0x0
|
||||||
;Boot signature
|
;Boot signature
|
||||||
dw 0xaa55
|
dw 0xaa55
|
||||||
|
|
||||||
stack:
|
;File system buffer
|
||||||
|
buffer:
|
||||||
|
|
|
@ -76,8 +76,7 @@ add ax, [.bootsectors]
|
||||||
push ax
|
push ax
|
||||||
call .calcsource
|
call .calcsource
|
||||||
;Set the destination
|
;Set the destination
|
||||||
mov si, stack
|
mov si, buffer
|
||||||
add si, 0x100
|
|
||||||
mov bx, si
|
mov bx, si
|
||||||
;Set the size
|
;Set the size
|
||||||
push dx
|
push dx
|
||||||
|
@ -94,8 +93,7 @@ int 0x13
|
||||||
|
|
||||||
;Search the root for the file entry
|
;Search the root for the file entry
|
||||||
;Set DI to the root
|
;Set DI to the root
|
||||||
mov di, stack
|
mov di, buffer
|
||||||
add di, 0x100
|
|
||||||
;Initialise the search loop
|
;Initialise the search loop
|
||||||
mov cx, word [.rootentries]
|
mov cx, word [.rootentries]
|
||||||
mov ax, 0x0
|
mov ax, 0x0
|
||||||
|
@ -109,8 +107,7 @@ rep cmpsb
|
||||||
je .loadentry
|
je .loadentry
|
||||||
;Set DI to the next entry
|
;Set DI to the next entry
|
||||||
add ax, 0x20
|
add ax, 0x20
|
||||||
mov di, stack
|
mov di, buffer
|
||||||
add di, 0x100
|
|
||||||
add di, ax
|
add di, ax
|
||||||
;Load CX from the stack
|
;Load CX from the stack
|
||||||
pop cx
|
pop cx
|
||||||
|
@ -134,8 +131,7 @@ mov word [.cluster], ax
|
||||||
mov ax, 0x1
|
mov ax, 0x1
|
||||||
call .calcsource
|
call .calcsource
|
||||||
;Set the destination
|
;Set the destination
|
||||||
mov di, stack
|
mov di, buffer
|
||||||
add di, 0x100
|
|
||||||
mov bx, di
|
mov bx, di
|
||||||
;Set the size
|
;Set the size
|
||||||
mov ax, [.sectorsperfat]
|
mov ax, [.sectorsperfat]
|
||||||
|
@ -174,8 +170,7 @@ mov bx, 0x3
|
||||||
mul bx
|
mul bx
|
||||||
mov bx, 0x2
|
mov bx, 0x2
|
||||||
div bx
|
div bx
|
||||||
mov si, stack
|
mov si, buffer
|
||||||
add si, 0x100
|
|
||||||
add si, ax
|
add si, ax
|
||||||
mov ax, word [ds:si]
|
mov ax, word [ds:si]
|
||||||
or dx, dx
|
or dx, dx
|
||||||
|
@ -200,7 +195,7 @@ jmp .loadcluster
|
||||||
.clearcarry:
|
.clearcarry:
|
||||||
clc
|
clc
|
||||||
|
|
||||||
;Clear left over values from the stack
|
;Clear the stack
|
||||||
.clearstack:
|
.clearstack:
|
||||||
pop cx
|
pop cx
|
||||||
pop bx
|
pop bx
|
||||||
|
@ -215,7 +210,7 @@ pop cx
|
||||||
pop bx
|
pop bx
|
||||||
pop ax
|
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
|
jc .setal
|
||||||
mov al, 0x0
|
mov al, 0x0
|
||||||
iret
|
iret
|
||||||
|
|
|
@ -4,6 +4,7 @@ printstr:
|
||||||
|
|
||||||
;Store the initial registers in the stack
|
;Store the initial registers in the stack
|
||||||
push ax
|
push ax
|
||||||
|
push si
|
||||||
|
|
||||||
;Print the string
|
;Print the string
|
||||||
.loop:
|
.loop:
|
||||||
|
@ -21,6 +22,7 @@ jmp .loop
|
||||||
.done:
|
.done:
|
||||||
|
|
||||||
;Load the initial registers from the stack
|
;Load the initial registers from the stack
|
||||||
|
pop si
|
||||||
pop ax
|
pop ax
|
||||||
|
|
||||||
iret
|
iret
|
||||||
|
|
|
@ -7,6 +7,7 @@ push ax
|
||||||
push bx
|
push bx
|
||||||
push cx
|
push cx
|
||||||
push dx
|
push dx
|
||||||
|
push di
|
||||||
|
|
||||||
;Setup
|
;Setup
|
||||||
;Store the input length in the stack
|
;Store the input length in the stack
|
||||||
|
@ -124,6 +125,7 @@ jmp .findend
|
||||||
.done:
|
.done:
|
||||||
|
|
||||||
;Load the initial registers from the stack
|
;Load the initial registers from the stack
|
||||||
|
pop di
|
||||||
pop dx
|
pop dx
|
||||||
pop cx
|
pop cx
|
||||||
pop bx
|
pop bx
|
||||||
|
|
|
@ -34,12 +34,6 @@ iret
|
||||||
|
|
||||||
start:
|
start:
|
||||||
|
|
||||||
;Setup
|
|
||||||
;Set up the stack
|
|
||||||
cli
|
|
||||||
mov sp, stack
|
|
||||||
add sp, 0x100
|
|
||||||
sti
|
|
||||||
;Set up the interrupt vectors
|
;Set up the interrupt vectors
|
||||||
;Interrupt 0x20 offset
|
;Interrupt 0x20 offset
|
||||||
mov ax, int0x20
|
mov ax, int0x20
|
||||||
|
@ -63,10 +57,9 @@ int 0x21
|
||||||
|
|
||||||
shell:
|
shell:
|
||||||
|
|
||||||
;Re-set up the stack
|
;Re-set the stack
|
||||||
cli
|
cli
|
||||||
mov sp, stack
|
mov sp, 0x0
|
||||||
add sp, 0x100
|
|
||||||
sti
|
sti
|
||||||
|
|
||||||
;Prompt for and read a command
|
;Prompt for and read a command
|
||||||
|
@ -76,11 +69,14 @@ mov ah, 0x0
|
||||||
int 0x21
|
int 0x21
|
||||||
;Read
|
;Read
|
||||||
mov di, input
|
mov di, input
|
||||||
mov al, 0xff
|
mov al, 0x4e
|
||||||
mov ah, 0x3
|
mov ah, 0x3
|
||||||
int 0x21
|
int 0x21
|
||||||
|
|
||||||
;Load an execute the program
|
;Load an execute the program
|
||||||
|
;Check for an empty command
|
||||||
|
cmp byte [input], 0x0
|
||||||
|
jz shell
|
||||||
;Load
|
;Load
|
||||||
mov bx, 0x2000
|
mov bx, 0x2000
|
||||||
mov si, input
|
mov si, input
|
||||||
|
@ -109,7 +105,7 @@ jmp shell
|
||||||
welcomemsg db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0
|
welcomemsg db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0
|
||||||
prompt db "> ", 0x0
|
prompt db "> ", 0x0
|
||||||
errormsg db "Unknown command", 0x0
|
errormsg db "Unknown command", 0x0
|
||||||
input times 0xff db 0x0
|
input times 0x4e db 0x0
|
||||||
crlf db 0xd, 0xa, 0x0
|
crlf db 0xd, 0xa, 0x0
|
||||||
|
|
||||||
;Print a CRLF
|
;Print a CRLF
|
||||||
|
@ -124,4 +120,5 @@ int 0x21
|
||||||
pop si
|
pop si
|
||||||
ret
|
ret
|
||||||
|
|
||||||
stack:
|
;File system buffer
|
||||||
|
buffer:
|
||||||
|
|
Loading…
Reference in a new issue