Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel fix #28

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions source/kernel/idt.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,6 @@ __attribute__((aligned(0x10))) static idt_entry_t idt[NUM_IDTS];
// define the idtr
static idtr_t idtr;

static uint32_t has_triggered = 0;
static uint32_t hits = 0;
static uint32_t oopsie_woopsie = 0;

uint32_t get_hits(void) { return oopsie_woopsie; }

// we no-inline because I don't want it inlined :lemonthink:
// also i want the actual isr to only have save register, call, then iret
__attribute__((noinline)) static void actual_exception_handler(void)
{
oopsie_woopsie++;
}

// this currently will triple-fault on pressing a keyboard
__attribute__((noinline)) static void actualirq1Handler(void)
{
// seems to triple fault before reaching here, idk pls can we get serial
// driver
hits++;
if (terminal_driver_loaded() && !has_triggered) {
terminal_putchar('U');
terminal_update_cursor();
// inb(0x60) is the port containing the key pressed
terminal_put64(inb(0x60));
terminal_update_cursor();

// send eoi to the master PIC
// this is needed in the PIC remapping, don't question it
outb(0x20, 0x20);
__asm__ volatile("cli");
}
}

void idt_set_entry(int idx, uint32_t handler_ptr, uint16_t code_selector,
uint8_t attributes)
{
Expand Down
6 changes: 6 additions & 0 deletions source/kernel/isr.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ void breakpoint(registers_t *frame) { printf("breakpoint\n"); }

void overflow(registers_t *frame) { printf("overflow trap\n"); }

void pagefault(registers_t *frame) { printf("page fault\n"); }

void init_isr()
{
for (int i = 0; i < 256; i++)
Expand All @@ -31,9 +33,13 @@ void init_isr()
register_interrupt_handler(3, &breakpoint);
register_interrupt_handler(4, &overflow);

register_interrupt_handler(14, &pagefault);

// irq handlers
register_interrupt_handler(33, &keyboard_irq);

printf("%x\n", &keyboard_irq);

// handler initializations
keyboard_init();
}
Expand Down
26 changes: 2 additions & 24 deletions source/kernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,10 @@ void main()
{
init_drivers();
terminal_clear();
init_paging();
terminal_update_cursor();
init_idt();
asm volatile("int $0x3");
asm volatile("int $0x4");
init_paging();
printf("Hello");

write_serial(COM1, "Hello From SecureOS!");
// printf(s.data);

// init_paging();
// string s;
// s.data =
// "HEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLLLLLLLLLLLL"
// "LLOOOOOOOOOOOOOOOOOOOOOOOOOOOOO";
// s.len = 96;
// printf(&s);
// uint32_t* wow = (uint32_t*) 0x12340000;
// palloc(wow, PAGE_PRESENT | PAGE_RW);
// *wow = 0x42042069;
// terminal_put64(*wow);
// for (int i = 0; i < 30; i ++) {
// uint32_t* smol = kalloc(200);
// *smol = 0x12345678;
// terminal_put64(smol);
// terminal_putchar(' ');
// terminal_put64(*smol);
// terminal_putchar('\n');
// }
}
2 changes: 1 addition & 1 deletion source/kernel/kernel_entry.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ global kernel_entry

; flags for a megapage
MEGAPAGE_FLAGS equ (1 << 7) | (1 << 1) | (1 << 0)
L2_PAGE_BASE equ l2_page_table - (1 << 31)
L2_PAGE_BASE equ l2_page_table - (0x80100000)

kernel_entry:
; enable page size extensions
Expand Down
3 changes: 2 additions & 1 deletion source/kernel/memory.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "memory.h"
#include "terminal_driver.h"
#include "io.h"
#include <stdint.h>
#include <stdlib.h>

uint32_t l2_page_table[1024] __attribute__((aligned(4096)));

Expand Down Expand Up @@ -266,5 +266,6 @@ void print_chunks()
void init_paging()
{
// unmap lower page
printf("%x\n", l2_page_table[0]);
l2_page_table[0] = 0;
}