2019-11-28 13:02:47 +01:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
// GNU GPL OS/K //
|
|
|
|
// //
|
|
|
|
// Desc: Kernel shell //
|
|
|
|
// //
|
|
|
|
// //
|
|
|
|
// 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 <https://www.gnu.org/licenses/>. //
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
#include <vers.h>
|
|
|
|
#include <mm/mm.h>
|
|
|
|
#include <io/ata.h>
|
|
|
|
#include <io/vga.h>
|
|
|
|
#include <io/spkr.h>
|
|
|
|
#include <ke/time.h>
|
|
|
|
#include <lib/buf.h>
|
|
|
|
#include <sh/shell.h>
|
|
|
|
#include <po/shtdwn.h>
|
|
|
|
|
|
|
|
static Command_t testcmdtable[];
|
|
|
|
|
|
|
|
error_t CmdTest(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
ExecuteCommand(cmdline+5, testcmdtable);
|
|
|
|
KernLog ("\n");
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdArgs(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
KernLog("cmdline: '%s'\nargc: %d\n", cmdline, argc);
|
|
|
|
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
KernLog("argv[%d]: '%s'\n", i, argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-12-21 12:40:53 +01:00
|
|
|
error_t CmdAtoi(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
KernLog("cmdline: '%s'\nargc: %d\n", cmdline, argc);
|
|
|
|
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
KernLog("argv[%d]: '%u'\n", i, atoi(argv[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-11-28 13:02:47 +01:00
|
|
|
error_t CmdDumpATASect(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
char sector[512] = {0};
|
2019-12-07 17:54:48 +01:00
|
|
|
int sectNumber = atoi(argv[1]);
|
|
|
|
int nb = 1; //atoi(argv[2]);
|
2019-11-28 13:02:47 +01:00
|
|
|
int x = 0;
|
|
|
|
int step = 16;
|
|
|
|
|
|
|
|
if (sectNumber <= 0 || sectNumber > 255) {
|
|
|
|
KernLog("Bad argument\n\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nb) nb = 1;
|
|
|
|
|
|
|
|
KernLog("Sector begin: %d\n", (sectNumber - 1)*512);
|
|
|
|
|
|
|
|
IoReadATA(sector, nb, sectNumber);
|
|
|
|
|
|
|
|
while(x < 512*nb) {
|
|
|
|
KernLog("%C", shcol);
|
|
|
|
for (int i = 0; i < step; i++) {
|
|
|
|
KernLog("%02x ", (uchar)sector[i+x]);
|
|
|
|
}
|
|
|
|
KernLog(" %C ", VGA_COLOR_LIGHT_BLUE);
|
|
|
|
for (int i = 0; i < step; i++) {
|
|
|
|
if (isprint(sector[i+x]))
|
|
|
|
KernLog("%c",
|
|
|
|
sector[i+x]
|
|
|
|
);
|
|
|
|
else
|
|
|
|
KernLog("%c", 0);
|
|
|
|
}
|
|
|
|
KernLog("\n");
|
|
|
|
x += step;
|
|
|
|
}
|
|
|
|
|
|
|
|
KernLog("\n\n");
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2020-01-07 00:44:39 +01:00
|
|
|
error_t CmdDumpMem(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
char sector[1024] = {0};
|
|
|
|
char *address = (char*)atol(argv[1]);
|
|
|
|
int nb = 1; //atoi(argv[2]);
|
|
|
|
int x = 0;
|
|
|
|
int step = 16;
|
|
|
|
|
|
|
|
KernLog("Address begin: %p\n", address);
|
|
|
|
|
|
|
|
for (int i = 0; i < 1024*nb; i++) {
|
|
|
|
sector[i] = *address++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(x < 1024*nb) {
|
|
|
|
KernLog("%C", shcol);
|
|
|
|
for (int i = 0; i < step; i++) {
|
|
|
|
KernLog("%02x ", (uchar)sector[i+x]);
|
|
|
|
}
|
|
|
|
KernLog(" %C ", VGA_COLOR_LIGHT_BLUE);
|
|
|
|
for (int i = 0; i < step; i++) {
|
|
|
|
if (isprint(sector[i+x]))
|
|
|
|
KernLog("%c",
|
|
|
|
sector[i+x]
|
|
|
|
);
|
|
|
|
else
|
|
|
|
KernLog("%c", 0);
|
|
|
|
}
|
|
|
|
KernLog("\n");
|
|
|
|
x += step;
|
|
|
|
}
|
|
|
|
|
|
|
|
KernLog("\n\n");
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
2019-11-28 13:02:47 +01:00
|
|
|
error_t CmdFloatDiv(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-12-07 17:54:48 +01:00
|
|
|
double a = (double)atoi(argv[1]);
|
|
|
|
double b = (double)atoi(argv[2]);
|
2019-11-28 13:02:47 +01:00
|
|
|
|
|
|
|
double number = a / b;
|
|
|
|
double number_ent = (double)(ulong)number;
|
|
|
|
double dec = number - number_ent;
|
|
|
|
double sub = 0.0;
|
|
|
|
|
|
|
|
char res[17]; // 10e-16 is the max precision
|
|
|
|
|
|
|
|
for(int i = 0; i < 16; i++) {
|
|
|
|
dec = (dec * 10.0) - (sub * 10.0);
|
|
|
|
sub = (double)(ulong)dec;
|
|
|
|
|
|
|
|
snprintf(&res[i], 17-i, "%d", (ulong)dec);
|
|
|
|
}
|
|
|
|
|
|
|
|
KernLog("%d / %d = %d.%s \n", (ulong)a, (ulong)b, (ulong)number_ent, res);
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdHelpTest(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
uint i, count = 0;
|
|
|
|
Command_t *cmd;
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
KernLog("List of all test built-ins:\n");
|
|
|
|
for (cmd = testcmdtable; 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 CmdPF(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2020-01-09 18:19:49 +01:00
|
|
|
ulong *address = (ulong*)(ulong)atoul(argv[1]);
|
|
|
|
|
|
|
|
if (!address) {
|
|
|
|
address = (ulong *)0x12fdc3000 - 1 ;
|
|
|
|
}
|
2019-11-28 13:02:47 +01:00
|
|
|
|
|
|
|
KernLog("Provoking Page Fault at %#x\n", address);
|
|
|
|
|
2020-01-05 22:12:50 +01:00
|
|
|
KernLog("It contained %#x\n", *address);
|
2019-11-28 13:02:47 +01:00
|
|
|
*address = 1;
|
2020-01-05 22:12:50 +01:00
|
|
|
KernLog("Now it contains %#x\n", *address);
|
2019-11-28 13:02:47 +01:00
|
|
|
|
|
|
|
KernLog("No page fault : address was valid/present\n");
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdShell(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
ShStartShell();
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdStackOverflow(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
CmdStackOverflow(0, 0, 0);
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdStackUnderflow(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
|
|
|
for (int i = 0 ;; i++) {
|
|
|
|
asm volatile ("pop %rax\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t CmdTimerTest(int argc, char **argv, char *cmdline)
|
|
|
|
{
|
2019-12-07 17:54:48 +01:00
|
|
|
int delay = atoi(argv[1]);
|
2019-11-28 13:02:47 +01:00
|
|
|
|
|
|
|
Timer_t *timer = KeSetTimer(delay);
|
|
|
|
|
|
|
|
while(!(KeGetTimer(timer))) {
|
|
|
|
bprintf(BStdOut,".");
|
|
|
|
BStdOut->flusher(BStdOut);
|
|
|
|
}
|
|
|
|
|
|
|
|
KernLog("Finished !\n");
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Command_t testcmdtable[] =
|
|
|
|
{
|
|
|
|
{ "args", CmdArgs, "Print command line" },
|
2019-12-21 12:40:53 +01:00
|
|
|
{ "atoi", CmdAtoi, "Print command line atoised" },
|
2019-11-28 13:02:47 +01:00
|
|
|
{ "dmpsec", CmdDumpATASect, "Dump an ATA sector on screen" },
|
2020-01-07 00:44:39 +01:00
|
|
|
{ "dmp", CmdDumpMem, "Dump 1MB of memory starting from addr"},
|
2019-11-28 13:02:47 +01:00
|
|
|
{ "help", CmdHelpTest, "Show this message" },
|
|
|
|
{ "div", CmdFloatDiv, "Float div. Usage : div a b. Returns a/b"},
|
|
|
|
{ "pf", CmdPF, "Provoke a PF. Usage: pfault <address>"},
|
|
|
|
{ "shell", CmdShell, "Start a new shell (nested)", },
|
|
|
|
{ "stkov", CmdStackOverflow, "Provoke a stack overflow" },
|
|
|
|
{ "stkun", CmdStackUnderflow, "Provoke a stack underflow" },
|
|
|
|
{ "timer", CmdTimerTest, "test timer of x ms" },
|
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|