Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 3 | * BIOS emulator and interface |
| 4 | * to Realmode X86 Emulator Library |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 5 | * |
Kumar Gala | 4c2e3da | 2009-07-28 21:49:52 -0500 | [diff] [blame] | 6 | * Copyright (C) 2007 Freescale Semiconductor, Inc. |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 7 | * Jason Jin <Jason.jin@freescale.com> |
| 8 | * |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 9 | * Copyright (C) 1996-1999 SciTech Software, Inc. |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 10 | * |
| 11 | * ======================================================================== |
| 12 | * |
| 13 | * Permission to use, copy, modify, distribute, and sell this software and |
| 14 | * its documentation for any purpose is hereby granted without fee, |
| 15 | * provided that the above copyright notice appear in all copies and that |
| 16 | * both that copyright notice and this permission notice appear in |
| 17 | * supporting documentation, and that the name of the authors not be used |
| 18 | * in advertising or publicity pertaining to distribution of the software |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 19 | * without specific, written prior permission. The authors makes no |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 20 | * representations about the suitability of this software for any purpose. |
| 21 | * It is provided "as is" without express or implied warranty. |
| 22 | * |
| 23 | * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 24 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 25 | * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 26 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF |
| 27 | * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
| 28 | * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 29 | * PERFORMANCE OF THIS SOFTWARE. |
| 30 | * |
| 31 | * ======================================================================== |
| 32 | * |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 33 | * Language: ANSI C |
| 34 | * Environment: Any |
| 35 | * Developer: Kendall Bennett |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 36 | * |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 37 | * Description: Internal header file for the BIOS emulator library. |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 38 | * |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 39 | * Jason ported this file to u-boot, Added some architecture |
| 40 | * related Macro. |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 41 | * |
| 42 | ****************************************************************************/ |
| 43 | |
| 44 | #ifndef __BIOSEMUI_H |
| 45 | #define __BIOSEMUI_H |
| 46 | |
| 47 | #include "biosemu.h" |
| 48 | #include <asm/io.h> |
| 49 | /*---------------------- Macros and type definitions ----------------------*/ |
| 50 | |
Simon Glass | b3521f2 | 2014-11-14 20:56:42 -0700 | [diff] [blame] | 51 | #ifdef CONFIG_X86EMU_DEBUG |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 52 | #define DB(x) x |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 53 | #else |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 54 | #define DB(x) do{}while(0); |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 55 | #endif |
| 56 | |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 57 | #define BIOS_SEG 0xfff0 |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 58 | extern X86EMU_sysEnv _X86EMU_env; |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 59 | #define M _X86EMU_env |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 60 | |
| 61 | /* Macros to read and write values to x86 emulator memory. Memory is always |
| 62 | * considered to be little endian, so we use macros to do endian swapping |
| 63 | * where necessary. |
| 64 | */ |
| 65 | |
| 66 | #ifdef __BIG_ENDIAN__ |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 67 | #define readb_le(base) *((u8*)(base)) |
| 68 | #define readw_le(base) ((u16)readb_le(base) | ((u16)readb_le((base) + 1) << 8)) |
| 69 | #define readl_le(base) ((u32)readb_le((base) + 0) | ((u32)readb_le((base) + 1) << 8) | \ |
| 70 | ((u32)readb_le((base) + 2) << 16) | ((u32)readb_le((base) + 3) << 24)) |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 71 | #define writeb_le(base, v) *((u8*)(base)) = (v) |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 72 | #define writew_le(base, v) writeb_le(base + 0, (v >> 0) & 0xff), \ |
| 73 | writeb_le(base + 1, (v >> 8) & 0xff) |
| 74 | #define writel_le(base, v) writeb_le(base + 0, (v >> 0) & 0xff), \ |
| 75 | writeb_le(base + 1, (v >> 8) & 0xff), \ |
| 76 | writeb_le(base + 2, (v >> 16) & 0xff), \ |
| 77 | writeb_le(base + 3, (v >> 24) & 0xff) |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 78 | #else |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 79 | #define readb_le(base) *((u8*)(base)) |
| 80 | #define readw_le(base) *((u16*)(base)) |
| 81 | #define readl_le(base) *((u32*)(base)) |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 82 | #define writeb_le(base, v) *((u8*)(base)) = (v) |
| 83 | #define writew_le(base, v) *((u16*)(base)) = (v) |
| 84 | #define writel_le(base, v) *((u32*)(base)) = (v) |
| 85 | #endif |
| 86 | |
| 87 | /**************************************************************************** |
| 88 | REMARKS: |
| 89 | Function codes passed to the emulated I/O port functions to determine the |
| 90 | type of operation to perform. |
| 91 | ****************************************************************************/ |
| 92 | typedef enum { |
| 93 | REG_READ_BYTE = 0, |
| 94 | REG_READ_WORD = 1, |
| 95 | REG_READ_DWORD = 2, |
| 96 | REG_WRITE_BYTE = 3, |
| 97 | REG_WRITE_WORD = 4, |
| 98 | REG_WRITE_DWORD = 5 |
| 99 | } RegisterFlags; |
| 100 | |
| 101 | /**************************************************************************** |
| 102 | REMARKS: |
| 103 | Function codes passed to the emulated I/O port functions to determine the |
| 104 | type of operation to perform. |
| 105 | ****************************************************************************/ |
| 106 | typedef enum { |
| 107 | PORT_BYTE = 1, |
| 108 | PORT_WORD = 2, |
| 109 | PORT_DWORD = 3, |
| 110 | } PortInfoFlags; |
| 111 | |
| 112 | /**************************************************************************** |
| 113 | REMARKS: |
| 114 | Data structure used to describe the details for the BIOS emulator system |
| 115 | environment as used by the X86 emulator library. |
| 116 | |
| 117 | HEADER: |
| 118 | biosemu.h |
| 119 | |
| 120 | MEMBERS: |
Wolfgang Denk | 9c7e4b0 | 2007-08-06 02:17:36 +0200 | [diff] [blame] | 121 | type - Type of port access (1 = byte, 2 = word, 3 = dword) |
| 122 | defVal - Default power on value |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 123 | finalVal - Final value |
| 124 | ****************************************************************************/ |
| 125 | typedef struct { |
| 126 | u8 type; |
| 127 | u32 defVal; |
| 128 | u32 finalVal; |
| 129 | } BE_portInfo; |
| 130 | |
Simon Glass | 70f2030 | 2023-07-15 21:38:39 -0600 | [diff] [blame] | 131 | #define PM_inpb(port) inb(port) |
| 132 | #define PM_inpw(port) inw(port) |
| 133 | #define PM_inpd(port) inl(port) |
| 134 | #define PM_outpb(port, val) outb(val, port) |
| 135 | #define PM_outpw(port, val) outw(val, port) |
| 136 | #define PM_outpd(port, val) outl(val, port) |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 137 | |
| 138 | #define LOG_inpb(port) PM_inpb(port) |
| 139 | #define LOG_inpw(port) PM_inpw(port) |
| 140 | #define LOG_inpd(port) PM_inpd(port) |
Simon Glass | 70f2030 | 2023-07-15 21:38:39 -0600 | [diff] [blame] | 141 | #define LOG_outpb(port, val) PM_outpb(port, val) |
| 142 | #define LOG_outpw(port, val) PM_outpw(port, val) |
| 143 | #define LOG_outpd(port, val) PM_outpd(port, val) |
Jason Jin | ece92f8 | 2007-07-06 08:34:56 +0800 | [diff] [blame] | 144 | |
| 145 | /*-------------------------- Function Prototypes --------------------------*/ |
| 146 | |
| 147 | /* bios.c */ |
| 148 | |
| 149 | void _BE_bios_init(u32 * intrTab); |
| 150 | void _BE_setup_funcs(void); |
| 151 | |
| 152 | /* besys.c */ |
| 153 | #define DEBUG_IO() (M.x86.debug & DEBUG_IO_TRACE_F) |
| 154 | |
| 155 | u8 X86API BE_rdb(u32 addr); |
| 156 | u16 X86API BE_rdw(u32 addr); |
| 157 | u32 X86API BE_rdl(u32 addr); |
| 158 | void X86API BE_wrb(u32 addr, u8 val); |
| 159 | void X86API BE_wrw(u32 addr, u16 val); |
| 160 | void X86API BE_wrl(u32 addr, u32 val); |
| 161 | |
| 162 | u8 X86API BE_inb(X86EMU_pioAddr port); |
| 163 | u16 X86API BE_inw(X86EMU_pioAddr port); |
| 164 | u32 X86API BE_inl(X86EMU_pioAddr port); |
| 165 | void X86API BE_outb(X86EMU_pioAddr port, u8 val); |
| 166 | void X86API BE_outw(X86EMU_pioAddr port, u16 val); |
| 167 | void X86API BE_outl(X86EMU_pioAddr port, u32 val); |
| 168 | #endif |
| 169 | /* __BIOSEMUI_H */ |