Skip to content

Commit e3b0c80

Browse files
committed
architectural updates to the kernel
1 parent a77b161 commit e3b0c80

4 files changed

Lines changed: 31 additions & 6 deletions

File tree

‎include/timer.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
void pit_init(uint32_t frequency);
77
uint64_t timer_get_ticks(void);
8+
void timer_handler(void);
9+
void timer_init(void);
810

911
#endif
1012

‎src/arch/timer.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdint.h>
2+
#include "timer.h"
3+
4+
// This counter increments every time the PIT timer fires
5+
static uint64_t global_ticks = 0;
6+
7+
uint64_t timer_get_ticks() {
8+
return global_ticks;
9+
}
10+
11+
// This is called by your interrupt handler in isr.c
12+
void timer_handler(void) {
13+
global_ticks++;
14+
}
15+
16+
// Basic PIT initialization (100Hz)
17+
void timer_init(void) {
18+
// You can add outb() commands here later to set the frequency
19+
}

‎src/cpu/isr.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
#include "serial.h"
99
#include "types.h"
1010

11+
#include "timer.h"
12+
1113
static isr_t interrupt_handlers[256];
12-
static volatile uint64_t timer_ticks = 0;
1314
static volatile uint32_t interrupt_depth = 0;
1415

1516
static uint16_t* const vga_buffer = (uint16_t*)0xB8000;
@@ -194,7 +195,7 @@ static registers_t* exception_handler(registers_t* regs) {
194195
}
195196

196197
static registers_t* irq0_handler(registers_t* regs) {
197-
timer_ticks++;
198+
timer_handler();
198199
kswapd_tick();
199200
process_t* previous = 0;
200201
process_t* next = switch_task(regs, &previous);
@@ -239,7 +240,3 @@ registers_t* irq_handler(registers_t* regs) {
239240
outb(0x20, 0x20);
240241
return regs;
241242
}
242-
243-
uint64_t timer_get_ticks(void) {
244-
return timer_ticks;
245-
}

‎src/cpu/isr_handler.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "idt.h"
2+
3+
// Redirect to the implementation in isr.c
4+
void register_interrupt_handler(uint8_t n, isr_t handler);
5+
6+
// This file exists to satisfy dependencies on isr_handler.c
7+
// and can be expanded for specific handler logic if needed.

0 commit comments

Comments
 (0)