Kevin O'Connor | 3df600b | 2013-09-14 19:28:55 -0400 | [diff] [blame] | 1 | // Misc function and variable declarations. |
| 2 | #ifndef __STACKS_H |
| 3 | #define __STACKS_H |
| 4 | |
| 5 | #include "types.h" // u32 |
| 6 | |
Kevin O'Connor | 55215cd | 2014-04-11 11:20:41 -0400 | [diff] [blame] | 7 | #define CALL32SMM_CMDID 0xb5 |
| 8 | #define CALL32SMM_ENTERID 0x1234 |
| 9 | #define CALL32SMM_RETURNID 0x5678 |
| 10 | |
Kevin O'Connor | 3df600b | 2013-09-14 19:28:55 -0400 | [diff] [blame] | 11 | // stacks.c |
Kevin O'Connor | 55215cd | 2014-04-11 11:20:41 -0400 | [diff] [blame] | 12 | extern int HaveSmmCall32; |
Kevin O'Connor | b4cca86 | 2015-10-09 11:53:02 -0400 | [diff] [blame] | 13 | u32 __call32(void *func, u32 eax, u32 errret); |
| 14 | #define call32(func, eax, errret) ({ \ |
| 15 | extern void _cfunc32flat_ ##func (void); \ |
| 16 | __call32( _cfunc32flat_ ##func , (u32)(eax), (errret)); \ |
| 17 | }) |
Kevin O'Connor | 3df600b | 2013-09-14 19:28:55 -0400 | [diff] [blame] | 18 | extern u8 ExtraStack[], *StackPos; |
Kevin O'Connor | b4cca86 | 2015-10-09 11:53:02 -0400 | [diff] [blame] | 19 | u32 __stack_hop(u32 eax, u32 edx, void *func); |
| 20 | #define stack_hop(func, eax, edx) \ |
| 21 | __stack_hop((u32)(eax), (u32)(edx), (func)) |
| 22 | u32 __stack_hop_back(u32 eax, u32 edx, void *func); |
| 23 | #define stack_hop_back(func, eax, edx) ({ \ |
| 24 | extern void _cfunc16_ ##func (void); \ |
| 25 | __stack_hop_back((u32)(eax), (u32)(edx), _cfunc16_ ##func ); \ |
| 26 | }) |
Kevin O'Connor | fabc1b5 | 2014-09-29 19:18:25 -0400 | [diff] [blame] | 27 | int on_extra_stack(void); |
Kevin O'Connor | 3df600b | 2013-09-14 19:28:55 -0400 | [diff] [blame] | 28 | struct bregs; |
Kevin O'Connor | 79c3ab3 | 2014-09-30 00:11:38 -0400 | [diff] [blame] | 29 | void farcall16(struct bregs *callregs); |
| 30 | void farcall16big(struct bregs *callregs); |
| 31 | void __call16_int(struct bregs *callregs, u16 offset); |
Kevin O'Connor | 3df600b | 2013-09-14 19:28:55 -0400 | [diff] [blame] | 32 | #define call16_int(nr, callregs) do { \ |
Kevin O'Connor | b4cca86 | 2015-10-09 11:53:02 -0400 | [diff] [blame] | 33 | extern void irq_trampoline_ ##nr (void); \ |
Kevin O'Connor | 3df600b | 2013-09-14 19:28:55 -0400 | [diff] [blame] | 34 | __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \ |
| 35 | } while (0) |
Kevin O'Connor | 43197a2 | 2014-06-06 13:49:33 -0400 | [diff] [blame] | 36 | void reset(void); |
Kevin O'Connor | 3df600b | 2013-09-14 19:28:55 -0400 | [diff] [blame] | 37 | extern struct thread_info MainThread; |
| 38 | struct thread_info *getCurThread(void); |
| 39 | void yield(void); |
| 40 | void yield_toirq(void); |
Kevin O'Connor | 8b9942f | 2015-07-14 15:44:26 -0400 | [diff] [blame] | 41 | void thread_setup(void); |
Kevin O'Connor | d29ce62 | 2014-04-07 12:15:34 -0400 | [diff] [blame] | 42 | int threads_during_optionroms(void); |
Kevin O'Connor | 3df600b | 2013-09-14 19:28:55 -0400 | [diff] [blame] | 43 | void run_thread(void (*func)(void*), void *data); |
| 44 | void wait_threads(void); |
| 45 | struct mutex_s { u32 isLocked; }; |
| 46 | void mutex_lock(struct mutex_s *mutex); |
| 47 | void mutex_unlock(struct mutex_s *mutex); |
| 48 | void start_preempt(void); |
| 49 | void finish_preempt(void); |
| 50 | int wait_preempt(void); |
| 51 | void check_preempt(void); |
Kevin O'Connor | b4cca86 | 2015-10-09 11:53:02 -0400 | [diff] [blame] | 52 | u32 __call32_params(void *func, u32 eax, u32 edx, u32 ecx, u32 errret); |
| 53 | #define call32_params(func, eax, edx, ecx, errret) ({ \ |
| 54 | extern void _cfunc32flat_ ##func (void); \ |
| 55 | __call32_params( _cfunc32flat_ ##func , (u32)(eax), (u32)(edx) \ |
| 56 | , (u32)(ecx), (errret)); \ |
| 57 | }) |
Kevin O'Connor | 3df600b | 2013-09-14 19:28:55 -0400 | [diff] [blame] | 58 | |
Kevin O'Connor | fabc1b5 | 2014-09-29 19:18:25 -0400 | [diff] [blame] | 59 | // Inline functions |
| 60 | |
| 61 | // Check if a call to stack_hop_back is needed. |
| 62 | static inline int |
| 63 | need_hop_back(void) |
| 64 | { |
Kevin O'Connor | 8056825 | 2014-09-29 19:39:31 -0400 | [diff] [blame] | 65 | return !MODESEGMENT || on_extra_stack(); |
Kevin O'Connor | fabc1b5 | 2014-09-29 19:18:25 -0400 | [diff] [blame] | 66 | } |
| 67 | |
Kevin O'Connor | 3df600b | 2013-09-14 19:28:55 -0400 | [diff] [blame] | 68 | #endif // stacks.h |