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 movq %cr3, %rax 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 movq %cr3, %rdi 45*ae115bc7Smrj movq %rdi, %cr3 46*ae115bc7Smrj .end 47*ae115bc7Smrj 48*ae115bc7Smrj/ 49*ae115bc7Smrj/ return value of cr8 register 50*ae115bc7Smrj/ 51*ae115bc7Smrj .inline getcr8,0 52*ae115bc7Smrj movq %cr8, %rax 53*ae115bc7Smrj .end 54*ae115bc7Smrj 55*ae115bc7Smrj/ 56*ae115bc7Smrj/ set cr8 register 57*ae115bc7Smrj/ 58*ae115bc7Smrj .inline setcr8,0 59*ae115bc7Smrj movq %rdi, %cr8 60*ae115bc7Smrj .end 61*ae115bc7Smrj 62*ae115bc7Smrj/ 63*ae115bc7Smrj/ enable interrupts 64*ae115bc7Smrj/ 65*ae115bc7Smrj .inline sti,0 66*ae115bc7Smrj sti 67*ae115bc7Smrj .end 68*ae115bc7Smrj 69*ae115bc7Smrj/ 70*ae115bc7Smrj/ disable interrupts 71*ae115bc7Smrj/ 72*ae115bc7Smrj .inline cli,0 73*ae115bc7Smrj cli 74*ae115bc7Smrj .end 75*ae115bc7Smrj 76*ae115bc7Smrj/ 77*ae115bc7Smrj/ disable interrupts and return value describing if interrupts were enabled 78*ae115bc7Smrj/ 79*ae115bc7Smrj .inline clear_int_flag,0 80*ae115bc7Smrj pushfq 81*ae115bc7Smrj cli 82*ae115bc7Smrj popq %rax 83*ae115bc7Smrj .end 84*ae115bc7Smrj 85*ae115bc7Smrj .inline intr_clear,0 86*ae115bc7Smrj pushfq 87*ae115bc7Smrj cli 88*ae115bc7Smrj popq %rax 89*ae115bc7Smrj .end 90*ae115bc7Smrj 91*ae115bc7Smrj/ 92*ae115bc7Smrj/ return the value of the flags register 93*ae115bc7Smrj/ 94*ae115bc7Smrj .inline getflags,0 95*ae115bc7Smrj pushfq 96*ae115bc7Smrj popq %rax 97*ae115bc7Smrj .end 98*ae115bc7Smrj 99*ae115bc7Smrj/ 100*ae115bc7Smrj/ restore interrupt enable flag to value returned from 'clear_int_flag' above 101*ae115bc7Smrj/ 102*ae115bc7Smrj .inline restore_int_flag,4 103*ae115bc7Smrj pushq %rdi 104*ae115bc7Smrj popfq 105*ae115bc7Smrj .end 106*ae115bc7Smrj 107*ae115bc7Smrj .inline intr_restore,4 108*ae115bc7Smrj pushq %rdi 109*ae115bc7Smrj popfq 110*ae115bc7Smrj .end 111*ae115bc7Smrj 112*ae115bc7Smrj/ 113*ae115bc7Smrj/ in and out 114*ae115bc7Smrj/ 115*ae115bc7Smrj .inline inb,4 116*ae115bc7Smrj movq %rdi, %rdx 117*ae115bc7Smrj xorq %rax, %rax 118*ae115bc7Smrj inb (%dx) 119*ae115bc7Smrj .end 120*ae115bc7Smrj 121*ae115bc7Smrj .inline inw,4 122*ae115bc7Smrj movq %rdi, %rdx 123*ae115bc7Smrj xorq %rax, %rax 124*ae115bc7Smrj inw (%dx) 125*ae115bc7Smrj .end 126*ae115bc7Smrj 127*ae115bc7Smrj .inline inl,4 128*ae115bc7Smrj movq %rdi, %rdx 129*ae115bc7Smrj xorq %rax, %rax 130*ae115bc7Smrj inl (%dx) 131*ae115bc7Smrj .end 132*ae115bc7Smrj 133*ae115bc7Smrj .inline outb,8 134*ae115bc7Smrj movq %rdi, %rdx 135*ae115bc7Smrj movq %rsi, %rax 136*ae115bc7Smrj outb (%dx) 137*ae115bc7Smrj .end 138*ae115bc7Smrj 139*ae115bc7Smrj .inline outw,8 140*ae115bc7Smrj movq %rdi, %rdx 141*ae115bc7Smrj movq %rsi, %rax 142*ae115bc7Smrj outw (%dx) 143*ae115bc7Smrj .end 144*ae115bc7Smrj 145*ae115bc7Smrj .inline outl,8 146*ae115bc7Smrj movq %rdi, %rdx 147*ae115bc7Smrj movq %rsi, %rax 148*ae115bc7Smrj outl (%dx) 149*ae115bc7Smrj .end 150*ae115bc7Smrj 151*ae115bc7Smrj/* 152*ae115bc7Smrj * Read Time Stamp Counter 153*ae115bc7Smrj * uint64_t tsc_read(); 154*ae115bc7Smrj * 155*ae115bc7Smrj * usage: 156*ae115bc7Smrj * uint64_t cycles = tsc_read(); 157*ae115bc7Smrj */ 158*ae115bc7Smrj .inline tsc_read, 0 159*ae115bc7Smrj rdtsc / %edx:%eax = RDTSC 160*ae115bc7Smrj shlq $32, %rdx 161*ae115bc7Smrj orq %rdx, %rax 162*ae115bc7Smrj .end 163*ae115bc7Smrj 164*ae115bc7Smrj/* 165*ae115bc7Smrj * Call the halt instruction. This will put the CPU to sleep until 166*ae115bc7Smrj * it is again awoken via an interrupt. 167*ae115bc7Smrj * This function should be called with interrupts already disabled 168*ae115bc7Smrj * for the CPU. 169*ae115bc7Smrj * Note that "sti" will only enable interrupts at the end of the 170*ae115bc7Smrj * subsequent instruction...in this case: "hlt". 171*ae115bc7Smrj */ 172*ae115bc7Smrj .inline i86_halt,0 173*ae115bc7Smrj sti 174*ae115bc7Smrj hlt 175*ae115bc7Smrj .end 176*ae115bc7Smrj/ 177*ae115bc7Smrj/ execute the bsrw instruction 178*ae115bc7Smrj/ 179*ae115bc7Smrj .inline bsrw_insn,4 180*ae115bc7Smrj xorl %eax, %eax 181*ae115bc7Smrj bsrw %di, %ax 182*ae115bc7Smrj .end 183*ae115bc7Smrj 184