blob: d4052634584975bdda5a59af56e671bd9a2f3b80 [file] [log] [blame]
Kevin O'Connore9161822014-04-05 09:11:45 -04001// Structure layout of cpu registers that the bios uses.
Kevin O'Connor9521e262008-07-04 13:04:29 -04002//
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'Connorb9c6a962013-09-14 13:01:30 -040010#include "types.h" // u16
Kevin O'Connorb9c6a962013-09-14 13:01:30 -040011#include "x86.h" // F_CF
12
Kevin O'Connor9f985422009-09-09 11:34:39 -040013
Kevin O'Connor9521e262008-07-04 13:04:29 -040014/****************************************************************
15 * Registers saved/restored in romlayout.S
16 ****************************************************************/
17
18#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; }; }
19
20// Layout of registers passed in to irq handlers. Note that this
21// layout corresponds to code in romlayout.S - don't change it here
22// without also updating the assembler code.
23struct bregs {
24 u16 ds;
25 u16 es;
Kevin O'Connor88db9fd2011-05-07 13:56:48 -040026 UREG(edi, di, di8u, di8l);
27 UREG(esi, si, si8u, si8l);
28 UREG(ebp, bp, bp8u, bp8l);
Kevin O'Connor9521e262008-07-04 13:04:29 -040029 UREG(ebx, bx, bh, bl);
30 UREG(edx, dx, dh, dl);
31 UREG(ecx, cx, ch, cl);
32 UREG(eax, ax, ah, al);
Kevin O'Connor9f985422009-09-09 11:34:39 -040033 struct segoff_s code;
Kevin O'Connor9521e262008-07-04 13:04:29 -040034 u16 flags;
35} PACKED;
36
37
38/****************************************************************
39 * Helper functions
40 ****************************************************************/
41
Kevin O'Connor9521e262008-07-04 13:04:29 -040042static inline void
43set_cf(struct bregs *regs, int cond)
44{
45 if (cond)
46 regs->flags |= F_CF;
47 else
48 regs->flags &= ~F_CF;
49}
50
51// Frequently used return codes
52#define RET_EUNSUPPORTED 0x86
53
54static inline void
55set_success(struct bregs *regs)
56{
57 set_cf(regs, 0);
58}
59
60static inline void
61set_code_success(struct bregs *regs)
62{
63 regs->ah = 0;
64 set_cf(regs, 0);
65}
66
67static inline void
Kevin O'Connordfefeb52009-12-13 13:04:17 -050068set_invalid_silent(struct bregs *regs)
Kevin O'Connor9521e262008-07-04 13:04:29 -040069{
70 set_cf(regs, 1);
71}
72
73static inline void
Kevin O'Connordfefeb52009-12-13 13:04:17 -050074set_code_invalid_silent(struct bregs *regs, u8 code)
Kevin O'Connor9521e262008-07-04 13:04:29 -040075{
76 regs->ah = code;
77 set_cf(regs, 1);
78}
79
Kevin O'Connor9521e262008-07-04 13:04:29 -040080#endif // bregs.h