Author Topic: Prizm C libraries.  (Read 3001 times)

0 Members and 2 Guests are viewing this topic.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Prizm C libraries.
« on: May 26, 2011, 05:09:42 am »
Recently, Tari on Cemetech posted a short piece about programming Assembly for C libraries. In order to generate libraries usable in C programs, a specific format must be used. First of all, the registers are each assigned the following uses by GCC:

    - r0-r1     Stores function return value, caller saves.
    - r2-r3     Scratch space, caller saves.
    - r4-r7     Function parameters, caller saves.
    - r8-r13    Scratch, callee saves.
    - r14       Frame pointer, callee saves.
    - r15       Stack pointer, callee saves.
    - MACH,MACL Callee saves.

If an argument is more than 32 bits long, it's pushed onto the stack rather than split amongst different registers.

The format for a function in such a library is to declare the function global with the .global tag. An example of this would be this function to return the jump to a syscall:

Code: [Select]
.global _Syscall
     
/* Syscall(short <syscall number>) */
/* Jumps to the syscall */

    mov.l Table,r2
    shll2 r4
    mov.l @(r4+r2),r0
    jsr @r0
    nop
    nop
     
    Table: .long 0x805EDCA8

The code is then included in the compiled code with the #include <example.s> declaration.

Using this, I've been working on a few libraries recently to help with some of GCC's weak areas and other speed critical functions.

Partial list of implemented and planned functions for my math library (which I've actually had around for quite some time):

Modulus
Arbitrary precision addition
Arbitrary precision subtraction
Arbitrary precision multiplication
Arbitrary precision integer division
Hardware division
64 bit operations
Single precision Floating point operations
OS variable floating point operations
Integer Square root
Integer inverse square root
Floating point -> integer conversion
Integer->Floating point conversion
Floating point Absolute value (it's like two lines, but whatever :p)
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: Prizm C libraries.
« Reply #1 on: May 26, 2011, 10:23:16 am »
Good information there. One thing I was wondering was how to properly write inline asm functions for gcc. It is not the keyword inline that I'm having issues with, but just how the asm needs to be formatted. In a normal function I use RTS once it is finished, but on an inline function do I just skip that? Also I know gcc has some special rules when inserting x86 code into a program, but so far it doesn't seem like Super H gcc has that.

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)