1/*- 2 * Copyright (c) 2001 Jake Burkholder. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
| 1/*- 2 * Copyright (c) 2001 Jake Burkholder. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
|
26 * $FreeBSD: head/sys/sparc64/sparc64/machdep.c 80708 2001-07-31 05:45:16Z jake $
| 26 * $FreeBSD: head/sys/sparc64/sparc64/machdep.c 80709 2001-07-31 06:05:05Z jake $
|
27 */ 28
| 27 */ 28
|
| 29#include "opt_ddb.h" 30
|
29#include <sys/param.h> 30#include <sys/systm.h>
| 31#include <sys/param.h> 32#include <sys/systm.h>
|
| 33#include <sys/cons.h> 34#include <sys/kernel.h> 35#include <sys/linker.h> 36#include <sys/lock.h>
|
31#include <sys/mutex.h>
| 37#include <sys/mutex.h>
|
| 38#include <sys/pcpu.h>
|
32#include <sys/proc.h>
| 39#include <sys/proc.h>
|
| 40#include <sys/bio.h> 41#include <sys/buf.h>
|
33#include <sys/ptrace.h> 34#include <sys/signalvar.h> 35#include <sys/sysproto.h>
| 42#include <sys/ptrace.h> 43#include <sys/signalvar.h> 44#include <sys/sysproto.h>
|
| 45#include <sys/timetc.h> 46#include <sys/user.h>
|
36 37#include <dev/ofw/openfirm.h> 38
| 47 48#include <dev/ofw/openfirm.h> 49
|
| 50#include <vm/vm.h> 51#include <vm/vm_param.h> 52#include <vm/vm_kern.h> 53#include <vm/vm_object.h> 54#include <vm/vm_page.h> 55#include <vm/vm_map.h> 56#include <vm/vm_pager.h> 57#include <vm/vm_extern.h> 58 59#include <ddb/ddb.h> 60 61#include <machine/bootinfo.h> 62#include <machine/frame.h>
|
39#include <machine/md_var.h>
| 63#include <machine/md_var.h>
|
| 64#include <machine/pmap.h> 65#include <machine/pstate.h>
|
40#include <machine/reg.h> 41
| 66#include <machine/reg.h> 67
|
42void sparc64_init(ofw_vec_t *ofw_vec);
| 68typedef int ofw_vec_t(void *);
|
43
| 69
|
| 70extern char tl0_base[]; 71 72extern char _end[]; 73 74int physmem = 0;
|
44int cold = 1; 45long dumplo; 46int Maxmem = 0; 47 48struct mtx Giant; 49struct mtx sched_lock; 50
| 75int cold = 1; 76long dumplo; 77int Maxmem = 0; 78 79struct mtx Giant; 80struct mtx sched_lock; 81
|
51struct user *proc0paddr;
| 82struct globaldata __globaldata; 83char user0[UPAGES * PAGE_SIZE];
|
52
| 84
|
| 85vm_offset_t clean_sva; 86vm_offset_t clean_eva; 87 88u_long ofw_vec; 89u_long ofw_tba; 90 91static vm_offset_t buffer_sva; 92static vm_offset_t buffer_eva; 93static vm_offset_t pager_sva; 94static vm_offset_t pager_eva; 95 96static struct timecounter tick_tc; 97 98static timecounter_get_t tick_get_timecount; 99void sparc64_init(struct bootinfo *bi, ofw_vec_t *vec); 100 101static void cpu_startup(void *); 102SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL); 103 104static void 105cpu_startup(void *arg) 106{ 107 vm_offset_t physmem_est; 108 vm_offset_t minaddr; 109 vm_offset_t maxaddr; 110 phandle_t child; 111 phandle_t root; 112 vm_offset_t va; 113 vm_size_t size; 114 char name[32]; 115 char type[8]; 116 u_int clock; 117 int factor; 118 caddr_t p; 119 int i; 120 121 root = OF_peer(0); 122 for (child = OF_child(root); child != 0; child = OF_peer(child)) { 123 OF_getprop(child, "device_type", type, sizeof(type)); 124 if (strcmp(type, "cpu") == 0) 125 break; 126 } 127 if (child == 0) 128 panic("cpu_startup: no cpu\n"); 129 OF_getprop(child, "name", name, sizeof(name)); 130 OF_getprop(child, "clock-frequency", &clock, sizeof(clock)); 131 132 tick_tc.tc_get_timecount = tick_get_timecount; 133 tick_tc.tc_poll_pps = NULL; 134 tick_tc.tc_counter_mask = ~0u; 135 tick_tc.tc_frequency = clock; 136 tick_tc.tc_name = "tick"; 137 tc_init(&tick_tc); 138 139 p = name; 140 if (bcmp(p, "SUNW,", 5) == 0) 141 p += 5; 142 printf("CPU: %s Processor (%d.%02d MHz CPU)\n", p, 143 (clock + 4999) / 1000000, ((clock + 4999) / 10000) % 100); 144#if 0 145 ver = rdpr(ver); 146 printf("manuf: %#lx impl: %#lx mask: %#lx maxtl: %#lx maxwin: %#lx\n", 147 VER_MANUF(ver), VER_IMPL(ver), VER_MASK(ver), VER_MAXTL(ver), 148 VER_MAXWIN(ver)); 149#endif 150 151 /* 152 * XXX make most of this MI and move to sys/kern. 153 */ 154 155 /* 156 * Calculate callout wheel size. 157 */ 158 for (callwheelsize = 1, callwheelbits = 0; callwheelsize < ncallout; 159 callwheelsize <<= 1, ++callwheelbits) 160 ; 161 callwheelmask = callwheelsize - 1; 162 163 size = 0; 164 va = 0; 165again: 166 p = (caddr_t)va; 167 168#define valloc(name, type, num) \ 169 (name) = (type *)p; p = (caddr_t)((name) + (num)) 170 171 valloc(callout, struct callout, ncallout); 172 valloc(callwheel, struct callout_tailq, callwheelsize); 173 174 if (kernel_map->first_free == NULL) { 175 printf("Warning: no free entries in kernel_map.\n"); 176 physmem_est = physmem; 177 } else 178 physmem_est = min(physmem, 179 kernel_map->max_offset - kernel_map->min_offset); 180 181 if (nbuf == 0) { 182 factor = 4 * BKVASIZE / PAGE_SIZE; 183 nbuf = 50; 184 if (physmem_est > 1024) 185 nbuf += min((physmem_est - 1024) / factor, 186 16384 / factor); 187 if (physmem_est > 16384) 188 nbuf += (physmem_est - 16384) * 2 / (factor * 5); 189 } 190 191 if (nbuf > (kernel_map->max_offset - kernel_map->min_offset) / 192 (BKVASIZE * 2)) { 193 nbuf = (kernel_map->max_offset - kernel_map->min_offset) / 194 (BKVASIZE * 2); 195 printf("Warning: nbufs capped at %d\n", nbuf); 196 } 197 198 nswbuf = max(min(nbuf/4, 256), 16); 199 200 valloc(swbuf, struct buf, nswbuf); 201 valloc(buf, struct buf, nbuf); 202 p = bufhashinit(p); 203 204 if (va == 0) { 205 size = (vm_size_t)(p - va); 206 if ((va = kmem_alloc(kernel_map, round_page(size))) == 0) 207 panic("startup: no room for tables"); 208 goto again; 209 } 210 211 if ((vm_size_t)(p - va) != size) 212 panic("startup: table size inconsistency"); 213 214 clean_map = kmem_suballoc(kernel_map, &clean_sva, &clean_eva, 215 (nbuf*BKVASIZE) + (nswbuf*MAXPHYS) + pager_map_size); 216 buffer_map = kmem_suballoc(clean_map, &buffer_sva, &buffer_eva, 217 (nbuf*BKVASIZE)); 218 buffer_map->system_map = 1; 219 pager_map = kmem_suballoc(clean_map, &pager_sva, &pager_eva, 220 (nswbuf*MAXPHYS) + pager_map_size); 221 pager_map->system_map = 1; 222 exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, 223 (16*(ARG_MAX+(PAGE_SIZE*3)))); 224 225 SLIST_INIT(&callfree); 226 for (i = 0; i < ncallout; i++) { 227 callout_init(&callout[i], 0); 228 callout[i].c_flags = CALLOUT_LOCAL_ALLOC; 229 SLIST_INSERT_HEAD(&callfree, &callout[i], c_links.sle); 230 } 231 232 for (i = 0; i < callwheelsize; i++) 233 TAILQ_INIT(&callwheel[i]); 234 235 mtx_init(&callout_lock, "callout", MTX_SPIN | MTX_RECURSE); 236 237 bufinit(); 238 vm_pager_bufferinit(); 239 240 globaldata_register(globaldata); 241 242} 243 244unsigned 245tick_get_timecount(struct timecounter *tc) 246{ 247 return ((unsigned)rd(tick)); 248} 249
|
53void
| 250void
|
54sparc64_init(ofw_vec_t *ofw_vec)
| 251sparc64_init(struct bootinfo *bi, ofw_vec_t *vec)
|
55{
| 252{
|
56 OF_init(ofw_vec);
| 253 struct trapframe *tf; 254 255 /* 256 * Initialize openfirmware (needed for console). 257 */ 258 OF_init(vec); 259 260 /* 261 * Initialize the console before printing anything. 262 */
|
57 cninit();
| 263 cninit();
|
58 printf("hello world!!\n");
| 264 265 /* 266 * Check that the bootinfo struct is sane. 267 */ 268 if (bi->bi_version != BOOTINFO_VERSION) 269 panic("sparc64_init: bootinfo version mismatch"); 270 if (bi->bi_metadata == 0) 271 panic("sparc64_init: no loader metadata"); 272 preload_metadata = (caddr_t)bi->bi_metadata; 273 274#ifdef DDB 275 kdb_init(); 276#endif 277 278 /* 279 * Initialize virtual memory. 280 */ 281 pmap_bootstrap(bi->bi_kpa, bi->bi_end); 282 283 /* 284 * XXX Clear tick and disable the comparator. 285 */ 286 wrpr(tick, 0, 0); 287 wr(asr23, 1L << 63, 0); 288 289 /* 290 * Force trap level 1 and take over the trap table. 291 */ 292 wrpr(tl, 0, 1); 293 wrpr(tba, tl0_base, 0); 294 295 /* 296 * Initialize proc0 stuff (p_contested needs to be done early). 297 */ 298 LIST_INIT(&proc0.p_contested); 299 proc0.p_addr = (struct user *)user0; 300 tf = (struct trapframe *)(user0 + UPAGES * PAGE_SIZE - sizeof(*tf)); 301 proc0.p_frame = tf; 302 303 /* 304 * Initialize the per-cpu pointer so we can set curproc. 305 */ 306 globaldata = &__globaldata; 307 308 /* 309 * Initialize curproc so that mutexes work. 310 */ 311 PCPU_SET(curproc, &proc0); 312 PCPU_SET(curpcb, &((struct user *)user0)->u_pcb); 313 PCPU_SET(spinlocks, NULL); 314 315 /* 316 * Initialize mutexes. 317 */ 318 mtx_init(&sched_lock, "sched lock", MTX_SPIN | MTX_RECURSE); 319 mtx_init(&Giant, "Giant", MTX_DEF | MTX_RECURSE); 320 mtx_init(&proc0.p_mtx, "process lock", MTX_DEF); 321 322 mtx_lock(&Giant);
|
59} 60 61void
| 323} 324 325void
|
| 326set_openfirm_callback(ofw_vec_t *vec) 327{ 328 ofw_tba = rdpr(tba); 329 ofw_vec = (u_long)vec; 330} 331 332void
|
62sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code) 63{ 64 TODO; 65} 66 67#ifndef _SYS_SYSPROTO_H_ 68struct sigreturn_args { 69 ucontext_t *ucp; 70}; 71#endif 72 73int 74sigreturn(struct proc *p, struct sigreturn_args *uap) 75{ 76 TODO; 77 return (0); 78} 79 80void 81cpu_halt(void) 82{ 83 TODO; 84} 85 86int 87ptrace_read_u_check(struct proc *p, vm_offset_t addr, size_t len) 88{ 89 TODO; 90 return (0); 91} 92 93int 94ptrace_write_u(struct proc *p, vm_offset_t off, long data) 95{ 96 TODO; 97 return (0); 98} 99 100int 101ptrace_set_pc(struct proc *p, u_long addr) 102{ 103 TODO; 104 return (0); 105} 106 107int 108ptrace_single_step(struct proc *p) 109{ 110 TODO; 111 return (0); 112} 113 114void 115setregs(struct proc *p, u_long entry, u_long stack, u_long ps_strings) 116{ 117 TODO; 118} 119 120void 121Debugger(const char *msg) 122{
| 333sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code) 334{ 335 TODO; 336} 337 338#ifndef _SYS_SYSPROTO_H_ 339struct sigreturn_args { 340 ucontext_t *ucp; 341}; 342#endif 343 344int 345sigreturn(struct proc *p, struct sigreturn_args *uap) 346{ 347 TODO; 348 return (0); 349} 350 351void 352cpu_halt(void) 353{ 354 TODO; 355} 356 357int 358ptrace_read_u_check(struct proc *p, vm_offset_t addr, size_t len) 359{ 360 TODO; 361 return (0); 362} 363 364int 365ptrace_write_u(struct proc *p, vm_offset_t off, long data) 366{ 367 TODO; 368 return (0); 369} 370 371int 372ptrace_set_pc(struct proc *p, u_long addr) 373{ 374 TODO; 375 return (0); 376} 377 378int 379ptrace_single_step(struct proc *p) 380{ 381 TODO; 382 return (0); 383} 384 385void 386setregs(struct proc *p, u_long entry, u_long stack, u_long ps_strings) 387{ 388 TODO; 389} 390 391void 392Debugger(const char *msg) 393{
|
123 TODO;
| 394 395 printf("Debugger(\"%s\")\n", msg); 396 breakpoint();
|
124} 125 126int 127fill_dbregs(struct proc *p, struct dbreg *dbregs) 128{ 129 TODO; 130 return (0); 131} 132 133int 134set_dbregs(struct proc *p, struct dbreg *dbregs) 135{ 136 TODO; 137 return (0); 138} 139 140int 141fill_regs(struct proc *p, struct reg *regs) 142{ 143 TODO; 144 return (0); 145} 146 147int 148set_regs(struct proc *p, struct reg *regs) 149{ 150 TODO; 151 return (0); 152} 153 154int 155fill_fpregs(struct proc *p, struct fpreg *fpregs) 156{ 157 TODO; 158 return (0); 159} 160 161int 162set_fpregs(struct proc *p, struct fpreg *fpregs) 163{ 164 TODO; 165 return (0); 166}
| 397} 398 399int 400fill_dbregs(struct proc *p, struct dbreg *dbregs) 401{ 402 TODO; 403 return (0); 404} 405 406int 407set_dbregs(struct proc *p, struct dbreg *dbregs) 408{ 409 TODO; 410 return (0); 411} 412 413int 414fill_regs(struct proc *p, struct reg *regs) 415{ 416 TODO; 417 return (0); 418} 419 420int 421set_regs(struct proc *p, struct reg *regs) 422{ 423 TODO; 424 return (0); 425} 426 427int 428fill_fpregs(struct proc *p, struct fpreg *fpregs) 429{ 430 TODO; 431 return (0); 432} 433 434int 435set_fpregs(struct proc *p, struct fpreg *fpregs) 436{ 437 TODO; 438 return (0); 439}
|