Kevin O'Connor | e916182 | 2014-04-05 09:11:45 -0400 | [diff] [blame] | 1 | // Structure layout of cpu registers that the bios uses. |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 2 | // |
| 3 | // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net> |
| 4 | // |
Kevin O'Connor | b1b7c2a | 2009-01-15 20:52:58 -0500 | [diff] [blame] | 5 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 6 | |
| 7 | #ifndef __BREGS_H |
| 8 | #define __BREGS_H |
| 9 | |
Kevin O'Connor | b9c6a96 | 2013-09-14 13:01:30 -0400 | [diff] [blame] | 10 | #include "types.h" // u16 |
Kevin O'Connor | b9c6a96 | 2013-09-14 13:01:30 -0400 | [diff] [blame] | 11 | #include "x86.h" // F_CF |
| 12 | |
Kevin O'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 13 | |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 14 | /**************************************************************** |
| 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. |
| 23 | struct bregs { |
| 24 | u16 ds; |
| 25 | u16 es; |
Kevin O'Connor | 88db9fd | 2011-05-07 13:56:48 -0400 | [diff] [blame] | 26 | UREG(edi, di, di8u, di8l); |
| 27 | UREG(esi, si, si8u, si8l); |
| 28 | UREG(ebp, bp, bp8u, bp8l); |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 29 | 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'Connor | 9f98542 | 2009-09-09 11:34:39 -0400 | [diff] [blame] | 33 | struct segoff_s code; |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 34 | u16 flags; |
| 35 | } PACKED; |
| 36 | |
| 37 | |
| 38 | /**************************************************************** |
| 39 | * Helper functions |
| 40 | ****************************************************************/ |
| 41 | |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 42 | static inline void |
| 43 | set_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 | |
| 54 | static inline void |
| 55 | set_success(struct bregs *regs) |
| 56 | { |
| 57 | set_cf(regs, 0); |
| 58 | } |
| 59 | |
| 60 | static inline void |
| 61 | set_code_success(struct bregs *regs) |
| 62 | { |
| 63 | regs->ah = 0; |
| 64 | set_cf(regs, 0); |
| 65 | } |
| 66 | |
| 67 | static inline void |
Kevin O'Connor | dfefeb5 | 2009-12-13 13:04:17 -0500 | [diff] [blame] | 68 | set_invalid_silent(struct bregs *regs) |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 69 | { |
| 70 | set_cf(regs, 1); |
| 71 | } |
| 72 | |
| 73 | static inline void |
Kevin O'Connor | dfefeb5 | 2009-12-13 13:04:17 -0500 | [diff] [blame] | 74 | set_code_invalid_silent(struct bregs *regs, u8 code) |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 75 | { |
| 76 | regs->ah = code; |
| 77 | set_cf(regs, 1); |
| 78 | } |
| 79 | |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 80 | #endif // bregs.h |