diff options
author | Ian Moffett <ian@osmora.org> | 2024-06-24 23:00:41 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-06-24 23:00:41 -0400 |
commit | 963478ff0ad358fc3a44ff5dba0c64ddc889f296 (patch) | |
tree | a14c3ea6feb7d1b783364737fcefabce249473ff /tools | |
parent | 236963e7563be3e3f8220dac7bb4af446928e194 (diff) | |
parent | 6f6a36d1e8b3dd50cb4d394fa1de4888663b4ea5 (diff) |
Import hyra expt
Diffstat (limited to 'tools')
-rw-r--r-- | tools/cross.sh | 164 | ||||
-rw-r--r-- | tools/kconf/.gitignore | 4 | ||||
-rw-r--r-- | tools/kconf/Makefile | 9 | ||||
-rw-r--r-- | tools/kconf/grammer.y | 86 | ||||
-rw-r--r-- | tools/kconf/scan.l | 60 | ||||
-rwxr-xr-x | tools/ksyms | 12 | ||||
-rwxr-xr-x | tools/update-copyright | 11 |
7 files changed, 346 insertions, 0 deletions
diff --git a/tools/cross.sh b/tools/cross.sh new file mode 100644 index 0000000..52e7b1b --- /dev/null +++ b/tools/cross.sh @@ -0,0 +1,164 @@ +#!/bin/bash + +# +# Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Hyra nor the names of its contributors may be used +# to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +################################################################ +# Toolchain configuration +################################################################ + +set -e + +if [ "$1" == "amd64" ] +then + TARGET="x86_64-hyra" +else + TARGET="$1-elf" +fi + +BINUTILS_VERSION=2.42 +GCC_VERSION=13.2.0 +BINUTILS_NAME="binutils-$BINUTILS_VERSION" +BINUTILS_TARBALL="$BINUTILS_NAME.tar.xz" +BINUTILS_URL="https://ftp.gnu.org/gnu/binutils/$BINUTILS_TARBALL" +GCC_NAME="gcc-$GCC_VERSION" +GCC_TARBALL="$GCC_NAME.tar.xz" +GCC_URL="https://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/$GCC_TARBALL" + +# Remove debugging information, it takes up a lot of space +export CFLAGS="-g0" +export CXXFLAGS="-g0" + +# System-dependent configuration +SYSTEM_NAME="$(uname -s)" +MAKE="make" +NPROC="nproc" +if [ "$SYSTEM_NAME" = "OpenBSD" ]; then + MAKE="gmake" + NPROC="sysctl -n hw.ncpuonline" +elif [ "$SYSTEM_NAME" = "FreeBSD" ]; then + MAKE="gmake" + NPROC="sysctl -n hw.ncpu" +elif [ "$SYSTEM_NAME" = "Darwin" ]; then + NPROC="sysctl -n hw.ncpu" +fi +CORES="$($NPROC)" + +# Set build paths +PREFIX="$(pwd)/cross" +export PATH="$PREFIX/bin:$PATH" + +# Create build directory +mkdir -p "$PREFIX/build" +cd "$PREFIX/build" + +################################################################ +# Download and extract sources +################################################################ + +if [ ! -f $BINUTILS_TARBALL ]; then + echo "Downloading binutils..." + curl $BINUTILS_URL -o $BINUTILS_TARBALL +fi +if [ ! -f $GCC_TARBALL ]; then + echo "Downloading gcc..." + curl $GCC_URL -o $GCC_TARBALL +fi + +echo "Extracting binutils..." +rm -rf $BINUTILS_NAME +tar -xf $BINUTILS_TARBALL +echo "Extracting gcc..." +rm -rf $GCC_NAME +tar -xf $GCC_TARBALL + +################################################################ +# Build packages +################################################################ + +echo "Removing previous builds..." +rm -rf build-gcc build-binutils + +# Binutils build +clear +mkdir build-binutils + +echo "Applying binutils patch" +cp -r $BINUTILS_NAME $BINUTILS_NAME-copy +patch -s -p0 < ../../builddeps/binutils.patch +rm -rf $BINUTILS_NAME-copy + +echo "Configuring $BINUTILS_NAME..." +cd build-binutils +../$BINUTILS_NAME/configure --target="$TARGET" --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror --enable-targets=all +echo "Building $BINUTILS_NAME..." +$MAKE -j$CORES +echo "Installing $BINUTILS_NAME..." +$MAKE install +echo "Cleaning $BINUTILS_NAME..." +cd .. +rm -rf $BINUTILS_NAME build-binutils + +# GCC build +clear +echo "Downloading prerequisites for $GCC_NAME..." +cd $GCC_NAME +contrib/download_prerequisites +cd .. + +echo "Applying GCC patch" +cp -r $GCC_NAME $GCC_NAME-copy +patch -s -p0 < ../../builddeps/gcc.patch +rm -rf $GCC_NAME-copy + +echo "Configuring $GCC_NAME..." +mkdir build-gcc +cd build-gcc +../$GCC_NAME/configure --target="$TARGET" --with-sysroot=/ --prefix="$PREFIX" --disable-nls --enable-languages=c,c++,lto --disable-multilib +echo "Building all-gcc..." +$MAKE all-gcc -j"$CORES" +echo "Building all-target-libgcc..." +$MAKE all-target-libgcc -j"$CORES" +echo "Installing $GCC_NAME..." +$MAKE install-gcc +echo "Installing target-libgcc..." +$MAKE install-target-libgcc +echo "Cleaning $GCC_NAME..." +cd .. +rm -rf $GCC_NAME build-gcc + +################################################################ +# Cleanup +################################################################ + +clear +"$TARGET"-ld -v +"$TARGET"-gcc --version | head -n1 +echo "Build complete, binaries are in $PREFIX" +echo "Finished in $(($SECONDS / 60)) minutes and $(($SECONDS % 60)) seconds" diff --git a/tools/kconf/.gitignore b/tools/kconf/.gitignore new file mode 100644 index 0000000..4b51a2a --- /dev/null +++ b/tools/kconf/.gitignore @@ -0,0 +1,4 @@ +*.tab.c +*.tab.h +*.yy.c +kconf diff --git a/tools/kconf/Makefile b/tools/kconf/Makefile new file mode 100644 index 0000000..c6df7ee --- /dev/null +++ b/tools/kconf/Makefile @@ -0,0 +1,9 @@ +kconf: + bison -d grammer.y + flex scan.l + gcc lex.yy.c grammer.tab.c -lfl -o kconf + +clean: + rm grammer.tab.* + rm lex.yy.c + rm kconf diff --git a/tools/kconf/grammer.y b/tools/kconf/grammer.y new file mode 100644 index 0000000..2f131fc --- /dev/null +++ b/tools/kconf/grammer.y @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +%{ +#include <stdio.h> +#include <stdlib.h> + +int yylex(); +int yyerror(char *s); +%} + +%union { + char *str; + int num; +} + +%token OPTION SETVAL +%token <str> IDENTIFIER +%token YES NO +%token NUMBER STRING + +%type <str> str STRING +%type <num> yes_or_no YES NO +%type <num> num NUMBER + +%% + +input: + | line input + ; + +line: OPTION IDENTIFIER yes_or_no { + printf("-D__%s=%d ", $2, $3); + free($2); + } + | SETVAL IDENTIFIER num { + printf("-D__%s=%d " , $2, $3); + free($2); + } + | SETVAL IDENTIFIER str { + printf("-D__%s=%s ", $2, $3); + free($2); + free($3); + } + +yes_or_no: YES { $$ = 1; } + | NO { $$ = 0; } + ; + +num: NUMBER { $$ = $1; } +str: STRING { $$ = $1; } + +%% + +int +main(void) +{ + yyparse(); + printf("\n"); +} diff --git a/tools/kconf/scan.l b/tools/kconf/scan.l new file mode 100644 index 0000000..e416241 --- /dev/null +++ b/tools/kconf/scan.l @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023-2024 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +%{ + #include <stdio.h> + #include <stdlib.h> + #include "grammer.tab.h" + + int yyerror(char *e); +%} + +%% + +"option" { return OPTION; } +"setval" { return SETVAL; } +"yes" { return YES; } +"no" { return NO; } +\"([^\"])*\" { yylval.str = strdup(yytext); return STRING; } +[a-zA-Z_][a-zA-Z0-9_]+ { yylval.str = strdup(yytext); return IDENTIFIER; } +[0-9]+ { yylval.num = atoi(yytext); return NUMBER; } +[ \t] { /* Ignore */ } +[\/\/.*] { /* Ignore */ } +\n { /* IGnore */ } +"//".* { /* Ignore */ } +. { /* Ignore */ } + +%% + +int +yyerror(char *e) +{ + printf("\n** kconf: %s **", e); + return 0; +} diff --git a/tools/ksyms b/tools/ksyms new file mode 100755 index 0000000..643c3e1 --- /dev/null +++ b/tools/ksyms @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +rm -f $1 +printf "#ifndef _KSYMS_H_\n" > $1 +printf "#define _KSYMS_H_\n\n" >> $1 +printf "#include <sys/types.h>\n\nstruct kernel_symbol" >> $1 +printf " {\n\tuint64_t addr;\n\tchar* name;\n};\n\n" >> $1 +printf "const struct kernel_symbol g_ksym_table[] = {\n" >> $1 +nm $2 | grep " [tT] " | awk '{ print " { .addr = 0x"$1", .name = \""$3"\" }," }' | sort >> $1 +printf " { .addr = (size_t)-1, .name = \"\" }\n};\n\n" >> $1 +printf "const int ksym_elem_count = sizeof(g_ksym_table) / sizeof(*g_ksym_table);\n" >> $1 +printf "\n#endif /* !_KSYMS_H_ */\n" >> $1 diff --git a/tools/update-copyright b/tools/update-copyright new file mode 100755 index 0000000..0f2ba80 --- /dev/null +++ b/tools/update-copyright @@ -0,0 +1,11 @@ +#!/bin/bash + +# Set the current year as a variable +current_year=$(date +"%Y") + +# Find all files in the sys/ directory and its subdirectories +find . -type f -print0 | while read -d $'\0' file +do + # Replace the old copyright notice with the new one + sed -i "s/\(Copyright (c) \)2023-[0-9]\{4\}\(.*\)/\12023-${current_year}\2/g" "${file}" +done |