Skip to content
This repository has been archived by the owner on May 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #34 from KevinAlavik/rewrite
Browse files Browse the repository at this point in the history
Refactored alot of code. And fixed all warnings and errors.
  • Loading branch information
KevinAlavik authored Mar 24, 2024
2 parents bb3e795 + 680c198 commit 3237960
Show file tree
Hide file tree
Showing 91 changed files with 924 additions and 1,049 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Daily Build
name: Daily Build (Rewrite)

on:
push:
branches:
- main
- rewrite
schedule:
- cron: '0 0 * * *'

Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
path = limine
url = https://github.com/limine-bootloader/limine.git
branch = v6.x-branch-binary
[submodule "src/nighterm"]
path = src/nighterm
[submodule "kernel/nighterm"]
path = kernel/nighterm
url = https://github.com/schkwve/nighterm-extended
67 changes: 46 additions & 21 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ override LD := ld
override MAKEFLAGS += -rR

override KERNEL := Paradox
KERNEL_DIR := kernel
ARCH_DIR := arch/x86_64

UNAME_S := $(shell uname -s)

Expand Down Expand Up @@ -41,8 +43,9 @@ $(eval $(call DEFAULT_VAR,LDFLAGS,$(DEFAULT_LDFLAGS)))
override CFLAGS += \
-O0 \
-Ilimine \
-Isrc \
-Isrc/corelib \
-Ikernel \
-Iarch \
-Ikernel/corelib \
-Wall \
-Wextra \
-std=gnu11 \
Expand All @@ -67,42 +70,64 @@ override CFLAGS += \
-Wdiv-by-zero \
-Wunused-variable



override LDFLAGS += -nostdlib -static -m elf_x86_64 -z max-page-size=0x1000 -T linker.ld

override CPPFLAGS := -I. $(CPPFLAGS) -MMD -MP

override NASMFLAGS += -Wall -f elf64

override CFILES := $(shell cd src && find -L * -type f -name '*.c')
override ASFILES := $(shell cd src && find -L * -type f -name '*.S')
override NASMFILES := $(shell cd src && find -L * -type f -name '*.asm')
override CFILES := $(shell cd $(KERNEL_DIR) && find -L * -type f -name '*.c')
override ASFILES := $(shell cd $(KERNEL_DIR) && find -L * -type f -name '*.S')
override NASMFILES := $(shell cd $(KERNEL_DIR) && find -L * -type f -name '*.asm')
override OBJ := $(addprefix obj/,$(CFILES:.c=.c.o) $(ASFILES:.S=.S.o) $(NASMFILES:.asm=.asm.o))
override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))

override ARCH_CFILES := $(shell cd $(ARCH_DIR) && find -L * -type f -name '*.c')
override ARCH_ASFILES := $(shell cd $(ARCH_DIR) && find -L * -type f -name '*.S')
override ARCH_ASMFILES := $(shell cd $(ARCH_DIR) && find -L * -type f -name '*.asm')
override ARCH_OBJ := $(addprefix obj/,$(ARCH_CFILES:.c=.c.o) $(ARCH_ASFILES:.S=.S.o) $(ARCH_ASMFILES:.asm=.asm.o))
override ARCH_HEADER_DEPS := $(addprefix obj/,$(ARCH_CFILES:.c=.c.d) $(ARCH_ASFILES:.S=.S.d) $(ARCH_ASMFILES:.asm=.asm.d))

.PHONY: all
all: bin/$(KERNEL)

bin/$(KERNEL): GNUmakefile linker.ld $(OBJ)
mkdir -p "$$(dirname $@)"
$(LD) $(OBJ) $(LDFLAGS) -o $@
bin/$(KERNEL): GNUmakefile linker.ld $(OBJ) $(ARCH_OBJ)
@printf " LD\t$@\n"
@mkdir -p "$$(dirname $@)"
@$(LD) $(OBJ) $(ARCH_OBJ) $(LDFLAGS) -o $@

-include $(HEADER_DEPS) $(ARCH_HEADER_DEPS)

-include $(HEADER_DEPS)
obj/%.c.o: $(KERNEL_DIR)/%.c GNUmakefile
@printf " CC\t$<\n"
@mkdir -p "$$(dirname $@)"
@$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

obj/%.c.o: src/%.c GNUmakefile
mkdir -p "$$(dirname $@)"
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
obj/%.S.o: $(KERNEL_DIR)/%.S GNUmakefile
@printf " AS\t$<\n"
@mkdir -p "$$(dirname $@)"
@$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

obj/%.S.o: src/%.S GNUmakefile
mkdir -p "$$(dirname $@)"
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
obj/%.asm.o: $(KERNEL_DIR)/%.asm GNUmakefile
@printf " AS\t$<\n"
@mkdir -p "$$(dirname $@)"
@nasm $(NASMFLAGS) $< -o $@

obj/%.asm.o: src/%.asm GNUmakefile
mkdir -p "$$(dirname $@)"
nasm $(NASMFLAGS) $< -o $@
obj/%.c.o: $(ARCH_DIR)/%.c GNUmakefile
@printf " CC\t$<\n"
@mkdir -p "$$(dirname $@)"
@$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

obj/%.S.o: $(ARCH_DIR)/%.S GNUmakefile
@printf " AS\t$<\n"
@mkdir -p "$$(dirname $@)"
@$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

obj/%.asm.o: $(ARCH_DIR)/%.asm GNUmakefile
@printf " AS\t$<\n"
@mkdir -p "$$(dirname $@)"
@nasm $(NASMFLAGS) $< -o $@

.PHONY: clean
clean:
rm -rf bin obj Paradox.raw.bin image.iso modules/ramdisk.tar

Binary file added Roboto-Black.psf
Binary file not shown.
2 changes: 1 addition & 1 deletion src/system/cpu/cpu.c → arch/x86_64/cpu/cpu.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <system/cpu/cpu.h>
#include <x86_64/cpu/cpu.h>
#include <serial/serial.h>

void hcf()
Expand Down
File renamed without changes.
76 changes: 76 additions & 0 deletions arch/x86_64/cpu/panic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <filesystem/tar.h>
#include <kernel/init.h>
#include <kif.h>
#include <nighterm/nighterm.h> // Dont make this need nighterm.h to draw things on the screen. Use vga.h
#include <printf.h>
#include <stdint.h>
#include <x86_64/cpu/cpu.h>
#include <system/devices/speaker.h>
#include <system/memory/pmm.h>
#include <vga.h>

void panic(const char *reason, int_frame_t frame)
{
flush(70, 105, 255);
nighterm_set_bg_color(70, 105, 255);

char *img;

vfs_op_status status;

status = driver_read(vfs, 0x00000000, "/usr/share/icons/bsod.kif", &img);

if (status == STATUS_OK)
{
draw_image(img, 0, 0, 0);
}

nighterm_set_cursor_position(0, 20);

printf("\tComputer no workie :( \n\n");

printf("\t* %s\n\n", reason);

nighterm_set_fg_color(201, 183, 193);

printf("\trax: 0x%.16llX, rbx: 0x%.16llX, rcx: 0x%.16llX, rdx: 0x%.16llX\n",
frame.rax, frame.rbx, frame.rcx, frame.rdx);

printf("\trsp: 0x%.16llX, rbp: 0x%.16llX, rsi: 0x%.16llX, rdi: 0x%.16llX\n",
frame.rsp, frame.rbp, frame.rsi, frame.rdi);

printf("\tr8: 0x%.16llX, r9: 0x%.16llX, r10: 0x%.16llX, r11: 0x%.16llX\n",
frame.r8, frame.r9, frame.r10, frame.r11);

printf("\tr12: 0x%.16llX, r13: 0x%.16llX, r14: 0x%.16llX, r15: 0x%.16llX\n",
frame.r12, frame.r13, frame.r14, frame.r15);

printf("\trfl: 0x%.16llX, rip: 0x%.16llX, cs: 0x%.16llX, ss: 0x%.16llX\n",
frame.rflags, frame.rip, frame.cs, frame.ss);

dprintf("[\e[0;31mKernel Panic\e[0m] rax: 0x%.16llX, rbx: 0x%.16llX, rcx: "
"0x%.16llX, rdx: "
"0x%.16llX\n",
frame.rax, frame.rbx, frame.rcx, frame.rdx);
dprintf("[\e[0;31mKernel Panic\e[0m] rsp: 0x%.16llX, rbp: 0x%.16llX, rsi: "
"0x%.16llX, rdi: "
"0x%.16llX\n",
frame.rsp, frame.rbp, frame.rsi, frame.rdi);
dprintf("[\e[0;31mKernel Panic\e[0m] r8: 0x%.16llX, r9: 0x%.16llX, r10: "
"0x%.16llX, r11: "
"0x%.16llX\n",
frame.r8, frame.r9, frame.r10, frame.r11);
dprintf("[\e[0;31mKernel Panic\e[0m] r12: 0x%.16llX, r13: 0x%.16llX, r14: "
"0x%.16llX, r15: "
"0x%.16llX\n",
frame.r12, frame.r13, frame.r14, frame.r15);
dprintf("[\e[0;31mKernel Panic\e[0m] rfl: 0x%.16llX, rip: 0x%.16llX, cs: "
"0x%.16llX, ss: "
"0x%.16llX\n",
frame.rflags, frame.rip, frame.cs, frame.ss);

// visualize_pmm(0, 0, framebuffer->width, (bitmap_size * PAGE_SIZE) /
// framebuffer->width);

beep();
}
2 changes: 1 addition & 1 deletion src/system/cpu/panic.h → arch/x86_64/cpu/panic.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include <system/idt/idt.h>
#include <x86_64/idt/idt.h>

void panic(const char *reason, int_frame_t frame);
File renamed without changes.
41 changes: 26 additions & 15 deletions src/system/idt/idt.c → arch/x86_64/idt/idt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
#include <printf.h>
#include <stddef.h>
#include <stdint.h>
#include <system/cpu/cpu.h>
#include <system/cpu/panic.h>
#include <x86_64/cpu/cpu.h>
#include <x86_64/cpu/panic.h>
#include <system/pic/pic.h>

#define NULL (void *)0

#define IDT_ENTRIES 256

idt_entry_t idt[IDT_ENTRIES];
Expand Down Expand Up @@ -51,7 +49,8 @@ static const char *exception_strings[32] = {"Division By Zero",

extern void load_idt(uint64_t);

void set_idt_gate(int num, uint64_t base, uint16_t sel, uint8_t flags) {
void set_idt_gate(int num, uint64_t base, uint16_t sel, uint8_t flags)
{
dprintf("[\e[0;32mIDT\e[0m] Setting IDT gate for interrupt %d. Base: "
"0x%016llX, Sel: 0x%08llX, Flags: 0x%04llX\n",
num, base, sel, flags);
Expand All @@ -64,20 +63,23 @@ void set_idt_gate(int num, uint64_t base, uint16_t sel, uint8_t flags) {
idt[num].zero = 0;
}

void init_idt() {
void init_idt()
{
dprintf("[\e[0;32mIDT\e[0m] Initializing IDT\n");
idt_p.limit = sizeof(idt_entry_t) * IDT_ENTRIES - 1;
idt_p.base = (uint64_t)&idt;

for (size_t i = 0; i < 16; i++) {
for (size_t i = 0; i < 16; i++)
{
irq_handlers[i] = NULL;
}

// Remap the PIC
asm("sti");
i8259_Configure(PIC_REMAP_OFFSET, PIC_REMAP_OFFSET + 8, true);

for (int i = 0; i < IDT_ENTRIES; ++i) {
for (int i = 0; i < IDT_ENTRIES; ++i)
{
set_idt_gate(i, isr_tbl[i], 0x28, 0x8E);
}

Expand All @@ -89,40 +91,49 @@ void init_idt() {
dprintf("[\e[0;32mIDT\e[0m] IDT Initialization complete\n");
}

void excp_handler(int_frame_t frame) {
void excp_handler(int_frame_t frame)
{
// dprintf("[\e[0;32mIDT\e[0m] Handling exception with vector %d\n",
// frame.vector);

if (frame.vector < 0x20) {
if (frame.vector < 0x20)
{
dprintf("[\e[0;31mIDT\e[0m] Exception: %s\n",
exception_strings[frame.vector]);
panic(exception_strings[frame.vector], frame);
hcf();
} else if (frame.vector >= 0x20 && frame.vector <= 0x2f) {
}
else if (frame.vector >= 0x20 && frame.vector <= 0x2f)
{
// dprintf("[\e[0;32mIDT\e[0m] Handling IRQ: %d\n", frame.vector - 0x20);

int irq = frame.vector - 0x20;
typedef void (*handler_func_t)(int_frame_t *);

handler_func_t handler = irq_handlers[irq];

if (handler != NULL) {
if (handler != NULL)
{
// dprintf("[\e[0;32mIDT\e[0m] Found handler for IRQ %d\n", irq);
handler(&frame);
}

i8259_SendEndOfInterrupt(irq);
} else if (frame.vector == 0x80) {
}
else if (frame.vector == 0x80)
{
dprintf("[\e[0;32mIDT\e[0m] Handling system call\n");
}
}

void irq_register(uint8_t irq, void *handler) {
void irq_register(uint8_t irq, void *handler)
{
dprintf("[\e[0;32mIDT\e[0m] Registering IRQ handler for IRQ %d\n", irq);
irq_handlers[irq] = handler;
}

void irq_deregister(uint8_t irq) {
void irq_deregister(uint8_t irq)
{
dprintf("[\e[0;32mIDT\e[0m] Deregistering IRQ handler for IRQ %d\n", irq);
irq_handlers[irq] = NULL;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added initrd/usr/share/backgrounds/night.tga
Binary file not shown.
Binary file added initrd/usr/share/fonts/Uni3-Terminus12x6.psf
Binary file not shown.
Binary file added initrd/usr/share/fonts/Uni3-Terminus20x10.psf
Binary file not shown.
File renamed without changes.
2 changes: 2 additions & 0 deletions initrd/usr/share/themes/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Themes:
They are un supported atm
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 3237960

Please sign in to comment.