From f13837f6f8c07d933d318da4b1354c3581efb79b Mon Sep 17 00:00:00 2001 From: Cetica Marco Date: Sun, 3 Jan 2021 18:24:55 +0100 Subject: [PATCH] Added system fetcher and strcpy(string.h) --- kernel/kernel_main.c | 1 - kernel/libc/string.c | 9 ++++++++- kernel/libc/string.h | 1 + kernel/userspace/Makefile | 6 +++--- kernel/userspace/fetch.c | 34 ++++++++++++++++++++++++++++++++++ kernel/userspace/fetch.h | 15 +++++++++++++++ kernel/userspace/shell.c | 15 +++------------ kernel/userspace/shell.h | 1 - 8 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 kernel/userspace/fetch.c create mode 100644 kernel/userspace/fetch.h diff --git a/kernel/kernel_main.c b/kernel/kernel_main.c index be643d0..3fc8ff9 100644 --- a/kernel/kernel_main.c +++ b/kernel/kernel_main.c @@ -58,6 +58,5 @@ void kernel_main() { PRTOK printf(" - Heap works!"); - iceos_ascii_logo(); init_prompt(); // Initialize frame buffer } diff --git a/kernel/libc/string.c b/kernel/libc/string.c index 7cb8c57..959edcd 100644 --- a/kernel/libc/string.c +++ b/kernel/libc/string.c @@ -88,6 +88,13 @@ size_t strlen(const uint8_t *buf) { return i; } +uint8_t *strcpy(uint8_t *dst, const uint8_t *src) { + uint8_t *dst_p = dst; + while((*dst++ = *src++)); + + return dst_p; +} + /* Worst memset implementation * i could find on the net. * however it works so... */ @@ -122,4 +129,4 @@ void strlower(uint8_t *str) { if(str[i] == 'A' && str[i] < 'Z') str[i] |= 0x60; } -} \ No newline at end of file +} diff --git a/kernel/libc/string.h b/kernel/libc/string.h index d234859..ab341d7 100644 --- a/kernel/libc/string.h +++ b/kernel/libc/string.h @@ -15,6 +15,7 @@ int32_t strcmp(const uint8_t *s1, const uint8_t *s2); uint8_t *itoa(int32_t val, uint8_t *buf, uint32_t radix); uint8_t *uitoa(uint32_t val, uint8_t *buf, uint32_t radix); size_t strlen(const uint8_t *buf); +uint8_t *strcpy(uint8_t *dst, const uint8_t *src); void *memset(void *s, uint32_t c, size_t n); void *memmove(void *dst, const void *src, size_t len); void strupper(uint8_t *str); diff --git a/kernel/userspace/Makefile b/kernel/userspace/Makefile index 3f1da65..ac1b288 100644 --- a/kernel/userspace/Makefile +++ b/kernel/userspace/Makefile @@ -1,10 +1,10 @@ -OBJS = shell.o +OBJS = shell.o fetch.o CC = i686-elf-gcc # cross-compiler -CFLAGS = -m32 -fno-stack-protector -ffreestanding -Wall -Wextra -Werror -g -c +CFLAGS = -DDEFAULT_USER=root -DDEFAULT_HOSTNAME=vulcan -m32 -fno-stack-protector -ffreestanding -Wall -Wextra -Werror -g -c all:${OBJS} %.o: %.c - $(CC) $(CFLAGS) $< -o $@ \ No newline at end of file + $(CC) $(CFLAGS) $< -o $@ diff --git a/kernel/userspace/fetch.c b/kernel/userspace/fetch.c new file mode 100644 index 0000000..95532ba --- /dev/null +++ b/kernel/userspace/fetch.c @@ -0,0 +1,34 @@ +#include "fetch.h" +#include "../libc/stdio.h" +#include "../libc/string.h" +#include "../libc/time.h" +#include "../drivers/tty.h" + + + +void system_fetcher() { + /*uint8_t *logo = (uint8_t*)" \n \ + __ __ ___ ___ \n \ + \\ \\ / / / _ \\/ __| \n \ + \\ V / | (_) \\__ \\ \n \ + \\_/ \\___/|___/";*/ + + uint8_t user[64], hostname[64]; +#define STRINGIZE(x) #x +#define STRINGIZE_VALUE_OF(x) STRINGIZE(x) +#ifdef DEFAULT_USER + strcpy(user, (uint8_t*)STRINGIZE_VALUE_OF(DEFAULT_USER)); +#else + #error "-DDEFAULT_USER flag not set" +#endif + +#ifdef DEFAULT_HOSTNAME + strcpy(hostname, (uint8_t*)STRINGIZE_VALUE_OF(DEFAULT_HOSTNAME)); +#else + #error "-DDEFAULT_HOSTNAME flag not set" +#endif + printf_color("\n__ __ ___ ___ ", LIGHT_RED, BLACK); + printf_color((char*)user, LIGHT_CYAN, BLACK); + printf_color("@", LIGHT_RED, BLACK); + printf_color((char*)hostname, LIGHT_CYAN, BLACK); +} diff --git a/kernel/userspace/fetch.h b/kernel/userspace/fetch.h new file mode 100644 index 0000000..39f2103 --- /dev/null +++ b/kernel/userspace/fetch.h @@ -0,0 +1,15 @@ +/************************************** + * VulcanOS Kernel * + * Developed by Marco 'icebit' Cetica * + * (c) 2019-2021 * + * Released under GPLv3 * + * https://github.com/ice-bit/iceOS * + ***************************************/ +#ifndef FETCH_H +#define FETCH_H + +#include + +void system_fetcher(); + +#endif diff --git a/kernel/userspace/shell.c b/kernel/userspace/shell.c index aa498ca..467a2b1 100644 --- a/kernel/userspace/shell.c +++ b/kernel/userspace/shell.c @@ -1,4 +1,5 @@ #include "shell.h" +#include "fetch.h" #include "../libc/string.h" #include "../libc/stdio.h" #include "../drivers/tty.h" @@ -110,20 +111,10 @@ void processCommand(uint8_t *cmd) { register_dump(); else if(strcmp(cmd, (uint8_t*)"timer") == 0) timer_dump(); - else if(strcmp(cmd, (uint8_t*)"banner") == 0) - iceos_ascii_logo(); + else if(strcmp(cmd, (uint8_t*)"fetch") == 0) + system_fetcher(); else if(strcmp(cmd, (uint8_t*)"reboot") == 0) reboot(); else puts("\nCommand not found!"); } - -void iceos_ascii_logo() { - printf_color("\n\n" - "###################################################\n#", - LIGHT_BLUE, BLACK); - printf_color(" iceOS - developed by Marco Cetica (c) 2019-2020 ", - LIGHT_MAGENTA, BLACK); - printf_color("#\n###################################################\n", - LIGHT_BLUE, BLACK); -} diff --git a/kernel/userspace/shell.h b/kernel/userspace/shell.h index eec7d89..a69cf0c 100644 --- a/kernel/userspace/shell.h +++ b/kernel/userspace/shell.h @@ -15,6 +15,5 @@ void helper(); void processCommand(uint8_t *cmd); -void iceos_ascii_logo(); #endif