blob: 82c4c3c85dbb43b4f2508cf992d2cf3dafd86151 [file] [log] [blame]
Kevin O'Connor3df600b2013-09-14 19:28:55 -04001// Misc function and variable declarations.
2#ifndef __STACKS_H
3#define __STACKS_H
4
5#include "types.h" // u32
6
Kevin O'Connor55215cd2014-04-11 11:20:41 -04007#define CALL32SMM_CMDID 0xb5
8#define CALL32SMM_ENTERID 0x1234
9#define CALL32SMM_RETURNID 0x5678
10
Kevin O'Connor3df600b2013-09-14 19:28:55 -040011// stacks.c
Kevin O'Connor55215cd2014-04-11 11:20:41 -040012extern int HaveSmmCall32;
Kevin O'Connor1389eee2014-09-29 19:08:57 -040013u32 call32(void *func, u32 eax, u32 errret);
Kevin O'Connor3df600b2013-09-14 19:28:55 -040014extern u8 ExtraStack[], *StackPos;
15u32 stack_hop(u32 eax, u32 edx, void *func);
16u32 stack_hop_back(u32 eax, u32 edx, void *func);
Kevin O'Connorfabc1b52014-09-29 19:18:25 -040017int on_extra_stack(void);
Kevin O'Connor3df600b2013-09-14 19:28:55 -040018struct bregs;
Kevin O'Connor79c3ab32014-09-30 00:11:38 -040019void farcall16(struct bregs *callregs);
20void farcall16big(struct bregs *callregs);
21void __call16_int(struct bregs *callregs, u16 offset);
Kevin O'Connor3df600b2013-09-14 19:28:55 -040022#define call16_int(nr, callregs) do { \
23 extern void irq_trampoline_ ##nr (); \
24 __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \
25 } while (0)
Kevin O'Connor43197a22014-06-06 13:49:33 -040026void reset(void);
Kevin O'Connor3df600b2013-09-14 19:28:55 -040027extern struct thread_info MainThread;
28struct thread_info *getCurThread(void);
29void yield(void);
30void yield_toirq(void);
Kevin O'Connord29ce622014-04-07 12:15:34 -040031void thread_init(void);
32int threads_during_optionroms(void);
Kevin O'Connor3df600b2013-09-14 19:28:55 -040033void run_thread(void (*func)(void*), void *data);
34void wait_threads(void);
35struct mutex_s { u32 isLocked; };
36void mutex_lock(struct mutex_s *mutex);
37void mutex_unlock(struct mutex_s *mutex);
38void start_preempt(void);
39void finish_preempt(void);
40int wait_preempt(void);
41void check_preempt(void);
Kevin O'Connor7f54bf72013-12-30 22:04:28 -050042u32 call32_params(void *func, u32 eax, u32 edx, u32 ecx, u32 errret);
Kevin O'Connor3df600b2013-09-14 19:28:55 -040043
Kevin O'Connorfabc1b52014-09-29 19:18:25 -040044// Inline functions
45
46// Check if a call to stack_hop_back is needed.
47static inline int
48need_hop_back(void)
49{
Kevin O'Connor80568252014-09-29 19:39:31 -040050 return !MODESEGMENT || on_extra_stack();
Kevin O'Connorfabc1b52014-09-29 19:18:25 -040051}
52
Kevin O'Connor3df600b2013-09-14 19:28:55 -040053#endif // stacks.h