diff options
37 files changed, 20 insertions, 568 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ff06f04..843493e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ set(CMAKE_ASM_LINK_EXECUTABLE "<CMAKE_LINKER> ${CMAKE_EXE_LINKER_FLAGS} <OBJECTS # Recursive sources file(GLOB_RECURSE kernel_sources src/kernel/*.c src/kernel/*.asm) file(GLOB_RECURSE resources_sources src/resources/*.c) -file(GLOB_RECURSE user_sources src/userspace/*.c src/userspace/*.asm) +file(GLOB_RECURSE user_sources src/userspace/programs/*.c src/userspace/libc/*.c) # KERNEL add_executable(kernel ${kernel_sources}) @@ -53,9 +53,9 @@ add_custom_command( # USERSPACE add_executable(user ${user_sources}) -target_include_directories(user PUBLIC "src/userspace/") -set_target_properties(user PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/user.o") -target_link_libraries(user PRIVATE "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/userspace/linker.ld") +target_include_directories(user PUBLIC "src/userspace/libc/") +set_target_properties(user PROPERTIES OUTPUT_NAME "${CMAKE_CURRENT_SOURCE_DIR}/build/sh.o") +target_link_libraries(user PRIVATE "-T ${CMAKE_CURRENT_SOURCE_DIR}/src/userspace/linker.ld -emain") # Dependencies add_dependencies(kernel resources user) @@ -120,7 +120,7 @@ make_build() { mkdir -p ./mnt/usr/ mkdir -p ./mnt/bin/ cp ./build/font.bin ./mnt/bin/font - cp ./build/user.o ./mnt/bin/user + cp ./build/sh.o ./mnt/bin/sh echo "Hello world, ext2!" | tee -a ./mnt/etc/test /usr/local/bin/genext2fs -B 4096 -d mnt -U -N 4096 -b 65536 ./build/disk.img rm -r mnt/ diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 3461913..1b34a73 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -68,7 +68,7 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address, uint32_t esp) printf("%s", read_file("/etc/test")); syscalls_install(); - struct process *proc = elf_load("/bin/user"); + struct process *proc = elf_load("/bin/sh"); if (proc) { proc->stdin = NULL; proc->stdout = NULL; @@ -79,4 +79,4 @@ void kernel_main(uint32_t magic, uint32_t multiboot_address, uint32_t esp) log("Okidoko!"); halt_loop(); // asm ("div %0" :: "r"(0)); // Exception testing x/0 -}
\ No newline at end of file +} diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c index 1454198..f883f2e 100644 --- a/src/kernel/syscall/syscall.c +++ b/src/kernel/syscall/syscall.c @@ -35,4 +35,4 @@ void syscall_handler(struct regs *r) void syscalls_install() { isr_install_handler(0x80, syscall_handler); -}
\ No newline at end of file +} diff --git a/src/userspace/graphics/framebuffer.c b/src/userspace/graphics/framebuffer.c deleted file mode 100644 index 9994075..0000000 --- a/src/userspace/graphics/framebuffer.c +++ /dev/null @@ -1,46 +0,0 @@ -#include <syscall.h> -#include <graphics/graphics.h> - -unsigned char *fb; -int vbe_bpl = 4; -int vbe_pitch = 10240; -int vbe_height = 1600; -int vbe_width = 2560; - -void vesa_draw_rectangle(int x1, int y1, int x2, int y2, const uint32_t color[3]) -{ - int pos1 = x1 * vbe_bpl + y1 * vbe_pitch; - char *draw = (char *)&fb[pos1]; - for (int i = 0; i <= y2 - y1; i++) { - for (int j = 0; j <= x2 - x1; j++) { - draw[vbe_bpl * j] = color[2]; - draw[vbe_bpl * j + 1] = color[1]; - draw[vbe_bpl * j + 2] = color[0]; - } - draw += vbe_pitch; - } -} - -void vesa_set_pixel(uint16_t x, uint16_t y, const uint32_t color[3]) -{ - unsigned pos = x * vbe_bpl + y * vbe_pitch; - char *draw = (char *)&fb[pos]; - draw[pos] = color[2]; - draw[pos + 1] = color[1]; - draw[pos + 2] = color[0]; -} - -void vesa_clear() -{ - uint32_t color[3] = { 0, 0, 0 }; - vesa_draw_rectangle(0, 0, vbe_width - 1, vbe_height - 1, color); -} - -void init_framebuffer() -{ - struct userspace_pointers *pointers = (struct userspace_pointers *)syscall_get_pointers(); - fb = (unsigned char *)0xfd000000; - - uint32_t color[3] = { 0xff, 0x00, 0x00 }; - vesa_set_pixel(0, 0, color); -}
\ No newline at end of file diff --git a/src/userspace/graphics/graphics.h b/src/userspace/graphics/graphics.h deleted file mode 100644 index 0e3d5be..0000000 --- a/src/userspace/graphics/graphics.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MELVIX_GRAPHICS_H -#define MELVIX_GRAPHICS_H - -#include <stdint.h> - -struct font { - uint16_t font_32[758][32]; - uint16_t font_24[758][24]; - uint8_t font_16[758][16]; - uint16_t cursor[19]; -}; - -struct userspace_pointers { - unsigned char *fb; - struct font *font; -}; - -void init_framebuffer(); - -#endif
\ No newline at end of file diff --git a/src/userspace/syscall.c b/src/userspace/libc/syscall.c index 9462b10..c147703 100644 --- a/src/userspace/syscall.c +++ b/src/userspace/libc/syscall.c @@ -17,4 +17,4 @@ DEFN_SYSCALL0(get_pointers, 5); DEFN_SYSCALL1(alloc, 6, uint32_t); -DEFN_SYSCALL1(free, 7, uint32_t);
\ No newline at end of file +DEFN_SYSCALL1(free, 7, uint32_t); diff --git a/src/userspace/syscall.h b/src/userspace/libc/syscall.h index 9f5bdb0..7dfd28d 100644 --- a/src/userspace/syscall.h +++ b/src/userspace/libc/syscall.h @@ -84,4 +84,4 @@ DECL_SYSCALL1(alloc, uint32_t); DECL_SYSCALL1(free, uint32_t); -#endif
\ No newline at end of file +#endif diff --git a/src/userspace/main.c b/src/userspace/main.c deleted file mode 100644 index 4a8ff33..0000000 --- a/src/userspace/main.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <syscall.h> -#include <mlibc/stdlib.h> - -void main() -{ - syscall_halt(); - // As char[]: 0xC105BFD6 - // As const char *: 0x8048B20 - - /* char test[] = "banane"; */ - /* syscall_write(test); */ - /* syscall_halt(); */ -}
\ No newline at end of file diff --git a/src/userspace/mlibc/math.h b/src/userspace/mlibc/math.h deleted file mode 100644 index 57877ad..0000000 --- a/src/userspace/mlibc/math.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MELVIX_MATH_H -#define MELVIX_MATH_H - -int pow(int base, int exp); - -#endif
\ No newline at end of file diff --git a/src/userspace/mlibc/math/pow.c b/src/userspace/mlibc/math/pow.c deleted file mode 100644 index 5cdcfa5..0000000 --- a/src/userspace/mlibc/math/pow.c +++ /dev/null @@ -1,13 +0,0 @@ -int pow(int base, int exp) -{ - if (exp < 0) - return 0; - - if (!exp) - return 1; - - int ret = base; - for (int i = 1; i < exp; i++) - ret *= base; - return ret; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/stdio.h b/src/userspace/mlibc/stdio.h deleted file mode 100644 index b44a9b7..0000000 --- a/src/userspace/mlibc/stdio.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef MELVIX_STDIO_H -#define MELVIX_STDIO_H - -#include <stdarg.h> - -char getch(); - -char *readline(); - -void writec(char c); - -void vprintf(const char *format, va_list args); - -void printf(const char *format, ...); - -#endif
\ No newline at end of file diff --git a/src/userspace/mlibc/stdio/getch.c b/src/userspace/mlibc/stdio/getch.c deleted file mode 100644 index 908a871..0000000 --- a/src/userspace/mlibc/stdio/getch.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <syscall.h> - -char getch() -{ - return (char)syscall_readc(); -}
\ No newline at end of file diff --git a/src/userspace/mlibc/stdio/printf.c b/src/userspace/mlibc/stdio/printf.c deleted file mode 100644 index 5a50f8d..0000000 --- a/src/userspace/mlibc/stdio/printf.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdarg.h> -#include <mlibc/stdio.h> - -void printf(const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - vprintf(fmt, args); - va_end(args); -}
\ No newline at end of file diff --git a/src/userspace/mlibc/stdio/readline.c b/src/userspace/mlibc/stdio/readline.c deleted file mode 100644 index b59545b..0000000 --- a/src/userspace/mlibc/stdio/readline.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <mlibc/stdlib.h> -#include <mlibc/stdio.h> - -char *readline() -{ - char *ret = malloc(256); - char buf = 0; - while (buf != '\n') { - buf = getch(); - writec(buf); - strcpy(ret, &buf); - } - return ret; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/stdio/vprintf.c b/src/userspace/mlibc/stdio/vprintf.c deleted file mode 100644 index 0f5ae68..0000000 --- a/src/userspace/mlibc/stdio/vprintf.c +++ /dev/null @@ -1,52 +0,0 @@ -#include <stdarg.h> -#include <stdint.h> -#include <mlibc/stdio.h> -#include <mlibc/stdlib.h> - -void _writes(const char *data) -{ - for (size_t i = 0; i < strlen(data); i++) - writec(data[i]); -} - -void vprintf(const char *fmt, va_list args) -{ - uint8_t readyToFormat = 0; - - char buff = 0; - - for (; *fmt; fmt++) { - if (readyToFormat) { - if (*fmt == '%') { - writec('%'); - readyToFormat = 0; - continue; - } - - buff = *fmt; - if (buff == 's') { - const char *str = va_arg(args, const char *); - _writes(str); - readyToFormat = 0; - } else if (buff == 'x') { - char *p = htoa((uint32_t)va_arg(args, int)); - _writes(p); - free(p); - readyToFormat = 0; - } else if (buff == 'd') { - char *p = itoa(va_arg(args, int)); - _writes(p); - free(p); - readyToFormat = 0; - } else if (buff == 'c') { - writec((char)va_arg(args, int)); - readyToFormat = 0; - } - } else { - if (*fmt == '%') - readyToFormat = 1; - else - writec(*fmt); - } - } -}
\ No newline at end of file diff --git a/src/userspace/mlibc/stdio/writec.c b/src/userspace/mlibc/stdio/writec.c deleted file mode 100644 index 1f918b6..0000000 --- a/src/userspace/mlibc/stdio/writec.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <syscall.h> - -void writec(char c) -{ - syscall_writec(c); -}
\ No newline at end of file diff --git a/src/userspace/mlibc/stdlib.h b/src/userspace/mlibc/stdlib.h deleted file mode 100644 index 3ccdec2..0000000 --- a/src/userspace/mlibc/stdlib.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef MELVIX_STDLIB_H -#define MELVIX_STDLIB_H - -#include <stdint.h> - -#ifndef MELVIX_ALLOC_H - -#include <mlibc/stdlib/liballoc.h> - -#endif - -#ifndef MELVIX_STRING_H - -#include <mlibc/string.h> - -#endif - -char *itoa(int n); - -int atoi(char *str); - -char *htoa(uint32_t n); - -int htoi(char *str); - -#endif
\ No newline at end of file diff --git a/src/userspace/mlibc/stdlib/atoi.c b/src/userspace/mlibc/stdlib/atoi.c deleted file mode 100644 index f1c3755..0000000 --- a/src/userspace/mlibc/stdlib/atoi.c +++ /dev/null @@ -1,28 +0,0 @@ -#include <mlibc/math.h> -#include <stddef.h> -#include <stdint.h> -#include <mlibc/stdlib.h> - -int atoi(char *str) -{ - size_t s_str = strlen(str); - if (!s_str) - return 0; - - uint8_t negative = 0; - if (str[0] == '-') - negative = 1; - - size_t i = 0; - if (negative) - i++; - - int ret = 0; - for (; i < s_str; i++) { - ret += (str[i] - '0') * pow(10, (s_str - i) - 1); - } - - if (negative) - ret *= -1; - return ret; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/stdlib/htoa.c b/src/userspace/mlibc/stdlib/htoa.c deleted file mode 100644 index 42cc71c..0000000 --- a/src/userspace/mlibc/stdlib/htoa.c +++ /dev/null @@ -1,32 +0,0 @@ -#include <stdint.h> -#include <mlibc/stdlib.h> -#include <mlibc/stdlib.h> - -static const char HTOA_TABLE[] = "0123456789ABCDEF"; - -char *htoa(uint32_t n) -{ - char *ret = 0; - //kmalloc(10); - - int i = 0; - while (n) { - ret[i++] = HTOA_TABLE[n & 0xF]; - n >>= 4; - } - - if (!i) { - ret[0] = '0'; - i++; - } - - for (; i <= 9; i++) - ret[i] = 0; - - char *aux = strdup(ret); - // kfree(ret); - ret = aux; - - strinv(ret); - return ret; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/stdlib/htoi.c b/src/userspace/mlibc/stdlib/htoi.c deleted file mode 100644 index 69149d6..0000000 --- a/src/userspace/mlibc/stdlib/htoi.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <stddef.h> -#include <mlibc/math.h> -#include <mlibc/stdlib.h> - -int htoi(char *str) -{ - size_t s_str = strlen(str); - - size_t i = 0; - int ret = 0; - for (; i < s_str; i++) { - char c = str[i]; - int aux = 0; - if (c >= '0' && c <= '9') - aux = c - '0'; - else if (c >= 'A' && c <= 'F') - aux = (c - 'A') + 10; - - ret += aux * pow(16, (s_str - i) - 1); - } - - return ret; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/stdlib/itoa.c b/src/userspace/mlibc/stdlib/itoa.c deleted file mode 100644 index 6db7539..0000000 --- a/src/userspace/mlibc/stdlib/itoa.c +++ /dev/null @@ -1,48 +0,0 @@ -#include <stdint.h> -#include <mlibc/math.h> -#include <mlibc/stdlib.h> - -static const char ITOA_TABLE[] = "0123456789"; - -char *itoa(int n) -{ - //if (paging_enabled == 0) - // return "0"; // kmalloc isn't available - - if (!n) { - char *ret = 0; - //kmalloc(2); - ret[0] = '0'; - ret[1] = 0; - return ret; - } - uint8_t negative = (uint8_t)(n < 0); - if (negative) - n *= -1; - - int sz; - for (sz = 0; n % pow(10, sz) != n; sz++) { - } - - char *ret = 0; - //kmalloc(sz + 1); - - for (int i = 0; i < sz; i++) { - int digit = (n % pow(10, i + 1)) / pow(10, i); - ret[i] = ITOA_TABLE[digit]; - } - ret[sz] = 0; - - if (negative) { - char *aux = 0; - //kmalloc(sz + 2); - strcpy(aux, ret); - aux[sz] = '-'; - aux[sz + 1] = 0; - // kfree(ret); - ret = aux; - } - - strinv(ret); - return ret; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/stdlib/liballoc.c b/src/userspace/mlibc/stdlib/liballoc.c deleted file mode 100644 index e57a5e2..0000000 --- a/src/userspace/mlibc/stdlib/liballoc.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stddef.h> -#include <syscall.h> - -void *malloc(size_t count) -{ - return (void *)syscall_alloc(count); -} - -void free(void *ptr) -{ - syscall_free((uint32_t)ptr); -}
\ No newline at end of file diff --git a/src/userspace/mlibc/stdlib/liballoc.h b/src/userspace/mlibc/stdlib/liballoc.h deleted file mode 100644 index 64b7cce..0000000 --- a/src/userspace/mlibc/stdlib/liballoc.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef MELVIX_ALLOC_H -#define MELVIX_ALLOC_H - -#include <stddef.h> - -void *malloc(size_t); - -void free(void *); - -#endif
\ No newline at end of file diff --git a/src/userspace/mlibc/string.h b/src/userspace/mlibc/string.h deleted file mode 100644 index ad0858d..0000000 --- a/src/userspace/mlibc/string.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef MELVIX_STRING_H -#define MELVIX_STRING_H - -#include <stddef.h> - -size_t strlen(const char *str); - -void strcpy(char *dest, const char *orig); - -void strdisp(char *str, int n); - -void strcat(char *dest, const char *orig); - -void strcati(char *dest, const char *orig); - -char strcmp(const char *a, const char *b); - -char *strdup(const char *orig); - -void strinv(char *str); - -void *memcpy(void *dest, const void *src, size_t count); - -void *memset(void *dest, char val, size_t count); - -int memcmp(const void *a_ptr, const void *b_ptr, size_t size); - -#endif
\ No newline at end of file diff --git a/src/userspace/mlibc/string/memcmp.c b/src/userspace/mlibc/string/memcmp.c deleted file mode 100644 index f1f1e3f..0000000 --- a/src/userspace/mlibc/string/memcmp.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stddef.h> - -int memcmp(const void *a_ptr, const void *b_ptr, size_t size) -{ - const unsigned char *a = (const unsigned char *)a_ptr; - const unsigned char *b = (const unsigned char *)b_ptr; - for (size_t i = 0; i < size; i++) { - if (a[i] < b[i]) - return -1; - else if (b[i] < a[i]) - return 1; - } - return 0; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/string/memcpy.c b/src/userspace/mlibc/string/memcpy.c deleted file mode 100644 index eec798b..0000000 --- a/src/userspace/mlibc/string/memcpy.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stddef.h> - -void *memcpy(void *dest, const void *src, size_t count) -{ - const char *sp = (const char *)src; - char *dp = (char *)dest; - for (; count != 0; count--) - *dp++ = *sp++; - return dest; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/string/memset.c b/src/userspace/mlibc/string/memset.c deleted file mode 100644 index 1d9bec1..0000000 --- a/src/userspace/mlibc/string/memset.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stddef.h> - -void *memset(void *dest, char val, size_t count) -{ - char *temp = (char *)dest; - for (; count != 0; count--) - *temp++ = val; - return dest; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/string/strcat.c b/src/userspace/mlibc/string/strcat.c deleted file mode 100644 index 0374e6c..0000000 --- a/src/userspace/mlibc/string/strcat.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <mlibc/stdlib.h> - -void strcat(char *dest, const char *orig) -{ - size_t s_dest = strlen(dest); - size_t s_orig = strlen(orig); - - for (size_t i = 0; i < s_orig; i++) - dest[s_dest + i] = orig[i]; - dest[s_dest + s_orig] = 0; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/string/strcati.c b/src/userspace/mlibc/string/strcati.c deleted file mode 100644 index be39b51..0000000 --- a/src/userspace/mlibc/string/strcati.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <mlibc/stdlib.h> - -void strcati(char *dest, const char *orig) -{ - size_t s_orig = strlen(orig); - strdisp(dest, (int)s_orig); - for (size_t i = 0; i < s_orig; i++) - dest[i] = orig[i]; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/string/strcmp.c b/src/userspace/mlibc/string/strcmp.c deleted file mode 100644 index 8cbf189..0000000 --- a/src/userspace/mlibc/string/strcmp.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <mlibc/stdlib.h> - -char strcmp(const char *a, const char *b) -{ - if (strlen(a) != strlen(b)) - return 1; - - for (size_t i = 0; i < strlen(a); i++) - if (a[i] != b[i]) - return 1; - - return 0; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/string/strcpy.c b/src/userspace/mlibc/string/strcpy.c deleted file mode 100644 index 3a4832c..0000000 --- a/src/userspace/mlibc/string/strcpy.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <mlibc/stdlib.h> - -void strcpy(char *dest, const char *orig) -{ - size_t s_orig = strlen(orig); - - for (size_t i = 0; i < s_orig; i++) - dest[i] = orig[i]; - dest[s_orig] = 0; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/string/strdisp.c b/src/userspace/mlibc/string/strdisp.c deleted file mode 100644 index 51c5a90..0000000 --- a/src/userspace/mlibc/string/strdisp.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <mlibc/stdlib.h> - -void strdisponce(char *str) -{ - for (size_t i = sizeof(str) + 2; i > 0; i--) - str[i] = str[i - 1]; - str[0] = 0; -} - -void strdisp(char *str, int n) -{ - for (int i = 0; i < n; i++) - strdisponce(str); -}
\ No newline at end of file diff --git a/src/userspace/mlibc/string/strdup.c b/src/userspace/mlibc/string/strdup.c deleted file mode 100644 index 6a4fa86..0000000 --- a/src/userspace/mlibc/string/strdup.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <mlibc/stdlib.h> -#include <mlibc/stdlib.h> - -char *strdup(const char *orig) -{ - // size_t s_orig = strlen(orig); - char *ret = 0; - // kmalloc(s_orig + 1); - strcpy(ret, orig); - return ret; -}
\ No newline at end of file diff --git a/src/userspace/mlibc/string/strinv.c b/src/userspace/mlibc/string/strinv.c deleted file mode 100644 index 20b916e..0000000 --- a/src/userspace/mlibc/string/strinv.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <mlibc/stdlib.h> - -void strinv(char *str) -{ - size_t s_str = strlen(str); - - int iterations = (int)s_str / 2; - for (int i = 0; i < iterations; i++) { - char aux = str[i]; - str[i] = str[(s_str - i) - 1]; - str[(s_str - i) - 1] = aux; - } -}
\ No newline at end of file diff --git a/src/userspace/mlibc/string/strlen.c b/src/userspace/mlibc/string/strlen.c deleted file mode 100644 index f652495..0000000 --- a/src/userspace/mlibc/string/strlen.c +++ /dev/null @@ -1,35 +0,0 @@ -#include <mlibc/stdlib.h> - -size_t strlen(const char *str) -{ - const char *char_ptr; - const unsigned long int *longword_ptr; - unsigned long int longword, himagic, lomagic; - - for (char_ptr = str; ((unsigned long int)char_ptr & (sizeof(longword) - 1)) != 0; - ++char_ptr) - if (*char_ptr == '\0') - return char_ptr - str; - - longword_ptr = (unsigned long int *)char_ptr; - - himagic = 0x80808080L; - lomagic = 0x01010101L; - - for (;;) { - longword = *longword_ptr++; - - if (((longword - lomagic) & himagic) != 0) { - const char *cp = (const char *)(longword_ptr - 1); - - if (cp[0] == 0) - return cp - str; - if (cp[1] == 0) - return cp - str + 1; - if (cp[2] == 0) - return cp - str + 2; - if (cp[3] == 0) - return cp - str + 3; - } - } -}
\ No newline at end of file diff --git a/src/userspace/programs/sh.c b/src/userspace/programs/sh.c new file mode 100644 index 0000000..3cb2bf9 --- /dev/null +++ b/src/userspace/programs/sh.c @@ -0,0 +1,10 @@ +#include <syscall.h> + +void main() +{ + syscall_write("\nHello from Userspace!\n"); + + syscall_write("> "); + + syscall_halt(); +} |