summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/Makefile2
-rw-r--r--kernel/fs/devfs.c2
-rw-r--r--kernel/includes/ctype.h1
-rw-r--r--kernel/includes/stdlib.h4
-rw-r--r--kernel/libc/ctype/tolower.c7
-rw-r--r--kernel/libc/stdlib/parsenum.c83
6 files changed, 97 insertions, 2 deletions
diff --git a/kernel/Makefile b/kernel/Makefile
index 7fd8310..a27b108 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -1,6 +1,6 @@
CC="i686-sb-gcc"
AS="i686-sb-as"
-OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o kubsan.o drivers/serial.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o elf.o sched/scheduler.o libc/string/copy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o signal.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o arch/i386/interrupts.o cpu/isr.o lib/stack.o lib/buffered_write.o lib/list.o cpu/arch_inst.o cpu/int_syscall.o lib/ringbuffer.o lib/relist.o arch/i386/tsc.o arch/i386/asm_tsc.o drivers/cmos.o timer.o queue.o fonts.o drivers/ac97.o audio.o libc/ctype/isdigit.o
+OBJ = arch/i386/boot.o init/kernel.o cpu/gdt.o cpu/reload_gdt.o cpu/idt.o cpu/io.o libc/stdio/print.o drivers/keyboard.o log.o drivers/pit.o libc/string/memcpy.o libc/string/strlen.o libc/string/memcmp.o drivers/ata.o libc/string/memset.o cpu/syscall.o read_eip.o libc/exit/assert.o process.o libc/string/strcpy.o arch/i386/mmu.o kmalloc.o fs/ext2.o fs/vfs.o fs/devfs.o cpu/spinlock.o random.o libc/string/strcmp.o crypto/ChaCha20/chacha20.o crypto/SHA1/sha1.o fs/tmpfs.o libc/string/isequal.o drivers/pst.o kubsan.o drivers/serial.o socket.o poll.o fs/fifo.o hashmap/hashmap.o fs/shm.o elf.o sched/scheduler.o libc/string/copy.o drivers/mouse.o libc/string/strlcpy.o libc/string/strcat.o drivers/vbe.o drivers/pci.o drivers/rtl8139.o network/ethernet.o network/arp.o network/bytes.o network/ipv4.o network/udp.o signal.o network/tcp.o drivers/ahci.o crypto/xoshiro256plusplus/xoshiro256plusplus.o arch/i386/interrupts.o cpu/isr.o lib/stack.o lib/buffered_write.o lib/list.o cpu/arch_inst.o cpu/int_syscall.o lib/ringbuffer.o lib/relist.o arch/i386/tsc.o arch/i386/asm_tsc.o drivers/cmos.o timer.o queue.o fonts.o drivers/ac97.o audio.o libc/ctype/isdigit.o libc/stdlib/parsenum.o libc/ctype/tolower.o
CFLAGS = -std=c99 -O0 -fsanitize=vla-bound,shift-exponent,pointer-overflow,shift,signed-integer-overflow,bounds -ggdb -ffreestanding -Wall -Wextra -Wno-int-conversion -Wno-unused-parameter -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign -DKERNEL
LDFLAGS=
#CFLAGS = -std=c99 -O3 -flto -ggdb -ffreestanding -Wall -Wextra -Wno-int-conversion -Wno-unused-parameter -Werror -mgeneral-regs-only -Wimplicit-fallthrough -I./libc/include/ -I. -Wno-pointer-sign -DKERNEL
diff --git a/kernel/fs/devfs.c b/kernel/fs/devfs.c
index 833aab5..8e09b7c 100644
--- a/kernel/fs/devfs.c
+++ b/kernel/fs/devfs.c
@@ -64,7 +64,7 @@ int stdout_write(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) {
int rc = len;
for (; len--;) {
- putc(*buffer++);
+ write_serial(*buffer++);
}
return rc;
}
diff --git a/kernel/includes/ctype.h b/kernel/includes/ctype.h
index 4f9a3b3..f6be4f2 100644
--- a/kernel/includes/ctype.h
+++ b/kernel/includes/ctype.h
@@ -1 +1,2 @@
int isdigit(int c);
+int tolower(int c);
diff --git a/kernel/includes/stdlib.h b/kernel/includes/stdlib.h
new file mode 100644
index 0000000..3b24fb6
--- /dev/null
+++ b/kernel/includes/stdlib.h
@@ -0,0 +1,4 @@
+#include <typedefs.h>
+
+u64 parse_u64(const char *restrict str, char **restrict endptr, int base,
+ int *err);
diff --git a/kernel/libc/ctype/tolower.c b/kernel/libc/ctype/tolower.c
new file mode 100644
index 0000000..f1bb163
--- /dev/null
+++ b/kernel/libc/ctype/tolower.c
@@ -0,0 +1,7 @@
+#include <ctype.h>
+
+int tolower(int c) {
+ if (c >= 'A' && c <= 'Z')
+ return c - 'A' + 'a';
+ return c;
+}
diff --git a/kernel/libc/stdlib/parsenum.c b/kernel/libc/stdlib/parsenum.c
new file mode 100644
index 0000000..3990c7b
--- /dev/null
+++ b/kernel/libc/stdlib/parsenum.c
@@ -0,0 +1,83 @@
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#define MAX_64 0xFFFFFFFFFFFFFFFF
+
+extern int errno;
+int get_value(char c, long base) {
+ int r;
+ int l = tolower(c);
+ if (l >= '0' && l <= '9') {
+ r = l - '0';
+ } else if (l >= 'a' && l <= 'z') {
+ r = (l - 'a') + 10;
+ } else {
+ return -1;
+ }
+ if (r >= base) {
+ return -1;
+ }
+ return r;
+}
+
+u64 parse_u64(const char *restrict str, char **restrict endptr, int base,
+ int *err) {
+ if (err) {
+ *err = 0;
+ }
+ u64 ret_value = 0;
+ if (endptr) {
+ *endptr = (char *)str;
+ }
+ if (!*str) {
+ return ret_value;
+ }
+
+ if (0 == base) {
+ char prefix = *str;
+ if ('0' == prefix) {
+ str++;
+ if ('x' == tolower(*str)) {
+ str++;
+ base = 16;
+ } else {
+ base = 8;
+ }
+ } else {
+ base = 10;
+ }
+ }
+
+ if (2 <= base && 36 >= base) {
+ for (; *str; str++) {
+ int val = get_value(*str, base);
+ if (-1 == val) {
+ break;
+ }
+ if (-1 == val) {
+ break;
+ }
+ ret_value *= base;
+ if (ret_value > MAX_64 - val) {
+ if (err) {
+ *err = 1;
+ }
+ return 0;
+ }
+
+ ret_value += val;
+ }
+ } else {
+ if (err) {
+ *err = 1;
+ }
+ return 0;
+ }
+ if (endptr) {
+ *endptr = (char *)str;
+ }
+ return ret_value;
+}