diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | .vscode/c_cpp_properties.json | 16 | ||||
-rw-r--r-- | makefile | 28 | ||||
-rw-r--r-- | progs/shel/shel.c | 42 | ||||
-rw-r--r-- | progs/touch/touch.c | 13 | ||||
-rw-r--r-- | sys.s | 78 |
6 files changed, 179 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5451a03 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +kernel + diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..4039bef --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,16 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000..990196a --- /dev/null +++ b/makefile @@ -0,0 +1,28 @@ +.PHONY: all build_asmlib build_init build_shell build_fdmaker build_devscan + +PROGS := $(wildcard progs/*) +SBIN := $(wildcard sbin/*) + +all: build_asmlib build_init build_shell build_fdmaker build_devscan + @for dir in $(PROGS); do \ + if [ -d $$dir ]; then \ + name=$$(basename $$dir); \ + echo "Processing $$name $$dir/$$name.c"; \ + rm build/$$name; \ + gcc -o ./build/$$name $$dir/$$name.c -z noexecstack -static -march=x86-64; \ + fi \ + done + @for dir in $(SBIN); do \ + if [ -d $$dir ]; then \ + name=$$(basename $$dir); \ + echo "Processing $$name $$dir/$$name.c"; \ + rm build/$$name; \ + gcc -o ./build/$$name $$dir/$$name.c -z noexecstack -static -march=x86-64; \ + fi \ + done + +# CFLAGS = -Dlint -I../../sys/arch/aarch64/include -I../../sys/meeem/ -I../../sys/ -I../../lib/libutil/compat/ + +build_asmlib: + as sys.s + @echo asm built diff --git a/progs/shel/shel.c b/progs/shel/shel.c new file mode 100644 index 0000000..f375250 --- /dev/null +++ b/progs/shel/shel.c @@ -0,0 +1,42 @@ +#include <unistd.h> +#include <stdlib.h> +#include <sys/wait.h> +#include <stdbool.h> +#include <string.h> + +void parseInput(char *input, char *command, char *argv) { + bool reachedArgv = false; + char arg[32] = {0}; + int idx = 0; + int argvIdx = 1; + + for (int i = 0; i < sizeof(input); i++) + { + if (reachedArgv) { + arg[idx] = input[i]; + idx++; + continue; + } + if (input[i] == ' ') { + arg[idx] == '\0'; + strcpy(command, arg); + reachedArgv = true; + memset(arg, 0, sizeof(arg)); + idx++; + continue; + } + arg[idx] = input[i]; + idx++; + } + +} + +int main() { + char input[255] = {0}; + char command[128] = {0}; + char *argv[32] = {0}; + char *env[32] = {"PATH=/bin"}; + char path[128] = "/"; + + parseInput(input, command, argv); +} \ No newline at end of file diff --git a/progs/touch/touch.c b/progs/touch/touch.c new file mode 100644 index 0000000..815dae3 --- /dev/null +++ b/progs/touch/touch.c @@ -0,0 +1,13 @@ +#include <unistd.h> +#include <stdlib.h> +#include <fcntl.h> +#include <sys/stat.h> + +int main(int argc, char *argv[]) { + if (!argv[1]) { + write(1, "you IDIOT, you forgot to include the file name, MORON\n", 55); + exit(1); + } + int fd2 = open(argv[1], O_RDWR | O_CREAT, S_IRUSR | S_IRGRP | S_IROTH); + exit(0); +} \ No newline at end of file diff --git a/sys.s b/sys.s new file mode 100644 index 0000000..9a72e16 --- /dev/null +++ b/sys.s @@ -0,0 +1,78 @@ +.intel_syntax noprefix + .global write + .global read + .global open + .global close + .global fork + .global real_waitid + .global execve + .global pause + .global mknod + .global dup2 + .global chdir + .global mount + .global exit + + write: + mov rax, 1 + syscall + ret + + read: + mov rax, 0 # syscall number for read + mov rdi, rdi # file descriptor (already in rdi) + mov rsi, rsi # buffer pointer (already in rsi) + mov rdx, rdx # size (already in rdx) + syscall + ret + + open: + mov rax, 2 + syscall + ret + + close: + mov rax, 3 + syscall + ret + + fork: + mov rax, 57 + syscall + ret + + real_waitid: + mov rax, 247 + mov r10, rcx + syscall + ret + + execve: + mov rax, 59 + syscall + + pause: + mov rax, 34 + syscall + + mknod: + mov rax, 133 + syscall + + dup2: + mov rax, 33 + syscall + + chdir: + mov rax, 80 + syscall + + mount: + mov rax, 165 + mov r10, rcx + syscall + + exit: + mov rax, 60 + syscall + ret |