From bd5f99ed371539d5ff68d8b61b7c33cda2334c68 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Thu, 9 May 2019 10:27:44 +0200 Subject: [PATCH 1/3] PoShutdown --- include/kernel/pwmgnt.h | 1 + kaleid/kernel/init/init.c | 3 +-- kaleid/kernel/po/shtdwn.c | 5 +++++ kaleid/kernel/sh/shcmds.c | 2 +- kaleid/kernel/sh/shell.c | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/kernel/pwmgnt.h b/include/kernel/pwmgnt.h index f3ffba9..a212866 100644 --- a/include/kernel/pwmgnt.h +++ b/include/kernel/pwmgnt.h @@ -31,6 +31,7 @@ //----------------------------------------------------------------------------// +noreturn void PoShutdown(void); noreturn void PoShutdownQemu(void); noreturn void PoShutdownVirtualbox(void); noreturn void PoShutdownBochs(void); diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 5c7bcd9..11f80a4 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -64,6 +64,5 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) KeStartShell(); - KernLog("End of input reached\n"); - PoShutdownQemu(); + PoShutdown(); } diff --git a/kaleid/kernel/po/shtdwn.c b/kaleid/kernel/po/shtdwn.c index 7d405d3..d54db81 100644 --- a/kaleid/kernel/po/shtdwn.c +++ b/kaleid/kernel/po/shtdwn.c @@ -59,3 +59,8 @@ noreturn void PoShutdownBochs(void) __builtin_unreachable(); } +noreturn void PoShutdown(void) +{ + PoShutdownQemu(); +} + diff --git a/kaleid/kernel/sh/shcmds.c b/kaleid/kernel/sh/shcmds.c index 5ce7698..abc58b2 100644 --- a/kaleid/kernel/sh/shcmds.c +++ b/kaleid/kernel/sh/shcmds.c @@ -44,7 +44,7 @@ error_t CmdStarWars(int argc, char **argv, char *cmdline) error_t CmdQuit(int argc, char **argv, char *cmdline) { - PoShutdownQemu(); + PoShutdown(); return EOK; } diff --git a/kaleid/kernel/sh/shell.c b/kaleid/kernel/sh/shell.c index 8dcf6b9..8c961e2 100644 --- a/kaleid/kernel/sh/shell.c +++ b/kaleid/kernel/sh/shell.c @@ -111,7 +111,7 @@ void KeStartShell(void) break; case KEY_ESC: - PoShutdownQemu(); + PoShutdown(); break; default: From f03a587337afee4cc87c30236d05d3b9c39715d4 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Thu, 9 May 2019 11:19:44 +0200 Subject: [PATCH 2/3] musage --- kaleid/kernel/init/info.c | 2 +- kaleid/kernel/init/init.c | 2 - kaleid/kernel/io/rtc.c | 2 +- kaleid/kernel/sh/shcmds.c | 120 ++++++++++++++++++++++++++++++-------- kaleid/kernel/sh/shell.h | 1 + 5 files changed, 99 insertions(+), 28 deletions(-) diff --git a/kaleid/kernel/init/info.c b/kaleid/kernel/init/info.c index d8dec18..6ee8aba 100644 --- a/kaleid/kernel/init/info.c +++ b/kaleid/kernel/init/info.c @@ -116,6 +116,6 @@ void BtDoSanityChecks(uint mbMagic) { DebugLog("[Init] Kernel successfully loaded at %p with %x magic\n" " and it uses %dKB\n\n", BtLoaderInfo.kernelAddr, - mbMagic,tmp); + mbMagic, tmp); } diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 2012209..11f80a4 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -62,8 +62,6 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) IoGetRtcTimeChar(); IoPrintRtcTime(); - KernLog("%d\n",realKernelEnd); - KeStartShell(); PoShutdown(); diff --git a/kaleid/kernel/io/rtc.c b/kaleid/kernel/io/rtc.c index c28a3fa..427590d 100644 --- a/kaleid/kernel/io/rtc.c +++ b/kaleid/kernel/io/rtc.c @@ -151,7 +151,7 @@ void RtcHandler(ISRFrame_t *regs) void IoPrintRtcTime(void) { Time_t* RtcTime = IoGetRtcTime(); - KernLog("[RTC Time] %02d/%02d/%04d ; %02d:%02d:%02d \n\n", + KernLog("[RTC Time] %02d/%02d/%04d ; %02d:%02d:%02d \n", RtcTime->day, RtcTime->month, RtcTime->year + RtcTime->century*100, diff --git a/kaleid/kernel/sh/shcmds.c b/kaleid/kernel/sh/shcmds.c index abc58b2..e00a95c 100644 --- a/kaleid/kernel/sh/shcmds.c +++ b/kaleid/kernel/sh/shcmds.c @@ -80,42 +80,114 @@ error_t CmdMemMap(int argc, char **argv, char *cmdline) return EOK; } +extern ulong realKernelEnd; + error_t CmdMemUsage(int argc, char **argv, char *cmdline) { - size_t start, end; - size_t diff, max; + size_t stack_cur; + size_t img_diff, stack_diff; + size_t heap_start, heap_end; + size_t heap_diff, heap_max; ulong flags = KePauseIRQs(); - start = (size_t)_heap_start; - end = (size_t)_heap_end; - max = _heap_max; + heap_start = (size_t)_heap_start; + heap_end = (size_t)_heap_end; + heap_max = _heap_max; KeRestoreIRQs(flags); - diff = (size_t)end - (size_t)start; + img_diff = realKernelEnd - (size_t)BtLoaderInfo.kernelAddr; + stack_diff = (size_t)BtLoaderInfo.kernelEndAddr - (realKernelEnd + 1); + heap_diff = (size_t)heap_end - (size_t)heap_start; - KernLog("Heap start:\t\t%p (%luMB + %luKB + %luB)\n", - start, _ADDR_TO_MB(start), - _ADDR_TO_KB(start), - _ADDR_TO_B(start)); + KernLog("Kernel image:\n"); - KernLog("Heap end:\t\t%p (%luMB + %luKB + %luB)\n", - end, _ADDR_TO_MB(end), - _ADDR_TO_KB(end), - _ADDR_TO_B(end)); + KernLog("\tstarts at:\t\t%p (%04luMB + %04luKB + %04luB)\n", + BtLoaderInfo.kernelAddr, + _ADDR_TO_MB((size_t)BtLoaderInfo.kernelAddr), + _ADDR_TO_KB((size_t)BtLoaderInfo.kernelAddr), + _ADDR_TO_B((size_t)BtLoaderInfo.kernelAddr)); - KernLog("Heap size:\t\t%luMB + %luKB + %luB (%#lx)\n", - _ADDR_TO_MB(diff), - _ADDR_TO_KB(diff), - _ADDR_TO_B(diff), - diff); + KernLog("\tends at:\t\t%p (%04luMB + %04luKB + %04luB)\n", + realKernelEnd, + _ADDR_TO_MB(realKernelEnd), + _ADDR_TO_KB(realKernelEnd), + _ADDR_TO_B(realKernelEnd)); - KernLog("Max heap size:\t%luMB + %luKB + %luB (%#lx)\n", - _ADDR_TO_MB(max), - _ADDR_TO_KB(max), - _ADDR_TO_B(max), - max); + KernLog("\tsize:\t\t\t%04luMB + %04luKB + %04luB (%p)\n", + _ADDR_TO_MB(img_diff), + _ADDR_TO_KB(img_diff), + _ADDR_TO_B(img_diff), + img_diff); + + KernLog("Kernel stack:\n"); + + KernLog("\tstarts at:\t\t%p (%04luMB + %04luKB + %04luB)\n", + BtLoaderInfo.kernelEndAddr, + _ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr), + _ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr), + _ADDR_TO_B((size_t)BtLoaderInfo.kernelEndAddr)); + + BARRIER(); + char var; + (void)var; + + stack_cur = (size_t)BtLoaderInfo.kernelEndAddr - (size_t)&var; + + KernLog("\tends at:\t\t%p (%04luMB + %04luKB + %04luB)\n", + stack_cur, + _ADDR_TO_MB(stack_cur), + _ADDR_TO_KB(stack_cur), + _ADDR_TO_B(stack_cur)); + + KernLog("\tmin addr:\t\t%p (%04luMB + %04luKB + %04luB)\n", + realKernelEnd+1, + _ADDR_TO_MB(realKernelEnd+1), + _ADDR_TO_KB(realKernelEnd+1), + _ADDR_TO_B(realKernelEnd+1)); + + KernLog("\tsize (cur):\t\t%04luMB + %04luKB + %04luB (%p)\n", + _ADDR_TO_MB(stack_cur), + _ADDR_TO_KB(stack_cur), + _ADDR_TO_B(stack_cur), + stack_cur); + + KernLog("\tsize (max):\t\t%04luMB + %04luKB + %04luB (%p)\n", + _ADDR_TO_MB(stack_diff), + _ADDR_TO_KB(stack_diff), + _ADDR_TO_B(stack_diff), + stack_diff); + + KernLog("Kernel heap:\n"); + + KernLog("\tstarts at:\t\t%p (%04luMB + %04luKB + %04luB)\n", + heap_start, _ADDR_TO_MB(heap_start), + _ADDR_TO_KB(heap_start), + _ADDR_TO_B(heap_start)); + + KernLog("\tends at:\t\t%p (%04luMB + %04luKB + %04luB)\n", + heap_end, _ADDR_TO_MB(heap_end), + _ADDR_TO_KB(heap_end), + _ADDR_TO_B(heap_end)); + + KernLog("\tmax addr:\t\t%p (%04luMB + %04luKB + %04luB)\n", + heap_start + heap_max, + _ADDR_TO_MB(heap_start + heap_max), + _ADDR_TO_KB(heap_start + heap_max), + _ADDR_TO_B(heap_start + heap_max)); + + KernLog("\tsize (cur):\t\t%04luMB + %04luKB + %04luB (%p)\n", + _ADDR_TO_MB(heap_diff), + _ADDR_TO_KB(heap_diff), + _ADDR_TO_B(heap_diff), + heap_diff); + + KernLog("\tsize (max):\t\t%04luMB + %04luKB + %04luB (%p)\n", + _ADDR_TO_MB(heap_max), + _ADDR_TO_KB(heap_max), + _ADDR_TO_B(heap_max), + heap_max); return EOK; } diff --git a/kaleid/kernel/sh/shell.h b/kaleid/kernel/sh/shell.h index 591dd3b..1c39878 100644 --- a/kaleid/kernel/sh/shell.h +++ b/kaleid/kernel/sh/shell.h @@ -26,6 +26,7 @@ #include #include +#include #include #include #include From 7f27ead23b6a10d4e27acd49219adb25a83b54c2 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Thu, 9 May 2019 11:33:07 +0200 Subject: [PATCH 3/3] Stuff --- kaleid/kernel/mm/map.c | 2 +- kaleid/kernel/ps/sched.c | 2 +- kaleid/kernel/sh/shcmds.c | 6 +++--- kaleid/kernel/sh/shell.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kaleid/kernel/mm/map.c b/kaleid/kernel/mm/map.c index 45334c7..6f1c6cb 100644 --- a/kaleid/kernel/mm/map.c +++ b/kaleid/kernel/mm/map.c @@ -195,7 +195,7 @@ void MmPrintMemoryMap(void) { ulong len = memoryMap.entry[i].length; - KernLog("Mem zone : %lp\t%s\twith length: %luMB + %luKB + %luB\n", + KernLog("mem zone: %lp\t%s\twith length: %04luMB + %04luKB + %04luB\n", memoryMap.entry[i].addr, avStr, _ADDR_TO_MB(len), _ADDR_TO_KB(len), _ADDR_TO_B(len) ); diff --git a/kaleid/kernel/ps/sched.c b/kaleid/kernel/ps/sched.c index b7ab3dc..047c728 100644 --- a/kaleid/kernel/ps/sched.c +++ b/kaleid/kernel/ps/sched.c @@ -390,7 +390,7 @@ void pstest(void) while (tick < 100) { //if (tick%25==0)ClearTerm(StdOut); - if (tick > 0 && tick != 50 && tick % 10 == 0) { + if (tick > 0 && tick != 50 && tick % 10 == 0 && PsCurProc) { KernLog("Blocking current process\n"); PsBlockCurProc(); } diff --git a/kaleid/kernel/sh/shcmds.c b/kaleid/kernel/sh/shcmds.c index e00a95c..6c5240c 100644 --- a/kaleid/kernel/sh/shcmds.c +++ b/kaleid/kernel/sh/shcmds.c @@ -101,7 +101,7 @@ error_t CmdMemUsage(int argc, char **argv, char *cmdline) stack_diff = (size_t)BtLoaderInfo.kernelEndAddr - (realKernelEnd + 1); heap_diff = (size_t)heap_end - (size_t)heap_start; - KernLog("Kernel image:\n"); + KernLog("Kernel image\n"); KernLog("\tstarts at:\t\t%p (%04luMB + %04luKB + %04luB)\n", BtLoaderInfo.kernelAddr, @@ -121,7 +121,7 @@ error_t CmdMemUsage(int argc, char **argv, char *cmdline) _ADDR_TO_B(img_diff), img_diff); - KernLog("Kernel stack:\n"); + KernLog("Kernel stack\n"); KernLog("\tstarts at:\t\t%p (%04luMB + %04luKB + %04luB)\n", BtLoaderInfo.kernelEndAddr, @@ -159,7 +159,7 @@ error_t CmdMemUsage(int argc, char **argv, char *cmdline) _ADDR_TO_B(stack_diff), stack_diff); - KernLog("Kernel heap:\n"); + KernLog("Kernel heap\n"); KernLog("\tstarts at:\t\t%p (%04luMB + %04luKB + %04luB)\n", heap_start, _ADDR_TO_MB(heap_start), diff --git a/kaleid/kernel/sh/shell.c b/kaleid/kernel/sh/shell.c index 8c961e2..3b0a8a9 100644 --- a/kaleid/kernel/sh/shell.c +++ b/kaleid/kernel/sh/shell.c @@ -67,7 +67,7 @@ void KeStartShell(void) memzero(argv0, ARG_MAX); shargv = &argv0; - KernLog("shell> "); + KernLog("\nshell> "); BFlushBuf(BStdOut); while ((rc = BGetFromBuf(BStdIn, &ch)) == EOK || rc == EENDF) {