Alexander Graf | dd4b265 | 2009-11-12 21:53:13 +0100 | [diff] [blame] | 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 NO_QEMU_PROTOS |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 23 | #include "../../include/hw/nvram/fw_cfg.h" |
Alexander Graf | dd4b265 | 2009-11-12 21:53:13 +0100 | [diff] [blame] | 24 | |
| 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 Graf | 590bf49 | 2010-06-02 01:56:50 +0200 | [diff] [blame] | 53 | #define read_fw_blob_pre(var) \ |
Alexander Graf | dd4b265 | 2009-11-12 21:53:13 +0100 | [diff] [blame] | 54 | 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 Graf | 590bf49 | 2010-06-02 01:56:50 +0200 | [diff] [blame] | 60 | 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 Bonzini | cdebec5 | 2014-10-06 16:49:57 +0200 | [diff] [blame] | 69 | read_fw var ## _ADDR; \ |
| 70 | mov %eax, %edi; \ |
Alexander Graf | 590bf49 | 2010-06-02 01:56:50 +0200 | [diff] [blame] | 71 | read_fw_blob_pre(var); \ |
Juergen Lock | dd4239d | 2009-11-20 23:37:57 +0100 | [diff] [blame] | 72 | /* old as(1) doesn't like this insn so emit the bytes instead: \ |
| 73 | rep insb (%dx), %es:(%edi); \ |
| 74 | */ \ |
Alexander Graf | 590bf49 | 2010-06-02 01:56:50 +0200 | [diff] [blame] | 75 | .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 Bonzini | cdebec5 | 2014-10-06 16:49:57 +0200 | [diff] [blame] | 83 | #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 Graf | 590bf49 | 2010-06-02 01:56:50 +0200 | [diff] [blame] | 99 | 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 Lock | dd4239d | 2009-11-20 23:37:57 +0100 | [diff] [blame] | 103 | .dc.b 0x67,0xf3,0x6c |
Alexander Graf | dd4b265 | 2009-11-12 21:53:13 +0100 | [diff] [blame] | 104 | |
| 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 Graf | dd4b265 | 2009-11-12 21:53:13 +0100 | [diff] [blame] | 115 | lret; \ |
Gleb Natapov | 75b9f69 | 2011-01-31 15:11:01 +0200 | [diff] [blame] | 116 | .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 Graf | dd4b265 | 2009-11-12 21:53:13 +0100 | [diff] [blame] | 137 | /* DS = CS */ \ |
| 138 | movw %cs, %ax; \ |
| 139 | movw %ax, %ds; |
| 140 | |
| 141 | #define OPTION_ROM_END \ |
Jan Kiszka | 209ca75 | 2012-02-17 18:31:21 +0100 | [diff] [blame] | 142 | .byte 0; \ |
| 143 | .align 512, 0; \ |
Alexander Graf | dd4b265 | 2009-11-12 21:53:13 +0100 | [diff] [blame] | 144 | _end: |
| 145 | |
| 146 | #define BOOT_ROM_END \ |
Gleb Natapov | 75b9f69 | 2011-01-31 15:11:01 +0200 | [diff] [blame] | 147 | _manufacturer:; \ |
| 148 | .asciz "QEMU"; \ |
| 149 | _product:; \ |
| 150 | .asciz BOOT_ROM_PRODUCT; \ |
Alexander Graf | dd4b265 | 2009-11-12 21:53:13 +0100 | [diff] [blame] | 151 | OPTION_ROM_END |
| 152 | |