2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 #define __NO_UNDERSCORES__
28 pushl %ebp // setup mcount's frame
30 pushf // save interrupt state
31 cli // disable interrupts
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.
43 // Check that this cpu is ready.
44 // This delays the start of mcounting until a cpu is really prepared.
46 movl %gs:CPD_CPU_STATUS,%eax
51 // Test for recursion as indicated by a per-cpu flag.
52 // Skip if nested, otherwise set the flag and call the C mount().
54 movl %gs:CPD_MCOUNT_OFF,%eax
55 testl %eax,%eax // test for recursion
57 incl %gs:CPD_MCOUNT_OFF // set recursion flag
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
66 decl %gs:CPD_MCOUNT_OFF // turn off recursion flag
68 popf // restore interrupt state
69 movl %ebp,%esp // tear down mcount's frame