#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/dirent.h>
#include <sys/wait.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <syscall.h>
Go to the source code of this file.
◆ SHELL_MAX_ARGS
◆ SHELL_MAX_LINE
#define SHELL_MAX_LINE 256 |
◆ Cmd_Exit()
void Cmd_Exit |
( |
int |
argc, |
|
|
const char * |
argv[] |
|
) |
| |
Definition at line 41 of file shell.c.
42{
43 int val = 0;
44
45 if (argc != 1 && argc != 2) {
46 printf(
"Invalid number of arguments\n");
47 return;
48 }
49
50 if (argc == 2) {
52 }
53
55}
int printf(const char *fmt,...)
int atoi(const char *nptr)
◆ Cmd_Help()
void Cmd_Help |
( |
int |
argc, |
|
|
const char * |
argv[] |
|
) |
| |
Definition at line 33 of file shell.c.
34{
35 printf(
"bkpt Trigger a kernel breakpoint\n");
36 printf(
"exit Exit shell\n");
37 printf(
"help Display the list of commands\n");
38}
◆ Cmd_Run()
void Cmd_Run |
( |
int |
argc, |
|
|
const char * |
argv[] |
|
) |
| |
Definition at line 66 of file shell.c.
67{
68 int i, status;
69 char path[256];
71
72 if (argc == 0)
73 return;
74
75 i = 0;
79
80 status =
OSStat(path, &sb);
81 if (status != 0) {
82 i++;
83 continue;
84 }
85
87 status =
spawn(path, &argv[0]);
88 if (status > 100000) {
90 }
91#if 0
93 printf(
"Process result: %d\n", status);
94#endif
95 return;
96 }
97
98 printf(
"Unknown command '%s'\n", argv[0]);
99}
uint64_t OSWait(uint64_t pid)
int OSStat(const char *path, struct stat *sb)
const char * searchpath[]
char * strcpy(char *to, const char *from)
char * strcat(char *s, const char *append)
pid_t spawn(const char *path, const char *argv[])
◆ DispatchCommand()
void DispatchCommand |
( |
char * |
buf | ) |
|
Definition at line 102 of file shell.c.
103{
104 int i;
105 int argc;
107 char *nextArg;
108
109
110 for (i = 0;
buf[i] != 0; i++) {
111 if (
buf[i] ==
'\n') {
113 break;
114 }
115 }
116
117
121 break;
122
123 argv[argc] = nextArg;
125 }
126
127
128 if (
strcmp(argv[0],
"help") == 0) {
129 Cmd_Help(argc, (
const char **)argv);
130 }
else if (
strcmp(argv[0],
"bkpt") == 0) {
131 asm volatile("int3");
132 }
else if (
strcmp(argv[0],
"exit") == 0) {
133 Cmd_Exit(argc, (
const char **)argv);
134 }
else if (
strcmp(argv[0],
"#") == 0) {
135
136 }
else if (
buf[0] ==
'\0') {
137
138 } else {
139 Cmd_Run(argc, (
const char **)argv);
140 }
141}
void Cmd_Run(int argc, const char *argv[])
void Cmd_Exit(int argc, const char *argv[])
void Cmd_Help(int argc, const char *argv[])
int strcmp(const char *s1, const char *s2)
char * strtok(char *str, const char *delim)
◆ main()
int main |
( |
int |
argc, |
|
|
const char * |
argv[] |
|
) |
| |
Definition at line 18 of file shell.c.
19{
21
23
24 while (1) {
27
29 }
30}
void DispatchCommand(char *buf)
char * fgets(char *str, int size, FILE *fh)
int fputs(const char *str, FILE *fh)
◆ searchpath
Initial value:= {
"",
"/sbin/",
"/bin/",
"/tests/",
}
Definition at line 57 of file shell.c.