AdaCasio/README.md
2026-03-30 17:19:10 +02:00

145 lines
5 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.
## 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]
> 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.
Prepare the build environment to configure the tools.
```bash
# mkdir build-binutils build-gcc $(pwd)/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="$PREFIX" \
--target="sh3eb-elf" \
--with-multilib-list="m3,m4-nofpu" \
--program-prefix="sh-elf-" \
--disable-nls \
--disable-multilib \
--disable-shared \
--with-sysroot
```
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` |
| --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 |
### Compiling binutils
We now compile `binutils` with our custom configuration using
```bash
# make configure-host
# 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
```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
```
%TODO: Da fuck all these flags for? Which used did I use again? look at .zsh_history on desktop
| Column1 | Column2 |
|--------------- | --------------- |
| --disable-libada | We will be adding our own runtime |
| Item1.2 | Item2.2 |
| 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
```
%TODO: Why all-gcc and the other stuff? Look that up!
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.
---
## 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
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
Copyright (c) 2026 Ada Orbit. All Rights Reserved.