diff options
Diffstat (limited to 'src/lib/cothread/ppc.c')
-rw-r--r-- | src/lib/cothread/ppc.c | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/src/lib/cothread/ppc.c b/src/lib/cothread/ppc.c index f898e2d3634..637ad426ada 100644 --- a/src/lib/cothread/ppc.c +++ b/src/lib/cothread/ppc.c @@ -22,15 +22,15 @@ floating-point and AltiVec save/restore */ /* State format (offsets in 32-bit words) -+0 Pointer to swap code - Rest of function descriptor for entry function -+8 PC -+10 SP - Special regs - GPRs - FPRs - VRs - stack ++0 Pointer to swap code + Rest of function descriptor for entry function ++8 PC ++10 SP + Special regs + GPRs + FPRs + VRs + stack */ enum { state_size = 1024 }; @@ -56,7 +56,7 @@ or are directly to function */ #ifdef __cplusplus extern "C" #endif - + /* Swap code is in ppc.S */ void co_swap_asm( cothread_t, cothread_t ); #define CO_SWAP_ASM( x, y ) co_swap_asm( x, y ) @@ -285,15 +285,15 @@ static const uint32_t libco_ppc_code [] = { static uint32_t* co_create_( unsigned size, uintptr_t entry ) { uint32_t* t = (uint32_t*) malloc( size ); - + (void) entry; - + #if LIBCO_PPCDESC if ( t ) { /* Copy entry's descriptor */ memcpy( t, (void*) entry, sizeof (void*) * 3 ); - + /* Set function pointer to swap routine */ #ifdef LIBCO_PPC_ASM *(const void**) t = *(void**) &co_swap_asm; @@ -302,7 +302,7 @@ static uint32_t* co_create_( unsigned size, uintptr_t entry ) #endif } #endif - + return t; } @@ -310,54 +310,54 @@ cothread_t co_create( unsigned int size, void (*entry_)( void ) ) { uintptr_t entry = (uintptr_t) entry_; uint32_t* t = NULL; - + /* Be sure main thread was successfully allocated */ if ( co_active() ) { size += state_size + above_stack + stack_align; t = co_create_( size, entry ); } - + if ( t ) { uintptr_t sp; int shift; - + /* Save current registers into new thread, so that any special ones will - have proper values when thread is begun */ + have proper values when thread is begun */ CO_SWAP_ASM( t, t ); - + #if LIBCO_PPCDESC /* Get real address */ entry = (uintptr_t) *(void**) entry; #endif - + /* Put stack near end of block, and align */ sp = (uintptr_t) t + size - above_stack; sp -= sp % stack_align; - + /* On PPC32, we save and restore GPRs as 32 bits. For PPC64, we - save and restore them as 64 bits, regardless of the size the ABI - uses. So, we manually write pointers at the proper size. We always - save and restore at the same address, and since PPC is big-endian, - we must put the low byte first on PPC32. */ - + save and restore them as 64 bits, regardless of the size the ABI + uses. So, we manually write pointers at the proper size. We always + save and restore at the same address, and since PPC is big-endian, + we must put the low byte first on PPC32. */ + /* If uintptr_t is 32 bits, >>32 is undefined behavior, so we do two shifts - and don't have to care how many bits uintptr_t is. */ + and don't have to care how many bits uintptr_t is. */ #if LIBCO_PPC64 shift = 16; #else shift = 0; #endif - + /* Set up so entry will be called on next swap */ t [8] = (uint32_t) (entry >> shift >> shift); t [9] = (uint32_t) entry; - - t [10] = (uint32_t) (sp >> shift >> shift); + + t [10] = (uint32_t) (sp >> shift >> shift); t [11] = (uint32_t) sp; } - + return t; } @@ -370,23 +370,23 @@ static void co_init_( void ) { #if LIBCO_MPROTECT /* TODO: pre- and post-pad PPC code so that this doesn't make other - data executable and writable */ + data executable and writable */ long page_size = sysconf( _SC_PAGESIZE ); if ( page_size > 0 ) { uintptr_t align = page_size; uintptr_t begin = (uintptr_t) libco_ppc_code; uintptr_t end = begin + sizeof libco_ppc_code; - + /* Align beginning and end */ end += align - 1; end -= end % align; begin -= begin % align; - + mprotect( (void*) begin, end - begin, PROT_READ | PROT_WRITE | PROT_EXEC ); } #endif - + co_active_handle = co_create_( state_size, (uintptr_t) &co_switch ); } @@ -394,7 +394,7 @@ cothread_t co_active() { if ( !co_active_handle ) co_init_(); - + return co_active_handle; } @@ -402,6 +402,6 @@ void co_switch( cothread_t t ) { cothread_t old = co_active_handle; co_active_handle = t; - + CO_SWAP_ASM( t, old ); } |