From 3d4615d27651fc32389d9ce9d5ef793923382275 Mon Sep 17 00:00:00 2001 From: d0p1 Date: Wed, 6 May 2020 12:40:10 +0200 Subject: [PATCH] first commit --- .gitignore | 4 +++ LICENSE | 29 ++++++++++++++++++ Makefile | 20 +++++++++++++ README.md | 4 +++ boot/floppy.s | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ kern/kernel.s | 0 6 files changed, 138 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 boot/floppy.s create mode 100644 kern/kernel.s diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..242cbeb --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.o +*.img +*.bin +*~ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fd4bae7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2020, d0p1 +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..261883c --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +all: stupid.img + +stupid.img: floppy.bin kern.bin + cat $^ /dev/zero | dd of=$@ bs=512 count=2880 + +floppy.bin: boot/floppy.s + nasm -fbin -o $@ $^ + +kern.bin: kern/kernel.s + nasm -fbin -o $@ $^ + +clean: + rm floppy.bin kern.bin + +fclean: + rm stupid.img + +re: fclean all + +.PHONY: all clean fclean re diff --git a/README.md b/README.md new file mode 100644 index 0000000..8205a9f --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# StupidOS + +16bit real mode Operating System in assembly + diff --git a/boot/floppy.s b/boot/floppy.s new file mode 100644 index 0000000..69d9108 --- /dev/null +++ b/boot/floppy.s @@ -0,0 +1,81 @@ + [ORG 0x7c00] + [BITS 16] + + jmp short entry + nop + + ;; ----------------------------------------------------------- + ;; OEM & Bios Parameter Block + ;; ----------------------------------------------------------- + db "StupidOS" + + dw 512 ; bytes per sector + db 1 ; sector per cluster + dw 1 ; reserved sector + db 2 ; number of FATs + dw 224 ; root entries + dw 2400 ; total sector + db 0xF9 ; media descriptor type + dw 7 ; sectors per FAT + dw 15 ; sectors per track + dw 2 ; heads per cylinder + dd 0 ; hidden sectors + dd 0 ; total sector big + db 0 ; drive number + db 0 ; unused + db 0x29 ; drive signature (0x29 = floppy) + dd 0x00000000 ; serial number (ignore) + db 'STUPID DISK' ; volume label + db 'FAT12 ' ; filesystem type + + ;; ----------------------------------------------------------- + ;; Print string using bios interrupt + ;; ----------------------------------------------------------- +boot_print: + pusha +.loop: + lodsb + cmp al, 0 + jz .end + mov ah, 0x0E ; bios print + mov bx, 0x07 + int 0x10 + jmp .loop +.end: + popa + ret + + ;; ----------------------------------------------------------- + ;; Variables + ;; ----------------------------------------------------------- + copyright db "Copyright (c) d0p1", 13, 10, 0 + err_disk_reset db "Error reseting disk..retry", 13, 10, 0 + + ;; ----------------------------------------------------------- + ;; entry + ;; ----------------------------------------------------------- +entry: + xor ax, ax + mov ds, ax + + mov si, copyright + call boot_print +reset_disk: + xor ah, ah + xor dl, dl + int 0x13 + jnc .reset_disk_end + mov si, err_disk_reset + call boot_print + jmp reset_disk +.reset_disk_end: + +hang: + jmp hang + cli + hlt + + times 510-($-$$) db 0 + db 0x55 + db 0xAA + diff --git a/kern/kernel.s b/kern/kernel.s new file mode 100644 index 0000000..e69de29