xref: /freebsd/sys/compat/x86bios/x86bios.h (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
1 /*-
2  * Copyright (c) 2009 Alex Keda <admin@lissyara.su>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 /*
29  * x86 registers were borrowed from x86emu.h x86emu_regs.h
30  * for compatibility.
31  */
32 
33 #ifndef _X86BIOS_H_
34 #define	_X86BIOS_H_
35 
36 #include <sys/endian.h>
37 #include <sys/systm.h>
38 #include <sys/types.h>
39 
40 #ifdef	__BIG_ENDIAN__
41 
42 struct x86_register32 {
43 	uint32_t		e_reg;
44 };
45 
46 struct x86_register16 {
47 	uint16_t		filler0;
48 	uint16_t		x_reg;
49 };
50 
51 struct x86_register8 {
52 	uint8_t			filler0;
53 	uint8_t			filler1;
54 	uint8_t			h_reg;
55 	uint8_t			l_reg;
56 };
57 
58 #else /* !__BIG_ENDIAN__ */
59 
60 struct x86_register32 {
61 	uint32_t		e_reg;
62 };
63 
64 struct x86_register16 {
65 	uint16_t		x_reg;
66 };
67 
68 struct x86_register8 {
69 	uint8_t			l_reg;
70 	uint8_t			h_reg;
71 };
72 
73 #endif /* __BIG_ENDIAN__ */
74 
75 union x86_register {
76 	struct x86_register32	I32_reg;
77 	struct x86_register16	I16_reg;
78 	struct x86_register8	I8_reg;
79 };
80 
81 struct x86regs {
82 	uint16_t		_pad0;		/* CS */
83 	uint16_t		_pad1;		/* DS */
84 	uint16_t		register_es;
85 	uint16_t		register_fs;
86 	uint16_t		register_gs;
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;
93 
94 	union x86_register	_pad3;		/* SP */
95 	union x86_register	register_bp;
96 	union x86_register	register_si;
97 	union x86_register	register_di;
98 };
99 
100 typedef struct x86regs	x86regs_t;
101 
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
111 
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
117 
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
123 
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
129 
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
135 
136 /* segment registers */
137 #define	R_ES		register_es
138 #define	R_FS		register_fs
139 #define	R_GS		register_gs
140 
141 #define	X86BIOS_PHYSTOSEG(x)	(((x) >> 4) & 0xff00)
142 #define	X86BIOS_PHYSTOOFF(x)	((x) & 0x0fff)
143 
144 __BEGIN_DECLS
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);
155 __END_DECLS
156 
157 #endif /* !_X86BIOS_H_ */
158