diff options
| author | EmulatedSeasons <89668582+EmulatedSeasons@users.noreply.github.com> | 2024-07-18 22:25:44 -0400 |
|---|---|---|
| committer | EmulatedSeasons <89668582+EmulatedSeasons@users.noreply.github.com> | 2024-09-03 14:07:04 -0400 |
| commit | 8eda325ede02d3fc606a34f7fa3c4922b05a84e4 (patch) | |
| tree | 881da3ba217871a002e6e79bdfc90149cc589e1d /libc | |
| parent | 82bcab74e6e0c581dcf4ac4d7997aec5c5e14aae (diff) | |
Remerged the std stuff into the kernel
Diffstat (limited to 'libc')
| -rw-r--r-- | libc/README.txt | 5 | ||||
| -rw-r--r-- | libc/abort.c | 11 | ||||
| -rw-r--r-- | libc/include/stdio.h | 18 | ||||
| -rw-r--r-- | libc/include/stdlib.h | 15 | ||||
| -rw-r--r-- | libc/include/string.h | 20 | ||||
| -rw-r--r-- | libc/include/sys/cdefs.h | 6 | ||||
| -rw-r--r-- | libc/makefile | 79 | ||||
| -rw-r--r-- | libc/memcmp.c | 13 | ||||
| -rw-r--r-- | libc/memcpy.c | 9 | ||||
| -rw-r--r-- | libc/memmove.c | 14 | ||||
| -rw-r--r-- | libc/memset.c | 8 | ||||
| -rw-r--r-- | libc/printf.c | 199 | ||||
| -rw-r--r-- | libc/putchar.c | 11 | ||||
| -rw-r--r-- | libc/puts.c | 5 | ||||
| -rw-r--r-- | libc/strlen.c | 9 |
15 files changed, 0 insertions, 422 deletions
diff --git a/libc/README.txt b/libc/README.txt deleted file mode 100644 index 6806bd4..0000000 --- a/libc/README.txt +++ /dev/null @@ -1,5 +0,0 @@ -a temporary(?) libc for the kernel
-
-code based off meaty skeleton from osdev.org
-
-todo:
\ No newline at end of file diff --git a/libc/abort.c b/libc/abort.c deleted file mode 100644 index 83873e8..0000000 --- a/libc/abort.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h>
-#include <stdlib.h>
-
-__attribute__((__noreturn__))
-void abort(void) {
- // TODO: Add proper kernel panic.
- printf("kernel: panic: abort()\n");
- asm volatile("hlt");
- while (1) { }
- __builtin_unreachable();
-}
\ No newline at end of file diff --git a/libc/include/stdio.h b/libc/include/stdio.h deleted file mode 100644 index eb4e45b..0000000 --- a/libc/include/stdio.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _STDIO_H
-#define _STDIO_H 1
-
-#define EOF (-1)
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int printf(const char* __restrict, ...);
-int putchar(int);
-int puts(const char*);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
\ No newline at end of file diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h deleted file mode 100644 index 1d1ee32..0000000 --- a/libc/include/stdlib.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _STDLIB_H
-#define _STDLIB_H 1
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-__attribute__((__noreturn__))
-void abort(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
\ No newline at end of file diff --git a/libc/include/string.h b/libc/include/string.h deleted file mode 100644 index 4f6b5bd..0000000 --- a/libc/include/string.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _STRING_H
-#define _STRING_H 1
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int memcmp(const void*, const void*, size_t);
-void* memcpy(void* __restrict, const void* __restrict, size_t);
-void* memmove(void*, const void*, size_t);
-void* memset(void*, int, size_t);
-size_t strlen(const char*);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
\ No newline at end of file diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h deleted file mode 100644 index 1e2c277..0000000 --- a/libc/include/sys/cdefs.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _SYS_CDEFS_H
-#define _SYS_CDEFS_H 1
-
-
-
-#endif
\ No newline at end of file diff --git a/libc/makefile b/libc/makefile deleted file mode 100644 index aec21ef..0000000 --- a/libc/makefile +++ /dev/null @@ -1,79 +0,0 @@ -# libc makefile
-
-ifndef AR
- AR = i686-elf-ar
-endif
-
-ifndef CFLAGS
- CFLAGS = -ffreestanding -Wall -Wextra -g -std=gnu11 -O2 -Iinclude
- CFLAGS += --sysroot=$(SYSROOT)
- CFLAGS += -isystem $(SYSROOT)/usr/include
-endif
-
-ifndef CXXFLAGS
- CXXFLAGS = -ffreestanding -Wall -Wextra -fno-exceptions -fno-rtti -D__is_kernel -g -O2 -Iinclude
- CXXFLAGS += -Iinclude
- CXXFLAGS += --sysroot=$(SYSROOT)
- CXXFLAGS += -isystem $(SYSROOT)/usr/include
-endif
-
-ifndef LDFLAGS
- LDFLAGS = -T arch/$(ARCH)/linker.ld -ffreestanding -g -O2 -Iinclude
- LDFLAGS += --sysroot=$(SYSROOT)
- LDFLAGS += -isystem $(SYSROOT)/usr/include
-endif
-
-ifndef SYSROOT
- $(error No sysroot specified)
-endif
-
-
-LIBS = -nostdlib -lgcc
-
-#Find all the source files
-C_SOURCES := $(shell find $(PWD) -type f -name '*.c')
-#CPP_SOURCES := $(shell find $(PWD)/kernel -type f -name '*.cpp')
-HEADERS := $(shell find $(PWD) -type f -name '*.h')
-#ASMFILES := $(shell find $(PWD) -type f -name '*.asm')
-
-OBJECTS := $(patsubst %.c,%.o,$(C_SOURCES))
-# OBJECTS += $(patsubst %.cpp,%.o,$(CPP_SOURCES))
-# OBJECTS += $(patsubst %.asm,%.o,$(ASMFILES))
-
-DEPFILES := $(patsubst %.c,%.d,$(C_SOURCES))
-# DEPFILES += $(patsubst %.cpp,%.d,$(CPP_SOURCES))
-
-LINKLST += $(OBJECTS)
-LINKLST += $(LIBS)
-
--include $(DEPFILES)
-
-.PHONY: all install-headers install-lib clean
-
-all: libc.a install-lib
-
-libc.a: ${OBJECTS}
- $(info [INFO] Linking $<)
- $(AR) rcs $@ $(OBJECTS)
-
-%.o: %.cpp
- $(info [INFO] Compiling $<)
- $(CXX) ${CXXFLAGS} -MMD -MP -c $< -o $@
-
-%.o: %.c
- $(info [INFO] Compiling $<)
- $(CC) $(CFLAGS) -MMD -MP -c $< -o $@
-
-%.o: %.asm
- $(info [INFO] Assembling $<)
- $(NASM) $< -felf32 -o $@ -g
-
-install-headers:
- cp -r --preserve=timestamps include/. $(SYSROOT)/usr/include
-
-install-lib: libc.a
- cp -r $< $(SYSROOT)/usr/lib/.
-
-clean:
- $(info [INFO] Cleaning)
- $(RM) ${OBJECTS} $(DEPFILES) libc.a
\ No newline at end of file diff --git a/libc/memcmp.c b/libc/memcmp.c deleted file mode 100644 index 93141e1..0000000 --- a/libc/memcmp.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <string.h>
-
-int memcmp(const void* aptr, const void* bptr, size_t size) {
- const unsigned char* a = (const unsigned char*) aptr;
- const unsigned char* b = (const unsigned char*) bptr;
- 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/libc/memcpy.c b/libc/memcpy.c deleted file mode 100644 index 7e09be7..0000000 --- a/libc/memcpy.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <string.h>
-
-void* memcpy(void* restrict dstptr, const void* restrict srcptr, size_t size) {
- unsigned char* dst = (unsigned char*) dstptr;
- const unsigned char* src = (const unsigned char*) srcptr;
- for (size_t i=0; i < size; i++)
- dst[i] = src[i];
- return dstptr;
-}
\ No newline at end of file diff --git a/libc/memmove.c b/libc/memmove.c deleted file mode 100644 index 98c787f..0000000 --- a/libc/memmove.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <string.h>
-
-void* memmove(void* dstptr, const void* srcptr, size_t size) {
- unsigned char* dst = (unsigned char*) dstptr;
- const unsigned char* src = (const unsigned char*) srcptr;
- if (dst < src) {
- for (size_t i = 0; i < size; i++)
- dst[i] = src[i];
- } else {
- for (size_t i = size; i != 0; i--)
- dst[i-1] = src[i-1];
- }
- return dstptr;
-}
\ No newline at end of file diff --git a/libc/memset.c b/libc/memset.c deleted file mode 100644 index 67dadfe..0000000 --- a/libc/memset.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <string.h>
-
-void* memset(void* bufptr, int value, size_t size) {
- unsigned char* buf = (unsigned char*) bufptr;
- for (size_t i = 0; i < size; i++)
- buf[i] = (unsigned char) value;
- return bufptr;
-}
\ No newline at end of file diff --git a/libc/printf.c b/libc/printf.c deleted file mode 100644 index 0bb5506..0000000 --- a/libc/printf.c +++ /dev/null @@ -1,199 +0,0 @@ -#include <limits.h>
-#include <stdbool.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-
-static bool print(const char* data, size_t length) {
- const unsigned char* bytes = (const unsigned char*) data;
- for (size_t i = 0; i < length; i++)
- if (putchar(bytes[i]) == EOF)
- return false;
- return true;
-}
-
-// for %d and %x.
-static const char* itoa(unsigned int num, char* str, unsigned int base) {
- int cou = 0; // nt
-
- if (num == 0) { // 0
- str[cou] = '0';
- str[++cou] = '\0';
- return str;
- }
-
- while (num)
- {
- unsigned int rem = (num % base);
- // brings the number up to ascii 0 + the digit
- if (rem > 9) {
- str[cou] = rem + '7'; // 7 = 55 + 10(A) = 65
- } else {
- str[cou] = rem + '0';
- }
- num /= base;
- ++cou;
- }
-
- // reverse the string
- size_t start = 0;
- size_t end = cou - 1;
- while (start < end) {
- char temp = str[start];
- str[start] = str[end];
- str[end] = temp;
- ++start;
- --end;
- }
-
- str[cou] = '\0';
- return str;
-}
-
-// have no idea if there's a better way to do this. for %lx
-static const char* itoa_u64(unsigned long long num, char* str, int base) {
- size_t cou = 0; // nt
-
- if (num == 0) { // 0
- str[cou] = '0';
- str[++cou] = '\0';
- return str;
- }
-
- while (num)
- {
- unsigned long long rem = num % base;
- // brings the number up to ascii 0 + the digit
- if (rem > 9) {
- str[cou] = rem + '7'; // 7 = 55 + 10(A) = 65
- } else {
- str[cou] = rem + '0';
- }
- num /= base;
- ++cou;
- }
-
- // reverse the string
- size_t start = 0;
- size_t end = cou - 1;
- while (start < end) {
- char temp = str[start];
- str[start] = str[end];
- str[end] = temp;
- ++start;
- --end;
- }
-
- str[cou] = '\0';
- return str;
-}
-
-int printf(const char* restrict format, ...) {
- va_list parameters;
- va_start(parameters, format);
-
- int written = 0;
-
- while (*format != '\0') {
- size_t maxrem = INT_MAX - written;
-
- if (format[0] != '%' || format[1] == '%') {
- if (format[0] == '%')
- format++;
- size_t amount = 1;
- while (format[amount] && format[amount] != '%')
- amount++;
- if (maxrem < amount) {
- // TODO: Set errno to EOVERFLOW.
- return -1;
- }
- if (!print(format, amount))
- return -1;
- format += amount;
- written += amount;
- continue;
- }
-
- const char* format_begun_at = format++;
-
- if (*format == 'c') {
- format++;
- char c = (char) va_arg(parameters, int /* char promotes to int */);
- if (!maxrem) {
- // TODO: Set errno to EOVERFLOW.
- return -1;
- }
- if (!print(&c, sizeof(c)))
- return -1;
- written++;
- } else if (*format == 'd') {
- format++;
- char str[20]; // probably a long enough buffer
- unsigned int d = va_arg(parameters, unsigned int);
- itoa(d, str, 10);
- size_t len = strlen(str);
- if (maxrem < len) {
- // TODO: Set errno to EOVERFLOW.
- return -1;
- }
- if (!print(str, len))
- return -1;
- written += len;
- } else if (*format == 'x') {
- format++;
- char str[20]; // probably a long enough buffer
- unsigned int d = va_arg(parameters, unsigned int);
- itoa(d, str, 16);
- size_t len = strlen(str);
- if (maxrem < len) {
- // TODO: Set errno to EOVERFLOW.
- return -1;
- }
- if (!print(str, len))
- return -1;
- written += len;
- } else if (*format == 'l') { // for %lx and others that start with l
- format++;
- if (*format == 'x') {
- format++;
- char str[20]; // probably a long enough buffer
- unsigned long long d = va_arg(parameters, unsigned long long);
- itoa_u64(d, str, 16);
- size_t len = strlen(str);
- if (maxrem < len) {
- // TODO: Set errno to EOVERFLOW.
- return -1;
- }
- if (!print(str, len))
- return -1;
- written += len;
- }
- } else if (*format == 's') {
- format++;
- const char* str = va_arg(parameters, const char*);
- size_t len = strlen(str);
- if (maxrem < len) {
- // TODO: Set errno to EOVERFLOW.
- return -1;
- }
- if (!print(str, len))
- return -1;
- written += len;
- } else {
- format = format_begun_at;
- size_t len = strlen(format);
- if (maxrem < len) {
- // TODO: Set errno to EOVERFLOW.
- return -1;
- }
- if (!print(format, len))
- return -1;
- written += len;
- format += len;
- }
- }
-
- va_end(parameters);
- return written;
-}
\ No newline at end of file diff --git a/libc/putchar.c b/libc/putchar.c deleted file mode 100644 index f0f5783..0000000 --- a/libc/putchar.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdio.h>
-
-//#include <arch/i386/tmtty.h>
-#include <arch/x86_64/serial.h>
-
-int putchar(int ic) {
- char c = (char) ic;
- serial_putchar(c);
- //terminal_write(&c, sizeof(c));
- return ic;
-}
\ No newline at end of file diff --git a/libc/puts.c b/libc/puts.c deleted file mode 100644 index 8c8c036..0000000 --- a/libc/puts.c +++ /dev/null @@ -1,5 +0,0 @@ -#include <stdio.h>
-
-int puts(const char* string) {
- return printf("%s\n", string);
-}
\ No newline at end of file diff --git a/libc/strlen.c b/libc/strlen.c deleted file mode 100644 index 441622a..0000000 --- a/libc/strlen.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <string.h>
-
-size_t strlen(const char* str) {
- size_t len = 0;
- while (str[len]) {
- ++len;
- }
- return len;
-}
\ No newline at end of file |
