Skip to content

Commit b3c6bcd

Browse files
committed
init
going public :^)
1 parent 39afbff commit b3c6bcd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+5266
-1
lines changed

.gdbinit

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
file /share/build/kernel.elf
2+
gef-remote --qemu-user --qemu-binary /share/build/kernel.elf localhost 1234

.github/workflows/ci.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Pipeline
2+
3+
on: push
4+
5+
jobs:
6+
build-os:
7+
runs-on: ubuntu-20.04
8+
steps:
9+
- name: Checkout repo
10+
uses: actions/checkout@v4
11+
12+
- name: Install deps
13+
run: |
14+
chmod +x ./deps-container.sh
15+
sudo ./deps-container.sh
16+
17+
- name: Compile Kernel
18+
run: |
19+
make dirsetup
20+
make kernel
21+
22+
- name: Compile Filesystem/Userland
23+
run: make fs
24+
25+
- name: Build iso image
26+
run: make iso

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
later/
2+
build/
3+
iso/targets/x86/boot/kernel.bin
4+
.vscode/
5+
tmp/
6+
.cache/
7+
*.o
8+
**/*.o
9+
disk.img

Makefile

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
CC=gcc
2+
ASM=nasm
3+
LD=ld
4+
CFLAGS=-ffreestanding -fno-pic -static -fno-builtin \
5+
-fno-strict-aliasing -O2 -Wall -ggdb -m32 \
6+
-Werror -fno-omit-frame-pointer -fno-stack-protector -mno-80387 -Wno-div-by-zero
7+
8+
SRC_DIR=src
9+
INC_DIR=src -I/usr/include/ -I/usr/include/x86_64-linux-gnu
10+
BUILD_DIR=build
11+
DISK_IMG=disk.img
12+
13+
KERN_SRC_DIR=$(SRC_DIR)/kernel
14+
KERN_OBJ_DIR=$(BUILD_DIR)/kernel
15+
16+
DRIVERS_SRC_DIR=$(SRC_DIR)/drivers
17+
DRIVERS_OBJ_DIR=$(BUILD_DIR)/drivers
18+
19+
# $(wildcard *.cpp /xxx/xxx/*.cpp): get all .cpp files from the current directory and dir "/xxx/xxx/"
20+
# $(patsubst %.cpp,%.o,$(SRCS)): substitute all ".cpp" file name strings to ".o" file name strings
21+
22+
KERNEL_SRCS := $(wildcard $(KERN_SRC_DIR)/*.c)
23+
KERNEL_SRCS += $(wildcard $(KERN_SRC_DIR)/*.S)
24+
KERNEL_OBJS := $(patsubst $(KERN_SRC_DIR)/%.c,$(KERN_OBJ_DIR)/%.o,$(KERNEL_SRCS))
25+
KERNEL_OBJS := $(patsubst $(KERN_SRC_DIR)/%.S,$(KERN_OBJ_DIR)/%.o,$(KERNEL_OBJS))
26+
27+
DRIVER_SRCS := $(wildcard $(DRIVERS_SRC_DIR)/*.c)
28+
DRIVER_OBJS := $(patsubst $(DRIVERS_SRC_DIR)/%.c,$(DRIVERS_OBJ_DIR)/%.o,$(DRIVER_SRCS))
29+
30+
CPUS=1
31+
QEMU_OPTS=-smp $(CPUS) -m 512 -serial pty -serial stdio
32+
33+
dirsetup:
34+
mkdir -p $(DRIVERS_OBJ_DIR)
35+
mkdir -p $(KERN_OBJ_DIR)
36+
python3 ./gen_vectors.py > $(KERN_SRC_DIR)/trap_dispatcher.S
37+
38+
39+
# drivers
40+
# -------------------------
41+
build/drivers/%.o: src/drivers/%.c
42+
@echo "[*] Compiling $^"
43+
$(CC) $(CFLAGS) -fno-pic -nostdinc -I$(INC_DIR) -c $^ -o $@
44+
45+
drivers: $(DRIVER_OBJS)
46+
@echo "[*] ======= Done compiling drivers ======="
47+
48+
# kernel (C sources & assemblies)
49+
# -------------------------
50+
build/kernel/%.o: src/kernel/%.c
51+
@echo "[*] Compiling $^"
52+
$(CC) $(CFLAGS) -fno-pic -nostdinc -I$(INC_DIR) -c $^ -o $@
53+
54+
build/kernel/%.o: src/kernel/%.S
55+
@echo "[*] Compiling $^"
56+
$(CC) $(CFLAGS) -fno-pic -nostdinc -I$(INC_DIR) -c $^ -o $@
57+
58+
kern: $(KERNEL_OBJS)
59+
@echo "[*] ======= Done compiling kernel ======="
60+
61+
kernel: kern drivers
62+
@echo "\n[*] ======= Linking kernel.elf ======="
63+
$(LD) $(LDFLAGS) -T$(KERN_SRC_DIR)/kernel.ld -o $(BUILD_DIR)/kernel.elf $(KERNEL_OBJS) $(DRIVER_OBJS) -b binary
64+
65+
66+
# OS image
67+
# -------------------------
68+
iso: kernel fs
69+
@echo "\n[*] ======= Making iso image w/ GRUB bootloader ======="
70+
cp $(BUILD_DIR)/kernel.elf iso/targets/x86/boot/kernel.bin && \
71+
grub-mkrescue /usr/lib/grub/i386-pc -o $(BUILD_DIR)/kernel.iso iso/targets/x86
72+
73+
clean:
74+
rm -rf $(BUILD_DIR)/*
75+
$(MAKE) clean -C ./src/userland/
76+
77+
# Emulation & debugging
78+
# -------------------------
79+
qemu:
80+
qemu-system-i386 -cdrom $(BUILD_DIR)/kernel.iso $(QEMU_OPTS)
81+
82+
qemu-nox:
83+
qemu-system-i386 -nographic -boot d -cdrom $(BUILD_DIR)/kernel.iso -hda $(DISK_IMG) $(QEMU_EXTRAS)
84+
85+
qemu-gdb:
86+
@echo "\n[*] ======= starting QEMU+gdb ======="
87+
@echo "[*] To close: Ctrl-A X"
88+
@echo "Starting "
89+
qemu-system-i386 -s -S -nographic -boot d -cdrom $(BUILD_DIR)/kernel.iso -hda $(DISK_IMG) $(QEMU_EXTRAS)
90+
91+
# Disk / filesystem
92+
# -------------------------
93+
disk:
94+
@echo "\n[*] ======= Generating FAT32 disk image ======="
95+
dd if=/dev/zero of=disk.img bs=1M count=1
96+
mkfs.vfat -F 32 disk.img
97+
98+
fs: disk
99+
$(MAKE) fs -C ./src/userland/

README.md

+70-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,71 @@
11
# GenesisOS
2-
curiosity got me here
2+
<p align="center">
3+
<img src='docs/images/logo.png' />
4+
<br />
5+
<img src='https://github.com/0xbigshaq/GenesisOS/actions/workflows/ci.yaml/badge.svg' />
6+
<a href='https://discord.gg/PpeeR64k'><img src='https://img.shields.io/discord/1231650335802789959.svg?logo=discord&logoColor=white&logoWidth=20labelColor=7289DA&color=17cf48&label=Discord' /></a>
7+
<img src='https://img.shields.io/badge/arch-x86/32bit-blue' />
8+
</p>
9+
10+
Dumb project I made because I wanted to learn about kernels and how they work. You are welcomed to contribute to my chaos and join the cult.
11+
12+
This operating system have the following features:
13+
* Kernel allocator
14+
* Virtual Memory
15+
* Interrupts / IRQs
16+
* Disk: ATA PIO
17+
* Syscalls
18+
* Scheduler (_Round-Robin_ algorithm)
19+
* Console/UART driver
20+
* Filesystem: Support FAT32
21+
* ELF Loader
22+
* Userland shell/init binary
23+
* Devices/File descriptors(not rly/partial)
24+
25+
All this work, just to load an ELF binary that echoes back whatever you write to it by calling `SYS_read` and `SYS_write`:
26+
27+
<img src='docs/images/terminal.gif' />
28+
29+
To write this project, I used:
30+
* _Intel SDM Vol 3_(`325384-sdm-vol-3abcd.pdf`)
31+
* OSDev Discord community([link](https://discord.gg/osdev))
32+
* OSDev: https://wiki.osdev.org/
33+
* "_The little book about OS development_": https://littleosbook.github.io/
34+
* Academic projects: SerenityOS, JOS and xv6 (to get inspiration for design ideas)
35+
* _nanobyte-dev_ YT channel to get introduction on FAT filesystems.
36+
37+
38+
# Build & Run
39+
40+
Launch an `ubuntu:20.04` container and follow the steps below
41+
```sh
42+
docker run -v $(pwd):/share/ --rm --privileged --name osdev -it ubuntu:20.04
43+
```
44+
45+
1. First, run `./deps-container.sh` to install the required dependencies.
46+
2. prepare the directory tree by running `make dirsetup`
47+
3. Compile & pack everything by running `make iso`
48+
4. To run the OS in qemu, run `make qemu-nox`
49+
50+
>Note: _nox_ stands for _no-graphics_. If you run `make qemu` a qemu window will pop. However, it has bugs because the video driver is not finished(unlike the UART/console driver, which is more mature)
51+
52+
53+
# Debug
54+
55+
To debug:
56+
1. Run `make qemu-gdb`
57+
2. Connect with gdb by running `target remote :12345`
58+
59+
# Security
60+
61+
Found a security issue? Good, fix it and send a PR.
62+
63+
>There are plenty of vulns around the codebase. I'm considering opening a special activities/event for vuln researchers who are interested in OSDev so we can learn and grow together. Should update about it in the Discord server.
64+
65+
# Compile DB
66+
67+
For easier code navigation and auto-completion, use _clangd_'s vscode plugin + [compiledb](https://github.com/nickdiego/compiledb).
68+
69+
```
70+
compiledb make iso
71+
```

0 commit comments

Comments
 (0)