]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/mcount.s
xnu-792.24.17.tar.gz
[apple/xnu.git] / osfmk / ppc / mcount.s
1 /*
2 * Copyright (c) 2000 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 #include <ppc/asm.h>
23 #include <ppc/proc_reg.h>
24 #include <assym.s>
25 #include <debug.h>
26 #include <mach/ppc/vm_param.h>
27 #include <ppc/exception.h>
28
29
30 /*
31 * The compiler generates calls to this function and passes address
32 * of caller of the function [ from which mcount is called ] as the
33 * first parameter.
34 * mcount disables interrupts prior to call mcount() and restores
35 * interrupt upon return.
36 * To prevent recursive calls to mcount(), a flag, mcountOff, is set
37 * in cpu_flags per_proc.
38 */
39
40 .align 4
41 .globl mcount
42 mcount:
43 mflr r0 ; Load lr
44 stw r0,8(r1) ; Save lr on the stack
45 stwu r1,-64(r1) ; Get a stack frame
46 mfmsr r9 ; Get msr
47 rlwinm r9,r9,0,MSR_FP_BIT+1,MSR_FP_BIT-1 ; Force floating point off
48 rlwinm r9,r9,0,MSR_VEC_BIT+1,MSR_VEC_BIT-1 ; Force vectors off
49 rlwinm r8,r9,0,MSR_EE_BIT+1,MSR_EE_BIT-1 ; Turn off interruptions
50 mtmsr r8 ; Update msr
51 isync
52 mfsprg r7,1 ; Get the current activation
53 lwz r7,ACT_PER_PROC(r7) ; Get the per_proc block
54 lhz r6,PP_CPU_FLAGS(r7) ; Get cpu flags
55 ori r5,r6,mcountOff ;
56 cmplw r5,r6 ; is mount off
57 beq mcount_ret ; return if off
58 sth r5,PP_CPU_FLAGS(r7) ; Update cpu_flags
59 stw r9,FM_ARG0(r1) ; Save MSR
60 mr r4, r0
61 bl _mcount ; Call the C routine
62 lwz r9,FM_ARG0(r1)
63 mfsprg r7,1 ; Get the current activation
64 lwz r7,ACT_PER_PROC(r7) ; Get the per_proc block
65 lhz r6,PP_CPU_FLAGS(r7) ; Get CPU number
66 li r5,mcountOff ;
67 andc r6,r6,r5 ; Clear mcount_off
68 sth r6,PP_CPU_FLAGS(r7) ; Save cpu_flags
69 mcount_ret:
70 addi r1,r1,64
71 mtmsr r9 ; Restore MSR
72 lwz r0,8(r1)
73 mtlr r0
74 blr
75