main gen.h
 1#ifndef GEN_H_
 2#define GEN_H_
 3#include <stdint.h>
 4
 5#if defined(__x86_64__)
 6#define X86_64
 7#elif defined(__i386__)
 8#define X86_32
 9#else
10#error "The Wayland build requires an x86 host"
11#endif
12
13#if defined(X86_64) || defined(X86_32)
14typedef uint8_t code_word;
15#define RESERVE_WORDS 5 //opcode + 4-byte displacement
16#else
17typedef uint32_t code_word;
18#define RESERVE_WORDS 4 //1 push + 1 ldr + 1bx + 1 constant
19#endif
20typedef code_word * code_ptr;
21#define CODE_ALLOC_SIZE (1024*1024)
22
23typedef struct {
24	code_ptr cur;
25	code_ptr last;
26	uint32_t stack_off;
27} code_info;
28
29void check_alloc_code(code_info *code, uint32_t inst_size);
30
31void init_code_info(code_info *code);
32void call(code_info *code, code_ptr fun);
33void jmp(code_info *code, code_ptr dest);
34void jmp_r(code_info *code, uint8_t dst);
35//standard return from subroutine instruction
36void rts(code_info *code);
37//call a function and put the arguments in the appropriate place according to the host ABI
38void call_args(code_info *code, code_ptr fun, uint32_t num_args, ...);
39//like the above, but call a function pointer stored in a register
40void call_args_r(code_info *code, uint8_t fun_reg, uint32_t num_args, ...);
41//like the above, but follows other aspects of the ABI like stack alignment
42//void call_args_abi(code_info *code, code_ptr fun, uint32_t num_args, ...);
43#define call_args_abi call_args
44void save_callee_save_regs(code_info *code);
45void restore_callee_save_regs(code_info *code);
46
47#endif //GEN_H_