From 1dd4e728d41265ac3cfe819eb87b9a2917e92c54 Mon Sep 17 00:00:00 2001 From: xamidev Date: Wed, 11 Mar 2026 14:59:20 +0100 Subject: [PATCH] Build folder + coding style guidelines --- .gitignore | 3 +- DOOM.txt | 24 --------------- Makefile | 21 ++++++++----- docs/STYLE.md | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ test.bin | 1 - 5 files changed, 98 insertions(+), 34 deletions(-) delete mode 100644 DOOM.txt create mode 100644 docs/STYLE.md delete mode 100644 test.bin diff --git a/.gitignore b/.gitignore index 8120a94..8de7009 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ iso_root .gdb_history symbols.map symbols.S -*.log \ No newline at end of file +*.log +build/ \ No newline at end of file diff --git a/DOOM.txt b/DOOM.txt deleted file mode 100644 index 4f1aa83..0000000 --- a/DOOM.txt +++ /dev/null @@ -1,24 +0,0 @@ -up to doom: - -- Return from pedicel_main() normally (to idle) - -** Checkpoint: ring0 process working - -- VFS layer (open/read/write/...) with USTar filesystem (for initrd) - -** Checkpoint: files not linked to but accessible by the kernel - -- Ring3 memory mappings -- Ring3 privilege switch - -** Checkpoint: welcome to userland - -- Syscall interface -- Implement syscalls needed for doom - -** Checkpoint: can run simple programs, ring 3, loaded from filesystem - -- Properly handle the keyboard interrupt (keyboard buffer) -- Port DOOMgeneric (few functions with Framebuffer/ticks/etc.) - -** Achievement: It runs doom! diff --git a/Makefile b/Makefile index e0bc1e9..4a0a45c 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,21 @@ SOURCES = src/debug/misc.c src/io/term/flanterm_backends/fb.c src/io/term/flanterm.c src/debug/panic.c src/debug/stacktrace.c src/boot/boot.c src/sched/scheduler.c src/sched/process.c src/mem/heap/kheap.c src/mem/paging/vmm.c src/mem/paging/paging.c src/mem/paging/pmm.c src/string/string.c src/io/kbd/ps2.c src/io/serial/serial.c src/io/term/printf.c src/io/term/term.c src/idt/idt.c src/mem/gdt/gdt.c src/mem/misc/utils.c src/time/timer.c src/kmain.c -PROBLEMATIC_FLAGS=-Wno-unused-parameter -Wno-unused-variable +CC_FLAGS=-Wall -Wextra -std=gnu99 -nostdlib -ffreestanding -fno-stack-protector -fno-omit-frame-pointer -fno-stack-check -fno-PIC -ffunction-sections -fdata-sections -mcmodel=kernel +CC_PROBLEMATIC_FLAGS=-Wno-unused-parameter -Wno-unused-variable + +.PHONY: build build-iso debug debug2 run clean build: - rm -f *.o - x86_64-elf-gcc -g -c -Isrc $(SOURCES) $(PROBLEMATIC_FLAGS) -Wall -Wextra -std=gnu99 -nostdlib -ffreestanding -fno-stack-protector -fno-omit-frame-pointer -fno-stack-check -fno-PIC -ffunction-sections -fdata-sections -mcmodel=kernel - nasm -f elf64 src/idt/idt.S -o idt_stub.o - x86_64-elf-ld -o pepperk -T linker.ld *.o + mkdir -p build + rm -f *.o build/*.o + x86_64-elf-gcc -g -c -Isrc $(SOURCES) $(CC_PROBLEMATIC_FLAGS) $(CC_FLAGS) + mv *.o build/ + nasm -f elf64 src/idt/idt.S -o build/idt_stub.o + x86_64-elf-ld -o pepperk -T linker.ld build/*.o nm -n pepperk | awk '$$2 ~ /[TtDdBbRr]/ {print $$1, $$3}' > symbols.map python3 symbols.py - nasm -f elf64 symbols.S -o symbols.o - x86_64-elf-ld -o pepperk -T linker.ld *.o + nasm -f elf64 symbols.S -o build/symbols.o + x86_64-elf-ld -o pepperk -T linker.ld build/*.o limine/limine: rm -rf limine @@ -46,4 +51,4 @@ run: build-iso /usr/bin/qemu-system-x86_64 -cdrom pepper.iso -serial stdio clean: - rm -rf *.o symbols.map symbols.S pepperk iso_root pepper.iso limine + rm -rf *.o symbols.map symbols.S pepperk iso_root pepper.iso limine build/*.o diff --git a/docs/STYLE.md b/docs/STYLE.md new file mode 100644 index 0000000..c7db749 --- /dev/null +++ b/docs/STYLE.md @@ -0,0 +1,83 @@ +# Pepper kernel coding style + +This document describes the coding style for the Pepper kernel. It is used as a guideline across all source files. + +## Indentation + +Indentations should be 4 characters long. + +## Line length + +Lines should not be more than 100 characters long. + +## Variables + +Variables should be declared at most once per line. + +## Braces + +Non-function statement blocks should have an opening brace last on the line, and a closing brace first. Exception is made for `else`, `else if` statements and the like: + +```c +if (something) { + do_something(); +} else if (something_else) { + do_something_else(); +} +``` + +Functions should have their opening brace on a separate line, and the same goes for the closing brace: + +```c +void function() +{ + do_something(); +} +``` + +## Spaces + +Use a space after `if, switch, case, for, do, while` keywords, but not for `sizeof, typeof, alignof, __attribute__` and the like. + +For pointers, the asterisk should always be placed adjacent to the type name, like `char* str;`. + +## Naming + +Functions should be named with whole words, beginning with the corresponding name of the module in the kernel (the parent folder). Words should be spaced with underscores, like so: + +```c +serial_init(void* ptr, char* str, int foo); +``` + +Constants should be named in all caps, separated by underscores: + +```c +#define MAX_HEAP_SIZE 0x1000 +``` + +Global variables need to have descriptive names. Local variables can be kept short (especially for loop counters). + +## Typedefs + +Structures should not be `typedef`'d. + +## Functions + +Functions should be short, simple, and only do one thing. + +Function prototypes should include parameter names and their data types. + +## Commenting + +Comments should describe what a function does and why, not how it does it. + +```c +/* + * This is the preferred style for multi-line + * comments in the Pepper kernel + */ +``` + +### Resources + +Some of the elements here are inspired by the [Linux kernel coding style](https://www.kernel.org/doc/html/v4.10/process/coding-style.html). \ No newline at end of file diff --git a/test.bin b/test.bin deleted file mode 100644 index 60f94fd..0000000 --- a/test.bin +++ /dev/null @@ -1 +0,0 @@ -ΈοΎ­ήλώ \ No newline at end of file