blob: c71bdc8e3957f4a5ccc929a6409026d8e9f2b12e [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'Connorb4cca862015-10-09 11:53:02 -040013u32 __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'Connor3df600b2013-09-14 19:28:55 -040018extern u8 ExtraStack[], *StackPos;
Kevin O'Connorb4cca862015-10-09 11:53:02 -040019u32 __stack_hop(u32 eax, u32 edx, void *func);
20#define stack_hop(func, eax, edx) \
21 __stack_hop((u32)(eax), (u32)(edx), (func))
22u32 __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'Connorfabc1b52014-09-29 19:18:25 -040027int on_extra_stack(void);
Kevin O'Connor3df600b2013-09-14 19:28:55 -040028struct bregs;
Kevin O'Connor79c3ab32014-09-30 00:11:38 -040029void farcall16(struct bregs *callregs);
30void farcall16big(struct bregs *callregs);
31void __call16_int(struct bregs *callregs, u16 offset);
Kevin O'Connor3df600b2013-09-14 19:28:55 -040032#define call16_int(nr, callregs) do { \
Kevin O'Connorb4cca862015-10-09 11:53:02 -040033 extern void irq_trampoline_ ##nr (void); \
Kevin O'Connor3df600b2013-09-14 19:28:55 -040034 __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \
35 } while (0)
Kevin O'Connor43197a22014-06-06 13:49:33 -040036void reset(void);
Kevin O'Connor3df600b2013-09-14 19:28:55 -040037extern struct thread_info MainThread;
38struct thread_info *getCurThread(void);
39void yield(void);
40void yield_toirq(void);
Kevin O'Connor8b9942f2015-07-14 15:44:26 -040041void thread_setup(void);
Kevin O'Connord29ce622014-04-07 12:15:34 -040042int threads_during_optionroms(void);
Kevin O'Connor3df600b2013-09-14 19:28:55 -040043void run_thread(void (*func)(void*), void *data);
44void wait_threads(void);
45struct mutex_s { u32 isLocked; };
46void mutex_lock(struct mutex_s *mutex);
47void mutex_unlock(struct mutex_s *mutex);
48void start_preempt(void);
49void finish_preempt(void);
50int wait_preempt(void);
51void check_preempt(void);
Kevin O'Connorb4cca862015-10-09 11:53:02 -040052u32 __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'Connor3df600b2013-09-14 19:28:55 -040058
Kevin O'Connorfabc1b52014-09-29 19:18:25 -040059// Inline functions
60
61// Check if a call to stack_hop_back is needed.
62static inline int
63need_hop_back(void)
64{
Kevin O'Connor80568252014-09-29 19:39:31 -040065 return !MODESEGMENT || on_extra_stack();
Kevin O'Connorfabc1b52014-09-29 19:18:25 -040066}
67
Kevin O'Connor3df600b2013-09-14 19:28:55 -040068#endif // stacks.h