diff --git a/SOURCE/BOOT.ASM b/SOURCE/BOOT.ASM new file mode 100644 index 0000000..d60eb06 --- /dev/null +++ b/SOURCE/BOOT.ASM @@ -0,0 +1,176 @@ +[ORG 0x7c00] +jmp short 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 " + +start: + +;Set up the data segment +mov ax, 0x0 +mov ds, ax + +;Set up the stack +cli +mov ax, 0x0 +mov ss, ax +mov sp, 0x7c00 +sti + +;Store the boot device number +mov [bootdev], dl + +;Load the root FAT +;Set the source +mov ax, 0x13 +call calcsource +;Set the destination +mov si, 0x7e00 +mov bx, ds +mov es, bx +mov bx, si +;Set the size +mov al, 0xe +;Load +mov ah, 0x2 +int 0x13 + +;Search the root FAT 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 ax, 0x0 +search: +;Store CX in the stack +push cx +;Check for the binary +mov si, sysfile +mov cx, 0xb +rep cmpsb +je loadsysfat +;Set DI to the next entry +add ax, 0x20 +mov di, 0x7e00 +add di, ax +;Load CX from the stack +pop cx +loop search + +;Load the system FAT +loadsysfat: +;??? +mov ax, word [es:di+0xf] +mov word [cluster], ax +;Set the source +mov ax, 0x1 +call calcsource +;Set the destination +mov di, 0x7e00 +mov bx, di +;Set the size +mov al, 0x9 +;Load +mov ah, 0x2 +int 0x13 + +;Load the system +loadsys: +;Set the source +mov ax, word [cluster] +add ax, 0x1f +call calcsource +;Set the destination +mov ax, 0x0 +mov es, ax +mov bx, word [pointer] +;Set the size +mov al, 0x1 +;Load a cluster +mov ah, 0x2 +int 0x13 + +;Calculate the next cluster +mov ax, [cluster] +mov dx, 0x0 +mov bx, 0x3 +mul bx +mov bx, 2 +div bx +mov si, 0x7e00 +add si, ax +mov ax, word [ds:si] +or dx, dx +jz even +odd: +shr ax, 4 +jmp contcluster +even: +and ax, 0xfff +contcluster: +mov word [cluster], ax +cmp ax, 0xff8 +jge boot +add word [pointer], 0x200 +jmp loadsys + +boot: +jmp 0x0:0x9e00 + +sysfile: +db "SYSTEM BIN" + +bootdev: +db 0 + +cluster: +dw 0x0 + +pointer: +dw 0x9e00 + +calcsource: +push ax +push bx +mov bx, ax +mov dx, 0x0 +div word [SectorsPerTrack] +add dl, 0x1 +mov cl, dl +mov ax, bx +mov dx, 0x0 +div word [SectorsPerTrack] +mov dx, 0x0 +div word [Sides] +mov dh, dl +mov ch, al +pop bx +pop ax +mov dl, byte [bootdev] +ret + +;Padding +times 0x1fe-($-$$) db 0x0 + +;Boot signature +dw 0xaa55 diff --git a/source/byte2hexstr.inc b/SOURCE/BYTE2HEX.INC similarity index 97% rename from source/byte2hexstr.inc rename to SOURCE/BYTE2HEX.INC index 1dcdee3..a3588b2 100644 --- a/source/byte2hexstr.inc +++ b/SOURCE/BYTE2HEX.INC @@ -1,6 +1,6 @@ ;Converts a byte in ah to a hex string at di. -byte2hexstr: +byte2hex: ;Store the initial registers in the stack pusha diff --git a/source/cmpstr.inc b/SOURCE/CMPSTR.INC similarity index 100% rename from source/cmpstr.inc rename to SOURCE/CMPSTR.INC diff --git a/source/echo.inc b/SOURCE/ECHO.INC similarity index 100% rename from source/echo.inc rename to SOURCE/ECHO.INC diff --git a/source/hello.inc b/SOURCE/HELLO.INC similarity index 100% rename from source/hello.inc rename to SOURCE/HELLO.INC diff --git a/source/help.inc b/SOURCE/HELP.INC similarity index 100% rename from source/help.inc rename to SOURCE/HELP.INC diff --git a/source/keycode.inc b/SOURCE/KEYCODE.INC similarity index 93% rename from source/keycode.inc rename to SOURCE/KEYCODE.INC index 64268d9..263dc95 100644 --- a/source/keycode.inc +++ b/SOURCE/KEYCODE.INC @@ -17,13 +17,13 @@ call printstr ;Convert the scancode to a hex string mov ah, [.scan] mov di, .keycode -call byte2hexstr +call byte2hex ;Convert the ascii value to a hex string mov ah, [.ascii] mov di, .keycode add di, 0x2 -call byte2hexstr +call byte2hex ;Print the keycode mov si, .keycode diff --git a/source/println.inc b/SOURCE/PRINTLN.INC similarity index 89% rename from source/println.inc rename to SOURCE/PRINTLN.INC index 86db73c..911b38f 100644 --- a/source/println.inc +++ b/SOURCE/PRINTLN.INC @@ -6,6 +6,6 @@ println: call printstr ;Print a newline -call printcrlf +call printnl ret diff --git a/source/printcrlf.inc b/SOURCE/PRINTNL.INC similarity index 84% rename from source/printcrlf.inc rename to SOURCE/PRINTNL.INC index 88814fd..9d603db 100644 --- a/source/printcrlf.inc +++ b/SOURCE/PRINTNL.INC @@ -1,12 +1,12 @@ ;Prints a newline -printcrlf: +printnl: ;Store the initial registers in the stack pusha ;Print the newline -mov si, .crlf +mov si, .nl call printstr ;Load the initial registers from the stack @@ -14,5 +14,5 @@ popa ret -.crlf: +.nl: db 0xd, 0xa, 0x0 diff --git a/source/printstr.inc b/SOURCE/PRINTSTR.INC similarity index 100% rename from source/printstr.inc rename to SOURCE/PRINTSTR.INC diff --git a/source/readln.inc b/SOURCE/READLN.INC similarity index 90% rename from source/readln.inc rename to SOURCE/READLN.INC index 451b380..572edd6 100644 --- a/source/readln.inc +++ b/SOURCE/READLN.INC @@ -6,6 +6,6 @@ readln: call readstr ;Print a newline -call printcrlf +call printnl ret diff --git a/source/readstr.inc b/SOURCE/READSTR.INC similarity index 100% rename from source/readstr.inc rename to SOURCE/READSTR.INC diff --git a/source/system.asm b/SOURCE/SYSTEM.ASM similarity index 80% rename from source/system.asm rename to SOURCE/SYSTEM.ASM index 9feec80..0d76431 100644 --- a/source/system.asm +++ b/SOURCE/SYSTEM.ASM @@ -1,20 +1,20 @@ -[ORG 0x7e00] +[ORG 0x9e00] jmp start ;Calls -%include "printcrlf.inc" -%include "printstr.inc" -%include "println.inc" -%include "readstr.inc" -%include "readln.inc" -%include "cmpstr.inc" -%include "byte2hexstr.inc" +%include "PRINTNL.INC" +%include "PRINTSTR.INC" +%include "PRINTLN.INC" +%include "READSTR.INC" +%include "READLN.INC" +%include "CMPSTR.INC" +%include "BYTE2HEX.INC" ;Commands -%include "echo.inc" -%include "hello.inc" -%include "help.inc" -%include "keycode.inc" +%include "ECHO.INC" +%include "HELLO.INC" +%include "HELP.INC" +%include "KEYCODE.INC" start: diff --git a/make.sh b/make.sh index 6f4e029..dfaa6fa 100755 --- a/make.sh +++ b/make.sh @@ -1,8 +1,14 @@ #!/bin/bash -cd source/ -nasm boot.asm -f bin -O0 -o ../boot.bin -nasm system.asm -f bin -O0 -o ../system.bin +cd SOURCE/ +nasm BOOT.ASM -f bin -O0 -o ../BOOT.BIN +nasm SYSTEM.ASM -f bin -O0 -o ../SYSTEM.BIN cd .. -cat boot.bin system.bin > EttinOS.img +if [[ -f EttinOS.img ]] +then + rm EttinOS.img +fi +mkfs.fat -C EttinOS.img 1440 +mcopy -i EttinOS.img SYSTEM.BIN :: +dd if=BOOT.BIN of=EttinOS.img conv=notrunc bs=512 count=1 diff --git a/source/boot.asm b/source/boot.asm deleted file mode 100644 index 74fda39..0000000 --- a/source/boot.asm +++ /dev/null @@ -1,60 +0,0 @@ -[ORG 0x7c00] -jmp short start -nop - -;Disk description table -db "EttinOS " ;Disk label -dw 0x200 ;Bytes per sector -db 0x1 ;Sectors per cluster -dw 0x1 ;Sectors reserved for the boot record -db 0x2 ;Number of copies of the FAT -dw 0xe0 ;Number of directory entries -dw 0xb40 ;Number of logical sectors -db 0xf0 ;Media descriptor type -dw 0x9 ;Sectors per FAT -dw 0x12 ;Sectors per track -dw 0x2 ;Number of heads -dd 0x0 ;Number of hidden sectors -dd 0x0 ;Number of LBA sectors -dw 0x0 ;Drive number -db 0x29 ;Drive signature -dd 0x0 ;Volume ID -db "EttinOS " ;Volume label -db "FAT12 " ;File system type - -start: - -;Set up the data segment -mov ax, 0x0 -mov ds, ax - -;Set up the stack -cli -mov ax, 0x0 -mov ss, ax -mov sp, 0x7c00 -sti - -;Load the system -;Set the source -mov dh, 0x0 -mov ch, 0x0 -mov cl, 0x2 -;Set the destination -mov ax, 0x0 -mov es, ax -mov bx, 0x7e00 -;Set the size -mov al, 0x5 -;Load -mov ah, 0x2 -int 0x13 - -;Boot the system -jmp 0x0:0x7e00 - -;Padding -times 0x1fe-($-$$) db 0x0 - -;Boot signature -dw 0xaa55