]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/mcount.s
xnu-517.7.7.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 pushf // save interrupt state
31 cli // disable interrupts
32
33 //
34 // Check that %gs, with segment pointing at the per-cpu data area,
35 // has been set up. C routines (mp_desc_init() in particular) may
36 // be called very early before this happens.
37 //
38 mov %gs,%ax
39 test %ax,%ax
40 jz 1f
41
42 //
43 // Check that this cpu is ready.
44 // This delays the start of mcounting until a cpu is really prepared.
45 //
46 movl %gs:CPD_CPU_STATUS,%eax
47 testl %eax,%eax
48 jz 1f
49
50 //
51 // Test for recursion as indicated by a per-cpu flag.
52 // Skip if nested, otherwise set the flag and call the C mount().
53 //
54 movl %gs:CPD_MCOUNT_OFF,%eax
55 testl %eax,%eax // test for recursion
56 jnz 1f
57 incl %gs:CPD_MCOUNT_OFF // set recursion flag
58
59 movl (%ebp),%eax // frame pointer of mcount's caller
60 movl 4(%eax),%eax // mcount's caller's return address
61 pushl 4(%ebp) // push selfpc parameter for mcount()
62 pushl %eax // push frompc parameter for mcount()
63 call _mcount // call the C mcount
64 addl $8,%esp // pop args
65
66 decl %gs:CPD_MCOUNT_OFF // turn off recursion flag
67 1:
68 popf // restore interrupt state
69 movl %ebp,%esp // tear down mcount's frame
70 popl %ebp
71 ret