├── LICENSE ├── Makefile ├── README.md ├── build └── placeholder_floppy.img └── src └── main.asm /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Lucas Gabriel 4 | 5 | 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: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | 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. 10 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ASM=nasm 2 | 3 | SRC_DIR=src 4 | BUILD_DIR=build 5 | 6 | $(BUILD_DIR)/main_floppy.img: $(BUILD_DIR)/main.bin 7 | cp $(BUILD_DIR)/main.bin $(BUILD_DIR)/main_floppy.img 8 | truncate -s 1440k $(BUILD_DIR)/main_floppy.img 9 | 10 | $(BUILD_DIR)/main.bin: $(SRC_DIR)/main.asm 11 | $(ASM) $(SRC_DIR)/main.asm -f bin -o $(BUILD_DIR)/main.bin 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # asm_x86_sys 2 | 3 | This repo contains the code for a simple Operating System that shows the message "Hello World!" when booted. 4 | 5 | Following the ["Building an OS"](https://www.youtube.com/watch?v=9t-SPC7Tczc&list=PLFjM7v6KGMpiH2G-kT781ByCNC_0pKpPN) tutorial. 6 | 7 | ### Pre-requisites 8 | Any Linux distribution or macOS (via Homebrew). If you use Windows, you can try [WSL (Linux on Windows)](https://learn.microsoft.com/en-us/windows/wsl/install). 9 | 10 | ### Installing tools 11 | Run the commands below to install Make, NASM (the Assembly compiler) and the QEMU Virtual Machine system. 12 | ```sh 13 | sudo apt install make nasm qemu qemu-system-x86 14 | ``` 15 | 16 | ### Compiling and testing 17 | Run the commands below to compile the ASM file inside /src and run the OS: 18 | ```sh 19 | make && qemu-system-i386 -fda build/main_floppy.img 20 | ``` 21 | 22 | Credits: nanobyte - [GitHub](https://github.com/nanobyte-dev), [YouTube](https://www.youtube.com/@nanobyte-dev) 23 | -------------------------------------------------------------------------------- /build/placeholder_floppy.img: -------------------------------------------------------------------------------- 1 | # This floppy image does nothing. Compile the OS using the instructions on the README file. 2 | # :) 3 | -------------------------------------------------------------------------------- /src/main.asm: -------------------------------------------------------------------------------- 1 | org 0x7C00 2 | bits 16 3 | 4 | %define ENDL 0x0D, 0x0A 5 | 6 | 7 | start: 8 | jmp main 9 | 10 | ; 11 | ; Prints a string to the screen. 12 | ; Params: 13 | ; -ds:si points to string 14 | ; 15 | puts: 16 | ; save registers we will modify 17 | push si 18 | push ax 19 | 20 | .loop: 21 | lodsb ; loads next character in al 22 | or al, al ; verify if next character is null? 23 | jz .done 24 | 25 | mov ah, 0x0e ; call bios interrupt 26 | mov bh, 0 27 | int 0x10 28 | 29 | jmp .loop 30 | 31 | .done: 32 | pop ax 33 | pop si 34 | ret 35 | 36 | main: 37 | ; setup data segments 38 | mov ax, 0 ; can't write to ds/es directly 39 | mov ds, ax 40 | mov es, ax 41 | 42 | ; setup stack 43 | mov ss, ax 44 | mov sp, 0x7C00 ; stack grows downwards from where we are loaded in memory 45 | 46 | ; print message 47 | mov si, msg_hello 48 | call puts 49 | 50 | hlt 51 | 52 | .halt: 53 | jmp .halt 54 | 55 | 56 | msg_hello: db 'Hello World!', ENDL, 0 57 | 58 | times 510-($-$$) db 0 59 | dw 0AA55h 60 | --------------------------------------------------------------------------------