mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
Correcting dynamic paging
This commit is contained in:
parent
4e32aa157d
commit
4f3bda6ec2
4
Makefile
4
Makefile
@ -29,7 +29,7 @@
|
||||
|
||||
# Debug
|
||||
mode ?= debug
|
||||
ram ?= 8G
|
||||
ram ?= 4G
|
||||
|
||||
# Programs
|
||||
ASM=nasm
|
||||
@ -203,7 +203,7 @@ $(KOBJDIR)/%.o: %.c | $(KOBJDIR)
|
||||
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
|
||||
|
||||
test: all
|
||||
@qemu-system-x86_64 -cpu core2duo -soundhw pcspk -rtc base=localtime -m $(ram) -hda $(BUILDDIR)/bin/disk.img \
|
||||
@qemu-system-x86_64 -cpu core2duo -soundhw pcspk -s -rtc base=localtime -m $(ram) -hda $(BUILDDIR)/bin/disk.img \
|
||||
-d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
|
||||
|
||||
test32: all
|
||||
|
@ -23,7 +23,7 @@
|
||||
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
|
||||
;=----------------------------------------------------------------------------=;
|
||||
|
||||
%define MAX_MEMORY 4 ; GiB
|
||||
%define MAX_MEMORY 1 ; GiB
|
||||
|
||||
[BITS 32]
|
||||
[section .text]
|
||||
|
@ -48,8 +48,8 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
|
||||
|
||||
// Memory
|
||||
MmInitMemoryMap();
|
||||
MmInitHeap();
|
||||
MmInitPaging();
|
||||
MmInitHeap();
|
||||
|
||||
// Interrupts launching
|
||||
KeSetupIDT();
|
||||
|
@ -33,7 +33,7 @@ enum
|
||||
MF_NX = 1 << 31
|
||||
};
|
||||
|
||||
#define RAM_MAX 16
|
||||
#define RAM_MAX 32
|
||||
#define NB_4K 150
|
||||
// * 2 MB
|
||||
|
||||
@ -54,56 +54,55 @@ volatile ulong MmStackGuards[2] = { 0 };
|
||||
void MmInitPaging(void)
|
||||
{
|
||||
extern MemoryMap_t memoryMap;
|
||||
uint phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize;
|
||||
ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize;
|
||||
|
||||
memzero((void *)&MmPML4[0], sizeof(MmPML4));
|
||||
memzero((void *)&MmPDP[0], sizeof(MmPDP));
|
||||
memzero((void *)&MmPD[0], sizeof(MmPD));
|
||||
memzero((void *)&MmPT[0], sizeof(MmPT));
|
||||
|
||||
for (int i = 0; i < 512 * NB_4K; i++) {
|
||||
for (volatile ulong i = 0; i < 512 * NB_4K; i++) {
|
||||
// STACK GUARD PAGE
|
||||
if ((ulong)i*4096 == (ulong)BtLoaderInfo.stackEndAddr) {
|
||||
MmPT[i] = ((ulong)i * 4096);
|
||||
if ((ulong)(i*4096) == (ulong)BtLoaderInfo.stackEndAddr) {
|
||||
MmPT[i] = ((ulong)(i*4096));
|
||||
MmStackGuards[0] = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
// ENOMEM like
|
||||
if ((ulong)i*4096 > (ulong)phRamSize) {
|
||||
MmPT[i] = ((ulong)i * 4096) | MF_READWRITE;// | MF_NX;
|
||||
continue;
|
||||
if ((ulong)(i*4096) > (ulong)phRamSize) {
|
||||
break;
|
||||
}
|
||||
|
||||
// STACK GARD PAGE
|
||||
if ((ulong)i*4096 == (ulong)BtLoaderInfo.kernelEndAddr) {
|
||||
MmPT[i] = ((ulong)i * 4096);
|
||||
if ((ulong)(i*4096) == (ulong)BtLoaderInfo.kernelEndAddr) {
|
||||
MmPT[i] = ((ulong)(i*4096));
|
||||
MmStackGuards[1] = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
MmPT[i] = ((ulong)i * 4096) | MF_PRESENT | MF_READWRITE;
|
||||
MmPT[i] = ((ulong)(i*4096)) | MF_PRESENT | MF_READWRITE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < NB_4K; i++) {
|
||||
for (volatile ulong i = 0; i < NB_4K; i++) {
|
||||
MmPD[i] = (ulong)(&MmPT[i*512])| MF_PRESENT | MF_READWRITE;
|
||||
}
|
||||
|
||||
for (int i = NB_4K; i < 512 * RAM_MAX; i++) {
|
||||
for (volatile ulong i = NB_4K; i < 512 * RAM_MAX; i++) {
|
||||
// ENOMEM like
|
||||
if ((ulong)i* 2048 * 1024 > (ulong)phRamSize) {
|
||||
MmPD[i] = ((ulong)i * 2048 * 1024) | MF_READWRITE;// | MF_NX;
|
||||
continue;
|
||||
if ((ulong)(i* 2048 * 1024) > (ulong)phRamSize) {
|
||||
break;
|
||||
}
|
||||
|
||||
MmPD[i] = ((ulong)i * 2048 * 1024) | MF_PRESENT | MF_READWRITE | MF_HUGE;
|
||||
MmPD[i] = 0;
|
||||
MmPD[i] = ((ulong)(i* 2048 * 1024)) | MF_PRESENT | MF_READWRITE | MF_HUGE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < RAM_MAX; i++) {
|
||||
for (volatile int i = 0; i < RAM_MAX; i++) {
|
||||
MmPDP[i] = (ulong)(&MmPD[i*512])| MF_PRESENT | MF_READWRITE;
|
||||
}
|
||||
|
||||
MmPML4[0] = (ulong)(&MmPDP[0])| MF_PRESENT | MF_READWRITE;
|
||||
|
||||
//MmLoadPML4((void *)MmPML4);
|
||||
MmLoadPML4((void *)MmPML4);
|
||||
}
|
||||
|
@ -224,13 +224,31 @@ error_t CmdDie(int argc, char **argv, char *cmdline)
|
||||
|
||||
error_t CmdPF(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
if (argc != 2)
|
||||
return EINVAL;
|
||||
/* if (argc != 2) */
|
||||
/* return EINVAL; */
|
||||
|
||||
ulong address = atoul(argv[1]);
|
||||
KernLog("print: %s, %d\n", argv[1], address);
|
||||
/* ulong address = atoul(argv[1]); */
|
||||
/* KernLog("print: %s, %d\n", argv[1], address); */
|
||||
|
||||
*((char*)address) += 1;
|
||||
/* *((char*)address) += 1; */
|
||||
|
||||
*((char*)(1*GB)) += 1;
|
||||
KernLog("1GB ");
|
||||
*((char*)(2*GB)) += 1;
|
||||
KernLog("2GB ");
|
||||
*((char*)(3*GB)) += 1;
|
||||
KernLog("3GB ");
|
||||
*((char*)(4*GB)) += 1;
|
||||
KernLog("4GB ");
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
||||
void MmInitPaging(void);
|
||||
|
||||
error_t CmdReloadPage(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
MmInitPaging();
|
||||
return EOK;
|
||||
}
|
||||
|
||||
@ -251,6 +269,7 @@ Command_t cmdtable[] =
|
||||
{ "die", CmdDie, "Die painfully" },
|
||||
{ "exit", CmdQuit, "Initiate shutdown" },
|
||||
{ "help", CmdHelp, "Show this message" },
|
||||
{ "rpag", CmdReloadPage, "Reload the pages directory" },
|
||||
{ "march", CmdStarWars, "Play the Imperial March"},
|
||||
{ "mmap", CmdMemMap, "Show memory map" },
|
||||
{ "musage", CmdMemUsage, "Show memory statistics" },
|
||||
|
Loading…
Reference in New Issue
Block a user