Put timing information in cpu structure
This commit is contained in:
parent
7e3febe699
commit
9ef3c195d0
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@ -12,4 +12,10 @@
|
|||||||
|
|
||||||
"C_Cpp.default.includePath": ["src/kernel/include", "sysroot/usr/include"],
|
"C_Cpp.default.includePath": ["src/kernel/include", "sysroot/usr/include"],
|
||||||
"C_Cpp.default.cStandard": "c17",
|
"C_Cpp.default.cStandard": "c17",
|
||||||
|
"files.associations": {
|
||||||
|
"cpu.h": "c"
|
||||||
|
},
|
||||||
|
"[c]": {
|
||||||
|
"editor.tabSize": 2,
|
||||||
|
},
|
||||||
}
|
}
|
@ -2,6 +2,7 @@
|
|||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <mittos/graphics.h>
|
#include <mittos/graphics.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
#include <cpu.h>
|
||||||
|
|
||||||
extern gfx_context *term_fb;
|
extern gfx_context *term_fb;
|
||||||
extern gfx_context kernel_fb;
|
extern gfx_context kernel_fb;
|
||||||
@ -18,6 +19,12 @@ void thread1() {
|
|||||||
RGB(255,255,0), RGB(0,0,0),
|
RGB(255,255,0), RGB(0,0,0),
|
||||||
'0'+(a++%10)
|
'0'+(a++%10)
|
||||||
);
|
);
|
||||||
|
int s = (current_cpu->timer_ticks/1000)%10;
|
||||||
|
putCharacter(term_fb,
|
||||||
|
0, 0,
|
||||||
|
RGB(255,255,0), RGB(0,0,0),
|
||||||
|
'0'+(s%10)
|
||||||
|
);
|
||||||
flip(term_fb);
|
flip(term_fb);
|
||||||
draw_line(ctx, 0, 100, 50, ((a-1)%100), RGB(0,0,0));
|
draw_line(ctx, 0, 100, 50, ((a-1)%100), RGB(0,0,0));
|
||||||
draw_line(ctx, 0, 100, 50, (a%100), RGB(255,0,0));
|
draw_line(ctx, 0, 100, 50, (a%100), RGB(255,0,0));
|
||||||
|
@ -55,23 +55,22 @@ static uint64_t calibrate_apic_timer() {
|
|||||||
|
|
||||||
void reset_apic_timer(uint64_t us) {
|
void reset_apic_timer(uint64_t us) {
|
||||||
APIC_REG(APIC_TIMER_DIVIDER) = 0xB;
|
APIC_REG(APIC_TIMER_DIVIDER) = 0xB;
|
||||||
APIC_REG(APIC_TIMER_INIT) = us*apic_ticks_per_us;
|
APIC_REG(APIC_TIMER_INIT) = us*current_cpu->timer_freq;
|
||||||
APIC_REG(APIC_LVT(LVT_TIMER)) = 0x0 | IRQ_INTERRUPT(IRQ_TIMER);
|
APIC_REG(APIC_LVT(LVT_TIMER)) = 0x0 | IRQ_INTERRUPT(IRQ_TIMER);
|
||||||
}
|
}
|
||||||
|
|
||||||
volatile int ctr = 0;
|
volatile int ctr = 0;
|
||||||
|
|
||||||
registers *apic_timer_handler(registers *r) {
|
registers *apic_timer_handler(registers *r) {
|
||||||
|
current_cpu->timer_ticks++;
|
||||||
ctr++;
|
|
||||||
__asm__("cli");
|
|
||||||
reset_apic_timer(1000);
|
reset_apic_timer(1000);
|
||||||
irq_ack();
|
irq_ack();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void timer_init() {
|
void timer_init() {
|
||||||
apic_ticks_per_us = calibrate_apic_timer();
|
current_cpu->timer_ticks = 0;
|
||||||
|
current_cpu->timer_freq = calibrate_apic_timer();
|
||||||
bind_interrupt(IRQ_INTERRUPT(IRQ_TIMER), apic_timer_handler);
|
bind_interrupt(IRQ_INTERRUPT(IRQ_TIMER), apic_timer_handler);
|
||||||
reset_apic_timer(1000);
|
reset_apic_timer(1000);
|
||||||
}
|
}
|
@ -55,6 +55,8 @@ struct cpu {
|
|||||||
uint8_t id;
|
uint8_t id;
|
||||||
uint8_t apic_id;
|
uint8_t apic_id;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
|
uint64_t timer_ticks;
|
||||||
|
uint64_t timer_freq; // in ticks per microsecond
|
||||||
};
|
};
|
||||||
struct ioapic {
|
struct ioapic {
|
||||||
uint8_t id;
|
uint8_t id;
|
||||||
@ -66,6 +68,8 @@ extern struct cpu *cpus[MAX_CPUS];
|
|||||||
extern struct ioapic ioapic;
|
extern struct ioapic ioapic;
|
||||||
extern uint8_t irq_redirects[MAX_IRQS];
|
extern uint8_t irq_redirects[MAX_IRQS];
|
||||||
|
|
||||||
|
#define current_cpu (cpus[0])
|
||||||
|
|
||||||
// cpu/cpu.c
|
// cpu/cpu.c
|
||||||
void early_cpu_init();
|
void early_cpu_init();
|
||||||
void cpu_init();
|
void cpu_init();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user