xref: /illumos-gate/usr/src/test/bhyve-tests/tests/common/payload_utils.S (revision 85dff7a05711e1238299281f8a94d2d40834c775)
1/*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source.  A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12/*
13 * Copyright 2022 Oxide Computer Company
14 */
15
16#include <sys/asm_linkage.h>
17
18/* void outb(uint16_t port, uint8_t val) */
19ENTRY(outb)
20	movw    %di, %dx
21	movb    %sil, %al
22	outb    (%dx)
23	ret
24SET_SIZE(outb)
25
26/* void outw(uint16_t port, uint16_t val) */
27ENTRY(outw)
28	movw    %di, %dx
29	movw    %si, %ax
30	outw    (%dx)
31	ret
32SET_SIZE(outb)
33
34/* void outl(uint16_t port, uint32_t val) */
35ENTRY(outl)
36	movw    %di, %dx
37	movl    %esi, %eax
38	outl    (%dx)
39	ret
40SET_SIZE(outl)
41
42/* uint8_t inb(uint16_t port) */
43ENTRY(inb)
44	movw    %di, %dx
45	inb    (%dx)
46	ret
47SET_SIZE(inb)
48
49/* uint16_t inw(uint16_t port) */
50ENTRY(inw)
51	movw    %di, %dx
52	inw    (%dx)
53	ret
54SET_SIZE(inw)
55
56/* uint32_t inl(uint16_t port) */
57ENTRY(inl)
58	movw    %di, %dx
59	inl    (%dx)
60	ret
61SET_SIZE(inl)
62
63/* uint64_t wrmsr(uint32_t msr) */
64ENTRY(rdmsr)
65	movl    %edi, %ecx
66	rdmsr
67	shlq    $32, %rdx
68	orq     %rdx, %rax
69	ret
70SET_SIZE(rdmsr)
71
72/* void wrmsr(uint32_t msr, uint64_t val) */
73ENTRY(wrmsr)
74	movq    %rsi, %rdx
75	shrq    $32, %rdx
76	movl    %esi, %eax
77	movl    %edi, %ecx
78	wrmsr
79	ret
80SET_SIZE(wrmsr)
81
82/* void cpuid(uint32_t in_eax, uint32_t in_ecx, uint32_t *out_regs) */
83ENTRY(cpuid)
84	pushq   %rbx
85	movl    %edi, %eax
86	movl    %esi, %ecx
87	movq    %rdx, %r8
88	cpuid
89	movl    %eax, (%r8)
90	movl    %ebx, 4(%r8)
91	movl    %ecx, 8(%r8)
92	movl    %edx, 12(%r8)
93	popq    %rbx
94	ret
95SET_SIZE(cpuid)
96