E200 Thread Init

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
eshton
Posts: 5
Joined: Fri Oct 27, 2017 10:50 am
Has thanked: 2 times

E200 Thread Init

Post by eshton »

Hello,

I've been going through the powerpc port code in reference while porting a risc v board and there's a bit of the thread init code I don't understand.

After writing to the interrupt enable register, r31 is copied to r3 and r30 is copied to ctr but there I found no init of those regs( r30,r31) and the e200 documents make no specific mention of them in this context.

I found some documentation online that suggests linux uses r31 as the global pointer but this is specific to that kernel, OS X uses r13. Could someone point me in the right direction?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: E200 Thread Init

Post by Giovanni »

Hi,

Look in the thread context setup macro, those registers are initialized there:

Code: Select all

#define PORT_SETUP_CONTEXT(tp, wbase, wtop, pf, arg) {                      \
  uint8_t *sp = (uint8_t *)(wtop) - sizeof(struct port_eabi_frame);         \
  ((struct port_eabi_frame *)sp)->slink = 0;                                \
  ((struct port_eabi_frame *)sp)->shole = (uint32_t)_port_thread_start;     \
  (tp)->ctx.sp = (struct port_intctx *)(sp - sizeof(struct port_intctx));   \
  (tp)->ctx.sp->r31 = (regppc_t)(arg);                                      \
  (tp)->ctx.sp->r30 = (regppc_t)(pf);                                       \
}


The context structure is copied into registers on the first context switch. Those registers represent the thread start address and the thread argument pointer. This part is tricky and architecture-dependent, looking at other ports could help understand it, in PPC it looks complex because its EABI stack organization.

Is there any RISK V HW available? I would be interested trying it too.

Giovanni
eshton
Posts: 5
Joined: Fri Oct 27, 2017 10:50 am
Has thanked: 2 times

Re: E200 Thread Init

Post by eshton »

Well the Risc V specs don't include any type of stack organization, it's essentially an exercise left to implementors. Our cpu also doesn't address this so it's a software detail now. It seems that the most important requirement is that a consistent organization is followed.

I've heard of about 2 or so Risc V boards (Rocket and Spike I believe) but I haven't gotten my hands on any of them. I'm working with our board and referencing the ppc code; most of what I have is rather untested code.
Post Reply