Some cosmetic changes

This commit is contained in:
Adrien Bourmault 2019-05-22 18:15:23 +02:00
parent f0d6580ff5
commit b80c912a34
10 changed files with 202 additions and 143 deletions

View File

@ -204,7 +204,8 @@ $(KOBJDIR)/%.o: %.c | $(KOBJDIR)
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
test: all 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 & -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
test32: all test32: all

View File

@ -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_MEMINFO equ 1 << 1 ; Ask to provide memory map
MB_VIDEOINFO equ 1 << 2 ; Ask to provide video infos MB_VIDEOINFO equ 1 << 2 ; Ask to provide video infos
MB_VIDEO_MODE equ 0x1 ; Text mode MB_VIDEO_MODE equ 0x1 ; Text mode
MB_VIDEO_WIDTH equ 80 MB_VIDEO_WIDTH equ 132
MB_VIDEO_HEIGHT equ 24 MB_VIDEO_HEIGHT equ 60
MB_VIDEO_DEPTH equ 0x0 MB_VIDEO_DEPTH equ 0x0
MB_HEADER_MAGIC equ 0x1badb002 MB_HEADER_MAGIC equ 0x1badb002
MB_GRUB_MAGIC equ 0x2badb002 MB_GRUB_MAGIC equ 0x2badb002

View File

@ -35,6 +35,7 @@ void IoStartSpeaker(int);
void IoQuietSpeaker(void); void IoQuietSpeaker(void);
void IoDoBeep(void); void IoDoBeep(void);
void IoDoTone(uint tone, uint time); void IoDoTone(uint tone, uint time);
void IoDoBeepNoIdt(void);
void IoDoStarWars(void); void IoDoStarWars(void);

View File

@ -58,12 +58,25 @@ void IoDoTone(uint tone, uint time)
IoQuietSpeaker(); 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) void IoDoBeep(void)
{ {
if (KeIdtIsInitialized) if (KeIdtIsInitialized)
IoDoTone(1000, 100); IoDoTone(1000, 100);
} }
void IoDoBeepNoIdt(void)
{
IoDoToneNoIdt(1000, 100);
}
void IoDoStarWars(void) void IoDoStarWars(void)
{ {
size_t i; size_t i;

View File

@ -27,6 +27,7 @@
#include <ke/idt.h> #include <ke/idt.h>
#include <io/vga.h> #include <io/vga.h>
#include <mm/mm.h> #include <mm/mm.h>
#include <io/spkr.h>
IdtEntry_t idt[256] = { 0 }; IdtEntry_t idt[256] = { 0 };
IdtPtr_t _KeIdtPtr; IdtPtr_t _KeIdtPtr;
@ -338,7 +339,9 @@ static void DoubleFaultHandler(ISRFrame_t *regs)
void KeBrkDumpRegisters(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" "%C RIP: %#016lx RSP: %#016lx RBP: %#016lx\n\n"
@ -382,7 +385,7 @@ void KeBrkDumpRegisters(ISRFrame_t *regs)
regs->r15, regs->r15,
regs->rflags, regs->rflags,
regs->rflags regs->rflags
); );
BStdOut->flusher(BStdOut); BStdOut->flusher(BStdOut);
} }

View File

@ -51,7 +51,7 @@ noreturn void KeStartPanic(const char *fmt, ...)
{ {
va_list ap; va_list ap;
bprintf(BStdOut, "%C\nPANIC\n\a", VGA_COLOR_LIGHT_RED); bprintf(BStdOut, "%C\nPANIC\n", VGA_COLOR_LIGHT_RED);
KeDisableIRQs(); KeDisableIRQs();
KeCurProc = NULL; KeCurProc = NULL;

View File

@ -25,6 +25,7 @@
#include <mm/mm.h> #include <mm/mm.h>
#include <init/boot.h> #include <init/boot.h>
#include <init/mboot.h> #include <init/mboot.h>
#include <io/vga.h>
// Initializes globally the memory map // Initializes globally the memory map
MemoryMap_t memoryMap = { 0 }; MemoryMap_t memoryMap = { 0 };
@ -174,29 +175,55 @@ void *MmGetFirstAvailZone(void *start) {
} }
void MmPrintMemoryMap(void) { void MmPrintMemoryMap(void) {
char *avStr = ""; char avStr[15];
extern int shcol;
for (uint i=0; i < memoryMap.length; i++) { for (uint i=0; i < memoryMap.length; i++) {
switch (memoryMap.entry[i].type) { switch (memoryMap.entry[i].type) {
case AVAILABLE_ZONE: avStr="Available"; case AVAILABLE_ZONE: snprintf(avStr, 15, "%CAvailable%C",
VGA_COLOR_GREEN,
shcol);
break; break;
case RESERVED_ZONE: avStr="Reserved"; case RESERVED_ZONE: snprintf(avStr, 15, "%CReserved %C",
VGA_COLOR_RED,
shcol);
break; break;
case ACPI_ZONE: avStr="ACPI "; case ACPI_ZONE: snprintf(avStr, 15, "%CACPI %C",
VGA_COLOR_LIGHT_BROWN,
shcol);
break; break;
case NVS_ZONE: avStr="NVS "; case NVS_ZONE: snprintf(avStr, 15, "%CNVS %C",
VGA_COLOR_LIGHT_BROWN,
shcol);
break; break;
case BADRAM_ZONE: avStr="Bad Ram"; case BADRAM_ZONE: snprintf(avStr, 15, "%CBAD RAM %C",
VGA_COLOR_LIGHT_RED,
shcol);
break; break;
default:; default:;
} }
ulong len = memoryMap.entry[i].length; 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, 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");
} }

View File

@ -120,11 +120,12 @@ void MmReloadPaging(void)
extern MemoryMap_t memoryMap; extern MemoryMap_t memoryMap;
ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize; ulong phRamSize = memoryMap.freeRamSize + memoryMap.nonfreeRamSize;
for (volatile ulong i = 0; i < 512 * NB_4K; i++) { for (volatile ulong i = 0; i < 512 * NB_4K; i++) {
// STACK GUARD PAGE // STACK GUARD PAGE
if ((ulong)(i*KPAGESIZE) == (ulong)BtLoaderInfo.stackEndAddr) { if ((ulong)(i*KPAGESIZE) == (ulong)BtLoaderInfo.stackEndAddr) {
MmPT[i] = ((ulong)(i*KPAGESIZE)); MmPT[i] = ((ulong)(i*KPAGESIZE));
MmStackGuards[0] = i; MmStackGuards[0] = ((ulong)(i*KPAGESIZE));
continue; continue;
} }
@ -136,7 +137,7 @@ void MmReloadPaging(void)
// STACK GARD PAGE // STACK GARD PAGE
if ((ulong)(i*KPAGESIZE) == (ulong)BtLoaderInfo.kernelEndAddr) { if ((ulong)(i*KPAGESIZE) == (ulong)BtLoaderInfo.kernelEndAddr) {
MmPT[i] = ((ulong)(i*KPAGESIZE)); MmPT[i] = ((ulong)(i*KPAGESIZE));
MmStackGuards[1] = i; MmStackGuards[1] = ((ulong)(i*KPAGESIZE));
continue; continue;
} }
@ -157,8 +158,15 @@ void MmReloadPaging(void)
MmPD[i] = ((ulong)(i* UPAGESIZE)) | MF_PRESENT | MF_READWRITE | MF_HUGE; MmPD[i] = ((ulong)(i* UPAGESIZE)) | MF_PRESENT | MF_READWRITE | MF_HUGE;
} }
DebugLog("Paging tables reloaded at %p, %p\n", &MmPD, &MmPT); for (volatile int i = 0; i < RAM_MAX; i++) {
DebugLog("Stack Guards at %p, %p\n", MmStackGuards[0], MmStackGuards[1]); 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 // Returns the rank of the Stack Guards

View File

@ -24,107 +24,6 @@
#include "shell.h" #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) error_t CmdArgs(int argc, char **argv, char *cmdline)
{ {
int i; int i;
@ -134,7 +33,25 @@ error_t CmdArgs(int argc, char **argv, char *cmdline)
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
KernLog("argv[%d]: '%s'\n", i, argv[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; return EOK;
} }
@ -142,12 +59,12 @@ error_t CmdColor(int argc, char **argv, char *cmdline)
{ {
int col = 0; int col = 0;
char *p; char *p;
if (argc > 2) { if (argc > 2) {
KernLog("Usage: 'color [#|list]'\n"); KernLog("Usage: 'color [#|list]'\n");
return EINVAL; return EINVAL;
} }
if (argc == 1) { if (argc == 1) {
KernLog("Current color: %s (%d)\n", RtlColorNames[shcol], shcol); 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]); KernLog("%d - %s\n", col, RtlColorNames[col]);
} }
} }
else { else {
p = argv[1]; p = argv[1];
@ -175,13 +92,72 @@ error_t CmdColor(int argc, char **argv, char *cmdline)
else { else {
shcol = col; shcol = col;
} }
} }
return EOK; return EOK;
} }
void MmInitPaging(void); error_t CmdDate(int argc, char **argv, char *cmdline)
void MmReloadPaging(void); {
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) error_t CmdReloadPage(int argc, char **argv, char *cmdline)
{ {
@ -189,8 +165,6 @@ error_t CmdReloadPage(int argc, char **argv, char *cmdline)
return EOK; return EOK;
} }
extern void KeStartShell(void);
error_t CmdShell(int argc, char **argv, char *cmdline) error_t CmdShell(int argc, char **argv, char *cmdline)
{ {
KeStartShell(); KeStartShell();
@ -198,7 +172,7 @@ error_t CmdShell(int argc, char **argv, char *cmdline)
} }
error_t CmdStackOverflow(int argc, char **argv, char *cmdline) error_t CmdStackOverflow(int argc, char **argv, char *cmdline)
{ {
CmdStackOverflow(0, 0, 0); CmdStackOverflow(0, 0, 0);
return EOK; return EOK;
} }
@ -212,17 +186,44 @@ error_t CmdStackUnderflow(int argc, char **argv, char *cmdline)
return EOK; 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) error_t CmdVersion(int argc, char **argv, char *cmdline)
{ {
KernLog("OS/K version %s (x86-64)\n", _KALEID_VERSION); int CH = VGA_COLOR_LIGHT_BLUE;
KernLog("Copyright (C) 2018-2019 The OS/K Team\n"); int CN = shcol;
KernLog("License GNU GPL version 3 "
"or later, see <http://gnu.org/licenses/gpl.html>\n"); KernLog("OS/K version %C%s (x86-64)%C\n",
KernLog("This is free software; you are " CH,
"free to change and redistribute it.\n"); _KALEID_VERSION,
KernLog("There is NO WARRANTY, to the extent permitted by law.\n\n"); 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 <http://gnu.org/licenses/gpl.html>\n\n");
return EOK; return EOK;
} }
@ -236,19 +237,20 @@ Command_t cmdtable[] =
{ "color", CmdColor, "Change shell text color" }, { "color", CmdColor, "Change shell text color" },
{ "date", CmdDate, "Print date" }, { "date", CmdDate, "Print date" },
{ "die", CmdDie, "Die painfully" }, { "die", CmdDie, "Die painfully" },
{ "exit", CmdQuit, "Initiate shutdown" },
{ "help", CmdHelp, "Show this message" }, { "help", CmdHelp, "Show this message" },
{ "rpag", CmdReloadPage, "Reload the pages directory" },
{ "march", CmdStarWars, "Play the Imperial March"},
{ "mmap", CmdMemMap, "Show memory map" }, { "mmap", CmdMemMap, "Show memory map" },
{ "musage", CmdMemUsage, "Show memory statistics" }, { "musage", CmdMemUsage, "Show memory statistics" },
{ "pfault", CmdPF, "Provoke a PF. Usage : pfault <address>" }, { "pfault", CmdPF, "Provoke a PF. Usage : pfault <address>" },
{ "pstest", CmdPsTest, "Scheduler test routine" }, { "pstest", CmdPsTest, "Scheduler test routine" },
{ "exit", CmdQuit, "Initiate shutdown" },
{ "quit", CmdQuit, "Alias for 'exit'" }, { "quit", CmdQuit, "Alias for 'exit'" },
{ "rpag", CmdReloadPage, "Reload the pages directory" },
{ "shell", CmdShell, "Start a new shell (nested)", }, { "shell", CmdShell, "Start a new shell (nested)", },
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" }, { "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" }, { "time", CmdTime, "Print time" },
{ "test", CmdTime, "Undocumented (various tests)" },
{ "ver", CmdVersion, "Version and legal infos" }, { "ver", CmdVersion, "Version and legal infos" },
{ NULL, NULL, NULL } { NULL, NULL, NULL }
}; };

View File

@ -35,8 +35,12 @@
#include <io/vga.h> #include <io/vga.h>
#include <po/shtdwn.h> #include <po/shtdwn.h>
extern void IoScrollDown(void); void IoScrollDown(void);
extern void IoScrollUp(void); void IoScrollUp(void);
void KeStartShell(void);
void pstest(void);
void MmInitPaging(void);
void MmReloadPaging(void);
extern int shcol; extern int shcol;
extern int shargc; extern int shargc;