Clean up the USB driver directories, remove unbuilt source.
[dragonfly.git] / sys / platform / pc64 / isa / prof_machdep.c
blobaad250933059e6323132f390c1e741fe708adfcb
1 /*-
2 * Copyright (c) 1996 Bruce D. Evans.
3 * Copyright (c) 2008 The DragonFly Project.
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
27 * $FreeBSD: src/sys/i386/isa/prof_machdep.c,v 1.14.2.1 2000/08/03 00:09:30 ps Exp $
30 #ifdef GUPROF
31 #include "opt_i586_guprof.h"
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/gmon.h>
36 #include <sys/kernel.h>
37 #include <sys/sysctl.h>
39 #include <machine/clock.h>
40 #include <machine/profile.h>
41 #undef MCOUNT
42 #endif
44 #include <machine/asmacros.h>
46 #include <bus/isa/isa.h>
47 #include <machine_base/isa/timerreg.h>
49 #ifdef GUPROF
50 #define CPUTIME_CLOCK_UNINITIALIZED 0
51 #define CPUTIME_CLOCK_I8254 1
52 #define CPUTIME_CLOCK_TSC 2
53 #define CPUTIME_CLOCK_I586_PMC 3
54 #define CPUTIME_CLOCK_I8254_SHIFT 7
56 int cputime_bias = 1; /* initialize for locality of reference */
58 static int cputime_clock = CPUTIME_CLOCK_UNINITIALIZED;
59 #endif /* GUPROF */
61 #ifdef __GNUC__
62 __asm(" \n\
63 GM_STATE = 0 \n\
64 GMON_PROF_OFF = 3 \n\
65 \n\
66 .text \n\
67 .p2align 4,0x90 \n\
68 .globl __mcount \n\
69 .type __mcount,@function \n\
70 __mcount: \n\
71 # \n\
72 # Check that we are profiling. Do it early for speed. \n\
73 # \n\
74 cmpl $GMON_PROF_OFF," __XSTRING(CNAME(_gmonparam)) "+GM_STATE \n\
75 je .mcount_exit \n\
76 # \n\
77 # __mcount is the same as [.]mcount except the caller \n\
78 # hasn't changed the stack except to call here, so the \n\
79 # caller's raddr is above our raddr. \n\
80 # \n\
81 pushl %eax \n\
82 pushl %ecx \n\
83 pushl %edx \n\
84 movl 12+4(%esp),%edx \n\
85 jmp .got_frompc \n\
86 \n\
87 .p2align 4,0x90 \n\
88 .globl " __XSTRING(HIDENAME(mcount)) " \n\
89 " __XSTRING(HIDENAME(mcount)) ": \n\
90 cmpl $GMON_PROF_OFF," __XSTRING(CNAME(_gmonparam)) "+GM_STATE \n\
91 je .mcount_exit \n\
92 # \n\
93 # The caller's stack frame has already been built, so \n\
94 # %ebp is the caller's frame pointer. The caller's \n\
95 # raddr is in the caller's frame following the caller's \n\
96 # caller's frame pointer. \n\
97 # \n\
98 pushl %eax \n\
99 pushl %ecx \n\
100 pushl %edx \n\
101 movl 4(%ebp),%edx \n\
102 .got_frompc: \n\
103 # \n\
104 # Our raddr is the caller's pc. \n\
105 # \n\
106 movl (%esp),%eax \n\
108 pushfl \n\
109 pushl %eax \n\
110 pushl %edx \n\
111 cli \n\
112 call " __XSTRING(CNAME(mcount)) " \n\
113 addl $8,%esp \n\
114 popfl \n\
115 popl %edx \n\
116 popl %ecx \n\
117 popl %eax \n\
118 .mcount_exit: \n\
119 ret \n\
121 #else /* !__GNUC__ */
122 #error
123 #endif /* __GNUC__ */
125 #ifdef GUPROF
127 * [.]mexitcount saves the return register(s), loads selfpc and calls
128 * mexitcount(selfpc) to do the work. Someday it should be in a machine
129 * dependent file together with cputime(), __mcount and [.]mcount. cputime()
130 * can't just be put in machdep.c because it has to be compiled without -pg.
132 #ifdef __GNUC__
133 __asm(" \n\
134 .text \n\
135 # \n\
136 # Dummy label to be seen when gprof -u hides [.]mexitcount. \n\
137 # \n\
138 .p2align 4,0x90 \n\
139 .globl __mexitcount \n\
140 .type __mexitcount,@function \n\
141 __mexitcount: \n\
142 nop \n\
144 GMON_PROF_HIRES = 4 \n\
146 .p2align 4,0x90 \n\
147 .globl " __XSTRING(HIDENAME(mexitcount)) " \n\
148 " __XSTRING(HIDENAME(mexitcount)) ": \n\
149 cmpl $GMON_PROF_HIRES," __XSTRING(CNAME(_gmonparam)) "+GM_STATE \n\
150 jne .mexitcount_exit \n\
151 pushl %edx \n\
152 pushl %ecx \n\
153 pushl %eax \n\
154 movl 12(%esp),%eax \n\
155 pushfl \n\
156 pushl %eax \n\
157 cli \n\
158 call " __XSTRING(CNAME(mexitcount)) " \n\
159 addl $4,%esp \n\
160 popfl \n\
161 popl %eax \n\
162 popl %ecx \n\
163 popl %edx \n\
164 .mexitcount_exit: \n\
165 ret \n\
167 #else /* !__GNUC__ */
168 #error
169 #endif /* __GNUC__ */
172 * Return the time elapsed since the last call. The units are machine-
173 * dependent.
176 cputime(void)
178 u_int count;
179 int delta;
180 u_char high, low;
181 static u_int prev_count;
184 * Read the current value of the 8254 timer counter 0.
186 outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
187 low = inb(TIMER_CNTR0);
188 high = inb(TIMER_CNTR0);
189 count = ((high << 8) | low) << CPUTIME_CLOCK_I8254_SHIFT;
192 * The timer counts down from TIMER_CNTR0_MAX to 0 and then resets.
193 * While profiling is enabled, this routine is called at least twice
194 * per timer reset (for mcounting and mexitcounting hardclock()),
195 * so at most one reset has occurred since the last call, and one
196 * has occurred iff the current count is larger than the previous
197 * count. This allows counter underflow to be detected faster
198 * than in microtime().
200 delta = prev_count - count;
201 prev_count = count;
202 if (delta <= 0)
203 return (delta + (timer0_max_count << CPUTIME_CLOCK_I8254_SHIFT));
204 return (delta);
207 static int
208 sysctl_machdep_cputime_clock(SYSCTL_HANDLER_ARGS)
210 int clock;
211 int error;
213 clock = cputime_clock;
214 error = sysctl_handle_opaque(oidp, &clock, sizeof clock, req);
215 if (error == 0 && req->newptr != NULL) {
216 if (clock < 0 || clock >= CPUTIME_CLOCK_I586_PMC)
217 return (EINVAL);
218 cputime_clock = clock;
220 return (error);
223 SYSCTL_PROC(_machdep, OID_AUTO, cputime_clock, CTLTYPE_INT | CTLFLAG_RW,
224 0, sizeof(u_int), sysctl_machdep_cputime_clock, "I", "");
227 * The start and stop routines need not be here since we turn off profiling
228 * before calling them. They are here for convenience.
231 void
232 startguprof(struct gmonparam *gp)
234 if (cputime_clock == CPUTIME_CLOCK_UNINITIALIZED)
235 cputime_clock = CPUTIME_CLOCK_I8254;
236 gp->profrate = timer_freq << CPUTIME_CLOCK_I8254_SHIFT;
237 cputime_bias = 0;
238 cputime();
241 void
242 stopguprof(struct gmonparam *gp)
246 #else /* !GUPROF */
247 #ifdef __GNUC__
248 __asm(" \n\
249 .text \n\
250 .p2align 4,0x90 \n\
251 .globl " __XSTRING(HIDENAME(mexitcount)) " \n\
252 " __XSTRING(HIDENAME(mexitcount)) ": \n\
253 ret \n\
255 #else /* !__GNUC__ */
256 #error
257 #endif /* __GNUC__ */
258 #endif /* GUPROF */