VirtualBox

source: vbox/trunk/src/VBox/Devices/PC/BIOS/inlines.h@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/* $Id: inlines.h 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * Inline routines for Watcom C.
4 */
5
6/*
7 * Copyright (C) 2010-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef VBOX_INCLUDED_SRC_PC_BIOS_inlines_h
29#define VBOX_INCLUDED_SRC_PC_BIOS_inlines_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34extern unsigned inp(unsigned port);
35extern unsigned outp(unsigned port, unsigned value);
36extern unsigned inpw(unsigned port);
37extern unsigned outpw(unsigned port, unsigned value);
38#pragma intrinsic(inp,outp,inpw,outpw)
39#define inb(p) inp(p)
40#define outb(p, v) outp(p, v)
41#define inw(p) inpw(p)
42#define outw(p, v) outpw(p, v)
43
44/* Far byte/word/dword access routines. */
45
46inline uint8_t read_byte(uint16_t seg, uint16_t offset)
47{
48 return( *(seg:>(uint8_t *)offset) );
49}
50
51inline void write_byte(uint16_t seg, uint16_t offset, uint8_t data)
52{
53 *(seg:>(uint8_t *)offset) = data;
54}
55
56inline uint16_t read_word(uint16_t seg, uint16_t offset)
57{
58 return( *(seg:>(uint16_t *)offset) );
59}
60
61inline void write_word(uint16_t seg, uint16_t offset, uint16_t data)
62{
63 *(seg:>(uint16_t *)offset) = data;
64}
65
66inline uint32_t read_dword(uint16_t seg, uint16_t offset)
67{
68 return( *(seg:>(uint32_t *)offset) );
69}
70
71inline void write_dword(uint16_t seg, uint16_t offset, uint32_t data)
72{
73 *(seg:>(uint32_t *)offset) = data;
74}
75
76
77void int_enable(void);
78#pragma aux int_enable = "sti" modify exact [] nomemory;
79
80void int_disable(void);
81#pragma aux int_disable = "cli" modify exact [] nomemory;
82
83void int_enable_hlt_disable(void);
84#pragma aux int_enable_hlt_disable = \
85 "sti" \
86 "hlt" \
87 "cli" \
88 modify exact [] nomemory;
89
90uint16_t int_query(void);
91#pragma aux int_query = \
92 "pushf" \
93 "pop ax" \
94 value [ax] modify exact [ax] nomemory;
95
96void int_restore(uint16_t old_flags);
97#pragma aux int_restore = \
98 "push ax" \
99 "popf" \
100 parm [ax] modify exact [] nomemory;
101
102void halt(void);
103#pragma aux halt = "hlt" modify exact [] nomemory;
104
105void halt_forever(void);
106#pragma aux halt_forever = \
107 "forever:" \
108 "hlt" \
109 "jmp forever" \
110 modify exact [] nomemory aborts;
111
112/* Output a null-terminated string to a specified port, without the
113 * terminating null character.
114 */
115static void out_ctrl_str_asm(uint16_t port, const char *s);
116#pragma aux out_ctrl_str_asm = \
117 "mov al, [bx]" \
118 "next:" \
119 "out dx, al" \
120 "inc bx" \
121 "mov al, [bx]" \
122 "or al, al" \
123 "jnz next" \
124 parm [dx] [bx] modify exact [ax bx] nomemory;
125
126#ifdef __386__
127
128void 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 edi] [dx esi] [ecx];
135
136#else
137
138void rep_movsb(void __far *d, void __far *s, int nbytes);
139#pragma aux rep_movsb = \
140 "push ds" \
141 "mov ds, dx" \
142 "rep movsb" \
143 "pop ds" \
144 parm [es di] [dx si] [cx];
145
146#endif
147
148void rep_movsw(void __far *d, void __far *s, int nwords);
149#pragma aux rep_movsw = \
150 "push ds" \
151 "mov ds, dx" \
152 "rep movsw" \
153 "pop ds" \
154 parm [es di] [dx si] [cx];
155
156#ifndef __386__
157
158char __far *rep_insb(char __far *buffer, unsigned nbytes, unsigned port);
159#pragma aux rep_insb = ".286" "rep insb" parm [es di] [cx] [dx] value [es di] modify exact [cx di];
160
161char __far *rep_insw(char __far *buffer, unsigned nwords, unsigned port);
162#pragma aux rep_insw = ".286" "rep insw" parm [es di] [cx] [dx] value [es di] modify exact [cx di];
163
164# if VBOX_BIOS_CPU >= 80386
165char __far *rep_insd(char __far *buffer, unsigned ndwords, unsigned port);
166# pragma aux rep_insd = ".386" "rep insd" parm [es di] [cx] [dx] value [es di] modify exact [cx di];
167# endif
168
169char __far *rep_outsb(char __far *buffer, unsigned nbytes, unsigned port);
170#pragma aux rep_outsb = ".286" "rep outs dx,byte ptr es:[si]" parm [es si] [cx] [dx] value [es si] modify exact [cx si];
171
172char __far *rep_outsw(char __far *buffer, unsigned nwords, unsigned port);
173#pragma aux rep_outsw = ".286" "rep outs dx,word ptr es:[si]" parm [es si] [cx] [dx] value [es si] modify exact [cx si];
174
175# if VBOX_BIOS_CPU >= 80386
176char __far *rep_outsd(char __far *buffer, unsigned ndwords, unsigned port);
177# pragma aux rep_outsd = ".386" "rep outs dx,dword ptr es:[si]" parm [es si] [cx] [dx] value [es si] modify exact [cx si];
178# endif
179
180uint16_t swap_16(uint16_t val);
181#pragma aux swap_16 = "xchg ah,al" parm [ax] value [ax] modify exact [ax] nomemory;
182
183uint32_t swap_32(uint32_t val);
184#pragma aux swap_32 = \
185 "xchg ah, al" \
186 "xchg dh, dl" \
187 "xchg ax, dx" \
188 parm [dx ax] value [dx ax] modify exact [dx ax] nomemory;
189
190uint64_t swap_64(uint64_t val);
191#pragma aux swap_64 = \
192 "xchg ah, al" \
193 "xchg bh, bl" \
194 "xchg ch, cl" \
195 "xchg dh, dl" \
196 "xchg ax, dx" \
197 "xchg bx, cx" \
198 parm [ax bx cx dx] value [ax bx cx dx] modify exact [ax bx cx dx] nomemory;
199
200#endif
201
202#if VBOX_BIOS_CPU >= 80386
203
204/* Warning: msr_read/msr_write destroy high bits of 32-bit registers (EAX, ECX, EDX). */
205
206uint64_t msr_read(uint32_t msr);
207#pragma aux msr_read = \
208 ".586" \
209 "shl ecx, 16" \
210 "mov cx, ax" \
211 "rdmsr" \
212 "xchg eax, edx" \
213 "mov bx, ax" \
214 "shr eax, 16" \
215 "mov cx, dx" \
216 "shr edx, 16" \
217 "xchg dx, cx" \
218 parm [cx ax] value [ax bx cx dx] modify [] nomemory;
219
220void msr_write(uint64_t val, uint32_t msr);
221#pragma aux msr_write = \
222 ".586" \
223 "shl eax, 16" \
224 "mov ax, bx" \
225 "xchg dx, cx" \
226 "shl edx, 16" \
227 "mov dx, cx" \
228 "xchg eax, edx" \
229 "mov cx, di" \
230 "shl ecx, 16" \
231 "mov cx, si" \
232 "wrmsr" \
233 parm [ax bx cx dx] [di si] modify [] nomemory;
234
235/* Warning: eflags_read/eflags_write destroy high bits of 32-bit registers (EDX). */
236uint32_t eflags_read( void );
237#pragma aux eflags_read = \
238 ".386" \
239 "pushfd" \
240 "pop edx" \
241 "mov ax, dx" \
242 "shr edx, 16" \
243 value [dx ax] modify [dx ax];
244
245uint32_t eflags_write( uint32_t e_flags );
246#pragma aux eflags_write = \
247 ".386" \
248 "shl edx, 16" \
249 "mov dx, ax" \
250 "push edx" \
251 "popfd" \
252 parm [dx ax] modify [dx ax];
253
254/* Warning cpuid destroys high bits of 32-bit registers (EAX, EBX, ECX, EDX). */
255void cpuid( uint32_t __far cpu_id[4], uint32_t leaf );
256#pragma aux cpuid = \
257 ".586" \
258 "shl edx, 16" \
259 "mov dx, ax" \
260 "mov eax, edx" \
261 "cpuid" \
262 "mov es:[di+0], eax" \
263 "mov es:[di+4], ebx" \
264 "mov es:[di+8], ecx" \
265 "mov es:[di+12], edx" \
266 parm [es di] [dx ax] modify [bx cx dx]
267
268#endif
269
270#endif /* !VBOX_INCLUDED_SRC_PC_BIOS_inlines_h */
271
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette