AdaCasio/README.md
2026-04-15 19:23:44 +02:00

189 lines
5.9 KiB
Markdown

# AdaCasio
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
```
> [!NOTE]
> 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 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.
### Configuring binutils
```bash
cd build-binutils
../binutils-*/configure \
--prefix="$(pwd)/../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.
| Flag | Meaning |
|----------------------- | ----------------------------------------------------- |
| --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 |
| --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 -j$(nproc)
make install-strip
```
We now configure and install `gcc` using the same steps but with different flags.
### 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="c,c++,ada" \
--without-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"
```
TODO: Da fuck all these flags for?
| Column1 | Column2 |
|--------------- | --------------- |
| --disable-libada | We will be adding our own runtime |
| Item1.2 | Item2.2 |
| Item1.3 | Item2.3 |
| Item1.4 | Item2.4 |
### Compiling GCC
We now compile `gcc` the same way we did `binutils`.
```bash
make -j$(nproc) all-gcc all-target-libgcc
make install-strip-gcc install-strip-target-libgcc # TODO: may need to add Ada stuff?
```
We now have successfully cross compiled gcc. However we still need to add a libc and compile gnat.
For that we will have to install the required headers into the correct coresponding direcotry
```bash
cd ..
export PATH="$PATH:$(pwd)/sysroot/bin"
PREFIX="$(sh-elf-gcc --print-file-name=.)"
```
The `PREFIX` directory is where gcc is going to look for all the system headers.
### Adding libc
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 [libfxcg](https://github.com/Jonimoose/libfxcg.git)
```bash
git clone https://github.com/Jonimoose/libfxcg.git
cd libfxcg/libc
```
replace all the `sh3eb-` with `sh-elf`
```bash
make
cp lib/* ../sysroot/lib/
cp -r include/* ../sysroot/lib/gcc/sh3eb-elf/15.2.0/include/
```
Go back to build-gcc and run
```bash
make -C gcc cross-gnattools
make install-strip
```
> [!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)
> [!WARNING]
> Building gcc with c++ does not work
Build now the c++ support with
```bash
make -j$(nproc) all-target-libstdc++-v3
make install-strip-target-libstdc++-v3
```
---
## packaging the binary
We will need to build `mkg3a` to package the binary.
```bash
git clone https://gitlab.com/taricorp/mkg3a.git
mkdir build
cd build
cmake ..
make
make install/local # do not want to install it to the system but to
```
## Adding our custom compiler to GPRBuild
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
- https://prizm.cemetech.net/Mkg3a/
---
Copyright (c) 2026 Ada Orbit. All Rights Reserved.