blob: 577effc0e5b76b2164cada64091dcac02aa0d2fe [file] [log] [blame]
Kevin O'Connor9521e262008-07-04 13:04:29 -04001// Structure layout of cpu registers the the bios uses.
2//
3// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05005// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connor9521e262008-07-04 13:04:29 -04006
7#ifndef __BREGS_H
8#define __BREGS_H
9
Kevin O'Connor3eac0092008-11-16 09:59:32 -050010// CPU flag bitdefs
Kevin O'Connor3eac0092008-11-16 09:59:32 -050011#define F_CF (1<<0)
Kevin O'Connor05600342009-01-02 13:10:58 -050012#define F_ZF (1<<6)
13#define F_IF (1<<9)
Kevin O'Connor9eb21002012-01-29 13:30:56 -050014#define F_ID (1<<21)
Kevin O'Connor65e63422008-07-19 14:12:32 -040015
Kevin O'Connor3eac0092008-11-16 09:59:32 -050016// 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__
Kevin O'Connor9521e262008-07-04 13:04:29 -040024
Kevin O'Connor9f985422009-09-09 11:34:39 -040025#include "farptr.h" // struct segoff_s
26
Kevin O'Connor9521e262008-07-04 13:04:29 -040027/****************************************************************
28 * Registers saved/restored in romlayout.S
29 ****************************************************************/
30
Kevin O'Connor3eac0092008-11-16 09:59:32 -050031#include "types.h" // u16
32
Kevin O'Connor9521e262008-07-04 13:04:29 -040033#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.
38struct bregs {
39 u16 ds;
40 u16 es;
Kevin O'Connor88db9fd2011-05-07 13:56:48 -040041 UREG(edi, di, di8u, di8l);
42 UREG(esi, si, si8u, si8l);
43 UREG(ebp, bp, bp8u, bp8l);
Kevin O'Connor9521e262008-07-04 13:04:29 -040044 UREG(ebx, bx, bh, bl);
45 UREG(edx, dx, dh, dl);
46 UREG(ecx, cx, ch, cl);
47 UREG(eax, ax, ah, al);
Kevin O'Connor9f985422009-09-09 11:34:39 -040048 struct segoff_s code;
Kevin O'Connor9521e262008-07-04 13:04:29 -040049 u16 flags;
50} PACKED;
51
52
53/****************************************************************
54 * Helper functions
55 ****************************************************************/
56
Kevin O'Connor9521e262008-07-04 13:04:29 -040057static inline void
58set_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
69static inline void
70set_success(struct bregs *regs)
71{
72 set_cf(regs, 0);
73}
74
75static inline void
76set_code_success(struct bregs *regs)
77{
78 regs->ah = 0;
79 set_cf(regs, 0);
80}
81
82static inline void
Kevin O'Connordfefeb52009-12-13 13:04:17 -050083set_invalid_silent(struct bregs *regs)
Kevin O'Connor9521e262008-07-04 13:04:29 -040084{
85 set_cf(regs, 1);
86}
87
88static inline void
Kevin O'Connordfefeb52009-12-13 13:04:17 -050089set_code_invalid_silent(struct bregs *regs, u8 code)
Kevin O'Connor9521e262008-07-04 13:04:29 -040090{
91 regs->ah = code;
92 set_cf(regs, 1);
93}
94
Kevin O'Connor3eac0092008-11-16 09:59:32 -050095#endif // !__ASSEMBLY__
96
Kevin O'Connor9521e262008-07-04 13:04:29 -040097#endif // bregs.h