Select Git revision
-
Hazal2.Veziroglu@live.uwe.ac.uk authoredHazal2.Veziroglu@live.uwe.ac.uk authored
README.md 3.40 KiB
Tiny OS Development Project
This project focuses on creating a minimal operating system that can boot, execute simple C functions, and display text using a framebuffer driver. It follows Worksheet 2 Part 1 and references The Little Book of OS Development.
1. Project Overview
The project's primary objectives are:
- Develop a bootloader to load the kernel.
- Transition from assembly to C for kernel functionality.
- Implement a framebuffer driver for text output, cursor positioning, and screen clearing.
- Test the operating system in QEMU and document the outcomes.
2. Directory Structure
The directory structure is organized as follows:
tiny-os/
├── source/
│ ├── loader.asm # Bootloader in assembly
│ ├── kernel.c # Main kernel logic
│ ├── fb.c # Framebuffer driver
│ ├── io.c # Low-level I/O functions
│ └── link.ld # Linker script
├── include/
│ ├── fb.h # Framebuffer driver header
│ └── io.h # I/O functions header
├── iso/
│ └── boot/
│ └── grub/
│ ├── stage2_eltorito # GRUB bootloader file
│ └── menu.lst # GRUB configuration
├── Makefile # Automates build processes
└── README.md # Project documentation
---
## **3.Features**
Key features of this project include:
1. Bootloader:
- GRUB is used to load the kernel.
- The kernel starts execution at the entry point defined in loader.asm.
2. Transition to C:
- The kernel successfully calls and executes functions implemented in kernel.c.
3.Framebuffer Driver:
- Implements the following functions:
-fb_clear(): Clears the screen.
-fb_print(): Prints text at specified row and column.
-fb_move(): Moves the cursor to a specific position.
4.QEMU Testing:
-The OS is tested using QEMU in graphical and curses modes.
---
## **4. Implementation Details**
Bootloader (loader.asm)
The bootloader adheres to the Multiboot specification and transfers control to the kernel:
```asm
global loader
extern kernel_main
section .text
align 4
MAGIC_NUMBER equ 0x1BADB002
FLAGS equ 0x0
CHECKSUM equ -MAGIC_NUMBER
dd MAGIC_NUMBER
dd FLAGS
dd CHECKSUM
loader:
call kernel_main
hlt
Kernel (kernel.c) The kernel initializes the framebuffer and tests its driver:
#include "fb.h"
void kernel_main() {
fb_clear();
fb_print("Sum: 6", 0, 0);
fb_print("Booting Tiny OS", 1, 0);
fb_move(2, 0);
while (1) {}
}
Framebuffer Driver (fb.c) Implements APIs for interacting with the framebuffer:
#include "fb.h"
#include "io.h"
void fb_clear() {
char *fb = (char *)0xB8000;
for (int i = 0; i < 80 * 25; i++) {
fb[i * 2] = ' ';
fb[i * 2 + 1] = 0x07;
}
}
void fb_print(const char *str, unsigned short row, unsigned short col) {
char *fb = (char *)0xB8000;
unsigned short pos = (row * 80 + col) * 2;
for (int i = 0; str[i] != '\0'; i++) {
fb[pos + i * 2] = str[i];
fb[pos + i * 2 + 1] = 0x07;
}
}
void fb_move(unsigned short row, unsigned short col) {
unsigned short pos = row * 80 + col;
outb(0x3D4, 0x0F);
outb(0x3D5, (unsigned char)(pos & 0xFF));
outb(0x3D4, 0x0E);
outb(0x3D5, (unsigned char)((pos >> 8) & 0xFF));
}
5. Build and Run Instructions
- Clean the Build Directory
make clean