Support %ebp register in 'struct bregs'.
[seabios.git] / src / bregs.h
1 // Structure layout of cpu registers the the bios uses.
2 //
3 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
4 //
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
6
7 #ifndef __BREGS_H
8 #define __BREGS_H
9
10 // CPU flag bitdefs
11 #define F_CF (1<<0)
12 #define F_ZF (1<<6)
13 #define F_IF (1<<9)
14
15 // CR0 flags
16 #define CR0_PG (1<<31) // Paging
17 #define CR0_CD (1<<30) // Cache disable
18 #define CR0_NW (1<<29) // Not Write-through
19 #define CR0_PE (1<<0)  // Protection enable
20
21
22 #ifndef __ASSEMBLY__
23
24 /****************************************************************
25  * Registers saved/restored in romlayout.S
26  ****************************************************************/
27
28 #include "types.h" // u16
29
30 #define UREG(ER, R, RH, RL) union { u32 ER; struct { u16 R; u16 R ## _hi; }; struct { u8 RL; u8 RH; u8 R ## _hilo; u8 R ## _hihi; }; }
31
32 // Layout of registers passed in to irq handlers.  Note that this
33 // layout corresponds to code in romlayout.S - don't change it here
34 // without also updating the assembler code.
35 struct bregs {
36     u16 ds;
37     u16 es;
38     UREG(edi, di, di_hi, di_lo);
39     UREG(esi, si, si_hi, si_lo);
40     UREG(ebp, bp, bp_hi, bp_lo);
41     UREG(ebx, bx, bh, bl);
42     UREG(edx, dx, dh, dl);
43     UREG(ecx, cx, ch, cl);
44     UREG(eax, ax, ah, al);
45     u16 ip;
46     u16 cs;
47     u16 flags;
48 } PACKED;
49
50
51 /****************************************************************
52  * Helper functions
53  ****************************************************************/
54
55 static inline void
56 set_cf(struct bregs *regs, int cond)
57 {
58     if (cond)
59         regs->flags |= F_CF;
60     else
61         regs->flags &= ~F_CF;
62 }
63
64 // Frequently used return codes
65 #define RET_EUNSUPPORTED 0x86
66
67 static inline void
68 set_success(struct bregs *regs)
69 {
70     set_cf(regs, 0);
71 }
72
73 static inline void
74 set_code_success(struct bregs *regs)
75 {
76     regs->ah = 0;
77     set_cf(regs, 0);
78 }
79
80 static inline void
81 set_fail_silent(struct bregs *regs)
82 {
83     set_cf(regs, 1);
84 }
85
86 static inline void
87 set_code_fail_silent(struct bregs *regs, u8 code)
88 {
89     regs->ah = code;
90     set_cf(regs, 1);
91 }
92
93 #define set_fail(regs)                          \
94     __set_fail((regs), __LINE__, __func__)
95 #define set_code_fail(regs, code)                               \
96     __set_code_fail((regs), (code) | (__LINE__ << 8), __func__)
97
98 // output.c
99 void __set_fail(struct bregs *regs, int lineno, const char *fname);
100 void __set_code_fail(struct bregs *regs, u32 linecode, const char *fname);
101
102 #endif // !__ASSEMBLY__
103
104 #endif // bregs.h