Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
35 changes: 1 addition & 34 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 Expand Up @@ -109,7 +76,7 @@ void setup_pic(void)
//
// remember that ^ toggles bits, so bits 1 and 2 will be toggled to 0
// (which will enable them in hw)
mask1 = 0xff ^ (1 << 1 | 1 << 2);
mask1 = 0xff ^ (1 << 0 | 1 << 1 | 1 << 2);
mask2 = 0xff;
outb(0x21, mask1);
io_wait();
Expand Down
4 changes: 3 additions & 1 deletion source/kernel/include/timer.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once
#include <stdint.h>
#include "idt.h"

unsigned long long get_cpu_time();
void timer_init(uint32_t hz);
void timer_irq(registers_t *frame);
11 changes: 8 additions & 3 deletions source/kernel/isr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "io.h"
#include "keyboard_driver.h"
#include "terminal_driver.h"
#include "timer.h"

isr_t interrupt_handlers[256];

Expand All @@ -21,6 +22,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,11 +34,13 @@ void init_isr()
register_interrupt_handler(3, &breakpoint);
register_interrupt_handler(4, &overflow);

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

// handler initializations
// irq handlers IRQ# + 32
timer_init(100);
register_interrupt_handler(32, &timer_irq);
keyboard_init();
register_interrupt_handler(33, &keyboard_irq);
}

void isr_handler(registers_t *frame)
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
2 changes: 1 addition & 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
51 changes: 44 additions & 7 deletions source/kernel/timer.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
#include "timer.h"
#include "io.h"

unsigned long long get_cpu_time()
{
unsigned long long time_stamp;
// get time_stamp from cpu register
asm volatile("rdtsc" : "=A"(time_stamp));
#define PORT_CHANNEL_0 0x40
#define PORT_CHANNEL_1 0x41
#define PORT_CHANNEL_2 0x42
#define PORT_CMD 0x43

return time_stamp;
// Channel options
#define CHANNEL_0 (0b00 << 6)
#define CHANNEL_1 (0b01 << 6)
#define CHANNEL_2 (0b10 << 6)
#define READ_BACK (0b11 << 6)

// Access mode options
#define LATCH_COUNT (0b00 << 4)
#define LOBYTE_ONLY (0b01 << 4)
#define HIBYTE_ONLY (0b10 << 4)
#define LOBYTE_HIBYTE (0b11 << 4)

// Operating mode options
#define MODE_0 (0b000 << 1) //interrupt on terminal count
#define MODE_1 (0b001 << 1) //hardware retriggerable one-shot
#define MODE_2 (0b010 << 1) //rate generator
#define MODE_3 (0b011 << 1) //square wave generator
#define MODE_4 (0b100 << 1) //software strobe
#define MODE_5 (0b101 << 1) //hardware strobe

// BCD/Binary mode options
#define BINARY_MODE 0
#define BCD_MODE 1

uint32_t divisor;
uint32_t tick;

void timer_init(uint32_t hz) {
tick = 0;
divisor = 1193180 / hz;
outb(PORT_CMD, CHANNEL_0 | LOBYTE_HIBYTE | MODE_3 | BINARY_MODE);
uint8_t lowbyte = (uint8_t) (divisor & 0xFF);
uint8_t highbyte = (uint8_t) ((divisor >> 8) & 0xFF);
outb(PORT_CHANNEL_0, lowbyte);
outb(PORT_CHANNEL_0, highbyte);
}

unsigned long long get_cpu_frequency() {}
void timer_irq(registers_t *frame) {
tick++;
// printf("%x\n", tick);
}