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