mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-08-03 09:16:13 -04:00
Prepare userland shell
This commit is contained in:
parent
447083666d
commit
7be2b2596a
6
Makefile
6
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
|
||||
|
15
programs/tsh/Makefile
Normal file
15
programs/tsh/Makefile
Normal file
@ -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
|
27
programs/tsh/src/main.cpp
Normal file
27
programs/tsh/src/main.cpp
Normal file
@ -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 <print.hpp>
|
||||
#include <system.hpp>
|
||||
#include <string.hpp>
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
programs/tsh/tsh
Executable file
BIN
programs/tsh/tsh
Executable file
Binary file not shown.
40
userlib/include/string.hpp
Normal file
40
userlib/include/string.hpp
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user