luxos/SysCore/shell/apps.h

196 lines
6.0 KiB
C
Raw Normal View History

2021-09-14 15:34:14 +00:00
const char *apps_lst[] = {
"",
"reboot",
"osver",
"time",
"place",
"cls",
"memory",
"help",
"cpu_info",
"mem_alloc", //0
"mem_free", //1
"mem_stat",
"mem_test", //2
};
int apps_count = 13;
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");
}
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);
}
void apps_place()
{
printf ("On your desk, if you didn't notice... \n");
}
void apps_clrscr()
{
clrscr();
}
void apps_memory(const int pn, const char* param[])
{
if (pn<3) {
printf ("Correct syntax: memory [start_address] [end_address] (in hex)\n");
return;
}
byte *start, *end;
start = (byte *) atox (param[1]);
end = (byte *) atox (param[2]);
byte* count;
while (start <= end) {
put_hex ((unsigned int) start); puts(": ");
for (count = start; count < start+16; count++) {
putc(hex[*count/16]); putc(hex[*count%16]);
putc(' ');
}
puts(" ");
for (count = start; count < start+16; count++) {
if (*count < 32) putc('.');
else putc(*count);
}
putc('\n');
start+=16;
}
}
void apps_help(const int pn, const char* param[])
{
int i;
puts ("\n");
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");
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]);
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;
}
puts("\n\n");
}
extern void detect_cpu();
void apps_memory_manager (const int function, const int pn, const char* param[])
{
switch (function) {
// Alloc
case 0:
{ unsigned int times = 1;
if (pn > 1 && strcmp(param[1], "times") == 0)
times = atoui(param[2]);
uint32_t temp;
for (; times > 0; times--) {
temp = (uint32_t) pmmngr_alloc_block();
if (temp == 0) {
printf ("Out of memory.\n");
break;
}
else printf ("New block allocated at address 0x%x\n", temp);
}
return;
}
// Free
case 1:
{ if (pn <= 1) {
printf ("Parameter missing: [address (hex)]\n");
return;
}
uint32_t temp = atox(param[1]);
pmmngr_free_block ((void*)temp);
printf ("Block containing address 0x%x now free.", temp);
return;
}
// Test
case 2:
{ if (pn <= 1) {
printf ("Parameter missing: [block number]");
return ; }
unsigned int temp = atoui(param[1]);
printf (pmmngr_test_block(temp) ? "Block %u is free.\n" : "Block %u is used.\n", temp);
}
}
}
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");
}