Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
1dd4e728d4
|
|||
|
b9c77a316a
|
|||
| 6fc28806e2 |
@@ -11,3 +11,4 @@ iso_root
|
|||||||
symbols.map
|
symbols.map
|
||||||
symbols.S
|
symbols.S
|
||||||
*.log
|
*.log
|
||||||
|
build/
|
||||||
@@ -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!
|
|
||||||
@@ -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
|
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:
|
build:
|
||||||
rm -f *.o
|
mkdir -p build
|
||||||
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
|
rm -f *.o build/*.o
|
||||||
nasm -f elf64 src/idt/idt.S -o idt_stub.o
|
x86_64-elf-gcc -g -c -Isrc $(SOURCES) $(CC_PROBLEMATIC_FLAGS) $(CC_FLAGS)
|
||||||
x86_64-elf-ld -o pepperk -T linker.ld *.o
|
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
|
nm -n pepperk | awk '$$2 ~ /[TtDdBbRr]/ {print $$1, $$3}' > symbols.map
|
||||||
python3 symbols.py
|
python3 symbols.py
|
||||||
nasm -f elf64 symbols.S -o symbols.o
|
nasm -f elf64 symbols.S -o build/symbols.o
|
||||||
x86_64-elf-ld -o pepperk -T linker.ld *.o
|
x86_64-elf-ld -o pepperk -T linker.ld build/*.o
|
||||||
|
|
||||||
limine/limine:
|
limine/limine:
|
||||||
rm -rf limine
|
rm -rf limine
|
||||||
@@ -46,4 +51,4 @@ run: build-iso
|
|||||||
/usr/bin/qemu-system-x86_64 -cdrom pepper.iso -serial stdio
|
/usr/bin/qemu-system-x86_64 -cdrom pepper.iso -serial stdio
|
||||||
|
|
||||||
clean:
|
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
|
||||||
|
|||||||
@@ -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).
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
#include "io/serial/serial.h"
|
#include "io/serial/serial.h"
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
|
||||||
|
extern struct init_status init;
|
||||||
|
|
||||||
void panic(struct cpu_status_t* ctx, const char* str)
|
void panic(struct cpu_status_t* ctx, const char* str)
|
||||||
{
|
{
|
||||||
CLEAR_INTERRUPTS;
|
CLEAR_INTERRUPTS;
|
||||||
@@ -15,6 +17,13 @@ void panic(struct cpu_status_t* ctx, const char* str)
|
|||||||
skputc('\r');
|
skputc('\r');
|
||||||
skputc('\n');
|
skputc('\n');
|
||||||
DEBUG("\x1b[38;5;231m\x1b[48;5;196mend Kernel panic - halting...\x1b[0m");
|
DEBUG("\x1b[38;5;231m\x1b[48;5;196mend Kernel panic - halting...\x1b[0m");
|
||||||
|
|
||||||
|
if (init.terminal)
|
||||||
|
{
|
||||||
|
printf("\r\n\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m Something went horribly wrong! (no cpu ctx)");
|
||||||
|
printf("\r\n%s\r\n\x1b[38;5;231m\x1b[48;5;196mend Kernel panic - halting...\x1b[0m", str);
|
||||||
|
}
|
||||||
|
|
||||||
hcf();
|
hcf();
|
||||||
}
|
}
|
||||||
DEBUG("\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m at rip=%p\r\nSomething went horribly wrong! (%s) vect=0x%.2x errcode=0x%x\n\rrax=%p rbx=%p rcx=%p rdx=%p\n\rrsi=%p rdi=%p r8=%p r9=%p\n\rr10=%p r11=%p r12=%p r13=%p\n\rr14=%p r15=%p\n\n\rflags=%p\n\rHalting...",
|
DEBUG("\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m at rip=%p\r\nSomething went horribly wrong! (%s) vect=0x%.2x errcode=0x%x\n\rrax=%p rbx=%p rcx=%p rdx=%p\n\rrsi=%p rdi=%p r8=%p r9=%p\n\rr10=%p r11=%p r12=%p r13=%p\n\rr14=%p r15=%p\n\n\rflags=%p\n\rHalting...",
|
||||||
@@ -22,6 +31,17 @@ void panic(struct cpu_status_t* ctx, const char* str)
|
|||||||
str,
|
str,
|
||||||
ctx->vector_number, ctx->error_code, ctx->rax, ctx->rbx, ctx->rcx, ctx->rdx, ctx->rsi, ctx->rdi,
|
ctx->vector_number, ctx->error_code, ctx->rax, ctx->rbx, ctx->rcx, ctx->rdx, ctx->rsi, ctx->rdi,
|
||||||
ctx->r8, ctx->r9, ctx->r10, ctx->r11, ctx->r12, ctx->r13, ctx->r14, ctx->r15, ctx->iret_flags);
|
ctx->r8, ctx->r9, ctx->r10, ctx->r11, ctx->r12, ctx->r13, ctx->r14, ctx->r15, ctx->iret_flags);
|
||||||
|
|
||||||
|
if (init.terminal)
|
||||||
|
{
|
||||||
|
printf("\r\n\x1b[38;5;231m\x1b[48;5;196mKernel panic!!!\x1b[0m at rip=%p\r\nSomething went horribly wrong! (%s) vect=0x%.2x errcode=0x%x\n\rrax=%p rbx=%p rcx=%p rdx=%p\n\rrsi=%p rdi=%p r8=%p r9=%p\n\rr10=%p r11=%p r12=%p r13=%p\n\rr14=%p r15=%p\n\n\rflags=%p\n\rHalting...",
|
||||||
|
ctx->iret_rip,
|
||||||
|
str,
|
||||||
|
ctx->vector_number, ctx->error_code, ctx->rax, ctx->rbx, ctx->rcx, ctx->rdx, ctx->rsi, ctx->rdi,
|
||||||
|
ctx->r8, ctx->r9, ctx->r10, ctx->r11, ctx->r12, ctx->r13, ctx->r14, ctx->r15, ctx->iret_flags);
|
||||||
|
}
|
||||||
|
|
||||||
debug_stack_trace(100);
|
debug_stack_trace(100);
|
||||||
|
|
||||||
hcf();
|
hcf();
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
|
||||||
|
extern struct init_status init;
|
||||||
|
|
||||||
void debug_stack_trace(unsigned int max_frames)
|
void debug_stack_trace(unsigned int max_frames)
|
||||||
{
|
{
|
||||||
DEBUG("*** begin stack trace ***");
|
DEBUG("*** begin stack trace ***");
|
||||||
|
if (init.terminal)
|
||||||
|
{
|
||||||
|
printf("\r\n*** begin stack trace ***\r\n");
|
||||||
|
}
|
||||||
// Thanks GCC :)
|
// Thanks GCC :)
|
||||||
uintptr_t* rbp = (uintptr_t*)__builtin_frame_address(0);
|
uintptr_t* rbp = (uintptr_t*)__builtin_frame_address(0);
|
||||||
|
|
||||||
@@ -15,6 +21,11 @@ void debug_stack_trace(unsigned int max_frames)
|
|||||||
const char* name = debug_find_symbol(rip, &offset);
|
const char* name = debug_find_symbol(rip, &offset);
|
||||||
DEBUG("[%u] <0x%p> (%s+0x%x)", frame, (void*)rip, name, offset);
|
DEBUG("[%u] <0x%p> (%s+0x%x)", frame, (void*)rip, name, offset);
|
||||||
|
|
||||||
|
if (init.terminal)
|
||||||
|
{
|
||||||
|
printf("[%u] <0x%p> (%s+0x%x)\r\n", frame, (void*)rip, name, offset);
|
||||||
|
}
|
||||||
|
|
||||||
uintptr_t* next_rbp = (uintptr_t*)rbp[0];
|
uintptr_t* next_rbp = (uintptr_t*)rbp[0];
|
||||||
|
|
||||||
// invalid rbp or we're at the end
|
// invalid rbp or we're at the end
|
||||||
@@ -25,6 +36,10 @@ void debug_stack_trace(unsigned int max_frames)
|
|||||||
|
|
||||||
rbp = next_rbp;
|
rbp = next_rbp;
|
||||||
}
|
}
|
||||||
|
if (init.terminal)
|
||||||
|
{
|
||||||
|
printf("*** end stack trace ***");
|
||||||
|
}
|
||||||
DEBUG("*** end stack trace ***");
|
DEBUG("*** end stack trace ***");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ bool iran = false;
|
|||||||
// Never gets executed although pedicel is scheduled?
|
// Never gets executed although pedicel is scheduled?
|
||||||
void pedicel_main(void* arg)
|
void pedicel_main(void* arg)
|
||||||
{
|
{
|
||||||
|
//panic(NULL, "test");
|
||||||
bool iran = true;
|
bool iran = true;
|
||||||
// FROM THE NEXT LINE ONWARDS, CANNOT WRITE TO FRAMEBUFFER WITHOUT PAGE FAULT!
|
// FROM THE NEXT LINE ONWARDS, CANNOT WRITE TO FRAMEBUFFER WITHOUT PAGE FAULT!
|
||||||
//printf("\n\nWelcome to PepperOS! Pedicel speaking.\nNothing left to do, halting the system!");
|
//printf("\n\nWelcome to PepperOS! Pedicel speaking.\nNothing left to do, halting the system!");
|
||||||
|
|||||||
Reference in New Issue
Block a user