-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathcommand.c
More file actions
151 lines (126 loc) · 2.84 KB
/
command.c
File metadata and controls
151 lines (126 loc) · 2.84 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "command.h"
#include "process/thread.h"
#include "mm/cpio.h"
#include "mm/allocator.h"
#include "fs/vfs.h"
#include "../lib/uart.h"
#include "../lib/string.h"
void InputBufferOverflowMessage(char cmd[])
{
uart_puts("Follow command: \"");
uart_puts(cmd);
uart_puts("\"... is too long to process.\n");
uart_puts("The maximum length of input is 64.");
}
void CommandInit()
{
buddy_initialize();
thread_init();
init_filesystem();
}
void CommandHelp()
{
uart_puts("\n");
uart_puts("Valid Command:\n");
uart_puts("\thelp:\t\tprint this help.\n");
uart_puts("\thello:\t\tprint \"Hello World!\"\n");
// cpio
uart_puts("cpio:\n");
uart_puts("\tls:\t\tls cpio file.\n");
uart_puts("\tcat [filename]:\tcat cpio file content.\n");
uart_puts("\texe [app.img]:\texe userprogram [app.img].\n");
// buddy
uart_puts("buddy:\n");
uart_puts("\tbuddyinit:\t\t\tinit buddy system.\n");
uart_puts("\tloglist:\t\t\tlog buddy linked list.\n");
uart_puts("\tlogpool:\t\t\tlog buddy allocated pool.\n");
uart_puts("\tlogtable:\t\t\tlog buddy page table.\n");
uart_puts("\talloc [num]:\t\t\talloc memory size [num].\n");
uart_puts("\tfree [index]:\t\t\tfree memory [index].\n");
uart_puts("\tfree16/32/64/128 [index]:\tfree small memory [index].\n");
// system
uart_puts("system:\n");
uart_puts("\ttimestamp:\tget current timestamp.\n");
uart_puts("\treboot:\t\treboot rpi3.\n");
uart_puts("\n");
}
void CommandHello()
{
uart_puts("Hello World!\n");
}
void CommandCpiols()
{
Cpiols();
}
void CommandCpiocat(char arg[])
{
Cpiocat(arg);
}
void CommandCpioexe(char arg[])
{
Cpioexe(arg);
}
void CommandTimestamp()
{
unsigned long int cnt_freq, cnt_tpct;
char str[20];
asm volatile(
"mrs %0, cntfrq_el0 \n\t"
"mrs %1, cntpct_el0 \n\t"
: "=r" (cnt_freq), "=r" (cnt_tpct)
:
);
ftoa((float)cnt_tpct / cnt_freq, str, 6);
uart_send('[');
uart_puts(str);
uart_puts("]\n");
}
void CommandBuddyInit()
{
buddy_initialize();
}
void CommandBuddyLogList()
{
buddy_log_list();
}
void CommandBuddyLogTable()
{
buddy_log_allocated_table();
}
void CommandBuddyLogPool()
{
buddy_log_pool();
}
void CommandBuddyFree(const int section)
{
buddy_free(section);
}
void CommandBuddyFreePool(int pool, int index)
{
buddy_free_pool(pool, index);
}
void CommandBuddyAlloc(const int size)
{
buddy_alloc(size);
}
void CommandThreadTest(int test_id)
{
thread_test(test_id);
}
void CommandVfsTest(int test_id)
{
vfs_test(test_id);
}
void CommandNotFound(char *s)
{
uart_puts("Err: command ");
uart_puts(s);
uart_puts(" not found, try <help>\n");
}
void CommandReboot()
{
uart_puts("Start Rebooting...\n");
*PM_RSTC = PM_PASSWORD | 0x20;
*PM_WDOG = PM_PASSWORD | 100;
while(1);
}