blob: 9a381d0f95d5e6c262f99624c1dd04846d76b672 [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'Connor65e63422008-07-19 14:12:32 -040014
Kevin O'Connor3eac0092008-11-16 09:59:32 -050015// CR0 flags
16#define CR0_PG (1<<31) // Paging
17#define CR0_CD (1<<30) // Cache disable
18#define CR0_NW (1<<29) // Not Write-through
19#define CR0_PE (1<<0) // Protection enable
20
21
22#ifndef __ASSEMBLY__
Kevin O'Connor9521e262008-07-04 13:04:29 -040023
Kevin O'Connor9f985422009-09-09 11:34:39 -040024#include "farptr.h" // struct segoff_s
25
Kevin O'Connor9521e262008-07-04 13:04:29 -040026/****************************************************************
27 * Registers saved/restored in romlayout.S
28 ****************************************************************/
29
Kevin O'Connor3eac0092008-11-16 09:59:32 -050030#include "types.h" // u16
31
Kevin O'Connor9521e262008-07-04 13:04:29 -040032#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; }; }
33
34// Layout of registers passed in to irq handlers. Note that this
35// layout corresponds to code in romlayout.S - don't change it here
36// without also updating the assembler code.
37struct bregs {
38 u16 ds;
39 u16 es;
40 UREG(edi, di, di_hi, di_lo);
41 UREG(esi, si, si_hi, si_lo);
Kevin O'Connor7da210c2009-05-16 23:57:08 -040042 UREG(ebp, bp, bp_hi, bp_lo);
Kevin O'Connor9521e262008-07-04 13:04:29 -040043 UREG(ebx, bx, bh, bl);
44 UREG(edx, dx, dh, dl);
45 UREG(ecx, cx, ch, cl);
46 UREG(eax, ax, ah, al);
Kevin O'Connor9f985422009-09-09 11:34:39 -040047 struct segoff_s code;
Kevin O'Connor9521e262008-07-04 13:04:29 -040048 u16 flags;
49} PACKED;
50
51
52/****************************************************************
53 * Helper functions
54 ****************************************************************/
55
Kevin O'Connor9521e262008-07-04 13:04:29 -040056static inline void
57set_cf(struct bregs *regs, int cond)
58{
59 if (cond)
60 regs->flags |= F_CF;
61 else
62 regs->flags &= ~F_CF;
63}
64
65// Frequently used return codes
66#define RET_EUNSUPPORTED 0x86
67
68static inline void
69set_success(struct bregs *regs)
70{
71 set_cf(regs, 0);
72}
73
74static inline void
75set_code_success(struct bregs *regs)
76{
77 regs->ah = 0;
78 set_cf(regs, 0);
79}
80
81static inline void
Kevin O'Connordfefeb52009-12-13 13:04:17 -050082set_invalid_silent(struct bregs *regs)
Kevin O'Connor9521e262008-07-04 13:04:29 -040083{
84 set_cf(regs, 1);
85}
86
87static inline void
Kevin O'Connordfefeb52009-12-13 13:04:17 -050088set_code_invalid_silent(struct bregs *regs, u8 code)
Kevin O'Connor9521e262008-07-04 13:04:29 -040089{
90 regs->ah = code;
91 set_cf(regs, 1);
92}
93
Kevin O'Connor3eac0092008-11-16 09:59:32 -050094#endif // !__ASSEMBLY__
95
Kevin O'Connor9521e262008-07-04 13:04:29 -040096#endif // bregs.h