From d9467603b39ef83a1f229901f389943ce4fb73de Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Thu, 19 Mar 2026 18:02:58 -0400 Subject: [PATCH 1/9] Remove getpid app --- src/apps/CMakeLists.txt | 1 - src/apps/getpid/CMakeLists.txt | 3 --- src/apps/getpid/link.ld | 29 ----------------------------- src/apps/getpid/src/getpid.c | 7 ------- 4 files changed, 40 deletions(-) delete mode 100644 src/apps/getpid/CMakeLists.txt delete mode 100644 src/apps/getpid/link.ld delete mode 100644 src/apps/getpid/src/getpid.c diff --git a/src/apps/CMakeLists.txt b/src/apps/CMakeLists.txt index 68ddbee1..9a10d434 100644 --- a/src/apps/CMakeLists.txt +++ b/src/apps/CMakeLists.txt @@ -38,7 +38,6 @@ add_subdirectory(demo) add_subdirectory(ping) add_subdirectory(pong) add_subdirectory(shell) -add_subdirectory(getpid) message("App targets are ${APPS_TARGETS}") diff --git a/src/apps/getpid/CMakeLists.txt b/src/apps/getpid/CMakeLists.txt deleted file mode 100644 index 444d0d09..00000000 --- a/src/apps/getpid/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -set(TARGET getpid) - -add_app(${TARGET}) diff --git a/src/apps/getpid/link.ld b/src/apps/getpid/link.ld deleted file mode 100644 index 9ac34e30..00000000 --- a/src/apps/getpid/link.ld +++ /dev/null @@ -1,29 +0,0 @@ -ENTRY(__start) - -SECTIONS { - . = 0x400000; - - .text : - { - *(.text) - } - - /* Read-only data. */ - .rodata BLOCK(4K) : ALIGN(4K) - { - *(.rodata) - } - - /* Read-write data (initialized) */ - .data BLOCK(4K) : ALIGN(4K) - { - *(.data) - } - - /* Read-write data (uninitialized) and stack */ - .bss BLOCK(4K) : ALIGN(4K) - { - *(COMMON) - *(.bss) - } -} \ No newline at end of file diff --git a/src/apps/getpid/src/getpid.c b/src/apps/getpid/src/getpid.c deleted file mode 100644 index e02eadc8..00000000 --- a/src/apps/getpid/src/getpid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "libc/proc.h" -#include "libc/stdio.h" - -void main() { - int pid = getpid(); - printf("PID is %u\n"); -} From ba1113c2d520a113ed0b696ed8d536ee3a256326 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Thu, 19 Mar 2026 18:17:23 -0400 Subject: [PATCH 2/9] Don't print from cinit --- src/apps/cinit/src/cinit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/cinit/src/cinit.c b/src/apps/cinit/src/cinit.c index 2c601456..74de0dbb 100644 --- a/src/apps/cinit/src/cinit.c +++ b/src/apps/cinit/src/cinit.c @@ -4,11 +4,11 @@ extern int main(size_t argc, char ** argv); void __cinit(size_t argc, char ** argv) { - printf("c init\n"); + // printf("c init\n"); // TODO init malloc // TODO is there anything in signals or system calls to setup? // TODO do stdio handles setup here? int res = main(argc, argv); - printf("Main returned %d\n", res); + // printf("Main returned %d\n", res); proc_exit(res); } From 2d379d4f5cba312a58b471b221dfdb5422838545 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Thu, 19 Mar 2026 18:17:35 -0400 Subject: [PATCH 3/9] Replace echo command with app --- src/apps/CMakeLists.txt | 3 ++- src/apps/echo/CMakeLists.txt | 3 +++ src/apps/echo/link.ld | 29 +++++++++++++++++++++++++++++ src/apps/echo/src/echo.c | 29 +++++++++++++++++++++++++++++ src/apps/shell/src/commands.c | 25 ------------------------- 5 files changed, 63 insertions(+), 26 deletions(-) create mode 100644 src/apps/echo/CMakeLists.txt create mode 100644 src/apps/echo/link.ld create mode 100644 src/apps/echo/src/echo.c diff --git a/src/apps/CMakeLists.txt b/src/apps/CMakeLists.txt index 9a10d434..d9f4da61 100644 --- a/src/apps/CMakeLists.txt +++ b/src/apps/CMakeLists.txt @@ -33,8 +33,9 @@ add_subdirectory(cinit) # Programs loaded from disk add_subdirectory(foo) add_subdirectory(bar) -add_subdirectory(init) add_subdirectory(demo) +add_subdirectory(echo) +add_subdirectory(init) add_subdirectory(ping) add_subdirectory(pong) add_subdirectory(shell) diff --git a/src/apps/echo/CMakeLists.txt b/src/apps/echo/CMakeLists.txt new file mode 100644 index 00000000..bd1f5099 --- /dev/null +++ b/src/apps/echo/CMakeLists.txt @@ -0,0 +1,3 @@ +set(TARGET echo) + +add_app(${TARGET}) diff --git a/src/apps/echo/link.ld b/src/apps/echo/link.ld new file mode 100644 index 00000000..9ac34e30 --- /dev/null +++ b/src/apps/echo/link.ld @@ -0,0 +1,29 @@ +ENTRY(__start) + +SECTIONS { + . = 0x400000; + + .text : + { + *(.text) + } + + /* Read-only data. */ + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } + + /* Read-write data (initialized) */ + .data BLOCK(4K) : ALIGN(4K) + { + *(.data) + } + + /* Read-write data (uninitialized) and stack */ + .bss BLOCK(4K) : ALIGN(4K) + { + *(COMMON) + *(.bss) + } +} \ No newline at end of file diff --git a/src/apps/echo/src/echo.c b/src/apps/echo/src/echo.c new file mode 100644 index 00000000..8afd97a2 --- /dev/null +++ b/src/apps/echo/src/echo.c @@ -0,0 +1,29 @@ +#include +#include + +#include "libc/stdio.h" +#include "libc/string.h" + +int main(size_t argc, char ** argv) { + bool next_line = true; + if (argc > 1 && kmemcmp(argv[1], "-n", 2) == 0) { + next_line = false; + } + + size_t i = 1; + if (!next_line) { + i++; + } + for (; i < argc; i++) { + puts(argv[i]); + if (i < argc) { + putc(' '); + } + } + + if (next_line) { + putc('\n'); + } + + return 0; +} diff --git a/src/apps/shell/src/commands.c b/src/apps/shell/src/commands.c index 71d63f34..5a73cf71 100644 --- a/src/apps/shell/src/commands.c +++ b/src/apps/shell/src/commands.c @@ -8,30 +8,6 @@ #include "libc/time.h" #include "shell.h" -static int echo_cmd(size_t argc, char ** argv) { - bool next_line = true; - if (argc > 1 && kmemcmp(argv[1], "-n", 2) == 0) { - next_line = false; - } - - size_t i = 1; - if (!next_line) { - i++; - } - for (; i < argc; i++) { - puts(argv[i]); - if (i < argc) { - putc(' '); - } - } - - if (next_line) { - putc('\n'); - } - - return 0; -} - static int ls_cmd(size_t argc, char ** argv) { // dir_t dir = dir_open("/"); // if (!dir) { @@ -128,7 +104,6 @@ static int time_cmd(size_t argc, char ** argv) { } void init_commands() { - term_command_add("echo", echo_cmd); term_command_add("ls", ls_cmd); term_command_add("cat", cat_cmd); term_command_add("pid", pid_cmd); From 76438a07b32e8ff118088f24836b8906e2bed0f0 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Thu, 19 Mar 2026 18:18:56 -0400 Subject: [PATCH 4/9] Fix duplicate filename in argv from shell --- src/apps/shell/src/shell.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/apps/shell/src/shell.c b/src/apps/shell/src/shell.c index 8fb26547..c2b41711 100644 --- a/src/apps/shell/src/shell.c +++ b/src/apps/shell/src/shell.c @@ -329,7 +329,8 @@ static void exec_buff() { // No match was found else { - int pid = proc_open(argv[0], argc, argv); + // kernel adds filename at argv[0], so here it's a duplicate + int pid = proc_open(argv[0], argc - 1, &argv[1]); if (pid < 0) { printf("Unknown command '%s'\n", argv[0]); term_last_ret = 1; From f2f6191e3b0f027157e92f22f58f4e76fc12069c Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Thu, 19 Mar 2026 18:19:04 -0400 Subject: [PATCH 5/9] Remove print --- src/apps/shell/src/shell.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/apps/shell/src/shell.c b/src/apps/shell/src/shell.c index c2b41711..96cb61e3 100644 --- a/src/apps/shell/src/shell.c +++ b/src/apps/shell/src/shell.c @@ -335,9 +335,6 @@ static void exec_buff() { printf("Unknown command '%s'\n", argv[0]); term_last_ret = 1; } - else { - printf("Running command %u\n", pid); - } } // Free parsed args From baa9b3cc8a414395c7d306fd48bd4c967b0772d7 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Thu, 19 Mar 2026 18:23:42 -0400 Subject: [PATCH 6/9] Remove unused import --- src/apps/echo/src/echo.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/apps/echo/src/echo.c b/src/apps/echo/src/echo.c index 8afd97a2..b119017f 100644 --- a/src/apps/echo/src/echo.c +++ b/src/apps/echo/src/echo.c @@ -1,5 +1,4 @@ #include -#include #include "libc/stdio.h" #include "libc/string.h" From e0370a2c923153c7125de4d0b288b7c45e8c8611 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Thu, 19 Mar 2026 18:25:14 -0400 Subject: [PATCH 7/9] Replace cat command with app --- src/apps/CMakeLists.txt | 1 + src/apps/cat/CMakeLists.txt | 3 +++ src/apps/cat/link.ld | 29 +++++++++++++++++++++++++++++ src/apps/cat/src/cat.c | 21 +++++++++++++++++++++ src/apps/shell/src/commands.c | 19 ------------------- 5 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 src/apps/cat/CMakeLists.txt create mode 100644 src/apps/cat/link.ld create mode 100644 src/apps/cat/src/cat.c diff --git a/src/apps/CMakeLists.txt b/src/apps/CMakeLists.txt index d9f4da61..12cac08c 100644 --- a/src/apps/CMakeLists.txt +++ b/src/apps/CMakeLists.txt @@ -33,6 +33,7 @@ add_subdirectory(cinit) # Programs loaded from disk add_subdirectory(foo) add_subdirectory(bar) +add_subdirectory(cat) add_subdirectory(demo) add_subdirectory(echo) add_subdirectory(init) diff --git a/src/apps/cat/CMakeLists.txt b/src/apps/cat/CMakeLists.txt new file mode 100644 index 00000000..16594cfa --- /dev/null +++ b/src/apps/cat/CMakeLists.txt @@ -0,0 +1,3 @@ +set(TARGET cat) + +add_app(${TARGET}) diff --git a/src/apps/cat/link.ld b/src/apps/cat/link.ld new file mode 100644 index 00000000..9ac34e30 --- /dev/null +++ b/src/apps/cat/link.ld @@ -0,0 +1,29 @@ +ENTRY(__start) + +SECTIONS { + . = 0x400000; + + .text : + { + *(.text) + } + + /* Read-only data. */ + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } + + /* Read-write data (initialized) */ + .data BLOCK(4K) : ALIGN(4K) + { + *(.data) + } + + /* Read-write data (uninitialized) and stack */ + .bss BLOCK(4K) : ALIGN(4K) + { + *(COMMON) + *(.bss) + } +} \ No newline at end of file diff --git a/src/apps/cat/src/cat.c b/src/apps/cat/src/cat.c new file mode 100644 index 00000000..6dcd2507 --- /dev/null +++ b/src/apps/cat/src/cat.c @@ -0,0 +1,21 @@ +#include + +#include "libc/stdio.h" + +int main(size_t argc, char ** argv) { + if (argc < 2) { + printf("Usage: %s \n", argv[0]); + return -1; + } + + file_t * file = file_open(argv[1], "r"); + + char c; + while (file_read(file, 1, 1, &c)) { + putc(c); + } + + file_close(file); + + return 0; +} diff --git a/src/apps/shell/src/commands.c b/src/apps/shell/src/commands.c index 5a73cf71..764bb9d8 100644 --- a/src/apps/shell/src/commands.c +++ b/src/apps/shell/src/commands.c @@ -40,24 +40,6 @@ static int ls_cmd(size_t argc, char ** argv) { return 0; } -static int cat_cmd(size_t argc, char ** argv) { - if (argc < 2) { - printf("Usage: %s \n", argv[0]); - return -1; - } - - file_t * file = file_open(argv[1], "r"); - - char c; - while (file_read(file, 1, 1, &c)) { - putc(c); - } - - file_close(file); - - return 0; -} - static int pid_cmd(size_t argc, char ** argv) { printf("PID is %d\n", getpid()); return 0; @@ -105,7 +87,6 @@ static int time_cmd(size_t argc, char ** argv) { void init_commands() { term_command_add("ls", ls_cmd); - term_command_add("cat", cat_cmd); term_command_add("pid", pid_cmd); term_command_add("sleep", sleep_cmd); term_command_add("time", time_cmd); From a677f1bb39d0fe0f0262f98205030ff7250dd9c1 Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Thu, 19 Mar 2026 18:27:14 -0400 Subject: [PATCH 8/9] Replace sleep command with app --- src/apps/CMakeLists.txt | 1 + src/apps/shell/src/commands.c | 35 ------------------------------- src/apps/sleep/CMakeLists.txt | 3 +++ src/apps/sleep/link.ld | 29 ++++++++++++++++++++++++++ src/apps/sleep/src/sleep.c | 39 +++++++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 35 deletions(-) create mode 100644 src/apps/sleep/CMakeLists.txt create mode 100644 src/apps/sleep/link.ld create mode 100644 src/apps/sleep/src/sleep.c diff --git a/src/apps/CMakeLists.txt b/src/apps/CMakeLists.txt index 12cac08c..53985904 100644 --- a/src/apps/CMakeLists.txt +++ b/src/apps/CMakeLists.txt @@ -40,6 +40,7 @@ add_subdirectory(init) add_subdirectory(ping) add_subdirectory(pong) add_subdirectory(shell) +add_subdirectory(sleep) message("App targets are ${APPS_TARGETS}") diff --git a/src/apps/shell/src/commands.c b/src/apps/shell/src/commands.c index 764bb9d8..16725f91 100644 --- a/src/apps/shell/src/commands.c +++ b/src/apps/shell/src/commands.c @@ -45,40 +45,6 @@ static int pid_cmd(size_t argc, char ** argv) { return 0; } -static int sleep_cmd(size_t argc, char ** argv) { - if (argc < 2 || (!kstrcmp(argv[1], "-u") && argc < 3)) { - printf("Usage: %s [-u] \n", argv[0]); - puts("\nseconds must be at while number that is least 1\n"); - puts("-u use microseconds instead of seconds\n"); - return -1; - } - - if (!kstrcmp(argv[1], "-u")) { - int us = katoi(argv[2]); - if (us < 1) { - printf("Seconds must be a numer that is at least 1\n"); - return -1; - } - - printf("Sleeping for %d microseconds\n", us); - usleep(us); - } - else { - int seconds = katoi(argv[1]); - if (seconds < 1) { - printf("Seconds must be a numer that is at least 1\n"); - return -1; - } - - printf("Sleeping for %d sseconds\n", seconds); - sleep(seconds * 1000); - } - - puts("Finished sleep\n"); - - return 0; -} - static int time_cmd(size_t argc, char ** argv) { printf("The time is %u seconds\n", time()); @@ -88,6 +54,5 @@ static int time_cmd(size_t argc, char ** argv) { void init_commands() { term_command_add("ls", ls_cmd); term_command_add("pid", pid_cmd); - term_command_add("sleep", sleep_cmd); term_command_add("time", time_cmd); } diff --git a/src/apps/sleep/CMakeLists.txt b/src/apps/sleep/CMakeLists.txt new file mode 100644 index 00000000..f4d40785 --- /dev/null +++ b/src/apps/sleep/CMakeLists.txt @@ -0,0 +1,3 @@ +set(TARGET sleep) + +add_app(${TARGET}) diff --git a/src/apps/sleep/link.ld b/src/apps/sleep/link.ld new file mode 100644 index 00000000..9ac34e30 --- /dev/null +++ b/src/apps/sleep/link.ld @@ -0,0 +1,29 @@ +ENTRY(__start) + +SECTIONS { + . = 0x400000; + + .text : + { + *(.text) + } + + /* Read-only data. */ + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } + + /* Read-write data (initialized) */ + .data BLOCK(4K) : ALIGN(4K) + { + *(.data) + } + + /* Read-write data (uninitialized) and stack */ + .bss BLOCK(4K) : ALIGN(4K) + { + *(COMMON) + *(.bss) + } +} \ No newline at end of file diff --git a/src/apps/sleep/src/sleep.c b/src/apps/sleep/src/sleep.c new file mode 100644 index 00000000..c87e15ee --- /dev/null +++ b/src/apps/sleep/src/sleep.c @@ -0,0 +1,39 @@ +#include + +#include "libc/stdio.h" +#include "libc/string.h" +#include "libc/time.h" + +int main(size_t argc, char ** argv) { + if (argc < 2 || (!kstrcmp(argv[1], "-u") && argc < 3)) { + printf("Usage: %s [-u] \n", argv[0]); + puts("\nseconds must be at while number that is least 1\n"); + puts("-u use microseconds instead of seconds\n"); + return -1; + } + + if (!kstrcmp(argv[1], "-u")) { + int us = katoi(argv[2]); + if (us < 1) { + printf("Seconds must be a numer that is at least 1\n"); + return -1; + } + + printf("Sleeping for %d microseconds\n", us); + usleep(us); + } + else { + int seconds = katoi(argv[1]); + if (seconds < 1) { + printf("Seconds must be a numer that is at least 1\n"); + return -1; + } + + printf("Sleeping for %d sseconds\n", seconds); + sleep(seconds * 1000); + } + + puts("Finished sleep\n"); + + return 0; +} From b58ea394be441efd39ec81a2bf9bd4c655c83e6d Mon Sep 17 00:00:00 2001 From: Thomas Harrison Date: Thu, 19 Mar 2026 18:29:48 -0400 Subject: [PATCH 9/9] Replace time command with app --- src/apps/CMakeLists.txt | 1 + src/apps/shell/src/commands.c | 7 ------- src/apps/time/CMakeLists.txt | 3 +++ src/apps/time/link.ld | 29 +++++++++++++++++++++++++++++ src/apps/time/src/time.c | 11 +++++++++++ 5 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 src/apps/time/CMakeLists.txt create mode 100644 src/apps/time/link.ld create mode 100644 src/apps/time/src/time.c diff --git a/src/apps/CMakeLists.txt b/src/apps/CMakeLists.txt index 53985904..afbd1eb3 100644 --- a/src/apps/CMakeLists.txt +++ b/src/apps/CMakeLists.txt @@ -41,6 +41,7 @@ add_subdirectory(ping) add_subdirectory(pong) add_subdirectory(shell) add_subdirectory(sleep) +add_subdirectory(time) message("App targets are ${APPS_TARGETS}") diff --git a/src/apps/shell/src/commands.c b/src/apps/shell/src/commands.c index 16725f91..4e42a8e5 100644 --- a/src/apps/shell/src/commands.c +++ b/src/apps/shell/src/commands.c @@ -45,14 +45,7 @@ static int pid_cmd(size_t argc, char ** argv) { return 0; } -static int time_cmd(size_t argc, char ** argv) { - printf("The time is %u seconds\n", time()); - - return 0; -} - void init_commands() { term_command_add("ls", ls_cmd); term_command_add("pid", pid_cmd); - term_command_add("time", time_cmd); } diff --git a/src/apps/time/CMakeLists.txt b/src/apps/time/CMakeLists.txt new file mode 100644 index 00000000..44700299 --- /dev/null +++ b/src/apps/time/CMakeLists.txt @@ -0,0 +1,3 @@ +set(TARGET time) + +add_app(${TARGET}) diff --git a/src/apps/time/link.ld b/src/apps/time/link.ld new file mode 100644 index 00000000..9ac34e30 --- /dev/null +++ b/src/apps/time/link.ld @@ -0,0 +1,29 @@ +ENTRY(__start) + +SECTIONS { + . = 0x400000; + + .text : + { + *(.text) + } + + /* Read-only data. */ + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } + + /* Read-write data (initialized) */ + .data BLOCK(4K) : ALIGN(4K) + { + *(.data) + } + + /* Read-write data (uninitialized) and stack */ + .bss BLOCK(4K) : ALIGN(4K) + { + *(COMMON) + *(.bss) + } +} \ No newline at end of file diff --git a/src/apps/time/src/time.c b/src/apps/time/src/time.c new file mode 100644 index 00000000..494c91a4 --- /dev/null +++ b/src/apps/time/src/time.c @@ -0,0 +1,11 @@ +#include "libc/time.h" + +#include + +#include "libc/stdio.h" + +int main(size_t argc, char ** argv) { + printf("The time is %u seconds\n", time()); + + return 0; +}