Skip to content

Introduce gas-sh4dsp-prizm target for fx-CG[10|20/50] calculators #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

seija-amanojaku
Copy link
Contributor

@seija-amanojaku seija-amanojaku commented Jun 24, 2025

This PR introduces a backend to compile freestanding and "libb-ful" B programs for fx-CG10/20/50 calculators (with CPUs based on a FPUless SH4).

EDIT: Division and modulo are implemented as calls to intrisic_div and intrisic_mod. To be completely frank, I think this is the best way to pull things off, since the SH-4 architecture is designed in such a way that division is best kept as an external routine.

It also effectively requires a working SuperH crosscompiler/fxgxa to generate a .g3a executable.

The main problems as of now are the lack of division/modulo (there are
instructions to do it, but its better to deal with them via intrisics or
something similar, due to code repetition)
Also made some add-in icon assets à la va-vite :3
The main (visible) ones I've seen were the following:
        - Lack of a malloc function (which could be implemented via
          existing syscalls)
        - Tests which *should* fail on this platform (i.e: assembly
          tests)

On a more invisible side, array indexing is surprisingly broken as of
now.
@seija-amanojaku
Copy link
Contributor Author

Most tests here do build properly (except for one due to PCrel issues), although I'd probably need to setup a proper basic SH-4 "emulator" to be completely sure.

Instead of being located at the end of a function, literals now litter
your code to be as close as possible.

This also now brings the buildable tests to pretty much every single one
which aren't designed to be platform-specific!

I just need a test SH4 runner, so if anyone wants to contribute, feel
free.
@seija-amanojaku
Copy link
Contributor Author

Just fixed PCrel issues relating to loading litterals, which now makes pretty much all tests at least build :3
I think that at this point, this is pretty much a decent target

a screenshot of btest, which shows that all tests, aside from those requiring assembly from non-SH4 targets do, infact, build (although they fail due to the lack of a proper runner)

@seija-amanojaku seija-amanojaku changed the title WIP: Introduce a toy "gas-sh4dsp-prizm" target for fx-CG[10|20/50] calculators Introduce gas-sh4dsp-prizm target for fx-CG[10|20/50] calculators Jun 26, 2025
@seija-amanojaku
Copy link
Contributor Author

i hate delay slots

seija-amanojaku and others added 13 commits June 27, 2025 14:19
This has the bare minimum to be running B programs, and, infact, runs
all tests properly :D
literals still won't work due to libb not being complete
(with all the talk going around about SSA, I may as well start to prepare :p)
Also removes the dependency on objcopy, as the linker script now just
emits a raw binary to be fed into fxgxa
It does seem like tests are building, but my local runners show a
runtime error(?!)
@seija-amanojaku
Copy link
Contributor Author

Got most of CI working out for this target (at least through nektos' act)
image

@lephe
Copy link

lephe commented Jul 6, 2025

This looks fun. Absolutely random remarks, may help, may not: linker script ROM size 2 MB, nothing "new" there any more, RAM always 512 kB (mapped by MMU), the small offset is related to data the OS puts in there but you can ignore it. All SH reads from memory are sign-extended and immediate-mov is too. PC-relative moves and branches in delay slots is an exception, if you trust your compiler to produce correct code there's no need to worry about it.

The detect_calculator is slightly weird, the constant in the middle of the function is unusual (also .align 4 is 16, and the zero write is dead?) Usually one would write something like:

_detect_calculator:
    mov.l   .L_ilram, r4
    mov     #69, r0
    mov.l   r0, @r4
    mov.l   @r4, r4
    cmp/eq  r0, r4
    rts
    movt    r0

.balign 4
.L_ilram: .long 0xE5200000

No need for rts after jmp in the syscalls since jmp is a tail call - the syscall code will itself return to your caller.

Please ping if you get something fun to work 👀

@rexim
Copy link
Member

rexim commented Jul 11, 2025

@seija-amanojaku sorry that it's taking so long to come to any conclusion on this PR. It's extremely cool, but depends on too much of exotic stuff. It either has to become more self-contained, or I need to finish decoupling the codegens from the compiler so we can put it in a separate repo. I'm slowly working on the decoupling.

I should start decoupling work
now its time to get rid of the GNU dependency
@nullnominal
Copy link
Contributor

@seija-amanojaku sorry that it's taking so long to come to any conclusion on this PR. It's extremely cool, but depends on too much of exotic stuff. It either has to become more self-contained, or I need to finish decoupling the codegens from the compiler so we can put it in a separate repo. I'm slowly working on the decoupling.

There is also bytecode in #184 for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants