]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/Diagnostics.c
2 * Copyright (c) 2000 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 * @OSF_FREE_COPYRIGHT@
26 * @APPLE_FREE_COPYRIGHT@
30 * Author: Bill Angell, Apple
37 #include <kern/machine.h>
38 #include <kern/processor.h>
39 #include <mach/machine.h>
40 #include <mach/processor_info.h>
41 #include <mach/mach_types.h>
42 #include <mach/boolean.h>
43 #include <kern/thread.h>
44 #include <kern/task.h>
45 #include <mach/vm_param.h>
46 #include <vm/vm_kern.h>
47 #include <vm/vm_map.h>
48 #include <vm/vm_page.h>
50 #include <ppc/exception.h>
51 #include <ppc/Firmware.h>
52 #include <ppc/low_trace.h>
53 #include <ppc/db_low_trace.h>
54 #include <ppc/mappings.h>
57 #include <ppc/pmap_internals.h>
58 #include <ppc/savearea.h>
59 #include <ppc/Diagnostics.h>
60 #include <ppc/machine_cpu.h>
61 #include <pexpert/pexpert.h>
63 int diagCall(struct savearea
*save
) {
66 unsigned long long tbase
;
69 natural_t tbu
, tbu2
, tbl
;
70 struct per_proc_info
*per_proc
; /* Area for my per_proc address */
73 if(!(dgWork
.dgFlags
& enaDiagSCs
)) return 0; /* If not enabled, cause an exception */
75 switch(save
->save_r3
) { /* Select the routine */
78 * Adjust the timebase for drift recovery testing
80 case dgAdjTB
: /* Adjust the timebase */
82 adj
.tb
[0] = 0; /* Clear high part */
83 adj
.tb
[1] = save
->save_r4
; /* Set low order */
84 if(adj
.tb
[1] & 0x80000000) adj
.tb
[0] = 0xFFFFFFFF; /* Propagate sign bit */
86 do { /* Read current time */
87 asm volatile(" mftbu %0" : "=r" (tbu
));
88 asm volatile(" mftb %0" : "=r" (tbl
));
89 asm volatile(" mftbu %0" : "=r" (tbu2
));
90 } while (tbu
!= tbu2
);
92 ttt
.tb
[0] = tbu
; /* Set high */
93 ttt
.tb
[1] = tbl
; /* Set low */
95 ttt
.tbase
= ttt
.tbase
+ adj
.tbase
; /* Increment or decrement the TB */
97 tbu
= ttt
.tb
[0]; /* Save in regular variable */
98 tbl
= ttt
.tb
[1]; /* Save in regular variable */
100 mttb(0); /* Set low to keep from ticking */
101 mttbu(tbu
); /* Set adjusted high */
102 mttb(tbl
); /* Set adjusted low */
104 return -1; /* Return no AST checking... */
107 * Return physical address of a page
111 save
->save_r3
= pmap_extract(current_act()->map
->pmap
, save
->save_r4
); /* Get read address */
113 return -1; /* Return no AST checking... */
116 * Copy physical to virtual
121 save
->save_r3
= copyp2v(save
->save_r4
, save
->save_r5
, save
->save_r6
); /* Copy the physical page */
123 return 1; /* Return and check for ASTs... */
127 * Soft reset processor
131 cpu
= save
->save_r4
; /* Get the requested CPU number */
133 if(cpu
>= NCPUS
) { /* Check for bogus cpu */
134 save
->save_r3
= KERN_FAILURE
; /* Set failure */
138 if(!machine_slot
[cpu
].running
) return KERN_FAILURE
; /* It is not running */
140 per_proc
= &per_proc_info
[cpu
]; /* Point to the processor */
142 (void)PE_cpu_start(per_proc
->cpu_id
,
143 per_proc
->start_paddr
, (vm_offset_t
)per_proc
);
145 save
->save_r3
= KERN_SUCCESS
; /* Set scuuess */
147 return 1; /* Return and check for ASTs... */
154 pmap_remove(kernel_pmap
, save
->save_r4
, save
->save_r4
+ 4096);
156 return 1; /* Return and check for ASTs... */
159 default: /* Handle invalid ones */
160 return 0; /* Return an exception */