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:
parent
f2654038cb
commit
a62a87970a
|
@ -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
24
make.sh
|
@ -1,18 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd SOURCE/
|
||||
|
||||
if [ "$1" == "-F1440" ]
|
||||
then nasm BOOT.ASM -d F1440 -f bin -o ../BOOT.BIN
|
||||
else nasm BOOT.ASM -f bin -o ../BOOT.BIN
|
||||
rm -f EttinOS.img
|
||||
if [[ ! -d "bin" ]]
|
||||
then
|
||||
mkdir bin
|
||||
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 ..
|
||||
rm -f EttinOS.img
|
||||
if [ "$1" == "-F1440" ]
|
||||
if [ "$1" == "-1440" ]
|
||||
then mkfs.fat -C EttinOS.img 1440
|
||||
else mkfs.fat -C EttinOS.img 360
|
||||
fi
|
||||
dd if=BOOT.BIN of=EttinOS.img conv=notrunc bs=512 count=1
|
||||
mcopy -i EttinOS.img SYSTEM.BIN ::
|
||||
dd if=bin/BOOT.BIN of=EttinOS.img conv=notrunc bs=512 count=1
|
||||
mcopy -i EttinOS.img bin/SYSTEM.BIN ::
|
||||
|
|
|
@ -7,7 +7,7 @@ nop
|
|||
;Disk description tables
|
||||
|
||||
%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 "
|
||||
sectorsize dw 0x200 ;bytes
|
||||
clustersize db 0x1 ;sectors
|
||||
|
@ -52,17 +52,17 @@ filesystem db "FAT12 "
|
|||
|
||||
start:
|
||||
|
||||
;Set up the data segment
|
||||
;Setup
|
||||
;Set up the data, stack, and extra segments
|
||||
mov ax, 0x0
|
||||
mov ds, ax
|
||||
|
||||
mov ss, ax
|
||||
mov es, ax
|
||||
;Set up the stack
|
||||
cli
|
||||
mov ax, 0x0
|
||||
mov ss, ax
|
||||
mov sp, 0x7c00
|
||||
mov sp, stack
|
||||
add sp, 0x100
|
||||
sti
|
||||
|
||||
;Store the boot device number
|
||||
mov [bootdev], dl
|
||||
|
||||
|
@ -75,9 +75,7 @@ add ax, [bootsectors]
|
|||
push ax
|
||||
call calcsource
|
||||
;Set the destination
|
||||
mov si, 0x7e00
|
||||
mov bx, ds
|
||||
mov es, bx
|
||||
mov si, 0x7f00
|
||||
mov bx, si
|
||||
;Set the size
|
||||
push dx
|
||||
|
@ -93,10 +91,8 @@ mov ah, 0x2
|
|||
int 0x13
|
||||
|
||||
;Search the root for the system
|
||||
;Set DI to the root FAT
|
||||
mov ax, ds
|
||||
mov es, ax
|
||||
mov di, 0x7e00
|
||||
;Set DI to the root
|
||||
mov di, 0x7f00
|
||||
;Initialise the search loop
|
||||
mov cx, word [rootentries]
|
||||
mov ax, 0x0
|
||||
|
@ -110,13 +106,13 @@ rep cmpsb
|
|||
je loadfat
|
||||
;Set DI to the next entry
|
||||
add ax, 0x20
|
||||
mov di, 0x7e00
|
||||
mov di, 0x7f00
|
||||
add di, ax
|
||||
;Load CX from the stack
|
||||
pop cx
|
||||
loop search
|
||||
|
||||
;Load the system FAT
|
||||
;Load the system entry
|
||||
loadfat:
|
||||
;Load CX from the stack
|
||||
pop cx
|
||||
|
@ -127,7 +123,7 @@ mov word [cluster], ax
|
|||
mov ax, 0x1
|
||||
call calcsource
|
||||
;Set the destination
|
||||
mov di, 0x7e00
|
||||
mov di, 0x7f00
|
||||
mov bx, di
|
||||
;Set the size
|
||||
mov ax, [sectorsperfat]
|
||||
|
@ -140,20 +136,21 @@ int 0x13
|
|||
;Load a cluster
|
||||
loadcluster:
|
||||
;Set the source
|
||||
pop cx
|
||||
pop bx
|
||||
pop ax
|
||||
push ax
|
||||
push bx
|
||||
add ax, bx
|
||||
mov ax, word [cluster]
|
||||
sub ax, 0x2
|
||||
add ax, word [cluster]
|
||||
mul byte [clustersize]
|
||||
add ax, bx
|
||||
add ax, cx
|
||||
push bx
|
||||
push cx
|
||||
call calcsource
|
||||
;Set the destination
|
||||
mov ax, 0x0
|
||||
mov es, ax
|
||||
mov bx, word [pointer]
|
||||
;Set the size
|
||||
mov al, 0x1
|
||||
;mov al, 0x1
|
||||
mov al, [clustersize]
|
||||
;Load
|
||||
mov ah, 0x2
|
||||
int 0x13
|
||||
|
@ -165,7 +162,7 @@ mov bx, 0x3
|
|||
mul bx
|
||||
mov bx, 0x2
|
||||
div bx
|
||||
mov si, 0x7e00
|
||||
mov si, 0x7f00
|
||||
add si, ax
|
||||
mov ax, word [ds:si]
|
||||
or dx, dx
|
||||
|
@ -182,19 +179,22 @@ contcalc:
|
|||
mov word [cluster], ax
|
||||
cmp ax, 0xff8
|
||||
jge boot
|
||||
add word [pointer], 0x200
|
||||
mov ax, [sectorsize]
|
||||
mul word [clustersize]
|
||||
add word [pointer], ax
|
||||
jmp loadcluster
|
||||
|
||||
;Boot the system
|
||||
boot:
|
||||
jmp 0x0:0x9e00
|
||||
|
||||
sysfile db "SYSTEM BIN"
|
||||
jmp 0x0:0x500
|
||||
|
||||
;Data
|
||||
bootdev db 0x0
|
||||
|
||||
sysfile db "SYSTEM BIN"
|
||||
cluster dw 0x0
|
||||
pointer dw 0x9e00
|
||||
pointer dw 0x500
|
||||
|
||||
;Calculate the source arguments for loading data from the disk
|
||||
calcsource:
|
||||
push ax
|
||||
push bx
|
||||
|
@ -215,8 +215,10 @@ pop ax
|
|||
mov dl, byte [bootdev]
|
||||
ret
|
||||
|
||||
;Pad the binary to a full sector and make the disk bootable
|
||||
;Padding
|
||||
times 0x1fe-($-$$) db 0x0
|
||||
|
||||
;Boot signature
|
||||
dw 0xaa55
|
||||
|
||||
stack:
|
|
@ -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
|
|
@ -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
|
|
@ -1,5 +1,5 @@
|
|||
CPU 8086
|
||||
ORG 0x9e00
|
||||
ORG 0x500
|
||||
|
||||
jmp start
|
||||
|
||||
|
@ -16,12 +16,19 @@ jmp start
|
|||
|
||||
;Commands
|
||||
%include "ECHO.INC"
|
||||
;%include "FILEIFY.INC"
|
||||
%include "HELLO.INC"
|
||||
%include "HELP.INC"
|
||||
%include "KEYCODE.INC"
|
||||
|
||||
start:
|
||||
|
||||
;Set up the stack
|
||||
cli
|
||||
mov sp, stack
|
||||
add sp, 0x100
|
||||
sti
|
||||
|
||||
;Get the terminal width
|
||||
mov ah, 0xf
|
||||
int 0x10
|
||||
|
@ -33,10 +40,10 @@ call println
|
|||
|
||||
loop:
|
||||
|
||||
;Prompt for and read a command
|
||||
;Print a prompt
|
||||
mov si, prompt
|
||||
call printstr
|
||||
|
||||
;Read a command
|
||||
mov di, buffer
|
||||
mov al, 0xff
|
||||
|
@ -52,10 +59,20 @@ je loop
|
|||
mov si, buffer
|
||||
mov di, cmd.echo
|
||||
call cmpstr
|
||||
;jnc .fileify
|
||||
jnc .hello
|
||||
;Execute
|
||||
call echo
|
||||
jmp loop
|
||||
;.fileify:
|
||||
;;Check
|
||||
;mov si, buffer
|
||||
;mov di, cmd.fileify
|
||||
;call cmpstr
|
||||
;jnc .hello
|
||||
;;Execute
|
||||
;call fileify
|
||||
;jmp loop
|
||||
.hello:
|
||||
;Check
|
||||
mov si, buffer
|
||||
|
@ -96,10 +113,13 @@ prompt db "> ", 0x0
|
|||
|
||||
cmd:
|
||||
.echo db "echo", 0x0
|
||||
.fileify db "fileify", 0x0
|
||||
.hello db "hello", 0x0
|
||||
.help db "help", 0x0
|
||||
.keycode db "keycode", 0x0
|
||||
|
||||
error db "Unknown command", 0x0
|
||||
|
||||
buffer times 0xff db 0
|
||||
buffer times 0xff db 0x0
|
||||
|
||||
stack:
|
Loading…
Reference in New Issue