From b21f82cbdbda66a40e667263378d0f54eeea8468 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sat, 21 Dec 2019 12:40:53 +0100 Subject: [PATCH 1/3] Some buggy stuff about optimization of PIT --- include/ke/time.h | 6 +++--- kaleid/kernel/ke/pit.c | 16 ++++++++-------- kaleid/kernel/sh/testcmds.c | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/include/ke/time.h b/include/ke/time.h index b205289..1d7840f 100644 --- a/include/ke/time.h +++ b/include/ke/time.h @@ -61,9 +61,9 @@ char *KeFormatCurTime(void); void KeSetCurTime(Time_t); void KeEnablePIT(void); -void KeSleep(uint); -Timer_t *KeSetTimer(uint delay); -int KeGetTimer(Timer_t*); +void KeSleep(uint volatile); +Timer_t *KeSetTimer(uint volatile delay); +int KeGetTimer(Timer_t volatile *); //----------------------------------------------------------------------------// diff --git a/kaleid/kernel/ke/pit.c b/kaleid/kernel/ke/pit.c index db3bfda..c20dad7 100644 --- a/kaleid/kernel/ke/pit.c +++ b/kaleid/kernel/ke/pit.c @@ -29,10 +29,10 @@ #define COUNTDONE 1 #define PIT_FREQUENCY 1000 // Hz = 1ms -static Timer_t Timer[20]; //20 concurrent sleep max -static ulong Ticks = 0; -static Time_t CurTime; -static char TimeFmtBuf[22] = { 0 }; +static Timer_t volatile Timer[20]; //20 concurrent sleep max +static ulong volatile Ticks = 0; +static Time_t volatile CurTime; +static char volatile TimeFmtBuf[22] = { 0 }; // // ISR handler for the Programmable Interval Timer @@ -78,11 +78,11 @@ void KeSleep(uint delay) timerBlock->sema = 0; } -Timer_t *KeSetTimer(uint delay) +Timer_t *KeSetTimer(uint volatile delay) { - Timer_t *timerBlock; + Timer_t volatile *timerBlock; - if ((timerBlock = (Timer_t*)KeFindTimerBlock()) == NULL) + if ((timerBlock = (Timer_t volatile*)KeFindTimerBlock()) == NULL) return NULL; timerBlock->countDown = delay * PIT_FREQUENCY / 1000; @@ -90,7 +90,7 @@ Timer_t *KeSetTimer(uint delay) return timerBlock; } -int KeGetTimer(Timer_t *timerBlock) +int KeGetTimer(Timer_t volatile *timerBlock) { if (!(timerBlock->sema)) { return 0; diff --git a/kaleid/kernel/sh/testcmds.c b/kaleid/kernel/sh/testcmds.c index 50661fc..d2cf21f 100644 --- a/kaleid/kernel/sh/testcmds.c +++ b/kaleid/kernel/sh/testcmds.c @@ -55,6 +55,19 @@ error_t CmdArgs(int argc, char **argv, char *cmdline) return EOK; } +error_t CmdAtoi(int argc, char **argv, char *cmdline) +{ + int i; + + KernLog("cmdline: '%s'\nargc: %d\n", cmdline, argc); + + for (i = 0; i < argc; i++) { + KernLog("argv[%d]: '%u'\n", i, atoi(argv[i])); + } + + return EOK; +} + error_t CmdDumpATASect(int argc, char **argv, char *cmdline) { char sector[512] = {0}; @@ -199,6 +212,7 @@ error_t CmdTimerTest(int argc, char **argv, char *cmdline) static Command_t testcmdtable[] = { { "args", CmdArgs, "Print command line" }, + { "atoi", CmdAtoi, "Print command line atoised" }, { "dmpsec", CmdDumpATASect, "Dump an ATA sector on screen" }, { "help", CmdHelpTest, "Show this message" }, { "div", CmdFloatDiv, "Float div. Usage : div a b. Returns a/b"}, From 7b35afb2912e59c93e232f85b03343509bd7e6af Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sat, 21 Dec 2019 12:45:54 +0100 Subject: [PATCH 2/3] No more optimization (for instance) for PIT ISR --- include/ke/time.h | 6 +++--- kaleid/kernel/ke/pit.c | 26 ++++++++++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/ke/time.h b/include/ke/time.h index 1d7840f..b205289 100644 --- a/include/ke/time.h +++ b/include/ke/time.h @@ -61,9 +61,9 @@ char *KeFormatCurTime(void); void KeSetCurTime(Time_t); void KeEnablePIT(void); -void KeSleep(uint volatile); -Timer_t *KeSetTimer(uint volatile delay); -int KeGetTimer(Timer_t volatile *); +void KeSleep(uint); +Timer_t *KeSetTimer(uint delay); +int KeGetTimer(Timer_t*); //----------------------------------------------------------------------------// diff --git a/kaleid/kernel/ke/pit.c b/kaleid/kernel/ke/pit.c index c20dad7..a9d961c 100644 --- a/kaleid/kernel/ke/pit.c +++ b/kaleid/kernel/ke/pit.c @@ -29,14 +29,17 @@ #define COUNTDONE 1 #define PIT_FREQUENCY 1000 // Hz = 1ms -static Timer_t volatile Timer[20]; //20 concurrent sleep max -static ulong volatile Ticks = 0; -static Time_t volatile CurTime; -static char volatile TimeFmtBuf[22] = { 0 }; +static Timer_t Timer[20]; //20 concurrent sleep max +static ulong Ticks = 0; +static Time_t CurTime; +static char TimeFmtBuf[22] = { 0 }; // // ISR handler for the Programmable Interval Timer // + +#pragma GCC push_options +#pragma GCC optimize ("O0") static void HandlePIT(ISRFrame_t *regs) { Ticks++; @@ -52,6 +55,7 @@ static void HandlePIT(ISRFrame_t *regs) KeSendEOItoPIC(0x28); } } +#pragma GCC pop_options static Timer_t* KeFindTimerBlock(void) { @@ -63,6 +67,8 @@ static Timer_t* KeFindTimerBlock(void) return NULL; } +#pragma GCC push_options +#pragma GCC optimize ("O0") void KeSleep(uint delay) { Timer_t *timerBlock; @@ -77,20 +83,24 @@ void KeSleep(uint delay) } timerBlock->sema = 0; } +#pragma GCC pop_options -Timer_t *KeSetTimer(uint volatile delay) +#pragma GCC push_options +#pragma GCC optimize ("O0") +Timer_t *KeSetTimer(uint delay) { - Timer_t volatile *timerBlock; + Timer_t *timerBlock; - if ((timerBlock = (Timer_t volatile*)KeFindTimerBlock()) == NULL) + if ((timerBlock = (Timer_t*)KeFindTimerBlock()) == NULL) return NULL; timerBlock->countDown = delay * PIT_FREQUENCY / 1000; return timerBlock; } +#pragma GCC pop_options -int KeGetTimer(Timer_t volatile *timerBlock) +int KeGetTimer(Timer_t *timerBlock) { if (!(timerBlock->sema)) { return 0; From ca2c676df9ab786288ae5ec6779e34a4d1b80bef Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sat, 21 Dec 2019 13:55:02 +0100 Subject: [PATCH 3/3] Working on page protection --- build/kernel.ld | 7 +++++-- kaleid/kernel/io/spkr.c | 8 ++++---- kaleid/kernel/mm/paging.c | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/build/kernel.ld b/build/kernel.ld index 0840bf2..bcc86e2 100644 --- a/build/kernel.ld +++ b/build/kernel.ld @@ -38,13 +38,16 @@ SECTIONS { .text ALIGN (0x1000) : { + _text = .; *(.text) + _text_end = .; } .data ALIGN (0x1000) : { _data = .; *(.data) + _data_end = .; } .eh_frame ALIGN (0x1000) : @@ -55,7 +58,9 @@ SECTIONS { .rodata ALIGN (0x1000) : { + _rodata = .; *(.rodata) + _rodata_end = .; } .bss ALIGN (0x1000) : @@ -70,5 +75,3 @@ SECTIONS { kernelEnd = .; } - - diff --git a/kaleid/kernel/io/spkr.c b/kaleid/kernel/io/spkr.c index dff5d21..bc0450e 100644 --- a/kaleid/kernel/io/spkr.c +++ b/kaleid/kernel/io/spkr.c @@ -100,10 +100,10 @@ void IoDoStarWars(void) //bprintf(BStdOut, "\n"); - for (uint i = 0; i < sizeof(score)/sizeof(struct Note); i++) { - IoDoTone(score[i].tone, score[i].time); - //bprintf(BStdOut, "%d ", i); - //BStdOut->flusher(BStdOut); + for (uint i = 0; i < 41; i++) { + //IoDoTone(score[i].tone, score[i].time); + bprintf(BStdOut, "%d ", score[i].time); + BStdOut->flusher(BStdOut); } IoQuietSpeaker(); diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index 7b9a93c..9f25998 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -33,6 +33,13 @@ volatile pde_t MmPD[512 * RAM_MAX] __attribute__((__aligned__(KPAGESIZE)));; volatile pte_t MmPT[512 * NB_4K] __attribute__((__aligned__(KPAGESIZE)));; +extern ulong _text; +extern ulong _text_end; +extern ulong _rodata; +extern ulong _rodata_end; +extern ulong _data; +extern ulong _data_end; + ulong MmStackGuards[2] = { 0 }; // @@ -68,6 +75,24 @@ void MmInitPaging(void) continue; } + // TEXT + if ((ulong)(i*KPAGESIZE) >= (ulong)_text && (ulong)(i*KPAGESIZE) <= (ulong)_text_end) { + MmPT[i] = ((ulong)(i*KPAGESIZE)); + continue; + } + + // RODATA + if ((ulong)(i*KPAGESIZE) >= (ulong)_rodata && (ulong)(i*KPAGESIZE) <= (ulong)_rodata_end) { + MmPT[i] = ((ulong)(i*KPAGESIZE)) | MF_PRESENT; + continue; + } + + // DATA + if ((ulong)(i*KPAGESIZE) >= (ulong)_data && (ulong)(i*KPAGESIZE) <= (ulong)_data_end) { + MmPT[i] = ((ulong)(i*KPAGESIZE)) | MF_PRESENT; + continue; + } + MmPT[i] = ((ulong)(i*KPAGESIZE)) | MF_PRESENT | MF_READWRITE; }