Make the system compatible with Intel 8086 CPU, change the remaining media-dependent constants in the bootloader to variables, change the default media to a 360 KiB 5.25" floppy disk and offer 1.44 MB 3.5" disk as an option instead, and change labels used for data to variables because apparently using labels for data is not wise.

This commit is contained in:
CrazyEttin 2021-06-10 18:16:14 +03:00
parent 9afbaae05d
commit f2654038cb
12 changed files with 161 additions and 104 deletions

View File

@ -1,26 +1,54 @@
[ORG 0x7c00]
CPU 8086
ORG 0x7c00
jmp start
nop
;1.44 MB 3.5" floppy disk description table
OEMLabel db "ETTINOS "
BytesPerSector dw 0x200
SectorsPerCluster db 0x1
BootRecordSectors dw 0x1
FATs db 0x2
RootEntries dw 0xe0
LogicalSectors dw 0xb40
MediaDescriptor db 0xf0
SectorsPerFAT dw 0x9
SectorsPerTrack dw 0x12
Sides dw 0x2
HiddenSectors dd 0x0
LargeSectors dd 0x0
DriveNumber dw 0x0
DriveSignature db 0x29
VolumeID dd 0x0
VolumeLabel db "ETTINOS "
FileSystem db "FAT12 "
;Disk description tables
%ifdef F1440
;1.44 MB 3.5" floppy disk (enable by passing -d F1440 to NASM)
oemlabel db "ETTINOS "
sectorsize dw 0x200 ;bytes
clustersize db 0x1 ;sectors
bootsectors dw 0x1
fats db 0x2
rootentries dw 0xe0
logicalsectors dw 0xb40
mediadescriptor db 0xf0
sectorsperfat dw 0x9
sectorspertrack dw 0x12
sides dw 0x2
hiddensectors dd 0x0
largesectors dd 0x0
driveid dw 0x0
drivesignature db 0x29
volumeid dd 0x0
volumelabel db "ETTINOS "
filesystem db "FAT12 "
%else
;360 KiB 5.25" floppy disk (default)
oemlabel db "ETTINOS "
sectorsize dw 0x200 ;bytes
clustersize db 0x2 ;sectors
bootsectors dw 0x1
fats db 0x2
rootentries dw 0x70
logicalsectors dw 0x2d0
mediadescriptor db 0xfd
sectorsperfat dw 0x2
sectorspertrack dw 0x9
sides dw 0x2
hiddensectors dd 0x0
largesectors dd 0x0
driveid dw 0x0
drivesignature db 0x29
volumeid dd 0x0
volumelabel db "ETTINOS "
filesystem db "FAT12 "
%endif
start:
@ -38,9 +66,13 @@ sti
;Store the boot device number
mov [bootdev], dl
;Load the root FAT
;Load the root
;Set the source
mov ax, 0x13
mov ah, 0x0
mov al, [fats]
mul word [sectorsperfat]
add ax, [bootsectors]
push ax
call calcsource
;Set the destination
mov si, 0x7e00
@ -48,18 +80,25 @@ mov bx, ds
mov es, bx
mov bx, si
;Set the size
mov al, 0xe
push dx
mov ax, [rootentries]
mov dx, 0x20
mul dx
mov dx, 0x0
div word [sectorsize]
pop dx
push ax
;Load
mov ah, 0x2
int 0x13
;Search the root FAT for the system FAT
;Search the root for the system
;Set DI to the root FAT
mov ax, ds
mov es, ax
mov di, 0x7e00
;Initialise the search loop
mov cx, word [RootEntries]
mov cx, word [rootentries]
mov ax, 0x0
search:
;Store CX in the stack
@ -68,7 +107,7 @@ push cx
mov si, sysfile
mov cx, 0xb
rep cmpsb
je loadsysfat
je loadfat
;Set DI to the next entry
add ax, 0x20
mov di, 0x7e00
@ -78,7 +117,9 @@ pop cx
loop search
;Load the system FAT
loadsysfat:
loadfat:
;Load CX from the stack
pop cx
;Store the first cluster
mov ax, word [es:di+0xf]
mov word [cluster], ax
@ -89,16 +130,23 @@ call calcsource
mov di, 0x7e00
mov bx, di
;Set the size
mov al, 0x9
mov ax, [sectorsperfat]
;Load
mov ah, 0x2
int 0x13
;Load the system
loadsys:
;Load the system file
;Load a cluster
loadcluster:
;Set the source
mov ax, word [cluster]
add ax, 0x1f
pop bx
pop ax
push ax
push bx
add ax, bx
sub ax, 0x2
add ax, word [cluster]
call calcsource
;Set the destination
mov ax, 0x0
@ -106,7 +154,7 @@ mov es, ax
mov bx, word [pointer]
;Set the size
mov al, 0x1
;Load a cluster
;Load
mov ah, 0x2
int 0x13
@ -115,7 +163,7 @@ mov ax, [cluster]
mov dx, 0x0
mov bx, 0x3
mul bx
mov bx, 2
mov bx, 0x2
div bx
mov si, 0x7e00
add si, ax
@ -123,45 +171,43 @@ mov ax, word [ds:si]
or dx, dx
jz even
odd:
shr ax, 4
jmp contcluster
shr ax, 1
shr ax, 1
shr ax, 1
shr ax, 1
jmp contcalc
even:
and ax, 0xfff
contcluster:
contcalc:
mov word [cluster], ax
cmp ax, 0xff8
jge boot
add word [pointer], 0x200
jmp loadsys
jmp loadcluster
boot:
jmp 0x0:0x9e00
sysfile:
db "SYSTEM BIN"
sysfile db "SYSTEM BIN"
bootdev:
db 0
bootdev db 0x0
cluster:
dw 0x0
pointer:
dw 0x9e00
cluster dw 0x0
pointer dw 0x9e00
calcsource:
push ax
push bx
mov bx, ax
mov dx, 0x0
div word [SectorsPerTrack]
div word [sectorspertrack]
add dl, 0x1
mov cl, dl
mov ax, bx
mov dx, 0x0
div word [SectorsPerTrack]
div word [sectorspertrack]
mov dx, 0x0
div word [Sides]
div word [sides]
mov dh, dl
mov ch, al
pop bx

View File

@ -1,9 +1,15 @@
;Converts a byte in AH to a hex string at DI.
;Converts a byte in AL to a hex string at DI.
byte2hex:
;Store the initial registers in the stack
pusha
push si
push ax
push bx
push cx
;Move the byte to AH
mov ah, al
;Set a key for the hex digits
mov si, .key
@ -14,7 +20,10 @@ mov cx, 0x2
.loop:
;Read a nibble
rol ax, 0x4
rol ax, 0x1
rol ax, 0x1
rol ax, 0x1
rol ax, 0x1
mov bx, ax
;Convert the nibble to a hex digit
@ -30,9 +39,11 @@ dec cx
jnz .loop
;Load the initial registers from the stack
popa
pop cx
pop bx
pop ax
pop si
ret
.key:
db "0123456789abcdef"
.key db "0123456789abcdef"

View File

@ -1,9 +1,10 @@
;Compares strings from SI and SI and sets the carry flag if they are equal and clears it if not.
;Compares strings from SI and DI until a null and either sets the carry flag if they are equal or clears it if not.
cmpstr:
;Store the initial registers in the stack
pusha
push ax
push bx
.loop:
@ -38,6 +39,7 @@ stc
.done:
;Load the initial registers from the stack
popa
pop bx
pop ax
ret

View File

@ -7,5 +7,4 @@ call println
ret
.hello:
db "Hello world!", 0x0
.hello db "Hello world!", 0x0

View File

@ -7,5 +7,4 @@ 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
.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

View File

@ -15,12 +15,12 @@ mov si, .prefix
call printstr
;Convert the scancode to a hex string
mov ah, [.scan]
mov al, [.scan]
mov di, .keycode
call byte2hex
;Convert the ascii value to a hex string
mov ah, [.ascii]
mov al, [.ascii]
mov di, .keycode
add di, 0x2
call byte2hex
@ -31,14 +31,9 @@ call println
ret
.prefix:
db "0x", 0x0
.prefix db "0x", 0x0
.scan:
db 0x0
.scan db 0x0
.ascii db 0x0
.ascii:
db 0x0
.keycode:
times 0x5 db 0x0
.keycode times 0x5 db 0x0

View File

@ -3,16 +3,15 @@
printnl:
;Store the initial registers in the stack
pusha
push si
;Print the newline
mov si, .nl
call printstr
;Load the initial registers from the stack
popa
pop si
ret
.nl:
db 0xd, 0xa, 0x0
.nl db 0xd, 0xa, 0x0

View File

@ -3,7 +3,7 @@
printstr:
;Store the initial registers in the stack
pusha
push ax
.loop:
@ -24,6 +24,6 @@ jmp .loop
.done:
;Load the initial registers from the stack
popa
pop ax
ret

View File

@ -25,5 +25,4 @@ pop bx
mov ah, bh
pop bx
.done:
ret

View File

@ -3,7 +3,10 @@
readstr:
;Store the initial registers in the stack
pusha
push ax
push bx
push cx
push dx
;Store the input length in the stack
mov ah, 0
@ -116,7 +119,10 @@ jmp .findend
.done:
;Load the initial registers from the stack
popa
pop dx
pop cx
pop bx
pop ax
ret

View File

@ -1,4 +1,6 @@
[ORG 0x9e00]
CPU 8086
ORG 0x9e00
jmp start
;Calls
@ -86,26 +88,18 @@ mov si, error
call println
jmp loop
cpl:
db 0x0
cpl db 0x0
welcome:
db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0
welcome db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0
prompt:
db "> ", 0x0
prompt db "> ", 0x0
cmd:
.echo:
db "echo", 0x0
.hello:
db "hello", 0x0
.help:
db "help", 0x0
.keycode:
db "keycode", 0x0
error:
db "Unknown command", 0x0
.echo db "echo", 0x0
.hello db "hello", 0x0
.help db "help", 0x0
.keycode db "keycode", 0x0
buffer:
times 0xff db 0
error db "Unknown command", 0x0
buffer times 0xff db 0

11
make.sh
View File

@ -1,11 +1,18 @@
#!/bin/bash
cd SOURCE/
nasm BOOT.ASM -f bin -o ../BOOT.BIN
if [ "$1" == "-F1440" ]
then nasm BOOT.ASM -d F1440 -f bin -o ../BOOT.BIN
else nasm BOOT.ASM -f bin -o ../BOOT.BIN
fi
nasm SYSTEM.ASM -f bin -o ../SYSTEM.BIN
cd ..
rm -f EttinOS.img
mkfs.fat -C EttinOS.img 1440
if [ "$1" == "-F1440" ]
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 ::