CTAOS v3
This commit is contained in:
196
SysCore/shell/apps.h
Normal file
196
SysCore/shell/apps.h
Normal file
@ -0,0 +1,196 @@
|
||||
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");
|
||||
}
|
87
SysCore/shell/shell.c
Normal file
87
SysCore/shell/shell.c
Normal file
@ -0,0 +1,87 @@
|
||||
#include <conio.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()
|
||||
{
|
||||
char str[256];
|
||||
char* param[16];
|
||||
int i, len, params=0;
|
||||
|
||||
//clrscr();
|
||||
|
||||
|
||||
|
||||
for (;;) {
|
||||
puts("\n] ");
|
||||
get_str(str, 256);
|
||||
|
||||
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
|
||||
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
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 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 7: apps_help(params, (const char**)param); break;
|
||||
case 8: puts((char*)get_cpu_vender()); break;
|
||||
case 9: apps_memory_manager (0, params, (const char**)param); break;
|
||||
case 10: apps_memory_manager (1, params, (const char**)param); break;
|
||||
case 11: apps_memory_status(); break;
|
||||
case 12: apps_memory_manager (2, params, (const char**)param); break;
|
||||
|
||||
default: puts("Invalid function: "); puts(param[0]);
|
||||
putc('\n');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user