Changeset fca4207 in mainline


Ignore:
Timestamp:
2006-05-04T11:04:23Z (19 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4a7c273
Parents:
f33cb0b9
Message:

preliminary TLS & pthread support for ppc32

Location:
libc/arch/ppc32
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • libc/arch/ppc32/include/context_offset.h

    rf33cb0b9 rfca4207  
     1/* struct context */
     2#define OFFSET_SP    0x0
     3#define OFFSET_PC    0x4
     4#define OFFSET_R2    0x8
     5#define OFFSET_R13   0xc
     6#define OFFSET_R14   0x10
     7#define OFFSET_R15   0x14
     8#define OFFSET_R16   0x18
     9#define OFFSET_R17   0x1c
     10#define OFFSET_R18   0x20
     11#define OFFSET_R19   0x24
     12#define OFFSET_R20   0x28
     13#define OFFSET_R21   0x2c
     14#define OFFSET_R22   0x30
     15#define OFFSET_R23   0x34
     16#define OFFSET_R24   0x38
     17#define OFFSET_R25   0x3c
     18#define OFFSET_R26   0x40
     19#define OFFSET_R27   0x44
     20#define OFFSET_R28   0x48
     21#define OFFSET_R29   0x4c
     22#define OFFSET_R30   0x50
     23#define OFFSET_R31   0x54
     24#define OFFSET_CR    0x58
     25#define OFFSET_CR    0x58
  • libc/arch/ppc32/include/psthread.h

    rf33cb0b9 rfca4207  
    3232#include <types.h>
    3333
     34/* We define our own context_set, because we need to set
     35 * the TLS pointer to the tcb+0x7000
     36 *
     37 * See tls_set in thread.h
     38 */
    3439#define context_set(c, _pc, stack, size, ptls)                  \
    3540        (c)->pc = (sysarg_t) (_pc);                             \
    3641        (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA;     \
    37         (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t);
     42        (c)->tls = ((sysarg_t) (ptls)) + 0x7000 + sizeof(tcb_t);
    3843
    39 #define SP_DELTA        (8+16)
     44#define SP_DELTA        16
    4045
    41 typedef struct  {
     46typedef struct {
    4247        uint32_t sp;
    4348        uint32_t pc;
    4449       
    4550        uint32_t tls;
    46 } context_t;
     51        uint32_t r13;
     52        uint32_t r14;
     53        uint32_t r15;
     54        uint32_t r16;
     55        uint32_t r17;
     56        uint32_t r18;
     57        uint32_t r19;
     58        uint32_t r20;
     59        uint32_t r21;
     60        uint32_t r22;
     61        uint32_t r23;
     62        uint32_t r24;
     63        uint32_t r25;
     64        uint32_t r26;
     65        uint32_t r27;
     66        uint32_t r28;
     67        uint32_t r29;
     68        uint32_t r30;
     69        uint32_t r31;
     70       
     71        uint32_t cr;
     72} __attribute__ ((packed)) context_t;
    4773
    4874#endif
  • libc/arch/ppc32/include/thread.h

    rf33cb0b9 rfca4207  
    3030#define __LIBC__ppc32__THREAD_H__
    3131
     32/* I did not find any specification (neither MIPS nor PowerPC), but
     33 * as I found it
     34 * - it uses Variant II
     35 * - TCB is at Address(First TLS Block)+0x7000.
     36 * - DTV is at Address(First TLS Block)+0x8000
     37 * - What would happen if the TLS data was larger then 0x7000?
     38 * - The linker never accesses DTV directly, has the second definition any
     39 *   sense?
     40 * We will make it this way:
     41 * - TCB is at TP-0x7000-sizeof(tcb)
     42 * - No assumption about DTV etc., but it will not have a fixed address
     43 */
     44#define PPC_TP_OFFSET 0x7000
     45
    3246typedef struct {
    3347        void *pst_data;
     
    3650static inline void __tcb_set(tcb_t *tcb)
    3751{
     52        void *tp = tcb;
     53        tp += PPC_TP_OFFSET + sizeof(tcb_t);
     54       
     55        asm volatile (
     56                "mr %%r2, %0\n"
     57                :
     58                : "r" (tp)
     59        );
    3860}
    3961
    4062static inline tcb_t * __tcb_get(void)
    4163{
     64        void * retval;
     65       
     66        asm volatile (
     67                "mr %0, %%r2\n"
     68                : "=r" (retval)
     69        );
     70
     71        return (tcb_t *)(retval - PPC_TP_OFFSET - sizeof(tcb_t));
    4272}
    4373
  • libc/arch/ppc32/src/psthread.S

    rf33cb0b9 rfca4207  
    3232.global context_restore
    3333
     34#include <libarch/regname.h>
    3435#include <libarch/context_offset.h>
    3536
     37.macro CONTEXT_STORE r
     38        stw sp, OFFSET_SP(\r)
     39        stw r2, OFFSET_R2(\r)
     40        stw r13, OFFSET_R13(\r)
     41        stw r14, OFFSET_R14(\r)
     42        stw r15, OFFSET_R15(\r)
     43        stw r16, OFFSET_R16(\r)
     44        stw r17, OFFSET_R17(\r)
     45        stw r18, OFFSET_R18(\r)
     46        stw r19, OFFSET_R19(\r)
     47        stw r20, OFFSET_R20(\r)
     48        stw r21, OFFSET_R21(\r)
     49        stw r22, OFFSET_R22(\r)
     50        stw r23, OFFSET_R23(\r)
     51        stw r24, OFFSET_R24(\r)
     52        stw r25, OFFSET_R25(\r)
     53        stw r26, OFFSET_R26(\r)
     54        stw r27, OFFSET_R27(\r)
     55        stw r28, OFFSET_R28(\r)
     56        stw r29, OFFSET_R29(\r)
     57        stw r30, OFFSET_R30(\r)
     58        stw r31, OFFSET_R31(\r)
     59.endm
     60
     61.macro CONTEXT_LOAD r
     62        lwz sp, OFFSET_SP(\r)
     63        lwz r2, OFFSET_R2(\r)
     64        lwz r13, OFFSET_R13(\r)
     65        lwz r14, OFFSET_R14(\r)
     66        lwz r15, OFFSET_R15(\r)
     67        lwz r16, OFFSET_R16(\r)
     68        lwz r17, OFFSET_R17(\r)
     69        lwz r18, OFFSET_R18(\r)
     70        lwz r19, OFFSET_R19(\r)
     71        lwz r20, OFFSET_R20(\r)
     72        lwz r21, OFFSET_R21(\r)
     73        lwz r22, OFFSET_R22(\r)
     74        lwz r23, OFFSET_R23(\r)
     75        lwz r24, OFFSET_R24(\r)
     76        lwz r25, OFFSET_R25(\r)
     77        lwz r26, OFFSET_R26(\r)
     78        lwz r27, OFFSET_R27(\r)
     79        lwz r28, OFFSET_R28(\r)
     80        lwz r29, OFFSET_R29(\r)
     81        lwz r30, OFFSET_R30(\r)
     82        lwz r31, OFFSET_R31(\r)
     83.endm
     84
    3685context_save:
     86        CONTEXT_STORE r3
     87       
     88        mflr r4
     89        stw r4, OFFSET_PC(r3)
     90       
     91        mfcr r4
     92        stw r4, OFFSET_CR(r3)
     93       
     94        # context_save returns 1
     95        li r3, 1
    3796        blr
    3897
    3998
    4099context_restore:
     100        CONTEXT_LOAD r3
     101       
     102        lwz r4, OFFSET_CR(r3)
     103        mtcr r4
     104       
     105        lwz r4, OFFSET_PC(r3)
     106        mtlr r4
     107       
     108        # context_restore returns 0
     109        li r3, 0
    41110        blr
  • libc/arch/ppc32/src/thread.c

    rf33cb0b9 rfca4207  
    3434 * @param data Start of data section
    3535 * @return pointer to tcb_t structure
     36 *
    3637 */
    3738tcb_t * __alloc_tls(void **data, size_t size)
     
    4041       
    4142        *data = malloc(sizeof(tcb_t) + size);
    42 
    4343        tcb = (tcb_t *) (*data + size);
    44 
    4544        return tcb;
    4645}
Note: See TracChangeset for help on using the changeset viewer.