mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:37:44 +00:00
Lots of hacking:
- Turn Keyboard into a CharacterDevice (85,1) at /dev/keyboard. - Implement MM::unmapRegionsForTask() and MM::unmapRegion() - Save SS correctly on interrupt. - Add a simple Spawn syscall for launching another process. - Move a bunch of IO syscall debug output behind DEBUG_IO. - Have ASSERT do a "cli" immediately when failing. This makes the output look proper every time. - Implement a bunch of syscalls in LibC. - Add a simple shell ("sh"). All it can do now is read a line of text from /dev/keyboard and then try launching the specified executable by calling spawn(). There are definitely bugs in here, but we're moving on forward.
This commit is contained in:
parent
72514c8b97
commit
fe237ee215
29 changed files with 276 additions and 32 deletions
56
Userland/sh.cpp
Normal file
56
Userland/sh.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include <LibC/stdio.h>
|
||||
#include <LibC/unistd.h>
|
||||
#include <LibC/process.h>
|
||||
|
||||
static void prompt()
|
||||
{
|
||||
if (getuid() == 0)
|
||||
printf("# ");
|
||||
else
|
||||
printf("$ ");
|
||||
}
|
||||
|
||||
static int runcmd(char* cmd)
|
||||
{
|
||||
//printf("command: '%s'\n", cmd);
|
||||
int ret = spawn(cmd);
|
||||
if (ret == -1) {
|
||||
printf("spawn failed: %s\n", cmd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int c, char** v)
|
||||
{
|
||||
char linebuf[128];
|
||||
int linedx = 0;
|
||||
linebuf[0] = '\0';
|
||||
|
||||
int fd = open("/dev/keyboard");
|
||||
if (fd == -1) {
|
||||
printf("failed to open /dev/keyboard :(\n");
|
||||
return 1;
|
||||
}
|
||||
prompt();
|
||||
for (;;) {
|
||||
char keybuf[16];
|
||||
ssize_t nread = read(fd, keybuf, sizeof(keybuf));
|
||||
if (nread < 0) {
|
||||
printf("failed to read :(\n");
|
||||
return 2;
|
||||
}
|
||||
for (ssize_t i = 0; i < nread; ++i) {
|
||||
putchar(keybuf[i]);
|
||||
if (keybuf[i] != '\n') {
|
||||
linebuf[linedx++] = keybuf[i];
|
||||
linebuf[linedx] = '\0';
|
||||
} else {
|
||||
runcmd(linebuf);
|
||||
linebuf[0] = '\0';
|
||||
linedx = 0;
|
||||
prompt();
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue