summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2017-07-13 09:06:53 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2017-07-13 09:06:53 +0200
commited869aa3867d134fb37f586f1db029006677cebb (patch)
treea34cb31b0359d98e0be8a1269535f8f660c7db68
parent08487fb5bfd7f5e1d9564d4132d38592d2dd0cc2 (diff)
downloadabaos-ed869aa3867d134fb37f586f1db029006677cebb.tar.gz
abaos-ed869aa3867d134fb37f586f1db029006677cebb.tar.bz2
separated C library implementations with an OS_ABAOS define (for now),
we cannot test stdio and memory management in the hosted environment yet this way
-rw-r--r--src/Makefile2
-rw-r--r--src/kernel/kernel.c2
-rw-r--r--src/libc/stdio.h4
-rw-r--r--src/libc/stdlib.c9
-rw-r--r--src/libc/stdlib.h4
-rw-r--r--tests/libc/Makefile17
6 files changed, 23 insertions, 15 deletions
diff --git a/src/Makefile b/src/Makefile
index 7b173cd..4192fd1 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,5 +1,5 @@
CC := gcc
-INCLUDES = -I. -Ilibc -Ihardware -Idrivers -Idrivers/hdi -Idrivers/hdi/ps2 -Idrivers/video -Ikernel -Igui
+INCLUDES = -DOS_ABAOS -I. -Ilibc -Ihardware -Idrivers -Idrivers/hdi -Idrivers/hdi/ps2 -Idrivers/video -Ikernel -Igui
CFLAGS := -std=c99 -m32 -march=i486 -ffreestanding -O0 -g -Werror $(INCLUDES)
LD := ld
NASMFLAGS := -f elf32
diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c
index dc2f7eb..3be8758 100644
--- a/src/kernel/kernel.c
+++ b/src/kernel/kernel.c
@@ -13,6 +13,8 @@
#include "keyboard.h"
#include "mouse.h"
#include "pci.h"
+#include "memorymanagement.h"
+
#include "setjmp.h"
#include "kernel.h"
diff --git a/src/libc/stdio.h b/src/libc/stdio.h
index dbf7ac7..24632f6 100644
--- a/src/libc/stdio.h
+++ b/src/libc/stdio.h
@@ -5,7 +5,9 @@
#include "stddef.h"
+#ifdef OS_ABAOS
#include "console.h"
+#endif
#define EOF (-1)
@@ -13,6 +15,8 @@ int puts( const char *s );
int printf( const char *format, ... );
int vprintf( const char *format, va_list args );
+#ifdef OS_ABAOS
void __stdio_set_console( console_t *console );
+#endif
#endif //STDIO_H
diff --git a/src/libc/stdlib.c b/src/libc/stdlib.c
index 9150431..d6bb8b2 100644
--- a/src/libc/stdlib.c
+++ b/src/libc/stdlib.c
@@ -46,22 +46,29 @@ char *itoa( int v, char *s, int base )
return s;
}
+#ifdef OS_ABAOS
// TODO: we should have a global memory manager and one per
// user process later
static memory_manager_t *stdlib_memory_manager = NULL;
+#endif
void *malloc( size_t size )
{
+#ifdef OS_ABAOS
return memory_manager_allocate( stdlib_memory_manager, size );
+#endif
}
void free( void *p )
{
+#ifdef OS_ABAOS
memory_manager_deallocate( stdlib_memory_manager, &p );
+#endif
}
+#ifdef OS_ABAOS
void __stdlib_set_memory_manager( memory_manager_t *memory_manager )
{
stdlib_memory_manager = memory_manager;
}
-
+#endif
diff --git a/src/libc/stdlib.h b/src/libc/stdlib.h
index ff6b67f..9507fa3 100644
--- a/src/libc/stdlib.h
+++ b/src/libc/stdlib.h
@@ -3,13 +3,17 @@
#include "stddef.h"
+#ifdef OS_ABAOS
#include "memorymanagement.h"
+#endif
char *itoa( int v, char *s, int base );
void *malloc( size_t size );
void free( void *p );
+#ifdef OS_ABAOS
void __stdlib_set_memory_manager( memory_manager_t *memory_manager );
+#endif
#endif // STDLIB_H
diff --git a/tests/libc/Makefile b/tests/libc/Makefile
index 2a7c53c..ce7e121 100644
--- a/tests/libc/Makefile
+++ b/tests/libc/Makefile
@@ -1,9 +1,6 @@
CC := gcc
CFLAGS := -std=c99 -m32 -ffreestanding -O0 -g -Wall -Werror
-# TODO: make sure we can test the libc library without kernel code,
-# this means we have to separate initializers like __stdio_init..
-# from the rest, also we have to provide a stub for kernel_panic
-INCLUDES = -I../../src/libc -I../../src/kernel -I../../src/hardware -I../../src/drivers -I../../src/drivers/hdi/ps2 -I../../src/drivers/video -I../../src/gui
+INCLUDES = -I../../src/libc
LD := ld
all: test
@@ -20,8 +17,8 @@ test_strlcat: test_strlcat.o ../../src/libc/string.o
test_strlcat.o: test_strlcat.c
$(CC) $(CFLAGS) $(INCLUDES) -c -o test_strlcat.o test_strlcat.c
-test_itoa: test_itoa.o ../../src/libc/stdlib.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o ../../src/kernel/kernel.o
- $(CC) -o test_itoa test_itoa.o ../../src/libc/stdlib.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o ../../src/kernel/kernel.o
+test_itoa: test_itoa.o ../../src/libc/stdlib.o ../../src/libc/string.o
+ $(CC) -o test_itoa test_itoa.o ../../src/libc/stdlib.o ../../src/libc/string.o
test_itoa.o: test_itoa.c ../../src/libc/stdlib.o
$(CC) $(CFLAGS) $(INCLUDES) -c -o test_itoa.o test_itoa.c
@@ -32,16 +29,10 @@ test_itoa.o: test_itoa.c ../../src/libc/stdlib.o
../../src/libc/stdlib.o: ../../src/libc/stdlib.c
$(CC) $(CFLAGS) $(INCLUDES) -c -o ../../src/libc/stdlib.o ../../src/libc/stdlib.c
-../../src/kernel/memorymanagement.o: ../../src/kernel/memorymanagement.c
- $(CC) $(CFLAGS) $(INCLUDES) -c -o ../../src/kernel/memorymanagement.o ../../src/kernel/memorymanagement.c
-
-../../src/kernel/kernel.o: ../../src/kernel/kernel.c
- $(CC) $(CFLAGS) $(INCLUDES) -c -o ../../src/kernel/kernel.o ../../src/kernel/kernel.c
-
test: test_strlcpy test_strlcat test_itoa
./test_strlcpy
./test_strlcat
./test_itoa
clean:
- -rm -f test_strlcpy test_strlcat test_itoa *.o
+ -rm -f test_strlcpy test_strlcat test_itoa ../../src/libc/stdlib.o ../../src/libc/string.o *.o