Added system fetcher and strcpy(string.h)

This commit is contained in:
Cetica Marco 2021-01-03 18:24:55 +01:00
parent 21f017f13c
commit f13837f6f8
8 changed files with 64 additions and 18 deletions

View File

@ -58,6 +58,5 @@ void kernel_main() {
PRTOK
printf(" - Heap works!");
iceos_ascii_logo();
init_prompt(); // Initialize frame buffer
}

View File

@ -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;
}
}
}

View File

@ -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);

View File

@ -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 $@
$(CC) $(CFLAGS) $< -o $@

34
kernel/userspace/fetch.c Normal file
View File

@ -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);
}

15
kernel/userspace/fetch.h Normal file
View File

@ -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 <stdint.h>
void system_fetcher();
#endif

View File

@ -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);
}

View File

@ -15,6 +15,5 @@
void helper();
void processCommand(uint8_t *cmd);
void iceos_ascii_logo();
#endif