commit 893a9b9d932c574a27475cf273f1c7aaae9173b0
parent d56b7442a419310caff2742085fa951a4b77b841
Author: Georges Dupéron <georges.duperon@gmail.com>
Date: Sun, 8 Jul 2018 02:58:10 +0200
Added partition table to OS image, automatically format the first partition using FAT12
Diffstat:
3 files changed, 43 insertions(+), 16 deletions(-)
diff --git a/.travis.yml b/.travis.yml
@@ -19,6 +19,7 @@ addons:
- wmctrl
# example-os build dependencies:
- nasm
+ - mtools
matrix:
include:
diff --git a/example-os/Makefile b/example-os/Makefile
@@ -1,6 +1,12 @@
os_filename = os.bat
tests = test/qemu-system-i386 test/qemu-system-arm test/virtualbox test/bochs test/gui-sh test/dosbox
+os_image_size_kb = 1440
+os_sectors_before_partition = 720
+# CHS parameters for 1.44 MB floppy disk
+os_floppy_chs_h = 2
+os_floppy_chs_s = 9
+
.PHONY: all
# all: os.arm.disasm
all: $(os_filename) os.ndisasm.disasm os.reasm.asm os.reasm os.file .gitignore Makefile
@@ -12,6 +18,12 @@ all: $(os_filename) os.ndisasm.disasm os.reasm.asm os.reasm os.file .gitignore M
$(os_filename): os.asm ../deploy-screenshots Makefile
rm -f $@
nasm -o $@ $<
+ mformat -v "Example OS" \
+ -T $$(($(os_image_size_kb)*1024/512-$(os_sectors_before_partition))) \
+ -h $(os_floppy_chs_h) \
+ -s $(os_floppy_chs_s) \
+ -i "$@@@$$(($(os_sectors_before_partition)*512))"
+# mcopy … "$@@@$$(($(os_sectors_before_partition)*512))"
chmod a+x-w $@
os.file: $(os_filename) Makefile
diff --git a/example-os/os.asm b/example-os/os.asm
@@ -5,23 +5,24 @@ db `#!/usr/bin/env sh\n`
db `: <<'EOF'\n`
db `GOTO msdos\n`
+;;; The #!… above is interpreted as … jnz short 0x7c78 in x86 assembly.
times 0x7c78-0x7c00-($-$$) db 0
-
-;; Switch to 320x200x256 VGA mode
+
+;;; Switch to 320x200x256 VGA mode
mov ax, 0x0013
int 10h
-;; Framebuffer address is 0xa000, store it into the fs register (the segment base, in multiples of 16)
+;;; Framebuffer address is 0xa000, store it into the fs register (the segment base, in multiples of 16)
push 0xa000
pop fs
-;; Set pixel value (0, then increase at each step below)
+;;; Set pixel value (0, then increase at each step below)
xor bl, bl
-;; set register di to 0
+;;; set register di to 0
xor di,di
-;; Store pixels, display something flashy.
+;;; Store pixels, display something flashy.
loop:
mov byte [fs:di], bl
inc bl
@@ -38,33 +39,46 @@ endline:
je end
jmp loop
-;; Infinite loop
+;;; Infinite loop
end:
jmp end
-;; Fill the remaining bytes with 0 and end with 55 AA
-times 512-2-($-$$) db 0
-db 0x55
-db 0xaa
+;;; Fill the remaining bytes with 0 and write a partition table
+times 0x1b8-($-$$) db 0
+db "ExOSxx" ;; 0x1b8 unique disk ID (4 bytes, can be any value)
+;;; Partition table entries follow this format:
+;;; 1 byte Bootable flag (0x00 = no, 0x80 = yes)
+;;; 3 bytes Start Head Sector Cylinder (8 bits + 6 bits + 10 bits)
+;;; 1 byte Partition type (0x01 = FAT12)
+;;; 3 bytes End Head Sector Cylinder (8 bits + 6 bits + 10 bits)
+;;; 4 bytes LBA offset
+;;; 4 bytes LBA length
+db 0x80, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3d, 0x0b, 0x00, 0x00 ;; 0x1be p1
+db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;; 0x1ce p2
+db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;; 0x1de p3
+db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ;; 0x1ee p4
+db 0x55, 0xaa ;; 0x1fe End the bootsector with 55 AA, which is the MBR signature.
+
+;;; This is the end of the first 512 bytes (the bootsector).
-;; end of the bootsector, close the sh here-document skipped via : <<'EOF'
+;;; After the bootsector, close the sh here-document skipped via : <<'EOF'
db `\n`
db `EOF\n`
db `echo Hello world by the OS, from sh!\n`
db `while sleep 10; do :; done\n`
db `exit\n`
-;; for good measure: go into an infinite loop if the exit did not happen.
+;;; for good measure: go into an infinite loop if the exit did not happen.
db `while :; do sleep 1; done\n`
-;; end of the SH section, everything until this point is skipped by MS-DOS batch due to the GOTO'
+;;; end of the SH section, everything until this point is skipped by MS-DOS batch due to the GOTO'
db `:msdos\n`
db `@cls\n`
db `@echo Hello world by the OS, from MS-DOS!\n`
db `command.com\n`
db `exit\n`
-;; for good measure: go into an infinite loop if the exit did not happen.
+;;; for good measure: go into an infinite loop if the exit did not happen.
db `:loop\n`
db `GOTO loop\n`
-;; Fill up to 1.44M with 0
+;;; Fill up to 1.44M with 0
times (1440*1024)-($-$$) db 0