grml...
[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 #define F_ID (1<<21)
15
16 // CR0 flags
17 #define CR0_PG (1<<31) // Paging
18 #define CR0_CD (1<<30) // Cache disable
19 #define CR0_NW (1<<29) // Not Write-through
20 #define CR0_PE (1<<0)  // Protection enable
21
22
23 #ifndef __ASSEMBLY__
24
25 #include "farptr.h" // struct segoff_s
26
27 /****************************************************************
28  * Registers saved/restored in romlayout.S
29  ****************************************************************/
30
31 #include "types.h" // u16
32
33 #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; }; }
34
35 // Layout of registers passed in to irq handlers.  Note that this
36 // layout corresponds to code in romlayout.S - don't change it here
37 // without also updating the assembler code.
38 struct bregs {
39     u16 ds;
40     u16 es;
41     UREG(edi, di, di8u, di8l);
42     UREG(esi, si, si8u, si8l);
43     UREG(ebp, bp, bp8u, bp8l);
44     UREG(ebx, bx, bh, bl);
45     UREG(edx, dx, dh, dl);
46     UREG(ecx, cx, ch, cl);
47     UREG(eax, ax, ah, al);
48     struct segoff_s code;
49     u16 flags;
50 } PACKED;
51
52
53 /****************************************************************
54  * Helper functions
55  ****************************************************************/
56
57 static inline void
58 set_cf(struct bregs *regs, int cond)
59 {
60     if (cond)
61         regs->flags |= F_CF;
62     else
63         regs->flags &= ~F_CF;
64 }
65
66 // Frequently used return codes
67 #define RET_EUNSUPPORTED 0x86
68
69 static inline void
70 set_success(struct bregs *regs)
71 {
72     set_cf(regs, 0);
73 }
74
75 static inline void
76 set_code_success(struct bregs *regs)
77 {
78     regs->ah = 0;
79     set_cf(regs, 0);
80 }
81
82 static inline void
83 set_invalid_silent(struct bregs *regs)
84 {
85     set_cf(regs, 1);
86 }
87
88 static inline void
89 set_code_invalid_silent(struct bregs *regs, u8 code)
90 {
91     regs->ah = code;
92     set_cf(regs, 1);
93 }
94
95 #endif // !__ASSEMBLY__
96
97 #endif // bregs.h