diff --git a/.sh b/.sh new file mode 100644 index 0000000..d1195cc --- /dev/null +++ b/.sh @@ -0,0 +1,3 @@ +sudo apt install make nasm qemu +# snap install micro --classic + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5c9b733 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 chibicitiberiu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..30ebb9d --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +ASM=nasm + +SRC_DIR=src +BUILD_DIR=build + +$(BUILD_DIR)/main_floppy.img: $(BUILD_DIR)/main.bin + cp $(BUILD_DIR)/main.bin $(BUILD_DIR)/main_floppy.img + truncate -s 1440k $(BUILD_DIR)/main_floppy.img + +$(BUILD_DIR)/main.bin: $(SRC_DIR)/main.asm + $(ASM) $(SRC_DIR)/main.asm -f bin -o $(BUILD_DIR)/main.bin diff --git a/build/main.bin b/build/main.bin new file mode 100644 index 0000000..11a8f14 Binary files /dev/null and b/build/main.bin differ diff --git a/build/main_floppy.img b/build/main_floppy.img new file mode 100644 index 0000000..c0a0e8c Binary files /dev/null and b/build/main_floppy.img differ diff --git a/install_packages.sh b/install_packages.sh new file mode 100644 index 0000000..6b361dd --- /dev/null +++ b/install_packages.sh @@ -0,0 +1,2 @@ +sudo apt install make nasm qemu + diff --git a/src/main.asm b/src/main.asm new file mode 100644 index 0000000..a8c29e4 --- /dev/null +++ b/src/main.asm @@ -0,0 +1,67 @@ +; https://github.com/nanobyte-dev/nanobyte_os/blob/Part1/src/main.asm +org 0x7C00 +bits 16 + + +%define ENDL 0x0D, 0x0A + + +start: + jmp main + + +; +; Prints a string to the screen +; Params: +; - ds:si points to string +; +puts: + ; save registers we will modify + push si + push ax + push bx + +.loop: + lodsb ; loads next character in al + or al, al ; verify if next character is null? + jz .done + + mov ah, 0x0E ; call bios interrupt + mov bh, 0 ; set page number to 0 + int 0x10 + + jmp .loop + +.done: + pop bx + pop ax + pop si + ret + + +main: + ; setup data segments + mov ax, 0 ; can't set ds/es directly + mov ds, ax + mov es, ax + + ; setup stack + mov ss, ax + mov sp, 0x7C00 ; stack grows downwards from where we are loaded in memory + + ; print hello world message + mov si, msg_hello + call puts + + hlt + +.halt + jmp .halt + + + +msg_hello: db 'Hello world!', ENDL, 0 + + +times 510-($-$$) db 0 +dw 0AA55h diff --git a/start-qemu.sh b/start-qemu.sh new file mode 100755 index 0000000..52f414b --- /dev/null +++ b/start-qemu.sh @@ -0,0 +1 @@ +qemu-system-i386 -fda build/main_floppy.img