Major interrupt change

This commit is contained in:
2024-10-23 14:11:22 +02:00
parent 11feab5014
commit f163659f0c
38 changed files with 498 additions and 468 deletions
+6
View File
@@ -0,0 +1,6 @@
#ifndef ERROR_DEBUG_H
#define ERROR_DEBUG_H
int debugf(const char* fmt, ...);
#endif
+6
View File
@@ -0,0 +1,6 @@
#ifndef ERROR_PANIC_H
#define ERROR_PANIC_H
void panic();
#endif
+1 -9
View File
@@ -5,7 +5,7 @@
#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)
#define USR_INT_GAME_FLAGS 0xee // P = 1, DPL = 11, S = 0, Type = 1110 (32-bit Int gate)
#define USR_INT_GATE_FLAGS 0xee // P = 1, DPL = 11, S = 0, Type = 1110 (32-bit Int gate)
typedef struct {
uint16_t offsetLow;
@@ -20,14 +20,6 @@ typedef struct {
uint32_t base;
} __attribute__ ((packed)) idtp_t;
typedef struct {
uint32_t eip;
uint32_t cs;
uint32_t eflags;
uint32_t esp;
uint32_t ss;
} __attribute__ ((packed)) intFrame_t;
void idtSetGate(uint8_t i, void* handler, uint8_t flags);
void setupIdt();
+27
View File
@@ -0,0 +1,27 @@
#ifndef INTERRUPT_ISR_H
#define INTERRUPT_ISR_H
#include <stdint.h>
typedef struct {
// Pushed by OS
uint32_t esp, ebx, ecx, edx, esi, edi, ebp;
uint32_t ds, es, fs, gs, eax;
uint32_t interrupt, error;
// Pushed by CPU
uint32_t eip, cs, eflags, user_esp, user_ss;
} intFrame_t;
typedef void (*HandlerPtr)(intFrame_t* iframe);
void setupIsrs();
int handleInterrupt(intFrame_t iframe);
void registerIrq(uint8_t id, HandlerPtr handler);
// ISR Table
extern void* asm_isrRedirectTable[48];
// Int 0x80 - Syscall
extern void isr128();
#endif
-26
View File
@@ -1,26 +0,0 @@
#ifndef INTERRUPT_PIC_H
#define INTERRUPT_PIC_H
#include <stdint.h>
// PIC I/O Ports
#define PIC_1_CMD 0x20
#define PIC_1_DATA 0x21
#define PIC_2_CMD 0xA0
#define PIC_2_DATA 0xA1
// IRQs
#define NEW_IRQ_0 0x20 // IRQ 0 : int 32
#define NEW_IRQ_8 0x28 // IRQ 8 : int 40
// Commands
#define PIC_EOI 0x20 // End Of Interrupt
#define PIC_DISABLE 0xff
void sendPicEOI(uint8_t irq);
void disableIrqs();
void setIrqMask(uint8_t irq);
void unsetIrqMask(uint8_t irq);
void remapPic();
#endif
+2 -1
View File
@@ -1,13 +1,14 @@
#ifndef INTERRUPT_PIT_H
#define INTERRUPT_PIT_H
#include <interrupt/isr.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
void timerHandler(intFrame_t*);
void setPitPhase(uint8_t channel, uint8_t opMode, uint16_t hz);
void setupTimer();
#endif
+2 -1
View File
@@ -1,6 +1,7 @@
#ifndef INTERRUPT_RTC_H
#define INTERRUPT_RTC_H
#include <interrupt/isr.h>
#include <stdint.h>
#include <stdbool.h>
@@ -16,10 +17,10 @@ typedef struct {
uint16_t year;
} __attribute__ ((packed)) datetime_t;
void rtcHandler(intFrame_t*);
bool cmosUpdateProgress();
uint8_t getRtcRegister(uint8_t reg);
void enableRtc();
void disableRtc();
void setupRtc();
#endif
-24
View File
@@ -1,24 +0,0 @@
#ifndef INTERRUPT_SYSCALLS_H
#define INTERRUPT_SYSCALLS_H
#include <interrupt/idt.h>
#include <stdint.h>
typedef struct {
uint32_t esp;
uint32_t ebx;
uint32_t ecx;
uint32_t edx;
uint32_t esi;
uint32_t edi;
uint32_t ebp;
uint32_t ds;
uint32_t es;
uint32_t fs;
uint32_t gs;
uint32_t eax;
} __attribute__ ((packed)) sys_regs_t;
__attribute__ ((naked)) void syscallHandler(intFrame_t* iframe);
#endif
+2 -1
View File
@@ -1,6 +1,7 @@
#ifndef KEYBOARD_KEYBOARD_H
#define KEYBOARD_KEYBOARD_H
#include <interrupt/isr.h>
#include <stdbool.h>
typedef struct {
@@ -8,6 +9,6 @@ typedef struct {
bool shift;
} keyboardState_t;
void setupKeyboard();
void keyboardHandler(intFrame_t*);
#endif
+1 -1
View File
@@ -18,7 +18,7 @@ int serialTransmitEmpty(uint32_t port);
int serialRecieved(uint32_t port);
void serialWrite(uint32_t port, char c);
void serialPrint(uint32_t port, char* s);
void serialPrint(uint32_t port, const char* s);
char serialRead(uint32_t port);
#endif
+19
View File
@@ -0,0 +1,19 @@
#ifndef INTERRUPT_SYSCALLS_H
#define INTERRUPT_SYSCALLS_H
#include <interrupt/isr.h>
int sys_exit (intFrame_t* iframe);
int sys_read (intFrame_t* iframe);
int sys_write (intFrame_t* iframe);
int sys_open (intFrame_t* iframe);
int sys_close (intFrame_t* iframe);
int sys_seek (intFrame_t* iframe);
int sys_malloc (intFrame_t* iframe);
int sys_free (intFrame_t* iframe);
int sys_sleep (intFrame_t* iframe);
// Main syscall handler/dispatcher
int syscallHandler(intFrame_t* iframe);
#endif
+3 -3
View File
@@ -13,11 +13,11 @@ typedef struct {
uint32_t height; // Height in characters
char cursorChar; // Character to use as a cursor
bool hideCursor; // Should we display the cursor
} terminal_t;
} console_t;
extern terminal_t* terminal;
extern console_t* console;
int32_t terminalWrite(const void* buf, uint32_t len);
int32_t consoleWrite(const void* buf, uint32_t len);
void toggleCursor();
#endif