Load section address to cp

Technical questions regarding the XTC tools and programming with XMOS.
diltsman
Member++
Posts: 21
Joined: Sun Mar 03, 2013 11:26 pm

Load section address to cp

Post by diltsman »

I believe that the following code creates a section with the resource identifier for port 4f. I want to load this constant into a register. The ldw instruction takes an address relative to a section register so I think that I need to load the address of the section into cp. How would I load the cp register (yes, I use set, but I need the address first)? If that isn't the best way to do this, how would I go about it in a better way?

Code: Select all

  .section .cp.const4, "cM", @progbits, 4
.set XS1_PORT_4F, 0x40500
  .text
  .align 2
  .globl _start
_start:
  ldw r11, XS1_PORT_4F
  bu _start


User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

For programs following the usual ABI, the symbol _cp points to
the start of the CP section. You cannot load it with a single LDC
instruction, since the address is more than 16 bits. You can do e.g.

Code: Select all

ldap r11,_cp ; set cp,r11
diltsman
Member++
Posts: 21
Joined: Sun Mar 03, 2013 11:26 pm

Post by diltsman »

How would I load the base address of an arbitrary section into a register?
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

You arrange for some symbol to be equal to the starting address of
that section, and then you can use that symbol just like you use _cp.
diltsman
Member++
Posts: 21
Joined: Sun Mar 03, 2013 11:26 pm

Post by diltsman »

segher wrote:You arrange for some symbol to be equal to the starting address of
that section, and then you can use that symbol just like you use _cp.
Thanks. In retrospect this is obvious.