more work on timers
This commit is contained in:
parent
5d7374de80
commit
f317310437
9
Makefile
9
Makefile
|
@ -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) \
|
||||||
|
|
|
@ -48,21 +48,22 @@ struct Timer_t {
|
||||||
ulong sema;
|
ulong sema;
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
void KeSetupRTC(void);
|
void KeSetupRTC(void);
|
||||||
void KeEnableRTC(void);
|
void KeEnableRTC(void);
|
||||||
|
|
||||||
ulong KeGetTimeStamp(void);
|
ulong KeGetTimeStamp(void);
|
||||||
ulong KeGetClockTicks(void);
|
ulong KeGetClockTicks(void);
|
||||||
Time_t *KeGetOriginTime(void);
|
Time_t *KeGetOriginTime(void);
|
||||||
void KeDelayExecution(uint);
|
void KeDelayExecution(uint);
|
||||||
|
|
||||||
Time_t *KeGetCurTime(void);
|
Time_t *KeGetCurTime(void);
|
||||||
char *KeFormatCurTime(void);
|
char *KeFormatCurTime(void);
|
||||||
void KeSetCurTime(Time_t);
|
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*);
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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};
|
||||||
|
@ -213,7 +205,7 @@ error_t CmdPF(int argc, char **argv, char *cmdline)
|
||||||
|
|
||||||
error_t CmdPsTest(int argc, char **argv, char *cmdline)
|
error_t CmdPsTest(int argc, char **argv, char *cmdline)
|
||||||
{
|
{
|
||||||
// pstest();
|
// pstest();
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue