This commit is contained in:
2021-09-14 18:35:52 +03:00
parent f052f2294e
commit d605c6a016
84 changed files with 3647 additions and 1192 deletions

View File

@ -1,69 +1,40 @@
#define hex(x) (x < 10) ? x+'0' : x-10+'a'
const char *apps_lst[] = {
"",
"reboot",
"osver",
"time",
"place",
"cls",
"memory",
"help",
"cpu_info",
"memstat"
/*0*/ "",
/*1*/ "reboot",
/*2*/ "osver",
/*3*/ "time",
/*4*/ "place",
/*5*/ "cls",
/*6*/ "dump",
/*7*/ "help",
/*8*/ "cpuid",
/*9*/ "memstat",
/*A*/ "read"
};
int apps_count = 10;
int apps_count = 11;
unsigned int atox(const char* str)
{
unsigned int temp = 0;
int i; unsigned int digit = 0;
for (i = 0; str[i]!=0; i++) {
if (str[i] >= '0' && str[i] <= '9') digit = str[i] - '0';
else if (str[i] >= 'A' && str[i] <= 'F') digit = str[i] - 'A' + 10;
else if (str[i] >= 'a' && str[i] <= 'f') digit = str[i] - 'a' + 10;
else break;
temp = temp*16 + digit;
}
return temp;
}
unsigned int atoui(const char* str)
{
unsigned int temp = 0;
int i;
for (i = 0; str[i] >= '0' && str[i] <= '9' ; i++)
temp = temp*10 + (str[i] - '0');
return temp;
}
void apps_osver()
{
printf ("CTA 32bit Operating System v0.1");
printf ("\n(c) CTA 2010\n");
cprintf ("%#0BC%#0CT%#0AA %#0F32bit Operating System v0.1\n\r");
cprintf ("(c) CTA 2010\n\r");
}
void apps_time()
{
printf ("Today is %s, %u of %s, %u%u.\n", clock_weekdays[_internal_clock.weekday],
(unsigned int) _internal_clock.day, clock_months[_internal_clock.month],
(unsigned int) _internal_clock.century, (unsigned int) _internal_clock.year);
printf ("Now is %u:%u:%u.\n", (unsigned int) _internal_clock.hours,
(unsigned int) _internal_clock.minutes, (unsigned int) _internal_clock.seconds);
TIME _internal_clock = i86_pit_get_time();
cprintf ("Today is %#0F%s%#07, %#0F%u %#07of %#0F%s%#07, %#0F%u%u%#07.\n\r", clock_weekday[_internal_clock.weekday],
(unsigned) _internal_clock.day, clock_month[_internal_clock.month],
(unsigned) _internal_clock.century, (unsigned) _internal_clock.year);
cprintf ("%#07Now is %#0F%u%#87:%#0F%u%#87:%#0F%u%#07.\n\r", (unsigned) _internal_clock.hour,
(unsigned) _internal_clock.minute, (unsigned) _internal_clock.second);
}
void apps_place()
{
printf ("On your desk, if you didn't notice... \n");
cprintf ("%#0FOn your desk, %#07if you didn't notice... \n\r");
}
void apps_clrscr()
@ -71,66 +42,112 @@ void apps_clrscr()
clrscr();
}
void apps_memory(const int pn, const char* param[])
void apps_dump(const int pn, const char* param[])
{
if (pn<3) {
printf ("Correct syntax: memory [start_address] [end_address] (in hex)\n");
cprintf ("%#0CCorrect syntax: %#07dump %#0F[start_address] %#0F[end_address] %#0C(in hex)\n\r");
return;
}
byte *start, *end;
start = (byte *) atox (param[1]);
end = (byte *) atox (param[2]);
byte* count;
unsigned char *start, *end;
start = (unsigned char *) atox (param[1]);
end = (unsigned char *) atox (param[2]);
unsigned char* count;
while (start <= end) {
put_hex ((unsigned int) start); puts(": ");
cprintf("%#0D%x%#07: ", (unsigned int) start);
for (count = start; count < start+16; count++) {
putc(hex[*count/16]); putc(hex[*count%16]);
putc(' ');
if (*count == 0) cprintf ("%#0800 ");
else cprintf ("%#0F%c%c ", hex(*count/16), hex(*count%16));
}
puts(" ");
cprintf(" ");
for (count = start; count < start+16; count++) {
if (*count < 32) putc('.');
else putc(*count);
if (*count < 32) cprintf(".");
else cprintf("%#0A%c", *count);
}
putc('\n');
cprintf("\n\r");
start+=16;
}
}
int apps_help_sort(const void* a, const void* b)
{
return strcmp(apps_lst[*(short *)a], apps_lst[*(short *)b]);
}
void apps_help(const int pn, const char* param[])
{
short arr[apps_count];
int i;
puts ("\n");
for (i = 0; i < apps_count; i++)
arr[i] = i;
qsort((void*)arr, apps_count, sizeof(short), apps_help_sort);
if (pn==1) {
puts("[BeTA]\n");
puts("Available commands:");
for (i = 1; i < apps_count; i++) {
puts("\n \t "); puts((char*)apps_lst[i]);
}
puts("\n\nUse help [command] for help on individual commands.\n");
cprintf("%#0BC%#0CT%#0AA %#0FShell %#07commands:\n\r");
for (i = 1; i < apps_count; i++)
cprintf("%#0F\t%c %s\n\r", 0x7 ,apps_lst[arr[i]]);
cprintf("\n\rUse help %#0E[command]%#07 for help on individual commands.\n\r");
return;
}
for (i = 0; strcmp(apps_lst[i], param[1])!=0 && i<apps_count; i++);
puts("[BeTA]\nShowing help for command: "); puts((char*)apps_lst[i]);
cprintf("\n\r[%#0Bc%#0Ct%#0Aa %#0APreALphA%#07] Showing help for command: %#0E%s", apps_lst[i]);
// DESCRIPTION:
cprintf ("\n\r%#0FDescription:\t");
switch (i) {
case 0: break;
case 1: puts("\n\nReboots the system.\nUsage: reboot"); break;
case 2: puts("\n\nShows information about the current operating system.\nUsage: osver"); break;
case 3: puts("\n\nDisplays the current date.\nUsage: date"); break;
case 5: puts("\n\nClears the screen.\nUsage: cls");break;
case 6: puts("\n\nShows the content of memory in the interval specified.\nUsage: memory [start_address] [end_address]");break;
case 7: puts("\n\nShows a list of commands, or help for a specified command.\nUsage: help [opt:command]"); break;
default: puts("Invalid function: "); puts((char*)param[1]);
break;
case 1: cprintf("Restarts the system."); break;
case 2: cprintf("Shows information about the operating system."); break;
case 3: cprintf("Displays the current time and date."); break;
case 4: cprintf("%#08A little easter egg (shhhh... don't tell anyone."); break;
case 5: cprintf("Clears the screen.");break;
case 6: cprintf("Shows the virtual memory content between the specified\n\r\t\taddresses. ");break;
case 7: cprintf("Displays instructions for each command, or the list of\n\r\t\tcommands if none specified."); break;
case 8: cprintf("Shows the CPU's vendor."); break;
case 9: cprintf("Displays the current status of the memory, reported by\n\r\t\tthe memory manager."); break;
case 0xA: cprintf ("Reads one sector from floppy disk."); break;
default: cprintf("%#0CInvalid function, or help not implemented. "); break;
}
puts("\n\n");
// USAGE:
cprintf ("\n\r%#0FUsage:\t\t");
switch (i) {
case 1: cprintf("reboot"); break;
case 2: cprintf("osver"); break;
case 3: cprintf("time"); break;
case 4: cprintf("%#08Nobody knows. And %#07nobody %#08should ever do."); break;
case 5: cprintf("cls"); break;
case 6: cprintf("dump %#0E[start] [end]"); break;
case 7: cprintf("help %#0E[command]"); break;
case 8: cprintf("cpuid"); break;
case 9: cprintf("memstat"); break;
case 0xA: cprintf("read %#0e[sector]"); break;
default: cprintf("%#0CInvalid function, or help not implemented. "); break;
}
// NOTES:
cprintf ("\n\r%#0FNotes:\t");
switch (i) {
case 1: cprintf("\t%c Use wisely.", 0x7); break;
case 2: cprintf("%#08\t%c (None)", 0x7); break;
case 3: cprintf("%#08\t%c (None)", 0x7); break;
case 4: cprintf("%#08\t%c (None)", 0x7); break;
case 5: cprintf("%#08\t%c (None)", 0x7); break;
case 6: cprintf("\t%c %#0E[start]%#07 and %#0E[end]%#07 are virtual addresses in %#0Ahexadecimal%#07.", 0x7); break;
case 7: cprintf("\t%c The %#0E[command]%#07 parameter is optional.", 0x7); break;
case 8: cprintf("\t%c Shows CPU vendor returned by CPUID function.", 0x7); break;
case 9: cprintf("%#08\t%c (None)", 0x7); break;
case 0xA: cprintf("\t%c Sector is in decimal, starts from 0.", 0x7); break;
default: cprintf("%#0C\t%c Invalid function, or help not implemented. ", 0x7); break;
}
cprintf("\n\r");
}
@ -138,8 +155,20 @@ extern void detect_cpu();
void apps_memory_status()
{
printf ("Memory available: %u KB \n", pmmngr_get_memory_size ());
printf ("Total blocks: %u Used: %u Free: %u\n", pmmngr_get_block_count (), pmmngr_get_use_block_count (), pmmngr_get_free_block_count ());
printf ("Block size: %u bytes\nPaging is ", pmmngr_get_block_size());
printf ( pmmngr_is_paging() ? "enabled.\n" : "disabled.\n");
}
cprintf ("Memory available: %#0F%u KB \n\r", pmmngr_get_memory_size ());
cprintf ("Total blocks: %#0F%u %#07Used: %#0F%u %#07Free: %#0F%u\n\r", pmmngr_get_block_count (), pmmngr_get_use_block_count (), pmmngr_get_free_block_count ());
cprintf ("Block size: %#0F%u %#07bytes\n\rPaging is ", pmmngr_get_block_size());
cprintf ( pmmngr_is_paging() ? "%#0Aenabled%#07.\n\r" : "%#0Cdisabled%#07.\n\r");
}
void apps_read(const int pn, const char *param[])
{
if (pn <= 1) {
cprintf ("%#0CParameter missing: %#0F[sectorLBA]\n\r");
return;
}
cprintf ("Sector read, located at address %#0F0x%x.\n\r", i86_read_sector ((unsigned*) 0x7E00, 0, atoi(param[1])));
}

26
SysCore/shell/compile.bat Normal file
View File

@ -0,0 +1,26 @@
@echo off
rem NASM and DJGPP executable paths:
set nasm_path=C:\nasm
set djgpp_path=C:\DJGPP\bin
set objpath=..\objects
set incpath=../include
@echo Building CTA Shell...
del %objpath%\shell.o
goto build
:error
@echo.
@echo There have been build errors. Building halted.
@pause
exit
:build
@echo * Compiling ...
%djgpp_path%\gcc.exe -Wall -O -fstrength-reduce -fomit-frame-pointer -nostdinc -fno-builtin -I%incpath% -c -o %objpath%/shell.o shell.c
:check
if not exist %objpath%\shell.o goto error

View File

@ -1,82 +1,52 @@
#include <conio.h>
#include <hal.h>
#include <stdlib.h>
#include <string.h>
#include "../memory/mmngr_ph.h"
#include "apps.h"
void get_str(char *str, int len)
{
kb_key alpha;
int i;
for (i = 0; i<len-1 ; i++) {
text_mode_cursor(cursor_x, cursor_y);
alpha = getkey();
switch (alpha.character) {
case 0x00: --i; break; // Ignore null characters
case 0x7F: --i; break;
case '\b': // Backspace
if (i>0) { // Only backspace our string
if (--cursor_x < 0) { // Begin of row - 1 = End of previous row
cursor_x = 79; cursor_y--;
}
putc_pos(cursor_x, cursor_y, 0);
str[--i] = 0;
}
i--; break;
case '\n': str[i]=0; putc('\n'); return;
default: putc(alpha.character);
str[i] = alpha.character;
str[i+1] = 0;
break;
}
}
}
void shell()
{
apps_osver();
char str[256];
char* param[16];
int i, len, params=0;
//clrscr();
for (;;) {
puts("\n] ");
get_str(str, 256);
cprintf("%#0A\n] ");
cgets(str, 256);
cprintf("\n\r");
len = strlen(str);
len = strlen(str);
// Ignore spaces in front of command
i=0; params = 0;
while (str[i] == ' ') i++;
param[params] = str+i; params++; i++; // Parameter 0 = app itself
// Ignore spaces in front of command
i=0; params = 0;
while (str[i] == ' ') i++;
param[params] = str+i; params++; i++; // Parameter 0 = app itself
for (; i < len && params<16; i++) {
if (str[i] == ' ') str[i]=0;
for (; i < len && params<16; i++) {
if (str[i] == ' ') str[i]=0;
if (str[i] != 0 && str[i-1]==0) {
param[params] = str+i; params++;
}
if (str[i] != 0 && str[i-1]==0) {
param[params] = str+i; params++;
}
}
for (i = 0; strcmp(apps_lst[i], param[0])!=0 && i<apps_count; i++);
switch (i) {
case 0: puts("You must enter a command!\n"); break;
case 0: cprintf("%#0CYou must enter a command!\n\r"); break;
case 1: reboot();
case 2: apps_osver(); break;
case 3: apps_time(); break;
case 4: apps_place(); break;
case 5: apps_clrscr(); break;
case 6: apps_memory(params, (const char**)param); break;
case 6: apps_dump(params, (const char**)param); break;
case 7: apps_help(params, (const char**)param); break;
case 8: puts((char*)get_cpu_vender()); break;
case 8: cprintf("%#0A%s\n\r", (char*)get_cpu_vender()); break;
case 9: apps_memory_status(); break;
default: puts("Invalid function: "); puts(param[0]);
putc('\n');
case 10: apps_read (params, (const char**)param); break;
default: cprintf("%#0CInvalid function: %s\n\r", param[0]);
break;
}
}