Mini-OS is a simple bootable operating system kernel written in assembly. The system loads a kernel from a disk and displays a message to the user, prompting them to type specific characters. The kernel processes keypresses (A, B, C, and space) and prints the corresponding character to the screen. The system supports basic keyboard input and output via BIOS interrupts.
- Bootloader: A bootloader (boot.asm) that loads the kernel from disk.
- Kernel: A simple kernel (kernel.asm) that interacts with the user through the screen.
- User Input: The kernel waits for user input, displays corresponding characters for
A,B,C, andSPACE. - Assembly Code: The OS is written in x86 Assembly Language using NASM syntax.
- boot.asm: The bootloader code responsible for loading the kernel from disk.
- kernel.asm: The kernel code that displays a message and handles user input.
- Makefile: A script to compile the bootloader and kernel into a bootable image.
Before you can use Mini-OS, ensure you have the following tools installed on your system:
- NASM (Netwide Assembler): A powerful assembler used to compile the assembly code.
- QEMU: An emulator to run the bootable image and test the operating system.
- Make: A build automation tool to handle the compilation process.
-
Clone or Download the Source Code
Make sure you have the source code in the appropriate directory structure. The basic structure should look like this:
mini-os/ ├── Makefile ├── src/ │ ├── boot.asm │ └── kernel.asm └── build/ ├── mini-os.img (generated) ├── boot.bin (generated) └── kernel.bin (generated) -
Install Prerequisites
Install the required tools on your system:
-
NASM: Install NASM to assemble the code.
sudo apt-get install nasm
-
QEMU: Install QEMU to test the bootable image.
sudo apt-get install qemu
-
Make: Install
maketo automate the build process.sudo apt-get install make
-
-
Build the OS Image
To compile the Mini-OS, run the following command from the root of your project directory:
make
This command compiles the
boot.asmandkernel.asmfiles into binary files (boot.binandkernel.bin) and then combines them into a bootable image (mini-os.img) located in thebuild/directory. -
Clean Up the Build Artifacts
To clean up the generated files (binary and image), you can use the following command:
make clean
This will remove all files in the
build/directory with.binand.imgextensions.
After building the bootable image, you can run Mini-OS in QEMU to test it.
-
Run the Image in QEMU
Use the following command to boot the image in QEMU:
qemu-system-i386 -fda build/mini-os.img
This command will start QEMU with the
mini-os.imgfile as the floppy disk (-fda), simulating the system boot.Note: If you encounter warnings about the image format or block devices, you can specify the
-drive format=rawoption explicitly:qemu-system-i386 -fda build/mini-os.img -drive format=raw
-
Interact with the OS
Once the Mini-OS is booted, the following message will be displayed:
Type A, B, C or SPACE!You can then type the following keys:
- A: Displays
Aon the screen. - B: Displays
Bon the screen. - C: Displays
Con the screen. - Space: Displays a space on the screen.
- A: Displays
-
Exit the OS
The OS does not yet support an explicit exit or shutdown. You can manually close the QEMU window to stop the simulation.
-
boot.asm (Bootloader)
The bootloader is responsible for loading the kernel from disk and jumping to it. It is stored in the first sector of the disk. The bootloader performs the following tasks:
- Loads the kernel from the disk into memory at address
0x8000. - Jumps to the kernel code to start execution.
- Loads the kernel from the disk into memory at address
-
kernel.asm (Kernel)
The kernel is a simple program that:
- Clears the screen using BIOS interrupt
0x10and an escape sequence. - Displays a message to the user:
"Type A, B, C or SPACE!". - Waits for a keypress using the
get_keyfunction. - Responds to keypresses by displaying the corresponding character on the screen (A, B, C, SPACE).
- Clears the screen using BIOS interrupt
-
Makefile
The Makefile automates the build process for the bootloader and kernel. It contains the following rules:
- all: Builds the final
mini-os.imgby combining the bootloader and kernel binaries. - $(BUILD)/boot.bin: Assembles the bootloader (
boot.asm) into a binary file. - $(BUILD)/kernel.bin: Assembles the kernel (
kernel.asm) into a binary file. - clean: Cleans up the build directory by removing generated
.binand.imgfiles.
- all: Builds the final
- Support More Keypresses: Extend the
get_keyfunction to support more keys (e.g., Enter, Backspace). - Add More System Features: Implement basic memory management, task scheduling, and file handling.
- Error Handling: Add error messages or logging to help diagnose problems during execution.
- Interactive Interface: Implement a more complex interactive interface with menus, user input validation, etc.
Mini-OS is a basic example of an operating system kernel written in assembly. It demonstrates essential OS features like bootloading, keyboard input handling, and screen output. You can extend it further to add more complex functionality as you explore OS development and assembly programming.