Misc fixes and updates.
[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 GPLv3 license.
6
7 #ifndef __BREGS_H
8 #define __BREGS_H
9
10 #include "types.h" // u16
11
12
13 /****************************************************************
14  * Registers saved/restored in romlayout.S
15  ****************************************************************/
16
17 #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; }; }
18
19 // Layout of registers passed in to irq handlers.  Note that this
20 // layout corresponds to code in romlayout.S - don't change it here
21 // without also updating the assembler code.
22 struct bregs {
23     u16 ds;
24     u16 es;
25     UREG(edi, di, di_hi, di_lo);
26     UREG(esi, si, si_hi, si_lo);
27     UREG(ebx, bx, bh, bl);
28     UREG(edx, dx, dh, dl);
29     UREG(ecx, cx, ch, cl);
30     UREG(eax, ax, ah, al);
31     u16 ip;
32     u16 cs;
33     u16 flags;
34 } PACKED;
35
36
37 /****************************************************************
38  * Helper functions
39  ****************************************************************/
40
41 // bregs flags bitdefs
42 #define F_ZF (1<<6)
43 #define F_CF (1<<0)
44
45 static inline void
46 set_cf(struct bregs *regs, int cond)
47 {
48     if (cond)
49         regs->flags |= F_CF;
50     else
51         regs->flags &= ~F_CF;
52 }
53
54 // Frequently used return codes
55 #define RET_EUNSUPPORTED 0x86
56
57 static inline void
58 set_success(struct bregs *regs)
59 {
60     set_cf(regs, 0);
61 }
62
63 static inline void
64 set_code_success(struct bregs *regs)
65 {
66     regs->ah = 0;
67     set_cf(regs, 0);
68 }
69
70 static inline void
71 set_fail_silent(struct bregs *regs)
72 {
73     set_cf(regs, 1);
74 }
75
76 static inline void
77 set_code_fail_silent(struct bregs *regs, u8 code)
78 {
79     regs->ah = code;
80     set_cf(regs, 1);
81 }
82
83 #define set_fail(regs) \
84     __set_fail(__func__, __LINE__, (regs))
85 #define set_code_fail(regs, code)               \
86     __set_code_fail(__func__, __LINE__, (regs), (code))
87
88 // output.c
89 void __set_fail(const char *fname, int lineno, struct bregs *regs);
90 void __set_code_fail(const char *fname, int lineno, struct bregs *regs, u8 code);
91
92 #endif // bregs.h