diff --git a/Makefile b/Makefile index 1a402af3..15c97de5 100644 --- a/Makefile +++ b/Makefile @@ -32,11 +32,14 @@ programs/loop/a.out: force_look programs/keyboard/a.out: force_look cd programs/keyboard; ${MAKE} a.out +programs/tsh/tsh: force_look + cd programs/tsh; ${MAKE} tsh + hdd.img: dd if=/dev/zero of=hdd.img bs=516096c count=1000 (echo n; echo p; echo 1; echo ""; echo ""; echo t; echo c; echo a; echo 1; echo w;) | sudo fdisk -u -C1000 -S63 -H16 hdd.img -thor.flp: hdd.img bootloader/stage1.bin bootloader/stage2.bin kernel/kernel.bin programs/one/a.out programs/hello/a.out programs/long/a.out programs/loop/a.out programs/longone/a.out programs/longtwo/a.out programs/keyboard/a.out +thor.flp: hdd.img bootloader/stage1.bin bootloader/stage2.bin kernel/kernel.bin programs/one/a.out programs/hello/a.out programs/long/a.out programs/loop/a.out programs/longone/a.out programs/longtwo/a.out programs/keyboard/a.out programs/tsh/tsh mkdir -p mnt/fake/ dd if=bootloader/stage1.bin of=hdd.img conv=notrunc dd if=bootloader/stage2.bin of=hdd.img seek=1 conv=notrunc @@ -51,6 +54,7 @@ thor.flp: hdd.img bootloader/stage1.bin bootloader/stage2.bin kernel/kernel.bin sudo /bin/cp programs/longtwo/a.out mnt/fake/longtwo sudo /bin/cp programs/loop/a.out mnt/fake/loop sudo /bin/cp programs/keyboard/a.out mnt/fake/keyboard + sudo /bin/cp programs/tsh/tsh mnt/fake/tsh sleep 0.1 sudo /bin/umount mnt/fake/ sudo /sbin/losetup -d /dev/loop0 diff --git a/programs/tsh/Makefile b/programs/tsh/Makefile new file mode 100644 index 00000000..cce843d7 --- /dev/null +++ b/programs/tsh/Makefile @@ -0,0 +1,15 @@ +.PHONY: default clean + +default: tsh + +include ../../cpp.mk + +%.cpp.o: src/%.cpp + $(CC) $(PROGRAM_FLAGS) -mcmodel=large $(CPP_FLAGS_64) $(WARNING_FLAGS) -c $< -o $@ + +tsh: main.cpp.o + $(CC) $(PROGRAM_LINK_FLAGS) -mcmodel=small -fPIC $(CPP_FLAGS_64) -o tsh main.cpp.o + +clean: + rm -f *.cpp.o + rm -rf tsh diff --git a/programs/tsh/src/main.cpp b/programs/tsh/src/main.cpp new file mode 100644 index 00000000..c4474d8c --- /dev/null +++ b/programs/tsh/src/main.cpp @@ -0,0 +1,27 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + +#include +#include +#include + +int main(){ + char input_buffer[64]; + + while(true){ + for(int i = 0; i < 10; ++i){ + auto c = read_input(input_buffer, 63); + input_buffer[c] = '\0'; + + if(str_equals(input_buffer, "exit")){ + exit(0); + } else { + print_line("Unknown command"); + } + } + } +} \ No newline at end of file diff --git a/programs/tsh/tsh b/programs/tsh/tsh new file mode 100755 index 00000000..4342eacf Binary files /dev/null and b/programs/tsh/tsh differ diff --git a/userlib/include/string.hpp b/userlib/include/string.hpp new file mode 100644 index 00000000..a899477c --- /dev/null +++ b/userlib/include/string.hpp @@ -0,0 +1,40 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + +#ifndef USERLIB_STRING_H +#define USERLIB_STRING_H + +int str_compare(const char *s1, const char *s2){ + while (*s1 != '\0') { + if (*s2 == '\0'){ + return 1; + } + + if (*s2 > *s1){ + return -1; + } + + if (*s1 > *s2){ + return 1; + } + + s1++; + s2++; + } + + if (*s2 != '\0'){ + return -1; + } + + return 0; +} + +bool str_equals(const char* s1, const char* s2){ + return str_compare(s1, s2) == 0; +} + +#endif