]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ppc/Diagnostics.c
xnu-123.5.tar.gz
[apple/xnu.git] / osfmk / ppc / Diagnostics.c
CommitLineData
1c79356b
A
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/*
23 * @OSF_FREE_COPYRIGHT@
24 */
25/*
26 * @APPLE_FREE_COPYRIGHT@
27 */
28
29/*
30 * Author: Bill Angell, Apple
31 * Date: 9/auht-aught
32 *
33 * Random diagnostics
34 */
35
36
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>
49#include <vm/pmap.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>
55#include <ppc/pmap.h>
56#include <ppc/mem.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
63int diagCall(struct savearea *save) {
64
65 union {
66 unsigned long long tbase;
67 unsigned int tb[2];
68 } ttt, adj;
69 natural_t tbu, tbu2, tbl;
70 struct per_proc_info *per_proc; /* Area for my per_proc address */
71 int cpu;
72
73 if(!(dgWork.dgFlags & enaDiagSCs)) return 0; /* If not enabled, cause an exception */
74
75 switch(save->save_r3) { /* Select the routine */
76
77/*
78 * Adjust the timebase for drift recovery testing
79 */
80 case dgAdjTB: /* Adjust the timebase */
81
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 */
85
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);
91
92 ttt.tb[0] = tbu; /* Set high */
93 ttt.tb[1] = tbl; /* Set low */
94
95 ttt.tbase = ttt.tbase + adj.tbase; /* Increment or decrement the TB */
96
97 tbu = ttt.tb[0]; /* Save in regular variable */
98 tbl = ttt.tb[1]; /* Save in regular variable */
99
100 mttb(0); /* Set low to keep from ticking */
101 mttbu(tbu); /* Set adjusted high */
102 mttb(tbl); /* Set adjusted low */
103
104 return -1; /* Return no AST checking... */
105
106/*
107 * Return physical address of a page
108 */
109 case dgLRA:
110
111 save->save_r3 = pmap_extract(current_act()->map->pmap, save->save_r4); /* Get read address */
112
113 return -1; /* Return no AST checking... */
114
115/*
116 * Copy physical to virtual
117 */
118 case dgpcpy:
119
120#if 0
121 save->save_r3 = copyp2v(save->save_r4, save->save_r5, save->save_r6); /* Copy the physical page */
122#endif
123 return 1; /* Return and check for ASTs... */
124
125
126/*
127 * Soft reset processor
128 */
129 case dgreset:
130
131 cpu = save->save_r4; /* Get the requested CPU number */
132
133 if(cpu >= NCPUS) { /* Check for bogus cpu */
134 save->save_r3 = KERN_FAILURE; /* Set failure */
135 return 1;
136 }
137
138 if(!machine_slot[cpu].running) return KERN_FAILURE; /* It is not running */
139
140 per_proc = &per_proc_info[cpu]; /* Point to the processor */
141
142 (void)PE_cpu_start(per_proc->cpu_id,
143 per_proc->start_paddr, (vm_offset_t)per_proc);
144
145 save->save_r3 = KERN_SUCCESS; /* Set scuuess */
146
147 return 1; /* Return and check for ASTs... */
148
149/*
150 * various hack tests
151 */
152 case dgtest:
153
154 pmap_remove(kernel_pmap, save->save_r4, save->save_r4 + 4096);
155
156 return 1; /* Return and check for ASTs... */
157
158
159 default: /* Handle invalid ones */
160 return 0; /* Return an exception */
161
162 };
163
164}