175 lines
6.3 KiB
C
175 lines
6.3 KiB
C
#define hex(x) (x < 10) ? x+'0' : x-10+'a'
|
|
|
|
const char *apps_lst[] = {
|
|
/*0*/ "",
|
|
/*1*/ "reboot",
|
|
/*2*/ "osver",
|
|
/*3*/ "time",
|
|
/*4*/ "place",
|
|
/*5*/ "cls",
|
|
/*6*/ "dump",
|
|
/*7*/ "help",
|
|
/*8*/ "cpuid",
|
|
/*9*/ "memstat",
|
|
/*A*/ "read"
|
|
};
|
|
int apps_count = 11;
|
|
|
|
|
|
void apps_osver()
|
|
{
|
|
cprintf ("%#0BC%#0CT%#0AA %#0F32bit Operating System v0.1\n\r");
|
|
cprintf ("(c) CTA 2010\n\r");
|
|
}
|
|
|
|
void apps_time()
|
|
{
|
|
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()
|
|
{
|
|
cprintf ("%#0FOn your desk, %#07if you didn't notice... \n\r");
|
|
}
|
|
|
|
void apps_clrscr()
|
|
{
|
|
clrscr();
|
|
}
|
|
|
|
void apps_dump(const int pn, const char* param[])
|
|
{
|
|
if (pn<3) {
|
|
cprintf ("%#0CCorrect syntax: %#07dump %#0F[start_address] %#0F[end_address] %#0C(in hex)\n\r");
|
|
return;
|
|
}
|
|
|
|
unsigned char *start, *end;
|
|
start = (unsigned char *) atox (param[1]);
|
|
end = (unsigned char *) atox (param[2]);
|
|
unsigned char* count;
|
|
|
|
while (start <= end) {
|
|
cprintf("%#0D%x%#07: ", (unsigned int) start);
|
|
|
|
for (count = start; count < start+16; count++) {
|
|
if (*count == 0) cprintf ("%#0800 ");
|
|
else cprintf ("%#0F%c%c ", hex(*count/16), hex(*count%16));
|
|
}
|
|
|
|
cprintf(" ");
|
|
for (count = start; count < start+16; count++) {
|
|
if (*count < 32) cprintf(".");
|
|
else cprintf("%#0A%c", *count);
|
|
}
|
|
|
|
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;
|
|
|
|
for (i = 0; i < apps_count; i++)
|
|
arr[i] = i;
|
|
|
|
qsort((void*)arr, apps_count, sizeof(short), apps_help_sort);
|
|
|
|
if (pn==1) {
|
|
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++);
|
|
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 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;
|
|
}
|
|
|
|
// 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");
|
|
}
|
|
|
|
|
|
extern void detect_cpu();
|
|
|
|
void apps_memory_status()
|
|
{
|
|
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])));
|
|
}
|
|
|