Move the system from after the bootloader to the beginning of usable memory and the bootloader and system stacks to after their respective programs, fix a couple of bugs in the bootloader that made it not load the system correctly above a specific size, abandon the goal of eventual subdirectory support and modify the project directory structure and make.sh accordingly, and start writing fileify.

This commit is contained in:
CrazyEttin 2021-06-16 18:03:31 +03:00
parent f2654038cb
commit a62a87970a
18 changed files with 202 additions and 56 deletions

View File

@ -1,10 +0,0 @@
;Prints help.
help:
mov si, .help
call println
ret
.help db "Input:", 0xd, 0xa, "* Typing a character overwrites the cursor location.", 0xd, 0xa, "* The erase (=tab) key erases the cursor location.", 0xd, 0xa, "* The space and backspace keys move the cursor.", 0xd, 0xa, "Commands:", 0xd, 0xa, "* echo: echoes its input.", 0xd, 0xa, "* hello: a hello world program.", 0xd, 0xa, "* help: you are reading it.", 0xd, 0xa, "* keycode: echoes the BIOS code of a key.", 0x0

24
make.sh
View File

@ -1,18 +1,22 @@
#!/bin/bash #!/bin/bash
cd SOURCE/ rm -f EttinOS.img
if [[ ! -d "bin" ]]
if [ "$1" == "-F1440" ] then
then nasm BOOT.ASM -d F1440 -f bin -o ../BOOT.BIN mkdir bin
else nasm BOOT.ASM -f bin -o ../BOOT.BIN
fi fi
nasm SYSTEM.ASM -f bin -o ../SYSTEM.BIN
cd src/
if [ "$1" == "-F1440" ]
then nasm BOOT.ASM -d F1440 -f bin -o ../bin/BOOT.BIN
else nasm BOOT.ASM -f bin -o ../bin/BOOT.BIN
fi
nasm SYSTEM.ASM -f bin -o ../bin/SYSTEM.BIN
cd .. cd ..
rm -f EttinOS.img if [ "$1" == "-1440" ]
if [ "$1" == "-F1440" ]
then mkfs.fat -C EttinOS.img 1440 then mkfs.fat -C EttinOS.img 1440
else mkfs.fat -C EttinOS.img 360 else mkfs.fat -C EttinOS.img 360
fi fi
dd if=BOOT.BIN of=EttinOS.img conv=notrunc bs=512 count=1 dd if=bin/BOOT.BIN of=EttinOS.img conv=notrunc bs=512 count=1
mcopy -i EttinOS.img SYSTEM.BIN :: mcopy -i EttinOS.img bin/SYSTEM.BIN ::

View File

@ -7,7 +7,7 @@ nop
;Disk description tables ;Disk description tables
%ifdef F1440 %ifdef F1440
;1.44 MB 3.5" floppy disk (enable by passing -d F1440 to NASM) ;1.44 MB 3.5" floppy disk (enable with the argument -d F1440 when building)
oemlabel db "ETTINOS " oemlabel db "ETTINOS "
sectorsize dw 0x200 ;bytes sectorsize dw 0x200 ;bytes
clustersize db 0x1 ;sectors clustersize db 0x1 ;sectors
@ -52,17 +52,17 @@ filesystem db "FAT12 "
start: start:
;Set up the data segment ;Setup
;Set up the data, stack, and extra segments
mov ax, 0x0 mov ax, 0x0
mov ds, ax mov ds, ax
mov ss, ax
mov es, ax
;Set up the stack ;Set up the stack
cli cli
mov ax, 0x0 mov sp, stack
mov ss, ax add sp, 0x100
mov sp, 0x7c00
sti sti
;Store the boot device number ;Store the boot device number
mov [bootdev], dl mov [bootdev], dl
@ -75,9 +75,7 @@ add ax, [bootsectors]
push ax push ax
call calcsource call calcsource
;Set the destination ;Set the destination
mov si, 0x7e00 mov si, 0x7f00
mov bx, ds
mov es, bx
mov bx, si mov bx, si
;Set the size ;Set the size
push dx push dx
@ -93,10 +91,8 @@ mov ah, 0x2
int 0x13 int 0x13
;Search the root for the system ;Search the root for the system
;Set DI to the root FAT ;Set DI to the root
mov ax, ds mov di, 0x7f00
mov es, ax
mov di, 0x7e00
;Initialise the search loop ;Initialise the search loop
mov cx, word [rootentries] mov cx, word [rootentries]
mov ax, 0x0 mov ax, 0x0
@ -110,13 +106,13 @@ rep cmpsb
je loadfat je loadfat
;Set DI to the next entry ;Set DI to the next entry
add ax, 0x20 add ax, 0x20
mov di, 0x7e00 mov di, 0x7f00
add di, ax add di, ax
;Load CX from the stack ;Load CX from the stack
pop cx pop cx
loop search loop search
;Load the system FAT ;Load the system entry
loadfat: loadfat:
;Load CX from the stack ;Load CX from the stack
pop cx pop cx
@ -127,7 +123,7 @@ mov word [cluster], ax
mov ax, 0x1 mov ax, 0x1
call calcsource call calcsource
;Set the destination ;Set the destination
mov di, 0x7e00 mov di, 0x7f00
mov bx, di mov bx, di
;Set the size ;Set the size
mov ax, [sectorsperfat] mov ax, [sectorsperfat]
@ -140,20 +136,21 @@ int 0x13
;Load a cluster ;Load a cluster
loadcluster: loadcluster:
;Set the source ;Set the source
pop cx
pop bx pop bx
pop ax mov ax, word [cluster]
push ax
push bx
add ax, bx
sub ax, 0x2 sub ax, 0x2
add ax, word [cluster] mul byte [clustersize]
add ax, bx
add ax, cx
push bx
push cx
call calcsource call calcsource
;Set the destination ;Set the destination
mov ax, 0x0
mov es, ax
mov bx, word [pointer] mov bx, word [pointer]
;Set the size ;Set the size
mov al, 0x1 ;mov al, 0x1
mov al, [clustersize]
;Load ;Load
mov ah, 0x2 mov ah, 0x2
int 0x13 int 0x13
@ -165,7 +162,7 @@ mov bx, 0x3
mul bx mul bx
mov bx, 0x2 mov bx, 0x2
div bx div bx
mov si, 0x7e00 mov si, 0x7f00
add si, ax add si, ax
mov ax, word [ds:si] mov ax, word [ds:si]
or dx, dx or dx, dx
@ -182,19 +179,22 @@ contcalc:
mov word [cluster], ax mov word [cluster], ax
cmp ax, 0xff8 cmp ax, 0xff8
jge boot jge boot
add word [pointer], 0x200 mov ax, [sectorsize]
mul word [clustersize]
add word [pointer], ax
jmp loadcluster jmp loadcluster
;Boot the system
boot: boot:
jmp 0x0:0x9e00 jmp 0x0:0x500
sysfile db "SYSTEM BIN"
;Data
bootdev db 0x0 bootdev db 0x0
sysfile db "SYSTEM BIN"
cluster dw 0x0 cluster dw 0x0
pointer dw 0x9e00 pointer dw 0x500
;Calculate the source arguments for loading data from the disk
calcsource: calcsource:
push ax push ax
push bx push bx
@ -215,8 +215,10 @@ pop ax
mov dl, byte [bootdev] mov dl, byte [bootdev]
ret ret
;Pad the binary to a full sector and make the disk bootable
;Padding ;Padding
times 0x1fe-($-$$) db 0x0 times 0x1fe-($-$$) db 0x0
;Boot signature ;Boot signature
dw 0xaa55 dw 0xaa55
stack:

120
src/FILEIFY.INC Normal file
View File

@ -0,0 +1,120 @@
;Reads a string, checks if it is a valid 8.3 file name, converts it into FAT formatting, and prints it.
;To do: change the .test call to work with flags instead of direct jumps.
fileify:
;Read a string
mov di, buffer
mov al, 0xff
call readln
;Set SI and DI
mov si, buffer
mov di, .file
;Initialise the name with spaces
mov cx, 0xb
mov al, 0x20
rep stosb
sub di, 0xb
;Initialise the length counter for the main part of the name
mov bl, 0x8
.nameloop:
;Load a character
lodsb
;Check for a period
cmp al, 0x2e
je .initext
call .test
jmp .nameloop
.initext:
;Set DI and initialise the counter for the extension
mov bl, 0x3
mov di, .file+0x8
.extloop:
call .test
jmp .extloop
.error:
mov si, .errormsg
call println
jmp .done
.print:
mov si, .name
call printstr
mov si, .extension
call printstr
mov al, 0x7c
call printch
call printnl
.done:
ret
.file times 0xc db 0x0
.errormsg db "Invalid file name", 0x0
.test:
;Check for the string end
cmp al, 0x0
je .print
;Check for the length limit
cmp bl, 0x0
je .error
;Check for invalid characters
cmp al, 0x22
je .error
cmp al, 0x2a
jl .contcheck1
cmp al, 0x2c
jg .contcheck1
jmp .error
.contcheck1:
cmp al, 0x2f
je .error
cmp al, 0x3a
jl .contcheck2
cmp al, 0x3f
jg .contcheck2
jmp .error
.contcheck2:
cmp al, 0x5b
jl .contcheck3
cmp al, 0x5d
jg .contcheck3
jmp .error
.contcheck3:
cmp al, 0x7c
je .error
;Find and convert lower case letters to upper case
;Check for lower case
cmp al, 0x61
jl .conttest
cmp al, 0x7a
jg .conttest
;Convert lower to upper case
sub al, 0x20
.conttest:
;Store the character
stosb
;Increase the counter
dec bl
ret

10
src/HELP.INC Normal file
View File

@ -0,0 +1,10 @@
;Prints help.
help:
mov si, .help
call println
ret
.help db "Input:", 0xd, 0xa, " * Typing a character overwrites the cursor location.", 0xd, 0xa, " * The erase (=tab) key erases the cursor location.", 0xd, 0xa, " * The space and backspace keys move the cursor.", 0xd, 0xa, "Commands:", 0xd, 0xa, " * echo: echoes its input.", 0xd, 0xa, " * fileify: prints its input in FAT format if it is a valid filename.", 0xd, 0xa, " * hello: a hello world program.", 0xd, 0xa, " * help: you are reading it.", 0xd, 0xa, " * keycode: echoes the BIOS code of a key.", 0x0

View File

@ -1,5 +1,5 @@
CPU 8086 CPU 8086
ORG 0x9e00 ORG 0x500
jmp start jmp start
@ -16,12 +16,19 @@ jmp start
;Commands ;Commands
%include "ECHO.INC" %include "ECHO.INC"
;%include "FILEIFY.INC"
%include "HELLO.INC" %include "HELLO.INC"
%include "HELP.INC" %include "HELP.INC"
%include "KEYCODE.INC" %include "KEYCODE.INC"
start: start:
;Set up the stack
cli
mov sp, stack
add sp, 0x100
sti
;Get the terminal width ;Get the terminal width
mov ah, 0xf mov ah, 0xf
int 0x10 int 0x10
@ -33,10 +40,10 @@ call println
loop: loop:
;Prompt for and read a command
;Print a prompt ;Print a prompt
mov si, prompt mov si, prompt
call printstr call printstr
;Read a command ;Read a command
mov di, buffer mov di, buffer
mov al, 0xff mov al, 0xff
@ -52,10 +59,20 @@ je loop
mov si, buffer mov si, buffer
mov di, cmd.echo mov di, cmd.echo
call cmpstr call cmpstr
;jnc .fileify
jnc .hello jnc .hello
;Execute ;Execute
call echo call echo
jmp loop jmp loop
;.fileify:
;;Check
;mov si, buffer
;mov di, cmd.fileify
;call cmpstr
;jnc .hello
;;Execute
;call fileify
;jmp loop
.hello: .hello:
;Check ;Check
mov si, buffer mov si, buffer
@ -96,10 +113,13 @@ prompt db "> ", 0x0
cmd: cmd:
.echo db "echo", 0x0 .echo db "echo", 0x0
.fileify db "fileify", 0x0
.hello db "hello", 0x0 .hello db "hello", 0x0
.help db "help", 0x0 .help db "help", 0x0
.keycode db "keycode", 0x0 .keycode db "keycode", 0x0
error db "Unknown command", 0x0 error db "Unknown command", 0x0
buffer times 0xff db 0 buffer times 0xff db 0x0
stack: