master
h 226 lines 8.34 KB
Raw
1 /*
2 * Common Option ROM Functions
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright Novell Inc, 2009
18 * Authors: Alexander Graf <agraf@suse.de>
19 */
20
21
22 #define FW_CFG_KERNEL_ADDR 0x07
23 #define FW_CFG_KERNEL_SIZE 0x08
24 #define FW_CFG_KERNEL_CMDLINE 0x09
25 #define FW_CFG_INITRD_ADDR 0x0a
26 #define FW_CFG_INITRD_SIZE 0x0b
27 #define FW_CFG_KERNEL_ENTRY 0x10
28 #define FW_CFG_KERNEL_DATA 0x11
29 #define FW_CFG_INITRD_DATA 0x12
30 #define FW_CFG_CMDLINE_ADDR 0x13
31 #define FW_CFG_CMDLINE_SIZE 0x14
32 #define FW_CFG_CMDLINE_DATA 0x15
33 #define FW_CFG_SETUP_ADDR 0x16
34 #define FW_CFG_SETUP_SIZE 0x17
35 #define FW_CFG_SETUP_DATA 0x18
36
37 #define BIOS_CFG_IOPORT_CFG 0x510
38 #define BIOS_CFG_IOPORT_DATA 0x511
39
40 #define FW_CFG_DMA_CTL_ERROR 0x01
41 #define FW_CFG_DMA_CTL_READ 0x02
42 #define FW_CFG_DMA_CTL_SKIP 0x04
43 #define FW_CFG_DMA_CTL_SELECT 0x08
44 #define FW_CFG_DMA_CTL_WRITE 0x10
45
46 #define FW_CFG_DMA_SIGNATURE 0x51454d5520434647ULL /* "QEMU CFG" */
47
48 #define BIOS_CFG_DMA_ADDR_HIGH 0x514
49 #define BIOS_CFG_DMA_ADDR_LOW 0x518
50
51 /* Break the translation block flow so -d cpu shows us values */
52 #define DEBUG_HERE \
53 jmp 1f; \
54 1:
55
56 /*
57 * Read a variable from the fw_cfg device.
58 * Clobbers: %edx
59 * Out: %eax
60 */
61 .macro read_fw VAR
62 mov $\VAR, %ax
63 mov $BIOS_CFG_IOPORT_CFG, %dx
64 outw %ax, (%dx)
65 mov $BIOS_CFG_IOPORT_DATA, %dx
66 inb (%dx), %al
67 shl $8, %eax
68 inb (%dx), %al
69 shl $8, %eax
70 inb (%dx), %al
71 shl $8, %eax
72 inb (%dx), %al
73 bswap %eax
74 .endm
75
76
77 /*
78 * Read data from the fw_cfg device using DMA.
79 * Clobbers: %edx, %eax, ADDR, SIZE, memory[%esp-16] to memory[%esp]
80 */
81 .macro read_fw_dma VAR, SIZE, ADDR
82 /* Address */
83 bswapl \ADDR
84 pushl \ADDR
85
86 /* We only support 32 bit target addresses */
87 xorl %eax, %eax
88 pushl %eax
89 mov $BIOS_CFG_DMA_ADDR_HIGH, %dx
90 outl %eax, (%dx)
91
92 /* Size */
93 bswapl \SIZE
94 pushl \SIZE
95
96 /* Control */
97 movl $(\VAR << 16) | (FW_CFG_DMA_CTL_READ | FW_CFG_DMA_CTL_SELECT), %eax
98 bswapl %eax
99 pushl %eax
100
101 movl %esp, %eax /* Address of the struct we generated */
102 bswapl %eax
103 mov $BIOS_CFG_DMA_ADDR_LOW, %dx
104 outl %eax, (%dx) /* Initiate DMA */
105
106 1: mov (%esp), %eax /* Wait for completion */
107 bswapl %eax
108 testl $~FW_CFG_DMA_CTL_ERROR, %eax
109 jnz 1b
110 addl $16, %esp
111 .endm
112
113
114 /*
115 * Read a blob from the fw_cfg device using DMA
116 * Requires _ADDR, _SIZE and _DATA values for the parameter.
117 *
118 * Clobbers: %eax, %edx, %es, %ecx, %edi and adresses %esp-20 to %esp
119 */
120 #define read_fw_blob_dma(var) \
121 read_fw var ## _SIZE; \
122 mov %eax, %ecx; \
123 read_fw var ## _ADDR; \
124 mov %eax, %edi ; \
125 read_fw_dma var ## _DATA, %ecx, %edi
126
127 #define read_fw_blob_pre(var) \
128 read_fw var ## _SIZE; \
129 mov %eax, %ecx; \
130 mov $var ## _DATA, %ax; \
131 mov $BIOS_CFG_IOPORT_CFG, %edx; \
132 outw %ax, (%dx); \
133 mov $BIOS_CFG_IOPORT_DATA, %dx; \
134 cld
135
136 /*
137 * Read a blob from the fw_cfg device.
138 * Requires _ADDR, _SIZE and _DATA values for the parameter.
139 *
140 * Clobbers: %eax, %edx, %es, %ecx, %edi
141 */
142 #define read_fw_blob(var) \
143 read_fw var ## _ADDR; \
144 mov %eax, %edi; \
145 read_fw_blob_pre(var); \
146 /* old as(1) doesn't like this insn so emit the bytes instead: \
147 rep insb (%dx), %es:(%edi); \
148 */ \
149 .dc.b 0xf3,0x6c
150
151 /*
152 * Read a blob from the fw_cfg device in forced addr32 mode.
153 * Requires _ADDR, _SIZE and _DATA values for the parameter.
154 *
155 * Clobbers: %eax, %edx, %es, %ecx, %edi
156 */
157 #define read_fw_blob_addr32(var) \
158 read_fw var ## _ADDR; \
159 mov %eax, %edi; \
160 read_fw_blob_pre(var); \
161 /* old as(1) doesn't like this insn so emit the bytes instead: \
162 addr32 rep insb (%dx), %es:(%edi); \
163 */ \
164 .dc.b 0x67,0xf3,0x6c
165
166 /*
167 * Read a blob from the fw_cfg device in forced addr32 mode, address is in %edi.
168 * Requires _SIZE and _DATA values for the parameter.
169 *
170 * Clobbers: %eax, %edx, %edi, %es, %ecx
171 */
172 #define read_fw_blob_addr32_edi(var) \
173 read_fw_blob_pre(var); \
174 /* old as(1) doesn't like this insn so emit the bytes instead: \
175 addr32 rep insb (%dx), %es:(%edi); \
176 */ \
177 .dc.b 0x67,0xf3,0x6c
178
179 #define OPTION_ROM_START \
180 .code16; \
181 .text; \
182 .global _start; \
183 _start:; \
184 .short 0xaa55; \
185 .byte (_end - _start) / 512;
186
187 #define BOOT_ROM_START \
188 OPTION_ROM_START \
189 lret; \
190 .org 0x18; \
191 .short 0; \
192 .short _pnph; \
193 _pnph: \
194 .ascii "$PnP"; \
195 .byte 0x01; \
196 .byte ( _pnph_len / 16 ); \
197 .short 0x0000; \
198 .byte 0x00; \
199 .byte 0x00; \
200 .long 0x00000000; \
201 .short _manufacturer; \
202 .short _product; \
203 .long 0x00000000; \
204 .short 0x0000; \
205 .short 0x0000; \
206 .short _bev; \
207 .short 0x0000; \
208 .short 0x0000; \
209 .equ _pnph_len, . - _pnph; \
210 _bev:; \
211 /* DS = CS */ \
212 movw %cs, %ax; \
213 movw %ax, %ds;
214
215 #define OPTION_ROM_END \
216 .byte 0; \
217 .align 512, 0; \
218 _end:
219
220 #define BOOT_ROM_END \
221 _manufacturer:; \
222 .asciz "QEMU"; \
223 _product:; \
224 .asciz BOOT_ROM_PRODUCT; \
225 OPTION_ROM_END
226