test: Update so it builds with LLVM
diff --git a/test/Makefile b/test/Makefile
index e99d3f78..c06ad968 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -3,17 +3,18 @@ CFLAGS = -O2
LD = cc
QEMU = qemu-system-x86_64
QEMUFLAGS = -m 1G -enable-kvm -cpu host
-LDINTERNALFLAGS := -Tlinker.ld -nostdlib -pie -static-pie -fno-pic -fpie -z max-page-size=0x1000
-INTERNALCFLAGS := -I../stivale -I. -ffreestanding -fno-stack-protector \
- -fno-pic -fpie -fomit-frame-pointer -mno-red-zone -mgeneral-regs-only -masm=intel
+LDINTERNALFLAGS := -Tlinker.ld -nostdlib -fno-pic -fpie -z max-page-size=0x1000 \
+ -Wl,-static,-pie,--no-dynamic-linker,-ztext -static-pie
+INTERNALCFLAGS := -I../stivale -I. -ffreestanding -fno-stack-protector \
+ -fno-pic -fpie -mno-red-zone -mno-80387 -mno-mmx -mno-3dnow -mno-sse -mno-sse2
all: test.elf
-test.elf: stivale.o stivale2.o e9print.o
- $(LD) $(LDINTERNALFLAGS) stivale.o stivale2.o e9print.o -o test.elf
+test.elf: stivale.o stivale2.o e9print.o memory.o
+ $(LD) $(LDINTERNALFLAGS) $^ -o test.elf
%.o: %.c
$(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@
clean:
- rm -rf test.elf stivale.o stivale2.o e9print.o
+ rm -rf test.elf stivale.o stivale2.o e9print.o memory.o
diff --git a/test/e9print.c b/test/e9print.c
index 30450f5c..2895b1bf 100644
--- a/test/e9print.c
+++ b/test/e9print.c
@@ -8,7 +8,7 @@ static const char CONVERSION_TABLE[] = "0123456789abcdef";
void e9_putc(char c) {
if (stivale2_print != NULL)
stivale2_print(&c, 1);
- asm volatile ("out dx, al" :: "a" (c), "d" (0xE9) : "memory");
+ asm volatile ("outb %0, %1" :: "a" (c), "Nd" (0xe9) : "memory");
}
void e9_print(const char *msg) {
diff --git a/test/memory.c b/test/memory.c
new file mode 100644
index 00000000..9a58e46d
--- /dev/null
+++ b/test/memory.c
@@ -0,0 +1,52 @@
+#include <stddef.h>
+#include <stdint.h>
+
+void *memcpy(void *dest, const void *src, size_t n) {
+ uint8_t *pdest = dest;
+ const uint8_t *psrc = src;
+
+ for (size_t i = 0; i < n; i++) {
+ pdest[i] = psrc[i];
+ }
+
+ return dest;
+}
+
+void *memset(void *s, int c, size_t n) {
+ uint8_t *p = s;
+
+ for (size_t i = 0; i < n; i++) {
+ p[i] = (uint8_t)c;
+ }
+
+ return s;
+}
+
+void *memmove(void *dest, const void *src, size_t n) {
+ uint8_t *pdest = dest;
+ const uint8_t *psrc = src;
+
+ if (src > dest) {
+ for (size_t i = 0; i < n; i++) {
+ pdest[i] = psrc[i];
+ }
+ } else if (src < dest) {
+ for (size_t i = n; i > 0; i--) {
+ pdest[i-1] = psrc[i-1];
+ }
+ }
+
+ return dest;
+}
+
+int memcmp(const void *s1, const void *s2, size_t n) {
+ const uint8_t *p1 = s1;
+ const uint8_t *p2 = s2;
+
+ for (size_t i = 0; i < n; i++) {
+ if (p1[i] != p2[i])
+ return p1[i] < p2[i] ? -1 : 1;
+ }
+
+ return 0;
+}
