From 8826ed6396c15697c2178c1d98b89c35b8ff7814 Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Tue, 25 Nov 2014 22:24:54 -0800 Subject: [PATCH] Exposing SystemSpawn in libc and adding skeleton for basic shell. --- SConstruct | 2 ++ bin/shell/SConscript | 21 +++++++++++++++++++++ bin/shell/shell.c | 15 +++++++++++++++ include/errno.h | 1 + include/syscall.h | 1 + lib/libc/syscall.c | 6 ++++++ release/bootdisk.manifest | 3 +++ 7 files changed, 49 insertions(+) create mode 100644 bin/shell/SConscript create mode 100644 bin/shell/shell.c diff --git a/SConstruct b/SConstruct index 496590f..1b9ecb5 100644 --- a/SConstruct +++ b/SConstruct @@ -161,6 +161,7 @@ CopyTree('build/include/machine', 'sys/' + env['ARCH'] + '/include', env) # Build Targets SConscript('sys/SConscript', variant_dir='build/sys') SConscript('lib/libc/SConscript', variant_dir='build/lib/libc') +SConscript('bin/shell/SConscript', variant_dir='build/bin/shell') SConscript('sbin/init/SConscript', variant_dir='build/sbin/init') # Build Tools @@ -180,6 +181,7 @@ if env["BOOTDISK"] == "1": env.Append(BUILDERS = {'BuildImage' : newfs}) bootdisk = env.BuildImage('#build/bootdisk.img', '#release/bootdisk.manifest') Depends(bootdisk, "#build/tools/newfs_o2fs/newfs_o2fs") + Depends(bootdisk, "#build/bin/shell/shell") Depends(bootdisk, "#build/sbin/init/init") Depends(bootdisk, "#build/sys/castor") env.Alias('bootdisk', '#build/bootdisk.img') diff --git a/bin/shell/SConscript b/bin/shell/SConscript new file mode 100644 index 0000000..212ebf0 --- /dev/null +++ b/bin/shell/SConscript @@ -0,0 +1,21 @@ +import sys + +Import('env') + +init_env = env.Clone() + +src = [ ] + +src_common = [ + "shell.c" +] + +src.append(src_common) + +init_env.Append(LINKFLAGS = ['-nostdlib']) +init_env.Append(CPPFLAGS = ['-nostdinc']) +init_env.Append(CPPPATH = ['#build/include']) +init_env.Append(LIBPATH = ['#build/lib/libc'], LIBS = ['c']) + +init_env.Program("shell", src) + diff --git a/bin/shell/shell.c b/bin/shell/shell.c new file mode 100644 index 0000000..9475cef --- /dev/null +++ b/bin/shell/shell.c @@ -0,0 +1,15 @@ + +#include + +int +main(int argc, const char *argv[]) +{ + char buf[256]; + + fputs("Shell\n", stdout); + while (1) { + fputs("> ", stdout); + fgets(buf, sizeof(buf), stdin); + } +} + diff --git a/include/errno.h b/include/errno.h index b59b6f9..d3d5330 100644 --- a/include/errno.h +++ b/include/errno.h @@ -6,6 +6,7 @@ #define EBADF 2 #define EINVAL 3 #define EFAULT 4 +#define ENOMEM 5 #endif /* __ERRNO_H__ */ diff --git a/include/syscall.h b/include/syscall.h index afbbd36..a2e636d 100644 --- a/include/syscall.h +++ b/include/syscall.h @@ -5,6 +5,7 @@ uint64_t SystemTime(); void SystemExit(int status); uint64_t SystemGetPID(); +uint64_t SystemSpawn(const char *path); // Memory void *SystemMemMap(void *addr, uint64_t len, int flags); diff --git a/lib/libc/syscall.c b/lib/libc/syscall.c index a39c097..09dce04 100644 --- a/lib/libc/syscall.c +++ b/lib/libc/syscall.c @@ -25,6 +25,12 @@ SystemGetPID() return syscall(SYSCALL_GETPID); } +uint64_t +SystemSpawn(const char *path) +{ + return syscall(SYSCALL_SPAWN, path); +} + void * SystemMemMap(void *addr, uint64_t len, int flags) { diff --git a/release/bootdisk.manifest b/release/bootdisk.manifest index 4d2453b..cb37d8b 100644 --- a/release/bootdisk.manifest +++ b/release/bootdisk.manifest @@ -4,6 +4,9 @@ DIR / END DIR dev END + DIR bin + FILE shell build/bin/shell/shell + END DIR sbin FILE init build/sbin/init/init END