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