2 libco.armeabi (2013-04-05)
22 static thread_local uint32_t co_active_buffer[64];
23 static thread_local cothread_t co_active_handle;
26 #if defined(__thumb2__)
28 ".globl co_switch_arm\n"
29 ".globl _co_switch_arm\n"
32 ".type co_switch_arm, %function\n"
33 ".type _co_switch_arm, %function\n"
37 " stmia r1!, {r4, r5, r6, r7, r8, r9, r10, r11}\n"
38 " stmia r1!, {r3, lr}\n"
39 " ldmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11}\n"
40 " ldmfd r0!, { r3 }\n"
42 " ldmfd r0!, { r3 }\n"
47 ".globl co_switch_arm\n"
48 ".globl _co_switch_arm\n"
51 " stmia r1!, {r4, r5, r6, r7, r8, r9, r10, r11, sp, lr}\n"
52 " ldmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11, sp, pc}\n"
57 void co_switch_arm(cothread_t handle, cothread_t current);
59 cothread_t co_create(unsigned int size, void (*entrypoint)(void))
62 cothread_t handle = 0;
63 size = (size + 1023) & ~1023;
64 #if defined(__APPLE__) || HAVE_POSIX_MEMALIGN >= 1
65 if (posix_memalign(&handle, 1024, size + 256) < 0)
68 handle = memalign(1024, size + 256);
74 ptr = (uint32_t*)handle;
84 /* Align stack to 64-bit */
85 ptr[8] = (uintptr_t)ptr + size + 256 - 8; /* r13, stack pointer */
86 ptr[9] = (uintptr_t)entrypoint; /* r15, PC (link register r14 gets saved here). */
90 cothread_t co_active(void)
92 if (!co_active_handle)
93 co_active_handle = co_active_buffer;
94 return co_active_handle;
97 void co_delete(cothread_t handle)
102 void co_switch(cothread_t handle)
104 cothread_t co_previous_handle = co_active();
105 co_switch_arm(co_active_handle = handle, co_previous_handle);