diff --git a/comp_run_iso.sh b/comp_run_iso.sh new file mode 100755 index 000000000..8eae3139a --- /dev/null +++ b/comp_run_iso.sh @@ -0,0 +1,14 @@ +back=$(pwd) + +cd progs +cat files | cpio -H newc -o > init.cpio +cd $back + +rm -rf linux-*/arch/x86/boot/image.iso +cd linux-* +#make isoimage FDARGS="initrd=/init.cpio" FDINITRD="../progs/init.cpio" +# \/ \/ Turn off system messages (very annoying) +make isoimage FDARGS="initrd=/init.cpio loglevel=0 quiet" FDINITRD="../progs/init.cpio" +qemu-system-x86_64 -cdrom arch/x86/boot/image.iso + +cd $back diff --git a/instructions.md b/instructions.md index 342b67856..03372605f 100644 --- a/instructions.md +++ b/instructions.md @@ -46,4 +46,4 @@ make -j 4 make isoimage FDARGS="initrd=/init.cpio" FDINITRD="../progs/init.cpio" # Запуск ISO # -smp 1 - одно ядро, иначе сбивается время -qemu-system-x86_64 -cdrom arch/x86/boot/image.iso -smp 1 +qemu-system-x86_64 -cdrom arch/x86/boot/image.iso diff --git a/progs/echo b/progs/echo new file mode 100755 index 000000000..fd969455c Binary files /dev/null and b/progs/echo differ diff --git a/progs/files b/progs/files index b1b716105..25969bafb 100644 --- a/progs/files +++ b/progs/files @@ -1 +1,3 @@ init +ls +echo diff --git a/progs/init b/progs/init index da8cda7d8..93a132325 100755 Binary files a/progs/init and b/progs/init differ diff --git a/progs/init.cpio b/progs/init.cpio index e93bf7e8d..421da11d0 100644 Binary files a/progs/init.cpio and b/progs/init.cpio differ diff --git a/progs/ls b/progs/ls new file mode 100755 index 000000000..df4e02de6 Binary files /dev/null and b/progs/ls differ diff --git a/progs/shell b/progs/shell new file mode 100755 index 000000000..43c994378 Binary files /dev/null and b/progs/shell differ diff --git a/progs/shell.c b/progs/shell.c deleted file mode 100644 index 3ff558619..000000000 --- a/progs/shell.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include - -int real_waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options, void*); - -int main() -{ - char command[255]; - for (;;) { - write(1, "# ", 2); - int count = read(0, command, 255); - // /bin/ls\n -> /bin/ls\0 - command[count - 1] = 0; - pid_t fork_result = fork(); - if (fork_result == 0) { - execve(command, 0, 0); - break; - } else { - // wait - // - siginfo_t info; - real_waitid(P_ALL, 0, &info, WEXITED, 0); - } - } - - _exit(0); -} diff --git a/progs/shell.o b/progs/shell.o deleted file mode 100644 index b6474e95c..000000000 Binary files a/progs/shell.o and /dev/null differ diff --git a/progs/src/echo/build.sh b/progs/src/echo/build.sh new file mode 100755 index 000000000..65a91f9a7 --- /dev/null +++ b/progs/src/echo/build.sh @@ -0,0 +1,2 @@ +gcc -static echo.c -o echo +cp echo ../../echo diff --git a/progs/src/echo/echo b/progs/src/echo/echo new file mode 100755 index 000000000..fd969455c Binary files /dev/null and b/progs/src/echo/echo differ diff --git a/progs/src/echo/echo.c b/progs/src/echo/echo.c new file mode 100644 index 000000000..a6067596d --- /dev/null +++ b/progs/src/echo/echo.c @@ -0,0 +1,12 @@ +#include + +int main(int argc, char* argv[]) { + if (argc >= 2) { + for (int i = 1; i < argc; i++) { + printf("%s ", argv[i]); + } + printf("\n"); + } + + return 0; +} diff --git a/progs/src/echo/local_run.sh b/progs/src/echo/local_run.sh new file mode 100755 index 000000000..242d9b114 --- /dev/null +++ b/progs/src/echo/local_run.sh @@ -0,0 +1,2 @@ +gcc -static echo.c -o echo +./echo test diff --git a/progs/src/ls/build.sh b/progs/src/ls/build.sh new file mode 100755 index 000000000..0260a0da0 --- /dev/null +++ b/progs/src/ls/build.sh @@ -0,0 +1,2 @@ +gcc -static ls.c -o ls +cp ls ../../ls diff --git a/progs/src/ls/local_run.sh b/progs/src/ls/local_run.sh new file mode 100755 index 000000000..55fc4c8d2 --- /dev/null +++ b/progs/src/ls/local_run.sh @@ -0,0 +1,2 @@ +gcc -static ls.c -o ls +./ls diff --git a/progs/src/ls/ls b/progs/src/ls/ls new file mode 100755 index 000000000..df4e02de6 Binary files /dev/null and b/progs/src/ls/ls differ diff --git a/progs/src/ls/ls.c b/progs/src/ls/ls.c new file mode 100644 index 000000000..fc7234ec5 --- /dev/null +++ b/progs/src/ls/ls.c @@ -0,0 +1,29 @@ +#include +#include +#include + +int main(int argc, char* argv[]) { + + DIR *dir; + struct dirent *entry; + if (argc == 2) { + const char *path = argv[1]; + dir = opendir(path); + } else { + const char *path = "."; + dir = opendir(path); + } + if (dir == NULL) { + printf("No such file or directory\n"); + return 1; + } + + while ((entry = readdir(dir)) != NULL) { + if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) { + printf("%s\n", entry->d_name); + } + } + + closedir(dir); + return 0; +} diff --git a/progs/src/shell/build.sh b/progs/src/shell/build.sh new file mode 100755 index 000000000..27971e6c4 --- /dev/null +++ b/progs/src/shell/build.sh @@ -0,0 +1,2 @@ +gcc -static shell.c -o shell +cp shell ../../init diff --git a/progs/src/shell/local_run.sh b/progs/src/shell/local_run.sh new file mode 100755 index 000000000..af14d35b6 --- /dev/null +++ b/progs/src/shell/local_run.sh @@ -0,0 +1,2 @@ +gcc -static shell.c -o shell +./shell diff --git a/progs/src/shell/shell b/progs/src/shell/shell new file mode 100755 index 000000000..93a132325 Binary files /dev/null and b/progs/src/shell/shell differ diff --git a/progs/src/shell/shell.c b/progs/src/shell/shell.c new file mode 100644 index 000000000..ada6cf27d --- /dev/null +++ b/progs/src/shell/shell.c @@ -0,0 +1,33 @@ +#include +#include +#include + +int main() +{ + char command[255]; + for (;;) { + write(1, "# ", 2); + int count = read(0, command, 255); + command[count - 1] = 0; + + char *argArray[100]; + char *token = strtok(command, " "); + int argCount = 0; + while (token != NULL) { + argArray[argCount++] = token; + token = strtok(NULL, " "); + } + argArray[argCount] = NULL; + + pid_t fork_result = fork(); + if (fork_result == 0) { + execve(argArray[0], argArray, NULL); + _exit(1); + } else { + int status; + waitpid(fork_result, &status, 0); + } + } + + _exit(0); +} diff --git a/progs/src/shell/shell.o b/progs/src/shell/shell.o new file mode 100644 index 000000000..e3bff099c Binary files /dev/null and b/progs/src/shell/shell.o differ diff --git a/progs/sys b/progs/sys deleted file mode 100644 index 86de9967c..000000000 Binary files a/progs/sys and /dev/null differ diff --git a/progs/sys.S b/progs/sys.S deleted file mode 100644 index 1cf4e1da8..000000000 --- a/progs/sys.S +++ /dev/null @@ -1,39 +0,0 @@ -.intel_syntax noprefix - -.global write -.global read -.global fork -.global execve -.global real_waitid -.global _exit - -write: -mov rax, 1 -syscall -ret - -read: -mov rax, 0 -syscall -ret - -execve: -mov rax, 59 -syscall -ret - - -fork: -mov rax, 57 -syscall -ret - -real_waitid: -mov rax, 247 -mov r10, rcx -syscall -ret - -_exit: -mov rax, 60 -syscall