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:
parent
9afbaae05d
commit
f2654038cb
146
SOURCE/BOOT.ASM
146
SOURCE/BOOT.ASM
|
@ -1,26 +1,54 @@
|
||||||
[ORG 0x7c00]
|
CPU 8086
|
||||||
|
ORG 0x7c00
|
||||||
|
|
||||||
jmp start
|
jmp start
|
||||||
nop
|
nop
|
||||||
|
|
||||||
;1.44 MB 3.5" floppy disk description table
|
;Disk description tables
|
||||||
OEMLabel db "ETTINOS "
|
|
||||||
BytesPerSector dw 0x200
|
%ifdef F1440
|
||||||
SectorsPerCluster db 0x1
|
;1.44 MB 3.5" floppy disk (enable by passing -d F1440 to NASM)
|
||||||
BootRecordSectors dw 0x1
|
oemlabel db "ETTINOS "
|
||||||
FATs db 0x2
|
sectorsize dw 0x200 ;bytes
|
||||||
RootEntries dw 0xe0
|
clustersize db 0x1 ;sectors
|
||||||
LogicalSectors dw 0xb40
|
bootsectors dw 0x1
|
||||||
MediaDescriptor db 0xf0
|
fats db 0x2
|
||||||
SectorsPerFAT dw 0x9
|
rootentries dw 0xe0
|
||||||
SectorsPerTrack dw 0x12
|
logicalsectors dw 0xb40
|
||||||
Sides dw 0x2
|
mediadescriptor db 0xf0
|
||||||
HiddenSectors dd 0x0
|
sectorsperfat dw 0x9
|
||||||
LargeSectors dd 0x0
|
sectorspertrack dw 0x12
|
||||||
DriveNumber dw 0x0
|
sides dw 0x2
|
||||||
DriveSignature db 0x29
|
hiddensectors dd 0x0
|
||||||
VolumeID dd 0x0
|
largesectors dd 0x0
|
||||||
VolumeLabel db "ETTINOS "
|
driveid dw 0x0
|
||||||
FileSystem db "FAT12 "
|
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:
|
start:
|
||||||
|
|
||||||
|
@ -38,9 +66,13 @@ sti
|
||||||
;Store the boot device number
|
;Store the boot device number
|
||||||
mov [bootdev], dl
|
mov [bootdev], dl
|
||||||
|
|
||||||
;Load the root FAT
|
;Load the root
|
||||||
;Set the source
|
;Set the source
|
||||||
mov ax, 0x13
|
mov ah, 0x0
|
||||||
|
mov al, [fats]
|
||||||
|
mul word [sectorsperfat]
|
||||||
|
add ax, [bootsectors]
|
||||||
|
push ax
|
||||||
call calcsource
|
call calcsource
|
||||||
;Set the destination
|
;Set the destination
|
||||||
mov si, 0x7e00
|
mov si, 0x7e00
|
||||||
|
@ -48,18 +80,25 @@ mov bx, ds
|
||||||
mov es, bx
|
mov es, bx
|
||||||
mov bx, si
|
mov bx, si
|
||||||
;Set the size
|
;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
|
;Load
|
||||||
mov ah, 0x2
|
mov ah, 0x2
|
||||||
int 0x13
|
int 0x13
|
||||||
|
|
||||||
;Search the root FAT for the system FAT
|
;Search the root for the system
|
||||||
;Set DI to the root FAT
|
;Set DI to the root FAT
|
||||||
mov ax, ds
|
mov ax, ds
|
||||||
mov es, ax
|
mov es, ax
|
||||||
mov di, 0x7e00
|
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
|
||||||
search:
|
search:
|
||||||
;Store CX in the stack
|
;Store CX in the stack
|
||||||
|
@ -68,7 +107,7 @@ push cx
|
||||||
mov si, sysfile
|
mov si, sysfile
|
||||||
mov cx, 0xb
|
mov cx, 0xb
|
||||||
rep cmpsb
|
rep cmpsb
|
||||||
je loadsysfat
|
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, 0x7e00
|
||||||
|
@ -78,7 +117,9 @@ pop cx
|
||||||
loop search
|
loop search
|
||||||
|
|
||||||
;Load the system FAT
|
;Load the system FAT
|
||||||
loadsysfat:
|
loadfat:
|
||||||
|
;Load CX from the stack
|
||||||
|
pop cx
|
||||||
;Store the first cluster
|
;Store the first cluster
|
||||||
mov ax, word [es:di+0xf]
|
mov ax, word [es:di+0xf]
|
||||||
mov word [cluster], ax
|
mov word [cluster], ax
|
||||||
|
@ -89,16 +130,23 @@ call calcsource
|
||||||
mov di, 0x7e00
|
mov di, 0x7e00
|
||||||
mov bx, di
|
mov bx, di
|
||||||
;Set the size
|
;Set the size
|
||||||
mov al, 0x9
|
mov ax, [sectorsperfat]
|
||||||
;Load
|
;Load
|
||||||
mov ah, 0x2
|
mov ah, 0x2
|
||||||
int 0x13
|
int 0x13
|
||||||
|
|
||||||
;Load the system
|
;Load the system file
|
||||||
loadsys:
|
|
||||||
|
;Load a cluster
|
||||||
|
loadcluster:
|
||||||
;Set the source
|
;Set the source
|
||||||
mov ax, word [cluster]
|
pop bx
|
||||||
add ax, 0x1f
|
pop ax
|
||||||
|
push ax
|
||||||
|
push bx
|
||||||
|
add ax, bx
|
||||||
|
sub ax, 0x2
|
||||||
|
add ax, word [cluster]
|
||||||
call calcsource
|
call calcsource
|
||||||
;Set the destination
|
;Set the destination
|
||||||
mov ax, 0x0
|
mov ax, 0x0
|
||||||
|
@ -106,7 +154,7 @@ mov es, ax
|
||||||
mov bx, word [pointer]
|
mov bx, word [pointer]
|
||||||
;Set the size
|
;Set the size
|
||||||
mov al, 0x1
|
mov al, 0x1
|
||||||
;Load a cluster
|
;Load
|
||||||
mov ah, 0x2
|
mov ah, 0x2
|
||||||
int 0x13
|
int 0x13
|
||||||
|
|
||||||
|
@ -115,7 +163,7 @@ mov ax, [cluster]
|
||||||
mov dx, 0x0
|
mov dx, 0x0
|
||||||
mov bx, 0x3
|
mov bx, 0x3
|
||||||
mul bx
|
mul bx
|
||||||
mov bx, 2
|
mov bx, 0x2
|
||||||
div bx
|
div bx
|
||||||
mov si, 0x7e00
|
mov si, 0x7e00
|
||||||
add si, ax
|
add si, ax
|
||||||
|
@ -123,45 +171,43 @@ mov ax, word [ds:si]
|
||||||
or dx, dx
|
or dx, dx
|
||||||
jz even
|
jz even
|
||||||
odd:
|
odd:
|
||||||
shr ax, 4
|
shr ax, 1
|
||||||
jmp contcluster
|
shr ax, 1
|
||||||
|
shr ax, 1
|
||||||
|
shr ax, 1
|
||||||
|
jmp contcalc
|
||||||
even:
|
even:
|
||||||
and ax, 0xfff
|
and ax, 0xfff
|
||||||
contcluster:
|
contcalc:
|
||||||
mov word [cluster], ax
|
mov word [cluster], ax
|
||||||
cmp ax, 0xff8
|
cmp ax, 0xff8
|
||||||
jge boot
|
jge boot
|
||||||
add word [pointer], 0x200
|
add word [pointer], 0x200
|
||||||
jmp loadsys
|
jmp loadcluster
|
||||||
|
|
||||||
boot:
|
boot:
|
||||||
jmp 0x0:0x9e00
|
jmp 0x0:0x9e00
|
||||||
|
|
||||||
sysfile:
|
sysfile db "SYSTEM BIN"
|
||||||
db "SYSTEM BIN"
|
|
||||||
|
|
||||||
bootdev:
|
bootdev db 0x0
|
||||||
db 0
|
|
||||||
|
|
||||||
cluster:
|
cluster dw 0x0
|
||||||
dw 0x0
|
pointer dw 0x9e00
|
||||||
|
|
||||||
pointer:
|
|
||||||
dw 0x9e00
|
|
||||||
|
|
||||||
calcsource:
|
calcsource:
|
||||||
push ax
|
push ax
|
||||||
push bx
|
push bx
|
||||||
mov bx, ax
|
mov bx, ax
|
||||||
mov dx, 0x0
|
mov dx, 0x0
|
||||||
div word [SectorsPerTrack]
|
div word [sectorspertrack]
|
||||||
add dl, 0x1
|
add dl, 0x1
|
||||||
mov cl, dl
|
mov cl, dl
|
||||||
mov ax, bx
|
mov ax, bx
|
||||||
mov dx, 0x0
|
mov dx, 0x0
|
||||||
div word [SectorsPerTrack]
|
div word [sectorspertrack]
|
||||||
mov dx, 0x0
|
mov dx, 0x0
|
||||||
div word [Sides]
|
div word [sides]
|
||||||
mov dh, dl
|
mov dh, dl
|
||||||
mov ch, al
|
mov ch, al
|
||||||
pop bx
|
pop bx
|
||||||
|
|
|
@ -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:
|
byte2hex:
|
||||||
|
|
||||||
;Store the initial registers in the stack
|
;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
|
;Set a key for the hex digits
|
||||||
mov si, .key
|
mov si, .key
|
||||||
|
@ -14,7 +20,10 @@ mov cx, 0x2
|
||||||
.loop:
|
.loop:
|
||||||
|
|
||||||
;Read a nibble
|
;Read a nibble
|
||||||
rol ax, 0x4
|
rol ax, 0x1
|
||||||
|
rol ax, 0x1
|
||||||
|
rol ax, 0x1
|
||||||
|
rol ax, 0x1
|
||||||
mov bx, ax
|
mov bx, ax
|
||||||
|
|
||||||
;Convert the nibble to a hex digit
|
;Convert the nibble to a hex digit
|
||||||
|
@ -30,9 +39,11 @@ dec cx
|
||||||
jnz .loop
|
jnz .loop
|
||||||
|
|
||||||
;Load the initial registers from the stack
|
;Load the initial registers from the stack
|
||||||
popa
|
pop cx
|
||||||
|
pop bx
|
||||||
|
pop ax
|
||||||
|
pop si
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.key:
|
.key db "0123456789abcdef"
|
||||||
db "0123456789abcdef"
|
|
||||||
|
|
|
@ -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:
|
cmpstr:
|
||||||
|
|
||||||
;Store the initial registers in the stack
|
;Store the initial registers in the stack
|
||||||
pusha
|
push ax
|
||||||
|
push bx
|
||||||
|
|
||||||
.loop:
|
.loop:
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ stc
|
||||||
.done:
|
.done:
|
||||||
|
|
||||||
;Load the initial registers from the stack
|
;Load the initial registers from the stack
|
||||||
popa
|
pop bx
|
||||||
|
pop ax
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -7,5 +7,4 @@ call println
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.hello:
|
.hello db "Hello world!", 0x0
|
||||||
db "Hello world!", 0x0
|
|
|
@ -7,5 +7,4 @@ call println
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.help:
|
.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
|
||||||
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
|
|
||||||
|
|
|
@ -15,12 +15,12 @@ mov si, .prefix
|
||||||
call printstr
|
call printstr
|
||||||
|
|
||||||
;Convert the scancode to a hex string
|
;Convert the scancode to a hex string
|
||||||
mov ah, [.scan]
|
mov al, [.scan]
|
||||||
mov di, .keycode
|
mov di, .keycode
|
||||||
call byte2hex
|
call byte2hex
|
||||||
|
|
||||||
;Convert the ascii value to a hex string
|
;Convert the ascii value to a hex string
|
||||||
mov ah, [.ascii]
|
mov al, [.ascii]
|
||||||
mov di, .keycode
|
mov di, .keycode
|
||||||
add di, 0x2
|
add di, 0x2
|
||||||
call byte2hex
|
call byte2hex
|
||||||
|
@ -31,14 +31,9 @@ call println
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.prefix:
|
.prefix db "0x", 0x0
|
||||||
db "0x", 0x0
|
|
||||||
|
|
||||||
.scan:
|
.scan db 0x0
|
||||||
db 0x0
|
.ascii db 0x0
|
||||||
|
|
||||||
.ascii:
|
.keycode times 0x5 db 0x0
|
||||||
db 0x0
|
|
||||||
|
|
||||||
.keycode:
|
|
||||||
times 0x5 db 0x0
|
|
||||||
|
|
|
@ -3,16 +3,15 @@
|
||||||
printnl:
|
printnl:
|
||||||
|
|
||||||
;Store the initial registers in the stack
|
;Store the initial registers in the stack
|
||||||
pusha
|
push si
|
||||||
|
|
||||||
;Print the newline
|
;Print the newline
|
||||||
mov si, .nl
|
mov si, .nl
|
||||||
call printstr
|
call printstr
|
||||||
|
|
||||||
;Load the initial registers from the stack
|
;Load the initial registers from the stack
|
||||||
popa
|
pop si
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.nl:
|
.nl db 0xd, 0xa, 0x0
|
||||||
db 0xd, 0xa, 0x0
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
printstr:
|
printstr:
|
||||||
|
|
||||||
;Store the initial registers in the stack
|
;Store the initial registers in the stack
|
||||||
pusha
|
push ax
|
||||||
|
|
||||||
.loop:
|
.loop:
|
||||||
|
|
||||||
|
@ -24,6 +24,6 @@ jmp .loop
|
||||||
.done:
|
.done:
|
||||||
|
|
||||||
;Load the initial registers from the stack
|
;Load the initial registers from the stack
|
||||||
popa
|
pop ax
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -25,5 +25,4 @@ pop bx
|
||||||
mov ah, bh
|
mov ah, bh
|
||||||
pop bx
|
pop bx
|
||||||
|
|
||||||
.done:
|
|
||||||
ret
|
ret
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
readstr:
|
readstr:
|
||||||
|
|
||||||
;Store the initial registers in the stack
|
;Store the initial registers in the stack
|
||||||
pusha
|
push ax
|
||||||
|
push bx
|
||||||
|
push cx
|
||||||
|
push dx
|
||||||
|
|
||||||
;Store the input length in the stack
|
;Store the input length in the stack
|
||||||
mov ah, 0
|
mov ah, 0
|
||||||
|
@ -116,7 +119,10 @@ jmp .findend
|
||||||
.done:
|
.done:
|
||||||
|
|
||||||
;Load the initial registers from the stack
|
;Load the initial registers from the stack
|
||||||
popa
|
pop dx
|
||||||
|
pop cx
|
||||||
|
pop bx
|
||||||
|
pop ax
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
[ORG 0x9e00]
|
CPU 8086
|
||||||
|
ORG 0x9e00
|
||||||
|
|
||||||
jmp start
|
jmp start
|
||||||
|
|
||||||
;Calls
|
;Calls
|
||||||
|
@ -86,26 +88,18 @@ mov si, error
|
||||||
call println
|
call println
|
||||||
jmp loop
|
jmp loop
|
||||||
|
|
||||||
cpl:
|
cpl db 0x0
|
||||||
db 0x0
|
|
||||||
|
|
||||||
welcome:
|
welcome db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0
|
||||||
db 0xd, 0xa, "Welcome to EttinOS!", 0xd, 0xa, 0x0
|
|
||||||
|
|
||||||
prompt:
|
prompt db "> ", 0x0
|
||||||
db "> ", 0x0
|
|
||||||
|
|
||||||
cmd:
|
cmd:
|
||||||
.echo:
|
.echo db "echo", 0x0
|
||||||
db "echo", 0x0
|
.hello db "hello", 0x0
|
||||||
.hello:
|
.help db "help", 0x0
|
||||||
db "hello", 0x0
|
.keycode db "keycode", 0x0
|
||||||
.help:
|
|
||||||
db "help", 0x0
|
|
||||||
.keycode:
|
|
||||||
db "keycode", 0x0
|
|
||||||
error:
|
|
||||||
db "Unknown command", 0x0
|
|
||||||
|
|
||||||
buffer:
|
error db "Unknown command", 0x0
|
||||||
times 0xff db 0
|
|
||||||
|
buffer times 0xff db 0
|
||||||
|
|
11
make.sh
11
make.sh
|
@ -1,11 +1,18 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
cd SOURCE/
|
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
|
nasm SYSTEM.ASM -f bin -o ../SYSTEM.BIN
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
rm -f EttinOS.img
|
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
|
dd if=BOOT.BIN of=EttinOS.img conv=notrunc bs=512 count=1
|
||||||
mcopy -i EttinOS.img SYSTEM.BIN ::
|
mcopy -i EttinOS.img SYSTEM.BIN ::
|
||||||
|
|
Loading…
Reference in New Issue