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