Compare commits

...

5 Commits

Author SHA1 Message Date
f0ca9de14b Added the current timer tick as a global variable. 2019-08-19 22:58:45 +01:00
2691c1e30e Seriously prioritise output.
Added a beep function to allow PC Speaker output.
This will require an edit to the current QEMU launchscript to get working.
2019-08-19 22:58:26 +01:00
437e10e86c Prioritise output before all else, just so we know when the kernel actually works. 2019-08-19 22:55:28 +01:00
24aad1e4a5 Fix a silly issue with the Interrupts using bits instead of bytes when reading and writing ports. 2019-08-19 22:54:08 +01:00
bec10bcee8 Gitignore weirdness. 2019-07-25 00:44:34 +01:00
4 changed files with 84 additions and 16 deletions

6
.gitignore vendored
View File

@ -57,3 +57,9 @@ Mkfile.old
dkms.conf dkms.conf
# End of https://www.gitignore.io/api/c # End of https://www.gitignore.io/api/c
/.vs
/Sync-OS
/Sync-OS.sln
/Sync-OS.vcxproj
/Sync-OS.vcxproj.user
/Sync-OS.vcxproj.filters

View File

@ -686,6 +686,8 @@ void ScanCPUFeatures(size_t RAX, size_t RCX);
/* ==================== Interrupts ==================== */ /* ==================== Interrupts ==================== */
uint64_t time;
void IRQ_Common(INTERRUPT_FRAME* Frame, size_t Interupt); void IRQ_Common(INTERRUPT_FRAME* Frame, size_t Interupt);
void ISR_Common(INTERRUPT_FRAME* Frame, size_t Interrupt); void ISR_Common(INTERRUPT_FRAME* Frame, size_t Interrupt);
void ISR_Error_Common(EXCEPTION_FRAME* Frame, size_t Exception); void ISR_Error_Common(EXCEPTION_FRAME* Frame, size_t Exception);

View File

@ -44,12 +44,20 @@ void PrepareSystem(FILELOADER_PARAMS* FLOP) {
Memory_Info.MemoryMapDescriptorSize = FLOP->MemoryMapDescriptorSize; Memory_Info.MemoryMapDescriptorSize = FLOP->MemoryMapDescriptorSize;
Memory_Info.MemoryMapDescriptorVersion = FLOP->MemoryMapDescriptorVersion; Memory_Info.MemoryMapDescriptorVersion = FLOP->MemoryMapDescriptorVersion;
SetupPrinting(FLOP->GPU_Info->GPUs[0]);
/* All print functions are now available. */
printf("ready!");
InstallGDT();
InstallIDT();
beep();
if(SetIdentityMap(FLOP->RTServices) == NULL) { if(SetIdentityMap(FLOP->RTServices) == NULL) {
Memory_Info.MemoryMap = FLOP->MemoryMap; Memory_Info.MemoryMap = FLOP->MemoryMap;
} }
SetupPrinting(FLOP->GPU_Info->GPUs[0]);
/* All print functions are now available. */
PrepareAVX(); PrepareAVX();
@ -90,8 +98,6 @@ void PrepareSystem(FILELOADER_PARAMS* FLOP) {
} }
// Set up memory management // Set up memory management
InstallGDT();
InstallIDT();
InstallMemoryMap(); InstallMemoryMap();
InstallPaging(); InstallPaging();
@ -104,6 +110,54 @@ void PrepareSystem(FILELOADER_PARAMS* FLOP) {
} }
/*
* Following section is taken from the OSDev Wiki page on PC Speaker.
* This is beeped first, before *anything* else.
* This way, we know that at least *something* works.
*/
//Play sound using built in speaker
static void play_sound(uint32_t nFrequence) {
uint32_t Div;
uint8_t tmp;
//Set the PIT to the desired frequency
Div = 1193180 / nFrequence;
WritePort(0x0043, 0xb6, 1);
WritePort(0x0042, (uint8_t) (Div), 1);
WritePort(0x0042, (uint8_t) (Div >> 8), 1);
//And play the sound using the PC speaker
tmp = ReadPort(0x0061, 1);
if (tmp != (tmp | 3)) {
WritePort(0x0061, tmp | 3, 1);
}
}
//make it shutup
static void nosound() {
uint8_t tmp = ReadPort(0x0061, 1) & 0xFC;
WritePort(0x0061, tmp, 1);
}
//Make a beep
void beep() {
play_sound(1000);
timer_wait(10);
nosound();
//set_PIT_2(old_frequency);
}
void timer_wait(int ticks){
uint64_t FinalTick = time + ticks;
while(time < FinalTick);
}
/* A temporary system for keeping track of system performance. */ /* A temporary system for keeping track of system performance. */
size_t ClockTick() { size_t ClockTick() {

View File

@ -50,6 +50,7 @@ void ISR_Common(INTERRUPT_FRAME* Frame, size_t Exception) {
if(Exception < 32) { if(Exception < 32) {
/* exception_messages is an array of c-strings defined in kernel.h */ /* exception_messages is an array of c-strings defined in kernel.h */
// TODO: Serial! // TODO: Serial!
//serial_print(0x3F8, exception_messages[Exception]); //serial_print(0x3F8, exception_messages[Exception]);
//serial_print(0x3F8, " Exception.\r\n"); //serial_print(0x3F8, " Exception.\r\n");
printf("%s exception!", ExceptionStrings[Exception]); printf("%s exception!", ExceptionStrings[Exception]);
@ -89,26 +90,26 @@ void IRQ_Common(INTERRUPT_FRAME* Frame, size_t Interrupt) {
/* The Slave PIC must be told it's been read in order to receive another 8+ IRQ. */ /* The Slave PIC must be told it's been read in order to receive another 8+ IRQ. */
if(Interrupt > 7) if(Interrupt > 7)
WritePort(0xA0, 0x20, 8); WritePort(0xA0, 0x20, 1);
/* In either case, we tell the Master PIC it's been read to receive any IRQ. */ /* In either case, we tell the Master PIC it's been read to receive any IRQ. */
WritePort(0x20, 0x20, 8); WritePort(0x20, 0x20, 1);
} }
/* However, in order to actually be able to receive IRQs, we need to remap the PICs. */ /* However, in order to actually be able to receive IRQs, we need to remap the PICs. */
void RemapIRQControllers() { void RemapIRQControllers() {
/* 0x20 is the Master PIC, /* 0x20 is the Master PIC,
0xA0 is the Slave PIC. */ 0xA0 is the Slave PIC. */
WritePort(0x20, 0x11, 8); WritePort(0x20, 0x11, 1);
WritePort(0xA0, 0x11, 8); WritePort(0xA0, 0x11, 1);
WritePort(0x21, 0x20, 8); WritePort(0x21, 0x20, 1);
WritePort(0xA1, 0x28, 8); WritePort(0xA1, 0x28, 1);
WritePort(0x21, 0x04, 8); WritePort(0x21, 0x04, 1);
WritePort(0xA1, 0x02, 8); WritePort(0xA1, 0x02, 1);
WritePort(0x21, 0x01, 8); WritePort(0x21, 0x01, 1);
WritePort(0xA1, 0x01, 8); WritePort(0xA1, 0x01, 1);
WritePort(0x21, 0x0, 8); WritePort(0x21, 0x0, 1);
WritePort(0xA1, 0x0, 8); WritePort(0xA1, 0x0, 1);
} }
/* In order to actually handle the IRQs, though, we need to tell the kernel *where* the handlers are. */ /* In order to actually handle the IRQs, though, we need to tell the kernel *where* the handlers are. */
@ -150,6 +151,11 @@ void UninstallIRQHandler(int IRQ) {
*/ */
__attribute__((interrupt)) void ISR0Handler(INTERRUPT_FRAME* Frame) { __attribute__((interrupt)) void ISR0Handler(INTERRUPT_FRAME* Frame) {
// This baby is the timer.
// TODO: Change ISR0Handler to TimerHandler.
// Here, we can do some timer related stuff.
// For starts, we just tick a timer that tells us how long the program has been running.
time++;
ISR_Common(Frame, 0); ISR_Common(Frame, 0);
} }
__attribute__((interrupt)) void ISR1Handler(INTERRUPT_FRAME* Frame) { __attribute__((interrupt)) void ISR1Handler(INTERRUPT_FRAME* Frame) {