console.c (8028:6b05deee0ca3) console.c (8029:442f90a944eb)
1/*
1/*
2 * Copyright (c) 2003, 2004
3 * The Regents of The University of Michigan
4 * All Rights Reserved
2 * Copyright (c) 2003-2004 The Regents of The University of Michigan
3 * Copyright (c) 1993 The Hewlett-Packard Development Company
4 * All rights reserved.
5 *
5 *
6 * This code is part of the M5 simulator.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * 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 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
7 *
16 *
8 * Permission is granted to use, copy, create derivative works and
9 * redistribute this software and such derivative works for any purpose,
10 * so long as the copyright notice above, this grant of permission, and
11 * the disclaimer below appear in all copies made; and so long as the
12 * name of The University of Michigan is not used in any advertising or
13 * publicity pertaining to the use or distribution of this software
14 * without specific, written prior authorization.
15 *
16 * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE
17 * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND WITHOUT
18 * WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER EXPRESS OR
19 * IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE REGENTS OF
21 * THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE FOR ANY DAMAGES,
22 * INCLUDING DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
23 * DAMAGES, WITH RESPECT TO ANY CLAIM ARISING OUT OF OR IN CONNECTION
24 * WITH THE USE OF THE SOFTWARE, EVEN IF IT HAS BEEN OR IS HEREAFTER
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
26 *
27 * Modified for M5 by: Ali G. Saidi
28 * Nathan L. Binkert
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
28 */
29
31/*
32 * Copyright 1993 Hewlett-Packard Development Company, L.P.
33 *
34 * Permission is hereby granted, free of charge, to any person
35 * obtaining a copy of this software and associated documentation
36 * files (the "Software"), to deal in the Software without
37 * restriction, including without limitation the rights to use, copy,
38 * modify, merge, publish, distribute, sublicense, and/or sell copies
39 * of the Software, and to permit persons to whom the Software is
40 * furnished to do so, subject to the following conditions:
41 *
42 * The above copyright notice and this permission notice shall be
43 * included in all copies or substantial portions of the Software.
44 *
45 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
49 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
50 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
51 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
52 * SOFTWARE.
53 */
54
55/* ******************************************
56 * M5 Console
57 * ******************************************/
58
59#include <linux/stddef.h>
60#include <sys/types.h>
61
62#define CONSOLE
63#include "access.h"
64#include "cserve.h"
65#include "rpb.h"
66
67#define CONS_INT_TX 0x01 /* interrupt enable / state bits */
68#define CONS_INT_RX 0x02
69
70#define PAGE_SIZE (8192)
71
72#define KSTACK_REGION_VA 0x20040000
73
74#define KSEG 0xfffffc0000000000
75#define K1BASE 0xfffffc8000000000
76#define KSEG_TO_PHYS(x) (((ulong)x) & ~KSEG)
77
78#define ROUNDUP8(x) ((ulong)(((ulong)x)+7) & ~7)
79#define ROUNDUP128(x) ((ulong)(((ulong)x) + 127) & ~127)
80#define ROUNDUP8K(x) ((ulong)(((ulong)(x)) + 8191) & ~8191)
81
82#define FIRST(x) ((((ulong)(x)) >> 33) & 0x3ff)
83#define SECOND(x) ((((ulong)(x)) >> 23) & 0x3ff)
84#define THIRD(x) ((((ulong)(x)) >> 13) & 0x3ff)
85#define THIRD_XXX(x) ((((ulong)(x)) >> 13) & 0xfff)
86#define PFN(x) ((((ulong)(x) & ~KSEG) >> 13))
87
88/* Kernel write | kernel read | valid */
89#define KPTE(x) ((ulong)((((ulong)(x)) << 32) | 0x1101))
90
91#define HWRPB_PAGES 16
92
93#define NUM_KERNEL_THIRD (4)
94
95#define printf_lock(args...) \
96 do { \
97 SpinLock(&theLock); \
98 printf(args); \
99 SpinUnlock(&theLock); \
100 } while (0)
101
102
103void unixBoot(int argc, char **argv);
104void JToKern(char *bootadr, ulong rpb_percpu, ulong free_pfn, ulong k_argc,
105 char **k_argv, char **envp);
106void JToPal(ulong bootadr);
107void SlaveLoop(int cpu);
108
109volatile struct AlphaAccess *m5AlphaAccess;
110struct AlphaAccess m5Conf;
111
112ulong theLock;
113
114extern void SpinLock(ulong *lock);
115#define SpinUnlock(_x) *(_x) = 0;
116
117struct _kernel_params {
118 char *bootadr;
119 ulong rpb_percpu;
120 ulong free_pfn;
121 ulong argc;
122 ulong argv;
123 ulong envp; /* NULL */
124};
125
126extern consoleCallback[];
127extern consoleFixup[];
128long CallBackDispatcher();
129long CallBackFixup();
130
131/*
132 * m5 console output
133 */
134
135void
136InitConsole()
137{
138}
139
140char
141GetChar()
142{
143 return m5AlphaAccess->inputChar;
144}
145
146void
147PutChar(char c)
148{
149 m5AlphaAccess->outputChar = c;
150}
151
152int
153passArgs(int argc)
154{
155 return 0;
156}
157
158int
159main(int argc, char **argv)
160{
161 int x, i;
162 uint *k1ptr, *ksegptr;
163
164 InitConsole();
165 printf_lock("M5 console: m5AlphaAccess @ 0x%x\n", m5AlphaAccess);
166
167 /*
168 * get configuration from backdoor
169 */
170 m5Conf.last_offset = m5AlphaAccess->last_offset;
171 printf_lock("Got Configuration %d\n", m5Conf.last_offset);
172
173 m5Conf.last_offset = m5AlphaAccess->last_offset;
174 m5Conf.version = m5AlphaAccess->version;
175 m5Conf.numCPUs = m5AlphaAccess->numCPUs;
176 m5Conf.intrClockFrequency = m5AlphaAccess->intrClockFrequency;
177 m5Conf.cpuClock = m5AlphaAccess->cpuClock;
178 m5Conf.mem_size = m5AlphaAccess->mem_size;
179 m5Conf.kernStart = m5AlphaAccess->kernStart;
180 m5Conf.kernEnd = m5AlphaAccess->kernEnd;
181 m5Conf.entryPoint = m5AlphaAccess->entryPoint;
182 m5Conf.diskUnit = m5AlphaAccess->diskUnit;
183 m5Conf.diskCount = m5AlphaAccess->diskCount;
184 m5Conf.diskPAddr = m5AlphaAccess->diskPAddr;
185 m5Conf.diskBlock = m5AlphaAccess->diskBlock;
186 m5Conf.diskOperation = m5AlphaAccess->diskOperation;
187 m5Conf.outputChar = m5AlphaAccess->outputChar;
188 m5Conf.inputChar = m5AlphaAccess->inputChar;
189
190 if (m5Conf.version != ALPHA_ACCESS_VERSION) {
191 panic("Console version mismatch. Console expects %d. has %d \n",
192 ALPHA_ACCESS_VERSION, m5Conf.version);
193 }
194
195 /*
196 * setup arguments to kernel
197 */
198 unixBoot(argc, argv);
199
200 panic("unix failed to boot\n");
201 return 1;
202}
203
204/*
205 * BOOTING
206 */
207struct rpb m5_rpb = {
208 NULL, /* 000: physical self-reference */
209 ((long)'H') | (((long)'W') << 8) | (((long)'R') << 16) |
210 ((long)'P' << 24) | (((long)'B') << 32), /* 008: contains "HWRPB" */
211 6, /* 010: HWRPB version number */
212 /* the byte count is wrong, but who needs it? - lance */
213 0, /* 018: bytes in RPB perCPU CTB CRB MEDSC */
214 0, /* 020: primary cpu id */
215 PAGE_SIZE, /* 028: page size in bytes */
216 43, /* 030: number of phys addr bits */
217 127, /* 038: max valid ASN */
218 {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1'},
219 /* 040: system serial num: 10 ascii chars */
220 0, /* OVERRIDDEN */
221 (1<<10), /* 058: system variation */
222 'c'|('o'<<8)|('o'<<16)|('l'<< 24), /* 060: system revision */
223 1024*4096, /* 068: scaled interval clock intr freq */
224 0, /* 070: cycle counter frequency */
225 0x200000000, /* 078: virtual page table base */
226 0, /* 080: reserved */
227 0, /* 088: offset to translation buffer hint */
228 1, /* 090: number of processor slots OVERRIDDEN*/
229 sizeof(struct rpb_percpu), /* 098: per-cpu slot size. OVERRIDDEN */
230 0, /* 0A0: offset to per_cpu slots */
231 1, /* 0A8: number of CTBs */
232 sizeof(struct ctb_tt),
233 0, /* 0B8: offset to CTB (cons term block) */
234 0, /* 0C0: offset to CRB (cons routine block) */
235 0, /* 0C8: offset to memory descriptor table */
236 0, /* 0D0: offset to config data block */
237 0, /* 0D8: offset to FRU table */
238 0, /* 0E0: virt addr of save term routine */
239 0, /* 0E8: proc value for save term routine */
240 0, /* 0F0: virt addr of restore term routine */
241 0, /* 0F8: proc value for restore term routine */
242 0, /* 100: virt addr of CPU restart routine */
243 0, /* 108: proc value for CPU restart routine */
244 0, /* 110: used to determine presence of kdebug */
245 0, /* 118: reserved for hardware */
246/* the checksum is wrong, but who needs it? - lance */
247 0, /* 120: checksum of prior entries in rpb */
248 0, /* 128: receive ready bitmask */
249 0, /* 130: transmit ready bitmask */
250 0, /* 138: Dynamic System Recog. offset */
251};
252
253ulong m5_tbb[] = { 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e,
254 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e,
255 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e,
256 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e };
257
258struct rpb_percpu m5_rpb_percpu = {
259 {0,0,0,0,0,0,1,{0,0},{0,0,0,0,0,0,0,0}}, /* 000: boot/restart HWPCB */
260 (STATE_PA | STATE_PP | STATE_CV |
261 STATE_PV | STATE_PMV | STATE_PL), /* 080: per-cpu state bits */
262 0xc000, /* 088: palcode memory length */
263 0x2000, /* 090: palcode scratch length */
264 0x4000, /* 098: paddr of pal mem space */
265 0x2000, /* 0A0: paddr of pal scratch space */
266 (2 << 16) | (5 << 8) | 1, /* 0A8: PALcode rev required */
267 11 | (2L << 32), /* 0B0: processor type */
268 7, /* 0B8: processor variation */
269 'M'|('5'<<8)|('A'<<16)|('0'<<24), /* 0C0: processor revision */
270 {'M','5','/','A','l','p','h','a','0','0','0','0','0','0','0','0'},
271 /* 0C8: proc serial num: 10 chars */
272 0, /* 0D8: phys addr of logout area */
273 0, /* 0E0: len in bytes of logout area */
274 0, /* 0E8: halt pcb base */
275 0, /* 0F0: halt pc */
276 0, /* 0F8: halt ps */
277 0, /* 100: halt arg list (R25) */
278 0, /* 108: halt return address (R26) */
279 0, /* 110: halt procedure value (R27) */
280 0, /* 118: reason for halt */
281 0, /* 120: for software */
282 {0}, /* 128: inter-console comm buffer */
283 {1,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0}, /* 1D0: PALcode revs available */
284 0 /* 250: reserved for arch use */
285/* the dump stack grows from the end of the rpb page not to reach here */
286};
287
288struct _m5_rpb_mdt {
289 long rpb_checksum; /* 000: checksum of entire mem desc table */
290 long rpb_impaddr; /* 008: PA of implementation dep info */
291 long rpb_numcl; /* 010: number of clusters */
292 struct rpb_cluster rpb_cluster[3]; /* first instance of a cluster */
293};
294
295struct _m5_rpb_mdt m5_rpb_mdt = {
296 0, /* 000: checksum of entire mem desc table */
297 0, /* 008: PA of implementation dep info */
298 0, /* 010: number of clusters */
299 {{ 0, /* 000: starting PFN of this cluster */
300 0, /* 008: count of PFNs in this cluster */
301 0, /* 010: count of tested PFNs in cluster */
302 0, /* 018: va of bitmap */
303 0, /* 020: pa of bitmap */
304 0, /* 028: checksum of bitmap */
305 1 /* 030: usage of cluster */
306 },
307 { 0, /* 000: starting PFN of this cluster */
308 0, /* 008: count of PFNs in this cluster */
309 0, /* 010: count of tested PFNs in cluster */
310 0, /* 018: va of bitmap */
311 0, /* 020: pa of bitmap */
312 0, /* 028: checksum of bitmap */
313 0 /* 030: usage of cluster */
314 },
315 { 0, /* 000: starting PFN of this cluster */
316 0, /* 008: count of PFNs in this cluster */
317 0, /* 010: count of tested PFNs in cluster */
318 0, /* 018: va of bitmap */
319 0, /* 020: pa of bitmap */
320 0, /* 028: checksum of bitmap */
321 0 /* 030: usage of cluster */
322 }}
323};
324
325/* constants for slotinfo bus_type subfield */
326#define SLOTINFO_TC 0
327#define SLOTINFO_ISA 1
328#define SLOTINFO_EISA 2
329#define SLOTINFO_PCI 3
330
331struct rpb_ctb m5_rpb_ctb = {
332 CONS_DZ, /* 000: console type */
333 0, /* 008: console unit */
334 0, /* 010: reserved */
335 0 /* 018: byte length of device dep portion */
336};
337
338/* we don't do any fixup (aka relocate the console) - we hope */
339struct rpb_crb m5_rpb_crb = {
340 0, /* va of call-back dispatch rtn */
341 0, /* pa of call-back dispatch rtn */
342 0, /* va of call-back fixup rtn */
343 0, /* pa of call-back fixup rtn */
344 0, /* number of entries in phys/virt map */
345 0 /* Number of pages to be mapped */
346};
347
348struct _rpb_name {
349 ulong length;
350 char name[16];
351};
352
353extern struct _rpb_name m5_name;
354
355struct rpb_dsr m5_rpb_dsr = {
356 0,
357 0,
358 0,
359};
360
361struct _rpb_name m5_name = {
362 16,
363 {'U','M','I','C','H',' ','M','5','/','A','L','P','H','A',' ',0},
364};
365
366/*
367 * M5 has one LURT entry:
368 * 1050 is for workstations
369 * 1100 is servers (and is needed for CXX)
370 */
371long m5_lurt[10] = { 9, 12, -1, -1, -1, -1, -1, -1, 1100, 1100 };
372
373ulong unix_boot_mem;
374ulong bootadr;
375
376char **kargv;
377int kargc;
378ulong free_pfn;
379struct rpb_percpu *rpb_percpu;
380
381char *
382unix_boot_alloc(int pages)
383{
384 char *ret = (char *)unix_boot_mem;
385 unix_boot_mem += (pages * PAGE_SIZE);
386 return ret;
387}
388
389ulong *first = 0;
390ulong *third_rpb = 0;
391ulong *reservedFixup = 0;
392
393int strcpy(char *dst, char *src);
394
395struct rpb *rpb;
396extern ulong _end;
397
398void
399unixBoot(int argc, char **argv)
400{
401 ulong *second, *third_kernel, ptr, *tbb, size, *percpu_logout;
402 unsigned char *mdt_bitmap;
403 long *lp1, *lp2, sum;
404 int i, cl;
405 ulong kern_first_page;
406 ulong mem_size = m5Conf.mem_size;
407
408 ulong mem_pages = mem_size / PAGE_SIZE, cons_pages;
409 ulong mdt_bitmap_pages = mem_pages / (PAGE_SIZE*8);
410
411 ulong kernel_bytes, ksp, kernel_end, *unix_kernel_stack, bss,
412 ksp_bottom, ksp_top;
413 struct rpb_ctb *rpb_ctb;
414 struct ctb_tt *ctb_tt;
415 struct rpb_dsr *rpb_dsr;
416 struct rpb_crb *rpb_crb;
417 struct _m5_rpb_mdt *rpb_mdt;
418 int *rpb_lurt;
419 char *rpb_name;
420 ulong nextPtr;
421
422 printf_lock("memsize %x pages %x \n", mem_size, mem_pages);
423
424 /* Allocate:
425 * two pages for the HWRPB
426 * five page table pages:
427 * 1: First level page table
428 * 1: Second level page table
429 * 1: Third level page table for HWRPB
430 * 2: Third level page table for kernel (for up to 16MB)
431 * set up the page tables
432 * load the kernel at the physical address 0x230000
433 * build the HWRPB
434 * set up memory descriptor table to give up the
435 * physical memory between the end of the page
436 * tables and the start of the kernel
437 * enable kseg addressing
438 * jump to the kernel
439 */
440
441 unix_boot_mem = ROUNDUP8K(&_end);
442
443 printf_lock("First free page after ROM 0x%x\n", unix_boot_mem);
444
445 rpb = (struct rpb *)unix_boot_alloc(HWRPB_PAGES);
446
447 mdt_bitmap = (unsigned char *)unix_boot_alloc(mdt_bitmap_pages);
448 first = (ulong *)unix_boot_alloc(1);
449 second = (ulong *)unix_boot_alloc(1);
450 third_rpb = (ulong *)unix_boot_alloc(1);
451 reservedFixup = (ulong*) unix_boot_alloc(1);
452 third_kernel = (ulong *)unix_boot_alloc(NUM_KERNEL_THIRD);
453 percpu_logout = (ulong*)unix_boot_alloc(1);
454
455 cons_pages = KSEG_TO_PHYS(unix_boot_mem) / PAGE_SIZE;
456
457 /* Set up the page tables */
458 bzero((char *)first, PAGE_SIZE);
459 bzero((char *)second, PAGE_SIZE);
460 bzero((char *)reservedFixup, PAGE_SIZE);
461 bzero((char *)third_rpb, HWRPB_PAGES * PAGE_SIZE);
462 bzero((char *)third_kernel, PAGE_SIZE * NUM_KERNEL_THIRD);
463
464 first[0] = KPTE(PFN(second));
465 first[1] = KPTE(PFN(first)); /* Region 3 */
466
467 /* Region 0 */
468 second[SECOND(0x10000000)] = KPTE(PFN(third_rpb));
469
470 for (i = 0; i < NUM_KERNEL_THIRD; i++) {
471 /* Region 1 */
472 second[SECOND(0x20000000) + i] = KPTE(PFN(third_kernel) + i);
473 }
474
475 /* Region 2 */
476 second[SECOND(0x40000000)] = KPTE(PFN(second));
477
478
479 /* For some obscure reason, Dec Unix's database read
480 * from /etc/sysconfigtab is written to this fixed
481 * mapped memory location. Go figure, since it is
482 * not initialized by the console. Maybe it is
483 * to look at the database from the console
484 * after a boot/crash.
485 *
486 * Black magic to estimate the max size. SEGVs on overflow
487 * bugnion
488 */
489
490#define DATABASE_BASE 0x20000000
491#define DATABASE_END 0x20020000
492
493 ulong *dbPage = (ulong*)unix_boot_alloc(1);
494 bzero(dbPage, PAGE_SIZE);
495 second[SECOND(DATABASE_BASE)] = KPTE(PFN(dbPage));
496 for (i = DATABASE_BASE; i < DATABASE_END ; i += PAGE_SIZE) {
497 ulong *db = (ulong*)unix_boot_alloc(1);
498 dbPage[THIRD(i)] = KPTE(PFN(db));
499 }
500
501 /* Region 0 */
502 /* Map the HWRPB */
503 for (i = 0; i < HWRPB_PAGES; i++)
504 third_rpb[i] = KPTE(PFN(rpb) + i);
505
506 /* Map the MDT bitmap table */
507 for (i = 0; i < mdt_bitmap_pages; i++) {
508 third_rpb[HWRPB_PAGES + i] = KPTE(PFN(mdt_bitmap) + i);
509 }
510
511 /* Protect the PAL pages */
512 for (i = 1; i < PFN(first); i++)
513 third_rpb[HWRPB_PAGES + mdt_bitmap_pages + i] = KPTE(i);
514
515 /* Set up third_kernel after it's loaded, when we know where it is */
516 kern_first_page = (KSEG_TO_PHYS(m5Conf.kernStart)/PAGE_SIZE);
517 kernel_end = ROUNDUP8K(m5Conf.kernEnd);
518 bootadr = m5Conf.entryPoint;
519
520 printf_lock("HWRPB 0x%x l1pt 0x%x l2pt 0x%x l3pt_rpb 0x%x l3pt_kernel 0x%x"
521 " l2reserv 0x%x\n",
522 rpb, first, second, third_rpb, third_kernel, reservedFixup);
523 if (kernel_end - m5Conf.kernStart > (0x800000*NUM_KERNEL_THIRD)) {
524 printf_lock("Kernel is more than 8MB 0x%x - 0x%x = 0x%x\n",
525 kernel_end, m5Conf.kernStart,
526 kernel_end - m5Conf.kernStart );
527 panic("kernel too big\n");
528 }
529 printf_lock("kstart = 0x%x, kend = 0x%x, kentry = 0x%x, numCPUs = 0x%x\n", m5Conf.kernStart, m5Conf.kernEnd, m5Conf.entryPoint, m5Conf.numCPUs);
530 ksp_bottom = (ulong)unix_boot_alloc(1);
531 ksp_top = ksp_bottom + PAGE_SIZE;
532 ptr = (ulong) ksp_bottom;
533 bzero((char *)ptr, PAGE_SIZE);
534 dbPage[THIRD(KSTACK_REGION_VA)] = 0; /* Stack Guard Page */
535 dbPage[THIRD(KSTACK_REGION_VA + PAGE_SIZE)] = KPTE(PFN(ptr)); /* Kernel Stack Page */
536 dbPage[THIRD(KSTACK_REGION_VA + 2*PAGE_SIZE)] = 0; /* Stack Guard Page */
537
538 /* put argv into the bottom of the stack - argv starts at 1 because
539 * the command thatr got us here (i.e. "unixboot) is in argv[0].
540 */
541 ksp = ksp_top - 8; /* Back up one longword */
542 ksp -= argc * sizeof(char *); /* Make room for argv */
543 kargv = (char **) ksp;
544 for (i = 1; i < argc; i++) { /* Copy arguments to stack */
545 ksp -= ((strlen(argv[i]) + 1) + 7) & ~0x7;
546 kargv[i-1] = (char *) ksp;
547 strcpy(kargv[i - 1], argv[i]);
548 }
549 kargc = i - 1;
550 kargv[kargc] = NULL; /* just to be sure; doesn't seem to be used */
551 ksp -= sizeof(char *); /* point above last arg for no real reason */
552
553 free_pfn = PFN(kernel_end);
554
555 bcopy((char *)&m5_rpb, (char *)rpb, sizeof(struct rpb));
556
557 rpb->rpb_selfref = (struct rpb *) KSEG_TO_PHYS(rpb);
558 rpb->rpb_string = 0x0000004250525748;
559
560 tbb = (ulong *) (((char *) rpb) + ROUNDUP8(sizeof(struct rpb)));
561 rpb->rpb_trans_off = (ulong)tbb - (ulong)rpb;
562 bcopy((char *)m5_tbb, (char *)tbb, sizeof(m5_tbb));
563
564 /*
565 * rpb_counter. Use to determine timeouts in OS.
566 * XXX must be patched after a checkpoint restore (I guess)
567 */
568
569 printf_lock("CPU Clock at %d MHz IntrClockFrequency=%d \n",
570 m5Conf.cpuClock, m5Conf.intrClockFrequency);
571 rpb->rpb_counter = m5Conf.cpuClock * 1000 * 1000;
572
573 /*
574 * By definition, the rpb_clock is scaled by 4096 (in hz)
575 */
576 rpb->rpb_clock = m5Conf.intrClockFrequency * 4096;
577
578 /*
579 * Per CPU Slots. Multiprocessor support.
580 */
581 int percpu_size = ROUNDUP128(sizeof(struct rpb_percpu));
582
583 printf_lock("Booting with %d processor(s) \n", m5Conf.numCPUs);
584
585 rpb->rpb_numprocs = m5Conf.numCPUs;
586 rpb->rpb_slotsize = percpu_size;
587 rpb_percpu = (struct rpb_percpu *)
588 ROUNDUP128(((ulong)tbb) + (sizeof(m5_tbb)));
589
590 rpb->rpb_percpu_off = (ulong)rpb_percpu - (ulong)rpb;
591
592 for (i = 0; i < m5Conf.numCPUs; i++) {
593 struct rpb_percpu *thisCPU = (struct rpb_percpu*)
594 ((ulong)rpb_percpu + percpu_size * i);
595
596 bzero((char *)thisCPU, percpu_size);
597 bcopy((char *)&m5_rpb_percpu, (char *)thisCPU,
598 sizeof(struct rpb_percpu));
599
600 thisCPU->rpb_pcb.rpb_ksp = (KSTACK_REGION_VA + 2*PAGE_SIZE - (ksp_top - ksp));
601 thisCPU->rpb_pcb.rpb_ptbr = PFN(first);
602
603 thisCPU->rpb_logout = KSEG_TO_PHYS(percpu_logout);
604 thisCPU->rpb_logout_len = PAGE_SIZE;
605
606 printf_lock("KSP: 0x%x PTBR 0x%x\n",
607 thisCPU->rpb_pcb.rpb_ksp, thisCPU->rpb_pcb.rpb_ptbr);
608 }
609
610 nextPtr = (ulong)rpb_percpu + percpu_size * m5Conf.numCPUs;
611
612 /*
613 * Console Terminal Block
614 */
615 rpb_ctb = (struct rpb_ctb *) nextPtr;
616 ctb_tt = (struct ctb_tt*) rpb_ctb;
617
618 rpb->rpb_ctb_off = ((ulong)rpb_ctb) - (ulong)rpb;
619 rpb->rpb_ctb_size = sizeof(struct rpb_ctb);
620
621 bzero((char *)rpb_ctb, sizeof(struct ctb_tt));
622
623 rpb_ctb->rpb_type = CONS_DZ;
624 rpb_ctb->rpb_length = sizeof(ctb_tt) - sizeof(rpb_ctb);
625
626 /*
627 * uart initizliation
628 */
629 ctb_tt->ctb_tintr_vec = 0x6c0; /* matches tlaser pal code */
630 ctb_tt->ctb_rintr_vec = 0x680; /* matches tlaser pal code */
631 ctb_tt->ctb_term_type = CTB_GRAPHICS;
632
633 rpb_crb = (struct rpb_crb *) (((ulong)rpb_ctb) + sizeof(struct ctb_tt));
634 rpb->rpb_crb_off = ((ulong)rpb_crb) - (ulong)rpb;
635
636 bzero((char *)rpb_crb, sizeof(struct rpb_crb));
637
638 /*
639 * console callback stuff (m5)
640 */
641 rpb_crb->rpb_num = 1;
642 rpb_crb->rpb_mapped_pages = HWRPB_PAGES;
643 rpb_crb->rpb_map[0].rpb_virt = 0x10000000;
644 rpb_crb->rpb_map[0].rpb_phys = KSEG_TO_PHYS(((ulong)rpb) & ~0x1fff);
645 rpb_crb->rpb_map[0].rpb_pgcount = HWRPB_PAGES;
646
647 printf_lock("Console Callback at 0x%x, fixup at 0x%x, crb offset: 0x%x\n",
648 rpb_crb->rpb_va_disp, rpb_crb->rpb_va_fixup, rpb->rpb_crb_off);
649
650 rpb_mdt = (struct _m5_rpb_mdt *)((ulong)rpb_crb + sizeof(struct rpb_crb));
651 rpb->rpb_mdt_off = (ulong)rpb_mdt - (ulong)rpb;
652 bcopy((char *)&m5_rpb_mdt, (char *)rpb_mdt, sizeof(struct _m5_rpb_mdt));
653
654
655 cl = 0;
656 rpb_mdt->rpb_cluster[cl].rpb_pfncount = kern_first_page;
657 cl++;
658
659 rpb_mdt->rpb_cluster[cl].rpb_pfn = kern_first_page;
660 rpb_mdt->rpb_cluster[cl].rpb_pfncount = mem_pages - kern_first_page;
661 rpb_mdt->rpb_cluster[cl].rpb_pfntested =
662 rpb_mdt->rpb_cluster[cl].rpb_pfncount;
663 rpb_mdt->rpb_cluster[cl].rpb_pa = KSEG_TO_PHYS(mdt_bitmap);
664 rpb_mdt->rpb_cluster[cl].rpb_va = 0x10000000 + HWRPB_PAGES * PAGE_SIZE;
665 cl++;
666
667 rpb_mdt->rpb_numcl = cl;
668
669 for (i = 0; i < cl; i++)
670 printf_lock("Memory cluster %d [%d - %d]\n", i,
671 rpb_mdt->rpb_cluster[i].rpb_pfn,
672 rpb_mdt->rpb_cluster[i].rpb_pfncount);
673
674 /* Checksum the rpb for good luck */
675 sum = 0;
676 lp1 = (long *)&rpb_mdt->rpb_impaddr;
677 lp2 = (long *)&rpb_mdt->rpb_cluster[cl];
678 while (lp1 < lp2) sum += *lp1++;
679 rpb_mdt->rpb_checksum = sum;
680
681 /* XXX should checksum the cluster descriptors */
682 bzero((char *)mdt_bitmap, mdt_bitmap_pages * PAGE_SIZE);
683 for (i = 0; i < mem_pages/8; i++)
684 ((unsigned char *)mdt_bitmap)[i] = 0xff;
685
686 printf_lock("Initalizing mdt_bitmap addr 0x%x mem_pages %x \n",
687 (long)mdt_bitmap,(long)mem_pages);
688
689 m5_rpb.rpb_config_off = 0;
690 m5_rpb.rpb_fru_off = 0;
691
692 rpb_dsr = (struct rpb_dsr *)((ulong)rpb_mdt + sizeof(struct _m5_rpb_mdt));
693 rpb->rpb_dsr_off = (ulong)rpb_dsr - (ulong)rpb;
694 bzero((char *)rpb_dsr, sizeof(struct rpb_dsr));
695 rpb_dsr->rpb_smm = 1578; /* Official XXM SMM number as per SRM */
696 rpb_dsr->rpb_smm = 1089; /* Official Alcor SMM number as per SRM */
697
698 rpb_lurt = (int *) ROUNDUP8((ulong)rpb_dsr + sizeof(struct rpb_dsr));
699 rpb_dsr->rpb_lurt_off = ((ulong) rpb_lurt) - (ulong) rpb_dsr;
700 bcopy((char *)m5_lurt, (char *)rpb_lurt, sizeof(m5_lurt));
701
702 rpb_name = (char *) ROUNDUP8(((ulong)rpb_lurt) + sizeof(m5_lurt));
703 rpb_dsr->rpb_sysname_off = ((ulong) rpb_name) - (ulong) rpb_dsr;
704#define THENAME " M5/Alpha "
705 sum = sizeof(THENAME);
706 bcopy(THENAME, rpb_name, sum);
707 *(ulong *)rpb_name = sizeof(THENAME); /* put in length field */
708
709 /* calculate size of rpb */
710 rpb->rpb_size = ((ulong) &rpb_name[sum]) - (ulong)rpb;
711
712 if (rpb->rpb_size > PAGE_SIZE * HWRPB_PAGES) {
713 panic("HWRPB_PAGES=%d too small for HWRPB !!! \n");
714 }
715
716 ulong *rpbptr = (ulong*)((char*)rpb_dsr + sizeof(struct rpb_dsr));
717 rpb_crb->rpb_pa_disp = KSEG_TO_PHYS(rpbptr);
718 rpb_crb->rpb_va_disp = 0x10000000 +
719 (((ulong)rpbptr - (ulong)rpb) & (0x2000 * HWRPB_PAGES - 1));
720 printf_lock("ConsoleDispatch at virt %x phys %x val %x\n",
721 rpb_crb->rpb_va_disp, rpb_crb->rpb_pa_disp, consoleCallback);
722 *rpbptr++ = 0;
723 *rpbptr++ = (ulong) consoleCallback;
724 rpb_crb->rpb_pa_fixup = KSEG_TO_PHYS(rpbptr);
725 rpb_crb->rpb_va_fixup = 0x10000000 +
726 (((ulong)rpbptr - (ulong)rpb) & (0x2000 * HWRPB_PAGES - 1));
727 *rpbptr++ = 0;
728
729 *rpbptr++ = (ulong) consoleFixup;
730
731 /* Checksum the rpb for good luck */
732 sum = 0;
733 lp1 = (long *)rpb;
734 lp2 = &rpb->rpb_checksum;
735 while (lp1 < lp2)
736 sum += *lp1++;
737 *lp2 = sum;
738
739 /*
740 * MP bootstrap
741 */
742 for (i = 1; i < m5Conf.numCPUs; i++) {
743 ulong stack = (ulong)unix_boot_alloc(1);
744 printf_lock("Bootstraping CPU %d with sp=0x%x\n", i, stack);
745 m5AlphaAccess->cpuStack[i] = stack;
746 }
747
748 /*
749 * Make sure that we are not stepping on the kernel
750 */
751 if ((ulong)unix_boot_mem >= (ulong)m5Conf.kernStart) {
752 panic("CONSOLE: too much memory. Smashing kernel\n");
753 } else {
754 printf_lock("unix_boot_mem ends at %x \n", unix_boot_mem);
755 }
756
757 JToKern((char *)bootadr, (ulong)rpb_percpu, free_pfn, kargc, kargv, NULL);
758}
759
760
761void
762JToKern(char *bootadr, ulong rpb_percpu, ulong free_pfn, ulong k_argc,
763 char **k_argv, char **envp)
764{
765 extern ulong palJToKern[];
766
767 struct _kernel_params *kernel_params = (struct _kernel_params *) KSEG;
768 int i;
769
770 printf_lock("k_argc = %d ", k_argc);
771 for (i = 0; i < k_argc; i++) {
772 printf_lock("'%s' ", k_argv[i]);
773 }
774 printf_lock("\n");
775
776 kernel_params->bootadr = bootadr;
777 kernel_params->rpb_percpu = KSEG_TO_PHYS(rpb_percpu);
778 kernel_params->free_pfn = free_pfn;
779 kernel_params->argc = k_argc;
780 kernel_params->argv = (ulong)k_argv;
781 kernel_params->envp = (ulong)envp;
782 printf_lock("jumping to kernel at 0x%x, (PCBB 0x%x pfn %d)\n",
783 bootadr, rpb_percpu, free_pfn);
784 JToPal(KSEG_TO_PHYS(palJToKern));
785 printf_lock("returned from JToPal. Looping\n");
786 while (1)
787 continue;
788}
789
790void
791JToPal(ulong bootadr)
792{
793 cServe(bootadr, 0, CSERVE_K_JTOPAL);
794
795 /*
796 * Make sure that floating point is enabled incase
797 * it was disabled by the user program.
798 */
799 wrfen(1);
800}
801
802int
803strcpy(char *dst, char *src)
804{
805 int i = 0;
806 while (*src) {
807 *dst++ = *src++;
808 i++;
809 }
810 return i;
811}
812
813/*
814 * Console I/O
815 *
816 */
817
818int numOpenDevices = 11;
819struct {
820 char name[128];
821} deviceState[32];
822
823#define BOOTDEVICE_NAME "SCSI 1 0 0 1 100 0"
824
825void
826DeviceOperation(long op, long channel, long count, long address, long block)
827{
828 long pAddr;
829
830 if (strcmp(deviceState[channel].name, BOOTDEVICE_NAME )) {
831 panic("DeviceRead: only implemented for root disk \n");
832 }
833 pAddr = KSEG_TO_PHYS(address);
834 if (pAddr + count > m5Conf.mem_size) {
835 panic("DeviceRead: request out of range \n");
836 }
837
838 m5AlphaAccess->diskCount = count;
839 m5AlphaAccess->diskPAddr = pAddr;
840 m5AlphaAccess->diskBlock = block;
841 m5AlphaAccess->diskOperation = op; /* launch */
842}
843
844/*
845 * M5 Console callbacks
846 *
847 */
848
849/* AXP manual 2-31 */
850#define CONSCB_GETC 0x1
851#define CONSCB_PUTS 0x2
852#define CONSCB_RESET_TERM 0x3
853#define CONSCB_SET_TERM_INT 0x4
854#define CONSCB_SET_TERM_CTL 0x5
855#define CONSCB_PROCESS_KEY 0x6
856#define CONSCB_OPEN_CONSOLE 0x7
857#define CONSCB_CLOSE_CONSOLE 0x8
858
859#define CONSCB_OPEN 0x10
860#define CONSCB_CLOSE 0x11
861#define CONSCB_READ 0x13
862
863#define CONSCB_GETENV 0x22
864
865/* AXP manual 2-26 */
866#define ENV_AUTO_ACTION 0X01
867#define ENV_BOOT_DEV 0X02
868#define ENV_BOOTDEF_DEV 0X03
869#define ENV_BOOTED_DEV 0X04
870#define ENV_BOOT_FILE 0X05
871#define ENV_BOOTED_FILE 0X06
872#define ENV_BOOT_OSFLAGS 0X07
873#define ENV_BOOTED_OSFLAGS 0X08
874#define ENV_BOOT_RESET 0X09
875#define ENV_DUMP_DEV 0X0A
876#define ENV_ENABLE_AUDIT 0X0B
877#define ENV_LICENSE 0X0C
878#define ENV_CHAR_SET 0X0D
879#define ENV_LANGUAGE 0X0E
880#define ENV_TTY_DEV 0X0F
881#define ENV_SCSIID 0X42
882#define ENV_SCSIFAST 0X43
883#define ENV_COM1_BAUD 0X44
884#define ENV_COM1_MODEM 0X45
885#define ENV_COM1_FLOW 0X46
886#define ENV_COM1_MISC 0X47
887#define ENV_COM2_BAUD 0X48
888#define ENV_COM2_MODEM 0X49
889#define ENV_COM2_FLOW 0X4A
890#define ENV_COM2_MISC 0X4B
891#define ENV_PASSWORD 0X4C
892#define ENV_SECURE 0X4D
893#define ENV_LOGFAIL 0X4E
894#define ENV_SRM2DEV_ID 0X4F
895
896#define MAX_ENVLEN 32
897
898char env_auto_action[MAX_ENVLEN] = "BOOT";
899char env_boot_dev[MAX_ENVLEN] = "";
900char env_bootdef_dev[MAX_ENVLEN] = "";
901char env_booted_dev[MAX_ENVLEN] = BOOTDEVICE_NAME;
902char env_boot_file[MAX_ENVLEN] = "";
903char env_booted_file[MAX_ENVLEN] = "";
904char env_boot_osflags[MAX_ENVLEN] = "";
905char env_booted_osflags[MAX_ENVLEN] = "";
906char env_boot_reset[MAX_ENVLEN] = "";
907char env_dump_dev[MAX_ENVLEN] = "";
908char env_enable_audit[MAX_ENVLEN] = "";
909char env_license[MAX_ENVLEN] = "";
910char env_char_set[MAX_ENVLEN] = "";
911char env_language[MAX_ENVLEN] = "";
912char env_tty_dev[MAX_ENVLEN] = "0";
913char env_scsiid[MAX_ENVLEN] = "";
914char env_scsifast[MAX_ENVLEN] = "";
915char env_com1_baud[MAX_ENVLEN] = "";
916char env_com1_modem[MAX_ENVLEN] = "";
917char env_com1_flow[MAX_ENVLEN] = "";
918char env_com1_misc[MAX_ENVLEN] = "";
919char env_com2_baud[MAX_ENVLEN] = "";
920char env_com2_modem[MAX_ENVLEN] = "";
921char env_com2_flow[MAX_ENVLEN] = "";
922char env_com2_misc[MAX_ENVLEN] = "";
923char env_password[MAX_ENVLEN] = "";
924char env_secure[MAX_ENVLEN] = "";
925char env_logfail[MAX_ENVLEN] = "";
926char env_srm2dev_id[MAX_ENVLEN] = "";
927
928#define MAX_ENV_INDEX 100
929char *envptr[MAX_ENV_INDEX] = {
930 0, /* 0x00 */
931 env_auto_action, /* 0x01 */
932 env_boot_dev, /* 0x02 */
933 env_bootdef_dev, /* 0x03 */
934 env_booted_dev, /* 0x04 */
935 env_boot_file, /* 0x05 */
936 env_booted_file, /* 0x06 */
937 env_boot_osflags, /* 0x07 */
938 env_booted_osflags, /* 0x08 */
939 env_boot_reset, /* 0x09 */
940 env_dump_dev, /* 0x0A */
941 env_enable_audit, /* 0x0B */
942 env_license, /* 0x0C */
943 env_char_set, /* 0x0D */
944 (char *)&env_language, /* 0x0E */
945 env_tty_dev, /* 0x0F */
946 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* 0x10 - 0x1F */
947 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* 0x20 - 0x2F */
948 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* 0x30 - 0x3F */
949 0, /* 0x40 */
950 0, /* 0x41 */
951 env_scsiid, /* 0x42 */
952 env_scsifast, /* 0x43 */
953 env_com1_baud, /* 0x44 */
954 env_com1_modem, /* 0x45 */
955 env_com1_flow, /* 0x46 */
956 env_com1_misc, /* 0x47 */
957 env_com2_baud, /* 0x48 */
958 env_com2_modem, /* 0x49 */
959 env_com2_flow, /* 0x4A */
960 env_com2_misc, /* 0x4B */
961 env_password, /* 0x4C */
962 env_secure, /* 0x4D */
963 env_logfail, /* 0x4E */
964 env_srm2dev_id, /* 0x4F */
965 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* 0x50 - 0x5F */
966 0, /* 0x60 */
967 0, /* 0x61 */
968 0, /* 0x62 */
969 0, /* 0x63 */
970};
971
972long
973CallBackDispatcher(long a0, long a1, long a2, long a3, long a4)
974{
975 long i;
976 switch (a0) {
977 case CONSCB_GETC:
978 return GetChar();
979
980 case CONSCB_PUTS:
981 for (i = 0; i < a3; i++)
982 PutChar(*((char *)a2 + i));
983 return a3;
984
985 case CONSCB_GETENV:
986 if (a1 >= 0 && a1 < MAX_ENV_INDEX && envptr[a1] != 0 && *envptr[a1]) {
987 i = strcpy((char*)a2, envptr[a1]);
988 } else {
989 strcpy((char*)a2, "");
990 i = (long)0xc000000000000000;
991 if (a1 >= 0 && a1 < MAX_ENV_INDEX)
992 printf_lock("GETENV unsupported option %d (0x%x)\n", a1, a1);
993 else
994 printf_lock("GETENV unsupported option %s\n", a1);
995 }
996
997 if (i > a3)
998 panic("CONSCB_GETENV overwrote buffer\n");
999 return i;
1000
1001 case CONSCB_OPEN:
1002 bcopy((char*)a1, deviceState[numOpenDevices].name, a2);
1003 deviceState[numOpenDevices].name[a2] = '\0';
1004 printf_lock("CONSOLE OPEN : %s --> success \n",
1005 deviceState[numOpenDevices].name);
1006 return numOpenDevices++;
1007
1008 case CONSCB_READ:
1009 DeviceOperation(a0, a1, a2, a3, a4);
1010 break;
1011
1012 case CONSCB_CLOSE:
1013 break;
1014
1015 case CONSCB_OPEN_CONSOLE:
1016 printf_lock("CONSOLE OPEN\n");
1017 return 0; /* success */
1018 break; /* not reached */
1019
1020 case CONSCB_CLOSE_CONSOLE:
1021 printf_lock("CONSOLE CLOSE\n");
1022 return 0; /* success */
1023 break; /* not reached */
1024
1025 default:
1026 panic("CallBackDispatcher(%x,%x,%x,%x,%x)\n", a0, a1, a2, a3, a4);
1027 }
1028
1029 return 0;
1030}
1031
1032long
1033CallBackFixup(int a0, int a1, int a2)
1034{
1035 long temp;
1036 /*
1037 * Linux uses r8 for the current pointer (pointer to data
1038 * structure contating info about currently running process). It
1039 * is set when the kernel starts and is expected to remain
1040 * there... Problem is that the unlike the kernel, the console
1041 * does not prevent the assembler from using r8. So here is a work
1042 * around. So far this has only been a problem in CallBackFixup()
1043 * but any other call back functions couldd cause a problem at
1044 * some point
1045 */
1046
1047 /* save off the current pointer to a temp variable */
1048 asm("bis $8, $31, %0" : "=r" (temp));
1049
1050 /* call original code */
1051 printf_lock("CallbackFixup %x %x, t7=%x\n", a0, a1, temp);
1052
1053 /* restore the current pointer */
1054 asm("bis %0, $31, $8" : : "r" (temp) : "$8");
1055
1056 return 0;
1057}
1058
1059void
1060SlaveCmd(int cpu, struct rpb_percpu *my_rpb)
1061{
1062 extern ulong palJToSlave[];
1063
1064 printf_lock("Slave CPU %d console command %s", cpu,
1065 my_rpb->rpb_iccb.iccb_rxbuf);
1066
1067 my_rpb->rpb_state |= STATE_BIP;
1068 my_rpb->rpb_state &= ~STATE_RC;
1069
1070 printf_lock("SlaveCmd: restart %x %x vptb %x my_rpb %x my_rpb_phys %x\n",
1071 rpb->rpb_restart, rpb->rpb_restart_pv, rpb->rpb_vptb, my_rpb,
1072 KSEG_TO_PHYS(my_rpb));
1073
1074 cServe(KSEG_TO_PHYS(palJToSlave), (ulong)rpb->rpb_restart,
1075 CSERVE_K_JTOPAL, rpb->rpb_restart_pv, rpb->rpb_vptb,
1076 KSEG_TO_PHYS(my_rpb));
1077
1078 panic("SlaveCmd returned \n");
1079}
1080
1081void
1082SlaveLoop(int cpu)
1083{
1084 int size = ROUNDUP128(sizeof(struct rpb_percpu));
1085 struct rpb_percpu *my_rpb = (struct rpb_percpu*)
1086 ((ulong)rpb_percpu + size * cpu);
1087
1088 if (cpu == 0) {
1089 panic("CPU�0 entering slaveLoop. Reenetering the console. HOSED\n");
1090 } else {
1091 printf_lock("Entering slaveloop for cpu %d my_rpb=%x\n", cpu, my_rpb);
1092 }
1093
1094 // swap the processors context to the one in the
1095 // rpb_percpu struct very carefully (i.e. no stack usage)
1096 // so that linux knows which processor ends up in __smp_callin
1097 // and we don't trash any data is the process
1098 SlaveSpin(cpu, my_rpb, &my_rpb->rpb_iccb.iccb_rxlen);
1099}
30/* ******************************************
31 * M5 Console
32 * ******************************************/
33
34#include <linux/stddef.h>
35#include <sys/types.h>
36
37#define CONSOLE
38#include "access.h"
39#include "cserve.h"
40#include "rpb.h"
41
42#define CONS_INT_TX 0x01 /* interrupt enable / state bits */
43#define CONS_INT_RX 0x02
44
45#define PAGE_SIZE (8192)
46
47#define KSTACK_REGION_VA 0x20040000
48
49#define KSEG 0xfffffc0000000000
50#define K1BASE 0xfffffc8000000000
51#define KSEG_TO_PHYS(x) (((ulong)x) & ~KSEG)
52
53#define ROUNDUP8(x) ((ulong)(((ulong)x)+7) & ~7)
54#define ROUNDUP128(x) ((ulong)(((ulong)x) + 127) & ~127)
55#define ROUNDUP8K(x) ((ulong)(((ulong)(x)) + 8191) & ~8191)
56
57#define FIRST(x) ((((ulong)(x)) >> 33) & 0x3ff)
58#define SECOND(x) ((((ulong)(x)) >> 23) & 0x3ff)
59#define THIRD(x) ((((ulong)(x)) >> 13) & 0x3ff)
60#define THIRD_XXX(x) ((((ulong)(x)) >> 13) & 0xfff)
61#define PFN(x) ((((ulong)(x) & ~KSEG) >> 13))
62
63/* Kernel write | kernel read | valid */
64#define KPTE(x) ((ulong)((((ulong)(x)) << 32) | 0x1101))
65
66#define HWRPB_PAGES 16
67
68#define NUM_KERNEL_THIRD (4)
69
70#define printf_lock(args...) \
71 do { \
72 SpinLock(&theLock); \
73 printf(args); \
74 SpinUnlock(&theLock); \
75 } while (0)
76
77
78void unixBoot(int argc, char **argv);
79void JToKern(char *bootadr, ulong rpb_percpu, ulong free_pfn, ulong k_argc,
80 char **k_argv, char **envp);
81void JToPal(ulong bootadr);
82void SlaveLoop(int cpu);
83
84volatile struct AlphaAccess *m5AlphaAccess;
85struct AlphaAccess m5Conf;
86
87ulong theLock;
88
89extern void SpinLock(ulong *lock);
90#define SpinUnlock(_x) *(_x) = 0;
91
92struct _kernel_params {
93 char *bootadr;
94 ulong rpb_percpu;
95 ulong free_pfn;
96 ulong argc;
97 ulong argv;
98 ulong envp; /* NULL */
99};
100
101extern consoleCallback[];
102extern consoleFixup[];
103long CallBackDispatcher();
104long CallBackFixup();
105
106/*
107 * m5 console output
108 */
109
110void
111InitConsole()
112{
113}
114
115char
116GetChar()
117{
118 return m5AlphaAccess->inputChar;
119}
120
121void
122PutChar(char c)
123{
124 m5AlphaAccess->outputChar = c;
125}
126
127int
128passArgs(int argc)
129{
130 return 0;
131}
132
133int
134main(int argc, char **argv)
135{
136 int x, i;
137 uint *k1ptr, *ksegptr;
138
139 InitConsole();
140 printf_lock("M5 console: m5AlphaAccess @ 0x%x\n", m5AlphaAccess);
141
142 /*
143 * get configuration from backdoor
144 */
145 m5Conf.last_offset = m5AlphaAccess->last_offset;
146 printf_lock("Got Configuration %d\n", m5Conf.last_offset);
147
148 m5Conf.last_offset = m5AlphaAccess->last_offset;
149 m5Conf.version = m5AlphaAccess->version;
150 m5Conf.numCPUs = m5AlphaAccess->numCPUs;
151 m5Conf.intrClockFrequency = m5AlphaAccess->intrClockFrequency;
152 m5Conf.cpuClock = m5AlphaAccess->cpuClock;
153 m5Conf.mem_size = m5AlphaAccess->mem_size;
154 m5Conf.kernStart = m5AlphaAccess->kernStart;
155 m5Conf.kernEnd = m5AlphaAccess->kernEnd;
156 m5Conf.entryPoint = m5AlphaAccess->entryPoint;
157 m5Conf.diskUnit = m5AlphaAccess->diskUnit;
158 m5Conf.diskCount = m5AlphaAccess->diskCount;
159 m5Conf.diskPAddr = m5AlphaAccess->diskPAddr;
160 m5Conf.diskBlock = m5AlphaAccess->diskBlock;
161 m5Conf.diskOperation = m5AlphaAccess->diskOperation;
162 m5Conf.outputChar = m5AlphaAccess->outputChar;
163 m5Conf.inputChar = m5AlphaAccess->inputChar;
164
165 if (m5Conf.version != ALPHA_ACCESS_VERSION) {
166 panic("Console version mismatch. Console expects %d. has %d \n",
167 ALPHA_ACCESS_VERSION, m5Conf.version);
168 }
169
170 /*
171 * setup arguments to kernel
172 */
173 unixBoot(argc, argv);
174
175 panic("unix failed to boot\n");
176 return 1;
177}
178
179/*
180 * BOOTING
181 */
182struct rpb m5_rpb = {
183 NULL, /* 000: physical self-reference */
184 ((long)'H') | (((long)'W') << 8) | (((long)'R') << 16) |
185 ((long)'P' << 24) | (((long)'B') << 32), /* 008: contains "HWRPB" */
186 6, /* 010: HWRPB version number */
187 /* the byte count is wrong, but who needs it? - lance */
188 0, /* 018: bytes in RPB perCPU CTB CRB MEDSC */
189 0, /* 020: primary cpu id */
190 PAGE_SIZE, /* 028: page size in bytes */
191 43, /* 030: number of phys addr bits */
192 127, /* 038: max valid ASN */
193 {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1'},
194 /* 040: system serial num: 10 ascii chars */
195 0, /* OVERRIDDEN */
196 (1<<10), /* 058: system variation */
197 'c'|('o'<<8)|('o'<<16)|('l'<< 24), /* 060: system revision */
198 1024*4096, /* 068: scaled interval clock intr freq */
199 0, /* 070: cycle counter frequency */
200 0x200000000, /* 078: virtual page table base */
201 0, /* 080: reserved */
202 0, /* 088: offset to translation buffer hint */
203 1, /* 090: number of processor slots OVERRIDDEN*/
204 sizeof(struct rpb_percpu), /* 098: per-cpu slot size. OVERRIDDEN */
205 0, /* 0A0: offset to per_cpu slots */
206 1, /* 0A8: number of CTBs */
207 sizeof(struct ctb_tt),
208 0, /* 0B8: offset to CTB (cons term block) */
209 0, /* 0C0: offset to CRB (cons routine block) */
210 0, /* 0C8: offset to memory descriptor table */
211 0, /* 0D0: offset to config data block */
212 0, /* 0D8: offset to FRU table */
213 0, /* 0E0: virt addr of save term routine */
214 0, /* 0E8: proc value for save term routine */
215 0, /* 0F0: virt addr of restore term routine */
216 0, /* 0F8: proc value for restore term routine */
217 0, /* 100: virt addr of CPU restart routine */
218 0, /* 108: proc value for CPU restart routine */
219 0, /* 110: used to determine presence of kdebug */
220 0, /* 118: reserved for hardware */
221/* the checksum is wrong, but who needs it? - lance */
222 0, /* 120: checksum of prior entries in rpb */
223 0, /* 128: receive ready bitmask */
224 0, /* 130: transmit ready bitmask */
225 0, /* 138: Dynamic System Recog. offset */
226};
227
228ulong m5_tbb[] = { 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e,
229 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e,
230 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e,
231 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e };
232
233struct rpb_percpu m5_rpb_percpu = {
234 {0,0,0,0,0,0,1,{0,0},{0,0,0,0,0,0,0,0}}, /* 000: boot/restart HWPCB */
235 (STATE_PA | STATE_PP | STATE_CV |
236 STATE_PV | STATE_PMV | STATE_PL), /* 080: per-cpu state bits */
237 0xc000, /* 088: palcode memory length */
238 0x2000, /* 090: palcode scratch length */
239 0x4000, /* 098: paddr of pal mem space */
240 0x2000, /* 0A0: paddr of pal scratch space */
241 (2 << 16) | (5 << 8) | 1, /* 0A8: PALcode rev required */
242 11 | (2L << 32), /* 0B0: processor type */
243 7, /* 0B8: processor variation */
244 'M'|('5'<<8)|('A'<<16)|('0'<<24), /* 0C0: processor revision */
245 {'M','5','/','A','l','p','h','a','0','0','0','0','0','0','0','0'},
246 /* 0C8: proc serial num: 10 chars */
247 0, /* 0D8: phys addr of logout area */
248 0, /* 0E0: len in bytes of logout area */
249 0, /* 0E8: halt pcb base */
250 0, /* 0F0: halt pc */
251 0, /* 0F8: halt ps */
252 0, /* 100: halt arg list (R25) */
253 0, /* 108: halt return address (R26) */
254 0, /* 110: halt procedure value (R27) */
255 0, /* 118: reason for halt */
256 0, /* 120: for software */
257 {0}, /* 128: inter-console comm buffer */
258 {1,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0}, /* 1D0: PALcode revs available */
259 0 /* 250: reserved for arch use */
260/* the dump stack grows from the end of the rpb page not to reach here */
261};
262
263struct _m5_rpb_mdt {
264 long rpb_checksum; /* 000: checksum of entire mem desc table */
265 long rpb_impaddr; /* 008: PA of implementation dep info */
266 long rpb_numcl; /* 010: number of clusters */
267 struct rpb_cluster rpb_cluster[3]; /* first instance of a cluster */
268};
269
270struct _m5_rpb_mdt m5_rpb_mdt = {
271 0, /* 000: checksum of entire mem desc table */
272 0, /* 008: PA of implementation dep info */
273 0, /* 010: number of clusters */
274 {{ 0, /* 000: starting PFN of this cluster */
275 0, /* 008: count of PFNs in this cluster */
276 0, /* 010: count of tested PFNs in cluster */
277 0, /* 018: va of bitmap */
278 0, /* 020: pa of bitmap */
279 0, /* 028: checksum of bitmap */
280 1 /* 030: usage of cluster */
281 },
282 { 0, /* 000: starting PFN of this cluster */
283 0, /* 008: count of PFNs in this cluster */
284 0, /* 010: count of tested PFNs in cluster */
285 0, /* 018: va of bitmap */
286 0, /* 020: pa of bitmap */
287 0, /* 028: checksum of bitmap */
288 0 /* 030: usage of cluster */
289 },
290 { 0, /* 000: starting PFN of this cluster */
291 0, /* 008: count of PFNs in this cluster */
292 0, /* 010: count of tested PFNs in cluster */
293 0, /* 018: va of bitmap */
294 0, /* 020: pa of bitmap */
295 0, /* 028: checksum of bitmap */
296 0 /* 030: usage of cluster */
297 }}
298};
299
300/* constants for slotinfo bus_type subfield */
301#define SLOTINFO_TC 0
302#define SLOTINFO_ISA 1
303#define SLOTINFO_EISA 2
304#define SLOTINFO_PCI 3
305
306struct rpb_ctb m5_rpb_ctb = {
307 CONS_DZ, /* 000: console type */
308 0, /* 008: console unit */
309 0, /* 010: reserved */
310 0 /* 018: byte length of device dep portion */
311};
312
313/* we don't do any fixup (aka relocate the console) - we hope */
314struct rpb_crb m5_rpb_crb = {
315 0, /* va of call-back dispatch rtn */
316 0, /* pa of call-back dispatch rtn */
317 0, /* va of call-back fixup rtn */
318 0, /* pa of call-back fixup rtn */
319 0, /* number of entries in phys/virt map */
320 0 /* Number of pages to be mapped */
321};
322
323struct _rpb_name {
324 ulong length;
325 char name[16];
326};
327
328extern struct _rpb_name m5_name;
329
330struct rpb_dsr m5_rpb_dsr = {
331 0,
332 0,
333 0,
334};
335
336struct _rpb_name m5_name = {
337 16,
338 {'U','M','I','C','H',' ','M','5','/','A','L','P','H','A',' ',0},
339};
340
341/*
342 * M5 has one LURT entry:
343 * 1050 is for workstations
344 * 1100 is servers (and is needed for CXX)
345 */
346long m5_lurt[10] = { 9, 12, -1, -1, -1, -1, -1, -1, 1100, 1100 };
347
348ulong unix_boot_mem;
349ulong bootadr;
350
351char **kargv;
352int kargc;
353ulong free_pfn;
354struct rpb_percpu *rpb_percpu;
355
356char *
357unix_boot_alloc(int pages)
358{
359 char *ret = (char *)unix_boot_mem;
360 unix_boot_mem += (pages * PAGE_SIZE);
361 return ret;
362}
363
364ulong *first = 0;
365ulong *third_rpb = 0;
366ulong *reservedFixup = 0;
367
368int strcpy(char *dst, char *src);
369
370struct rpb *rpb;
371extern ulong _end;
372
373void
374unixBoot(int argc, char **argv)
375{
376 ulong *second, *third_kernel, ptr, *tbb, size, *percpu_logout;
377 unsigned char *mdt_bitmap;
378 long *lp1, *lp2, sum;
379 int i, cl;
380 ulong kern_first_page;
381 ulong mem_size = m5Conf.mem_size;
382
383 ulong mem_pages = mem_size / PAGE_SIZE, cons_pages;
384 ulong mdt_bitmap_pages = mem_pages / (PAGE_SIZE*8);
385
386 ulong kernel_bytes, ksp, kernel_end, *unix_kernel_stack, bss,
387 ksp_bottom, ksp_top;
388 struct rpb_ctb *rpb_ctb;
389 struct ctb_tt *ctb_tt;
390 struct rpb_dsr *rpb_dsr;
391 struct rpb_crb *rpb_crb;
392 struct _m5_rpb_mdt *rpb_mdt;
393 int *rpb_lurt;
394 char *rpb_name;
395 ulong nextPtr;
396
397 printf_lock("memsize %x pages %x \n", mem_size, mem_pages);
398
399 /* Allocate:
400 * two pages for the HWRPB
401 * five page table pages:
402 * 1: First level page table
403 * 1: Second level page table
404 * 1: Third level page table for HWRPB
405 * 2: Third level page table for kernel (for up to 16MB)
406 * set up the page tables
407 * load the kernel at the physical address 0x230000
408 * build the HWRPB
409 * set up memory descriptor table to give up the
410 * physical memory between the end of the page
411 * tables and the start of the kernel
412 * enable kseg addressing
413 * jump to the kernel
414 */
415
416 unix_boot_mem = ROUNDUP8K(&_end);
417
418 printf_lock("First free page after ROM 0x%x\n", unix_boot_mem);
419
420 rpb = (struct rpb *)unix_boot_alloc(HWRPB_PAGES);
421
422 mdt_bitmap = (unsigned char *)unix_boot_alloc(mdt_bitmap_pages);
423 first = (ulong *)unix_boot_alloc(1);
424 second = (ulong *)unix_boot_alloc(1);
425 third_rpb = (ulong *)unix_boot_alloc(1);
426 reservedFixup = (ulong*) unix_boot_alloc(1);
427 third_kernel = (ulong *)unix_boot_alloc(NUM_KERNEL_THIRD);
428 percpu_logout = (ulong*)unix_boot_alloc(1);
429
430 cons_pages = KSEG_TO_PHYS(unix_boot_mem) / PAGE_SIZE;
431
432 /* Set up the page tables */
433 bzero((char *)first, PAGE_SIZE);
434 bzero((char *)second, PAGE_SIZE);
435 bzero((char *)reservedFixup, PAGE_SIZE);
436 bzero((char *)third_rpb, HWRPB_PAGES * PAGE_SIZE);
437 bzero((char *)third_kernel, PAGE_SIZE * NUM_KERNEL_THIRD);
438
439 first[0] = KPTE(PFN(second));
440 first[1] = KPTE(PFN(first)); /* Region 3 */
441
442 /* Region 0 */
443 second[SECOND(0x10000000)] = KPTE(PFN(third_rpb));
444
445 for (i = 0; i < NUM_KERNEL_THIRD; i++) {
446 /* Region 1 */
447 second[SECOND(0x20000000) + i] = KPTE(PFN(third_kernel) + i);
448 }
449
450 /* Region 2 */
451 second[SECOND(0x40000000)] = KPTE(PFN(second));
452
453
454 /* For some obscure reason, Dec Unix's database read
455 * from /etc/sysconfigtab is written to this fixed
456 * mapped memory location. Go figure, since it is
457 * not initialized by the console. Maybe it is
458 * to look at the database from the console
459 * after a boot/crash.
460 *
461 * Black magic to estimate the max size. SEGVs on overflow
462 * bugnion
463 */
464
465#define DATABASE_BASE 0x20000000
466#define DATABASE_END 0x20020000
467
468 ulong *dbPage = (ulong*)unix_boot_alloc(1);
469 bzero(dbPage, PAGE_SIZE);
470 second[SECOND(DATABASE_BASE)] = KPTE(PFN(dbPage));
471 for (i = DATABASE_BASE; i < DATABASE_END ; i += PAGE_SIZE) {
472 ulong *db = (ulong*)unix_boot_alloc(1);
473 dbPage[THIRD(i)] = KPTE(PFN(db));
474 }
475
476 /* Region 0 */
477 /* Map the HWRPB */
478 for (i = 0; i < HWRPB_PAGES; i++)
479 third_rpb[i] = KPTE(PFN(rpb) + i);
480
481 /* Map the MDT bitmap table */
482 for (i = 0; i < mdt_bitmap_pages; i++) {
483 third_rpb[HWRPB_PAGES + i] = KPTE(PFN(mdt_bitmap) + i);
484 }
485
486 /* Protect the PAL pages */
487 for (i = 1; i < PFN(first); i++)
488 third_rpb[HWRPB_PAGES + mdt_bitmap_pages + i] = KPTE(i);
489
490 /* Set up third_kernel after it's loaded, when we know where it is */
491 kern_first_page = (KSEG_TO_PHYS(m5Conf.kernStart)/PAGE_SIZE);
492 kernel_end = ROUNDUP8K(m5Conf.kernEnd);
493 bootadr = m5Conf.entryPoint;
494
495 printf_lock("HWRPB 0x%x l1pt 0x%x l2pt 0x%x l3pt_rpb 0x%x l3pt_kernel 0x%x"
496 " l2reserv 0x%x\n",
497 rpb, first, second, third_rpb, third_kernel, reservedFixup);
498 if (kernel_end - m5Conf.kernStart > (0x800000*NUM_KERNEL_THIRD)) {
499 printf_lock("Kernel is more than 8MB 0x%x - 0x%x = 0x%x\n",
500 kernel_end, m5Conf.kernStart,
501 kernel_end - m5Conf.kernStart );
502 panic("kernel too big\n");
503 }
504 printf_lock("kstart = 0x%x, kend = 0x%x, kentry = 0x%x, numCPUs = 0x%x\n", m5Conf.kernStart, m5Conf.kernEnd, m5Conf.entryPoint, m5Conf.numCPUs);
505 ksp_bottom = (ulong)unix_boot_alloc(1);
506 ksp_top = ksp_bottom + PAGE_SIZE;
507 ptr = (ulong) ksp_bottom;
508 bzero((char *)ptr, PAGE_SIZE);
509 dbPage[THIRD(KSTACK_REGION_VA)] = 0; /* Stack Guard Page */
510 dbPage[THIRD(KSTACK_REGION_VA + PAGE_SIZE)] = KPTE(PFN(ptr)); /* Kernel Stack Page */
511 dbPage[THIRD(KSTACK_REGION_VA + 2*PAGE_SIZE)] = 0; /* Stack Guard Page */
512
513 /* put argv into the bottom of the stack - argv starts at 1 because
514 * the command thatr got us here (i.e. "unixboot) is in argv[0].
515 */
516 ksp = ksp_top - 8; /* Back up one longword */
517 ksp -= argc * sizeof(char *); /* Make room for argv */
518 kargv = (char **) ksp;
519 for (i = 1; i < argc; i++) { /* Copy arguments to stack */
520 ksp -= ((strlen(argv[i]) + 1) + 7) & ~0x7;
521 kargv[i-1] = (char *) ksp;
522 strcpy(kargv[i - 1], argv[i]);
523 }
524 kargc = i - 1;
525 kargv[kargc] = NULL; /* just to be sure; doesn't seem to be used */
526 ksp -= sizeof(char *); /* point above last arg for no real reason */
527
528 free_pfn = PFN(kernel_end);
529
530 bcopy((char *)&m5_rpb, (char *)rpb, sizeof(struct rpb));
531
532 rpb->rpb_selfref = (struct rpb *) KSEG_TO_PHYS(rpb);
533 rpb->rpb_string = 0x0000004250525748;
534
535 tbb = (ulong *) (((char *) rpb) + ROUNDUP8(sizeof(struct rpb)));
536 rpb->rpb_trans_off = (ulong)tbb - (ulong)rpb;
537 bcopy((char *)m5_tbb, (char *)tbb, sizeof(m5_tbb));
538
539 /*
540 * rpb_counter. Use to determine timeouts in OS.
541 * XXX must be patched after a checkpoint restore (I guess)
542 */
543
544 printf_lock("CPU Clock at %d MHz IntrClockFrequency=%d \n",
545 m5Conf.cpuClock, m5Conf.intrClockFrequency);
546 rpb->rpb_counter = m5Conf.cpuClock * 1000 * 1000;
547
548 /*
549 * By definition, the rpb_clock is scaled by 4096 (in hz)
550 */
551 rpb->rpb_clock = m5Conf.intrClockFrequency * 4096;
552
553 /*
554 * Per CPU Slots. Multiprocessor support.
555 */
556 int percpu_size = ROUNDUP128(sizeof(struct rpb_percpu));
557
558 printf_lock("Booting with %d processor(s) \n", m5Conf.numCPUs);
559
560 rpb->rpb_numprocs = m5Conf.numCPUs;
561 rpb->rpb_slotsize = percpu_size;
562 rpb_percpu = (struct rpb_percpu *)
563 ROUNDUP128(((ulong)tbb) + (sizeof(m5_tbb)));
564
565 rpb->rpb_percpu_off = (ulong)rpb_percpu - (ulong)rpb;
566
567 for (i = 0; i < m5Conf.numCPUs; i++) {
568 struct rpb_percpu *thisCPU = (struct rpb_percpu*)
569 ((ulong)rpb_percpu + percpu_size * i);
570
571 bzero((char *)thisCPU, percpu_size);
572 bcopy((char *)&m5_rpb_percpu, (char *)thisCPU,
573 sizeof(struct rpb_percpu));
574
575 thisCPU->rpb_pcb.rpb_ksp = (KSTACK_REGION_VA + 2*PAGE_SIZE - (ksp_top - ksp));
576 thisCPU->rpb_pcb.rpb_ptbr = PFN(first);
577
578 thisCPU->rpb_logout = KSEG_TO_PHYS(percpu_logout);
579 thisCPU->rpb_logout_len = PAGE_SIZE;
580
581 printf_lock("KSP: 0x%x PTBR 0x%x\n",
582 thisCPU->rpb_pcb.rpb_ksp, thisCPU->rpb_pcb.rpb_ptbr);
583 }
584
585 nextPtr = (ulong)rpb_percpu + percpu_size * m5Conf.numCPUs;
586
587 /*
588 * Console Terminal Block
589 */
590 rpb_ctb = (struct rpb_ctb *) nextPtr;
591 ctb_tt = (struct ctb_tt*) rpb_ctb;
592
593 rpb->rpb_ctb_off = ((ulong)rpb_ctb) - (ulong)rpb;
594 rpb->rpb_ctb_size = sizeof(struct rpb_ctb);
595
596 bzero((char *)rpb_ctb, sizeof(struct ctb_tt));
597
598 rpb_ctb->rpb_type = CONS_DZ;
599 rpb_ctb->rpb_length = sizeof(ctb_tt) - sizeof(rpb_ctb);
600
601 /*
602 * uart initizliation
603 */
604 ctb_tt->ctb_tintr_vec = 0x6c0; /* matches tlaser pal code */
605 ctb_tt->ctb_rintr_vec = 0x680; /* matches tlaser pal code */
606 ctb_tt->ctb_term_type = CTB_GRAPHICS;
607
608 rpb_crb = (struct rpb_crb *) (((ulong)rpb_ctb) + sizeof(struct ctb_tt));
609 rpb->rpb_crb_off = ((ulong)rpb_crb) - (ulong)rpb;
610
611 bzero((char *)rpb_crb, sizeof(struct rpb_crb));
612
613 /*
614 * console callback stuff (m5)
615 */
616 rpb_crb->rpb_num = 1;
617 rpb_crb->rpb_mapped_pages = HWRPB_PAGES;
618 rpb_crb->rpb_map[0].rpb_virt = 0x10000000;
619 rpb_crb->rpb_map[0].rpb_phys = KSEG_TO_PHYS(((ulong)rpb) & ~0x1fff);
620 rpb_crb->rpb_map[0].rpb_pgcount = HWRPB_PAGES;
621
622 printf_lock("Console Callback at 0x%x, fixup at 0x%x, crb offset: 0x%x\n",
623 rpb_crb->rpb_va_disp, rpb_crb->rpb_va_fixup, rpb->rpb_crb_off);
624
625 rpb_mdt = (struct _m5_rpb_mdt *)((ulong)rpb_crb + sizeof(struct rpb_crb));
626 rpb->rpb_mdt_off = (ulong)rpb_mdt - (ulong)rpb;
627 bcopy((char *)&m5_rpb_mdt, (char *)rpb_mdt, sizeof(struct _m5_rpb_mdt));
628
629
630 cl = 0;
631 rpb_mdt->rpb_cluster[cl].rpb_pfncount = kern_first_page;
632 cl++;
633
634 rpb_mdt->rpb_cluster[cl].rpb_pfn = kern_first_page;
635 rpb_mdt->rpb_cluster[cl].rpb_pfncount = mem_pages - kern_first_page;
636 rpb_mdt->rpb_cluster[cl].rpb_pfntested =
637 rpb_mdt->rpb_cluster[cl].rpb_pfncount;
638 rpb_mdt->rpb_cluster[cl].rpb_pa = KSEG_TO_PHYS(mdt_bitmap);
639 rpb_mdt->rpb_cluster[cl].rpb_va = 0x10000000 + HWRPB_PAGES * PAGE_SIZE;
640 cl++;
641
642 rpb_mdt->rpb_numcl = cl;
643
644 for (i = 0; i < cl; i++)
645 printf_lock("Memory cluster %d [%d - %d]\n", i,
646 rpb_mdt->rpb_cluster[i].rpb_pfn,
647 rpb_mdt->rpb_cluster[i].rpb_pfncount);
648
649 /* Checksum the rpb for good luck */
650 sum = 0;
651 lp1 = (long *)&rpb_mdt->rpb_impaddr;
652 lp2 = (long *)&rpb_mdt->rpb_cluster[cl];
653 while (lp1 < lp2) sum += *lp1++;
654 rpb_mdt->rpb_checksum = sum;
655
656 /* XXX should checksum the cluster descriptors */
657 bzero((char *)mdt_bitmap, mdt_bitmap_pages * PAGE_SIZE);
658 for (i = 0; i < mem_pages/8; i++)
659 ((unsigned char *)mdt_bitmap)[i] = 0xff;
660
661 printf_lock("Initalizing mdt_bitmap addr 0x%x mem_pages %x \n",
662 (long)mdt_bitmap,(long)mem_pages);
663
664 m5_rpb.rpb_config_off = 0;
665 m5_rpb.rpb_fru_off = 0;
666
667 rpb_dsr = (struct rpb_dsr *)((ulong)rpb_mdt + sizeof(struct _m5_rpb_mdt));
668 rpb->rpb_dsr_off = (ulong)rpb_dsr - (ulong)rpb;
669 bzero((char *)rpb_dsr, sizeof(struct rpb_dsr));
670 rpb_dsr->rpb_smm = 1578; /* Official XXM SMM number as per SRM */
671 rpb_dsr->rpb_smm = 1089; /* Official Alcor SMM number as per SRM */
672
673 rpb_lurt = (int *) ROUNDUP8((ulong)rpb_dsr + sizeof(struct rpb_dsr));
674 rpb_dsr->rpb_lurt_off = ((ulong) rpb_lurt) - (ulong) rpb_dsr;
675 bcopy((char *)m5_lurt, (char *)rpb_lurt, sizeof(m5_lurt));
676
677 rpb_name = (char *) ROUNDUP8(((ulong)rpb_lurt) + sizeof(m5_lurt));
678 rpb_dsr->rpb_sysname_off = ((ulong) rpb_name) - (ulong) rpb_dsr;
679#define THENAME " M5/Alpha "
680 sum = sizeof(THENAME);
681 bcopy(THENAME, rpb_name, sum);
682 *(ulong *)rpb_name = sizeof(THENAME); /* put in length field */
683
684 /* calculate size of rpb */
685 rpb->rpb_size = ((ulong) &rpb_name[sum]) - (ulong)rpb;
686
687 if (rpb->rpb_size > PAGE_SIZE * HWRPB_PAGES) {
688 panic("HWRPB_PAGES=%d too small for HWRPB !!! \n");
689 }
690
691 ulong *rpbptr = (ulong*)((char*)rpb_dsr + sizeof(struct rpb_dsr));
692 rpb_crb->rpb_pa_disp = KSEG_TO_PHYS(rpbptr);
693 rpb_crb->rpb_va_disp = 0x10000000 +
694 (((ulong)rpbptr - (ulong)rpb) & (0x2000 * HWRPB_PAGES - 1));
695 printf_lock("ConsoleDispatch at virt %x phys %x val %x\n",
696 rpb_crb->rpb_va_disp, rpb_crb->rpb_pa_disp, consoleCallback);
697 *rpbptr++ = 0;
698 *rpbptr++ = (ulong) consoleCallback;
699 rpb_crb->rpb_pa_fixup = KSEG_TO_PHYS(rpbptr);
700 rpb_crb->rpb_va_fixup = 0x10000000 +
701 (((ulong)rpbptr - (ulong)rpb) & (0x2000 * HWRPB_PAGES - 1));
702 *rpbptr++ = 0;
703
704 *rpbptr++ = (ulong) consoleFixup;
705
706 /* Checksum the rpb for good luck */
707 sum = 0;
708 lp1 = (long *)rpb;
709 lp2 = &rpb->rpb_checksum;
710 while (lp1 < lp2)
711 sum += *lp1++;
712 *lp2 = sum;
713
714 /*
715 * MP bootstrap
716 */
717 for (i = 1; i < m5Conf.numCPUs; i++) {
718 ulong stack = (ulong)unix_boot_alloc(1);
719 printf_lock("Bootstraping CPU %d with sp=0x%x\n", i, stack);
720 m5AlphaAccess->cpuStack[i] = stack;
721 }
722
723 /*
724 * Make sure that we are not stepping on the kernel
725 */
726 if ((ulong)unix_boot_mem >= (ulong)m5Conf.kernStart) {
727 panic("CONSOLE: too much memory. Smashing kernel\n");
728 } else {
729 printf_lock("unix_boot_mem ends at %x \n", unix_boot_mem);
730 }
731
732 JToKern((char *)bootadr, (ulong)rpb_percpu, free_pfn, kargc, kargv, NULL);
733}
734
735
736void
737JToKern(char *bootadr, ulong rpb_percpu, ulong free_pfn, ulong k_argc,
738 char **k_argv, char **envp)
739{
740 extern ulong palJToKern[];
741
742 struct _kernel_params *kernel_params = (struct _kernel_params *) KSEG;
743 int i;
744
745 printf_lock("k_argc = %d ", k_argc);
746 for (i = 0; i < k_argc; i++) {
747 printf_lock("'%s' ", k_argv[i]);
748 }
749 printf_lock("\n");
750
751 kernel_params->bootadr = bootadr;
752 kernel_params->rpb_percpu = KSEG_TO_PHYS(rpb_percpu);
753 kernel_params->free_pfn = free_pfn;
754 kernel_params->argc = k_argc;
755 kernel_params->argv = (ulong)k_argv;
756 kernel_params->envp = (ulong)envp;
757 printf_lock("jumping to kernel at 0x%x, (PCBB 0x%x pfn %d)\n",
758 bootadr, rpb_percpu, free_pfn);
759 JToPal(KSEG_TO_PHYS(palJToKern));
760 printf_lock("returned from JToPal. Looping\n");
761 while (1)
762 continue;
763}
764
765void
766JToPal(ulong bootadr)
767{
768 cServe(bootadr, 0, CSERVE_K_JTOPAL);
769
770 /*
771 * Make sure that floating point is enabled incase
772 * it was disabled by the user program.
773 */
774 wrfen(1);
775}
776
777int
778strcpy(char *dst, char *src)
779{
780 int i = 0;
781 while (*src) {
782 *dst++ = *src++;
783 i++;
784 }
785 return i;
786}
787
788/*
789 * Console I/O
790 *
791 */
792
793int numOpenDevices = 11;
794struct {
795 char name[128];
796} deviceState[32];
797
798#define BOOTDEVICE_NAME "SCSI 1 0 0 1 100 0"
799
800void
801DeviceOperation(long op, long channel, long count, long address, long block)
802{
803 long pAddr;
804
805 if (strcmp(deviceState[channel].name, BOOTDEVICE_NAME )) {
806 panic("DeviceRead: only implemented for root disk \n");
807 }
808 pAddr = KSEG_TO_PHYS(address);
809 if (pAddr + count > m5Conf.mem_size) {
810 panic("DeviceRead: request out of range \n");
811 }
812
813 m5AlphaAccess->diskCount = count;
814 m5AlphaAccess->diskPAddr = pAddr;
815 m5AlphaAccess->diskBlock = block;
816 m5AlphaAccess->diskOperation = op; /* launch */
817}
818
819/*
820 * M5 Console callbacks
821 *
822 */
823
824/* AXP manual 2-31 */
825#define CONSCB_GETC 0x1
826#define CONSCB_PUTS 0x2
827#define CONSCB_RESET_TERM 0x3
828#define CONSCB_SET_TERM_INT 0x4
829#define CONSCB_SET_TERM_CTL 0x5
830#define CONSCB_PROCESS_KEY 0x6
831#define CONSCB_OPEN_CONSOLE 0x7
832#define CONSCB_CLOSE_CONSOLE 0x8
833
834#define CONSCB_OPEN 0x10
835#define CONSCB_CLOSE 0x11
836#define CONSCB_READ 0x13
837
838#define CONSCB_GETENV 0x22
839
840/* AXP manual 2-26 */
841#define ENV_AUTO_ACTION 0X01
842#define ENV_BOOT_DEV 0X02
843#define ENV_BOOTDEF_DEV 0X03
844#define ENV_BOOTED_DEV 0X04
845#define ENV_BOOT_FILE 0X05
846#define ENV_BOOTED_FILE 0X06
847#define ENV_BOOT_OSFLAGS 0X07
848#define ENV_BOOTED_OSFLAGS 0X08
849#define ENV_BOOT_RESET 0X09
850#define ENV_DUMP_DEV 0X0A
851#define ENV_ENABLE_AUDIT 0X0B
852#define ENV_LICENSE 0X0C
853#define ENV_CHAR_SET 0X0D
854#define ENV_LANGUAGE 0X0E
855#define ENV_TTY_DEV 0X0F
856#define ENV_SCSIID 0X42
857#define ENV_SCSIFAST 0X43
858#define ENV_COM1_BAUD 0X44
859#define ENV_COM1_MODEM 0X45
860#define ENV_COM1_FLOW 0X46
861#define ENV_COM1_MISC 0X47
862#define ENV_COM2_BAUD 0X48
863#define ENV_COM2_MODEM 0X49
864#define ENV_COM2_FLOW 0X4A
865#define ENV_COM2_MISC 0X4B
866#define ENV_PASSWORD 0X4C
867#define ENV_SECURE 0X4D
868#define ENV_LOGFAIL 0X4E
869#define ENV_SRM2DEV_ID 0X4F
870
871#define MAX_ENVLEN 32
872
873char env_auto_action[MAX_ENVLEN] = "BOOT";
874char env_boot_dev[MAX_ENVLEN] = "";
875char env_bootdef_dev[MAX_ENVLEN] = "";
876char env_booted_dev[MAX_ENVLEN] = BOOTDEVICE_NAME;
877char env_boot_file[MAX_ENVLEN] = "";
878char env_booted_file[MAX_ENVLEN] = "";
879char env_boot_osflags[MAX_ENVLEN] = "";
880char env_booted_osflags[MAX_ENVLEN] = "";
881char env_boot_reset[MAX_ENVLEN] = "";
882char env_dump_dev[MAX_ENVLEN] = "";
883char env_enable_audit[MAX_ENVLEN] = "";
884char env_license[MAX_ENVLEN] = "";
885char env_char_set[MAX_ENVLEN] = "";
886char env_language[MAX_ENVLEN] = "";
887char env_tty_dev[MAX_ENVLEN] = "0";
888char env_scsiid[MAX_ENVLEN] = "";
889char env_scsifast[MAX_ENVLEN] = "";
890char env_com1_baud[MAX_ENVLEN] = "";
891char env_com1_modem[MAX_ENVLEN] = "";
892char env_com1_flow[MAX_ENVLEN] = "";
893char env_com1_misc[MAX_ENVLEN] = "";
894char env_com2_baud[MAX_ENVLEN] = "";
895char env_com2_modem[MAX_ENVLEN] = "";
896char env_com2_flow[MAX_ENVLEN] = "";
897char env_com2_misc[MAX_ENVLEN] = "";
898char env_password[MAX_ENVLEN] = "";
899char env_secure[MAX_ENVLEN] = "";
900char env_logfail[MAX_ENVLEN] = "";
901char env_srm2dev_id[MAX_ENVLEN] = "";
902
903#define MAX_ENV_INDEX 100
904char *envptr[MAX_ENV_INDEX] = {
905 0, /* 0x00 */
906 env_auto_action, /* 0x01 */
907 env_boot_dev, /* 0x02 */
908 env_bootdef_dev, /* 0x03 */
909 env_booted_dev, /* 0x04 */
910 env_boot_file, /* 0x05 */
911 env_booted_file, /* 0x06 */
912 env_boot_osflags, /* 0x07 */
913 env_booted_osflags, /* 0x08 */
914 env_boot_reset, /* 0x09 */
915 env_dump_dev, /* 0x0A */
916 env_enable_audit, /* 0x0B */
917 env_license, /* 0x0C */
918 env_char_set, /* 0x0D */
919 (char *)&env_language, /* 0x0E */
920 env_tty_dev, /* 0x0F */
921 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* 0x10 - 0x1F */
922 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* 0x20 - 0x2F */
923 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* 0x30 - 0x3F */
924 0, /* 0x40 */
925 0, /* 0x41 */
926 env_scsiid, /* 0x42 */
927 env_scsifast, /* 0x43 */
928 env_com1_baud, /* 0x44 */
929 env_com1_modem, /* 0x45 */
930 env_com1_flow, /* 0x46 */
931 env_com1_misc, /* 0x47 */
932 env_com2_baud, /* 0x48 */
933 env_com2_modem, /* 0x49 */
934 env_com2_flow, /* 0x4A */
935 env_com2_misc, /* 0x4B */
936 env_password, /* 0x4C */
937 env_secure, /* 0x4D */
938 env_logfail, /* 0x4E */
939 env_srm2dev_id, /* 0x4F */
940 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* 0x50 - 0x5F */
941 0, /* 0x60 */
942 0, /* 0x61 */
943 0, /* 0x62 */
944 0, /* 0x63 */
945};
946
947long
948CallBackDispatcher(long a0, long a1, long a2, long a3, long a4)
949{
950 long i;
951 switch (a0) {
952 case CONSCB_GETC:
953 return GetChar();
954
955 case CONSCB_PUTS:
956 for (i = 0; i < a3; i++)
957 PutChar(*((char *)a2 + i));
958 return a3;
959
960 case CONSCB_GETENV:
961 if (a1 >= 0 && a1 < MAX_ENV_INDEX && envptr[a1] != 0 && *envptr[a1]) {
962 i = strcpy((char*)a2, envptr[a1]);
963 } else {
964 strcpy((char*)a2, "");
965 i = (long)0xc000000000000000;
966 if (a1 >= 0 && a1 < MAX_ENV_INDEX)
967 printf_lock("GETENV unsupported option %d (0x%x)\n", a1, a1);
968 else
969 printf_lock("GETENV unsupported option %s\n", a1);
970 }
971
972 if (i > a3)
973 panic("CONSCB_GETENV overwrote buffer\n");
974 return i;
975
976 case CONSCB_OPEN:
977 bcopy((char*)a1, deviceState[numOpenDevices].name, a2);
978 deviceState[numOpenDevices].name[a2] = '\0';
979 printf_lock("CONSOLE OPEN : %s --> success \n",
980 deviceState[numOpenDevices].name);
981 return numOpenDevices++;
982
983 case CONSCB_READ:
984 DeviceOperation(a0, a1, a2, a3, a4);
985 break;
986
987 case CONSCB_CLOSE:
988 break;
989
990 case CONSCB_OPEN_CONSOLE:
991 printf_lock("CONSOLE OPEN\n");
992 return 0; /* success */
993 break; /* not reached */
994
995 case CONSCB_CLOSE_CONSOLE:
996 printf_lock("CONSOLE CLOSE\n");
997 return 0; /* success */
998 break; /* not reached */
999
1000 default:
1001 panic("CallBackDispatcher(%x,%x,%x,%x,%x)\n", a0, a1, a2, a3, a4);
1002 }
1003
1004 return 0;
1005}
1006
1007long
1008CallBackFixup(int a0, int a1, int a2)
1009{
1010 long temp;
1011 /*
1012 * Linux uses r8 for the current pointer (pointer to data
1013 * structure contating info about currently running process). It
1014 * is set when the kernel starts and is expected to remain
1015 * there... Problem is that the unlike the kernel, the console
1016 * does not prevent the assembler from using r8. So here is a work
1017 * around. So far this has only been a problem in CallBackFixup()
1018 * but any other call back functions couldd cause a problem at
1019 * some point
1020 */
1021
1022 /* save off the current pointer to a temp variable */
1023 asm("bis $8, $31, %0" : "=r" (temp));
1024
1025 /* call original code */
1026 printf_lock("CallbackFixup %x %x, t7=%x\n", a0, a1, temp);
1027
1028 /* restore the current pointer */
1029 asm("bis %0, $31, $8" : : "r" (temp) : "$8");
1030
1031 return 0;
1032}
1033
1034void
1035SlaveCmd(int cpu, struct rpb_percpu *my_rpb)
1036{
1037 extern ulong palJToSlave[];
1038
1039 printf_lock("Slave CPU %d console command %s", cpu,
1040 my_rpb->rpb_iccb.iccb_rxbuf);
1041
1042 my_rpb->rpb_state |= STATE_BIP;
1043 my_rpb->rpb_state &= ~STATE_RC;
1044
1045 printf_lock("SlaveCmd: restart %x %x vptb %x my_rpb %x my_rpb_phys %x\n",
1046 rpb->rpb_restart, rpb->rpb_restart_pv, rpb->rpb_vptb, my_rpb,
1047 KSEG_TO_PHYS(my_rpb));
1048
1049 cServe(KSEG_TO_PHYS(palJToSlave), (ulong)rpb->rpb_restart,
1050 CSERVE_K_JTOPAL, rpb->rpb_restart_pv, rpb->rpb_vptb,
1051 KSEG_TO_PHYS(my_rpb));
1052
1053 panic("SlaveCmd returned \n");
1054}
1055
1056void
1057SlaveLoop(int cpu)
1058{
1059 int size = ROUNDUP128(sizeof(struct rpb_percpu));
1060 struct rpb_percpu *my_rpb = (struct rpb_percpu*)
1061 ((ulong)rpb_percpu + size * cpu);
1062
1063 if (cpu == 0) {
1064 panic("CPU�0 entering slaveLoop. Reenetering the console. HOSED\n");
1065 } else {
1066 printf_lock("Entering slaveloop for cpu %d my_rpb=%x\n", cpu, my_rpb);
1067 }
1068
1069 // swap the processors context to the one in the
1070 // rpb_percpu struct very carefully (i.e. no stack usage)
1071 // so that linux knows which processor ends up in __smp_callin
1072 // and we don't trash any data is the process
1073 SlaveSpin(cpu, my_rpb, &my_rpb->rpb_iccb.iccb_rxlen);
1074}