aboutsummaryrefslogtreecommitdiff
path: root/pc-bios/optionrom/optionrom.h
blob: 7bcdf0eeb2404c518f5b4e14179d6ab4f320f54d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
 * Common Option ROM Functions
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright Novell Inc, 2009
 *   Authors: Alexander Graf <agraf@suse.de>
 */


#define FW_CFG_KERNEL_ADDR      0x07
#define FW_CFG_KERNEL_SIZE      0x08
#define FW_CFG_KERNEL_CMDLINE   0x09
#define FW_CFG_INITRD_ADDR      0x0a
#define FW_CFG_INITRD_SIZE      0x0b
#define FW_CFG_KERNEL_ENTRY     0x10
#define FW_CFG_KERNEL_DATA      0x11
#define FW_CFG_INITRD_DATA      0x12
#define FW_CFG_CMDLINE_ADDR     0x13
#define FW_CFG_CMDLINE_SIZE     0x14
#define FW_CFG_CMDLINE_DATA     0x15
#define FW_CFG_SETUP_ADDR       0x16
#define FW_CFG_SETUP_SIZE       0x17
#define FW_CFG_SETUP_DATA       0x18

#define BIOS_CFG_IOPORT_CFG    0x510
#define BIOS_CFG_IOPORT_DATA   0x511

#define FW_CFG_DMA_CTL_ERROR   0x01
#define FW_CFG_DMA_CTL_READ    0x02
#define FW_CFG_DMA_CTL_SKIP    0x04
#define FW_CFG_DMA_CTL_SELECT  0x08
#define FW_CFG_DMA_CTL_WRITE   0x10

#define FW_CFG_DMA_SIGNATURE 0x51454d5520434647ULL /* "QEMU CFG" */

#define BIOS_CFG_DMA_ADDR_HIGH  0x514
#define BIOS_CFG_DMA_ADDR_LOW   0x518

/* Break the translation block flow so -d cpu shows us values */
#define DEBUG_HERE              \
        jmp         1f;         \
        1:

/*
 * Read a variable from the fw_cfg device.
 * Clobbers: %edx
 * Out: %eax
 */
.macro read_fw VAR
        mov         $\VAR, %ax
        mov         $BIOS_CFG_IOPORT_CFG, %dx
        outw        %ax, (%dx)
        mov         $BIOS_CFG_IOPORT_DATA, %dx
        inb         (%dx), %al
        shl         $8, %eax
        inb         (%dx), %al
        shl         $8, %eax
        inb         (%dx), %al
        shl         $8, %eax
        inb         (%dx), %al
        bswap       %eax
.endm


/*
 * Read data from the fw_cfg device using DMA.
 * Clobbers: %edx, %eax, ADDR, SIZE, memory[%esp-16] to memory[%esp]
 */
.macro read_fw_dma VAR, SIZE, ADDR
        /* Address */
        bswapl      \ADDR
        pushl       \ADDR

        /* We only support 32 bit target addresses */
        xorl        %eax, %eax
        pushl       %eax
        mov         $BIOS_CFG_DMA_ADDR_HIGH, %dx
        outl        %eax, (%dx)

        /* Size */
        bswapl      \SIZE
        pushl       \SIZE

        /* Control */
        movl        $(\VAR << 16) | (FW_CFG_DMA_CTL_READ | FW_CFG_DMA_CTL_SELECT), %eax
        bswapl      %eax
        pushl       %eax

        movl        %esp, %eax /* Address of the struct we generated */
        bswapl      %eax
        mov         $BIOS_CFG_DMA_ADDR_LOW, %dx
        outl        %eax, (%dx) /* Initiate DMA */

1:      mov         (%esp), %eax /* Wait for completion */
        bswapl      %eax
        testl       $~FW_CFG_DMA_CTL_ERROR, %eax
        jnz         1b
        addl        $16, %esp
.endm


/*
 * Read a blob from the fw_cfg device using DMA
 * Requires _ADDR, _SIZE and _DATA values for the parameter.
 *
 * Clobbers: %eax, %edx, %es, %ecx, %edi and adresses %esp-20 to %esp
 */
#ifdef USE_FW_CFG_DMA
#define read_fw_blob_dma(var)                           \
        read_fw         var ## _SIZE;                   \
        mov             %eax, %ecx;                     \
        read_fw         var ## _ADDR;                   \
        mov             %eax, %edi ;                    \
        read_fw_dma     var ## _DATA, %ecx, %edi
#else
#define read_fw_blob_dma(var) read_fw_blob(var)
#endif

#define read_fw_blob_pre(var)                           \
        read_fw         var ## _SIZE;                   \
        mov             %eax, %ecx;                     \
        mov             $var ## _DATA, %ax;             \
        mov             $BIOS_CFG_IOPORT_CFG, %edx;     \
        outw            %ax, (%dx);                     \
        mov             $BIOS_CFG_IOPORT_DATA, %dx;     \
        cld

/*
 * Read a blob from the fw_cfg device.
 * Requires _ADDR, _SIZE and _DATA values for the parameter.
 *
 * Clobbers: %eax, %edx, %es, %ecx, %edi
 */
#define read_fw_blob(var)                               \
        read_fw         var ## _ADDR;                   \
        mov             %eax, %edi;                     \
        read_fw_blob_pre(var);                          \
        /* old as(1) doesn't like this insn so emit the bytes instead: \
        rep insb        (%dx), %es:(%edi);              \
        */                                              \
        .dc.b           0xf3,0x6c

/*
 * Read a blob from the fw_cfg device in forced addr32 mode.
 * Requires _ADDR, _SIZE and _DATA values for the parameter.
 *
 * Clobbers: %eax, %edx, %es, %ecx, %edi
 */
#define read_fw_blob_addr32(var)                        \
        read_fw         var ## _ADDR;                   \
        mov             %eax, %edi;                     \
        read_fw_blob_pre(var);                          \
        /* old as(1) doesn't like this insn so emit the bytes instead: \
        addr32 rep insb (%dx), %es:(%edi);              \
        */                                              \
        .dc.b           0x67,0xf3,0x6c

/*
 * Read a blob from the fw_cfg device in forced addr32 mode, address is in %edi.
 * Requires _SIZE and _DATA values for the parameter.
 *
 * Clobbers: %eax, %edx, %edi, %es, %ecx
 */
#define read_fw_blob_addr32_edi(var)                    \
        read_fw_blob_pre(var);                          \
        /* old as(1) doesn't like this insn so emit the bytes instead: \
        addr32 rep insb (%dx), %es:(%edi);              \
        */                                              \
        .dc.b           0x67,0xf3,0x6c

#define OPTION_ROM_START                                \
    .code16;                                            \
    .text;                                              \
        .global         _start;                         \
    _start:;                                            \
        .short          0xaa55;                         \
        .byte           (_end - _start) / 512;

#define BOOT_ROM_START                                  \
        OPTION_ROM_START                                \
        lret;                                           \
        .org            0x18;                           \
        .short          0;                              \
        .short          _pnph;                          \
    _pnph:                                              \
        .ascii          "$PnP";                         \
        .byte           0x01;                           \
        .byte           ( _pnph_len / 16 );             \
        .short          0x0000;                         \
        .byte           0x00;                           \
        .byte           0x00;                           \
        .long           0x00000000;                     \
        .short          _manufacturer;                  \
        .short          _product;                       \
        .long           0x00000000;                     \
        .short          0x0000;                         \
        .short          0x0000;                         \
        .short          _bev;                           \
        .short          0x0000;                         \
        .short          0x0000;                         \
        .equ            _pnph_len, . - _pnph;           \
    _bev:;                                              \
        /* DS = CS */                                   \
        movw            %cs, %ax;                       \
        movw            %ax, %ds;

#define OPTION_ROM_END                                  \
        .byte           0;                              \
        .align          512, 0;                         \
    _end:

#define BOOT_ROM_END                                    \
    _manufacturer:;                                     \
        .asciz "QEMU";                                  \
    _product:;                                          \
        .asciz BOOT_ROM_PRODUCT;                        \
        OPTION_ROM_END