summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--src/init/stdlib.c26
-rw-r--r--src/init/stdlib.h4
-rw-r--r--src/kernel/arch/i386/gdt/gdt.c2
-rw-r--r--src/kernel/arch/i386/pagedir.c2
-rw-r--r--src/kernel/mem/virt.c1
-rw-r--r--src/kernel/proc.c2
-rw-r--r--src/kernel/syscalls.c1
-rw-r--r--src/kernel/tests/util.c2
-rw-r--r--src/kernel/tests/vfs.c2
-rw-r--r--src/kernel/util.h5
-rw-r--r--src/kernel/vfs/mount.c2
-rw-r--r--src/kernel/vfs/path.c1
-rw-r--r--src/kernel/vfs/root.c2
-rw-r--r--src/shared/mem.c (renamed from src/kernel/util.c)24
-rw-r--r--src/shared/mem.h7
16 files changed, 33 insertions, 56 deletions
diff --git a/Makefile b/Makefile
index df82583..212ad97 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ PATH := $(shell pwd)/toolchain/bin/:$(PATH)
AS = i686-elf-as
CC = i686-elf-gcc
CHECK = sparse
-CFLAGS = -std=gnu99 -ffreestanding -O2 -Wall -Wextra -Wold-style-definition
+CFLAGS = -std=gnu99 -ffreestanding -O2 -Wall -Wextra -Wold-style-definition -Werror=implicit-function-declaration
CFLAGS += -mgeneral-regs-only
CFLAGS += -Isrc/
LFLAGS = -ffreestanding -O2 -nostdlib -lgcc
@@ -52,12 +52,12 @@ clean:
out/boot.iso: out/fs/boot/kernel.bin out/fs/boot/grub/grub.cfg out/fs/boot/init
@grub-mkrescue -o $@ out/fs/ > /dev/null 2>&1
-out/fs/boot/kernel.bin: src/kernel/linker.ld $(call from_sources, src/kernel/)
+out/fs/boot/kernel.bin: src/kernel/linker.ld $(call from_sources, src/kernel/) $(call from_sources, src/shared/)
@mkdir -p $(@D)
@$(CC) $(LFLAGS) -T $^ -o $@
grub-file --is-x86-multiboot $@
-out/raw_init: src/init/linker.ld $(call from_sources, src/init/)
+out/raw_init: src/init/linker.ld $(call from_sources, src/init/) $(call from_sources, src/shared/)
@mkdir -p $(@D)
@$(CC) $(LFLAGS) -T $^ -o $@
diff --git a/src/init/stdlib.c b/src/init/stdlib.c
index 3d9d8c3..c83440f 100644
--- a/src/init/stdlib.c
+++ b/src/init/stdlib.c
@@ -5,32 +5,6 @@
int __tty_fd;
-void *memcpy(void *dest, const void *src, size_t n) {
- char *d = dest;
- const char *s = src;
- for (size_t i = 0; i < n; i++)
- d[i] = s[i];
- return dest;
-}
-
-void *memset(void *s, int c, size_t n) {
- uint8_t *s2 = s;
- for (size_t i = 0; i < n; n++)
- s2[i] = c;
- return s;
-}
-
-int memcmp(const void *s1, const void *s2, size_t n) {
- const unsigned char *c1 = s1, *c2 = s2;
- for (size_t i = 0; i < n; i++) {
- if (c1[i] != c2[i]) {
- if (c1[i] < c2[i]) return -1;
- else return 1;
- }
- }
- return 0;
-}
-
int strcmp(const char *s1, const char *s2) {
while (*s1) {
if (*s1 != *s2) {
diff --git a/src/init/stdlib.h b/src/init/stdlib.h
index 5049a23..af0788b 100644
--- a/src/init/stdlib.h
+++ b/src/init/stdlib.h
@@ -1,11 +1,9 @@
#pragma once
+#include <shared/mem.h>
#include <stddef.h>
extern int __tty_fd;
-void *memcpy(void *dest, const void *src, size_t n);
-void *memset(void *s, int c, size_t n);
-int memcmp(const void *s1, const void *s2, size_t n);
int strcmp(const char *s1, const char *s2);
size_t strlen(const char *s);
int printf(const char *fmt, ...);
diff --git a/src/kernel/arch/i386/gdt/gdt.c b/src/kernel/arch/i386/gdt/gdt.c
index 6958bb5..56df995 100644
--- a/src/kernel/arch/i386/gdt/gdt.c
+++ b/src/kernel/arch/i386/gdt/gdt.c
@@ -1,6 +1,6 @@
#include <kernel/arch/generic.h>
#include <kernel/arch/i386/gdt.h>
-#include <kernel/util.h>
+#include <shared/mem.h>
#include <stdbool.h>
#include <stdint.h>
diff --git a/src/kernel/arch/i386/pagedir.c b/src/kernel/arch/i386/pagedir.c
index 5dd36ec..88f6ebb 100644
--- a/src/kernel/arch/i386/pagedir.c
+++ b/src/kernel/arch/i386/pagedir.c
@@ -1,6 +1,6 @@
#include <kernel/arch/generic.h>
#include <kernel/mem/alloc.h>
-#include <kernel/util.h>
+#include <shared/mem.h>
#include <stdint.h>
/* <heat> nitpick: I highly recommend you dont use bitfields for paging
diff --git a/src/kernel/mem/virt.c b/src/kernel/mem/virt.c
index b15297e..f0dca06 100644
--- a/src/kernel/mem/virt.c
+++ b/src/kernel/mem/virt.c
@@ -1,6 +1,7 @@
#include <kernel/arch/generic.h>
#include <kernel/mem/virt.h>
#include <kernel/util.h>
+#include <shared/mem.h>
void virt_iter_new(
struct virt_iter *iter, void __user *virt, size_t length,
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index aebd509..e67af19 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -3,8 +3,8 @@
#include <kernel/mem/virt.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
-#include <kernel/util.h>
#include <kernel/vfs/mount.h>
+#include <shared/mem.h>
#include <stdint.h>
struct process *process_first;
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 9a9b5d6..9948506 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -5,6 +5,7 @@
#include <kernel/proc.h>
#include <kernel/vfs/path.h>
#include <shared/flags.h>
+#include <shared/mem.h>
#include <shared/syscalls.h>
#include <stdint.h>
diff --git a/src/kernel/tests/util.c b/src/kernel/tests/util.c
index 3efbee8..05bba24 100644
--- a/src/kernel/tests/util.c
+++ b/src/kernel/tests/util.c
@@ -1,6 +1,6 @@
#include <kernel/tests/base.h>
#include <kernel/tests/tests.h>
-#include <kernel/util.h>
+#include <shared/mem.h>
TEST(memcmp) {
// basic equality checks
diff --git a/src/kernel/tests/vfs.c b/src/kernel/tests/vfs.c
index 339c6bd..8b749b4 100644
--- a/src/kernel/tests/vfs.c
+++ b/src/kernel/tests/vfs.c
@@ -1,9 +1,9 @@
#include <kernel/mem/alloc.h>
#include <kernel/tests/base.h>
#include <kernel/tests/tests.h>
-#include <kernel/util.h>
#include <kernel/vfs/mount.h>
#include <kernel/vfs/path.h>
+#include <shared/mem.h>
TEST(path_simplify) {
#define TEST_WRAPPER(argument, result) do { \
diff --git a/src/kernel/util.h b/src/kernel/util.h
index 839aa49..9b8cb3d 100644
--- a/src/kernel/util.h
+++ b/src/kernel/util.h
@@ -4,11 +4,6 @@
#define __NUM2STR(x) #x
#define NUM2STR(x) __NUM2STR(x)
-void *memcpy(void *dest, const void *src, size_t n);
-void *memset(void *s, int c, size_t n);
-
-int memcmp(const void *s1, const void *s2, size_t n);
-
// see https://gcc.gnu.org/onlinedocs/gcc/Typeof.html
#define min(a,b) ({ \
typeof (a) _a = (a); \
diff --git a/src/kernel/vfs/mount.c b/src/kernel/vfs/mount.c
index b6b3e8d..c962ba5 100644
--- a/src/kernel/vfs/mount.c
+++ b/src/kernel/vfs/mount.c
@@ -1,6 +1,6 @@
#include <kernel/mem/alloc.h>
-#include <kernel/util.h>
#include <kernel/vfs/mount.h>
+#include <shared/mem.h>
struct vfs_mount *vfs_mount_seed(void) {
struct vfs_mount *mount = kmalloc(sizeof *mount);
diff --git a/src/kernel/vfs/path.c b/src/kernel/vfs/path.c
index 096d3fe..df5f00f 100644
--- a/src/kernel/vfs/path.c
+++ b/src/kernel/vfs/path.c
@@ -1,5 +1,6 @@
#include <kernel/vfs/path.h>
#include <kernel/panic.h>
+#include <shared/mem.h>
int path_simplify(const char *in, char *out, size_t len) {
if (len == 0) return -1; // empty paths are invalid
diff --git a/src/kernel/vfs/root.c b/src/kernel/vfs/root.c
index 834bed7..adf1bfe 100644
--- a/src/kernel/vfs/root.c
+++ b/src/kernel/vfs/root.c
@@ -1,8 +1,8 @@
#include <kernel/mem/virt.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
-#include <kernel/util.h>
#include <kernel/vfs/root.h>
+#include <shared/mem.h>
enum {
HANDLE_ROOT,
diff --git a/src/kernel/util.c b/src/shared/mem.c
index 0977745..1b483fe 100644
--- a/src/kernel/util.c
+++ b/src/shared/mem.c
@@ -1,6 +1,17 @@
-#include <kernel/util.h>
+#include <shared/mem.h>
#include <stdint.h>
+int memcmp(const void *s1, const void *s2, size_t n) {
+ const unsigned char *c1 = s1, *c2 = s2;
+ for (size_t i = 0; i < n; i++) {
+ if (c1[i] != c2[i]) {
+ if (c1[i] < c2[i]) return -1;
+ else return 1;
+ }
+ }
+ return 0;
+}
+
void *memcpy(void *dest, const void *src, size_t n) {
char *d = dest;
const char *s = src;
@@ -15,14 +26,3 @@ void *memset(void *s, int c, size_t n) {
s2[i] = c;
return s;
}
-
-int memcmp(const void *s1, const void *s2, size_t n) {
- const unsigned char *c1 = s1, *c2 = s2;
- for (size_t i = 0; i < n; i++) {
- if (c1[i] != c2[i]) {
- if (c1[i] < c2[i]) return -1;
- else return 1;
- }
- }
- return 0;
-}
diff --git a/src/shared/mem.h b/src/shared/mem.h
new file mode 100644
index 0000000..682c184
--- /dev/null
+++ b/src/shared/mem.h
@@ -0,0 +1,7 @@
+#pragma once
+#include <stddef.h>
+
+int memcmp(const void *s1, const void *s2, size_t n);
+
+void *memcpy(void *dest, const void *src, size_t n);
+void *memset(void *s, int c, size_t n);