2 * Copyright (c) 2009 Alex Keda <admin@lissyara.su>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * x86 registers were borrowed from x86emu.h x86emu_regs.h
36 #include <sys/endian.h>
37 #include <sys/systm.h>
38 #include <sys/types.h>
42 struct x86_register32 {
46 struct x86_register16 {
51 struct x86_register8 {
58 #else /* !__BIG_ENDIAN__ */
60 struct x86_register32 {
64 struct x86_register16 {
68 struct x86_register8 {
73 #endif /* __BIG_ENDIAN__ */
76 struct x86_register32 I32_reg;
77 struct x86_register16 I16_reg;
78 struct x86_register8 I8_reg;
82 uint16_t _pad0; /* CS */
83 uint16_t _pad1; /* DS */
87 uint16_t _pad2; /* SS */
88 uint32_t register_flags;
89 union x86_register register_a;
90 union x86_register register_b;
91 union x86_register register_c;
92 union x86_register register_d;
94 union x86_register _pad3; /* SP */
95 union x86_register register_bp;
96 union x86_register register_si;
97 union x86_register register_di;
100 typedef struct x86regs x86regs_t;
102 /* 8 bit registers */
103 #define R_AH register_a.I8_reg.h_reg
104 #define R_AL register_a.I8_reg.l_reg
105 #define R_BH register_b.I8_reg.h_reg
106 #define R_BL register_b.I8_reg.l_reg
107 #define R_CH register_c.I8_reg.h_reg
108 #define R_CL register_c.I8_reg.l_reg
109 #define R_DH register_d.I8_reg.h_reg
110 #define R_DL register_d.I8_reg.l_reg
112 /* 16 bit registers */
113 #define R_AX register_a.I16_reg.x_reg
114 #define R_BX register_b.I16_reg.x_reg
115 #define R_CX register_c.I16_reg.x_reg
116 #define R_DX register_d.I16_reg.x_reg
118 /* 32 bit extended registers */
119 #define R_EAX register_a.I32_reg.e_reg
120 #define R_EBX register_b.I32_reg.e_reg
121 #define R_ECX register_c.I32_reg.e_reg
122 #define R_EDX register_d.I32_reg.e_reg
124 /* special registers */
125 #define R_BP register_bp.I16_reg.x_reg
126 #define R_SI register_si.I16_reg.x_reg
127 #define R_DI register_di.I16_reg.x_reg
128 #define R_FLG register_flags
130 /* special registers */
131 #define R_EBP register_bp.I32_reg.e_reg
132 #define R_ESI register_si.I32_reg.e_reg
133 #define R_EDI register_di.I32_reg.e_reg
134 #define R_EFLG register_flags
136 /* segment registers */
137 #define R_ES register_es
138 #define R_FS register_fs
139 #define R_GS register_gs
141 #define X86BIOS_PHYSTOSEG(x) (((x) >> 4) & 0xff00)
142 #define X86BIOS_PHYSTOOFF(x) ((x) & 0x0fff)
145 void *x86bios_alloc(uint32_t *offset, size_t size, int flags);
146 void x86bios_call(struct x86regs *regs, uint16_t seg, uint16_t off);
147 void x86bios_free(void *addr, size_t size);
148 uint32_t x86bios_get_intr(int intno);
149 void *x86bios_get_orm(uint32_t offset);
150 void x86bios_init_regs(struct x86regs *regs);
151 void x86bios_intr(struct x86regs *regs, int intno);
152 int x86bios_match_device(uint32_t offset, device_t dev);
153 void *x86bios_offset(uint32_t offset);
154 void x86bios_set_intr(int intno, uint32_t saddr);
157 #endif /* !_X86BIOS_H_ */