Vhex-kernel/src/user/shell/main.c

64 lines
1.3 KiB
C
Raw Normal View History

#include <lib/display.h>
#include <lib/unistd.h>
2019-12-20 11:31:34 +01:00
#include "util.h"
//TODO: documentation.
int main(void)
{
char input[12];
2019-12-20 11:31:34 +01:00
int cmd_size;
2020-03-15 00:56:31 +01:00
//char **argv;
//int argc;
//int STDOUT_FILENO;
2019-12-20 11:31:34 +01:00
// Try to open TTY
// @note:
// We use O_DIRECT to avoid cache
// generation because we do not have a
// lot of memory.
/*STDOUT_FILENO = open("/dev/tty", O_DIRECT);
if (STDOUT_FILENO < 0)
{
// Display error.
2020-03-15 00:56:31 +01:00
display_t disp;
dopen(&disp, "default");
dclear(&disp);
dprint(&disp, 0, 0, "User program fail to open TTY");
dprint(&disp, 0, 1, "Wait user manual reset...");
dupdate(&disp);
2019-12-20 11:31:34 +01:00
// Wait user manual reset.
while (1)
{
// @note: we can use "sleep" because we
// are in privilegied mode.
// TODO: use sleep syscall !
__asm__ volatile ("sleep");
}
}*/
2020-03-18 17:48:53 +01:00
2019-12-20 11:31:34 +01:00
// Shell main loop.
write(STDOUT_FILENO, "Boot Complete !\n", 16);
2019-12-20 11:31:34 +01:00
while (1)
{
// Get user command.
write(STDOUT_FILENO, ">", 1);
cmd_size = read(STDIN_FILENO, input, 12);
2019-12-20 11:31:34 +01:00
// Remove '\n' char.
// FIXME: create argc, argv !!
input[cmd_size - 1] = '\0';
// Check buit-in.
2020-03-18 17:48:53 +01:00
if (check_builtin(input) != 0)
{
write(STDOUT_FILENO, input, cmd_size - 1);
write(STDOUT_FILENO, ": command not found\n", 20);
2020-03-18 17:48:53 +01:00
} else {
write(STDOUT_FILENO, input, cmd_size - 1);
write(STDOUT_FILENO, ": command found :D !\n", 21);
2020-03-18 17:48:53 +01:00
}
2019-12-20 11:31:34 +01:00
}
return (0);
2019-12-20 11:31:34 +01:00
}