From 19b1bf216fc5ed1bb0eedeea3bcebf810b99d635 Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Sat, 10 Dec 2022 01:01:38 -0500 Subject: [PATCH] Split date out of shell --- SConstruct | 2 ++ bin/date/SConscript | 23 ++++++++++++++++++++++ bin/date/date.c | 11 +++++++++++ bin/shell/shell.c | 40 --------------------------------------- release/bootdisk.manifest | 1 + 5 files changed, 37 insertions(+), 40 deletions(-) create mode 100644 bin/date/SConscript create mode 100644 bin/date/date.c diff --git a/SConstruct b/SConstruct index c241f50..7e7b33c 100644 --- a/SConstruct +++ b/SConstruct @@ -174,6 +174,7 @@ SConscript('sys/SConscript', variant_dir='build/sys') SConscript('lib/libc/SConscript', variant_dir='build/lib/libc') #SConscript('lib/liblwip/SConscript', variant_dir='build/lib/liblwip') SConscript('bin/cat/SConscript', variant_dir='build/bin/cat') +SConscript('bin/date/SConscript', variant_dir='build/bin/date') SConscript('bin/ethdump/SConscript', variant_dir='build/bin/ethdump') SConscript('bin/ethinject/SConscript', variant_dir='build/bin/ethinject') SConscript('bin/ls/SConscript', variant_dir='build/bin/ls') @@ -201,6 +202,7 @@ if env["BOOTDISK"] == "1": bootdisk = env.BuildImage('#build/bootdisk.img', '#release/bootdisk.manifest') Depends(bootdisk, "#build/tools/newfs_o2fs/newfs_o2fs") Depends(bootdisk, "#build/bin/cat/cat") + Depends(bootdisk, "#build/bin/date/date") Depends(bootdisk, "#build/bin/ethdump/ethdump") Depends(bootdisk, "#build/bin/ethinject/ethinject") Depends(bootdisk, "#build/bin/ls/ls") diff --git a/bin/date/SConscript b/bin/date/SConscript new file mode 100644 index 0000000..cc40f90 --- /dev/null +++ b/bin/date/SConscript @@ -0,0 +1,23 @@ +import sys + +Import('env') + +cross_env = env.Clone() + +src = [ ] + +src_common = [ + "date.c" +] + +src.append(env["CRTBEGIN"]) +src.append(src_common) +src.append(env["CRTEND"]) + +cross_env.Append(LINKFLAGS = ['-nostdlib']) +cross_env.Append(CPPFLAGS = ['-fno-builtin', '-nostdinc']) +cross_env.Append(CPPPATH = ['#build/include']) +cross_env.Append(LIBPATH = ['#build/lib/libc'], LIBS = ['c']) + +cross_env.Program("date", src) + diff --git a/bin/date/date.c b/bin/date/date.c new file mode 100644 index 0000000..ad9a237 --- /dev/null +++ b/bin/date/date.c @@ -0,0 +1,11 @@ + +#include +#include + +int +main(int argc, const char *argv[]) +{ + time_t t = time(NULL); + fputs(ctime(&t), stdout); +} + diff --git a/bin/shell/shell.c b/bin/shell/shell.c index c28f65a..f675e2a 100644 --- a/bin/shell/shell.c +++ b/bin/shell/shell.c @@ -2,7 +2,6 @@ #include #include #include -#include // Castor Only #include @@ -33,11 +32,9 @@ void Cmd_Help(int argc, const char *argv[]) { printf("bkpt Trigger a kernel breakpoint\n"); - printf("date Print current date and time\n"); printf("echo Echo arguments\n"); printf("exit Exit shell\n"); printf("help Display the list of commands\n"); - printf("spawn Spawn a process\n"); } void @@ -52,39 +49,6 @@ Cmd_Echo(int argc, const char *argv[]) printf("\n"); } -void -Cmd_Date(int argc, const char *argv[]) -{ - time_t t = time(NULL); - fputs(ctime(&t), stdout); -} - -void -Cmd_Hexdump(int argc, const char *argv[]) -{ -} - -void -Cmd_Spawn(int argc, const char *argv[]) -{ - uint64_t status; - - if (argc != 2) { - fputs("Requires an argument\n", stdout); - return; - } - - printf("%s\n", argv[1]); - status = OSSpawn(argv[1]); - if (SYSCALL_ERRCODE(status) != 0) { - printf("Spawn failed: %d\n", status); - return; - } - // XXX: check errors - status = OSWait(status); - printf("Process result: %d\n", status); -} - const char *searchpath[] = { "", "/sbin/", @@ -160,14 +124,10 @@ DispatchCommand(char *buf) Cmd_Help(argc, (const char **)argv); } else if (strcmp(argv[0], "bkpt") == 0) { asm volatile("int3"); - } else if (strcmp(argv[0], "date") == 0) { - Cmd_Date(argc, (const char **)argv); } else if (strcmp(argv[0], "echo") == 0) { Cmd_Echo(argc, (const char **)argv); } else if (strcmp(argv[0], "exit") == 0) { exit(0); - } else if (strcmp(argv[0], "spawn") == 0) { - Cmd_Spawn(argc, (const char **)argv); } else if (strcmp(argv[0], "#") == 0) { // Ignore comments } else if (buf[0] == '\0') { diff --git a/release/bootdisk.manifest b/release/bootdisk.manifest index e9177c4..941175c 100644 --- a/release/bootdisk.manifest +++ b/release/bootdisk.manifest @@ -6,6 +6,7 @@ DIR / END DIR bin FILE cat build/bin/cat/cat + FILE date build/bin/date/date FILE ethdump build/bin/ethdump/ethdump FILE ethinject build/bin/ethinject/ethinject FILE ls build/bin/ls/ls