1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
41#define DEBUG_HERE \
42 jmp 1f; \
43 1:
44
45
46
47
48
49
50.macro read_fw VAR
51 mov $\VAR, %ax
52 mov $BIOS_CFG_IOPORT_CFG, %dx
53 outw %ax, (%dx)
54 mov $BIOS_CFG_IOPORT_DATA, %dx
55 inb (%dx), %al
56 shl $8, %eax
57 inb (%dx), %al
58 shl $8, %eax
59 inb (%dx), %al
60 shl $8, %eax
61 inb (%dx), %al
62 bswap %eax
63.endm
64
65#define read_fw_blob_pre(var) \
66 read_fw var ## _SIZE; \
67 mov %eax, %ecx; \
68 mov $var ## _DATA, %ax; \
69 mov $BIOS_CFG_IOPORT_CFG, %edx; \
70 outw %ax, (%dx); \
71 mov $BIOS_CFG_IOPORT_DATA, %dx; \
72 cld
73
74
75
76
77
78
79
80#define read_fw_blob(var) \
81 read_fw var ## _ADDR; \
82 mov %eax, %edi; \
83 read_fw_blob_pre(var); \
84
85
86 \
87 .dc.b 0xf3,0x6c
88
89
90
91
92
93
94
95#define read_fw_blob_addr32(var) \
96 read_fw var ## _ADDR; \
97 mov %eax, %edi; \
98 read_fw_blob_pre(var); \
99
100
101 \
102 .dc.b 0x67,0xf3,0x6c
103
104
105
106
107
108
109
110#define read_fw_blob_addr32_edi(var) \
111 read_fw_blob_pre(var); \
112
113
114 \
115 .dc.b 0x67,0xf3,0x6c
116
117#define OPTION_ROM_START \
118 .code16; \
119 .text; \
120 .global _start; \
121 _start:; \
122 .short 0xaa55; \
123 .byte (_end - _start) / 512;
124
125#define BOOT_ROM_START \
126 OPTION_ROM_START \
127 lret; \
128 .org 0x18; \
129 .short 0; \
130 .short _pnph; \
131 _pnph: \
132 .ascii "$PnP"; \
133 .byte 0x01; \
134 .byte ( _pnph_len / 16 ); \
135 .short 0x0000; \
136 .byte 0x00; \
137 .byte 0x00; \
138 .long 0x00000000; \
139 .short _manufacturer; \
140 .short _product; \
141 .long 0x00000000; \
142 .short 0x0000; \
143 .short 0x0000; \
144 .short _bev; \
145 .short 0x0000; \
146 .short 0x0000; \
147 .equ _pnph_len, . - _pnph; \
148 _bev:; \
149 \
150 movw %cs, %ax; \
151 movw %ax, %ds;
152
153#define OPTION_ROM_END \
154 .byte 0; \
155 .align 512, 0; \
156 _end:
157
158#define BOOT_ROM_END \
159 _manufacturer:; \
160 .asciz "QEMU"; \
161 _product:; \
162 .asciz BOOT_ROM_PRODUCT; \
163 OPTION_ROM_END
164
165