xref: /titanic_51/usr/src/uts/i86pc/ml/amd64.il (revision a563a037ee1e9e7c39304f3775eb7327ab86b914)
1ae115bc7Smrj/*
2ae115bc7Smrj * CDDL HEADER START
3ae115bc7Smrj *
4ae115bc7Smrj * The contents of this file are subject to the terms of the
5ae115bc7Smrj * Common Development and Distribution License (the "License").
6ae115bc7Smrj * You may not use this file except in compliance with the License.
7ae115bc7Smrj *
8ae115bc7Smrj * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9ae115bc7Smrj * or http://www.opensolaris.org/os/licensing.
10ae115bc7Smrj * See the License for the specific language governing permissions
11ae115bc7Smrj * and limitations under the License.
12ae115bc7Smrj *
13ae115bc7Smrj * When distributing Covered Code, include this CDDL HEADER in each
14ae115bc7Smrj * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15ae115bc7Smrj * If applicable, add the following below this CDDL HEADER, with the
16ae115bc7Smrj * fields enclosed by brackets "[]" replaced with your own identifying
17ae115bc7Smrj * information: Portions Copyright [yyyy] [name of copyright owner]
18ae115bc7Smrj *
19ae115bc7Smrj * CDDL HEADER END
20ae115bc7Smrj */
21ae115bc7Smrj
22ae115bc7Smrj/*
23*a563a037Sbholler * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24ae115bc7Smrj * Use is subject to license terms.
25ae115bc7Smrj */
26ae115bc7Smrj
27ae115bc7Smrj#pragma ident	"%Z%%M%	%I%	%E% SMI"
28ae115bc7Smrj
29ae115bc7Smrj/
30ae115bc7Smrj/ Inline functions specific to the i86pc kernel running on bare metal.
31ae115bc7Smrj/
32ae115bc7Smrj
33ae115bc7Smrj/
34ae115bc7Smrj/ return value of cr3 register
35ae115bc7Smrj/
36ae115bc7Smrj	.inline	getcr3,0
37ae115bc7Smrj	movq	%cr3, %rax
38ae115bc7Smrj	.end
39ae115bc7Smrj
40ae115bc7Smrj/
41ae115bc7Smrj/ reload cr3 register with its current value
42ae115bc7Smrj/
43ae115bc7Smrj	.inline	reload_cr3,0
44ae115bc7Smrj	movq	%cr3, %rdi
45ae115bc7Smrj	movq	%rdi, %cr3
46ae115bc7Smrj	.end
47ae115bc7Smrj
48ae115bc7Smrj/
49ae115bc7Smrj/ return value of cr8 register
50ae115bc7Smrj/
51ae115bc7Smrj	.inline	getcr8,0
52ae115bc7Smrj	movq	%cr8, %rax
53ae115bc7Smrj	.end
54ae115bc7Smrj
55ae115bc7Smrj/
56ae115bc7Smrj/ set cr8 register
57ae115bc7Smrj/
58ae115bc7Smrj	.inline	setcr8,0
59ae115bc7Smrj	movq	%rdi, %cr8
60ae115bc7Smrj	.end
61ae115bc7Smrj
62ae115bc7Smrj/
63ae115bc7Smrj/ enable interrupts
64ae115bc7Smrj/
65ae115bc7Smrj	.inline	sti,0
66ae115bc7Smrj	sti
67ae115bc7Smrj	.end
68ae115bc7Smrj
69ae115bc7Smrj/
70ae115bc7Smrj/ disable interrupts
71ae115bc7Smrj/
72ae115bc7Smrj	.inline cli,0
73ae115bc7Smrj	cli
74ae115bc7Smrj	.end
75ae115bc7Smrj
76ae115bc7Smrj/
77ae115bc7Smrj/ disable interrupts and return value describing if interrupts were enabled
78ae115bc7Smrj/
79ae115bc7Smrj	.inline	clear_int_flag,0
80ae115bc7Smrj	pushfq
81ae115bc7Smrj	cli
82ae115bc7Smrj	popq	%rax
83ae115bc7Smrj	.end
84ae115bc7Smrj
85ae115bc7Smrj	.inline	intr_clear,0
86ae115bc7Smrj	pushfq
87ae115bc7Smrj	cli
88ae115bc7Smrj	popq	%rax
89ae115bc7Smrj	.end
90ae115bc7Smrj
91ae115bc7Smrj/
92ae115bc7Smrj/ return the value of the flags register
93ae115bc7Smrj/
94ae115bc7Smrj	.inline	getflags,0
95ae115bc7Smrj	pushfq
96ae115bc7Smrj	popq	%rax
97ae115bc7Smrj	.end
98ae115bc7Smrj
99ae115bc7Smrj/
100ae115bc7Smrj/ restore interrupt enable flag to value returned from 'clear_int_flag' above
101ae115bc7Smrj/
102ae115bc7Smrj	.inline restore_int_flag,4
103*a563a037Sbholler	testq	$0x200, %rdi
104*a563a037Sbholler	jz	1f
105*a563a037Sbholler	sti
106*a563a037Sbholler1:
107ae115bc7Smrj	.end
108ae115bc7Smrj
109ae115bc7Smrj	.inline intr_restore,4
110*a563a037Sbholler	testq	$0x200, %rdi
111*a563a037Sbholler	jz	1f
112*a563a037Sbholler	sti
113*a563a037Sbholler1:
114ae115bc7Smrj	.end
115ae115bc7Smrj
116ae115bc7Smrj/
117ae115bc7Smrj/ in and out
118ae115bc7Smrj/
119ae115bc7Smrj	.inline	inb,4
120ae115bc7Smrj	movq	%rdi, %rdx
121ae115bc7Smrj	xorq    %rax, %rax
122ae115bc7Smrj	inb	(%dx)
123ae115bc7Smrj	.end
124ae115bc7Smrj
125ae115bc7Smrj	.inline	inw,4
126ae115bc7Smrj	movq	%rdi, %rdx
127ae115bc7Smrj	xorq    %rax, %rax
128ae115bc7Smrj	inw	(%dx)
129ae115bc7Smrj	.end
130ae115bc7Smrj
131ae115bc7Smrj	.inline	inl,4
132ae115bc7Smrj	movq	%rdi, %rdx
133ae115bc7Smrj	xorq    %rax, %rax
134ae115bc7Smrj	inl	(%dx)
135ae115bc7Smrj	.end
136ae115bc7Smrj
137ae115bc7Smrj	.inline	outb,8
138ae115bc7Smrj	movq	%rdi, %rdx
139ae115bc7Smrj	movq	%rsi, %rax
140ae115bc7Smrj	outb	(%dx)
141ae115bc7Smrj	.end
142ae115bc7Smrj
143ae115bc7Smrj	.inline	outw,8
144ae115bc7Smrj	movq	%rdi, %rdx
145ae115bc7Smrj	movq	%rsi, %rax
146ae115bc7Smrj	outw	(%dx)
147ae115bc7Smrj	.end
148ae115bc7Smrj
149ae115bc7Smrj	.inline	outl,8
150ae115bc7Smrj	movq	%rdi, %rdx
151ae115bc7Smrj	movq	%rsi, %rax
152ae115bc7Smrj	outl	(%dx)
153ae115bc7Smrj	.end
154ae115bc7Smrj
155ae115bc7Smrj/*
156ae115bc7Smrj * Call the halt instruction. This will put the CPU to sleep until
157ae115bc7Smrj * it is again awoken via an interrupt.
158ae115bc7Smrj * This function should be called with interrupts already disabled
159ae115bc7Smrj * for the CPU.
160ae115bc7Smrj * Note that "sti" will only enable interrupts at the end of the
161ae115bc7Smrj * subsequent instruction...in this case: "hlt".
162ae115bc7Smrj */
163ae115bc7Smrj	.inline i86_halt,0
164ae115bc7Smrj	sti
165ae115bc7Smrj	hlt
166ae115bc7Smrj	.end
167ae115bc7Smrj/
168ae115bc7Smrj/ execute the bsrw instruction
169ae115bc7Smrj/
170ae115bc7Smrj	.inline bsrw_insn,4
171ae115bc7Smrj	xorl	%eax, %eax
172ae115bc7Smrj	bsrw	%di, %ax
173ae115bc7Smrj	.end
174ae115bc7Smrj
175