summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordzwdz2023-02-23 15:38:17 +0100
committerdzwdz2023-02-23 15:38:17 +0100
commitc9daa8909313b020df57605d0bd50ac48b208d58 (patch)
tree7051752002999e648619bc91e4d99edfda7b9f01
parent5715a511fcd0490dfc74579ee95f88ef1877f021 (diff)
toolchain: update, move to a Camellia-specific toolchain
-rw-r--r--.gitignore3
-rw-r--r--.gitmodules7
-rw-r--r--Makefile19
-rwxr-xr-xport2
-rwxr-xr-xports/bin/cc2
-rw-r--r--ports/doom2
-rw-r--r--src/kernel/syscalls.c1
-rw-r--r--src/user/lib/elfload.c2
-rw-r--r--toolchain/.ignore2
m---------toolchain/binutils0
m---------toolchain/gcc0
-rwxr-xr-xtools/dep_builders/binutils47
-rwxr-xr-xtools/dep_builders/gcc55
13 files changed, 56 insertions, 86 deletions
diff --git a/.gitignore b/.gitignore
index 51d4fe8..a01d11b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
out
-toolchain/
+toolchain/prefix/
+toolchain/*-build/
diff --git a/.gitmodules b/.gitmodules
index a8a484d..9621900 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,10 @@
[submodule "src/user/app/ext2fs/ext2"]
path = src/user/app/ext2fs/ext2
url = https://github.com/dzwdz/ext2.git
+[submodule "toolchain/binutils"]
+ path = toolchain/binutils
+ url = https://github.com/dzwdz/camellia-binutils
+ branch = camellia
+[submodule "toolchain/gcc"]
+ path = toolchain/gcc
+ url = https://github.com/dzwdz/gcc
diff --git a/Makefile b/Makefile
index 0aee404..a917131 100644
--- a/Makefile
+++ b/Makefile
@@ -1,16 +1,17 @@
-PATH := $(shell pwd)/toolchain/bin/:$(PATH)
+PATH := $(shell pwd)/toolchain/prefix/bin/:$(PATH)
-AR = x86_64-elf-ar
-AS = x86_64-elf-as
-CC = x86_64-elf-gcc
+AR = x86_64-camellia-ar
+AS = x86_64-camellia-as
+CC = x86_64-camellia-gcc
CHECK = sparse
-CFLAGS += -g -std=gnu99 -ffreestanding -O2 -ftrack-macro-expansion=0
+CFLAGS += -g -std=gnu99 -O2 -ftrack-macro-expansion=0
CFLAGS += -Wall -Wextra -Wold-style-definition -Werror=implicit-function-declaration
CFLAGS += -Wno-address-of-packed-member -Werror=incompatible-pointer-types
CFLAGS += -Isrc/ -Isrc/shared/include/
-KERNEL_CFLAGS = $(CFLAGS) -mno-sse -mgeneral-regs-only
+KERNEL_CFLAGS = $(CFLAGS) -ffreestanding -mno-sse -mgeneral-regs-only
+LIBC_CFLAGS = $(CFLAGS) -Isrc/user/lib/include/ -ffreestanding
USER_CFLAGS = $(CFLAGS) -Isrc/user/lib/include/
SPARSEFLAGS = -Wno-non-pointer-null
@@ -149,9 +150,13 @@ out/obj/user/%.c.o: src/user/%.c
@mkdir -p $(@D)
@$(CC) $(USER_CFLAGS) -fPIC -c $^ -o $@
+out/obj/user/lib/%.c.o: src/user/lib/%.c
+ @mkdir -p $(@D)
+ @$(CC) $(LIBC_CFLAGS) -fPIC -c $^ -o $@
+
out/obj/user/lib/vendor/%.c.o: src/user/lib/vendor/%.c
@mkdir -p $(@D)
- @$(CC) $(USER_CFLAGS) -fPIC -c $^ -o $@ \
+ @$(CC) $(LIBC_CFLAGS) -fPIC -c $^ -o $@ \
-DLACKS_TIME_H -DLACKS_FCNTL_H -DLACKS_SYS_PARAM_H \
-DMAP_ANONYMOUS -DHAVE_MORECORE=0 -DNO_MALLOC_H \
-Wno-expansion-to-defined -Wno-old-style-definition
diff --git a/port b/port
index 2219d1c..053bf3b 100755
--- a/port
+++ b/port
@@ -2,7 +2,7 @@
set -eu
export REPO="$PWD"
export PREFIX="$REPO/out/initrd/usr/"
-export PATH="$REPO/ports/bin/:$REPO/toolchain/bin/:$PATH"
+export PATH="$REPO/ports/bin/:$REPO/toolchain/prefix/bin/:$PATH"
if [ $1 = deepclean ]; then
rm -rf ports/out/
diff --git a/ports/bin/cc b/ports/bin/cc
index 885b512..8f9a8c0 100755
--- a/ports/bin/cc
+++ b/ports/bin/cc
@@ -1,5 +1,5 @@
#!/bin/sh
-exec x86_64-elf-gcc -ffreestanding -fPIE \
+exec x86_64-camellia-gcc -fPIE \
-nostdlib -Wl,-pie -Wl,-no-dynamic-linker -T $REPO/src/user/linker.ld \
-I$REPO/src/ -I$REPO/src/shared/include/ -I$REPO/src/user/lib/include/ \
$* \
diff --git a/ports/doom b/ports/doom
index 774e6f6..0c10b08 100644
--- a/ports/doom
+++ b/ports/doom
@@ -147,4 +147,4 @@ case $1 in
install) (prep; make "CC=cc" && cp doomgeneric $PREFIX/bin/doom && cp DOOM1.WAD $PREFIX/) ;;
clean) (prep; make clean) ;;
*) echo "usage: $0 install|clean"; false ;;
-esac \ No newline at end of file
+esac
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 259b59f..0810720 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -319,6 +319,7 @@ void __user *_sys_memflag(void __user *addr, size_t len, int flags) {
addr = (userptr_t)((uintptr_t __force)addr & ~PAGE_MASK); // align to page boundary
if (flags & MEMFLAG_FINDFREE) {
+ // TODO space out page allocations to catch stupid bugs
addr = pagedir_findfree(pages, addr, len);
if (!(flags & MEMFLAG_PRESENT))
SYSCALL_RETURN((uintptr_t)addr);
diff --git a/src/user/lib/elfload.c b/src/user/lib/elfload.c
index cb7ce58..3862534 100644
--- a/src/user/lib/elfload.c
+++ b/src/user/lib/elfload.c
@@ -160,7 +160,7 @@ void elf_exec(void *base, char **argv, char **envp) {
void *exebase = elf_loadmem(ehdr);
if (!exebase) return;
- void *newstack = _sys_memflag((void*)0x11000, 0x1000, MEMFLAG_FINDFREE | MEMFLAG_PRESENT);
+ void *newstack = _sys_memflag((void*)0x11000, 0x1000, MEMFLAG_FINDFREE | MEMFLAG_PRESENT) + 0x1000 - 8;
if (!newstack) return;
_freejmp_chstack(exebase + ehdr->e_entry, exebase, elf_spread(ehdr) + 0x1000, (const char**)argv, envp, newstack);
diff --git a/toolchain/.ignore b/toolchain/.ignore
new file mode 100644
index 0000000..4dbdf6c
--- /dev/null
+++ b/toolchain/.ignore
@@ -0,0 +1,2 @@
+binutils
+gcc
diff --git a/toolchain/binutils b/toolchain/binutils
new file mode 160000
+Subproject 2b7ad6882f6df005e946e69f9ca762d094640ab
diff --git a/toolchain/gcc b/toolchain/gcc
new file mode 160000
+Subproject 9305ddf4b1e9b125abe13365b9c55775cc328d7
diff --git a/tools/dep_builders/binutils b/tools/dep_builders/binutils
index cd88f5c..3e6b7b7 100755
--- a/tools/dep_builders/binutils
+++ b/tools/dep_builders/binutils
@@ -1,47 +1,26 @@
#!/bin/sh
set -eu
-TOOL="binutils"
-VER="2.37"
-# this is ugly
-{ HASHES=$(cat) ; } <<'HASHES'
-c44968b97cd86499efbc4b4ab7d98471f673e5414c554ef54afa930062dbbfcb toolchain/cache/binutils-2.37.tar.gz
-HASHES
-
-export PREFIX="$(pwd)/toolchain/"
-export CACHE="$(pwd)/toolchain/cache/"
-export PATH="$(pwd)/toolchain/bin/:$PATH"
-export TARGET=x86_64-elf
-
-
# ensure that we're in the repo root
if [ ! -d .git ]; then
echo please cd to the repo\'s main directory
exit
fi
+export PREFIX="$(pwd)/toolchain/prefix/"
+export PATH="$(pwd)/toolchain/prefix/bin/:$PATH"
+BUILDDIR="$(pwd)/toolchain/binutils-build/"
+SYSROOT="$(pwd)/sysroot/"
mkdir -p $PREFIX
+mkdir -p $BUILDDIR
-echo "downloading missing files..."
-tools/dep_builders/dl "https://ftp.gnu.org/gnu/$TOOL/$TOOL-$VER.tar.gz"
-tools/dep_builders/dl "https://ftp.gnu.org/gnu/$TOOL/$TOOL-$VER.tar.gz.sig"
-tools/dep_builders/dl "https://ftp.gnu.org/gnu/gnu-keyring.gpg"
-
-echo "verifying signatures..."
-if ! gpg --verify --keyring toolchain/cache/gnu-keyring.gpg $CACHE/$TOOL-$VER.tar.gz.sig
-then
- echo "THE SIGNATURE COULDN'T BE VERIFIED. something's fishy."
- exit
-fi
-echo "$HASHES" | sha256sum --check || exit
-
-echo "unpacking the tarball..."
-tar xf toolchain/cache/$TOOL-$VER.tar.gz -C toolchain/cache
+cd $BUILDDIR
-echo "building..."
-rm -rf $CACHE/$TOOL-$VER/builddir
-mkdir $CACHE/$TOOL-$VER/builddir
-cd $CACHE/$TOOL-$VER/builddir
-../configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
-make
+../binutils/configure \
+ --target=x86_64-camellia \
+ --prefix="$PREFIX" \
+ --with-sysroot \
+ --disable-nls \
+ --disable-werror
+make -j4
make install
diff --git a/tools/dep_builders/gcc b/tools/dep_builders/gcc
index 6813abe..302bfdc 100755
--- a/tools/dep_builders/gcc
+++ b/tools/dep_builders/gcc
@@ -1,54 +1,29 @@
#!/bin/sh
set -eu
-TOOL="gcc"
-VER="11.2.0"
-# this is ugly
-{ HASHES=$(cat) ; } <<'HASHES'
-f0837f1bf8244a5cc23bd96ff6366712a791cfae01df8e25b137698aca26efc1 toolchain/cache/gcc-11.2.0.tar.gz
-HASHES
-
-export PREFIX="$(pwd)/toolchain/"
-export CACHE="$(pwd)/toolchain/cache/"
-export PATH="$(pwd)/toolchain/bin/:$PATH"
-export TARGET=x86_64-elf
-
-
# ensure that we're in the repo root
if [ ! -d .git ]; then
echo please cd to the repo\'s main directory
exit
fi
+export PREFIX="$(pwd)/toolchain/prefix/"
+export PATH="$(pwd)/toolchain/prefix/bin/:$PATH"
+BUILDDIR="$(pwd)/toolchain/gcc-build/"
+SYSROOT="$(pwd)/sysroot/"
mkdir -p $PREFIX
+mkdir -p $BUILDDIR
-echo "downloading missing files..."
-tools/dep_builders/dl "https://ftp.gnu.org/gnu/$TOOL/$TOOL-$VER/$TOOL-$VER.tar.gz"
-tools/dep_builders/dl "https://ftp.gnu.org/gnu/$TOOL/$TOOL-$VER/$TOOL-$VER.tar.gz.sig"
-tools/dep_builders/dl "https://ftp.gnu.org/gnu/gnu-keyring.gpg"
-
-echo "verifying signatures..."
-if ! gpg --verify --keyring toolchain/cache/gnu-keyring.gpg $CACHE/$TOOL-$VER.tar.gz.sig
-then
- echo "THE SIGNATURE COULDN'T BE VERIFIED. something's fishy."
- exit
-fi
-echo "$HASHES" | sha256sum --check || exit
-
-echo "unpacking the tarball..."
-tar xf toolchain/cache/$TOOL-$VER.tar.gz -C $CACHE
-
-echo "downloading required libraries..."
-cd $CACHE/$TOOL-$VER
-./contrib/download_prerequisites
-
-echo "building..."
-rm -rf $CACHE/$TOOL-$VER/builddir
-mkdir $CACHE/$TOOL-$VER/builddir
-cd $CACHE/$TOOL-$VER/builddir
+cd $BUILDDIR
-../configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c --without-headers
+../gcc/configure \
+ --target=x86_64-camellia \
+ --prefix="$PREFIX" \
+ --disable-nls \
+ --without-headers \
+ --enable-languages=c,c++ \
+ --disable-werror
make -j4 all-gcc
make -j4 all-target-libgcc
-make -j4 install-gcc
-make -j4 install-target-libgcc
+make install-gcc
+make install-target-libgcc