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