blob: f1a9021ec13b8bb1bd2bb51d4bee21429d6e24be [file] [log] [blame]
Alexander Grafdd4b2652009-11-12 21:53:13 +01001/*
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 NO_QEMU_PROTOS
Paolo Bonzini0d09e412013-02-05 17:06:20 +010023#include "../../include/hw/nvram/fw_cfg.h"
Alexander Grafdd4b2652009-11-12 21:53:13 +010024
25#define BIOS_CFG_IOPORT_CFG 0x510
26#define BIOS_CFG_IOPORT_DATA 0x511
27
28/* Break the translation block flow so -d cpu shows us values */
29#define DEBUG_HERE \
30 jmp 1f; \
31 1:
32
33/*
34 * Read a variable from the fw_cfg device.
35 * Clobbers: %edx
36 * Out: %eax
37 */
38.macro read_fw VAR
39 mov $\VAR, %ax
40 mov $BIOS_CFG_IOPORT_CFG, %dx
41 outw %ax, (%dx)
42 mov $BIOS_CFG_IOPORT_DATA, %dx
43 inb (%dx), %al
44 shl $8, %eax
45 inb (%dx), %al
46 shl $8, %eax
47 inb (%dx), %al
48 shl $8, %eax
49 inb (%dx), %al
50 bswap %eax
51.endm
52
Alexander Graf590bf492010-06-02 01:56:50 +020053#define read_fw_blob_pre(var) \
Alexander Grafdd4b2652009-11-12 21:53:13 +010054 read_fw var ## _SIZE; \
55 mov %eax, %ecx; \
56 mov $var ## _DATA, %ax; \
57 mov $BIOS_CFG_IOPORT_CFG, %edx; \
58 outw %ax, (%dx); \
59 mov $BIOS_CFG_IOPORT_DATA, %dx; \
Alexander Graf590bf492010-06-02 01:56:50 +020060 cld
61
62/*
63 * Read a blob from the fw_cfg device.
64 * Requires _ADDR, _SIZE and _DATA values for the parameter.
65 *
66 * Clobbers: %eax, %edx, %es, %ecx, %edi
67 */
68#define read_fw_blob(var) \
Paolo Bonzinicdebec52014-10-06 16:49:57 +020069 read_fw var ## _ADDR; \
70 mov %eax, %edi; \
Alexander Graf590bf492010-06-02 01:56:50 +020071 read_fw_blob_pre(var); \
Juergen Lockdd4239d2009-11-20 23:37:57 +010072 /* old as(1) doesn't like this insn so emit the bytes instead: \
73 rep insb (%dx), %es:(%edi); \
74 */ \
Alexander Graf590bf492010-06-02 01:56:50 +020075 .dc.b 0xf3,0x6c
76
77/*
78 * Read a blob from the fw_cfg device in forced addr32 mode.
79 * Requires _ADDR, _SIZE and _DATA values for the parameter.
80 *
81 * Clobbers: %eax, %edx, %es, %ecx, %edi
82 */
Paolo Bonzinicdebec52014-10-06 16:49:57 +020083#define read_fw_blob_addr32(var) \
84 read_fw var ## _ADDR; \
85 mov %eax, %edi; \
86 read_fw_blob_pre(var); \
87 /* old as(1) doesn't like this insn so emit the bytes instead: \
88 addr32 rep insb (%dx), %es:(%edi); \
89 */ \
90 .dc.b 0x67,0xf3,0x6c
91
92/*
93 * Read a blob from the fw_cfg device in forced addr32 mode, address is in %edi.
94 * Requires _SIZE and _DATA values for the parameter.
95 *
96 * Clobbers: %eax, %edx, %edi, %es, %ecx
97 */
98#define read_fw_blob_addr32_edi(var) \
Alexander Graf590bf492010-06-02 01:56:50 +020099 read_fw_blob_pre(var); \
100 /* old as(1) doesn't like this insn so emit the bytes instead: \
101 addr32 rep insb (%dx), %es:(%edi); \
102 */ \
Juergen Lockdd4239d2009-11-20 23:37:57 +0100103 .dc.b 0x67,0xf3,0x6c
Alexander Grafdd4b2652009-11-12 21:53:13 +0100104
105#define OPTION_ROM_START \
106 .code16; \
107 .text; \
108 .global _start; \
109 _start:; \
110 .short 0xaa55; \
111 .byte (_end - _start) / 512;
112
113#define BOOT_ROM_START \
114 OPTION_ROM_START \
Alexander Grafdd4b2652009-11-12 21:53:13 +0100115 lret; \
Gleb Natapov75b9f692011-01-31 15:11:01 +0200116 .org 0x18; \
117 .short 0; \
118 .short _pnph; \
119 _pnph: \
120 .ascii "$PnP"; \
121 .byte 0x01; \
122 .byte ( _pnph_len / 16 ); \
123 .short 0x0000; \
124 .byte 0x00; \
125 .byte 0x00; \
126 .long 0x00000000; \
127 .short _manufacturer; \
128 .short _product; \
129 .long 0x00000000; \
130 .short 0x0000; \
131 .short 0x0000; \
132 .short _bev; \
133 .short 0x0000; \
134 .short 0x0000; \
135 .equ _pnph_len, . - _pnph; \
136 _bev:; \
Alexander Grafdd4b2652009-11-12 21:53:13 +0100137 /* DS = CS */ \
138 movw %cs, %ax; \
139 movw %ax, %ds;
140
141#define OPTION_ROM_END \
Jan Kiszka209ca752012-02-17 18:31:21 +0100142 .byte 0; \
143 .align 512, 0; \
Alexander Grafdd4b2652009-11-12 21:53:13 +0100144 _end:
145
146#define BOOT_ROM_END \
Gleb Natapov75b9f692011-01-31 15:11:01 +0200147 _manufacturer:; \
148 .asciz "QEMU"; \
149 _product:; \
150 .asciz BOOT_ROM_PRODUCT; \
Alexander Grafdd4b2652009-11-12 21:53:13 +0100151 OPTION_ROM_END
152