From b80c912a34b997f82b4863a2e642087d88ff269d Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 22 May 2019 18:15:23 +0200 Subject: [PATCH] Some cosmetic changes --- Makefile | 3 +- boot/loader/multiboot/header.inc | 4 +- include/io/spkr.h | 1 + kaleid/kernel/io/spkr.c | 13 ++ kaleid/kernel/ke/idt.c | 7 +- kaleid/kernel/ke/panic.c | 2 +- kaleid/kernel/mm/map.c | 43 +++++- kaleid/kernel/mm/paging.c | 16 +- kaleid/kernel/sh/shcmds.c | 248 ++++++++++++++++--------------- kaleid/kernel/sh/shell.h | 8 +- 10 files changed, 202 insertions(+), 143 deletions(-) diff --git a/Makefile b/Makefile index 34bdf39..3705098 100644 --- a/Makefile +++ b/Makefile @@ -204,7 +204,8 @@ $(KOBJDIR)/%.o: %.c | $(KOBJDIR) @echo ${CL2}[$@] ${CL}Compiled.${CL3} test: all - @qemu-system-x86_64 -cpu core2duo -soundhw pcspk -s -rtc base=localtime -m $(ram) -hda $(BUILDDIR)/bin/disk.img \ + @qemu-system-x86_64 -vga std -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 diff --git a/boot/loader/multiboot/header.inc b/boot/loader/multiboot/header.inc index e7a8b1c..06c743c 100644 --- a/boot/loader/multiboot/header.inc +++ b/boot/loader/multiboot/header.inc @@ -29,8 +29,8 @@ MB_ALIGN equ 1 << 0 ; Ask to align loaded modules on page bounda MB_MEMINFO equ 1 << 1 ; Ask to provide memory map MB_VIDEOINFO equ 1 << 2 ; Ask to provide video infos MB_VIDEO_MODE equ 0x1 ; Text mode -MB_VIDEO_WIDTH equ 80 -MB_VIDEO_HEIGHT equ 24 +MB_VIDEO_WIDTH equ 132 +MB_VIDEO_HEIGHT equ 60 MB_VIDEO_DEPTH equ 0x0 MB_HEADER_MAGIC equ 0x1badb002 MB_GRUB_MAGIC equ 0x2badb002 diff --git a/include/io/spkr.h b/include/io/spkr.h index 85737a8..815b4a6 100644 --- a/include/io/spkr.h +++ b/include/io/spkr.h @@ -35,6 +35,7 @@ void IoStartSpeaker(int); void IoQuietSpeaker(void); void IoDoBeep(void); void IoDoTone(uint tone, uint time); +void IoDoBeepNoIdt(void); void IoDoStarWars(void); diff --git a/kaleid/kernel/io/spkr.c b/kaleid/kernel/io/spkr.c index 1bc418a..95ca317 100644 --- a/kaleid/kernel/io/spkr.c +++ b/kaleid/kernel/io/spkr.c @@ -58,12 +58,25 @@ void IoDoTone(uint tone, uint time) IoQuietSpeaker(); } +static void IoDoToneNoIdt(uint tone, uint time) +{ + extern void temporize(void); + IoStartSpeaker(tone); + for (int i = 0; i < 100; i++) temporize(); + IoQuietSpeaker(); +} + void IoDoBeep(void) { if (KeIdtIsInitialized) IoDoTone(1000, 100); } +void IoDoBeepNoIdt(void) +{ + IoDoToneNoIdt(1000, 100); +} + void IoDoStarWars(void) { size_t i; diff --git a/kaleid/kernel/ke/idt.c b/kaleid/kernel/ke/idt.c index b8a0c4d..47f23f6 100644 --- a/kaleid/kernel/ke/idt.c +++ b/kaleid/kernel/ke/idt.c @@ -27,6 +27,7 @@ #include #include #include +#include IdtEntry_t idt[256] = { 0 }; IdtPtr_t _KeIdtPtr; @@ -338,7 +339,9 @@ static void DoubleFaultHandler(ISRFrame_t *regs) void KeBrkDumpRegisters(ISRFrame_t *regs) { - bprintf(BStdOut, "\n\n" + IoDoBeepNoIdt(); + + bprintf(BStdOut, "\n\n" "%C RIP: %#016lx RSP: %#016lx RBP: %#016lx\n\n" @@ -382,7 +385,7 @@ void KeBrkDumpRegisters(ISRFrame_t *regs) regs->r15, regs->rflags, regs->rflags - ); + ); BStdOut->flusher(BStdOut); } diff --git a/kaleid/kernel/ke/panic.c b/kaleid/kernel/ke/panic.c index c0cb5af..8f3bf8d 100644 --- a/kaleid/kernel/ke/panic.c +++ b/kaleid/kernel/ke/panic.c @@ -51,7 +51,7 @@ noreturn void KeStartPanic(const char *fmt, ...) { va_list ap; - bprintf(BStdOut, "%C\nPANIC\n\a", VGA_COLOR_LIGHT_RED); + bprintf(BStdOut, "%C\nPANIC\n", VGA_COLOR_LIGHT_RED); KeDisableIRQs(); KeCurProc = NULL; diff --git a/kaleid/kernel/mm/map.c b/kaleid/kernel/mm/map.c index f338d1d..f7e164c 100644 --- a/kaleid/kernel/mm/map.c +++ b/kaleid/kernel/mm/map.c @@ -25,6 +25,7 @@ #include #include #include +#include // Initializes globally the memory map MemoryMap_t memoryMap = { 0 }; @@ -174,29 +175,55 @@ void *MmGetFirstAvailZone(void *start) { } void MmPrintMemoryMap(void) { - char *avStr = ""; + char avStr[15]; + extern int shcol; for (uint i=0; i < memoryMap.length; i++) { switch (memoryMap.entry[i].type) { - case AVAILABLE_ZONE: avStr="Available"; + case AVAILABLE_ZONE: snprintf(avStr, 15, "%CAvailable%C", + VGA_COLOR_GREEN, + shcol); break; - case RESERVED_ZONE: avStr="Reserved"; + case RESERVED_ZONE: snprintf(avStr, 15, "%CReserved %C", + VGA_COLOR_RED, + shcol); break; - case ACPI_ZONE: avStr="ACPI "; + case ACPI_ZONE: snprintf(avStr, 15, "%CACPI %C", + VGA_COLOR_LIGHT_BROWN, + shcol); break; - case NVS_ZONE: avStr="NVS "; + case NVS_ZONE: snprintf(avStr, 15, "%CNVS %C", + VGA_COLOR_LIGHT_BROWN, + shcol); break; - case BADRAM_ZONE: avStr="Bad Ram"; + case BADRAM_ZONE: snprintf(avStr, 15, "%CBAD RAM %C", + VGA_COLOR_LIGHT_RED, + shcol); break; default:; } ulong len = memoryMap.entry[i].length; - KernLog("mem zone: %lp\t%s\twith length: %4luMB + %4luKB + %4luB\n", + KernLog("%Cmem zone:%C %lp %s %Cwith length:%C %4lu%CMB" + "+%C%4lu%CKB+%C%4lu%CB\n", + + VGA_COLOR_DARK_GREY, + shcol, memoryMap.entry[i].addr, avStr, - _ADDR_TO_MB(len), _ADDR_TO_KB(len), _ADDR_TO_B(len) + VGA_COLOR_DARK_GREY, + shcol, + _ADDR_TO_MB(len), + VGA_COLOR_DARK_GREY, + shcol, + _ADDR_TO_KB(len), + VGA_COLOR_DARK_GREY, + shcol, + _ADDR_TO_B(len), + VGA_COLOR_DARK_GREY, + shcol ); } + KernLog("\n"); } diff --git a/kaleid/kernel/mm/paging.c b/kaleid/kernel/mm/paging.c index b61783a..5aab6ab 100644 --- a/kaleid/kernel/mm/paging.c +++ b/kaleid/kernel/mm/paging.c @@ -120,11 +120,12 @@ void MmReloadPaging(void) extern MemoryMap_t memoryMap; ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize; + for (volatile ulong i = 0; i < 512 * NB_4K; i++) { // STACK GUARD PAGE if ((ulong)(i*KPAGESIZE) == (ulong)BtLoaderInfo.stackEndAddr) { MmPT[i] = ((ulong)(i*KPAGESIZE)); - MmStackGuards[0] = i; + MmStackGuards[0] = ((ulong)(i*KPAGESIZE)); continue; } @@ -136,7 +137,7 @@ void MmReloadPaging(void) // STACK GARD PAGE if ((ulong)(i*KPAGESIZE) == (ulong)BtLoaderInfo.kernelEndAddr) { MmPT[i] = ((ulong)(i*KPAGESIZE)); - MmStackGuards[1] = i; + MmStackGuards[1] = ((ulong)(i*KPAGESIZE)); continue; } @@ -157,8 +158,15 @@ void MmReloadPaging(void) MmPD[i] = ((ulong)(i* UPAGESIZE)) | MF_PRESENT | MF_READWRITE | MF_HUGE; } - DebugLog("Paging tables reloaded at %p, %p\n", &MmPD, &MmPT); - DebugLog("Stack Guards at %p, %p\n", MmStackGuards[0], MmStackGuards[1]); + 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); + DebugLog("\tPaging tables initialized at %p, %p\n", &MmPD, &MmPT); + DebugLog("\tStack Guards at %p, %p\n", MmStackGuards[0], MmStackGuards[1]); } // Returns the rank of the Stack Guards diff --git a/kaleid/kernel/sh/shcmds.c b/kaleid/kernel/sh/shcmds.c index c65a675..d7fa41c 100644 --- a/kaleid/kernel/sh/shcmds.c +++ b/kaleid/kernel/sh/shcmds.c @@ -24,107 +24,6 @@ #include "shell.h" -error_t CmdBeep(int argc, char **argv, char *cmdline) -{ - IoDoBeep(); - return EOK; -} - -error_t CmdStarWars(int argc, char **argv, char *cmdline) -{ - IoDoStarWars(); - - return EOK; -} - -error_t CmdQuit(int argc, char **argv, char *cmdline) -{ - PoShutdown(); - return EOK; -} - -error_t CmdHelp(int argc, char **argv, char *cmdline) -{ - uint i, count = 0; - Command_t *cmd; - - if (argc == 1) { - KernLog("List of all shell built-ins:\n"); - for (cmd = cmdtable; cmd->name != NULL; cmd++, count++) { - KernLog("\t%s", cmd->name); - for (i = strlen(cmd->name)/4; i<3; i++) { - KernLog("\t"); - } - KernLog("%s\n", cmd->help); - } - KernLog("End of list; %u commands total\n", count); - } - - return EOK; -} - -error_t CmdClear(int argc, char **argv, char *cmdline) -{ - BLockBuf(BStdOut); - - BStdOut->wp = BStdOut->rp = BStdOut->buf; - BStdOut->lastLF = 0; - - BUnlockBuf(BStdOut); - - return EOK; -} - -error_t CmdDate(int argc, char **argv, char *cmdline) -{ - KernLog("%.10s\n", KeFormatCurTime()); - return EOK; -} - -error_t CmdTime(int argc, char **argv, char *cmdline) -{ - KernLog("%s\n", &KeFormatCurTime()[13]); - return EOK; -} - -error_t CmdMemMap(int argc, char **argv, char *cmdline) -{ - MmPrintMemoryMap(); - return EOK; -} - -extern void pstest(void); - -error_t CmdPsTest(int argc, char **argv, char *cmdline) -{ - // pstest(); - return EOK; -} - -error_t CmdDie(int argc, char **argv, char *cmdline) -{ - *(char *)NULL += 1; - return EOK; -} - -error_t CmdPF(int argc, char **argv, char *cmdline) -{ - /* if (argc != 2) */ - /* return EINVAL; */ - - /* ulong address = atoul(argv[1]); */ - /* KernLog("print: %s, %d\n", argv[1], address); */ - - /* *((char*)address) += 1; */ - - for (int i = 0; i < 32; i++) { - KernLog("%dGB ", i); - *((char*)(i*GB)) = 1; - } - - return EOK; -} - error_t CmdArgs(int argc, char **argv, char *cmdline) { int i; @@ -134,7 +33,25 @@ error_t CmdArgs(int argc, char **argv, char *cmdline) for (i = 0; i < argc; i++) { KernLog("argv[%d]: '%s'\n", i, argv[i]); } - + + return EOK; +} + +error_t CmdBeep(int argc, char **argv, char *cmdline) +{ + IoDoBeep(); + return EOK; +} + +error_t CmdClear(int argc, char **argv, char *cmdline) +{ + BLockBuf(BStdOut); + + BStdOut->wp = BStdOut->rp = BStdOut->buf; + BStdOut->lastLF = 0; + + BUnlockBuf(BStdOut); + return EOK; } @@ -142,12 +59,12 @@ error_t CmdColor(int argc, char **argv, char *cmdline) { int col = 0; char *p; - + if (argc > 2) { KernLog("Usage: 'color [#|list]'\n"); return EINVAL; } - + if (argc == 1) { KernLog("Current color: %s (%d)\n", RtlColorNames[shcol], shcol); } @@ -158,7 +75,7 @@ error_t CmdColor(int argc, char **argv, char *cmdline) KernLog("%d - %s\n", col, RtlColorNames[col]); } } - + else { p = argv[1]; @@ -175,13 +92,72 @@ error_t CmdColor(int argc, char **argv, char *cmdline) else { shcol = col; } - + } return EOK; } -void MmInitPaging(void); -void MmReloadPaging(void); +error_t CmdDate(int argc, char **argv, char *cmdline) +{ + KernLog("%.10s\n", KeFormatCurTime()); + return EOK; +} + +error_t CmdDie(int argc, char **argv, char *cmdline) +{ + *(char *)NULL += 1; + return EOK; +} + +error_t CmdHelp(int argc, char **argv, char *cmdline) +{ + uint i, count = 0; + Command_t *cmd; + + if (argc == 1) { + KernLog("List of all shell built-ins:\n"); + for (cmd = cmdtable; cmd->name != NULL; cmd++, count++) { + KernLog("\t%s", cmd->name); + for (i = strlen(cmd->name)/4; i<3; i++) { + KernLog("\t"); + } + KernLog("%C%s%C\n", VGA_COLOR_DARK_GREY, cmd->help, shcol); + } + KernLog("End of list; %u commands total\n", count); + } + + return EOK; +} + +error_t CmdMemMap(int argc, char **argv, char *cmdline) +{ + MmPrintMemoryMap(); + return EOK; +} + +error_t CmdMemUsage(int argc, char **argv, char *cmdline); + +error_t CmdPF(int argc, char **argv, char *cmdline) +{ + for (int i = 0; i < 32; i++) { + KernLog("%dGB ", i); + *((char*)(i*GB)) = 1; + } + + return EOK; +} + +error_t CmdPsTest(int argc, char **argv, char *cmdline) +{ + // pstest(); + return EOK; +} + +error_t CmdQuit(int argc, char **argv, char *cmdline) +{ + PoShutdown(); + return EOK; +} error_t CmdReloadPage(int argc, char **argv, char *cmdline) { @@ -189,8 +165,6 @@ error_t CmdReloadPage(int argc, char **argv, char *cmdline) return EOK; } -extern void KeStartShell(void); - error_t CmdShell(int argc, char **argv, char *cmdline) { KeStartShell(); @@ -198,7 +172,7 @@ error_t CmdShell(int argc, char **argv, char *cmdline) } error_t CmdStackOverflow(int argc, char **argv, char *cmdline) -{ +{ CmdStackOverflow(0, 0, 0); return EOK; } @@ -212,17 +186,44 @@ error_t CmdStackUnderflow(int argc, char **argv, char *cmdline) return EOK; } -error_t CmdMemUsage(int argc, char **argv, char *cmdline); +error_t CmdStarWars(int argc, char **argv, char *cmdline) +{ + IoDoStarWars(); + + return EOK; +} + +error_t CmdTest(int argc, char **argv, char *cmdline) +{ + KernLog("%s\n", &KeFormatCurTime()[13]); + return EOK; +} + +error_t CmdTime(int argc, char **argv, char *cmdline) +{ + KernLog("%s\n", &KeFormatCurTime()[13]); + return EOK; +} error_t CmdVersion(int argc, char **argv, char *cmdline) { - KernLog("OS/K version %s (x86-64)\n", _KALEID_VERSION); - KernLog("Copyright (C) 2018-2019 The OS/K Team\n"); - KernLog("License GNU GPL version 3 " - "or later, see \n"); - KernLog("This is free software; you are " - "free to change and redistribute it.\n"); - KernLog("There is NO WARRANTY, to the extent permitted by law.\n\n"); + int CH = VGA_COLOR_LIGHT_BLUE; + int CN = shcol; + + KernLog("OS/K version %C%s (x86-64)%C\n", + CH, + _KALEID_VERSION, + CN + ); + + KernLog("Copyright (C) 2018-2019 The OS/K Team\n\n"); + KernLog("This program is free software, released under the\n"); + KernLog("terms of the GNU GPL version 3 or later as published\n"); + KernLog("by the Free Software Foundation.\n"); + KernLog("You are free to change and redistribute it.\n"); + KernLog("There is NO WARRANTY, to the extent permitted by law.\n"); + KernLog("See \n\n"); + return EOK; } @@ -236,19 +237,20 @@ Command_t cmdtable[] = { "color", CmdColor, "Change shell text color" }, { "date", CmdDate, "Print date" }, { "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" }, { "pfault", CmdPF, "Provoke a PF. Usage : pfault
" }, { "pstest", CmdPsTest, "Scheduler test routine" }, + { "exit", CmdQuit, "Initiate shutdown" }, { "quit", CmdQuit, "Alias for 'exit'" }, + { "rpag", CmdReloadPage, "Reload the pages directory" }, { "shell", CmdShell, "Start a new shell (nested)", }, { "stkov", CmdStackOverflow, "Provoke a stack overflow" }, - { "stkun", CmdStackUnderflow, "Provoke a stack underflow" }, + { "stkun", CmdStackUnderflow, "Provoke a stack underflow" }, + { "march", CmdStarWars, "Play the Imperial March"}, { "time", CmdTime, "Print time" }, + { "test", CmdTime, "Undocumented (various tests)" }, { "ver", CmdVersion, "Version and legal infos" }, { NULL, NULL, NULL } }; diff --git a/kaleid/kernel/sh/shell.h b/kaleid/kernel/sh/shell.h index 79d1815..0ce9e23 100644 --- a/kaleid/kernel/sh/shell.h +++ b/kaleid/kernel/sh/shell.h @@ -35,8 +35,12 @@ #include #include -extern void IoScrollDown(void); -extern void IoScrollUp(void); +void IoScrollDown(void); +void IoScrollUp(void); +void KeStartShell(void); +void pstest(void); +void MmInitPaging(void); +void MmReloadPaging(void); extern int shcol; extern int shargc;