wip: timer. sending to pc
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Copyright (c) 2025 0xKarinyash
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include <types.h>
|
||||
|
||||
void timer_init(u32 freq);
|
||||
void timer_handler();
|
||||
void sleep(u64 ms);
|
||||
u64 get_uptime();
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,7 @@ void cmd_meow();
|
||||
void cmd_help();
|
||||
void cmd_regs();
|
||||
void print_regs();
|
||||
void cmd_sleep();
|
||||
int rectest(int a);
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Copyright (c) 2025 0xKarinyash
|
||||
|
||||
#include "drivers/timer.h"
|
||||
#include <io.h>
|
||||
#include <core/panic.h>
|
||||
#include <drivers/keyboard.h>
|
||||
@@ -17,7 +18,7 @@ void isr_handler_c(Registers *regs) {
|
||||
|
||||
void irq_handler_c(Registers *regs) {
|
||||
switch (regs->int_no) {
|
||||
case 32: return outb(MASTER_COMMAND, 0x20);
|
||||
case 32: return timer_handler();
|
||||
case 33: return kb_handler();
|
||||
default: outb(SLAVE_COMMAND, 0x20); break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Copyright (c) 2025 0xKarinyash
|
||||
|
||||
#include <drivers/timer.h>
|
||||
#include <io.h>
|
||||
#include <types.h>
|
||||
|
||||
#define PIT_BASE_CLOCK 1193180
|
||||
#define PIT_CMD 0x43
|
||||
#define PIT_DATA 0x40
|
||||
|
||||
volatile u64 ticks = 0;
|
||||
|
||||
void timer_init(u32 freq) {
|
||||
u32 divisor = PIT_BASE_CLOCK / freq;
|
||||
|
||||
outb(PIT_CMD, 0x36); // 0x36 = 00110110 = channel 0, LOHI byte access, Mode 3, binary
|
||||
outb(PIT_DATA, divisor & 0xFF);
|
||||
outb(PIT_DATA, (divisor >> 8) & 0xFF);
|
||||
|
||||
u8 mask = inb(0x21);
|
||||
mask &= ~(1 << 0);
|
||||
outb(0x21, mask);
|
||||
}
|
||||
|
||||
void timer_handler() {
|
||||
ticks++;
|
||||
outb(MASTER_COMMAND, 0x20);
|
||||
}
|
||||
|
||||
void sleep(u64 ms) {
|
||||
u64 start = ticks;
|
||||
while (ticks < start + ms) __asm__ volatile ("hlt");
|
||||
}
|
||||
|
||||
u64 get_uptime() {
|
||||
return ticks;
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
// Copyright (c) 2025 0xKarinyash
|
||||
|
||||
#include "bootinfo.h"
|
||||
#include "drivers/timer.h"
|
||||
#include <shell/ksh.h>
|
||||
|
||||
#include <types.h>
|
||||
@@ -39,6 +40,8 @@ void kmain(Bootinfo* info) {
|
||||
serial_write("PMM initialized\n");
|
||||
vmm_init(info);
|
||||
serial_write("VMM initialized\n");
|
||||
timer_init(1000);
|
||||
serial_write("Timer initialized\n");
|
||||
|
||||
info = (Bootinfo*)PHYS_TO_HHDM((u64)info);
|
||||
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
#include <drivers/console.h>
|
||||
#include <core/rand.h>
|
||||
|
||||
#include <drivers/timer.h>
|
||||
#include <types.h>
|
||||
|
||||
#include "../data/cats.h"
|
||||
#include "types.h"
|
||||
|
||||
const char* ascii_logo[] = {
|
||||
" /\\___/\\ ",
|
||||
@@ -25,13 +27,15 @@ int rectest(int a) {
|
||||
}
|
||||
|
||||
void cmd_kfetch() {
|
||||
u64 uptime_s = get_uptime() / 1000;
|
||||
|
||||
kprintf("\n\n");
|
||||
kprintf("^p %s ^!\t\t^g kernel^!@^gtermos\n^0", ascii_logo[0]);
|
||||
kprintf("^p %s ^!\t\t^!-------------\n^!", ascii_logo[1]);
|
||||
kprintf("^p %s ^!\t\t^gOS^!: termOS 0.0.1\n^!", ascii_logo[2]);
|
||||
kprintf("^p %s ^!\t\t^gKernel^!: sucks\n^!", ascii_logo[3]);
|
||||
kprintf("^p %s ^!\t\t^gUptime^!: 0h 0m\n^!", ascii_logo[4]);
|
||||
kprintf("^p %s ^!\t\t^gShell^!: termosh\n^!", ascii_logo[5]);
|
||||
kprintf("^p %s ^!\t\t^gUptime^!: %d seconds\n^!", ascii_logo[4], uptime_s);
|
||||
kprintf("^p %s ^!\t\t^gShell^!: ksh\n^!", ascii_logo[5]);
|
||||
kprintf("^p %s ^p\t\t^gDE^!: shitgui\n^!", ascii_logo[6]);
|
||||
kprintf("^p %s ^p\t\t^gCPU^!: %s\n^!", ascii_logo[7], "cool one");
|
||||
kprintf("\n\n");
|
||||
@@ -66,3 +70,8 @@ void print_regs(Registers *regs) {
|
||||
kprintf("^gR15^!=%X\n",regs->r15);
|
||||
kprintf("--------------------------------\n");
|
||||
}
|
||||
|
||||
|
||||
void cmd_sleep() {
|
||||
sleep(3000);
|
||||
}
|
||||
@@ -24,6 +24,8 @@ typedef enum {
|
||||
TOKEN_KFETCH,
|
||||
TOKEN_MEOW,
|
||||
|
||||
TOKEN_SLEEP,
|
||||
|
||||
TOKEN_REGS,
|
||||
TOKEN_RECTEST,
|
||||
TOKEN_PANIC,
|
||||
@@ -55,12 +57,14 @@ static const ksh_command_map token_map[] = {
|
||||
{"fastfetch", TOKEN_KFETCH},
|
||||
{"neofetch", TOKEN_KFETCH},
|
||||
|
||||
{"sleep", TOKEN_SLEEP},
|
||||
{"regs", TOKEN_REGS},
|
||||
{"rectest", TOKEN_RECTEST},
|
||||
{"panic", TOKEN_PANIC},
|
||||
{"ud2", TOKEN_PANIC_UD2},
|
||||
{"pf", TOKEN_PANIC_PF},
|
||||
|
||||
|
||||
{"help", TOKEN_HELP},
|
||||
{nullptr, TOKEN_NULL}
|
||||
};
|
||||
@@ -82,6 +86,7 @@ void ksh() {
|
||||
|
||||
case TOKEN_QUIT: return; // that'll cause panic lol
|
||||
|
||||
case TOKEN_SLEEP: cmd_sleep(); break;
|
||||
case TOKEN_REGS: cmd_regs(); break;
|
||||
case TOKEN_RECTEST: rectest(0); break;
|
||||
case TOKEN_PANIC: panic("Manually initiated panic");
|
||||
|
||||
Reference in New Issue
Block a user