1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00

Merge branch 'cpu&memory' into BetterTerm

This commit is contained in:
Adrien Bourmault 2019-04-24 22:40:29 +02:00
commit a2280e31e2
2 changed files with 74 additions and 11 deletions

View File

@ -38,6 +38,7 @@ extern error_t IoInitVGABuffer(void);
//io/keyb.c //io/keyb.c
extern void IoSetupKeyb(void); extern void IoSetupKeyb(void);
extern void IoEnableKeyb(void);
//io/rtc.c //io/rtc.c
extern void IoSetupRtc(void); extern void IoSetupRtc(void);
@ -87,21 +88,20 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
// Drivers ISR inits // Drivers ISR inits
IoSetupRtc(); IoSetupRtc();
IoSetupKeyb();
// Interrupts launching // Interrupts launching
IdtSetup(); IdtSetup();
KeEnableIRQs(); KeEnableIRQs();
// Drivers enabling // Drivers enabling
IoEnableRtc(); IoEnableRtc();
IoEnableKeyb();
while (1) { while (1) {
asm volatile ("hlt");
if (IoRtcTicks > 2000) {
KernLog("CC\n");
break;
}
}
KernLog("\nGoodbye after %d ticks", IoRtcTicks);
}
KernLog("\nGoodbye after %d ticks", IoRtcTicks);
// End this machine's suffering // End this machine's suffering
BFlushBuf(BStdOut); BFlushBuf(BStdOut);
KeCrashSystem(); KeCrashSystem();

View File

@ -24,18 +24,83 @@
#include <kernel/base.h> #include <kernel/base.h>
#include <kernel/iomisc.h> #include <kernel/iomisc.h>
#include <extras/buf.h>
extern void KeybIsr(void); extern void KeybIsr(void);
extern void IdtRegisterIrq(void (*isr)(void), uchar irq, uchar flags); extern void IdtRegisterIrq(void (*isr)(void), uchar irq, uchar flags);
extern void SendEOItoPIC(void); extern void SendEOItoPIC(void);
char ScanCodes[100] = { 0 };
void IoSetupKeyb(void) void IoSetupKeyb(void)
{ {
IdtRegisterIrq(KeybIsr, 0x21, 0x8E); IdtRegisterIrq(KeybIsr, 0x21, 0x8E);
} }
void KeybPrint(char code)
{
if (code) {
bprintf(BStdOut, "%c", ScanCodes[(int)code]);
BFlushBuf(BStdOut);
}
}
uchar KeybHandler(void) void ScanCodesInit(void)
{
ScanCodes[0x02] = '1';
ScanCodes[0x03] = '2';
ScanCodes[0x04] = '3';
ScanCodes[0x05] = '4';
ScanCodes[0x06] = '5';
ScanCodes[0x07] = '6';
ScanCodes[0x08] = '7';
ScanCodes[0x09] = '8';
ScanCodes[0x0A] = '9';
ScanCodes[0x0B] = '0';
ScanCodes[0x10] = 'a';
ScanCodes[0x11] = 'z';
ScanCodes[0x12] = 'e';
ScanCodes[0x13] = 'r';
ScanCodes[0x14] = 't';
ScanCodes[0x15] = 'y';
ScanCodes[0x16] = 'u';
ScanCodes[0x17] = 'i';
ScanCodes[0x18] = 'o';
ScanCodes[0x19] = 'p';
ScanCodes[0x1E] = 'q';
ScanCodes[0x1F] = 's';
ScanCodes[0x20] = 'd';
ScanCodes[0x21] = 'f';
ScanCodes[0x22] = 'g';
ScanCodes[0x23] = 'h';
ScanCodes[0x24] = 'j';
ScanCodes[0x25] = 'k';
ScanCodes[0x26] = 'l';
ScanCodes[0x2C] = 'w';
ScanCodes[0x2D] = 'x';
ScanCodes[0x2E] = 'c';
ScanCodes[0x2F] = 'v';
ScanCodes[0x30] = 'b';
ScanCodes[0x31] = 'n';
ScanCodes[0x32] = 'm';
ScanCodes[0x1C] = '\n';
ScanCodes[0x39] = ' ';
}
void IoEnableKeyb(void)
{
ulong flags = KePauseIRQs();
char readedInterruptConfig = IoReadByteFromPort(0x21);
IoWriteByteOnPort(0x21, 0xFD & readedInterruptConfig);
KeRestoreIRQs(flags);
ScanCodesInit();
}
void KeybHandler(void)
{ {
char status; char status;
char code = 0; char code = 0;
@ -50,7 +115,5 @@ uchar KeybHandler(void)
if(code < 0) code = 0; if(code < 0) code = 0;
} }
KeybPrint((int)code);
return code;
} }