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