1

I'm building legacy code using the GNUARM C compiler and trying to resolve all the implicit declarations of functions.

I've come across some ARM specific functions and can't find the header file containing the declarations for these functions:

get_pc 
get_cpsr 
get_sp

I have searched the web and only came up with source code containing these functions without any non-standard include files.

I'll also settle for the function declarations.

Since I will also be porting the code to the Cygwin / Windows platform, what are the equivalent declarations for Cygwin GNU GCC?

Thanks.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
  • How are they used? They have x86 equivalents (%eip, eflags and %esp), but a direct translation is unlikely to yield the desired results unless it's just used for debugging. – user786653 Nov 04 '11 at 07:31
  • They are used as part of a self-check. The program would read the stack pointer register, and determine if the stack is overflowing. – Thomas Matthews Nov 04 '11 at 15:03

2 Answers2

3

Just write your own if you really need those functions, asm is easier than inline asm:

.globl get_pc
get_pc:
    mov r0,pc
    bx lr

.globl get_sp
get_sp:
    mov r0,sp
    bx lr

.globl get_cpsr
get_cpsr:
    mrs r0,cpsr
    bx lr

At least for arm. if you are porting to x86 and need the equivalents, I have to wonder what the code needs with those things anyway. the cpsr in particular you would likely have to change any code that uses the result as the status registers across processor vendors/families pretty much never match. The x86 equivalents should still be about the same level of effort, takes longer to do a google search and read the results than it is to just write the code (if you know the processor).

Depending on what your application is doing it is probably better to just comment out any code that calls those functions and/or uses the return value. I can imagine a few reasons why those items would be used, but it could get into architecture specific stuff and that is more involved than just porting a few register read functions. So what user786653 asked is the key question. How are these functions used? Not where can I find them but how are they used and why do you think you need them.

old_timer
  • 69,149
  • 8
  • 89
  • 168
  • The issue is not writing these functions. The issue is finding a declaration for these functions to remove compiler warnings. – Thomas Matthews Nov 04 '11 at 19:08
  • they are all 32 bit registers, uint32_t get_pc(void) uint32_t get_sp(), etc. should work yes? – old_timer Nov 05 '11 at 01:01
  • 2
    The `get_pc` function should probably have `mov r0,lr` or it'll just always return the address of the `get_pc` function. Also, take note that this will return the PC value unadjusted for the ARM's 'pipeline effect', which may or may not be what the OP expects (I'm not familiar with the GNU `get_pc()` intrinsic). – Michael Burr Nov 06 '11 at 22:09
2

Are you sure those are functions? I'm not very familiar with ARM, but those sound like compiler intrinsics to me. If you're moving to GCC, you might be better off replacing those with inline assembly.

DrGoldfire
  • 986
  • 9
  • 13
  • Or finding a matching [intrinsic/builtin](http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html#C-Extensions) – user786653 Nov 03 '11 at 18:57
  • The `get_pc` function returns the value in the Program Counter variable. Similarly for get_cpsr (ARM CPSR register) and get_sp (Stack Pointer). – Thomas Matthews Nov 03 '11 at 20:15
  • But those are registers, not variables. You can't access registers directly from a C function, you need either inline assembly or for the compiler to provide you some built-in intrinsics (which will sometimes be declared in a compiler-specific header and sometimes nowhere at all). I don't see any evidence that GCC provides the built-ins that you need (there are some ARM-related ones, but no equivalents of the ones you want), so I think you'll need some inline ASM for this. – DrGoldfire Nov 03 '11 at 20:30