diff --git a/README.md b/README.md index c7879e0f..6ace6537 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ You can choose between 3 run scripts: `tools/debug.sh` will run Luna in QEMU with a port open for GDB to connect to. (run `tools/build-debug.sh`, `tools/gdb.sh`, and then `tools/debug.sh` in a separate terminal for an optimal debugging experience) -Beware that running without hardware virtualization/with optimizations disabled may cause the kernel to behave differently, which is why I don't use it that often. +Beware that running with optimizations disabled may cause the kernel to behave differently, which is why I don't use it that often. Essentially, since `run.sh` builds the toolchain if it hasn't been built, builds Luna if it hasn't been built, and runs it, you could just checkout this repo, run `run.sh`, and you're done. No need for the other scripts. Those are included for more fine-grained control/building step-by-step. @@ -81,10 +81,9 @@ These images do reflect the latest changes on the `main` branch, but are obvious ## Is there third-party software I can use on Luna? Yes, actually! Check out the [ports](ports/) directory. -Right now, there are very few ports, because our C Library is quite primitive and doesn't support complex projects. -I'm in the process of trying to port the [GNU binutils](https://www.gnu.org/software/binutils/), though. +Right now, there are very few ports, because our C Library is a bit primitive and doesn't support complex projects. -You should also keep in mind that it is not possible to compile software written in any language other than C for Luna right now. +You should also keep in mind that it is not possible to compile software written in any language other than C/C++ (and C++ was added recently, its standard library doesn't work very well) for Luna right now. But feel free to try to port some program yourself and add it to the ports directory! diff --git a/ports/binutils/binutils.patch b/ports/binutils/binutils.patch new file mode 100644 index 00000000..6c8e94a6 --- /dev/null +++ b/ports/binutils/binutils.patch @@ -0,0 +1,144 @@ +diff --color -rN -u binutils-2.38/bfd/config.bfd binutils-2.38/bfd/config.bfd +--- a/binutils-2.38/bfd/config.bfd 2022-01-22 13:14:07.000000000 +0100 ++++ b/binutils-2.38/bfd/config.bfd 2022-11-09 16:09:46.143869977 +0100 +@@ -651,6 +651,11 @@ + targ_selvecs="iamcu_elf32_vec i386_pei_vec" + targ64_selvecs="x86_64_elf64_vec x86_64_elf32_vec x86_64_pe_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" + ;; ++ i[3-7]86-*-luna*) ++ targ_defvec=i386_elf32_vec ++ targ_selvecs= ++ targ64_selvecs=x86_64_elf64_vec ++ ;; + i[3-7]86-*-redox*) + targ_defvec=i386_elf32_vec + targ_selvecs= +@@ -706,6 +711,11 @@ + targ_selvecs="i386_elf32_vec iamcu_elf32_vec x86_64_elf32_vec i386_pei_vec x86_64_pe_vec x86_64_pei_vec l1om_elf64_vec k1om_elf64_vec" + want64=true + ;; ++ x86_64-*-luna*) ++ targ_defvec=x86_64_elf64_vec ++ targ_selvecs=i386_elf32_vec ++ want64=true ++ ;; + x86_64-*-mingw* | x86_64-*-pe | x86_64-*-pep | x86_64-*-cygwin) + targ_defvec=x86_64_pe_vec + targ_selvecs="x86_64_pe_vec x86_64_pei_vec x86_64_pe_big_vec x86_64_elf64_vec l1om_elf64_vec k1om_elf64_vec i386_pe_vec i386_pei_vec i386_elf32_vec iamcu_elf32_vec" +diff --color -rN -u binutils-2.38/gas/configure.tgt binutils-2.38/gas/configure.tgt +--- a/binutils-2.38/gas/configure.tgt 2022-01-22 13:14:08.000000000 +0100 ++++ b/binutils-2.38/gas/configure.tgt 2022-11-09 16:09:46.144869977 +0100 +@@ -238,6 +238,7 @@ + x86_64*-linux-gnux32) arch=x86_64:32 ;; + esac ;; + i386-*-lynxos*) fmt=elf em=lynx ;; ++ i386-*-luna*) fmt=elf em=gnu ;; + i386-*-redox*) fmt=elf ;; + i386-*-solaris*) fmt=elf em=solaris ;; + i386-*-freebsd* \ +diff --color -rN -u binutils-2.38/gas/messages.c binutils-2.38/gas/messages.c +--- a/binutils-2.38/gas/messages.c 2022-01-22 13:14:08.000000000 +0100 ++++ b/binutils-2.38/gas/messages.c 2022-11-09 16:26:03.275802078 +0100 +@@ -324,7 +324,9 @@ + signal_crash (int signo) + { + /* Reset, to prevent unbounded recursion. */ ++#ifndef __luna__ + signal (signo, SIG_DFL); ++#endif + + as_abort (NULL, 0, strsignal (signo)); + } +diff --color -rN -u binutils-2.38/ld/configure.tgt binutils-2.38/ld/configure.tgt +--- a/binutils-2.38/ld/configure.tgt 2022-01-22 15:19:36.000000000 +0100 ++++ b/binutils-2.38/ld/configure.tgt 2022-11-09 16:09:46.145869977 +0100 +@@ -329,6 +329,11 @@ + targ64_extra_emuls="elf_x86_64 elf32_x86_64 elf_l1om elf_k1om" + targ64_extra_libpath="elf_x86_64 elf32_x86_64" + ;; ++i[3-7]86-*-luna*) ++ targ_emul=elf_i386_luna ++ targ_extra_emuls=elf_i386 ++ targ64_extra_emuls="elf_x86_64_luna elf_x86_64" ++ ;; + i[3-7]86-*-redox*) targ_emul=elf_i386 + targ_extra_emuls=elf_x86_64 + ;; +@@ -967,6 +972,10 @@ + targ_extra_libpath="elf_i386 elf32_x86_64 elf_l1om elf_k1om" + tdir_elf_i386=`echo ${targ_alias} | sed -e 's/x86_64/i386/'` + ;; ++x86_64-*-luna*) ++ targ_emul=elf_x86_64_luna ++ targ_extra_emuls="elf_i386_luna elf_x86_64 elf_i386" ++ ;; + x86_64-*-redox*) targ_emul=elf_x86_64 + targ_extra_emuls=elf_i386 + ;; +diff --color -rN -u binutils-2.38/ld/emulparams/elf_i386_luna.sh binutils-2.38/ld/emulparams/elf_i386_luna.sh +--- a/binutils-2.38/ld/emulparams/elf_i386_luna.sh 1970-01-01 01:00:00.000000000 +0100 ++++ b/binutils-2.38/ld/emulparams/elf_i386_luna.sh 2022-11-09 16:09:46.145869977 +0100 +@@ -0,0 +1,3 @@ ++source_sh ${srcdir}/emulparams/elf_i386.sh ++TEXT_START_ADDR=0x08000000 ++MAXPAGESIZE=0x1000 +\ No newline at end of file +diff --color -rN -u binutils-2.38/ld/emulparams/elf_x86_64_luna.sh binutils-2.38/ld/emulparams/elf_x86_64_luna.sh +--- a/binutils-2.38/ld/emulparams/elf_x86_64_luna.sh 1970-01-01 01:00:00.000000000 +0100 ++++ b/binutils-2.38/ld/emulparams/elf_x86_64_luna.sh 2022-11-09 16:09:46.145869977 +0100 +@@ -0,0 +1,2 @@ ++source_sh ${srcdir}/emulparams/elf_x86_64.sh ++MAXPAGESIZE=0x1000 +\ No newline at end of file +diff --color -rN -u binutils-2.38/ld/Makefile.am binutils-2.38/ld/Makefile.am +--- a/binutils-2.38/ld/Makefile.am 2022-01-22 13:14:09.000000000 +0100 ++++ b/binutils-2.38/ld/Makefile.am 2022-11-09 16:09:46.145869977 +0100 +@@ -278,6 +278,7 @@ + eelf32xtensa.c \ + eelf32z80.c \ + eelf_i386.c \ ++ eelf_i386_luna.c \ + eelf_i386_be.c \ + eelf_i386_fbsd.c \ + eelf_i386_haiku.c \ +@@ -464,6 +465,7 @@ + eelf_x86_64_fbsd.c \ + eelf_x86_64_haiku.c \ + eelf_x86_64_sol2.c \ ++ eelf_x86_64_luna.c \ + ehppa64linux.c \ + ei386pep.c \ + emmo.c +diff --color -rN -u binutils-2.38/ld/Makefile.in binutils-2.38/ld/Makefile.in +--- a/binutils-2.38/ld/Makefile.in 2022-02-09 12:49:03.000000000 +0100 ++++ b/binutils-2.38/ld/Makefile.in 2022-11-09 16:09:46.146869977 +0100 +@@ -769,6 +769,7 @@ + eelf32xtensa.c \ + eelf32z80.c \ + eelf_i386.c \ ++ eelf_i386_luna.c \ + eelf_i386_be.c \ + eelf_i386_fbsd.c \ + eelf_i386_haiku.c \ +@@ -954,6 +955,7 @@ + eelf_x86_64_fbsd.c \ + eelf_x86_64_haiku.c \ + eelf_x86_64_sol2.c \ ++ eelf_x86_64_luna.c \ + ehppa64linux.c \ + ei386pep.c \ + emmo.c +diff --color -rN -u binutils-2.38/libiberty/pex-unix.c binutils-2.38/libiberty/pex-unix.c +--- a/binutils-2.38/libiberty/pex-unix.c 2022-01-22 13:14:09.000000000 +0100 ++++ b/binutils-2.38/libiberty/pex-unix.c 2022-11-09 16:25:21.767804963 +0100 +@@ -773,8 +773,10 @@ + { + /* If we are cleaning up when the caller didn't retrieve process + status for some reason, encourage the process to go away. */ ++#ifndef __luna__ + if (done) + kill (pid, SIGTERM); ++#endif + + if (pex_wait (obj, pid, status, time) < 0) + { diff --git a/ports/binutils/package.sh b/ports/binutils/package.sh new file mode 100644 index 00000000..e712b772 --- /dev/null +++ b/ports/binutils/package.sh @@ -0,0 +1,48 @@ +pkgname="binutils" +pkgver="2.38" +pkgurl="https://ftp.gnu.org/gnu/binutils/binutils-$pkgver.tar.xz" + +pkgmode="web" + +pkgdeps=('gmp' 'mpfr' 'mpc') + +setupdir="$workdir" +builddir="$workdir/build" +installdir="$workdir/build" +srcdir="$workdir/binutils-$pkgver" + +port_unpack() +{ + tar xvf binutils-$pkgver.tar.xz +} + +port_patch() +{ + patch -u -i $portdir/binutils.patch -p 1 -d $workdir +} + +port_configure() +{ + CFLAGS="-ffunction-sections -fdata-sections" LDFLAGS="-Wl,--gc-sections" $srcdir/configure --target=x86_64-luna --prefix="" --disable-werror --disable-nls --disable-dependency-tracking --with-build-sysroot=$LUNA_ROOT/base --host=x86_64-luna +} + +port_build() +{ + make -j$(nproc) +} + +port_install() +{ + make install-strip-binutils + rm -rf $DESTDIR/include/ + rm -rf $DESTDIR/lib/ + rm -rf $DESTDIR/share/ + rm -rf $DESTDIR/x86_64-luna/ + # keep only a few binaries since we only use an initial ramdisk for now, which doesn't like having many of these large binaries + rm -f $DESTDIR/bin/{ar,as,elfedit,gprof,ld,ld.bfd,objcopy,ranlib,strip} +} + +port_uninstall() +{ + rm -f $DESTDIR/bin/{addr2line,c++filt,nm,objdump,readelf,size,strings} +} \ No newline at end of file