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