From ca2c676df9ab786288ae5ec6779e34a4d1b80bef Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sat, 21 Dec 2019 13:55:02 +0100 Subject: [PATCH] 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; }