NOT TESTED YET

This commit is contained in:
Ada Orbit 2026-04-01 17:57:00 +02:00
parent fb9a47244e
commit 32265a5e25
3 changed files with 128 additions and 78 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ build-*/
binutils-*/
gcc-*/
*.tar.gz
sysroot/

156
README.md
View file

@ -6,25 +6,29 @@ Building and developing Ada applications for the **Casio fx-CG50**
The Casio fx-CG50 (from here on only called CG50) uses the SuperH architecture. Specifically a custom SH4-A chip. To be able to develope Add-ons, we first need to compile gcc with Ada and SuperH support.
> [!NOTE]
> This guide is mostly based on [Lephenixnoir](https://git.planet-casio.com/Lephenixnoir) guides for building fxSDK manually.
> I have changed a few parts to add Ada support _without_ an Ada Runtime (Later project)
## Building a GNAT cross compiler
We start by downloading the `binutils` and `gcc` source code.
```bash
# wget -O binutils.tar.gz "https://ftp.gnu.org/gnu/binutils/binutils-2.46.0.tar.gz"
# wget -O gcc.tar.gz "https://ftp.gnu.org/gnu/gcc/gcc-15.2.0/gcc-15.2.0.tar.gz"
# tar -xf binutils.tar.gz
# tar -xf gcc.tar.gz
wget -O binutils.tar.gz "https://ftp.gnu.org/gnu/binutils/binutils-2.46.0.tar.gz"
wget -O gcc.tar.gz "https://ftp.gnu.org/gnu/gcc/gcc-15.2.0/gcc-15.2.0.tar.gz"
tar -xf binutils.tar.gz
tar -xf gcc.tar.gz
```
> [!NOTE]
> I have tried gcc-14.1 but there were some problems with a missing `-gnatg` flag.
> Using gcc-15.2 solved the issue but I haven't tested other versions.
> You need a working ada compiler to compile ada. If you don't have gnat available in your repo, you can compile a stage1 gcc compiler.
> For my own sanity sake, I'll just assume that you already have gnat installed on your system.
Prepare the build environment to configure the tools.
```bash
# mkdir build-binutils build-gcc $(pwd)/sysroot
mkdir build-binutils build-gcc sysroot
```
`sysroot` is where _gcc_ and _binutils_ is going to be installed at. The `build-*` directories is where the tools are going to be build at. But before we do that we first have to configure them.
@ -33,73 +37,63 @@ Prepare the build environment to configure the tools.
```bash
cd build-binutils
../binutils-*/configure \
--prefix="$PREFIX" \
--target="sh3eb-elf" \
--with-multilib-list="m3,m4-nofpu" \
--program-prefix="sh-elf-" \
--disable-nls \
--disable-multilib \
--disable-shared \
--with-sysroot
../binutils-*/configure \
--prefix="$(sysroot)/../sysroot" \
--target="sh3eb-elf" \
--with-multilib-list="m3,m4-nofpu" \
--program-prefix="sh-elf-" \
--enable-libssp \
--enable-lto
```
You might ask yourself now why we chose these flags. Here I have tried to lay out _why_ we use some of these flags.
> [!NOTE]
> I couldn't figure out the usecase for all of these flags
> If you have to comments on which flags to use I'd be open to hear them!
| Flag | Meaning |
|----------------------- | ----------------------------------------------------- |
| --prefix | The install path. In our case it's `$(pwd)/sysroot` |
| --prefix | The install path. In our case it's `sysroot` |
| --target | What our target architecture is. The CG50 uses SuperH |
| --with-multilib-list | TODO: for what is that? |
| --program-prefix | prefix of the binuitls tools |
| --disable-nls | NO idea |
| --disable-shared | No Idea |
| --disable-multilib | No Idea |
| --with-sysroot | Set the sysroot |
| --enable-libssp | No Idea |
| --enable-lto | Link Time Optimization. Glue code faster together |
### Compiling binutils
We now compile `binutils` with our custom configuration using
```bash
# make configure-host
# make -j(nproc)
# make install-strip
make -j(nproc)
make install-strip
```
%TODO: What does configure-host do? why install-strip?
---
We now configure and install `gcc` using the same steps but with different flags.
### Configuring GCC
### Configuring GCC (Part 1)
We will first compile a working C cross compiler without a libc and add it later on to compile gcc with C++ and Ada support.
```bash
cd ../build-gcc
../gcc-*/configure \
--prefix="$(pwd)/sysroot" \
--target="sh3eb-elf" \
--with-multilib-list="m3,m4-nofpu" \
--enable-languages="ada,c,c++" \
--disable-libada \
--without-headers \
--program-prefix="sh-elf-" \
--enable-clocale="generic" \
--enable-libstdcxx-allocator \
--disable-threads \
--disable-libstdcxx-verbose \
--enable-cxx-flags="-fno-exceptions" \
--disable-nls \
--disable-multilib \
--disable-shared \
--without-headers
```
../gcc-*/configure \
--prefix="../sysroot" \
--target="sh3eb-elf" \
--with-multilib-list="m3,m4-nofpu" \
--enable-languages="c,c++,ada" \
--without-headers \
--program-prefix="sh-elf-" \
--enable-libssp \
--enable-lto \
--enable-clocale="generic" \
--enable-libstdcxx-allocator \
--disable-threads \
--disable-libstdcxx-verbose \
--enable-cxx-flags="-fno-exceptions"```
%TODO: Da fuck all these flags for? Which used did I use again? look at .zsh_history on desktop
TODO: Da fuck all these flags for?
| Column1 | Column2 |
|--------------- | --------------- |
| --disable-libada | We will be adding our own runtime |
@ -107,39 +101,73 @@ cd ../build-gcc
| Item1.3 | Item2.3 |
| Item1.4 | Item2.4 |
The first part of the compiler flags where from the Casio forum, focusing on c++ support. The second have where from the oswiki guide on making a gnat cross compiler.
### Compiling GCC
We now compile `gcc` the same way we did `binutils`.
```bash
# make -j(nproc) all-gcc all-target-libgcc
# make -j(nproc) -C gcc cross-gnattools ada.all.cross
# make install-strip-gcc install-strip-target-libgcc
make -j$(nproc) all-gcc all-target-libgcc
make install-strip-gcc install-strip-target-libgcc # TODO: may need to add Ada stuff?
```
%TODO: Why all-gcc and the other stuff? Look that up!
### Adding libc
We now have created our own custom Ada compiler that targets our chip!!! But being able to compile a program will not bring us far. We still have to package our binary in such a way that the OS of the CG50 can actually use it. That includes adding an icon and an App name. This step will be done later tho, as we want to integrate our compiler to gprbuild.
We will now install a libc implementation that works on the CG50. For that we will use [OpenLibm](https://git.planet-casio.com/Lephenixnoir/OpenLibm) and [fxlibc](https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc/)
```bash
COMPILER_DIR="$(sh-elf-gcc --print-file-name=.)" #TODO: maybe more elegant way to search for path?
LIBDIR="$COMPILER_DIR"
INCDIR="$COMPILER_DIR/include"
git clone https://git.planet-casio.com/Lephenixnoir/OpenLibm.git
cd OpenLibm
make USEGCC=1 TOOLPREFIX=sh-elf- AR=sh-elf-ar CC=sh-elf-gcc \
libdir="$LIBDIR" includedir="$INCDIR" \
install-static-superh install-headers-superh
```
Now we install the actual libc
```bash
git clone https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
cd fxlibc
cmake -B build-casiowin-cg -DFXLIBC_TARGET=casiowin-cg -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-sh.cmake -DCMAKE_INSTALL_PREFIX="$SYSROOT"
make -C build-casiowin-cg
make -C build-casiowin-cg install
```
> [!NOTE]
> There is also gint and vhex form the repo but those target also other calculators that I don't have access to.
> For my own sanity sake I'll just stick with the casiowin-cg
## Compiling GCC (Part 2)
Build now the c++ support with
```bash
make -j$(nproc) all-target-libstdc++-v3
make install-strip-target-libstdc++-v3
```
---
## Adding our custom compiler to GPRBuild
%TODO: follow osdev wiki guide and debug shit that aint worky worky
Maybe change database file or just straigt up make own gprbuild? IDk
TODO: look into ironclad gprbuild integration
Sources used:
- https://osdev.wiki/wiki/GNAT_Cross-Compiler
- https://www.planet-casio.com/Fr/forums/topic12970-1-tutoriel-installation-manuelle-de-gcc-et-du-fxsdk.html
- https://gcc.gnu.org/install/configure.html
- https://git.planet-casio.com/Lephenixnoir/fxsdk
---
Copyright (c) 2026 Ada Orbit. All Rights Reserved.
## TODO
Idea space thingy
Maybe try installing gcc the way Lephexnior does and just sneakally add --language=ada and no adalib to build everything?

49
build-gcc.sh Normal file → Executable file
View file

@ -1,7 +1,14 @@
#!/usr/bin/env bash
set -e
# Step 1. Download GCC and binutils source code
ADACASIO_BINUTILS_URL="https://ftp.gnu.org/gnu/binutils/binutils-2.46.0.tar.gz"
ADACASIO_GCC_URL="https://ftp.gnu.org/gnu/gcc/gcc-15.2.0/gcc-15.2.0.tar.gz"
ADACASIO_BINUTILS_VERSION="2.46.0"
ADACASIO_GCC_VERSION="15.2.0"
ADACASIO_BINUTILS_URL="https://ftp.gnu.org/gnu/binutils/binutils-$ADACASIO_BINUTILS_VERSION.tar.gz"
ADACASIO_GCC_URL="https://ftp.gnu.org/gnu/gcc/gcc-15.2.0/gcc-$ADACASIO_GCC_VERSION.tar.gz"
ADACASIO_PREFIX="$(pwd)/sysroot"
ADACASIO_TARGET="sh-elf"
# prepare configure and build enviornment
wget -O binutils.tar.gz $ADACASIO_BINUTILS_URL
@ -9,29 +16,43 @@ wget -O gcc.tar.gz $ADACASIO_GCC_URL
tar -xf binutils.tar.gz
tar -xf gcc.tar.gz
# Step 2. configure GCC and binutils
# Got the command list from https://git.planet-casio.com/Lephenixnoir/sh-elf-binutils Method 3
# Step 2. configure and build GCC and binutils
mkdir build-binutils build-gcc $ADACASIO_PREFIX
cd build-binutils
../binutils-*/configure \
--prefix="$PREFIX" \
--prefix="$ADACASIO_PREFIX" \
--target="sh3eb-elf" \
--with-multilib-list="m3,m4-nofpu" \
--program-prefix="sh3eb-elf-" \
--host="native" \
--disable-nls \
--disable-multilib \
--disable-shared \
--with-sysroot
--program-prefix="$ADACASIO_TARGET-" \
--enable-libssp \
--enable-lto
make -j$(nproc)
make install-strip
cd ../build-gcc
../gcc/configure \
--enable-languages="ada,c" \
# Build GCC the same way as Lephenixnoir does but also add ada
# https://git.planet-casio.com/Lephenixnoir/sh-elf-gcc
cd ../build-gcc/
../gcc-$VERSION/configure \
--prefix="$SYSROOT" \
--target="sh3eb-elf" \
--with-multilib-list="m3,m4-nofpu" \
--enable-languages="c,c++,ada" \
--disable-libada \
--without-headers \
--program-prefix="sh-elf-" \
--enable-libssp \
--enable-lto \
--enable-clocale="generic" \
--enable-libstdcxx-allocator \
--disable-threads \
--disable-libstdcxx-verbose \
--enable-cxx-flags="-fno-exceptions
--enable-cxx-flags="-fno-exceptions"
make -j$(nproc) all-gcc all-target-libgcc
make install-strip-gcc install-strip-target-libgcc
# TODO:
# install openlibm and fxlibc for C++ support later on