1 | /** @file
|
---|
2 | * Inline routines for Watcom C.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2010-2017 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 |
|
---|
18 | extern unsigned inp(unsigned port);
|
---|
19 | extern unsigned outp(unsigned port, unsigned value);
|
---|
20 | extern unsigned inpw(unsigned port);
|
---|
21 | extern unsigned outpw(unsigned port, unsigned value);
|
---|
22 | #pragma intrinsic(inp,outp,inpw,outpw)
|
---|
23 | #define inb(p) inp(p)
|
---|
24 | #define outb(p, v) outp(p, v)
|
---|
25 | #define inw(p) inpw(p)
|
---|
26 | #define outw(p, v) outpw(p, v)
|
---|
27 |
|
---|
28 | extern uint8_t read_byte(uint16_t seg, uint16_t offset);
|
---|
29 | extern uint16_t read_word(uint16_t seg, uint16_t offset);
|
---|
30 | extern uint32_t read_dword(uint16_t seg, uint16_t offset);
|
---|
31 | extern void write_byte(uint16_t seg, uint16_t offset, uint8_t data);
|
---|
32 | extern void write_word(uint16_t seg, uint16_t offset, uint16_t data);
|
---|
33 | extern void write_dword(uint16_t seg, uint16_t offset, uint32_t data);
|
---|
34 |
|
---|
35 | void int_enable(void);
|
---|
36 | #pragma aux int_enable = "sti" modify exact [] nomemory;
|
---|
37 |
|
---|
38 | void int_disable(void);
|
---|
39 | #pragma aux int_disable = "cli" modify exact [] nomemory;
|
---|
40 |
|
---|
41 | void int_enable_hlt_disable(void);
|
---|
42 | #pragma aux int_enable_hlt_disable = \
|
---|
43 | "sti" \
|
---|
44 | "hlt" \
|
---|
45 | "cli" \
|
---|
46 | modify exact [] nomemory;
|
---|
47 |
|
---|
48 | uint16_t int_query(void);
|
---|
49 | #pragma aux int_query = \
|
---|
50 | "pushf" \
|
---|
51 | "pop ax" \
|
---|
52 | value [ax] modify exact [ax] nomemory;
|
---|
53 |
|
---|
54 | void int_restore(uint16_t old_flags);
|
---|
55 | #pragma aux int_restore = \
|
---|
56 | "push ax" \
|
---|
57 | "popf" \
|
---|
58 | parm [ax] modify exact [] nomemory;
|
---|
59 |
|
---|
60 | void halt(void);
|
---|
61 | #pragma aux halt = "hlt" modify exact [] nomemory;
|
---|
62 |
|
---|
63 | void halt_forever(void);
|
---|
64 | #pragma aux halt_forever = \
|
---|
65 | "forever:" \
|
---|
66 | "hlt" \
|
---|
67 | "jmp forever" \
|
---|
68 | modify exact [] nomemory aborts;
|
---|
69 |
|
---|
70 | #ifdef __386__
|
---|
71 |
|
---|
72 | void rep_movsb(void __far *d, void __far *s, int nbytes);
|
---|
73 | #pragma aux rep_movsb = \
|
---|
74 | "push ds" \
|
---|
75 | "mov ds, dx" \
|
---|
76 | "rep movsb" \
|
---|
77 | "pop ds" \
|
---|
78 | parm [es edi] [dx esi] [ecx];
|
---|
79 |
|
---|
80 | #else
|
---|
81 |
|
---|
82 | void rep_movsb(void __far *d, void __far *s, int nbytes);
|
---|
83 | #pragma aux rep_movsb = \
|
---|
84 | "push ds" \
|
---|
85 | "mov ds, dx" \
|
---|
86 | "rep movsb" \
|
---|
87 | "pop ds" \
|
---|
88 | parm [es di] [dx si] [cx];
|
---|
89 |
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | void rep_movsw(void __far *d, void __far *s, int nwords);
|
---|
93 | #pragma aux rep_movsw = \
|
---|
94 | "push ds" \
|
---|
95 | "mov ds, dx" \
|
---|
96 | "rep movsw" \
|
---|
97 | "pop ds" \
|
---|
98 | parm [es di] [dx si] [cx];
|
---|
99 |
|
---|
100 | #ifndef __386__
|
---|
101 |
|
---|
102 | char __far *rep_insb(char __far *buffer, unsigned nbytes, unsigned port);
|
---|
103 | #pragma aux rep_insb = ".286" "rep insb" parm [es di] [cx] [dx] value [es di] modify exact [cx di];
|
---|
104 |
|
---|
105 | char __far *rep_insw(char __far *buffer, unsigned nwords, unsigned port);
|
---|
106 | #pragma aux rep_insw = ".286" "rep insw" parm [es di] [cx] [dx] value [es di] modify exact [cx di];
|
---|
107 |
|
---|
108 | # if VBOX_BIOS_CPU >= 80386
|
---|
109 | char __far *rep_insd(char __far *buffer, unsigned ndwords, unsigned port);
|
---|
110 | # pragma aux rep_insd = ".386" "rep insd" parm [es di] [cx] [dx] value [es di] modify exact [cx di];
|
---|
111 | # endif
|
---|
112 |
|
---|
113 | char __far *rep_outsb(char __far *buffer, unsigned nbytes, unsigned port);
|
---|
114 | #pragma aux rep_outsb = ".286" "rep outs dx,byte ptr es:[si]" parm [es si] [cx] [dx] value [es si] modify exact [cx si];
|
---|
115 |
|
---|
116 | char __far *rep_outsw(char __far *buffer, unsigned nwords, unsigned port);
|
---|
117 | #pragma aux rep_outsw = ".286" "rep outs dx,word ptr es:[si]" parm [es si] [cx] [dx] value [es si] modify exact [cx si];
|
---|
118 |
|
---|
119 | # if VBOX_BIOS_CPU >= 80386
|
---|
120 | char __far *rep_outsd(char __far *buffer, unsigned ndwords, unsigned port);
|
---|
121 | # pragma aux rep_outsd = ".386" "rep outs dx,dword ptr es:[si]" parm [es si] [cx] [dx] value [es si] modify exact [cx si];
|
---|
122 | # endif
|
---|
123 |
|
---|
124 | uint16_t swap_16(uint16_t val);
|
---|
125 | #pragma aux swap_16 = "xchg ah,al" parm [ax] value [ax] modify exact [ax] nomemory;
|
---|
126 |
|
---|
127 | uint32_t swap_32(uint32_t val);
|
---|
128 | #pragma aux swap_32 = \
|
---|
129 | "xchg ah, al" \
|
---|
130 | "xchg dh, dl" \
|
---|
131 | "xchg ax, dx" \
|
---|
132 | parm [dx ax] value [dx ax] modify exact [dx ax] nomemory;
|
---|
133 |
|
---|
134 | uint64_t swap_64(uint64_t val);
|
---|
135 | #pragma aux swap_64 = \
|
---|
136 | "xchg ah, al" \
|
---|
137 | "xchg bh, bl" \
|
---|
138 | "xchg ch, cl" \
|
---|
139 | "xchg dh, dl" \
|
---|
140 | "xchg ax, dx" \
|
---|
141 | "xchg bx, cx" \
|
---|
142 | parm [ax bx cx dx] value [ax bx cx dx] modify exact [ax bx cx dx] nomemory;
|
---|
143 |
|
---|
144 | #endif
|
---|
145 |
|
---|
146 | #if VBOX_BIOS_CPU >= 80386
|
---|
147 |
|
---|
148 | /* Warning: msr_read/msr_write destroy high bits of 32-bit registers (EAX, ECX, EDX). */
|
---|
149 |
|
---|
150 | uint64_t msr_read(uint32_t msr);
|
---|
151 | #pragma aux msr_read = \
|
---|
152 | ".586" \
|
---|
153 | "shl ecx, 16" \
|
---|
154 | "mov cx, ax" \
|
---|
155 | "rdmsr" \
|
---|
156 | "xchg eax, edx" \
|
---|
157 | "mov bx, ax" \
|
---|
158 | "shr eax, 16" \
|
---|
159 | "mov cx, dx" \
|
---|
160 | "shr edx, 16" \
|
---|
161 | "xchg dx, cx" \
|
---|
162 | parm [cx ax] value [ax bx cx dx] modify [] nomemory;
|
---|
163 |
|
---|
164 | void msr_write(uint64_t val, uint32_t msr);
|
---|
165 | #pragma aux msr_write = \
|
---|
166 | ".586" \
|
---|
167 | "shl eax, 16" \
|
---|
168 | "mov ax, bx" \
|
---|
169 | "xchg dx, cx" \
|
---|
170 | "shl edx, 16" \
|
---|
171 | "mov dx, cx" \
|
---|
172 | "xchg eax, edx" \
|
---|
173 | "mov cx, di" \
|
---|
174 | "shl ecx, 16" \
|
---|
175 | "mov cx, si" \
|
---|
176 | "wrmsr" \
|
---|
177 | parm [ax bx cx dx] [di si] modify [] nomemory;
|
---|
178 |
|
---|
179 | /* Warning: eflags_read/eflags_write destroy high bits of 32-bit registers (EDX). */
|
---|
180 | uint32_t eflags_read( void );
|
---|
181 | #pragma aux eflags_read = \
|
---|
182 | ".386" \
|
---|
183 | "pushfd" \
|
---|
184 | "pop edx" \
|
---|
185 | "mov ax, dx" \
|
---|
186 | "shr edx, 16" \
|
---|
187 | value [dx ax] modify [dx ax];
|
---|
188 |
|
---|
189 | uint32_t eflags_write( uint32_t e_flags );
|
---|
190 | #pragma aux eflags_write = \
|
---|
191 | ".386" \
|
---|
192 | "shl edx, 16" \
|
---|
193 | "mov dx, ax" \
|
---|
194 | "push edx" \
|
---|
195 | "popfd" \
|
---|
196 | parm [dx ax] modify [dx ax];
|
---|
197 |
|
---|
198 | /* Warning cpuid destroys high bits of 32-bit registers (EAX, EBX, ECX, EDX). */
|
---|
199 | void cpuid( uint32_t __far cpu_id[4], uint32_t leaf );
|
---|
200 | #pragma aux cpuid = \
|
---|
201 | ".586" \
|
---|
202 | "shl edx, 16" \
|
---|
203 | "mov dx, ax" \
|
---|
204 | "mov eax, edx" \
|
---|
205 | "cpuid" \
|
---|
206 | "mov es:[di+0], eax" \
|
---|
207 | "mov es:[di+4], ebx" \
|
---|
208 | "mov es:[di+8], ecx" \
|
---|
209 | "mov es:[di+12], edx" \
|
---|
210 | parm [es di] [dx ax] modify [bx cx dx]
|
---|
211 |
|
---|
212 | #endif
|
---|