Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libthr/arch/riscv/include/pthread_md.h
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | struct tcb { | ||||
struct pthread *tcb_thread; | struct pthread *tcb_thread; | ||||
}; | }; | ||||
/* Called from the thread to set its private data. */ | /* Called from the thread to set its private data. */ | ||||
static __inline void | static __inline void | ||||
_tcb_set(struct tcb *tcb) | _tcb_set(struct tcb *tcb) | ||||
{ | { | ||||
__asm __volatile("mv tp, %0" :: "r"((uint8_t *)tcb + TP_OFFSET)); | __asm __volatile("addi tp, %0, %1" :: "r"(tcb), "I"(TP_OFFSET)); | ||||
} | } | ||||
/* | /* | ||||
* Get the current tcb. | * Get the current tcb. | ||||
*/ | */ | ||||
static __inline struct tcb * | static __inline struct tcb * | ||||
_tcb_get(void) | _tcb_get(void) | ||||
{ | { | ||||
register uint8_t *_tp; | struct tcb *_tcb; | ||||
__asm __volatile("mv %0, tp" : "=r"(_tp)); | __asm __volatile("addi %0, tp, %1" : "=r"(_tcb) : "I"(-TP_OFFSET)); | ||||
return ((struct tcb *)(_tp - TP_OFFSET)); | return (_tcb); | ||||
} | } | ||||
static __inline struct pthread * | static __inline struct pthread * | ||||
_get_curthread(void) | _get_curthread(void) | ||||
{ | { | ||||
if (_thr_initial) | if (_thr_initial) | ||||
return (_tcb_get()->tcb_thread); | return (_tcb_get()->tcb_thread); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
#endif /* _PTHREAD_MD_H_ */ | #endif /* _PTHREAD_MD_H_ */ |