-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add few system calls like read, waitpid, exit
* First shell implementation, requires waitpid, read and exit system calls * User entry point changed to _start, that also call `exit` on return from application * User input is stored in circular buffer, and `read` is blocked on this buffer, interrupt handler wakes up thread * Added forktest user app Signed-off-by: Mahavir Jain <[email protected]>
- Loading branch information
Showing
11 changed files
with
218 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <tinyos.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <sys/wait.h> | ||
|
||
#define N 32 | ||
|
||
void forktest(void) | ||
{ | ||
int n, pid; | ||
|
||
printf("fork test\n"); | ||
|
||
for (n=0; n<N; n++) { | ||
pid = fork(); | ||
if(pid < 0) { | ||
break; | ||
} | ||
if(pid == 0) { | ||
exit(0); | ||
} | ||
} | ||
|
||
if (n == N) { | ||
printf("fork claimed to work N times!\n", N); | ||
} | ||
} | ||
|
||
int main(void) | ||
{ | ||
forktest(); | ||
waitpid(-1, NULL, 0); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,39 @@ | ||
#include <tinyos.h> | ||
#include <unistd.h> | ||
#include <sys/wait.h> | ||
#include <string.h> | ||
|
||
int a = 0xa5a5; | ||
int main() | ||
{ | ||
if (a == 0xa5a5) | ||
printf("I am shell\n"); | ||
else | ||
printf("I lost you\n"); | ||
for(;;); | ||
int ret; | ||
int c; | ||
char buf[32]; | ||
int index = 0; | ||
|
||
printf("\nStarting sh\n"); | ||
printf("Type `help` for commands\n"); | ||
printf("# "); | ||
for (;;) { | ||
ret = read(0, &c, 1); | ||
if (!ret) | ||
continue; | ||
buf[index++] = c; | ||
if (c == '\n') { | ||
buf[--index] = '\0'; | ||
ret = fork(); | ||
if (ret == 0) { | ||
if (!strcmp(buf, "help")) | ||
printf("Available commands 'forktest'\n"); | ||
else | ||
execve(buf, (char **) &ret, NULL); | ||
return -1; | ||
} else { | ||
waitpid(-1, NULL, 0); | ||
index = 0; | ||
printf("# "); | ||
} | ||
} | ||
} | ||
printf("Bye! Shell exiting\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ | |
#define __KEYBOARD_H__ | ||
|
||
void init_keyboard(); | ||
int sys_read(); | ||
|
||
#endif /* __KEYBOARD_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.