mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Changed libc structure, shouldn't've added anything new
This commit is contained in:
+4
-4
@@ -92,7 +92,7 @@ void main() {
|
|||||||
terminal->fg = FG_COLOR;
|
terminal->fg = FG_COLOR;
|
||||||
terminal->bg = BG_COLOR;
|
terminal->bg = BG_COLOR;
|
||||||
|
|
||||||
clear();
|
printf("\x1b[J"); // Clear
|
||||||
printf("kern.\n\n");
|
printf("kern.\n\n");
|
||||||
|
|
||||||
// Run Interactive Shell Program
|
// Run Interactive Shell Program
|
||||||
@@ -123,7 +123,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(argv[0], "clear") == 0) {
|
if (strcmp(argv[0], "clear") == 0) {
|
||||||
clear();
|
printf("\x1b[J");
|
||||||
} else if (strcmp(argv[0], "echo") == 0) {
|
} else if (strcmp(argv[0], "echo") == 0) {
|
||||||
if (argc < 2) continue;
|
if (argc < 2) continue;
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ void main() {
|
|||||||
} else if (strcmp(argv[0], "exit") == 0) {
|
} else if (strcmp(argv[0], "exit") == 0) {
|
||||||
break;
|
break;
|
||||||
} else if (strcmp(argv[0], "gfx") == 0) {
|
} else if (strcmp(argv[0], "gfx") == 0) {
|
||||||
clear();
|
printf("\x1b[J");
|
||||||
|
|
||||||
// Draw some stuff :)
|
// Draw some stuff :)
|
||||||
for (size_t i = 0; i < 120; i++) {
|
for (size_t i = 0; i < 120; i++) {
|
||||||
@@ -182,7 +182,7 @@ void main() {
|
|||||||
fillCircle(950, 750, 75, rgb(0xa2, 0xd6, 0xf9));
|
fillCircle(950, 750, 75, rgb(0xa2, 0xd6, 0xf9));
|
||||||
|
|
||||||
getc(); // Wait until we get a keystroke
|
getc(); // Wait until we get a keystroke
|
||||||
clear();
|
printf("\x1b[J");
|
||||||
} else if (strcmp(argv[0], "help") == 0) {
|
} else if (strcmp(argv[0], "help") == 0) {
|
||||||
printf("Available Commands:\n");
|
printf("Available Commands:\n");
|
||||||
printf(" clear | Clears the screen\n");
|
printf(" clear | Clears the screen\n");
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
#ifndef MATH_H
|
#ifndef _MATH_H
|
||||||
#define MATH_H
|
#define _MATH_H
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
#define PI 3.141592653589 // Should be good enough
|
#define PI 3.141592653589 // Should be good enough
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef STDARG_H
|
#ifndef _STDARG_H
|
||||||
#define STDARG_H
|
#define _STDARG_H
|
||||||
|
|
||||||
typedef char* va_list;
|
typedef char* va_list;
|
||||||
#define va_start(ap, paramn) (void)((ap) = (char*)(&(paramn) + 1))
|
#define va_start(ap, paramn) (void)((ap) = (char*)(&(paramn) + 1))
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef BOOL_H
|
#ifndef _BOOL_H
|
||||||
#define BOOL_H
|
#define _BOOL_H
|
||||||
|
|
||||||
#define bool _Bool
|
#define bool _Bool
|
||||||
#define true 1
|
#define true 1
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef STDDEF_H
|
#ifndef _STDDEF_H
|
||||||
#define STDDEF_H
|
#define _STDDEF_H
|
||||||
|
|
||||||
#define NULL ((void*)0)
|
#define NULL ((void*)0)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef STDINT_H
|
#ifndef _STDINT_H
|
||||||
#define STDINT_H
|
#define _STDINT_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
@@ -15,6 +15,4 @@ typedef unsigned short uint16_t;
|
|||||||
typedef unsigned int uint32_t;
|
typedef unsigned int uint32_t;
|
||||||
typedef unsigned long long uint64_t;
|
typedef unsigned long long uint64_t;
|
||||||
|
|
||||||
// TODO: floats
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef STDIO_H
|
#ifndef _STDIO_H
|
||||||
#define STDIO_H
|
#define _STDIO_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
#ifndef STDLIB_H
|
#ifndef _STDLIB_H
|
||||||
#define STDLIB_H
|
#define _STDLIB_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stddef.h>
|
||||||
#include <syscall.h>
|
|
||||||
|
|
||||||
void* malloc(const uint32_t size);
|
void* malloc(const size_t size);
|
||||||
void free(const void* ptr);
|
void free(const void* ptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+14
-8
@@ -1,23 +1,29 @@
|
|||||||
#ifndef STRING_H
|
#ifndef _STRING_H
|
||||||
#define STRING_H
|
#define _STRING_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
void* memcpy(void* src, void* dst, uint32_t length);
|
void* memcpy(void* src, void* dst, size_t length);
|
||||||
void* memcpy32(void* src, void* dst, uint32_t length);
|
void* memcpy32(void* src, void* dst, size_t length);
|
||||||
void* memset(void* dst, uint8_t value, uint32_t length);
|
void* memset(void* dst, uint8_t value, size_t length);
|
||||||
|
void* memset32(void* dst, uint32_t value, size_t length);
|
||||||
|
|
||||||
char* itoa(uint32_t val, uint8_t base);
|
char* itoa(size_t val, int base);
|
||||||
uint32_t atoi(const char* str);
|
uint32_t atoi(const char* str);
|
||||||
int isSpace(char c);
|
|
||||||
char* strcpy(char* str1, const char* str2);
|
char* strcpy(char* str1, const char* str2);
|
||||||
char* strncpy(char* str1, const char* str2, size_t n);
|
char* strncpy(char* str1, const char* str2, size_t n);
|
||||||
|
|
||||||
char* strcat(char* str1, const char* str2);
|
char* strcat(char* str1, const char* str2);
|
||||||
char* strncat(char* str1, const char* str2, size_t n);
|
char* strncat(char* str1, const char* str2, size_t n);
|
||||||
|
|
||||||
char* strchr(const char* str, char c);
|
char* strchr(const char* str, char c);
|
||||||
char* strrchr(const char* str, char c);
|
char* strrchr(const char* str, char c);
|
||||||
|
|
||||||
int strcmp(const char* str1, const char* str2);
|
int strcmp(const char* str1, const char* str2);
|
||||||
int strncmp(const char* str1, const char* str2, size_t n);
|
int strncmp(const char* str1, const char* str2, size_t n);
|
||||||
uint32_t strlen(const char* str);
|
|
||||||
|
size_t strlen(const char* str);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef _SYS_GFX_H
|
||||||
|
#define _SYS_GFX_H
|
||||||
|
|
||||||
|
#define BLACK 0x00000000 // 0
|
||||||
|
#define RED 0x00ff0000 // 1
|
||||||
|
#define GREEN 0x0000ff00 // 2
|
||||||
|
#define YELLOW 0x00ffff00 // 3
|
||||||
|
#define BLUE 0x000000ff // 4
|
||||||
|
#define MAGENTA 0x00ff00ff // 5
|
||||||
|
#define CYAN 0x0000ffff // 6
|
||||||
|
#define WHITE 0x00ffffff // 7
|
||||||
|
|
||||||
|
uint32_t codeToColor(uint8_t code);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef SYSCALL_H
|
#ifndef _SYSCALL_H
|
||||||
#define SYSCALL_H
|
#define _SYSCALL_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -1,8 +1,8 @@
|
|||||||
#ifndef TIME_H
|
#ifndef _TIME_H
|
||||||
#define TIME_H
|
#define _TIME_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
void sleep(uint32_t ms);
|
void sleep(size_t ms);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
#include <math.h>
|
|
||||||
|
|
||||||
/* TODO */
|
|
||||||
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#ifndef STDARG_H
|
|
||||||
#define STDARG_H
|
|
||||||
|
|
||||||
typedef char* va_list;
|
|
||||||
#define va_start(ap, paramn) (void)((ap) = (char*)(&(paramn) + 1))
|
|
||||||
#define va_end(ap) (void)((ap) = 0)
|
|
||||||
#define va_arg(ap, type) (((type*)((ap) = ((ap) + sizeof(type))))[-1])
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#ifndef STDDEF_H
|
|
||||||
#define STDDEF_H
|
|
||||||
|
|
||||||
#define NULL ((void*)0)
|
|
||||||
|
|
||||||
typedef unsigned int size_t;
|
|
||||||
typedef signed int ssize_t;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#ifndef STDINT_H
|
|
||||||
#define STDINT_H
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
// Signed ints
|
|
||||||
typedef signed char int8_t;
|
|
||||||
typedef signed short int16_t;
|
|
||||||
typedef signed int int32_t;
|
|
||||||
typedef signed long long int64_t;
|
|
||||||
|
|
||||||
// Unsigned ints
|
|
||||||
typedef unsigned char uint8_t;
|
|
||||||
typedef unsigned short uint16_t;
|
|
||||||
typedef unsigned int uint32_t;
|
|
||||||
typedef unsigned long long uint64_t;
|
|
||||||
|
|
||||||
// TODO: floats
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <syscall.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
FILE* stdin;
|
|
||||||
FILE* stdout;
|
|
||||||
FILE* stderr;
|
|
||||||
|
|
||||||
void putc(char c) {
|
|
||||||
// write(stdout, &c, 1); TODO: This doesn't work and we need to use a static variable
|
|
||||||
static char _c;
|
|
||||||
_c = c;
|
|
||||||
write(1, &_c, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
char getc() {
|
|
||||||
char* c = (char*)0x2100;
|
|
||||||
*c= '\0';
|
|
||||||
while (*c == '\0') { __asm__ volatile ("hlt"); }
|
|
||||||
return *c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print(const char* s) {
|
|
||||||
write(1, s, strlen(s));
|
|
||||||
}
|
|
||||||
|
|
||||||
void clear() {
|
|
||||||
print("\x1b[J");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reads until a newline
|
|
||||||
// TODO: Use Read() Syscall
|
|
||||||
void reads(char* buffer) {
|
|
||||||
char c;
|
|
||||||
int len = 0;
|
|
||||||
|
|
||||||
while ((c = getc()) != '\n') {
|
|
||||||
if (c == '\b') {
|
|
||||||
if (len < 1) continue; // Can we backspace?
|
|
||||||
len--;
|
|
||||||
putc(c);
|
|
||||||
} else {
|
|
||||||
buffer[len++] = c;
|
|
||||||
putc(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
putc(c); // Print the newline
|
|
||||||
buffer[len] = '\0'; // Null terminate
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#include <syscall.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void putc(char c) {
|
||||||
|
// write(stdout, &c, 1); TODO: This doesn't work and we need to use a static variable
|
||||||
|
static char _c;
|
||||||
|
_c = c;
|
||||||
|
write(1, &_c, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
char getc() {
|
||||||
|
char* c = (char*)0x2100; // TODO: Don't use a random looking memory address -_('-')_-
|
||||||
|
*c= '\0';
|
||||||
|
while (*c == '\0') { __asm__ volatile ("hlt"); }
|
||||||
|
return *c;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -3,6 +3,10 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
FILE* stdin;
|
||||||
|
FILE* stdout;
|
||||||
|
FILE* stderr;
|
||||||
|
|
||||||
FILE* fopen(const char* filename, const char* mode) {
|
FILE* fopen(const char* filename, const char* mode) {
|
||||||
int oflag = O_RDWR | O_CREAT | O_BIN; // TODO!
|
int oflag = O_RDWR | O_CREAT | O_BIN; // TODO!
|
||||||
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
// Warning: returns an allocated buffer, must be freed!
|
// Warning: returns an allocated buffer, must be freed!
|
||||||
char* _format(const char* fmt, va_list args) {
|
char* _format(const char* fmt, va_list args) {
|
||||||
@@ -123,3 +123,7 @@ int printf(const char* fmt, ...) {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print(const char* s) {
|
||||||
|
write(1, s, strlen(s));
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// Reads until a newline
|
||||||
|
// TODO: Use Read() Syscall
|
||||||
|
void reads(char* buffer) {
|
||||||
|
char c;
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
|
while ((c = getc()) != '\n') {
|
||||||
|
if (c == '\b') {
|
||||||
|
if (len < 1) continue; // Can we backspace?
|
||||||
|
len--;
|
||||||
|
putc(c);
|
||||||
|
} else {
|
||||||
|
buffer[len++] = c;
|
||||||
|
putc(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
putc(c); // Print the newline
|
||||||
|
buffer[len] = '\0'; // Null terminate
|
||||||
|
}
|
||||||
|
|
||||||
-136
@@ -1,136 +0,0 @@
|
|||||||
#include <string.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
// Source: http://www.strudel.org.uk/itoa/
|
|
||||||
char* itoa(uint32_t val, uint8_t base) {
|
|
||||||
static char buf[32] = { 0 };
|
|
||||||
|
|
||||||
if (base == 0 || base > 16) { return NULL; }
|
|
||||||
|
|
||||||
if (val == 0) {
|
|
||||||
buf[0] = '0';
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 30; val && i; i--, val /= base) {
|
|
||||||
buf[i] = "0123456789abcdef"[val % base];
|
|
||||||
}
|
|
||||||
|
|
||||||
return &buf[i + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t atoi(const char* str) {
|
|
||||||
uint32_t res = 0;
|
|
||||||
|
|
||||||
// TODO: Add error checking
|
|
||||||
|
|
||||||
while (*str >= '0' && *str <= '9') {
|
|
||||||
res = res * 10 + (*str++ - '0');
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
int isSpace(char c) {
|
|
||||||
if (c == ' ' || c == '\t' || c == '\n') return 1;
|
|
||||||
else return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Some implementations taken from https://en.wikibooks.org/wiki/C_Programming/String_manipulation
|
|
||||||
char* strcpy(char* str1, const char* str2) {
|
|
||||||
char* dst = str1;
|
|
||||||
const char* src = str2;
|
|
||||||
while ((*dst++ = *src++) != '\0');
|
|
||||||
return str1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* strncpy(char* str1, const char* str2, size_t n) {
|
|
||||||
char* dst = str1;
|
|
||||||
const char* src = str2;
|
|
||||||
while (n > 0) {
|
|
||||||
n--;
|
|
||||||
if ((*dst++ = *src++) == '\0') {
|
|
||||||
memset(dst, '\0', n);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return str1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* strcat(char* str1, const char* str2) {
|
|
||||||
char* s = str1;
|
|
||||||
while (*s != '\0') { s++; }
|
|
||||||
strcpy(s, str2);
|
|
||||||
return str1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* strncat(char* str1, const char* str2, size_t n) {
|
|
||||||
char* s = str1;
|
|
||||||
while (*s != '\0') { s++; }
|
|
||||||
strncpy(s, str2, n);
|
|
||||||
return str1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* strchr(const char* str, char c) {
|
|
||||||
const char* s = str;
|
|
||||||
while (*s != '\0' && *s != c) { s++; }
|
|
||||||
return (*s == c) ? (char*)s : NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* strrchr(const char* str, char c) { return NULL; } // TODO
|
|
||||||
|
|
||||||
int strcmp(const char* str1, const char* str2) {
|
|
||||||
while (*str1 != '\0' && *str1 == *str2) {
|
|
||||||
str1++;
|
|
||||||
str2++;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t c1 = (*(uint8_t*)str1);
|
|
||||||
uint8_t c2 = (*(uint8_t*)str2);
|
|
||||||
|
|
||||||
return ((c1 < c2) ? -1 : (c1 > c2));
|
|
||||||
}
|
|
||||||
|
|
||||||
int strncmp(const char* str1, const char* str2, size_t n) {
|
|
||||||
if (n == 0) { return 0; }
|
|
||||||
while (n-- > 0 && *str1 == *str2) {
|
|
||||||
if (n == 0 || *str1 == '\0') { return 0; }
|
|
||||||
str1++;
|
|
||||||
str2++;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t c1 = (*(uint8_t*)str1);
|
|
||||||
uint8_t c2 = (*(uint8_t*)str2);
|
|
||||||
|
|
||||||
return ((c1 < c2) ? -1 : (c1 > c2));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t strlen(const char* str) {
|
|
||||||
const char* p = str;
|
|
||||||
while (*++p != '\0');
|
|
||||||
return (uint32_t)(p - str);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Memory functions
|
|
||||||
void* memcpy(void* src, void* dst, uint32_t length) {
|
|
||||||
for (uint32_t i = 0; i < length; i++) {
|
|
||||||
*((uint8_t*)dst + i) = *((uint8_t*)src + i);
|
|
||||||
}
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* memcpy32(void* src, void* dst, uint32_t length) {
|
|
||||||
for (uint32_t i = 0; i * 4 < length; i++) {
|
|
||||||
*((uint32_t*)dst + i) = *((uint32_t*)src + i);
|
|
||||||
}
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* memset(void* dst, uint8_t value, uint32_t length) {
|
|
||||||
for (uint32_t i = 0; i < length; i++) {
|
|
||||||
*(uint8_t*)(dst + i) = value;
|
|
||||||
}
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
unsigned int atoi(const char* str) {
|
||||||
|
unsigned int res = 0;
|
||||||
|
|
||||||
|
// TODO: Add error checking
|
||||||
|
|
||||||
|
while (*str >= '0' && *str <= '9') {
|
||||||
|
res = res * 10 + (*str++ - '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
// Source: http://www.strudel.org.uk/itoa/
|
||||||
|
char* itoa(size_t val, int base) {
|
||||||
|
static char buf[32] = { 0 };
|
||||||
|
|
||||||
|
if (base == 0 || base > 16) { return NULL; }
|
||||||
|
|
||||||
|
if (val == 0) {
|
||||||
|
buf[0] = '0';
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i = 30; val && i; i--, val /= base) {
|
||||||
|
buf[i] = "0123456789abcdef"[val % base];
|
||||||
|
}
|
||||||
|
|
||||||
|
return &buf[i + 1];
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void* memcpy(void* src, void* dst, uint32_t length) {
|
||||||
|
for (uint32_t i = 0; i < length; i++) {
|
||||||
|
*((uint8_t*)dst + i) = *((uint8_t*)src + i);
|
||||||
|
}
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* memcpy32(void* src, void* dst, uint32_t length) {
|
||||||
|
for (uint32_t i = 0; i * 4 < length; i++) {
|
||||||
|
*((uint32_t*)dst + i) = *((uint32_t*)src + i);
|
||||||
|
}
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
void* memset(void* dst, uint8_t value, size_t length) {
|
||||||
|
for (size_t i = 0; i < length; i++) {
|
||||||
|
*(uint8_t*)(dst + i) = value;
|
||||||
|
}
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* memset32(void* dst, uint32_t value, size_t length) {
|
||||||
|
for (size_t i = 0; i < length; i++) {
|
||||||
|
*(uint32_t*)(dst + i) = value;
|
||||||
|
}
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char* strcat(char* str1, const char* str2) {
|
||||||
|
char* s = str1;
|
||||||
|
while (*s != '\0') { s++; }
|
||||||
|
strcpy(s, str2);
|
||||||
|
return str1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* strncat(char* str1, const char* str2, size_t n) {
|
||||||
|
char* s = str1;
|
||||||
|
while (*s != '\0') { s++; }
|
||||||
|
strncpy(s, str2, n);
|
||||||
|
return str1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char* strchr(const char* str, char c) {
|
||||||
|
const char* s = str;
|
||||||
|
while (*s != '\0' && *s != c) { s++; }
|
||||||
|
return (*s == c) ? (char*)s : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* strrchr(const char* str, char c) { return NULL; } // TODO
|
||||||
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int strcmp(const char* str1, const char* str2) {
|
||||||
|
while (*str1 != '\0' && *str1 == *str2) {
|
||||||
|
str1++;
|
||||||
|
str2++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t c1 = (*(uint8_t*)str1);
|
||||||
|
uint8_t c2 = (*(uint8_t*)str2);
|
||||||
|
|
||||||
|
return ((c1 < c2) ? -1 : (c1 > c2));
|
||||||
|
}
|
||||||
|
|
||||||
|
int strncmp(const char* str1, const char* str2, size_t n) {
|
||||||
|
if (n == 0) { return 0; }
|
||||||
|
while (n-- > 0 && *str1 == *str2) {
|
||||||
|
if (n == 0 || *str1 == '\0') { return 0; }
|
||||||
|
str1++;
|
||||||
|
str2++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t c1 = (*(uint8_t*)str1);
|
||||||
|
uint8_t c2 = (*(uint8_t*)str2);
|
||||||
|
|
||||||
|
return ((c1 < c2) ? -1 : (c1 > c2));
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char* strcpy(char* str1, const char* str2) {
|
||||||
|
char* dst = str1;
|
||||||
|
const char* src = str2;
|
||||||
|
while ((*dst++ = *src++) != '\0');
|
||||||
|
return str1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* strncpy(char* str1, const char* str2, size_t n) {
|
||||||
|
char* dst = str1;
|
||||||
|
const char* src = str2;
|
||||||
|
while (n > 0) {
|
||||||
|
n--;
|
||||||
|
if ((*dst++ = *src++) == '\0') {
|
||||||
|
memset(dst, '\0', n);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str1;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
size_t strlen(const char* str) {
|
||||||
|
const char* p = str;
|
||||||
|
while (*++p != '\0');
|
||||||
|
return (size_t)(p - str);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <color.h>
|
#include <sys/gfx.h>
|
||||||
|
|
||||||
uint32_t codeToColor(uint8_t code) {
|
uint32_t codeToColor(uint8_t code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
@@ -5,3 +5,4 @@
|
|||||||
void sleep(uint32_t ms) {
|
void sleep(uint32_t ms) {
|
||||||
syscall(SYS_SLEEP, ms, 0, 0);
|
syscall(SYS_SLEEP, ms, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <color.h>
|
#include <sys/gfx.h>
|
||||||
|
|
||||||
terminal_t* terminal = (terminal_t*)TERMINAL_INFO_LOC;
|
terminal_t* terminal = (terminal_t*)TERMINAL_INFO_LOC;
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -10,8 +10,8 @@ AS = nasm
|
|||||||
MAKE = make
|
MAKE = make
|
||||||
|
|
||||||
# Flags
|
# Flags
|
||||||
CFLAGS = -Wall -Wextra -Wpedantic -Wno-pointer-sign -Wno-pointer-arith\
|
CFLAGS = -Wall -Wextra -Wno-pointer-sign -Wno-pointer-arith -Wno-unused-parameter\
|
||||||
-Os -std=c17 -nostdinc -g\
|
-Os -std=c17 -nostdinc -g -Werror\
|
||||||
-ffreestanding -fno-stack-protector -fno-builtin -fno-pie\
|
-ffreestanding -fno-stack-protector -fno-builtin -fno-pie\
|
||||||
-m32 -mgeneral-regs-only -march=i386
|
-m32 -mgeneral-regs-only -march=i386
|
||||||
LDFLAGS = -z notext -melf_i386 -nostdlib
|
LDFLAGS = -z notext -melf_i386 -nostdlib
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ Legend:
|
|||||||
- [x] makefile
|
- [x] makefile
|
||||||
- [?] probably a full rewrite
|
- [?] probably a full rewrite
|
||||||
- [ ] filesystem
|
- [ ] filesystem
|
||||||
|
- [ ] use Ext1
|
||||||
- [ ] sysroot
|
- [ ] sysroot
|
||||||
- [ ] good buildutil
|
- [ ] good buildutil
|
||||||
- [ ] proper file organization
|
- [ ] proper file organization
|
||||||
@@ -32,8 +33,9 @@ Legend:
|
|||||||
|
|
||||||
- [ ] LIBC
|
- [ ] LIBC
|
||||||
- [ ] assert.h
|
- [ ] assert.h
|
||||||
- [ ] ctype.h
|
- [ ] complex.h (idk why we would need this)
|
||||||
- [ ] errno.h
|
- [x] ctype.h
|
||||||
|
- [x] errno.h
|
||||||
- [ ] fcntl.h
|
- [ ] fcntl.h
|
||||||
- [ ] float.h
|
- [ ] float.h
|
||||||
- [ ] limits.h
|
- [ ] limits.h
|
||||||
@@ -45,6 +47,7 @@ Legend:
|
|||||||
- [ ] stddef.h
|
- [ ] stddef.h
|
||||||
- [ ] stdint.h
|
- [ ] stdint.h
|
||||||
- [ ] stdio.h
|
- [ ] stdio.h
|
||||||
|
- [ ] syscall.h
|
||||||
- [ ] time.h
|
- [ ] time.h
|
||||||
- [ ] unistd.h (do we do POSIX?)
|
- [ ] unistd.h (do we do POSIX?)
|
||||||
- [ ] wchar.h (we would need text support for wide chars ig?)
|
- [ ] wchar.h (we would need text support for wide chars ig?)
|
||||||
|
|||||||
Reference in New Issue
Block a user