xref: /titanic_41/usr/src/uts/i86pc/ml/amd64.il (revision 193974072f41a843678abf5f61979c748687e66b)
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/*
23a563a037Sbholler * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24ae115bc7Smrj * Use is subject to license terms.
25ae115bc7Smrj */
26ae115bc7Smrj
27ae115bc7Smrj
28ae115bc7Smrj/
29ae115bc7Smrj/ Inline functions specific to the i86pc kernel running on bare metal.
30ae115bc7Smrj/
31ae115bc7Smrj
32ae115bc7Smrj/
33ae115bc7Smrj/ return value of cr3 register
34ae115bc7Smrj/
35ae115bc7Smrj	.inline	getcr3,0
36ae115bc7Smrj	movq	%cr3, %rax
37ae115bc7Smrj	.end
38ae115bc7Smrj
39ae115bc7Smrj/
40ae115bc7Smrj/ reload cr3 register with its current value
41ae115bc7Smrj/
42ae115bc7Smrj	.inline	reload_cr3,0
43ae115bc7Smrj	movq	%cr3, %rdi
44ae115bc7Smrj	movq	%rdi, %cr3
45ae115bc7Smrj	.end
46ae115bc7Smrj
47ae115bc7Smrj/
48*19397407SSherry Moore/ set cr3 register with new value
49*19397407SSherry Moore/
50*19397407SSherry Moore	.inline	setcr3,0
51*19397407SSherry Moore	movq	%rdi, %cr3
52*19397407SSherry Moore	.end
53*19397407SSherry Moore
54*19397407SSherry Moore/
55ae115bc7Smrj/ return value of cr8 register
56ae115bc7Smrj/
57ae115bc7Smrj	.inline	getcr8,0
58ae115bc7Smrj	movq	%cr8, %rax
59ae115bc7Smrj	.end
60ae115bc7Smrj
61ae115bc7Smrj/
62ae115bc7Smrj/ set cr8 register
63ae115bc7Smrj/
64ae115bc7Smrj	.inline	setcr8,0
65ae115bc7Smrj	movq	%rdi, %cr8
66ae115bc7Smrj	.end
67ae115bc7Smrj
68ae115bc7Smrj/
69ae115bc7Smrj/ enable interrupts
70ae115bc7Smrj/
71ae115bc7Smrj	.inline	sti,0
72ae115bc7Smrj	sti
73ae115bc7Smrj	.end
74ae115bc7Smrj
75ae115bc7Smrj/
76ae115bc7Smrj/ disable interrupts
77ae115bc7Smrj/
78ae115bc7Smrj	.inline cli,0
79ae115bc7Smrj	cli
80ae115bc7Smrj	.end
81ae115bc7Smrj
82ae115bc7Smrj/
83ae115bc7Smrj/ disable interrupts and return value describing if interrupts were enabled
84ae115bc7Smrj/
85ae115bc7Smrj	.inline	clear_int_flag,0
86ae115bc7Smrj	pushfq
87ae115bc7Smrj	cli
88ae115bc7Smrj	popq	%rax
89ae115bc7Smrj	.end
90ae115bc7Smrj
91ae115bc7Smrj	.inline	intr_clear,0
92ae115bc7Smrj	pushfq
93ae115bc7Smrj	cli
94ae115bc7Smrj	popq	%rax
95ae115bc7Smrj	.end
96ae115bc7Smrj
97ae115bc7Smrj/
98ae115bc7Smrj/ return the value of the flags register
99ae115bc7Smrj/
100ae115bc7Smrj	.inline	getflags,0
101ae115bc7Smrj	pushfq
102ae115bc7Smrj	popq	%rax
103ae115bc7Smrj	.end
104ae115bc7Smrj
105ae115bc7Smrj/
106ae115bc7Smrj/ restore interrupt enable flag to value returned from 'clear_int_flag' above
107ae115bc7Smrj/
108ae115bc7Smrj	.inline restore_int_flag,4
109a563a037Sbholler	testq	$0x200, %rdi
110a563a037Sbholler	jz	1f
111a563a037Sbholler	sti
112a563a037Sbholler1:
113ae115bc7Smrj	.end
114ae115bc7Smrj
115ae115bc7Smrj	.inline intr_restore,4
116a563a037Sbholler	testq	$0x200, %rdi
117a563a037Sbholler	jz	1f
118a563a037Sbholler	sti
119a563a037Sbholler1:
120ae115bc7Smrj	.end
121ae115bc7Smrj
122ae115bc7Smrj/
123ae115bc7Smrj/ in and out
124ae115bc7Smrj/
125ae115bc7Smrj	.inline	inb,4
126ae115bc7Smrj	movq	%rdi, %rdx
127ae115bc7Smrj	xorq    %rax, %rax
128ae115bc7Smrj	inb	(%dx)
129ae115bc7Smrj	.end
130ae115bc7Smrj
131ae115bc7Smrj	.inline	inw,4
132ae115bc7Smrj	movq	%rdi, %rdx
133ae115bc7Smrj	xorq    %rax, %rax
134ae115bc7Smrj	inw	(%dx)
135ae115bc7Smrj	.end
136ae115bc7Smrj
137ae115bc7Smrj	.inline	inl,4
138ae115bc7Smrj	movq	%rdi, %rdx
139ae115bc7Smrj	xorq    %rax, %rax
140ae115bc7Smrj	inl	(%dx)
141ae115bc7Smrj	.end
142ae115bc7Smrj
143ae115bc7Smrj	.inline	outb,8
144ae115bc7Smrj	movq	%rdi, %rdx
145ae115bc7Smrj	movq	%rsi, %rax
146ae115bc7Smrj	outb	(%dx)
147ae115bc7Smrj	.end
148ae115bc7Smrj
149ae115bc7Smrj	.inline	outw,8
150ae115bc7Smrj	movq	%rdi, %rdx
151ae115bc7Smrj	movq	%rsi, %rax
152ae115bc7Smrj	outw	(%dx)
153ae115bc7Smrj	.end
154ae115bc7Smrj
155ae115bc7Smrj	.inline	outl,8
156ae115bc7Smrj	movq	%rdi, %rdx
157ae115bc7Smrj	movq	%rsi, %rax
158ae115bc7Smrj	outl	(%dx)
159ae115bc7Smrj	.end
160ae115bc7Smrj
161ae115bc7Smrj/*
162ae115bc7Smrj * Call the halt instruction. This will put the CPU to sleep until
163ae115bc7Smrj * it is again awoken via an interrupt.
164ae115bc7Smrj * This function should be called with interrupts already disabled
165ae115bc7Smrj * for the CPU.
166ae115bc7Smrj * Note that "sti" will only enable interrupts at the end of the
167ae115bc7Smrj * subsequent instruction...in this case: "hlt".
168ae115bc7Smrj */
169ae115bc7Smrj	.inline i86_halt,0
170ae115bc7Smrj	sti
171ae115bc7Smrj	hlt
172ae115bc7Smrj	.end
173ae115bc7Smrj/
174ae115bc7Smrj/ execute the bsrw instruction
175ae115bc7Smrj/
176ae115bc7Smrj	.inline bsrw_insn,4
177ae115bc7Smrj	xorl	%eax, %eax
178ae115bc7Smrj	bsrw	%di, %ax
179ae115bc7Smrj	.end
180