CLib support

Discuss development specific to the Pi version of ADFFS
JonAbbott
Posts: 2956
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

CLib support

Post by JonAbbott »

I've added support for CLib in the latest dev builds, although there are issues still to resolve.

CLib issues
  1. Works for the most part under StrongARM emulation if I let CallASWI's through to the OS, Populous for example runs okay. On physical SA however this wont work as SWI's that require managed entries aren't supported (see CallASWI issues)
  2. CLib makes extensive use of CallASWI (partly coded)
  3. _kernel_osfile needs hypervising (coded by untested)
  4. On the Pi there's odd behaviour. The Abort vectors are being entered in User mode, causing ADFFS to crash when it tries to perform TLB and cache operations
  5. C code of yore makes use of code self-modification. Codelets from modified code aren't currently reused, so eventually the codelet space is exhausted. The codelet generator needs to track freed codelet space and reuse it
CallASWI issues
  1. SWI's that require codelets aren't supported, so any kind of vector claim or Sound_Configure/Sound_InstallVoice for example will cause ADFFS to abort the process. The problem here is that the entry points associated with the SWI are within the codelet, which is tied to the SWI instruction. In the case of CallASWI this can't happen as it could be calling various SWI's, so the codelet in effect dynamically changes. Either vector entry points need recoding so they're not associated with a codelet, or a dummy codelet needs creating (coded for vectors using dummy codelets)
  2. SWI's that require hypervising need changing on route to CallASWI, so they come back to the hypervised SWI handler (coded)
  3. Needs to confirm the SWI issuer is within code created by the JIT or in the case of CLib calls, that the CLib caller is code created by the JIT
Additional issues
  1. FPU instructions aren't covered by the JIT - Quest for Gold is causing Floating Point Exceptions
NOTE: As of ADFFS 2.59, CLib is handled via localized copies of CLib 1.x and 5.x which run within the JIT environment, so no translation or Hypervising is required.
Vanfanel
Posts: 576
Joined: Mon Sep 16, 2013 12:01 am

Re: CLib support

Post by Vanfanel »

Should I start trying to run Elite soon? :D
JonAbbott
Posts: 2956
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: CLib support

Post by JonAbbott »

We're some way from that point, I need to get CLib working on StrongARM before I attempt to get it working on the Pi! Elite will also require Wimp support, so it's some way off.

Populous and Quest for Gold will be the first CLib games I aim to get working. I'll let you know when there's something to test.
JonAbbott
Posts: 2956
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: CLib support

Post by JonAbbott »

JonAbbott wrote:Quest for Gold is causing Floating Point Exceptions
After debugging this, I realised Co-pro load/store instructions require covering by the JIT (LDF / STF). After adding these however QfG crashes whilst loading, so requires further investigation.

I need to find detail on the FPU instruction set, as none of the ARM manuals I have list them.
richw
Posts: 159
Joined: Sat Sep 14, 2013 9:05 pm

Re: CLib support

Post by richw »

JonAbbott
Posts: 2956
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: CLib support

Post by JonAbbott »

richw wrote:I assume this isn't enough?
Exactly what I need, thanks.

Populous is now consistent on both StrongARM and the Pi in that it loads and plays the demo okay, starting a game immediately quits. It's working under StrongARM emulation, so fingers crossed, if I can figure out what's not being corrected by the JIT it will also work on the Pi. It has to be cache related, that's the only real difference between emulation and physical.

Armed with the FPU info, I'll now look at Quest for Glory next to see why adding LDF/STF support to the JIT is causing it to crash.
JonAbbott
Posts: 2956
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: CLib support

Post by JonAbbott »

JonAbbott wrote:I'll now look at Quest for Glory next to see why adding LDF/STF support to the JIT is causing it to crash.
Turned out to be a bug in the Undefined instruction handler, where it wasn't passing Co-pro instructions in codelets on. It now runs, although I think my implementation of _kernel_swi / _kernel_swi_c or OS_CallASWIR12 is slightly wrong as it now crashes when you start an event with the error "SWI &43F40 not known".

&43F40 is Joystick_Read, which should fail silently if not present. Somehow it's being called without X set.

EDIT: Turned out to be a noddy error, you have to clear the _kernel_NONX flag to set the X flag - obvious! Both Quest for Gold and Populous are now working perfectly under StrongARM emulation. I just need to figure out what's breaking them on physical.
JonAbbott
Posts: 2956
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: CLib support

Post by JonAbbott »

CLib support for APCS-R is now complete enough to get games running. Some functions aren't implemented, but will cleanly report an error through CLib should something try to use them. Unimplemented are:
  • Multiple language description blocks
  • _kernel_osfile (it is implemented, but will report as it needs testing)
  • _kernel_register_allocs
  • _kernel_moduleinit
  • _kernel_entermodule
  • _kernel_register_slotextend
  • atexit
  • _swi
  • _swix
Vanfanel
Posts: 576
Joined: Mon Sep 16, 2013 12:01 am

Re: CLib support

Post by Vanfanel »

Both Populous and Quest for Gold (both versions) seem to work fine on the Raspberry Pi! :)
Elite isn't working as expected (32 bit module error).
JonAbbott
Posts: 2956
Joined: Thu Apr 11, 2013 12:13 pm
Location: Essex
Contact:

Re: CLib support

Post by JonAbbott »

Vanfanel wrote:Both Populous and Quest for Gold (both versions) seem to work fine on the Raspberry Pi! :)
Cool, I'm just finishing off Populous for release then I'll get it and ADFFS 2.41 beta available.

I can't get Quest for Gold to work after inserting disc 2, it does the same thing on RO3.1 so its got to be either an issue with the boot script or ADFFS.
Vanfanel wrote:Elite isn't working as expected (32 bit module error).
Elite is a long way off, it still requires 26bit module and WIMP support before it will run. I'm going to look at WIMP support next.
Post Reply