From d056bc2fb64831b74e63858a446197e008081860 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sun, 12 Jan 2020 17:21:12 +0100 Subject: [PATCH] Working on page allocator #67 --- ProjectTree | 6 ++++-- include/mm/paging.h | 1 + include/mm/palloc.h | 38 +++++++++++++++++++++++++++++++++++++ kaleid/kernel/mm/paging.c | 24 +++++++++++------------ kaleid/kernel/mm/palloc.c | 38 +++++++++++++++++++++++++++++++++++++ kaleid/kernel/sh/testcmds.c | 8 ++++---- 6 files changed, 96 insertions(+), 19 deletions(-) create mode 100644 include/mm/palloc.h create mode 100644 kaleid/kernel/mm/palloc.c diff --git a/ProjectTree b/ProjectTree index 05361f9..1c063cc 100644 --- a/ProjectTree +++ b/ProjectTree @@ -70,9 +70,11 @@ │   │   ├── buf.h │   │   └── list.h │   ├── mm +│   │   ├── gdt.h │   │   ├── heap.h │   │   ├── malloc.h -│   │   └── mm.h +│   │   ├── map.h +│   │   └── paging.h │   ├── po │   │   └── shtdwn.h │   ├── sh @@ -155,4 +157,4 @@ ├── ProjectTree └── README.md -28 directories, 102 files +28 directories, 104 files diff --git a/include/mm/paging.h b/include/mm/paging.h index c25ed08..d76f0ec 100644 --- a/include/mm/paging.h +++ b/include/mm/paging.h @@ -33,6 +33,7 @@ #define KPAGESIZE (4 * KB) #define UPAGESIZE (4 * KB) +#define USERSPACE 0x80000000 //----------------------------------------------------------------------------// diff --git a/include/mm/palloc.h b/include/mm/palloc.h new file mode 100644 index 0000000..bada93f --- /dev/null +++ b/include/mm/palloc.h @@ -0,0 +1,38 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Desc: Page allocator related functions // +// // +// // +// Copyright © 2018-2019 The OS/K Team // +// // +// This file is part of OS/K. // +// // +// OS/K is free software: you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation, either version 3 of the License, or // +// any later version. // +// // +// OS/K is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY//without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with OS/K. If not, see . // +//----------------------------------------------------------------------------// + +#ifndef _KERNEL_H +#include +#endif + +#ifndef _MM_PALLOC_H +#define _MM_PALLOC_H + +//----------------------------------------------------------------------------// + + + +//----------------------------------------------------------------------------// + +#endif diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index 86aee49..6c3487f 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -20,20 +20,18 @@ // // // You should have received a copy of the GNU General Public License // // along with OS/K. If not, see . // -//---------------------------------------------------------------------------- +//----------------------------------------------------------------------------// #include #include +#include #include #include #include #include -#include #include #include -#define USERSPACE 0x80000000 - //----------- pml4_t MmPageMapLevel4[512] __attribute__((__aligned__(KPAGESIZE))); @@ -194,16 +192,16 @@ void MmInitPaging(void) //DebugLog("\tLast page of kernel at %p\n", curAddrPT); } } - // While we're inside the userspace pages - else if ((ulong)curAddrPT >= USERSPACE) { - MmPT[index] = ((ulong)curAddrPT - diffKernUsr) | PRESENT; // Not present for instance - xedni = (((ulong)curAddrPT - diffKernUsr) / ((ulong)KPAGESIZE)); - //MmPhysicalPageTable[xedni] = (ulong)curAddrPT; + /* // While we're inside the userspace pages */ + /* else if ((ulong)curAddrPT >= USERSPACE) { */ + /* MmPT[index] = ((ulong)curAddrPT - diffKernUsr) | PRESENT; // Not present for instance */ + /* xedni = (((ulong)curAddrPT - diffKernUsr) / ((ulong)KPAGESIZE)); */ + /* //MmPhysicalPageTable[xedni] = (ulong)curAddrPT; */ - if ((ulong)curAddrPT == USERSPACE) { - DebugLog("\tUserspace at %p:%p\n", curAddrPT, curAddrPT - diffKernUsr); - } - } + /* if ((ulong)curAddrPT == USERSPACE) { */ + /* DebugLog("\tUserspace at %p:%p\n", curAddrPT, curAddrPT - diffKernUsr); */ + /* } */ + /* } */ else { MmPT[index] = 0; } diff --git a/kaleid/kernel/mm/palloc.c b/kaleid/kernel/mm/palloc.c new file mode 100644 index 0000000..22a0fdf --- /dev/null +++ b/kaleid/kernel/mm/palloc.c @@ -0,0 +1,38 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Desc: Page allocator related functions // +// // +// // +// Copyright © 2018-2019 The OS/K Team // +// // +// This file is part of OS/K. // +// // +// OS/K is free software: you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation, either version 3 of the License, or // +// any later version. // +// // +// OS/K is distributed in the hope that it will be useful, // +// but WITHOUT ANY WARRANTY//without even the implied warranty of // +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // +// GNU General Public License for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with OS/K. If not, see . // +//----------------------------------------------------------------------------// + +#include +#include +#include +#include +#include +#include + +//--------- + + + + +//--------- + diff --git a/kaleid/kernel/sh/testcmds.c b/kaleid/kernel/sh/testcmds.c index e83667f..271de10 100644 --- a/kaleid/kernel/sh/testcmds.c +++ b/kaleid/kernel/sh/testcmds.c @@ -263,13 +263,13 @@ error_t CmdPageBlock(int argc, char **argv, char *cmdline) error_t CmdPF(int argc, char **argv, char *cmdline) { - ulong *address = (ulong*)(ulong)strtoul(argv[1], NULL, 16); + register ulong *address = (ulong*)(ulong)strtoul(argv[1], NULL, 16); - KernLog("Provoking Page Fault at %#x\n", address); + KernLog("Test provoking a fault at %p\n", address); - KernLog("It contained %#x\n", *address); + KernLog("It contained %p\n", *address); *address = 1; - KernLog("Now it contains %#x\n", *address); + KernLog("Now it contains %p\n", *address); KernLog("No page fault : address was valid/present\n");