Statistics
| Branch: | Revision:

root / pc-bios / optionrom / optionrom.h @ dd4239d6

History | View | Annotate | Download (2.5 kB)

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
23
#include "../../hw/fw_cfg.h"
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

    
53
/*
54
 * Read a blob from the fw_cfg device.
55
 * Requires _ADDR, _SIZE and _DATA values for the parameter.
56
 *
57
 * Clobbers:        %eax, %edx, %es, %ecx, %edi
58
 */
59
#define read_fw_blob(var)                                \
60
        read_fw                var ## _ADDR;                        \
61
        mov                %eax, %edi;                        \
62
        read_fw                var ## _SIZE;                        \
63
        mov                %eax, %ecx;                        \
64
        mov                $var ## _DATA, %ax;                \
65
        mov                $BIOS_CFG_IOPORT_CFG, %edx;        \
66
        outw                %ax, (%dx);                        \
67
        mov                $BIOS_CFG_IOPORT_DATA, %dx;        \
68
        cld;                                                \
69
        /* old as(1) doesn't like this insn so emit the bytes instead: \
70
        rep insb        (%dx), %es:(%edi);                \
71
        */                                                \
72
        .dc.b                0x67,0xf3,0x6c
73

    
74
#define OPTION_ROM_START                                        \
75
    .code16;                                                \
76
    .text;                                                \
77
        .global         _start;                                \
78
    _start:;                                                \
79
        .short                0xaa55;                                \
80
        .byte                (_end - _start) / 512;
81

    
82
#define BOOT_ROM_START                                        \
83
        OPTION_ROM_START                                \
84
        push                %eax;                                \
85
        push                %ds;                                \
86
                                                        \
87
        /* setup ds so we can access the IVT */                \
88
        xor                %ax, %ax;                        \
89
        mov                %ax, %ds;                        \
90
                                                        \
91
        /* install our int 19 handler */                \
92
        movw                $int19_handler, (0x19*4);        \
93
        mov                %cs, (0x19*4+2);                \
94
                                                        \
95
        pop                %ds;                                \
96
        pop                %eax;                                \
97
        lret;                                                \
98
                                                        \
99
    int19_handler:;                                        \
100
        /* DS = CS */                                        \
101
        movw                %cs, %ax;                        \
102
        movw                %ax, %ds;
103

    
104
#define OPTION_ROM_END                                        \
105
    .align 512, 0;                                        \
106
    _end:
107

    
108
#define BOOT_ROM_END                                        \
109
        OPTION_ROM_END
110