mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Continuing terminal I/O
- Made stdio.h work - Moved printFiletable back into kernel.c - TODO: Add stdio.h to all files that should use it (probably next commmit) - Added some more global addresses. There's a memory layout, but i'm not using it - Got cursor to be drawn - Calc program now gets user input
This commit is contained in:
@@ -2,20 +2,18 @@
|
||||
#define ISRS_H
|
||||
|
||||
#include <interrupt/idt.h>
|
||||
#include <screen/text.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Exception handlers
|
||||
__attribute__ ((interrupt))
|
||||
void excp_divideErr(intFrame_t* iframe) { // ISR 0
|
||||
fgColor = RED;
|
||||
print("[ Division Error ]\n");
|
||||
print("\x1b[1M[ Division Error ]\n\x1b[8M");
|
||||
iframe->eip++;
|
||||
}
|
||||
|
||||
__attribute__ ((interrupt))
|
||||
void excp_doubleFault(intFrame_t* iframe, uint32_t errCode) { // ISR 8
|
||||
fgColor = RED;
|
||||
print("[ Double Fault ]\n"); // Error code should be 0 (TODO: Maybe check if it's != 0?)
|
||||
print("\x1b[1M[ Double Fault ]\n\x1b[8M"); // Error code should be 0 (TODO: Maybe check if it's != 0?)
|
||||
__asm__ volatile ("cli; hlt");
|
||||
}
|
||||
|
||||
@@ -26,19 +24,17 @@ void excp_pageFault(intFrame_t* iframe, uint32_t errCode) { // ISR 14
|
||||
// cr2 should contain invalid address
|
||||
__asm__ volatile("movl %%cr2, %0" : "=r"(badAddress));
|
||||
|
||||
fgColor = RED;
|
||||
print("[ Page Fault : 0x");
|
||||
print("\x1b[1M[ Page Fault : 0x");
|
||||
print(itoa(errCode, 16));
|
||||
print(" ] - Tried to access 0x");
|
||||
print(itoa(badAddress, 16));
|
||||
print(".\n");
|
||||
print(".\n\x1b[8M");
|
||||
__asm__ volatile ("cli; hlt");
|
||||
}
|
||||
|
||||
__attribute__ ((interrupt))
|
||||
void excp_reserved(intFrame_t* iframe) { // ISR 15
|
||||
fgColor = RED;
|
||||
print("[ Unknown Exception ]\n");
|
||||
print("\x1b[1M[ Unknown Exception ]\n\x1b[8M");
|
||||
__asm__ volatile ("cli; hlt");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define IDT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <screen/text.h>
|
||||
|
||||
#define TRAP_GATE_FLAGS 0x8f // P = 1, DPL = 00, S = 0, Type = 1111 (32-bit Trap gate)
|
||||
#define INT_GATE_FLAGS 0x8e // P = 1, DPL = 00, S = 0, Type = 1110 (32-bit Int gate)
|
||||
|
||||
+13
-7
@@ -1,24 +1,30 @@
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <interrupt/idt.h>
|
||||
#include <interrupt/pic.h>
|
||||
#include <screen/text.h>
|
||||
#include <terminal/terminal.h>
|
||||
#include <memory/addresses.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define CHANNEL_0 0x40 // Offset it by 1 or 2 for ch1 and ch2
|
||||
#define COMMAND 0x43
|
||||
#define INPUT_CLK 1193182
|
||||
|
||||
static uint32_t* timerTicks = (uint32_t*)0x1000;
|
||||
static uint32_t* sleepTimerTicks = (uint32_t*)SLEEP_TIMER;
|
||||
|
||||
__attribute__ ((interrupt))
|
||||
void timerHandler(intFrame_t* iframe) {
|
||||
*timerTicks += 1;
|
||||
static uint32_t cursorTicks = 0;
|
||||
cursorTicks++;
|
||||
|
||||
// TODO: Improve the cursor rendering
|
||||
if (*timerTicks % 500 == 0) putcAt(' ', cursor.x, cursor.y);
|
||||
else if (*timerTicks % 250 == 0) putcAt(127, cursor.x, cursor.y);
|
||||
|
||||
if (terminal->showCursor) {
|
||||
if (cursorTicks % 500 == 0) putcAt(127, terminal->x, terminal->y);
|
||||
else if (cursorTicks % 250 == 0) putcAt(' ', terminal->x, terminal->y);
|
||||
}
|
||||
|
||||
if (*sleepTimerTicks > 0) { --(*sleepTimerTicks); }
|
||||
|
||||
sendPicEOI(0);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ typedef struct {
|
||||
uint16_t year;
|
||||
} __attribute__ ((packed)) datetime_t;
|
||||
|
||||
static datetime_t* datetime = (datetime_t*)0x2000; // TODO: Put this at a constant address in memory
|
||||
static datetime_t* datetime = (datetime_t*)DATETIME_LOC;
|
||||
|
||||
bool cmosUpdateProgress() {
|
||||
outb(CMOS_ADDRESS, 0x8a); // Read status reg A, disable NMI
|
||||
@@ -128,7 +128,12 @@ __attribute__ ((interrupt)) void rtcHandler(intFrame_t* iframe) {
|
||||
strcat(buf, itoa(datetime->second, 10));
|
||||
|
||||
// The clock is a little offset down (about 0.4 of a character) It does look nice though!
|
||||
printAt(buf, gfxMode->xRes - strlen(buf) - 1, 0);
|
||||
uint8_t len = strlen(buf);
|
||||
uint32_t x = gfxMode->xRes - len - 1;
|
||||
char* str = &buf[0];
|
||||
for (uint8_t i = 0; i != len; i++, x++) {
|
||||
putcAt(str[i], x, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,17 +6,16 @@
|
||||
#include <terminal/terminal.h>
|
||||
#include <keyboard/keyboard.h>
|
||||
#include <memory/malloc.h>
|
||||
#include <memory/addresses.h>
|
||||
#include <syscall.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Syscall(0) - Sleep()
|
||||
// Args: ebx - number of miliseconds
|
||||
void sys_sleep() {
|
||||
uint32_t ms;
|
||||
__asm__ volatile ("movl %%ebx, %0" : "=r"(ms));
|
||||
__asm__ volatile ("movl %%ebx, %0" : "=r"(*sleepTimerTicks));
|
||||
|
||||
uint32_t requiredTicks = *timerTicks + ms;
|
||||
while (*timerTicks != requiredTicks) { // Wait...
|
||||
while (*sleepTimerTicks > 0) { // Wait...
|
||||
__asm__ volatile ("sti;hlt;cli;");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user