]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/mcount.s
xnu-792.10.96.tar.gz
[apple/xnu.git] / osfmk / i386 / mcount.s
CommitLineData
55e303ae
A
1/*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
A
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.
55e303ae 11 *
37839358
A
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
55e303ae
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
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.
55e303ae
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23#define __NO_UNDERSCORES__
24#include <i386/asm.h>
25#include <assym.s>
26
27Entry(mcount)
28 pushl %ebp // setup mcount's frame
29 movl %esp,%ebp
91447636 30 pushl %eax // save %eax
55e303ae
A
31 pushf // save interrupt state
32 cli // disable interrupts
33
55e303ae
A
34 //
35 // Check that this cpu is ready.
36 // This delays the start of mcounting until a cpu is really prepared.
37 //
91447636 38 movl %gs:CPU_RUNNING,%eax
55e303ae
A
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 //
91447636 46 movl %gs:CPU_MCOUNT_OFF,%eax
55e303ae
A
47 testl %eax,%eax // test for recursion
48 jnz 1f
91447636
A
49
50 incl %gs:CPU_MCOUNT_OFF // set recursion flag
55e303ae
A
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
91447636 59 decl %gs:CPU_MCOUNT_OFF // turn off recursion flag
55e303ae
A
601:
61 popf // restore interrupt state
91447636 62 popl %eax
55e303ae
A
63 movl %ebp,%esp // tear down mcount's frame
64 popl %ebp
65 ret