]>
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>
62 #include <ppc/POWERMAC/video_console.h>
64 extern struct vc_info vinfo
;
66 int diagCall(struct savearea
*save
) {
69 unsigned long long tbase
;
72 natural_t tbu
, tbu2
, tbl
;
73 struct per_proc_info
*per_proc
; /* Area for my per_proc address */
75 unsigned int tstrt
, tend
;
77 if(!(dgWork
.dgFlags
& enaDiagSCs
)) return 0; /* If not enabled, cause an exception */
79 switch(save
->save_r3
) { /* Select the routine */
82 * Adjust the timebase for drift recovery testing
84 case dgAdjTB
: /* Adjust the timebase */
86 adj
.tb
[0] = 0; /* Clear high part */
87 adj
.tb
[1] = save
->save_r4
; /* Set low order */
88 if(adj
.tb
[1] & 0x80000000) adj
.tb
[0] = 0xFFFFFFFF; /* Propagate sign bit */
90 do { /* Read current time */
91 asm volatile(" mftbu %0" : "=r" (tbu
));
92 asm volatile(" mftb %0" : "=r" (tbl
));
93 asm volatile(" mftbu %0" : "=r" (tbu2
));
94 } while (tbu
!= tbu2
);
96 ttt
.tb
[0] = tbu
; /* Set high */
97 ttt
.tb
[1] = tbl
; /* Set low */
99 ttt
.tbase
= ttt
.tbase
+ adj
.tbase
; /* Increment or decrement the TB */
101 tbu
= ttt
.tb
[0]; /* Save in regular variable */
102 tbl
= ttt
.tb
[1]; /* Save in regular variable */
104 mttb(0); /* Set low to keep from ticking */
105 mttbu(tbu
); /* Set adjusted high */
106 mttb(tbl
); /* Set adjusted low */
108 return -1; /* Return no AST checking... */
111 * Return physical address of a page
115 save
->save_r3
= pmap_extract(current_act()->map
->pmap
, save
->save_r4
); /* Get read address */
117 return -1; /* Return no AST checking... */
120 * Copy physical to virtual
125 save
->save_r3
= copyp2v(save
->save_r4
, save
->save_r5
, save
->save_r6
); /* Copy the physical page */
127 return 1; /* Return and check for ASTs... */
131 * Soft reset processor
135 cpu
= save
->save_r4
; /* Get the requested CPU number */
137 if(cpu
>= NCPUS
) { /* Check for bogus cpu */
138 save
->save_r3
= KERN_FAILURE
; /* Set failure */
142 if(!machine_slot
[cpu
].running
) return KERN_FAILURE
; /* It is not running */
144 per_proc
= &per_proc_info
[cpu
]; /* Point to the processor */
146 (void)PE_cpu_start(per_proc
->cpu_id
,
147 per_proc
->start_paddr
, (vm_offset_t
)per_proc
);
149 save
->save_r3
= KERN_SUCCESS
; /* Set scuuess */
151 return 1; /* Return and check for ASTs... */
159 cacheInit(); /* Blow cache */
161 asm volatile(" mftb %0" : "=r" (tstrt
));
163 while((tend
- tstrt
) < 0x000A2837) {
164 asm volatile(" mftb %0" : "=r" (tend
));
168 return 1; /* Return and check for ASTs... */
175 pmap_remove(kernel_pmap
, save
->save_r4
, save
->save_r4
+ 4096);
177 return 1; /* Return and check for ASTs... */
182 * Create a physical block map into the current task
183 * Don't bother to check for any errors.
184 * parms - vaddr, paddr, size, prot, attributes
188 pmap_map_block(current_act()->map
->pmap
, save
->save_r4
, save
->save_r5
, save
->save_r6
, /* Map in the block */
189 save
->save_r7
, save
->save_r8
, 0);
191 return 1; /* Return and check for ASTs... */
195 * Remove any mapping from the current task
196 * Don't bother to check for any errors.
201 (void)mapping_remove(current_act()->map
->pmap
, save
->save_r4
); /* Remove mapping */
202 return 1; /* Return and check for ASTs... */
205 * Return info for boot screen
210 ml_set_interrupts_enabled(1);
211 (void)copyout((char *)&vinfo
, (char *)save
->save_r4
, sizeof(struct vc_info
)); /* Copy out the video info */
212 ml_set_interrupts_enabled(0);
214 return 1; /* Return and check for ASTs... */
217 default: /* Handle invalid ones */
218 return 0; /* Return an exception */