From f31f7960bd260cb90ffdd766393d51bd85a547d1 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Fri, 14 Jul 2017 15:13:02 +0200 Subject: removed stddef.h and limits.h (come with the compiler header files) added a stub stdint.h (only sometimes comes with the compiler) added a guide on cross compiling adapted to cross compilation, for now tcc works --- README.CrossCompiling | 138 ++++++++++++++++++++++++++++++++++++++++++ src/README | 4 -- src/drivers/video/vga.h | 2 +- src/gui/composite_widget.c | 2 +- src/gui/desktop.c | 2 +- src/gui/text_widget.c | 2 +- src/gui/widget.c | 2 +- src/gui/window.c | 2 +- src/hardware/interrupts.h | 2 +- src/hardware/port.h | 2 +- src/kernel/console.c | 2 +- src/kernel/kernel.c | 2 +- src/kernel/memorymanagement.h | 3 +- src/kernel/tasks.h | 2 +- src/libc/limits.h | 7 --- src/libc/setjmp.h | 2 +- src/libc/stddef.h | 10 --- src/libc/stdint.h | 15 +++++ src/libc/stdio.c | 2 +- src/libc/stdio.h | 2 +- src/libc/stdlib.c | 2 +- src/libc/stdlib.h | 2 +- src/libc/string.h | 2 +- tests/libc/Makefile | 20 +++--- 24 files changed, 181 insertions(+), 50 deletions(-) create mode 100644 README.CrossCompiling delete mode 100644 src/libc/limits.h delete mode 100644 src/libc/stddef.h create mode 100644 src/libc/stdint.h diff --git a/README.CrossCompiling b/README.CrossCompiling new file mode 100644 index 0000000..67b5957 --- /dev/null +++ b/README.CrossCompiling @@ -0,0 +1,138 @@ +Intro +----- + +You can compile AbaOS from a 32-bit host or chroot (e.g. Arch32 chroot). +But you have to be extremly careful nothing from the host creeps into +the binaries. + +You can also create a cross-compilation environment. Not, we don't need +a full fledged chain, linker and compiler is enough. AbaOs has a small +integrated C library which is sufficient to build the kernel. + +gcc +--- + +mkdir -p $HOME/cross-compilers/gcc +cd $HOME/cross-compilers/gcc +wget https://ftp.gnu.org/gnu/binutils/binutils-2.28.tar.gz +tar xf binutils-2.28.tar.gz +mkdir binutils-build +cd binutils-build +../binutils-2.28/configure --target=i486-elf --prefix=$HOME/cross-compilers --disable-nls -v +make all +make check +make install +cd .. + +wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.lz +tar xf gmp-6.1.2.tar.lz +mkdir gmp-build +cd gmp-build +../gmp-6.1.2/configure --build=i486-elf --host=i486-elf --prefix=$HOME/cross-compilers +make all +make check +make install +cd .. + +wget http://www.mpfr.org/mpfr-current/mpfr-3.1.5.tar.gz +tar xf mpfr-3.1.5.tar.gz +mkdir mpfr-build +cd mpfr-build +../mpfr-3.1.5/configure -build=i486-elf --host=i486-elf --prefix=$HOME/cross-compilers \ + --with-gmp=$HOME/cross-compilers +make all +make check +make install +cd .. + +wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz +tar xf mpc-1.0.3.tar.gz +mkdir mpc-build +cd mpc-build +../mpc-1.0.3/configure --host=i486-elf --target=i486-elf \ + --prefix=$HOME/cross-compilers \ + --with-gmp=$HOME/cross-compilers \ + --with-mpfr=$HOME/cross-compilers +make all +make check +make install +cd .. + +wget ftp://ftp.mpi-sb.mpg.de/pub/gnu/mirror/gcc.gnu.org/pub/gcc/releases/gcc-7.1.0/gcc-7.1.0.tar.gz +tar zxf gcc-7.1.0.tar.gz +mkdir gcc-build +cd gcc-build +../gcc-7.1.0/configure --target=i486-elf --prefix=$HOME/cross-compilers \ + --with-gnu-as --with-gnu-ld \ + --disable-nls --enable-languages=c --disable-libgcj --without-headers \ + --with-gmp=$HOME/cross-compilers \ + --with-mpfr=$HOME/cross-compilers \ + --with-mpc=$HOME/cross-compilers +make all-gcc +make all-target-libgcc +make install-gcc +make install-target-libgcc + +tcc +--- + +mkdir -p $HOME/cross-compilers/tcc +cd $HOME/cross-compilers/tcc +wget https://ftp.gnu.org/gnu/binutils/binutils-2.28.tar.gz +tar xf binutils-2.28.tar.gz +mkdir binutils-build +cd binutils-build +../binutils-2.28/configure --target=i486-elf --prefix=$HOME/cross-compilers --disable-nls -v +make all +make check +make install +cd .. + +mkdir -p $HOME/cross-compilers/tcc +cd $HOME/cross-compilers/tcc +git clone git://repo.or.cz/tinycc.git +cd tinycc +./configure --cpu=i386 --enable-cross --prefix=$HOME/cross-compilers +make +cd .. + +setenv PATH "${PATH}:$HOME/cross-compilers" +make clean all CC=i386-tcc LD=i486-elf-ld + +pcc +--- + +mkdir -p $HOME/cross-compilers/pcc +cd $HOME/cross-compilers/pcc +wget https://ftp.gnu.org/gnu/binutils/binutils-2.28.tar.gz +tar xf binutils-2.28.tar.gz +mkdir binutils-build +cd binutils-build +../binutils-2.28/configure --target=i486-unknown-linux-gnu --prefix=$HOME/cross-compilers --disable-nls -v +make all +make check +make install +cd .. + +mkdir -p $HOME/cross-compilers/pcc +cvs -d :pserver:anonymous@pcc.ludd.ltu.se:/cvsroot co pcc-libs +mkdir pcc-libs-build +cd pcc-libs-build +../pcc-libs/configure --target=i486-unknown-linux-gnu --prefix=$HOME/cross-compilers +make +make install +cd .. + +cvs -d :pserver:anonymous@pcc.ludd.ltu.se:/cvsroot co pcc +mkdir pcc-build +cd pcc-build +../pcc/configure --target=i486-unknown-linux-gnu --prefix=$HOME/cross-compilers +make +make install + +Links +----- + +https://ftp.gnu.org/gnu/binutils/ +http://wiki.osdev.org/Target_Triplet +http://wiki.osdev.org/GCC_Cross-Compiler diff --git a/src/README b/src/README index 7b1b51c..a1c75e4 100644 --- a/src/README +++ b/src/README @@ -65,10 +65,6 @@ libc Stub C library implementation. -C library definitions -* stddef.h - definition of NULL, size_t -* limits.h - domain range constants like INT_MAX - C library routines * string.c - string, memory functions * stdlib.c - UNIX standard library functions diff --git a/src/drivers/video/vga.h b/src/drivers/video/vga.h index 0947856..9a637a2 100644 --- a/src/drivers/video/vga.h +++ b/src/drivers/video/vga.h @@ -4,7 +4,7 @@ #include #include "string.h" -#include "stddef.h" +#include #include "interrupts.h" #include "port.h" diff --git a/src/gui/composite_widget.c b/src/gui/composite_widget.c index 743360f..07056c0 100644 --- a/src/gui/composite_widget.c +++ b/src/gui/composite_widget.c @@ -1,7 +1,7 @@ #include "composite_widget.h" #include "string.h" -#include "stddef.h" +#include static composite_widget_vtable_t const composite_widget_vtable = { { diff --git a/src/gui/desktop.c b/src/gui/desktop.c index 98fb900..9851b78 100644 --- a/src/gui/desktop.c +++ b/src/gui/desktop.c @@ -1,7 +1,7 @@ #include "desktop.h" #include "string.h" -#include "stddef.h" +#include static desktop_vtable_t const desktop_vtable = { { diff --git a/src/gui/text_widget.c b/src/gui/text_widget.c index 49c1be7..5e468c7 100644 --- a/src/gui/text_widget.c +++ b/src/gui/text_widget.c @@ -1,7 +1,7 @@ #include "text_widget.h" #include "string.h" -#include "stddef.h" +#include static text_widget_vtable_t const text_widget_vtable = { { diff --git a/src/gui/widget.c b/src/gui/widget.c index 3620761..58b03ef 100644 --- a/src/gui/widget.c +++ b/src/gui/widget.c @@ -1,7 +1,7 @@ #include "widget.h" #include "string.h" -#include "stddef.h" +#include static widget_vtable_t const widget_vtable = { widget_draw, diff --git a/src/gui/window.c b/src/gui/window.c index 80c0b6c..fd53920 100644 --- a/src/gui/window.c +++ b/src/gui/window.c @@ -1,7 +1,7 @@ #include "window.h" #include "string.h" -#include "stddef.h" +#include static window_vtable_t const window_vtable = { { diff --git a/src/hardware/interrupts.h b/src/hardware/interrupts.h index c325d4f..64040cb 100644 --- a/src/hardware/interrupts.h +++ b/src/hardware/interrupts.h @@ -1,7 +1,7 @@ #ifndef INTERRUPTS_H #define INTERRUPTS_H -#include +#include "stdint.h" #include "port.h" #include "tasks.h" diff --git a/src/hardware/port.h b/src/hardware/port.h index ec96d09..8203fea 100644 --- a/src/hardware/port.h +++ b/src/hardware/port.h @@ -1,7 +1,7 @@ #ifndef PORT_H #define PORT_H -#include +#include "stdint.h" typedef struct { uint16_t number; // port number, e.g. 0x3d4 VGA index register diff --git a/src/kernel/console.c b/src/kernel/console.c index 8caefc8..04fb44f 100644 --- a/src/kernel/console.c +++ b/src/kernel/console.c @@ -1,7 +1,7 @@ #include "console.h" #include "string.h" -#include "stddef.h" +#include void console_init( console_t *console ) { diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 3be8758..a472cde 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -1,5 +1,5 @@ #include -#include +#include "stdint.h" #include #include "vgatext.h" diff --git a/src/kernel/memorymanagement.h b/src/kernel/memorymanagement.h index 647c05d..299fa4c 100644 --- a/src/kernel/memorymanagement.h +++ b/src/kernel/memorymanagement.h @@ -1,7 +1,8 @@ #ifndef MEMORYMANAGEMENT_H #define MEMORYMANAGEMENT_H -#include "stddef.h" +#include +#include "stdint.h" typedef struct { size_t offset; diff --git a/src/kernel/tasks.h b/src/kernel/tasks.h index dddf9bb..b982d13 100644 --- a/src/kernel/tasks.h +++ b/src/kernel/tasks.h @@ -1,7 +1,7 @@ #ifndef TASKS_H #define TASKS_H -#include +#include "stdint.h" #define TASK_STACK_SIZE 4096 diff --git a/src/libc/limits.h b/src/libc/limits.h deleted file mode 100644 index 1fc4e37..0000000 --- a/src/libc/limits.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef LIMITS_H -#define LIMITS_H - -#define INT_MAX 2147483647 -#define INT_MIN -2147483648 - -#endif // LIMITS_H diff --git a/src/libc/setjmp.h b/src/libc/setjmp.h index 5f987f1..4322124 100644 --- a/src/libc/setjmp.h +++ b/src/libc/setjmp.h @@ -1,7 +1,7 @@ #ifndef SETJMP_H #define SETJMP_H -#include +#include "stdint.h" // C99 states this should be an array so we can address it without // the & operator, see prototypes of setjmp and longjmp diff --git a/src/libc/stddef.h b/src/libc/stddef.h deleted file mode 100644 index 4333661..0000000 --- a/src/libc/stddef.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STDDEF_H -#define STDDEF_H - -#include - -#define NULL ( (void *)0 ) - -typedef uint32_t size_t; - -#endif /* STDDEF_H */ diff --git a/src/libc/stdint.h b/src/libc/stdint.h new file mode 100644 index 0000000..e0f35b6 --- /dev/null +++ b/src/libc/stdint.h @@ -0,0 +1,15 @@ +#ifndef STDINT_H +#define STDINT_H + +#if defined( __PCC__ ) || defined( __TINYC__ ) +// TODO: no stdint.h in pcc-libs/pcc or tcc, mock one, but this one is +// most likely very incorrect +typedef unsigned int uint32_t; +typedef signed int int32_t; +typedef unsigned short uint16_t; +typedef signed short int16_t; +typedef unsigned char uint8_t; +typedef signed char int8_t; +#endif + +#endif // STDINT_H diff --git a/src/libc/stdio.c b/src/libc/stdio.c index 631cfbb..87b70ef 100644 --- a/src/libc/stdio.c +++ b/src/libc/stdio.c @@ -1,5 +1,5 @@ #include "stdio.h" -#include "stddef.h" +#include #include "stdlib.h" #include "string.h" diff --git a/src/libc/stdio.h b/src/libc/stdio.h index 33d7946..58c80b1 100644 --- a/src/libc/stdio.h +++ b/src/libc/stdio.h @@ -3,7 +3,7 @@ #include -#include "stddef.h" +#include #ifdef OS_ABAOS #include "console.h" diff --git a/src/libc/stdlib.c b/src/libc/stdlib.c index 07eabd4..4fea56e 100644 --- a/src/libc/stdlib.c +++ b/src/libc/stdlib.c @@ -1,7 +1,7 @@ #include #include "string.h" #include "stdlib.h" -#include "stddef.h" +#include #include "kernel.h" diff --git a/src/libc/stdlib.h b/src/libc/stdlib.h index 5b2521f..f7cfc8c 100644 --- a/src/libc/stdlib.h +++ b/src/libc/stdlib.h @@ -1,7 +1,7 @@ #ifndef STDLIB_H #define STDLIB_H -#include "stddef.h" +#include #include "memorymanagement.h" diff --git a/src/libc/string.h b/src/libc/string.h index 6c0fa01..f078d48 100644 --- a/src/libc/string.h +++ b/src/libc/string.h @@ -1,7 +1,7 @@ #ifndef STRING_H #define STRING_H -#include "stddef.h" +#include void *memset( void *s, int c, size_t n ); void *memmove( void *d, const void *s, size_t n ); diff --git a/tests/libc/Makefile b/tests/libc/Makefile index 59fa715..d9d2927 100644 --- a/tests/libc/Makefile +++ b/tests/libc/Makefile @@ -1,48 +1,46 @@ CC := gcc DEFINES = -DOS_LINUX -INCLUDES = -I. -I../../src/libc -I../../src/kernel +INCLUDES = -I. -I../../src/libc -I../../src/kernel -I/home/abaumann/cross-compilers/include CFLAGS := -std=c99 -m32 -ffreestanding -O0 -g -Wall -Werror $(INCLUDES) $(DEFINES) -# tcc misses crt1.o from gcc?! and fails with _start symbol missing on -nostdlib, -# this seems very wrong.. -# TODO: for now test sanity of library tests with gcc and enabling -nostdlib -#LDFLAGS := -nostdlib +LD := ld +LDFLAGS := NASMFLAGS := -f elf32 NASM := nasm all: test test_strlcpy: test_strlcpy.o ../../src/libc/string.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o - $(CC) -o test_strlcpy test_strlcpy.o ../../src/libc/string.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o + $(LD) $(LDFLAGS) -o test_strlcpy test_strlcpy.o ../../src/libc/string.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o test_strlcpy.o: test_strlcpy.c $(CC) $(CFLAGS) -c -o test_strlcpy.o test_strlcpy.c test_strlcat: test_strlcat.o ../../src/libc/string.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o - $(CC) $(LDFLAGS) -o test_strlcat test_strlcat.o ../../src/libc/string.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o + $(LD) $(LDFLAGS) -o test_strlcat test_strlcat.o ../../src/libc/string.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o test_strlcat.o: test_strlcat.c $(CC) $(CFLAGS) -c -o test_strlcat.o test_strlcat.c test_itoa: test_itoa.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o - $(CC) $(LDFLAGS) -o test_itoa test_itoa.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o + $(LD) $(LDFLAGS) -o test_itoa test_itoa.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o test_itoa.o: test_itoa.c ../../src/libc/stdlib.h $(CC) $(CFLAGS) -c -o test_itoa.o test_itoa.c test_malloc: test_malloc.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o - $(CC) $(LDFLAGS) -o test_malloc test_malloc.o ../../src/libc/stdio.o ../../src/libc/stdlib.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o + $(LD) $(LDFLAGS) -o test_malloc test_malloc.o ../../src/libc/stdio.o ../../src/libc/stdlib.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o test_malloc.o: test_malloc.c ../../src/libc/stdlib.h $(CC) $(CFLAGS) -c -o test_malloc.o test_malloc.c test_printf: test_printf.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o - $(CC) $(LDFLAGS) -o test_printf test_printf.o ../../src/libc/stdio.o ../../src/libc/stdlib.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o + $(LD) $(LDFLAGS) -o test_printf test_printf.o ../../src/libc/stdio.o ../../src/libc/stdlib.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o test_printf.o: test_printf.c ../../src/libc/stdlib.h $(CC) $(CFLAGS) -c -o test_printf.o test_printf.c test_abort: test_abort.o ../../src/libc/stdlib.o ../../src/libc/stdio.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o - $(CC) $(LDFLAGS) -o test_abort test_abort.o ../../src/libc/stdio.o ../../src/libc/stdlib.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o + $(LD) $(LDFLAGS) -o test_abort test_abort.o ../../src/libc/stdio.o ../../src/libc/stdlib.o ../../src/libc/string.o ../../src/kernel/memorymanagement.o kernel_stub.o kernel_stub_asm.o test_abort.o: test_abort.c ../../src/libc/stdlib.h $(CC) $(CFLAGS) -c -o test_abort.o test_abort.c -- cgit v1.2.3-54-g00ecf