on modularity and extendability (the first full release should be 0.3beta. Up to now, it looks more like a monolithic kernel, for the development and the function testing phase).
So far, I've got IDT, GDT, exceptions, IRQs, and the PIT working. However, I now have the following problem: the keyboard won't work. I believe in an IRQ firing or dispatching problem, as calling the function manually shows it works.
Here is the code for the keyboard:
Code: Select all
/* Keyboard base driver */
#include <CoreKernel/SystemMgr-ck/SystemMgr-ck.h>
#include <SysCore/SC_io.h>
#include "KeyboardBase.h"
#include "KeyboardUSMap.h"
#include <libSystem/TermPCCons/TermPCCons.h>
unsigned char KbdStatus = 0;
void InputKbdIRQInstall() {
TermTextPrint("\t* Input manager: Installing keyboard handler\n",WHITE,BLACK);
SysIRQHandlerRegister(1,InputKbdIRQHandler);
}
void InputKbdIRQHandler(struct SSSysRegs_s *dummyp) {
unsigned char KbdScancode = 0;
TermTextPrint("* Input manager/Keyboard: Acquiring scancode\n", WHITE,BLACK);
KbdScancode = SC_IOPortRead(0x60);
if (KbdScancode & 0x80) {
switch (BaseKbdMap[KbdScancode]) {
case 160:
KbdStatus - 128;
break;
case 161:
KbdStatus - 64;
break;
}
}
else {
TermTextPrint("* Input manager/Keyboard: Checking for special scancodes\n",WHITE,BLACK);
if ((BaseKbdMap[KbdScancode] >= 160) && (BaseKbdMap[KbdScancode] <= 168)) {
switch (BaseKbdMap[KbdScancode]) {
case 160: // Shift
KbdStatus | 128;
break;
case 161: // Alt
KbdStatus | 64;
break;
}
}
else {
TermTextPrint("Printing key on terminal\n",WHITE,BLACK);
if (KbdStatus & 0x80) {
TermCharPut(BaseKbdShiftMap[KbdScancode],WHITE,BLACK);
}
else {
TermCharPut(BaseKbdMap[KbdScancode],WHITE,BLACK);
}
}
}
}
Code: Select all
/* Keyboard base driver header */
extern void InputKbdIRQInstall(void);
extern void InputKbdIRQHandler(struct SSSysRegs_s *dummyp);
Code: Select all
/* System manager IRQ routines */
#include "SystemMgr-ck.h"
#include <SysCore/SC_io.h>
void *SysIRQHandler[16] = {
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0
};
void SysIRQHandlerRegister(unsigned char IntNum, void (*IRQHandler)(struct SSSysRegs_s *regsp)) {
SysIRQHandler[IntNum] = IRQHandler;
}
void SysIRQHandlerUnregister(unsigned char IntNum) {
SysIRQHandler[IntNum] = 0;
}
void SysIRQRemap() {
SC_IOPortWrite(0x20, 0x11);
SC_IOPortWrite(0xA0, 0x11);
SC_IOPortWrite(0x21, 0x20);
SC_IOPortWrite(0xA1, 0x28);
SC_IOPortWrite(0x21, 0x04);
SC_IOPortWrite(0xA1, 0x02);
SC_IOPortWrite(0x21, 0x01);
SC_IOPortWrite(0xA1, 0x01);
SC_IOPortWrite(0x21, 0x0);
SC_IOPortWrite(0xA1, 0x0);
}
void SysIRQInstall() {
SysIRQRemap();
SysIDTEntrySet(32, (unsigned)SysIRQ0, 0x08, 0);
SysIDTEntrySet(33, (unsigned)SysIRQ1, 0x08, 0);
SysIDTEntrySet(34, (unsigned)SysIRQ2, 0x08, 0);
SysIDTEntrySet(35, (unsigned)SysIRQ3, 0x08, 0);
SysIDTEntrySet(36, (unsigned)SysIRQ4, 0x08, 0);
SysIDTEntrySet(37, (unsigned)SysIRQ5, 0x08, 0);
SysIDTEntrySet(38, (unsigned)SysIRQ6, 0x08, 0);
SysIDTEntrySet(39, (unsigned)SysIRQ7, 0x08, 0);
SysIDTEntrySet(40, (unsigned)SysIRQ8, 0x08, 0);
SysIDTEntrySet(41, (unsigned)SysIRQ9, 0x08, 0);
SysIDTEntrySet(42, (unsigned)SysIRQ10, 0x08, 0);
SysIDTEntrySet(43, (unsigned)SysIRQ11, 0x08, 0);
SysIDTEntrySet(44, (unsigned)SysIRQ12, 0x08, 0);
SysIDTEntrySet(45, (unsigned)SysIRQ13, 0x08, 0);
SysIDTEntrySet(46, (unsigned)SysIRQ14, 0x08, 0);
SysIDTEntrySet(47, (unsigned)SysIRQ15, 0x08, 0);
}
void SysIRQDispatcher(struct SSSysRegs_s *regsp) {
void (*CurrentIRQHandler)(struct SSSysRegs_s *regsp);
CurrentIRQHandler = SysIRQHandler[(regsp->int_no - 32)];
if (CurrentIRQHandler) {
CurrentIRQHandler(regsp);
}
if ((regsp->int_no >= 40) && (regsp->int_no <= 47)) {
SC_IOPortWrite(0xA0,0x20);
}
SC_IOPortWrite(0x20,0x20);
}
Code: Select all
/* SC_IO.c */
unsigned char SC_IOPortRead(unsigned short port) {
unsigned char rv;
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (port));
return rv;
}
void SC_IOPortWrite(unsigned short port, unsigned char value) {
__asm__ __volatile__ ("outb %1, %0" : : "dN" (port), "a" (value));
}