]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/Diagnostics.c
ffa7e0f6481c252667d0034d63b8ebbc22c370dc
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>
62 #include <ppc/POWERMAC/video_console.h>
65 extern struct vc_info vinfo
;
67 kern_return_t
testPerfTrap(int trapno
, struct savearea
*ss
,
68 unsigned int dsisr
, unsigned int dar
);
70 int diagCall(struct savearea
*save
) {
73 unsigned long long tbase
;
76 natural_t tbu
, tbu2
, tbl
;
77 struct per_proc_info
*per_proc
; /* Area for my per_proc address */
79 unsigned int tstrt
, tend
, temp
, temp2
;
81 if(!(dgWork
.dgFlags
& enaDiagSCs
)) return 0; /* If not enabled, cause an exception */
83 switch(save
->save_r3
) { /* Select the routine */
86 * Adjust the timebase for drift recovery testing
88 case dgAdjTB
: /* Adjust the timebase */
90 adj
.tb
[0] = 0; /* Clear high part */
91 adj
.tb
[1] = save
->save_r4
; /* Set low order */
92 if(adj
.tb
[1] & 0x80000000) adj
.tb
[0] = 0xFFFFFFFF; /* Propagate sign bit */
94 do { /* Read current time */
95 asm volatile(" mftbu %0" : "=r" (tbu
));
96 asm volatile(" mftb %0" : "=r" (tbl
));
97 asm volatile(" mftbu %0" : "=r" (tbu2
));
98 } while (tbu
!= tbu2
);
100 ttt
.tb
[0] = tbu
; /* Set high */
101 ttt
.tb
[1] = tbl
; /* Set low */
103 ttt
.tbase
= ttt
.tbase
+ adj
.tbase
; /* Increment or decrement the TB */
105 tbu
= ttt
.tb
[0]; /* Save in regular variable */
106 tbl
= ttt
.tb
[1]; /* Save in regular variable */
108 mttb(0); /* Set low to keep from ticking */
109 mttbu(tbu
); /* Set adjusted high */
110 mttb(tbl
); /* Set adjusted low */
112 return -1; /* Return no AST checking... */
115 * Return physical address of a page
119 save
->save_r3
= pmap_extract(current_act()->map
->pmap
, save
->save_r4
); /* Get read address */
121 return -1; /* Return no AST checking... */
124 * Copy physical to virtual
129 save
->save_r3
= copyp2v(save
->save_r4
, save
->save_r5
, save
->save_r6
); /* Copy the physical page */
131 return 1; /* Return and check for ASTs... */
135 * Soft reset processor
139 cpu
= save
->save_r4
; /* Get the requested CPU number */
141 if(cpu
>= NCPUS
) { /* Check for bogus cpu */
142 save
->save_r3
= KERN_FAILURE
; /* Set failure */
146 if(!machine_slot
[cpu
].running
) return KERN_FAILURE
; /* It is not running */
148 per_proc
= &per_proc_info
[cpu
]; /* Point to the processor */
150 (void)PE_cpu_start(per_proc
->cpu_id
,
151 per_proc
->start_paddr
, (vm_offset_t
)per_proc
);
153 save
->save_r3
= KERN_SUCCESS
; /* Set scuuess */
155 return 1; /* Return and check for ASTs... */
163 cacheInit(); /* Blow cache */
165 asm volatile(" mftb %0" : "=r" (tstrt
));
167 while((tend
- tstrt
) < 0x000A2837) {
168 asm volatile(" mftb %0" : "=r" (tend
));
172 return 1; /* Return and check for ASTs... */
179 if(save
->save_r4
) perfTrapHook
= testPerfTrap
;
180 else perfTrapHook
= 0;
182 return 1; /* Return and check for ASTs... */
187 * Create a physical block map into the current task
188 * Don't bother to check for any errors.
189 * parms - vaddr, paddr, size, prot, attributes
193 pmap_map_block(current_act()->map
->pmap
, save
->save_r4
, save
->save_r5
, save
->save_r6
, /* Map in the block */
194 save
->save_r7
, save
->save_r8
, 0);
196 return 1; /* Return and check for ASTs... */
200 * Remove any mapping from the current task
201 * Don't bother to check for any errors.
206 (void)mapping_remove(current_act()->map
->pmap
, save
->save_r4
); /* Remove mapping */
207 return 1; /* Return and check for ASTs... */
211 * Allows direct control of alignment handling.
213 * The bottom two bits of the parameter are used to set the two control bits:
214 * 0b00 - !trapUnalignbit - !notifyUnalignbit - default - instruction is emulated
215 * 0b01 - !trapUnalignbit - notifyUnalignbit - emulation is done, but traps afterwards
216 * 0b10 - trapUnalignbit - !notifyUnalignbit - no emulation - causes exception
217 * 0b11 - trapUnalignbit - notifyUnalignbit - no emulation - causes exception
221 temp
= current_act()->mact
.specFlags
; /* Save the old values */
223 temp
= ((current_act()->mact
.specFlags
>> (31 - trapUnalignbit
- 1)) /* Reformat them to pass back */
224 | (current_act()->mact
.specFlags
>> (31 - notifyUnalignbit
))) & 3;
226 temp2
= ((save
->save_r4
<< (31 - trapUnalignbit
- 1)) & trapUnalign
) /* Move parms into flag format */
227 | ((save
->save_r4
<< (31 - notifyUnalignbit
)) & notifyUnalign
);
229 current_act()->mact
.specFlags
&= ~(trapUnalign
| notifyUnalign
); /* Clean the old ones */
230 current_act()->mact
.specFlags
|= temp2
; /* Set the new ones */
232 per_proc_info
[cpu_number()].spcFlags
= current_act()->mact
.specFlags
;
234 save
->save_r3
= temp
;
236 return 1; /* Return and check for ASTs... */
239 * Return info for boot screen
244 ml_set_interrupts_enabled(1);
245 (void)copyout((char *)&vinfo
, (char *)save
->save_r4
, sizeof(struct vc_info
)); /* Copy out the video info */
246 ml_set_interrupts_enabled(0);
248 return 1; /* Return and check for ASTs... */
251 default: /* Handle invalid ones */
252 return 0; /* Return an exception */
258 kern_return_t
testPerfTrap(int trapno
, struct savearea
*ss
,
259 unsigned int dsisr
, unsigned int dar
) {
261 if(trapno
!= T_ALIGNMENT
) return KERN_FAILURE
;
263 kprintf("alignment exception at %08X, srr1 = %08X, dsisr = %08X, dar = %08X\n", ss
->save_srr0
,
264 ss
->save_srr1
, dsisr
, dar
);