1 | /* $Id: inlines.h 84752 2020-06-10 10:58:33Z 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 | /* Output a null-terminated string to a specified port, without the
|
---|
103 | * terminating null character.
|
---|
104 | */
|
---|
105 | static void out_ctrl_str_asm(uint16_t port, const char *s);
|
---|
106 | #pragma aux out_ctrl_str_asm = \
|
---|
107 | "mov al, [bx]" \
|
---|
108 | "next:" \
|
---|
109 | "out dx, al" \
|
---|
110 | "inc bx" \
|
---|
111 | "mov al, [bx]" \
|
---|
112 | "or al, al" \
|
---|
113 | "jnz next" \
|
---|
114 | parm [dx] [bx] modify exact [ax bx] nomemory;
|
---|
115 |
|
---|
116 | #ifdef __386__
|
---|
117 |
|
---|
118 | void rep_movsb(void __far *d, void __far *s, int nbytes);
|
---|
119 | #pragma aux rep_movsb = \
|
---|
120 | "push ds" \
|
---|
121 | "mov ds, dx" \
|
---|
122 | "rep movsb" \
|
---|
123 | "pop ds" \
|
---|
124 | parm [es edi] [dx esi] [ecx];
|
---|
125 |
|
---|
126 | #else
|
---|
127 |
|
---|
128 | void rep_movsb(void __far *d, void __far *s, int nbytes);
|
---|
129 | #pragma aux rep_movsb = \
|
---|
130 | "push ds" \
|
---|
131 | "mov ds, dx" \
|
---|
132 | "rep movsb" \
|
---|
133 | "pop ds" \
|
---|
134 | parm [es di] [dx si] [cx];
|
---|
135 |
|
---|
136 | #endif
|
---|
137 |
|
---|
138 | void rep_movsw(void __far *d, void __far *s, int nwords);
|
---|
139 | #pragma aux rep_movsw = \
|
---|
140 | "push ds" \
|
---|
141 | "mov ds, dx" \
|
---|
142 | "rep movsw" \
|
---|
143 | "pop ds" \
|
---|
144 | parm [es di] [dx si] [cx];
|
---|
145 |
|
---|
146 | #ifndef __386__
|
---|
147 |
|
---|
148 | char __far *rep_insb(char __far *buffer, unsigned nbytes, unsigned port);
|
---|
149 | #pragma aux rep_insb = ".286" "rep insb" parm [es di] [cx] [dx] value [es di] modify exact [cx di];
|
---|
150 |
|
---|
151 | char __far *rep_insw(char __far *buffer, unsigned nwords, unsigned port);
|
---|
152 | #pragma aux rep_insw = ".286" "rep insw" parm [es di] [cx] [dx] value [es di] modify exact [cx di];
|
---|
153 |
|
---|
154 | # if VBOX_BIOS_CPU >= 80386
|
---|
155 | char __far *rep_insd(char __far *buffer, unsigned ndwords, unsigned port);
|
---|
156 | # pragma aux rep_insd = ".386" "rep insd" parm [es di] [cx] [dx] value [es di] modify exact [cx di];
|
---|
157 | # endif
|
---|
158 |
|
---|
159 | char __far *rep_outsb(char __far *buffer, unsigned nbytes, unsigned port);
|
---|
160 | #pragma aux rep_outsb = ".286" "rep outs dx,byte ptr es:[si]" parm [es si] [cx] [dx] value [es si] modify exact [cx si];
|
---|
161 |
|
---|
162 | char __far *rep_outsw(char __far *buffer, unsigned nwords, unsigned port);
|
---|
163 | #pragma aux rep_outsw = ".286" "rep outs dx,word ptr es:[si]" parm [es si] [cx] [dx] value [es si] modify exact [cx si];
|
---|
164 |
|
---|
165 | # if VBOX_BIOS_CPU >= 80386
|
---|
166 | char __far *rep_outsd(char __far *buffer, unsigned ndwords, unsigned port);
|
---|
167 | # pragma aux rep_outsd = ".386" "rep outs dx,dword ptr es:[si]" parm [es si] [cx] [dx] value [es si] modify exact [cx si];
|
---|
168 | # endif
|
---|
169 |
|
---|
170 | uint16_t swap_16(uint16_t val);
|
---|
171 | #pragma aux swap_16 = "xchg ah,al" parm [ax] value [ax] modify exact [ax] nomemory;
|
---|
172 |
|
---|
173 | uint32_t swap_32(uint32_t val);
|
---|
174 | #pragma aux swap_32 = \
|
---|
175 | "xchg ah, al" \
|
---|
176 | "xchg dh, dl" \
|
---|
177 | "xchg ax, dx" \
|
---|
178 | parm [dx ax] value [dx ax] modify exact [dx ax] nomemory;
|
---|
179 |
|
---|
180 | uint64_t swap_64(uint64_t val);
|
---|
181 | #pragma aux swap_64 = \
|
---|
182 | "xchg ah, al" \
|
---|
183 | "xchg bh, bl" \
|
---|
184 | "xchg ch, cl" \
|
---|
185 | "xchg dh, dl" \
|
---|
186 | "xchg ax, dx" \
|
---|
187 | "xchg bx, cx" \
|
---|
188 | parm [ax bx cx dx] value [ax bx cx dx] modify exact [ax bx cx dx] nomemory;
|
---|
189 |
|
---|
190 | #endif
|
---|
191 |
|
---|
192 | #if VBOX_BIOS_CPU >= 80386
|
---|
193 |
|
---|
194 | /* Warning: msr_read/msr_write destroy high bits of 32-bit registers (EAX, ECX, EDX). */
|
---|
195 |
|
---|
196 | uint64_t msr_read(uint32_t msr);
|
---|
197 | #pragma aux msr_read = \
|
---|
198 | ".586" \
|
---|
199 | "shl ecx, 16" \
|
---|
200 | "mov cx, ax" \
|
---|
201 | "rdmsr" \
|
---|
202 | "xchg eax, edx" \
|
---|
203 | "mov bx, ax" \
|
---|
204 | "shr eax, 16" \
|
---|
205 | "mov cx, dx" \
|
---|
206 | "shr edx, 16" \
|
---|
207 | "xchg dx, cx" \
|
---|
208 | parm [cx ax] value [ax bx cx dx] modify [] nomemory;
|
---|
209 |
|
---|
210 | void msr_write(uint64_t val, uint32_t msr);
|
---|
211 | #pragma aux msr_write = \
|
---|
212 | ".586" \
|
---|
213 | "shl eax, 16" \
|
---|
214 | "mov ax, bx" \
|
---|
215 | "xchg dx, cx" \
|
---|
216 | "shl edx, 16" \
|
---|
217 | "mov dx, cx" \
|
---|
218 | "xchg eax, edx" \
|
---|
219 | "mov cx, di" \
|
---|
220 | "shl ecx, 16" \
|
---|
221 | "mov cx, si" \
|
---|
222 | "wrmsr" \
|
---|
223 | parm [ax bx cx dx] [di si] modify [] nomemory;
|
---|
224 |
|
---|
225 | /* Warning: eflags_read/eflags_write destroy high bits of 32-bit registers (EDX). */
|
---|
226 | uint32_t eflags_read( void );
|
---|
227 | #pragma aux eflags_read = \
|
---|
228 | ".386" \
|
---|
229 | "pushfd" \
|
---|
230 | "pop edx" \
|
---|
231 | "mov ax, dx" \
|
---|
232 | "shr edx, 16" \
|
---|
233 | value [dx ax] modify [dx ax];
|
---|
234 |
|
---|
235 | uint32_t eflags_write( uint32_t e_flags );
|
---|
236 | #pragma aux eflags_write = \
|
---|
237 | ".386" \
|
---|
238 | "shl edx, 16" \
|
---|
239 | "mov dx, ax" \
|
---|
240 | "push edx" \
|
---|
241 | "popfd" \
|
---|
242 | parm [dx ax] modify [dx ax];
|
---|
243 |
|
---|
244 | /* Warning cpuid destroys high bits of 32-bit registers (EAX, EBX, ECX, EDX). */
|
---|
245 | void cpuid( uint32_t __far cpu_id[4], uint32_t leaf );
|
---|
246 | #pragma aux cpuid = \
|
---|
247 | ".586" \
|
---|
248 | "shl edx, 16" \
|
---|
249 | "mov dx, ax" \
|
---|
250 | "mov eax, edx" \
|
---|
251 | "cpuid" \
|
---|
252 | "mov es:[di+0], eax" \
|
---|
253 | "mov es:[di+4], ebx" \
|
---|
254 | "mov es:[di+8], ecx" \
|
---|
255 | "mov es:[di+12], edx" \
|
---|
256 | parm [es di] [dx ax] modify [bx cx dx]
|
---|
257 |
|
---|
258 | #endif
|
---|
259 |
|
---|
260 | #endif /* !VBOX_INCLUDED_SRC_PC_BIOS_inlines_h */
|
---|
261 |
|
---|