Merge branch 'main' of git.chauvet.pro:starnakin/42_KFS

This commit is contained in:
0x35c 2024-10-17 16:11:40 +02:00
commit 9e85807a09
10 changed files with 95 additions and 16 deletions

View File

@ -1,10 +1,18 @@
#pragma once
#include "kprintf.h"
#include <stdint.h>
#define PRINT_VAR(var) kprintf("%s: %d\n", #var, var)
struct function_entry {
uint32_t addr;
char name[64];
};
struct stackframe {
struct stackframe *ebp;
uint32_t eip;
};
void print_stack(void);
void print_stack(void);

View File

@ -8,6 +8,7 @@
#define ACCESSED (1 << 4)
#define INIT_FLAGS (PRESENT | RW | SUPERVISOR)
#define PAGE_SIZE 4096
#define KERN_START 0xC0000000
void init_memory(void);
void *alloc_frames(size_t size);

54
headers/signal.h Normal file
View File

@ -0,0 +1,54 @@
#pragma once
#define SIG_DFL -1
#define SIG_IGN 0
enum {
SIGABRT, // Abort signal from abort(3)
SIGALRM, // Timer signal from alarm(2)
SIGBUS, // Bus error (bad memory access)
SIGCHLD, // Child stopped or terminated
SIGCLD, // A synonym for SIGCHLD
SIGCONT, // Continue if stopped
SIGEMT, // Emulator trap
SIGFPE, // Floating-point exception
SIGHUP, // Hangup detected on controlling terminal or death of
// controlling process
SIGILL, // Illegal Instruction
SIGINFO, // A synonym for SIGPWR
SIGINT, // Interrupt from keyboard
SIGIO, // I/O now possible (4.2BSD)
SIGIOT, // IOT trap. A synonym for SIGABRT
SIGKILL, // Kill signal
SIGLOST, // File lock lost (unused)
SIGPIPE, // Broken pipe: write to pipe with no readers; see pipe(7)
SIGPOLL, // Pollable event (Sys V); synonym for SIGIO
SIGPROF, // Profiling timer expired
SIGPWR, // Power failure (System V)
SIGQUIT, // Quit from keyboard
SIGSEGV, // Invalid memory reference
SIGSTKFLT, // Stack fault on coprocessor (unused)
SIGSTOP, // Stop process
SIGTSTP, // Stop typed at terminal
SIGSYS, // Bad system call (SVr4); see also seccomp(2)
SIGTERM, // Termination signal
SIGTRAP, // Trace/breakpoint trap
SIGTTIN, // Terminal input for background process
SIGTTOU, // Terminal output for background process
SIGUNUSED, // Synonymous with SIGSYS
SIGURG, // Urgent condition on socket (4.2BSD)
SIGUSR1, // User-defined signal 1
SIGUSR2, // User-defined signal 2
SIGVTALRM, // Virtual alarm clock (4.2BSD)
SIGXCPU, // CPU time limit exceeded (4.2BSD); see setrlimit(2)
SIGXFSZ, // File size limit exceeded (4.2BSD); see setrlimit(2)
SIGWINCH, // Window resize signal (4.3BSD, Sun)
SIG_INT, // Interrupt from keyboard
};
typedef void (*sighandler_t)(int);
struct signal {
int signum;
sighandler_t handler;
};

View File

@ -1,7 +1,6 @@
#pragma once
#include "keyboard.h"
#include "kprintf.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@ -58,4 +57,4 @@ void terminal_set_default_fg_color(uint8_t fg_color);
void terminal_set_default_bg_color(uint8_t fg_color);
void terminal_change_default_fg_color(uint8_t color);
uint8_t terminal_get_default_color(void);
uint8_t terminal_get_char(int column, int row);
uint8_t terminal_get_char(int column, int row);

View File

@ -91,7 +91,7 @@ _start:
# Enable paging and the write-protect bit.
movl %cr0, %ecx
orl $0x80010000, %ecx
orl $0x80000000, %ecx
movl %ecx, %cr0
# Jump to higher half with an absolute jump.
@ -119,4 +119,4 @@ _start:
# Infinite loop if the system has nothing more to do.
cli
1: hlt
jmp 1b
jmp 1b

View File

@ -1,5 +1,6 @@
#include "debug.h"
#include "kprintf.h"
#include <stddef.h>
void print_stack(void)
{

View File

@ -0,0 +1,10 @@
#include "signal.h"
#include <stddef.h>
void (*signal(int sig, void (*func)(int)))(int)
{
// TODO after multi tasking and processes
(void)sig;
(void)func;
return NULL;
}

View File

@ -6,6 +6,7 @@
#include "memory.h"
#include "power.h"
#include "shell.h"
#include "string.h"
#include "terminal.h"
#include <stdbool.h>
@ -28,13 +29,15 @@ void kernel_main(void)
terminal_initialize();
init_gdt();
init_idt();
/* init_memory(); */
init_memory();
load_drivers();
memset((void *)0x10001, 'a', 10);
kprintf(KERN_ALERT
"I see no way to confuse an array of 256 seg:off pairs with a "
"complex 8*unknown quantity -byte descriptor table. -- Troy "
"Martin 03:50, 22 March 2009 (UTC)\n");
while (!kmalloc(10))
;
/* vmalloc(10); */
/* while (!vmalloc(10)) */
/* ; */
shell_init();
}

View File

@ -8,15 +8,18 @@ void kpanic(const char *format, ...)
{
va_list va;
terminal_set_bg_color(VGA_COLOR_BLUE);
terminal_clear();
/* terminal_set_bg_color(VGA_COLOR_BLUE); */
/* terminal_clear(); */
va_start(va, format);
kvprintf(format, va);
va_end(va);
kprintf("\n\n");
print_stack();
kprintf("\n\n");
kprintf("PRESS SPACE TO REBOOT");
uint32_t faulting_address;
__asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_address));
kprintf("fault at address: %p\n", faulting_address);
/* kprintf("\n\n"); */
/* print_stack(); */
/* kprintf("\n\n"); */
/* kprintf("PRESS SPACE TO REBOOT"); */
while (terminal_getkey().scan_code != KEY_SPACE)
;
reboot();

View File

@ -6,10 +6,10 @@
#include "memory.h"
#include "utils.h"
#define PT_SIZE 0x300
#define PT_SIZE 1024
#define MAX_TLB_ENTRIES 32
extern uint32_t page_table_entries[PT_SIZE] __attribute__((aligned(4096)));
extern uint32_t page_table_entries[PT_SIZE];
static int16_t find_next_block(size_t nb_pages)
{