ia64/xen-unstable

view tools/firmware/rombios/32bitgateway.c @ 19848:5839491bbf20

[IA64] replace MAX_VCPUS with d->max_vcpus where necessary.

don't use MAX_VCPUS, and use vcpu::max_vcpus.
The changeset of 2f9e1348aa98 introduced max_vcpus to allow more vcpus
per guest. This patch is ia64 counter part.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Mon Jun 29 11:26:05 2009 +0900 (2009-06-29)
parents 909bb1245930
children
line source
1 /*
2 * Implementation of a gateway into 32bit space. Stub functions
3 * can be called from Bochs BIOS which call functions with a compatible
4 * signature in 32bit space. All interrupts are disabled while in
5 * 32 bit mode.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Copyright (C) IBM Corporation, 2006
22 * Copyright (c) 2008, Citrix Systems, Inc.
23 *
24 * Author: Stefan Berger <stefanb@us.ibm.com>
25 * Author: Keir Fraser <keir.fraser@citrix.com>
26 */
28 /*
29 * Note:
30 * BCC's ABI does not require to preserve any 16bit registers ax, bx, cs, dx
31 * by a called function. So these registers need not be preserved while
32 * calling a function in 32bit space, either.
33 *
34 * When bcc calls a function with 16bit parameters it pushes 2 bytes onto
35 * the stack for such a parameter. GCC, however, expects 32bit parameters
36 * (4 bytes) even for uint16_t, so casting to 32bit from bcc is a good idea.
37 */
39 /* At most 32 bytes in argument list to a 32-bit function. */
40 #define MAX_ARG_BYTES 32
42 #define REAL_MODE_CODE_OFFSET 0xf0000
44 /* Definitions of code/data segment descriptors. */
45 #define PM_32BIT_CS (gdt_entry_pm_32bit_cs - gdt_base)
46 #define PM_16BIT_CS (gdt_entry_pm_16bit_cs - gdt_base)
47 #define PM_32BIT_DS (gdt_entry_pm_32bit_ds - gdt_base)
48 #define PM_16BIT_DS (gdt_entry_pm_16bit_ds - gdt_base)
50 .align 16
51 gdt_base:
52 .word 0,0
53 .byte 0,0,0,0
54 gdt_entry_pm_32bit_cs:
55 .word 0xffff, 0x0000
56 .byte 0x00, 0x9b, 0xcf, 0x00
57 gdt_entry_pm_16bit_cs:
58 .word 0xffff, 0x0000
59 .byte REAL_MODE_CODE_OFFSET >> 16, 0x9b, 0x8f, 0x0
60 gdt_entry_pm_32bit_ds:
61 .word 0xffff, 0x0000
62 .byte 0x0, 0x93, 0xcf, 0x0
63 gdt_entry_pm_16bit_ds:
64 .word 0xffff, 0x0000
65 .byte 0x0, 0x93, 0x8f, 0x0
66 gdt_entry_end:
68 protmode_gdtdesc:
69 .word (gdt_entry_end - gdt_base) - 1
70 .long gdt_base | REAL_MODE_CODE_OFFSET
72 realmode_gdtdesc:
73 .word 0xffff
74 .long 0x0
76 Upcall:
77 ; Do an upcall into 32 bit space
78 ;
79 ; Input:
80 ; bx: index of function to call
81 ; Ouput:
82 ; dx, ax: 32 bit result of call (even if 'void' is expected)
84 ; Save caller state, stack frame offsets listed below
85 #define esp_off 0
86 #define ss_off 4
87 #define es_off 6
88 #define ds_off 8
89 #define flags_off 10
90 #define retaddr_off 12
91 #define args_off 14
92 pushf
93 cli
94 push ds
95 push es
96 push ss
97 push esp
99 ; Calculate protected-mode esp from ss:sp
100 and esp, #0xffff
101 xor eax, eax
102 mov ax, ss
103 shl eax, #4
104 add esp, eax
106 ; Switch to protected mode
107 seg cs
108 lgdt protmode_gdtdesc
109 mov eax, cr0
110 or al, #0x1 ; protected mode on
111 mov cr0, eax
112 jmpf DWORD (REAL_MODE_CODE_OFFSET|upcall1), #PM_32BIT_CS
113 upcall1:
114 USE32
115 mov ax, #PM_32BIT_DS
116 mov ds, ax
117 mov es, ax
118 mov ss, ax
120 ; Marshal arguments and call 32-bit function
121 mov ecx, #MAX_ARG_BYTES/4
122 upcall2:
123 push MAX_ARG_BYTES-4+args_off[esp]
124 loop upcall2
125 mov eax, [BIOS_INFO_PHYSICAL_ADDRESS + BIOSINFO_OFF_bios32_entry]
126 call eax
127 add esp, #MAX_ARG_BYTES
128 mov ecx, eax ; Result in ecx
130 ; Restore real-mode stack pointer
131 xor eax, eax
132 mov ax, ss_off[esp]
133 mov bx, ax ; Real-mode ss in bx
134 shl eax, 4
135 sub esp, eax
137 ; Return to real mode
138 jmpf upcall3, #PM_16BIT_CS
139 upcall3:
140 USE16
141 mov ax, #PM_16BIT_DS
142 mov ds, ax
143 mov es, ax
144 mov ss, ax
145 mov eax, cr0
146 and al, #0xfe ; protected mode off
147 mov cr0, eax
148 jmpf upcall4, #REAL_MODE_CODE_OFFSET>>4
149 upcall4:
150 seg cs
151 lgdt realmode_gdtdesc
153 ; Restore real-mode ss
154 mov ss, bx
156 ; Convert result into dx:ax format
157 mov eax, ecx
158 ror eax, #16
159 mov dx, ax
160 ror eax, #16
162 ; Restore caller state and return
163 pop esp
164 pop bx ; skip ss
165 pop es
166 pop ds
167 popf
168 ret
170 MACRO DoUpcall
171 mov bx, #?1
172 jmp Upcall
173 MEND
175 #define X(idx, ret, fn, args...) _ ## fn: DoUpcall(idx)
176 #include "32bitprotos.h"
177 #undef X