]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/mcount.s
xnu-792.6.56.tar.gz
[apple/xnu.git] / osfmk / i386 / mcount.s
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #define __NO_UNDERSCORES__
25 #include <i386/asm.h>
26 #include <assym.s>
27
28 Entry(mcount)
29 pushl %ebp // setup mcount's frame
30 movl %esp,%ebp
31 pushl %eax // save %eax
32 pushf // save interrupt state
33 cli // disable interrupts
34
35 //
36 // Check that this cpu is ready.
37 // This delays the start of mcounting until a cpu is really prepared.
38 //
39 movl %gs:CPU_RUNNING,%eax
40 testl %eax,%eax
41 jz 1f
42
43 //
44 // Test for recursion as indicated by a per-cpu flag.
45 // Skip if nested, otherwise set the flag and call the C mount().
46 //
47 movl %gs:CPU_MCOUNT_OFF,%eax
48 testl %eax,%eax // test for recursion
49 jnz 1f
50
51 incl %gs:CPU_MCOUNT_OFF // set recursion flag
52
53 movl (%ebp),%eax // frame pointer of mcount's caller
54 movl 4(%eax),%eax // mcount's caller's return address
55 pushl 4(%ebp) // push selfpc parameter for mcount()
56 pushl %eax // push frompc parameter for mcount()
57 call _mcount // call the C mcount
58 addl $8,%esp // pop args
59
60 decl %gs:CPU_MCOUNT_OFF // turn off recursion flag
61 1:
62 popf // restore interrupt state
63 popl %eax
64 movl %ebp,%esp // tear down mcount's frame
65 popl %ebp
66 ret