more work on timers

This commit is contained in:
Adrien Bourmault 2019-11-18 00:15:39 +01:00
parent 5d7374de80
commit f317310437
5 changed files with 69 additions and 44 deletions

View File

@ -22,7 +22,7 @@
# along with OS/K. If not, see <https://www.gnu.org/licenses/>. # # along with OS/K. If not, see <https://www.gnu.org/licenses/>. #
#=----------------------------------------------------------------------------=# #=----------------------------------------------------------------------------=#
.PHONY: all test test32 debug gdb install dust clean OS/K .PHONY: all test test32 debug gdb install dust clean OS/K run
.DELETE_ON_ERROR: $(BINDIR)/kaleid .DELETE_ON_ERROR: $(BINDIR)/kaleid
.DEFAULT_GOAL := all .DEFAULT_GOAL := all
@ -119,9 +119,6 @@ KernSources = kernel/ke/cpuid.c kernel/mm/paging.c \
KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources)) KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources))
KernDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(KernSources)) KernDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(KernSources))
all :
@make OS/K -j 8
## MISC MAKEFILE ------------------------------------------------------------- # ## MISC MAKEFILE ------------------------------------------------------------- #
./ProjectTree: ./.stylehlp_sh ./ProjectTree: ./.stylehlp_sh
@ -263,6 +260,8 @@ $(LOBJDIR)/loader.o: $(LOADERDIR)/loader.asm $(LOADERDIR)/*/*.inc
OS/K: $(dep) ./ProjectTree $(BINDIR)/kaleid OS/K: $(dep) ./ProjectTree $(BINDIR)/kaleid
@echo ${CL2}[[$@]] ${NC} OS/K successfully made, $(mode) mode.${CL3} @echo ${CL2}[[$@]] ${NC} OS/K successfully made, $(mode) mode.${CL3}
all :
@make OS/K -j 8
## QEMU/DEBUG RELATED ## QEMU/DEBUG RELATED
testkvm: all install testkvm: all install
@ -270,6 +269,8 @@ testkvm: all install
-rtc base=localtime -m $(ram) -hda $(installdisk) \ -rtc base=localtime -m $(ram) -hda $(installdisk) \
-d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
run: test
test: all install test: all install
@qemu-system-x86_64 -vga std -cpu $(cpu) -soundhw pcspk -s \ @qemu-system-x86_64 -vga std -cpu $(cpu) -soundhw pcspk -s \
-rtc base=localtime -m $(ram) -hda $(installdisk) \ -rtc base=localtime -m $(ram) -hda $(installdisk) \

View File

@ -63,6 +63,7 @@ void KeSetCurTime(Time_t);
void KeEnablePIT(void); void KeEnablePIT(void);
void KeSleep(uint); void KeSleep(uint);
Timer_t *KeSetTimer(uint delay); Timer_t *KeSetTimer(uint delay);
int KeGetTimer(Timer_t*);
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//

View File

@ -27,7 +27,7 @@
#include <ke/idt.h> #include <ke/idt.h>
#define COUNTDONE 1 #define COUNTDONE 1
#define PIT_FREQUENCY 1000 // Hz = 10ms #define PIT_FREQUENCY 1000 // Hz = 1ms
static Timer_t Timer[20]; //20 concurrent sleep max static Timer_t Timer[20]; //20 concurrent sleep max
static ulong Ticks = 0; static ulong Ticks = 0;
@ -65,33 +65,41 @@ static Timer_t* KeFindTimerBlock(void)
void KeSleep(uint delay) void KeSleep(uint delay)
{ {
struct Timer_t *timerBlock; Timer_t *timerBlock;
if ((timerBlock = (Timer_t*)KeFindTimerBlock()) == NULL) if ((timerBlock = (Timer_t*)KeFindTimerBlock()) == NULL)
return; return;
timerBlock->countDown = delay; timerBlock->countDown = delay * PIT_FREQUENCY / 1000;
while (!timerBlock->sema) { while (!timerBlock->sema) {
KeDelayExecution(1); KeRelaxCPU();
} }
timerBlock->sema = 0; timerBlock->sema = 0;
} }
Timer_t *KeSetTimer(uint delay) Timer_t *KeSetTimer(uint delay)
{ {
struct Timer_t *timerBlock; Timer_t *timerBlock;
if ((timerBlock = (Timer_t*)KeFindTimerBlock()) == NULL) if ((timerBlock = (Timer_t*)KeFindTimerBlock()) == NULL)
return NULL; return NULL;
timerBlock->countDown = delay; timerBlock->countDown = delay * PIT_FREQUENCY / 1000;
DebugLog("Timer set %d ms", delay);
return timerBlock; return timerBlock;
} }
int KeGetTimer(Timer_t *timerBlock)
{
if (!(timerBlock->sema)) {
return 0;
} else {
timerBlock->sema = 0;
return 1;
}
}
void KeEnablePIT(void) void KeEnablePIT(void)
{ {
ulong flags = KePauseIRQs(); ulong flags = KePauseIRQs();
@ -99,15 +107,15 @@ void KeEnablePIT(void)
KeRegisterISR(HandlePIT, 0x20); KeRegisterISR(HandlePIT, 0x20);
IoWriteByteOnPort(0x43, 0x36); // 0x34 = 00110100 for rate gen IoWriteByteOnPort(0x43, 0x36); // 0x36 for rate gen
IoWriteByteOnPort(0x40, (char)(divisor & 0xFF )); // low byte of freq IoWriteByteOnPort(0x40, (char)(divisor & 0xFF )); // low byte of freq
IoWriteByteOnPort(0x40, (char)((divisor >> 8)& 0xFF)); // high byte of freq IoWriteByteOnPort(0x40, (char)((divisor >> 8)& 0xFF)); // high byte of freq
// Setting up the IRQs // Setting up the IRQ line
KeUnmaskIRQ(0); KeUnmaskIRQ(0);
DebugLog("\tPIT activated with rate generator mode %d ms\n", 1000/PIT_FREQUENCY); DebugLog("\tPIT activated with period %d ms\n", 1000/PIT_FREQUENCY);
KeRestoreIRQs(flags); KeRestoreIRQs(flags);
KeEnableNMI(); KeEnableNMI();

View File

@ -189,9 +189,6 @@ void KeEnableRTC(void)
KeRegisterISR(HandleRTC, 0x28); KeRegisterISR(HandleRTC, 0x28);
// Setting up the register control and interrupt rates // Setting up the register control and interrupt rates
DebugLog("\tRTC interrupt frequency set to %d Hz\n",
32768 >> (RTC_RATE - 1));
IoWriteByteOnPort(0x70, 0x8B); IoWriteByteOnPort(0x70, 0x8B);
readRegister = IoReadByteFromPort(0x71); readRegister = IoReadByteFromPort(0x71);
IoWriteByteOnPort(0x70, 0x8B); // Because reading flushes IoWriteByteOnPort(0x70, 0x8B); // Because reading flushes
@ -204,10 +201,9 @@ void KeEnableRTC(void)
IoWriteByteOnPort(0x70, 0x0C); IoWriteByteOnPort(0x70, 0x0C);
IoReadByteFromPort(0x71); // Flush IoReadByteFromPort(0x71); // Flush
// Setting up the IRQs // Setting up the IRQ line
KeUnmaskIRQ(8); KeUnmaskIRQ(8);
// Clean-up // Clean-up
IoWriteByteOnPort(0x70, 0x0C); // Select status reg C IoWriteByteOnPort(0x70, 0x0C); // Select status reg C
IoReadByteFromPort(0x71); // Flush IoReadByteFromPort(0x71); // Flush
@ -217,6 +213,8 @@ void KeEnableRTC(void)
KeEnableNMI(); KeEnableNMI();
srand(KeGetTimeStamp()); // Initializes the kernel number generator srand(KeGetTimeStamp()); // Initializes the kernel number generator
DebugLog("\tRTC interrupt frequency set to %d Hz\n",
32768 >> (RTC_RATE - 1));
} }
void KeDelayExecution(uint time) void KeDelayExecution(uint time)

View File

@ -121,14 +121,6 @@ error_t CmdDate(int argc, char **argv, char *cmdline)
return EOK; return EOK;
} }
error_t CmdSleep(int argc, char **argv, char *cmdline)
{
int delay = ShAtoi(argv[1]);
KeSleep(delay);
return EOK;
}
error_t CmdDumpATASect(int argc, char **argv, char *cmdline) error_t CmdDumpATASect(int argc, char **argv, char *cmdline)
{ {
char sector[512] = {0}; char sector[512] = {0};
@ -235,6 +227,14 @@ error_t CmdShell(int argc, char **argv, char *cmdline)
return EOK; return EOK;
} }
error_t CmdSleep(int argc, char **argv, char *cmdline)
{
int delay = ShAtoi(argv[1]);
KeSleep(delay);
return EOK;
}
error_t CmdStackOverflow(int argc, char **argv, char *cmdline) error_t CmdStackOverflow(int argc, char **argv, char *cmdline)
{ {
CmdStackOverflow(0, 0, 0); CmdStackOverflow(0, 0, 0);
@ -269,6 +269,22 @@ error_t CmdTime(int argc, char **argv, char *cmdline)
return EOK; return EOK;
} }
error_t CmdTimerTest(int argc, char **argv, char *cmdline)
{
int delay = ShAtoi(argv[1]);
Timer_t *timer = KeSetTimer(delay);
while(!(KeGetTimer(timer))) {
bprintf(BStdOut,".");
BStdOut->flusher(BStdOut);
}
KernLog("Finished !\n");
return EOK;
}
error_t CmdVersion(int argc, char **argv, char *cmdline) error_t CmdVersion(int argc, char **argv, char *cmdline)
{ {
int CH = VGA_COLOR_LIGHT_BLUE; int CH = VGA_COLOR_LIGHT_BLUE;
@ -301,21 +317,22 @@ Command_t shcmdtable[] =
{ "color", CmdColor, "Change shell text color" }, { "color", CmdColor, "Change shell text color" },
{ "date", CmdDate, "Print date" }, { "date", CmdDate, "Print date" },
{ "dmpsec", CmdDumpATASect, "Dump an ATA sector on screen" }, { "dmpsec", CmdDumpATASect, "Dump an ATA sector on screen" },
{ "exit", CmdQuit, "Initiate shutdown" },
{ "help", CmdHelp, "Show this message" }, { "help", CmdHelp, "Show this message" },
{ "march", CmdStarWars, "Play the Imperial March" },
{ "mmap", CmdMemMap, "Show memory map" }, { "mmap", CmdMemMap, "Show memory map" },
{ "musage", CmdMemUsage, "Show memory statistics" }, { "musage", CmdMemUsage, "Show memory statistics" },
{ "pfault", CmdPF, "Provoke a PF. Usage: pfault <address>"}, { "pfault", CmdPF, "Provoke a PF. Usage: pfault <address>"},
{ "pstest", CmdPsTest, "Scheduler test routine" }, { "pstest", CmdPsTest, "Scheduler test routine" },
{ "exit", CmdQuit, "Initiate shutdown" },
{ "quit", CmdQuit, "Alias for 'exit'" }, { "quit", CmdQuit, "Alias for 'exit'" },
{ "rpag", CmdReloadPage, "Reload the pages directory" }, { "rpag", CmdReloadPage, "Reload the pages directory" },
{ "shell", CmdShell, "Start a new shell (nested)", }, { "shell", CmdShell, "Start a new shell (nested)", },
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" }, { "stkov", CmdStackOverflow, "Provoke a stack overflow" },
{ "stkun", CmdStackUnderflow, "Provoke a stack underflow" }, { "stkun", CmdStackUnderflow, "Provoke a stack underflow" },
{ "march", CmdStarWars, "Play the Imperial March" }, { "sleep", CmdSleep, "Sleep x ms" },
{ "testimer", CmdTimerTest, "test timer of x ms" },
{ "time", CmdTime, "Print time" }, { "time", CmdTime, "Print time" },
{ "ver", CmdVersion, "Version and legal infos" }, { "ver", CmdVersion, "Version and legal infos" },
{ "sleep", CmdSleep, "Sleep x ms" },
{ NULL, NULL, NULL } { NULL, NULL, NULL }
}; };