├── README.md └── hello-world | 001 ├── README.md ├── hello-world.asm └── output.bin /README.md: -------------------------------------------------------------------------------- 1 | OSdev | OS development step by step guide 2 | ----------------------------------------- 3 | 4 | This is a guide for creating an oprating system from scarth. \ 5 | which you can face deep concepts of computers in it and undrestand how they work. 6 | 7 | 8 | Requirements 9 | ------------ 10 | 11 | - Assembly x86 12 | - C/C++ 13 | - Undrestanding of CPU architectures 14 | 15 | Repository Structure 16 | --------------------- 17 | 18 | There is a folder for each section which consists both code and documentation. 19 | start with the first one and move downwardly. 20 | 21 | Inspiration Source's 22 | -------------------- 23 | [this repository](https://github.com/cfenollosa/os-tutorial/)\ 24 | [this document](http://www.cs.bham.ac.uk/~exr/lectures/opsys/10_11/lectures/os-dev.pdf)\ 25 | [OSDev wiki](http://wiki.osdev.org/)\ 26 | [the little book about OS development](https://littleosbook.github.io)\ 27 | [JamesM's kernel development tutorials](https://web.archive.org/web/20160412174753/http://www.jamesmolloy.co.uk/tutorial_html/index.html) 28 | 29 | Contributions 30 | ------------- 31 | This is a educational purpose project. 32 | so you are gladly welcome to express your opinions and show the issuess. 33 | -------------------------------------------------------------------------------- /hello-world | 001/README.md: -------------------------------------------------------------------------------- 1 | ## What is Boot Sectors 2 | 3 | A boot sector is a physical sector on a hard drive that includes information about how to start the boot process in order to load an operating system. 4 | 5 | Note: A sector on a hard drive is a section of the disk that can be read or written to. It is typically 512 bytes in size and contains data such as file information or boot instructions. 6 | 7 | ## The BIOS 8 | 9 | BIOS stands for Basic Input/Output System, which is a program that runs on a computer's motherboard. It is responsible for initializing hardware components during the boot process and providing a basic set of instructions to the operating system to enable it to start. It also provides a low-level interface for communicating with hardware components, such as hard drives and keyboards. 10 | 11 | ## Basically How 12 | 13 | When a computer starts up, the BIOS doesn't know how to load the operating system and requires a boot sector to do so. However, since there is no operating system, there is no path to the boot sector. To load it, the BIOS must know the physical location of the boot sector on the disk, which is cylinder 0, head 0, sector 0, and it's 512 bytes in size. 14 | 15 | To ensure that a disk is bootable, the BIOS checks for a specific signature. Specifically, the 511th and 512th bytes of the boot sector must be `0xAA55`. 16 | 17 | ![](https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fqph.fs.quoracdn.net%2Fmain-qimg-4c2c19e8f68405c99d125c58414f6359&f=1&nofb=1&ipt=c72bdb62d557c3762a309d11c657982b5ea040ea4ca2ce33607b7f207d3e1fd0&ipo=images) 18 | 19 | ## The BIOS **Interrupts** 20 | 21 | BIOS interrupts are software interrupts that are triggered by the BIOS during the boot process. These interrupts provide a way for the BIOS to communicate with the operating system and other software running on the computer. They can be used to perform tasks such as reading from or writing to disk, initializing hardware components, or performing low-level system functions. When an interrupt is triggered, the processor stops executing the current program and switches to the interrupt handler, which is a special routine that performs the required task before returning control to the main program. 22 | 23 | ## The CPU Registers 24 | 25 | CPU registers are small, high-speed storage locations within the CPU that are used to hold data that is being processed or manipulated. They are typically measured in bits, such as 8-bit or 32-bit registers, and can be used to store things like memory addresses, data being processed, and status information. Registers are an important component of a computer's architecture, as they allow for fast access to frequently used data and can greatly improve performance. 26 | 27 | --- 28 | 29 | # The Code 30 | 31 | ### A Simple Boot Sector 32 | 33 | ```nasm 34 | jmp $ ;Jump to the current address (Infinite loop)**** 35 | 36 | ; Fill with 510 zeros minus the size of the previous code 37 | times 510-($-$$) db 0 38 | 39 | ; the previously mentioned bios signature 40 | dw 0xaa55 41 | ``` 42 | 43 | ### Hello World ! 44 | 45 | In order to print a single character we use the BIOS interrupt `0x10` which is responsible for various video services. 46 | 47 | with `AH` set to `0x0E` (tty mode) and `AL` set to the ASCII value of the character to be displayed will display a single character on the screen. 48 | 49 | Basically the interrupt `0x10` reads the `AX` register which is 16-bit register consisted of `AH:AL` 50 | 51 | ```nasm 52 | mov ah, 0x0e ; tty mode 53 | mov al, 'H' 54 | int 0x10 55 | mov al, 'e' 56 | int 0x10 57 | mov al, 'l' 58 | int 0x10 59 | int 0x10 ; 'l' is still on al, remember? 60 | mov al, 'o' 61 | int 0x10 62 | 63 | jmp $ ; jump to current address (infinite loop) 64 | 65 | times 510 - ($-$$) db 0 66 | dw 0xaa55 67 | ``` 68 | 69 | ## Runing the os 70 | 71 | 1. Install the compiler and emulator 72 | 73 | ```console 74 | user@host:~$ sudo apt/dnf/brew/ nasm qemu -y 75 | ``` 76 | 77 | 2. Compile the assembly file 78 | 79 | ```console 80 | user@host:~$ nasm -f bin file.asm -o output.bin 81 | ``` 82 | 83 | 3. Run the compiled bin file 84 | 85 | ```console 86 | user@host:~$ qemu-system-x86_64 output.bin 87 | ``` 88 | -------------------------------------------------------------------------------- /hello-world | 001/hello-world.asm: -------------------------------------------------------------------------------- 1 | mov ah, 0x0e ; tty mode 2 | mov al, 'W' 3 | int 0x10 4 | mov al, 'e' 5 | int 0x10 6 | mov al, 'l' 7 | int 0x10 8 | mov al, 'c' 9 | int 0x10 10 | mov al, 'o' 11 | int 0x10 12 | mov al, 'm' 13 | int 0x10 14 | mov al, 'e' 15 | 16 | int 0x10 17 | mov al, ' ' 18 | int 0x10 19 | 20 | mov al, 't' 21 | int 0x10 22 | mov al, 'o' 23 | int 0x10 24 | 25 | mov al, ' ' 26 | int 0x10 27 | 28 | mov al, 'm' 29 | int 0x10 30 | mov al, 'a' 31 | int 0x10 32 | mov al, 'z' 33 | int 0x10 34 | mov al, 'y' 35 | int 0x10 36 | mov al, 'o' 37 | int 0x10 38 | mov al, 's' 39 | int 0x10 40 | 41 | jmp $ ; jump to current address = infinite loop 42 | 43 | times 510-($-$$) db 0 44 | ; Magic number 45 | dw 0xaa55 46 | -------------------------------------------------------------------------------- /hello-world | 001/output.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/OSdev/fd9c653144225d5d0d45c0693ee203813f33b2ee/hello-world | 001/output.bin --------------------------------------------------------------------------------