xref: /freebsd/sys/compat/x86bios/x86bios.h (revision 031beb4e239bfce798af17f5fe8dba8bcaf13d99)
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 /*
27  * x86 registers were borrowed from x86emu.h x86emu_regs.h
28  * for compatibility.
29  */
30 
31 #ifndef _X86BIOS_H_
32 #define	_X86BIOS_H_
33 
34 #include <sys/endian.h>
35 #include <sys/systm.h>
36 #include <sys/types.h>
37 
38 #ifdef	__BIG_ENDIAN__
39 
40 struct x86_register32 {
41 	uint32_t		e_reg;
42 };
43 
44 struct x86_register16 {
45 	uint16_t		filler0;
46 	uint16_t		x_reg;
47 };
48 
49 struct x86_register8 {
50 	uint8_t			filler0;
51 	uint8_t			filler1;
52 	uint8_t			h_reg;
53 	uint8_t			l_reg;
54 };
55 
56 #else /* !__BIG_ENDIAN__ */
57 
58 struct x86_register32 {
59 	uint32_t		e_reg;
60 };
61 
62 struct x86_register16 {
63 	uint16_t		x_reg;
64 };
65 
66 struct x86_register8 {
67 	uint8_t			l_reg;
68 	uint8_t			h_reg;
69 };
70 
71 #endif /* __BIG_ENDIAN__ */
72 
73 union x86_register {
74 	struct x86_register32	I32_reg;
75 	struct x86_register16	I16_reg;
76 	struct x86_register8	I8_reg;
77 };
78 
79 struct x86regs {
80 	uint16_t		_pad0;		/* CS */
81 	uint16_t		_pad1;		/* DS */
82 	uint16_t		register_es;
83 	uint16_t		register_fs;
84 	uint16_t		register_gs;
85 	uint16_t		_pad2;		/* SS */
86 	uint32_t		register_flags;
87 	union x86_register	register_a;
88 	union x86_register	register_b;
89 	union x86_register	register_c;
90 	union x86_register	register_d;
91 
92 	union x86_register	_pad3;		/* SP */
93 	union x86_register	register_bp;
94 	union x86_register	register_si;
95 	union x86_register	register_di;
96 };
97 
98 typedef struct x86regs	x86regs_t;
99 
100 /* 8 bit registers */
101 #define	R_AH		register_a.I8_reg.h_reg
102 #define	R_AL		register_a.I8_reg.l_reg
103 #define	R_BH		register_b.I8_reg.h_reg
104 #define	R_BL		register_b.I8_reg.l_reg
105 #define	R_CH		register_c.I8_reg.h_reg
106 #define	R_CL		register_c.I8_reg.l_reg
107 #define	R_DH		register_d.I8_reg.h_reg
108 #define	R_DL		register_d.I8_reg.l_reg
109 
110 /* 16 bit registers */
111 #define	R_AX		register_a.I16_reg.x_reg
112 #define	R_BX		register_b.I16_reg.x_reg
113 #define	R_CX		register_c.I16_reg.x_reg
114 #define	R_DX		register_d.I16_reg.x_reg
115 
116 /* 32 bit extended registers */
117 #define	R_EAX		register_a.I32_reg.e_reg
118 #define	R_EBX		register_b.I32_reg.e_reg
119 #define	R_ECX		register_c.I32_reg.e_reg
120 #define	R_EDX		register_d.I32_reg.e_reg
121 
122 /* special registers */
123 #define	R_BP		register_bp.I16_reg.x_reg
124 #define	R_SI		register_si.I16_reg.x_reg
125 #define	R_DI		register_di.I16_reg.x_reg
126 #define	R_FLG		register_flags
127 
128 /* special registers */
129 #define	R_EBP		register_bp.I32_reg.e_reg
130 #define	R_ESI		register_si.I32_reg.e_reg
131 #define	R_EDI		register_di.I32_reg.e_reg
132 #define	R_EFLG		register_flags
133 
134 /* segment registers */
135 #define	R_ES		register_es
136 #define	R_FS		register_fs
137 #define	R_GS		register_gs
138 
139 #define	X86BIOS_PHYSTOSEG(x)	(((x) >> 4) & 0xff00)
140 #define	X86BIOS_PHYSTOOFF(x)	((x) & 0x0fff)
141 
142 __BEGIN_DECLS
143 void	*x86bios_alloc(uint32_t *offset, size_t size, int flags);
144 void	 x86bios_call(struct x86regs *regs, uint16_t seg, uint16_t off);
145 void	 x86bios_free(void *addr, size_t size);
146 uint32_t x86bios_get_intr(int intno);
147 void	*x86bios_get_orm(uint32_t offset);
148 void	 x86bios_init_regs(struct x86regs *regs);
149 void	 x86bios_intr(struct x86regs *regs, int intno);
150 int	 x86bios_match_device(uint32_t offset, device_t dev);
151 void	*x86bios_offset(uint32_t offset);
152 void	 x86bios_set_intr(int intno, uint32_t saddr);
153 __END_DECLS
154 
155 #endif /* !_X86BIOS_H_ */
156