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