Compare commits

..

No commits in common. "9e85807a09ca6f7a949b378532b43d48d7be228d" and "457244222b49d35cd606d02620430821d56b6fa2" have entirely different histories.

10 changed files with 48 additions and 101 deletions

View File

@ -1,15 +1,7 @@
#pragma once #pragma once
#include "kprintf.h"
#include <stdint.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 {
struct stackframe *ebp; struct stackframe *ebp;
uint32_t eip; uint32_t eip;

View File

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

View File

@ -1,54 +0,0 @@
#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,6 +1,7 @@
#pragma once #pragma once
#include "keyboard.h" #include "keyboard.h"
#include "kprintf.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>

View File

@ -91,7 +91,7 @@ _start:
# Enable paging and the write-protect bit. # Enable paging and the write-protect bit.
movl %cr0, %ecx movl %cr0, %ecx
orl $0x80000000, %ecx orl $0x80010000, %ecx
movl %ecx, %cr0 movl %ecx, %cr0
# Jump to higher half with an absolute jump. # Jump to higher half with an absolute jump.

View File

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

View File

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

View File

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

View File

@ -4,16 +4,42 @@
#include <stdint.h> #include <stdint.h>
extern void enable_paging(void);
extern void load_page_directory(uint32_t *);
extern uint32_t boot_page_table1;
extern uint32_t boot_page_directory; extern uint32_t boot_page_directory;
// Pour récupérer une entrée spécifique
uint32_t *page_directory = &boot_page_directory; uint32_t *page_directory = &boot_page_directory;
uint32_t page_table1[1024] __attribute__((aligned(4096))); uint32_t page_table_entries[1024];
uint32_t page_table_entries[1024] __attribute__((aligned(4096)));
unsigned long read_cr3()
{
unsigned long cr3_value;
// Inline assembly to read CR3
__asm__ volatile(
"mov %%cr3, %0" // Move the value of CR3 into cr3_value
: "=r"(
cr3_value) // Output operand: cr3_value will receive the value
: // No input operands
: // No clobber list
);
return cr3_value;
}
static inline void load_cr3(uint64_t cr3_value)
{
asm volatile("mov %0, %%cr3" ::"r"(cr3_value) : "memory");
}
void init_memory(void) void init_memory(void)
{ {
for (int16_t i = 0; i < 0x300; i++)
page_directory[i] = 0x02; for (int i = 0; i < 1024; i++)
for (int16_t i = 0; i < 1024; i++) page_table_entries[i] = (i << 12) | INIT_FLAGS;
page_table1[i] = i << 12 | 0x03;
page_directory[0] = (uint32_t)page_table1 | 0x03; page_directory[0] = ((uint32_t)page_table_entries << 12) | INIT_FLAGS;
} }