1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#include <stdio.h>
#include <string.h>
#include "syscalls.c"
void hello() {
puts(
"Welcome to FoolShell v0.1"
);
}
void prompt() {
printf(
"$ "
);
}
int main(int argc, char **argv)
{
syscalls_init();
hello();
FILE *input;
input=fopen(1,"r");
char *buf=malloc(256);
while(1)
{
prompt();
fgets(buf,255,input);
buf[strlen(buf)-1]=0;
// puts(buf);
process(buf);
}
return 0;
}
int process(char *command)
{
// copied from trottelshell
if(!strcmp(command,"HELP"))
{
puts("foolshell: supported built-in commands: HELP, ECHO, TIME, MEM, PROC, TASKS, ALLOC, READ, SYSCALL.");
}
else if(!strcmp(command,"TIME"))
{
// uint32_t time=task_system_clock;
// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d seconds passed since system start.",(time/25));
puts("foolshell: TIME not supported now.");
}
else if(!strcmp(command,"MEM"))
{
//mmap_show_free();
puts("foolshell: MEM not supported now.");
}
else if(!strcmp(command,"PROC"))
{
/*
for(int i=0;i<SMP_MAX_PROC;i++)
{
if(cpu_counter[i]!=0)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"cpu: %d => %d.",i,cpu_counter[i]);
}
*/
puts("foolshell: PROC not supported now.");
}
else if(!strcmp(command,"TASKS"))
{
//log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d %d %d",c1,c2,c2);
puts("foolshell: TASKS not supported now.");
}
else if(!strcmp(command,"ALLOC"))
{
/*
uint32_t *malloc= pmmngr_alloc_block();
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"allocated 4KB block at: %08x.",malloc);
*/
puts("foolshell: ALLOC not supported now.");
}
else if(!strcmp(command,"SYSCALL"))
{
puts("system call 10");
unsigned int ebx; // will hold return value;
// system call
asm("pusha");
asm("mov $10,%eax"); // select syscall 10 (example_syscall)
asm("mov $666,%edx");
asm("mov $333,%ecx");
asm("int $0x80"); // actual syscall ! interrupt
asm("mov %%ebx, %0": "=b" (ebx));
asm("popa");
//
printf("system call returned %i\n",ebx);
}
else if(!strcmp(command,"ECHO"))
{
printf("%s\n",command);
}
else
{
puts("foolshell: command not found");
}
//
}
|