console.c (7977:60051d2262c2) console.c (7978:9700266d52f4)
1
2
3/* ******************************************
4 * SimOS SRM Console
5 *
6 * Derived from Lance Berc's SRM console
7 * for the SRC XXM�Machine
8 * ******************************************/
9
10
11/* from simos */
12typedef unsigned long long uint64;
1
2
3/* ******************************************
4 * SimOS SRM Console
5 *
6 * Derived from Lance Berc's SRM console
7 * for the SRC XXM�Machine
8 * ******************************************/
9
10
11/* from simos */
12typedef unsigned long long uint64;
13#include "machine_defs.h"
14#include "new_aouthdr.h"
13typedef unsigned int uint32;
14
15#define CONSOLE
15#include "alpha_access.h"
16#include "alpha_access.h"
17#include "machine_defs.h"
18
16#if 0
19#if 0
20#include "new_aouthdr.h"
17#include "srcmax.h"
18#endif
19
20/* from ../h */
21#include "lib.h"
22#include "rpb.h"
23#include "cserve.h"
24
25
26#define CONS_INT_TX 0x01 /* interrupt enable / state bits */
27#define CONS_INT_RX 0x02
28
29#define KSEG 0xfffffc0000000000
30#define K1BASE 0xfffffc8000000000
31#define KSEG_TO_PHYS(x)(((ul)x) & ~KSEG)
32
33#define CDR ((volatile DevConsoleRegisters *) \
34 (__MAGIC_ZONE(0, 0, MAGIC_ZONE_BDOOR_DEV) + __MAGIC_BDOOR_CNSLE_OFFS))
35
36
37#define PHYS_TO_K1(_x) (K1BASE|(_x))
38
39#define AOUT_LOAD_ADDR (KSEG|0xf000)
40
41#define ROUNDUP8(x) ((ul)(((ul)x)+7) & ~7)
42#define ROUNDUP128(x) ((ul)(((ul)x)+127) & ~127)
43#define ROUNDUP8K(x) ((ul)(((ul)(x))+8191) & ~8191)
44
45#define FIRST(x) ((((ul)(x)) >> 33) & 0x3ff)
46#define SECOND(x) ((((ul)(x)) >> 23) & 0x3ff)
47#define THIRD(x) ((((ul)(x)) >> 13) & 0x3ff)
48#define THIRD_XXX(x) ((((ul)(x)) >> 13) & 0xfff)
49#define PFN(x) ((((ul)(x) & ~KSEG) >> 13))
50
51/* Kernel write | kernel read | valid */
52#define KPTE(x) ((ul)((((ul)(x)) << 32) | 0x1101))
53
54#define HWRPB_PAGES 4
55#define MDT_BITMAP_PAGES 4
56
57#define CSERVE_K_JTOKERN 0x18
58
59#define NUM_KERNEL_THIRD (4)
60
61
62static unixBoot(int go, int argc, char **argv);
63void jToPal(ul bootadr);
64void SlaveLoop(int cpu);
65
66
21#include "srcmax.h"
22#endif
23
24/* from ../h */
25#include "lib.h"
26#include "rpb.h"
27#include "cserve.h"
28
29
30#define CONS_INT_TX 0x01 /* interrupt enable / state bits */
31#define CONS_INT_RX 0x02
32
33#define KSEG 0xfffffc0000000000
34#define K1BASE 0xfffffc8000000000
35#define KSEG_TO_PHYS(x)(((ul)x) & ~KSEG)
36
37#define CDR ((volatile DevConsoleRegisters *) \
38 (__MAGIC_ZONE(0, 0, MAGIC_ZONE_BDOOR_DEV) + __MAGIC_BDOOR_CNSLE_OFFS))
39
40
41#define PHYS_TO_K1(_x) (K1BASE|(_x))
42
43#define AOUT_LOAD_ADDR (KSEG|0xf000)
44
45#define ROUNDUP8(x) ((ul)(((ul)x)+7) & ~7)
46#define ROUNDUP128(x) ((ul)(((ul)x)+127) & ~127)
47#define ROUNDUP8K(x) ((ul)(((ul)(x))+8191) & ~8191)
48
49#define FIRST(x) ((((ul)(x)) >> 33) & 0x3ff)
50#define SECOND(x) ((((ul)(x)) >> 23) & 0x3ff)
51#define THIRD(x) ((((ul)(x)) >> 13) & 0x3ff)
52#define THIRD_XXX(x) ((((ul)(x)) >> 13) & 0xfff)
53#define PFN(x) ((((ul)(x) & ~KSEG) >> 13))
54
55/* Kernel write | kernel read | valid */
56#define KPTE(x) ((ul)((((ul)(x)) << 32) | 0x1101))
57
58#define HWRPB_PAGES 4
59#define MDT_BITMAP_PAGES 4
60
61#define CSERVE_K_JTOKERN 0x18
62
63#define NUM_KERNEL_THIRD (4)
64
65
66static unixBoot(int go, int argc, char **argv);
67void jToPal(ul bootadr);
68void SlaveLoop(int cpu);
69
70
67AlphaAccess simosConf;
71struct AlphaAccess simosConf;
68
69/* **************************************************************
70 * Console callbacks use VMS calling conventions
71 * read AXP manual, 2-64.
72 * ***************************************************************/
73typedef struct OpenVMSFunc {
74 long dummy;
75 long func;
76}OpenVMSFunc;
77
78OpenVMSFunc callbackFunc, fixupFunc;
79
80
81
82
83ul theLock;
84
85
86extern void SpinLock(ul *lock);
87#define SpinUnlock(_x) *(_x) = 0;
88
89struct _kernel_params {
90 char *bootadr;
91 ul rpb_percpu;
92 ul free_pfn;
93 ul argc;
94 ul argv;
95 ul envp; /* NULL */
96};
97
98
99extern consoleCallback[];
100extern consoleFixup[];
101long CallBackDispatcher();
102long CallBackFixup();
103
104/*
105 * simos console output
106 */
107
108void InitConsole(void)
109{
110#if 0
111 CDR->intr_status =(DevRegister)(DEV_CNSLE_RX_INTR |DEV_CNSLE_TX_INTR);
112#endif
113}
114
72
73/* **************************************************************
74 * Console callbacks use VMS calling conventions
75 * read AXP manual, 2-64.
76 * ***************************************************************/
77typedef struct OpenVMSFunc {
78 long dummy;
79 long func;
80}OpenVMSFunc;
81
82OpenVMSFunc callbackFunc, fixupFunc;
83
84
85
86
87ul theLock;
88
89
90extern void SpinLock(ul *lock);
91#define SpinUnlock(_x) *(_x) = 0;
92
93struct _kernel_params {
94 char *bootadr;
95 ul rpb_percpu;
96 ul free_pfn;
97 ul argc;
98 ul argv;
99 ul envp; /* NULL */
100};
101
102
103extern consoleCallback[];
104extern consoleFixup[];
105long CallBackDispatcher();
106long CallBackFixup();
107
108/*
109 * simos console output
110 */
111
112void InitConsole(void)
113{
114#if 0
115 CDR->intr_status =(DevRegister)(DEV_CNSLE_RX_INTR |DEV_CNSLE_TX_INTR);
116#endif
117}
118
119char GetChar()
120{
121 struct AlphaAccess *k1Conf = (struct AlphaAccess *)(__MAGIC_ZONE(0, 0, MAGIC_ZONE_EV5_ALIAS));
122 return 0;
123}
124
115void PutChar(char c)
116{
117#if 0
118 CDR->data = c;
119#endif
120#if 0
121 *(int*) PHYS_TO_K1(SLOT_D_COM1<<5) = c;
122#endif
125void PutChar(char c)
126{
127#if 0
128 CDR->data = c;
129#endif
130#if 0
131 *(int*) PHYS_TO_K1(SLOT_D_COM1<<5) = c;
132#endif
123 AlphaAccess *k1Conf = (AlphaAccess *)(__MAGIC_ZONE(0, 0, MAGIC_ZONE_EV5_ALIAS));
133 struct AlphaAccess *k1Conf = (struct AlphaAccess *)(__MAGIC_ZONE(0, 0, MAGIC_ZONE_EV5_ALIAS));
124 k1Conf->outputChar = c;
125
126}
127
128
134 k1Conf->outputChar = c;
135
136}
137
138
129int passArgs(int argc)
130{
131 ;
132}
139int
140passArgs(int argc)
141{ return 0; }
133
142
134
143int
135main(int argc, char **argv)
136{
137 int x,i;
144main(int argc, char **argv)
145{
146 int x,i;
138 AlphaAccess *k1Conf = (AlphaAccess *)(__MAGIC_ZONE(0, 0, MAGIC_ZONE_EV5_ALIAS));
147 struct AlphaAccess *k1Conf = (struct AlphaAccess *)(__MAGIC_ZONE(0, 0, MAGIC_ZONE_EV5_ALIAS));
139 ui *k1ptr,*ksegptr;
140
141
142 InitConsole();
143 printf("SimOS console \n");
144 /*
145 * get configuration from backdoor
146 */
147 simosConf.last_offset = k1Conf->last_offset;
148 printf(" Got simosConfiguration %d \n",simosConf.last_offset);
149
150 for (i=1;i<=simosConf.last_offset/4;i++) {
151 ui *k1ptr = (ui*)k1Conf + i;
152 ui *ksegptr = (ui*)(&simosConf.last_offset)+i;
153 *ksegptr = *k1ptr;
154
155 }
156
157 if (simosConf.version != ALPHA_ACCESS_VERSION) {
158 panic("Console version mismatch. Console expects %d. SimOS has %d \n",
159 ALPHA_ACCESS_VERSION,simosConf.version);
160 }
161
162
163 /*
164 * setup arguments to kernel
165 */
166 unixBoot(1,argc,argv);
167
168 x = *(volatile int *)(K1BASE-4);
169 while(1) continue;
170 return x;
171}
172
173/*
174 * BOOTING
175 */
176struct rpb xxm_rpb = {
177 NULL, /* 000: physical self-reference */
148 ui *k1ptr,*ksegptr;
149
150
151 InitConsole();
152 printf("SimOS console \n");
153 /*
154 * get configuration from backdoor
155 */
156 simosConf.last_offset = k1Conf->last_offset;
157 printf(" Got simosConfiguration %d \n",simosConf.last_offset);
158
159 for (i=1;i<=simosConf.last_offset/4;i++) {
160 ui *k1ptr = (ui*)k1Conf + i;
161 ui *ksegptr = (ui*)(&simosConf.last_offset)+i;
162 *ksegptr = *k1ptr;
163
164 }
165
166 if (simosConf.version != ALPHA_ACCESS_VERSION) {
167 panic("Console version mismatch. Console expects %d. SimOS has %d \n",
168 ALPHA_ACCESS_VERSION,simosConf.version);
169 }
170
171
172 /*
173 * setup arguments to kernel
174 */
175 unixBoot(1,argc,argv);
176
177 x = *(volatile int *)(K1BASE-4);
178 while(1) continue;
179 return x;
180}
181
182/*
183 * BOOTING
184 */
185struct rpb xxm_rpb = {
186 NULL, /* 000: physical self-reference */
178 'H'|('W'<<8)|('R'<<16)|('P'<<24)|('B'<<32), /* 008: contains string "HWRPB" */
187 ((long)'H') | (((long)'W') << 8) | (((long)'R') << 16) |
188 ((long)'P' << 24) | (((long)'B') << 32), /* 008: contains string "HWRPB" */
179 6, /* 010: HWRPB version number */
180 /* the byte count is wrong, but who needs it? - lance */
181 0, /* 018: bytes in RPB perCPU CTB CRB MEDSC */
182 0, /* 020: primary cpu id */
183 8192, /* 028: page size in bytes */
184 43, /* 030: number of phys addr bits */
185 127, /* 038: max valid ASN */
186 {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1'}, /* 040: system serial num: 10 ascii chars */
187#ifdef undef
188/* To be legitimate, the following system type and variation are correct for the XXM.
189 But there are too many #ifdefs etc to deal with in Unix, so we tell the kernel
190 that we're an Avanti, which is similar enough.
191 */
192 31, /* 050: system type - XXM is now in the Alpha SRM */
193 (1 << 10) | (2<<1),/* 058: system variation - XXM w/EV5 & embeded console */
194#endif
195#if 0
196 0x12, /* 050: system type - masquarade as some random 21064 */
197#endif
198 12, /* masquerade a DEC_3000_500 (bugnion) */
199 (2<<1), /* 058: system variation */
200 'c'|('o'<<8)|('o'<<16)|('l'<< 24), /* 060: system revision */
201 1024*4096, /* 068: scaled interval clock intr freq OVERRIDEN*/
202 0, /* 070: cycle counter frequency */
203 0x200000000, /* 078: virtual page table base */
204 0, /* 080: reserved */
205 0, /* 088: offset to translation buffer hint */
206 1, /* 090: number of processor slots OVERRIDDEN*/
207 sizeof(struct rpb_percpu), /* 098: per-cpu slot size. OVERRIDDEN */
208 0, /* 0A0: offset to per_cpu slots */
209 1, /* 0A8: number of CTBs */
210#ifdef bugnion_gone
211 sizeof(struct rpb_ctb), /* 0B0: bytes in largest CTB */
212#else
213 sizeof(struct ctb_tt),
214#endif
215 0, /* 0B8: offset to CTB (cons term block) */
216 0, /* 0C0: offset to CRB (cons routine block) */
217 0, /* 0C8: offset to memory descriptor table */
218 0, /* 0D0: offset to config data block */
219 0, /* 0D8: offset to FRU table */
220 0, /* 0E0: virt addr of save term routine */
221 0, /* 0E8: proc value for save term routine */
222 0, /* 0F0: virt addr of restore term routine */
223 0, /* 0F8: proc value for restore term routine */
224 0, /* 100: virt addr of CPU restart routine */
225 0, /* 108: proc value for CPU restart routine */
226 0, /* 110: used to determine presence of kdebug */
227 0, /* 118: reserved for hardware */
228/* the checksum is wrong, but who needs it? - lance */
229 0, /* 120: checksum of prior entries in rpb */
230 0, /* 128: receive ready bitmask */
231 0, /* 130: transmit ready bitmask */
232 0, /* 138: Dynamic System Recog. offset */
233};
234
235ul xxm_tbb[] = { 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e,
236 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e};
237
238struct rpb_percpu xxm_rpb_percpu = {
239 {0,0,0,0,0,0,0,{0,0},{0,0,0,0,0,0,0,0}}, /* 000: boot/restart HWPCB */
240 (STATE_PA | STATE_PP | STATE_CV | STATE_PV | STATE_PMV | STATE_PL), /* 080: per-cpu state bits */
241 0xc000, /* 088: palcode memory length */
242 0x2000, /* 090: palcode scratch length */
243 0x4000, /* 098: phys addr of palcode mem space */
244 0x2000, /* 0A0: phys addr of palcode scratch space */
245 (2 << 16) | (5 << 8) | 1, /* 0A8: PALcode rev required */
189 6, /* 010: HWRPB version number */
190 /* the byte count is wrong, but who needs it? - lance */
191 0, /* 018: bytes in RPB perCPU CTB CRB MEDSC */
192 0, /* 020: primary cpu id */
193 8192, /* 028: page size in bytes */
194 43, /* 030: number of phys addr bits */
195 127, /* 038: max valid ASN */
196 {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1'}, /* 040: system serial num: 10 ascii chars */
197#ifdef undef
198/* To be legitimate, the following system type and variation are correct for the XXM.
199 But there are too many #ifdefs etc to deal with in Unix, so we tell the kernel
200 that we're an Avanti, which is similar enough.
201 */
202 31, /* 050: system type - XXM is now in the Alpha SRM */
203 (1 << 10) | (2<<1),/* 058: system variation - XXM w/EV5 & embeded console */
204#endif
205#if 0
206 0x12, /* 050: system type - masquarade as some random 21064 */
207#endif
208 12, /* masquerade a DEC_3000_500 (bugnion) */
209 (2<<1), /* 058: system variation */
210 'c'|('o'<<8)|('o'<<16)|('l'<< 24), /* 060: system revision */
211 1024*4096, /* 068: scaled interval clock intr freq OVERRIDEN*/
212 0, /* 070: cycle counter frequency */
213 0x200000000, /* 078: virtual page table base */
214 0, /* 080: reserved */
215 0, /* 088: offset to translation buffer hint */
216 1, /* 090: number of processor slots OVERRIDDEN*/
217 sizeof(struct rpb_percpu), /* 098: per-cpu slot size. OVERRIDDEN */
218 0, /* 0A0: offset to per_cpu slots */
219 1, /* 0A8: number of CTBs */
220#ifdef bugnion_gone
221 sizeof(struct rpb_ctb), /* 0B0: bytes in largest CTB */
222#else
223 sizeof(struct ctb_tt),
224#endif
225 0, /* 0B8: offset to CTB (cons term block) */
226 0, /* 0C0: offset to CRB (cons routine block) */
227 0, /* 0C8: offset to memory descriptor table */
228 0, /* 0D0: offset to config data block */
229 0, /* 0D8: offset to FRU table */
230 0, /* 0E0: virt addr of save term routine */
231 0, /* 0E8: proc value for save term routine */
232 0, /* 0F0: virt addr of restore term routine */
233 0, /* 0F8: proc value for restore term routine */
234 0, /* 100: virt addr of CPU restart routine */
235 0, /* 108: proc value for CPU restart routine */
236 0, /* 110: used to determine presence of kdebug */
237 0, /* 118: reserved for hardware */
238/* the checksum is wrong, but who needs it? - lance */
239 0, /* 120: checksum of prior entries in rpb */
240 0, /* 128: receive ready bitmask */
241 0, /* 130: transmit ready bitmask */
242 0, /* 138: Dynamic System Recog. offset */
243};
244
245ul xxm_tbb[] = { 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e,
246 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e, 0x1e1e1e1e1e1e1e1e};
247
248struct rpb_percpu xxm_rpb_percpu = {
249 {0,0,0,0,0,0,0,{0,0},{0,0,0,0,0,0,0,0}}, /* 000: boot/restart HWPCB */
250 (STATE_PA | STATE_PP | STATE_CV | STATE_PV | STATE_PMV | STATE_PL), /* 080: per-cpu state bits */
251 0xc000, /* 088: palcode memory length */
252 0x2000, /* 090: palcode scratch length */
253 0x4000, /* 098: phys addr of palcode mem space */
254 0x2000, /* 0A0: phys addr of palcode scratch space */
255 (2 << 16) | (5 << 8) | 1, /* 0A8: PALcode rev required */
246 5|(2<<32), /* 0B0: processor type */
256 5 | (2L << 32), /* 0B0: processor type */
247 7, /* 0B8: processor variation */
248 'D'|('a'<<8)|('v'<<16)|('e'<<24), /* 0C0: processor revision */
249 {'D','a','v','e','C','o','n','r','o','y',0,0,0,0,0,0}, /* 0C8: proc serial num: 10 ascii chars */
250 0, /* 0D8: phys addr of logout area */
251 0, /* 0E0: length in bytes of logout area */
252 0, /* 0E8: halt pcb base */
253 0, /* 0F0: halt pc */
254 0, /* 0F8: halt ps */
255 0, /* 100: halt arg list (R25) */
256 0, /* 108: halt return address (R26) */
257 0, /* 110: halt procedure value (R27) */
258 0, /* 118: reason for halt */
259 0, /* 120: for software */
260 {0}, /* 128: inter-console communications buffer */
261 {1,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0}, /* 1D0: PALcode revs available */
262 0 /* 250: reserved for arch use */
263/* the dump stack grows from the end of the rpb page not to reach here */
264};
265
266struct _xxm_rpb_mdt {
267 long rpb_checksum; /* 000: checksum of entire mem desc table */
268 long rpb_impaddr; /* 008: PA of implementation dep info */
269 long rpb_numcl; /* 010: number of clusters */
270 struct rpb_cluster rpb_cluster[3]; /* first instance of a cluster */
271};
272
273struct _xxm_rpb_mdt xxm_rpb_mdt = {
274 0, /* 000: checksum of entire mem desc table */
275 0, /* 008: PA of implementation dep info */
276 0, /* 010: number of clusters */
277 {{ 0, /* 000: starting PFN of this cluster */
278 0, /* 008: count of PFNs in this cluster */
279 0, /* 010: count of tested PFNs in cluster */
280 0, /* 018: va of bitmap */
281 0, /* 020: pa of bitmap */
282 0, /* 028: checksum of bitmap */
283 1 /* 030: usage of cluster */
284 },
285 { 0, /* 000: starting PFN of this cluster */
286 0, /* 008: count of PFNs in this cluster */
287 0, /* 010: count of tested PFNs in cluster */
288 0, /* 018: va of bitmap */
289 0, /* 020: pa of bitmap */
290 0, /* 028: checksum of bitmap */
291 0 /* 030: usage of cluster */
292 },
293 { 0, /* 000: starting PFN of this cluster */
294 0, /* 008: count of PFNs in this cluster */
295 0, /* 010: count of tested PFNs in cluster */
296 0, /* 018: va of bitmap */
297 0, /* 020: pa of bitmap */
298 0, /* 028: checksum of bitmap */
299 0 /* 030: usage of cluster */
300 }}
301};
302
303/* constants for slotinfo bus_type subfield */
304#define SLOTINFO_TC 0
305#define SLOTINFO_ISA 1
306#define SLOTINFO_EISA 2
307#define SLOTINFO_PCI 3
308
309struct rpb_ctb xxm_rpb_ctb = {
310 CONS_DZ, /* 000: console type */
311 0, /* 008: console unit */
312 0, /* 010: reserved */
313 0 /* 018: byte length of device dep portion */
314};
315
316/* we don't do any fixup (aka relocate the console) - we hope */
317struct rpb_crb xxm_rpb_crb = {
318 0, /* va of call-back dispatch rtn */
319 0, /* pa of call-back dispatch rtn */
320 0, /* va of call-back fixup rtn */
321 0, /* pa of call-back fixup rtn */
322 0, /* number of entries in phys/virt map */
323 0 /* Number of pages to be mapped */
324};
325
326struct _rpb_name {
327 unsigned long length;
328 char name[16];
329};
330
331extern struct _rpb_name xxm_name;
332
333struct rpb_dsr xxm_rpb_dsr = {
334 0,
335 0,
336 0,
337};
338
339struct _rpb_name xxm_name = {
340 16,
341 {'D','E','C',' ','S','R','C',' ','X','X','M',' ','D','G','C',0},
342};
343
344/* XXM has one LURT entry - 1050 is for workstations, 1100 is servers (and is needed for CXX) */
345long xxm_lurt[10] = { 9, 12, -1, -1, -1, -1, -1, -1, 1100, 1100 };
346
347ul unix_boot_mem;
348unsigned long bootadr;
349#if 0
350unsigned long aout_bss_addr, aout_bss_size, aout_entry, aout_text_start, aout_data_addr;
351#endif
352char **kargv;
353int kargc;
354ul free_pfn;
355struct rpb_percpu *rpb_percpu;
356
357
358#define MAX_CPUS 32
359
360ul bootStrapImpure[MAX_CPUS];
361
362
363char *unix_boot_alloc(int pages)
364{
365 char *ret = (char *) unix_boot_mem;
366 unix_boot_mem += (pages * 8192);
367 return ret;
368}
369
370ul *first = 0;
371ul *third_rpb = 0;
372ul *reservedFixup = 0;
373
257 7, /* 0B8: processor variation */
258 'D'|('a'<<8)|('v'<<16)|('e'<<24), /* 0C0: processor revision */
259 {'D','a','v','e','C','o','n','r','o','y',0,0,0,0,0,0}, /* 0C8: proc serial num: 10 ascii chars */
260 0, /* 0D8: phys addr of logout area */
261 0, /* 0E0: length in bytes of logout area */
262 0, /* 0E8: halt pcb base */
263 0, /* 0F0: halt pc */
264 0, /* 0F8: halt ps */
265 0, /* 100: halt arg list (R25) */
266 0, /* 108: halt return address (R26) */
267 0, /* 110: halt procedure value (R27) */
268 0, /* 118: reason for halt */
269 0, /* 120: for software */
270 {0}, /* 128: inter-console communications buffer */
271 {1,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0}, /* 1D0: PALcode revs available */
272 0 /* 250: reserved for arch use */
273/* the dump stack grows from the end of the rpb page not to reach here */
274};
275
276struct _xxm_rpb_mdt {
277 long rpb_checksum; /* 000: checksum of entire mem desc table */
278 long rpb_impaddr; /* 008: PA of implementation dep info */
279 long rpb_numcl; /* 010: number of clusters */
280 struct rpb_cluster rpb_cluster[3]; /* first instance of a cluster */
281};
282
283struct _xxm_rpb_mdt xxm_rpb_mdt = {
284 0, /* 000: checksum of entire mem desc table */
285 0, /* 008: PA of implementation dep info */
286 0, /* 010: number of clusters */
287 {{ 0, /* 000: starting PFN of this cluster */
288 0, /* 008: count of PFNs in this cluster */
289 0, /* 010: count of tested PFNs in cluster */
290 0, /* 018: va of bitmap */
291 0, /* 020: pa of bitmap */
292 0, /* 028: checksum of bitmap */
293 1 /* 030: usage of cluster */
294 },
295 { 0, /* 000: starting PFN of this cluster */
296 0, /* 008: count of PFNs in this cluster */
297 0, /* 010: count of tested PFNs in cluster */
298 0, /* 018: va of bitmap */
299 0, /* 020: pa of bitmap */
300 0, /* 028: checksum of bitmap */
301 0 /* 030: usage of cluster */
302 },
303 { 0, /* 000: starting PFN of this cluster */
304 0, /* 008: count of PFNs in this cluster */
305 0, /* 010: count of tested PFNs in cluster */
306 0, /* 018: va of bitmap */
307 0, /* 020: pa of bitmap */
308 0, /* 028: checksum of bitmap */
309 0 /* 030: usage of cluster */
310 }}
311};
312
313/* constants for slotinfo bus_type subfield */
314#define SLOTINFO_TC 0
315#define SLOTINFO_ISA 1
316#define SLOTINFO_EISA 2
317#define SLOTINFO_PCI 3
318
319struct rpb_ctb xxm_rpb_ctb = {
320 CONS_DZ, /* 000: console type */
321 0, /* 008: console unit */
322 0, /* 010: reserved */
323 0 /* 018: byte length of device dep portion */
324};
325
326/* we don't do any fixup (aka relocate the console) - we hope */
327struct rpb_crb xxm_rpb_crb = {
328 0, /* va of call-back dispatch rtn */
329 0, /* pa of call-back dispatch rtn */
330 0, /* va of call-back fixup rtn */
331 0, /* pa of call-back fixup rtn */
332 0, /* number of entries in phys/virt map */
333 0 /* Number of pages to be mapped */
334};
335
336struct _rpb_name {
337 unsigned long length;
338 char name[16];
339};
340
341extern struct _rpb_name xxm_name;
342
343struct rpb_dsr xxm_rpb_dsr = {
344 0,
345 0,
346 0,
347};
348
349struct _rpb_name xxm_name = {
350 16,
351 {'D','E','C',' ','S','R','C',' ','X','X','M',' ','D','G','C',0},
352};
353
354/* XXM has one LURT entry - 1050 is for workstations, 1100 is servers (and is needed for CXX) */
355long xxm_lurt[10] = { 9, 12, -1, -1, -1, -1, -1, -1, 1100, 1100 };
356
357ul unix_boot_mem;
358unsigned long bootadr;
359#if 0
360unsigned long aout_bss_addr, aout_bss_size, aout_entry, aout_text_start, aout_data_addr;
361#endif
362char **kargv;
363int kargc;
364ul free_pfn;
365struct rpb_percpu *rpb_percpu;
366
367
368#define MAX_CPUS 32
369
370ul bootStrapImpure[MAX_CPUS];
371
372
373char *unix_boot_alloc(int pages)
374{
375 char *ret = (char *) unix_boot_mem;
376 unix_boot_mem += (pages * 8192);
377 return ret;
378}
379
380ul *first = 0;
381ul *third_rpb = 0;
382ul *reservedFixup = 0;
383
384int strcpy(char *dst, char *src);
385
374struct rpb *rpb;
375
376unixBoot(int go, int argc, char **argv)
377{
378 ul *second, *third_kernel, ptr, *tbb, size, *percpu_logout;
379 unsigned char *mdt_bitmap;
380 long *lp1, *lp2, sum;
381 int i, cl;
382 int kern_first_page;
383 int mem_size = simosConf.mem_size;
384
385 int mem_pages = mem_size / 8192, cons_pages;
386 ul kernel_bytes, ksp, kernel_end, *unix_kernel_stack, bss, ksp_bottom, ksp_top;
387 struct rpb_ctb *rpb_ctb;
388 struct ctb_tt *ctb_tt;
389 struct rpb_dsr *rpb_dsr;
390 struct rpb_crb *rpb_crb;
391 struct _xxm_rpb_mdt *rpb_mdt;
392 int *rpb_lurt;
393 char *rpb_name;
394 ul nextPtr;
395
396 printf( "memsize %x pages %x \n",mem_size,mem_pages);
397
398
399
400#ifdef notnow
401 if (unixArgs()) return;
402#endif
403
404 /* Allocate:
405 * two pages for the HWRPB
406 * five page table pages:
407 * 1: First level page table
408 * 1: Second level page table
409 * 1: Third level page table for HWRPB
410 * 2: Third level page table for kernel (for up to 16MB)
411 * set up the page tables
412 * load the kernel at the physical address 0x230000
413 * build the HWRPB
414 * set up memory descriptor table to give up the
415 * physical memory between the end of the page
416 * tables and the start of the kernel
417 * enable kseg addressing
418 * jump to the kernel
419 */
420
421 unix_boot_mem = ROUNDUP8K(&_end);
422
423 printf("First free page after ROM 0x%x\n", unix_boot_mem);
424
425 rpb = (struct rpb *) unix_boot_alloc( HWRPB_PAGES);
426
427 mdt_bitmap = (unsigned char *) unix_boot_alloc(MDT_BITMAP_PAGES);
428 first = (ul *)unix_boot_alloc(1);
429 second = (ul *)unix_boot_alloc(1);
430 third_rpb = (ul *)unix_boot_alloc(1);
431 reservedFixup = (ul*) unix_boot_alloc(1);
432 third_kernel = (ul *)unix_boot_alloc(NUM_KERNEL_THIRD);
433 percpu_logout = (ul*)unix_boot_alloc(1);
434
435
436 cons_pages = KSEG_TO_PHYS(unix_boot_mem) / 8192;
437
438 /* Set up the page tables */
439 bzero((char *)first, 8192);
440 bzero((char *)second, 8192);
441 bzero((char *)reservedFixup,8192);
442 bzero((char *)third_rpb, HWRPB_PAGES * 8192);
443 bzero((char *)third_kernel, 8192 * NUM_KERNEL_THIRD);
444
445 first[0] = KPTE(PFN(second));
446 first[1] = KPTE(PFN(first)); /* Region 3 */
447
448 second[SECOND(0x10000000)] = KPTE(PFN(third_rpb)); /* Region 0 */
449 for (i=0;i<NUM_KERNEL_THIRD;i++) {
450 second[SECOND(0x20000000)+i] = KPTE(PFN(third_kernel)+i); /* Region 1 */
451 }
452 second[SECOND(0x40000000)] = KPTE(PFN(second)); /* Region 2 */
453
454
455 {
456
457 /* For some obscure reason, Dec Unix's database read
458 * from /etc/sysconfigtab is written to this fixed
459 * mapped memory location. Go figure, since it is
460 * not initialized by the console. Maybe it is
461 * to look at the database from the console
462 * after a boot/crash.
463 *
464 * Black magic to estimate the max size. SEGVs on overflow
465 * bugnion
466 */
467
468#define DATABASE_BASE 0x20000000
469#ifdef not_not
470#define DATABASE_END 0x20230000 /* don't need all that */
471#endif
472
473#define DATABASE_END 0x20020000
474
475 int i;
476 ul *dbPage = (ul*)unix_boot_alloc(1);
477 second[SECOND(DATABASE_BASE)] = KPTE(PFN(dbPage));
478 for (i=DATABASE_BASE; i <DATABASE_END ; i+= 8096) {
479 ul *db = (ul*)unix_boot_alloc(1);
480 dbPage[THIRD(i)] = KPTE(PFN(db));
481 }
482 }
483
484 /* Region 0 */
485 /* Map the HWRPB */
486 for (i = 0; i < HWRPB_PAGES; i++) third_rpb[i] = KPTE(PFN(rpb) + i);
487
488 /* Map the MDT bitmap table */
489 for (i=0;i<MDT_BITMAP_PAGES;i++) {
490 third_rpb[HWRPB_PAGES+i] = KPTE(PFN(mdt_bitmap)+i);
491 }
492
493 /* Protect the PAL pages */
494 for (i = 1; i < PFN(first); i++) third_rpb[HWRPB_PAGES + MDT_BITMAP_PAGES + i] = KPTE(i);
495
496 /* Set up third_kernel after it's loaded, when we know where it is */
497
498#ifdef original__xxm
499 if (unixLoadKernel(AOUT_LOAD_ADDR, argv[1]) == -1) return;
500 aoutfixup(AOUT_LOAD_ADDR);
501#else
502 /* aoutfixup(simosConf.kernelFileHdr); */
503#endif
504#if 0
505 bss = aout_bss_addr;
506
507 kern_first_page = (KSEG_TO_PHYS(aout_text_start) / 8192);
508 kernel_end = ksp_top = ROUNDUP8K(aout_bss_addr + aout_bss_size);
509 bootadr = aout_entry;
510#endif
511
512 kern_first_page = (KSEG_TO_PHYS(simosConf.kernStart)/8192);
513 kernel_end = ksp_top = ROUNDUP8K(simosConf.kernEnd);
514 bootadr = simosConf.entryPoint;
515
516
517 printf("HWRPB 0x%x l1pt 0x%x l2pt 0x%x l3pt_rpb 0x%x l3pt_kernel 0x%x l2reserv 0x%x\n",
518 rpb, first, second, third_rpb, third_kernel,reservedFixup);
519 if (kernel_end - simosConf.kernStart > (0x800000*NUM_KERNEL_THIRD)) {
520 printf("Kernel is more than 8MB 0x%x - 0x%x = 0x%x\n",
521 kernel_end, simosConf.kernStart,
522 kernel_end -simosConf.kernStart );
523 panic("kernel too big\n");
524
525 }
526 /* Map the kernel's pages into the third level of region 2 */
527
528 for (ptr = simosConf.kernStart; ptr < kernel_end; ptr += 8192) {
529
530 third_kernel[THIRD_XXX(ptr)] = KPTE(PFN(ptr));
531 }
532 /* blow 2 pages of phys mem for guards since it maintains 1-to-1 mapping */
533 ksp = ksp_top + (3 * 8192);
534 if (ksp - simosConf.kernStart > (0x800000*NUM_KERNEL_THIRD)) {
535 printf("Kernel stack pushd us over 8MB\n");
536 panic("ksp too big\n");
537 }
538 if (THIRD_XXX((ul)ksp_top) > NUM_KERNEL_THIRD * 1024) {
539 panic("increase NUM_KERNEL_THIRD, and change THIRD_XXX\n");
540 }
541 ptr = (ul) ksp_top;
542 bzero((char *)ptr, 8192 * 2);
543 third_kernel[THIRD_XXX(ptr)] = 0; /* Stack Guard Page */
544 ptr += 8192;
545 third_kernel[THIRD_XXX(ptr)] = KPTE(PFN(ptr)); /* Kernel Stack Pages */
546 ptr += 8192;
547 third_kernel[THIRD_XXX(ptr)] = KPTE(PFN(ptr));
548 ptr += 8192;
549 third_kernel[THIRD_XXX(ptr)] = 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 */
554 ksp -= 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
566 free_pfn = PFN(ptr);
567
568 bcopy((char *)&xxm_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 = (ul *) (((char *) rpb) + ROUNDUP8(sizeof(struct rpb)));
574 rpb->rpb_trans_off = (ul)tbb - (ul)rpb;
575 bcopy((char *)xxm_tbb, (char *)tbb, sizeof(xxm_tbb));
576
577
578 /*
579 * rpb_counter. Use to determine timeouts in OS.
580 * XXX must be patched after a checkpoint restore (I guess)
581 */
582
583 printf("CPU Clock at %d MHz IntrClockFrequency=%d \n", simosConf.cpuClock,simosConf.intrClockFrequency);
584 rpb->rpb_counter = simosConf.cpuClock * 1000 * 1000;
585
586 /*
587 * By definition, the rpb_clock is scaled by 4096 (in hz)
588 */
589 rpb->rpb_clock = simosConf.intrClockFrequency * 4096;
590
591
592
593 /*
594 * Per CPU Slots. Multiprocessor support.
595 */
596 {
597 int i;
598 int size = ROUNDUP128(sizeof(struct rpb_percpu));
599
600 printf("Booting with %d processor(s) \n",simosConf.numCPUs);
601
602 rpb->rpb_numprocs = simosConf.numCPUs;
603 rpb->rpb_slotsize = size;
604 rpb_percpu = (struct rpb_percpu *)
605 ROUNDUP128(((ul) tbb) +(sizeof(xxm_tbb)));
606
607 rpb->rpb_percpu_off = (ul)rpb_percpu - (ul)rpb;
608
609 for (i=0;i<simosConf.numCPUs;i++) {
610 struct rpb_percpu *thisCPU = (struct rpb_percpu*)
611 ((ul)rpb_percpu + size*i);
612
613 bzero((char *)thisCPU, size);
614 bcopy((char *)&xxm_rpb_percpu,
615 (char *)thisCPU,
616 sizeof(struct rpb_percpu));
617
618 thisCPU->rpb_pcb.rpb_ksp = ksp;
619 thisCPU->rpb_pcb.rpb_ptbr = PFN(first);
620
621 thisCPU->rpb_logout = KSEG_TO_PHYS(percpu_logout);
622 thisCPU->rpb_logout_len = 8192;
623
624/* thisCPU->rpb_pcb.rpb_ptbr = PFN(second);*/
625
626 printf("KSP: 0x%x PTBR 0x%x\n", thisCPU->rpb_pcb.rpb_ksp, thisCPU->rpb_pcb.rpb_ptbr);
627
628 if (i) {
629 bootStrapImpure[i] = (ul)unix_boot_alloc(1);
630 }
631
632 }
633
634 nextPtr = (ul)rpb_percpu + size*simosConf.numCPUs;
635 }
636
637 /*
638 * Console Terminal Block
639 */
640
641
642 rpb_ctb = (struct rpb_ctb *) nextPtr;
643 ctb_tt = (struct ctb_tt*) rpb_ctb;
644
645 rpb->rpb_ctb_off = ((ul)rpb_ctb) - (ul)rpb;
646 rpb->rpb_ctb_size = sizeof(struct rpb_ctb);
647
648 bzero((char *)rpb_ctb, sizeof(struct ctb_tt));
649
650#ifdef original_xxm
651 if (tga_slot == -1)
652 rpb_ctb->rpb_type = CONS_DZ;
653 else {
654 rpb_ctb->rpb_type = CONS_GRPH;
655 rpb_ctb->rpb_unit = (SLOTINFO_PCI << 16) | (0 << 8) | tga_slot;
656 }
657#else
658 rpb_ctb->rpb_type = CONS_DZ;
659#endif
660
661 rpb_ctb->rpb_length = sizeof(ctb_tt)-sizeof(rpb_ctb);
662
663 /*
664 * uart initizliation
665 */
666 ctb_tt->ctb_csr = 0;
667 ctb_tt->ctb_tivec = 0x6c0; /* matches tlaser pal code */
668 ctb_tt->ctb_rivec = 0x680; /* matches tlaser pal code */
669 ctb_tt->ctb_baud = 9600;
670 ctb_tt->ctb_put_sts = 0;
671 ctb_tt->ctb_get_sts = 0;
672
673
674 rpb_crb = (struct rpb_crb *) (((ul)rpb_ctb) + sizeof(struct ctb_tt));
675 rpb->rpb_crb_off = ((ul)rpb_crb) - (ul)rpb;
676
677 bzero((char *)rpb_crb, sizeof(struct rpb_crb));
678 /*
679 * console callback stuff (simos)
680 */
681
682 rpb_crb->rpb_num = 1;
683 rpb_crb->rpb_mapped_pages = HWRPB_PAGES;
684 rpb_crb->rpb_map[0].rpb_virt = 0x10000000;
685 rpb_crb->rpb_map[0].rpb_phys = ((ul)rpb) & ~0x1fff;
686 rpb_crb->rpb_map[0].rpb_pgcount = HWRPB_PAGES;
687
688
689 printf("Console Callback at 0x%x, fixup at 0x%x \n",
690 rpb_crb->rpb_va_disp,
691 rpb_crb->rpb_va_fixup );
692
693 rpb_mdt = (struct _xxm_rpb_mdt *) (((ul)rpb_crb) + sizeof(struct rpb_crb));
694 rpb->rpb_mdt_off = (ul)rpb_mdt - (ul)rpb;
695 bcopy((char *)&xxm_rpb_mdt, (char *)rpb_mdt, sizeof(struct _xxm_rpb_mdt));
696
697
698 cl = 0;
699#ifdef undef
700 /* Until Digital Unix can handle it, account all pages below the kernel
701 * as "console" memory. */
702 rpb_mdt->rpb_cluster[cl].rpb_pfncount = cons_pages;
703#endif
704 rpb_mdt->rpb_cluster[cl].rpb_pfncount = kern_first_page;
705 cl++;
706
707 rpb_mdt->rpb_cluster[cl].rpb_pfn = kern_first_page;
708 rpb_mdt->rpb_cluster[cl].rpb_pfncount = mem_pages - kern_first_page;
709 rpb_mdt->rpb_cluster[cl].rpb_pfntested=rpb_mdt->rpb_cluster[cl].rpb_pfncount;
710 rpb_mdt->rpb_cluster[cl].rpb_pa = KSEG_TO_PHYS(mdt_bitmap);
711 rpb_mdt->rpb_cluster[cl].rpb_va = 0x10000000 + HWRPB_PAGES * 8192;
712 cl++;
713
714#ifdef undef
715 /* The stupid Unix kernel needs to have all mdt clusters in ascending
716 * order, and the last cluster is used to compute the top of memory.
717 * It can't make use of memory between the console and the kernel.
718 */
719 rpb_mdt->rpb_cluster[cl].rpb_pfn = cons_pages;
720 rpb_mdt->rpb_cluster[cl].rpb_pfncount = kern_first_page - cons_pages;
721 rpb_mdt->rpb_cluster[cl].rpb_pfntested=rpb_mdt->rpb_cluster[cl].rpb_pfncount;
722 rpb_mdt->rpb_cluster[cl].rpb_pa = KSEG_TO_PHYS(mdt_bitmap);
723 rpb_mdt->rpb_cluster[cl].rpb_va = 0x10000000 + HWRPB_PAGES * 8192;
724 cl++;
725#endif
726
727 rpb_mdt->rpb_numcl = cl;
728
729 for (i = 0; i < cl; i++)
730 printf("Memory cluster %d [%d - %d]\n", i, rpb_mdt->rpb_cluster[i].rpb_pfn, rpb_mdt->rpb_cluster[i].rpb_pfncount);
731
732
733
734 /* Checksum the rpb for good luck */
735 sum = 0;
736 lp1 = (long *)&rpb_mdt->rpb_impaddr;
737 lp2 = (long *)&rpb_mdt->rpb_cluster[cl];
738 while (lp1 < lp2) sum += *lp1++;
739 rpb_mdt->rpb_checksum = sum;
740
741 /* XXX should checksum the cluster descriptors */
742
743 bzero((char *)mdt_bitmap, MDT_BITMAP_PAGES * 8192);
744 for (i = 0; i < mem_pages/8; i++) ((unsigned char *)mdt_bitmap)[i] = 0xff;
745
746 printf("Initalizing mdt_bitmap addr 0x%x mem_pages %x \n",
747 (long)mdt_bitmap,(long)mem_pages);
748
749 xxm_rpb.rpb_config_off = 0;
750 xxm_rpb.rpb_fru_off = 0;
751
752 rpb_dsr = (struct rpb_dsr *) (((ul)rpb_mdt) + sizeof(struct _xxm_rpb_mdt));
753 rpb->rpb_dsr_off = ((ul)rpb_dsr) - (ul)rpb;
754 bzero((char *)rpb_dsr, sizeof(struct rpb_dsr));
755 rpb_dsr->rpb_smm = 1578; /* Official XXM SMM number as per SRM */
756 rpb_dsr->rpb_smm = 1089; /* Official Alcor SMM number as per SRM */
757
758 rpb_lurt = (int *) ROUNDUP8(((ul)rpb_dsr) + sizeof(struct rpb_dsr));
759 rpb_dsr->rpb_lurt_off = ((ul) rpb_lurt) - (ul) rpb_dsr;
760 bcopy((char *)xxm_lurt, (char *)rpb_lurt, sizeof(xxm_lurt));
761
762 rpb_name = (char *) ROUNDUP8(((ul)rpb_lurt) + sizeof(xxm_lurt));
763 rpb_dsr->rpb_sysname_off = ((ul) rpb_name) - (ul) rpb_dsr;
764#define THENAME " SimOS ALPHA/EV5"
765 sum = sizeof(THENAME);
766 bcopy(THENAME, rpb_name, sum);
767 *(ul *)rpb_name = sizeof(THENAME); /* put in length field */
768
769 /* calculate size of rpb */
770 rpb->rpb_size = ((ul) &rpb_name[sum]) - (ul)rpb;
771
772 if (rpb->rpb_size > 8192*HWRPB_PAGES) {
773 panic("HWRPB_PAGES=%d too small for HWRPB !!! \n");
774 }
775
776
777 {
778 ul *ptr = (ul*)((char*)rpb_dsr + sizeof(struct rpb_dsr ));
779 rpb_crb->rpb_pa_disp = KSEG_TO_PHYS(ptr);
386struct rpb *rpb;
387
388unixBoot(int go, int argc, char **argv)
389{
390 ul *second, *third_kernel, ptr, *tbb, size, *percpu_logout;
391 unsigned char *mdt_bitmap;
392 long *lp1, *lp2, sum;
393 int i, cl;
394 int kern_first_page;
395 int mem_size = simosConf.mem_size;
396
397 int mem_pages = mem_size / 8192, cons_pages;
398 ul kernel_bytes, ksp, kernel_end, *unix_kernel_stack, bss, ksp_bottom, ksp_top;
399 struct rpb_ctb *rpb_ctb;
400 struct ctb_tt *ctb_tt;
401 struct rpb_dsr *rpb_dsr;
402 struct rpb_crb *rpb_crb;
403 struct _xxm_rpb_mdt *rpb_mdt;
404 int *rpb_lurt;
405 char *rpb_name;
406 ul nextPtr;
407
408 printf( "memsize %x pages %x \n",mem_size,mem_pages);
409
410
411
412#ifdef notnow
413 if (unixArgs()) return;
414#endif
415
416 /* Allocate:
417 * two pages for the HWRPB
418 * five page table pages:
419 * 1: First level page table
420 * 1: Second level page table
421 * 1: Third level page table for HWRPB
422 * 2: Third level page table for kernel (for up to 16MB)
423 * set up the page tables
424 * load the kernel at the physical address 0x230000
425 * build the HWRPB
426 * set up memory descriptor table to give up the
427 * physical memory between the end of the page
428 * tables and the start of the kernel
429 * enable kseg addressing
430 * jump to the kernel
431 */
432
433 unix_boot_mem = ROUNDUP8K(&_end);
434
435 printf("First free page after ROM 0x%x\n", unix_boot_mem);
436
437 rpb = (struct rpb *) unix_boot_alloc( HWRPB_PAGES);
438
439 mdt_bitmap = (unsigned char *) unix_boot_alloc(MDT_BITMAP_PAGES);
440 first = (ul *)unix_boot_alloc(1);
441 second = (ul *)unix_boot_alloc(1);
442 third_rpb = (ul *)unix_boot_alloc(1);
443 reservedFixup = (ul*) unix_boot_alloc(1);
444 third_kernel = (ul *)unix_boot_alloc(NUM_KERNEL_THIRD);
445 percpu_logout = (ul*)unix_boot_alloc(1);
446
447
448 cons_pages = KSEG_TO_PHYS(unix_boot_mem) / 8192;
449
450 /* Set up the page tables */
451 bzero((char *)first, 8192);
452 bzero((char *)second, 8192);
453 bzero((char *)reservedFixup,8192);
454 bzero((char *)third_rpb, HWRPB_PAGES * 8192);
455 bzero((char *)third_kernel, 8192 * NUM_KERNEL_THIRD);
456
457 first[0] = KPTE(PFN(second));
458 first[1] = KPTE(PFN(first)); /* Region 3 */
459
460 second[SECOND(0x10000000)] = KPTE(PFN(third_rpb)); /* Region 0 */
461 for (i=0;i<NUM_KERNEL_THIRD;i++) {
462 second[SECOND(0x20000000)+i] = KPTE(PFN(third_kernel)+i); /* Region 1 */
463 }
464 second[SECOND(0x40000000)] = KPTE(PFN(second)); /* Region 2 */
465
466
467 {
468
469 /* For some obscure reason, Dec Unix's database read
470 * from /etc/sysconfigtab is written to this fixed
471 * mapped memory location. Go figure, since it is
472 * not initialized by the console. Maybe it is
473 * to look at the database from the console
474 * after a boot/crash.
475 *
476 * Black magic to estimate the max size. SEGVs on overflow
477 * bugnion
478 */
479
480#define DATABASE_BASE 0x20000000
481#ifdef not_not
482#define DATABASE_END 0x20230000 /* don't need all that */
483#endif
484
485#define DATABASE_END 0x20020000
486
487 int i;
488 ul *dbPage = (ul*)unix_boot_alloc(1);
489 second[SECOND(DATABASE_BASE)] = KPTE(PFN(dbPage));
490 for (i=DATABASE_BASE; i <DATABASE_END ; i+= 8096) {
491 ul *db = (ul*)unix_boot_alloc(1);
492 dbPage[THIRD(i)] = KPTE(PFN(db));
493 }
494 }
495
496 /* Region 0 */
497 /* Map the HWRPB */
498 for (i = 0; i < HWRPB_PAGES; i++) third_rpb[i] = KPTE(PFN(rpb) + i);
499
500 /* Map the MDT bitmap table */
501 for (i=0;i<MDT_BITMAP_PAGES;i++) {
502 third_rpb[HWRPB_PAGES+i] = KPTE(PFN(mdt_bitmap)+i);
503 }
504
505 /* Protect the PAL pages */
506 for (i = 1; i < PFN(first); i++) third_rpb[HWRPB_PAGES + MDT_BITMAP_PAGES + i] = KPTE(i);
507
508 /* Set up third_kernel after it's loaded, when we know where it is */
509
510#ifdef original__xxm
511 if (unixLoadKernel(AOUT_LOAD_ADDR, argv[1]) == -1) return;
512 aoutfixup(AOUT_LOAD_ADDR);
513#else
514 /* aoutfixup(simosConf.kernelFileHdr); */
515#endif
516#if 0
517 bss = aout_bss_addr;
518
519 kern_first_page = (KSEG_TO_PHYS(aout_text_start) / 8192);
520 kernel_end = ksp_top = ROUNDUP8K(aout_bss_addr + aout_bss_size);
521 bootadr = aout_entry;
522#endif
523
524 kern_first_page = (KSEG_TO_PHYS(simosConf.kernStart)/8192);
525 kernel_end = ksp_top = ROUNDUP8K(simosConf.kernEnd);
526 bootadr = simosConf.entryPoint;
527
528
529 printf("HWRPB 0x%x l1pt 0x%x l2pt 0x%x l3pt_rpb 0x%x l3pt_kernel 0x%x l2reserv 0x%x\n",
530 rpb, first, second, third_rpb, third_kernel,reservedFixup);
531 if (kernel_end - simosConf.kernStart > (0x800000*NUM_KERNEL_THIRD)) {
532 printf("Kernel is more than 8MB 0x%x - 0x%x = 0x%x\n",
533 kernel_end, simosConf.kernStart,
534 kernel_end -simosConf.kernStart );
535 panic("kernel too big\n");
536
537 }
538 /* Map the kernel's pages into the third level of region 2 */
539
540 for (ptr = simosConf.kernStart; ptr < kernel_end; ptr += 8192) {
541
542 third_kernel[THIRD_XXX(ptr)] = KPTE(PFN(ptr));
543 }
544 /* blow 2 pages of phys mem for guards since it maintains 1-to-1 mapping */
545 ksp = ksp_top + (3 * 8192);
546 if (ksp - simosConf.kernStart > (0x800000*NUM_KERNEL_THIRD)) {
547 printf("Kernel stack pushd us over 8MB\n");
548 panic("ksp too big\n");
549 }
550 if (THIRD_XXX((ul)ksp_top) > NUM_KERNEL_THIRD * 1024) {
551 panic("increase NUM_KERNEL_THIRD, and change THIRD_XXX\n");
552 }
553 ptr = (ul) ksp_top;
554 bzero((char *)ptr, 8192 * 2);
555 third_kernel[THIRD_XXX(ptr)] = 0; /* Stack Guard Page */
556 ptr += 8192;
557 third_kernel[THIRD_XXX(ptr)] = KPTE(PFN(ptr)); /* Kernel Stack Pages */
558 ptr += 8192;
559 third_kernel[THIRD_XXX(ptr)] = KPTE(PFN(ptr));
560 ptr += 8192;
561 third_kernel[THIRD_XXX(ptr)] = 0; /* Stack Guard Page */
562
563 /* put argv into the bottom of the stack - argv starts at 1 because
564 * the command thatr got us here (i.e. "unixboot) is in argv[0].
565 */
566 ksp -= 8; /* Back up one longword */
567 ksp -= argc * sizeof(char *); /* Make room for argv */
568 kargv = (char **) ksp;
569 for (i = 1; i < argc; i++) { /* Copy arguments to stack */
570 ksp -= ((strlen(argv[i]) + 1) + 7) & ~0x7;
571 kargv[i-1] = (char *) ksp;
572 strcpy(kargv[i-1], argv[i]);
573 }
574 kargc = i - 1;
575 kargv[kargc] = NULL; /* just to be sure; doesn't seem to be used */
576 ksp -= sizeof(char *); /* point above last arg for no real reason */
577
578 free_pfn = PFN(ptr);
579
580 bcopy((char *)&xxm_rpb, (char *)rpb, sizeof(struct rpb));
581
582 rpb->rpb_selfref = (struct rpb *) KSEG_TO_PHYS(rpb);
583 rpb->rpb_string = 0x0000004250525748;
584
585 tbb = (ul *) (((char *) rpb) + ROUNDUP8(sizeof(struct rpb)));
586 rpb->rpb_trans_off = (ul)tbb - (ul)rpb;
587 bcopy((char *)xxm_tbb, (char *)tbb, sizeof(xxm_tbb));
588
589
590 /*
591 * rpb_counter. Use to determine timeouts in OS.
592 * XXX must be patched after a checkpoint restore (I guess)
593 */
594
595 printf("CPU Clock at %d MHz IntrClockFrequency=%d \n", simosConf.cpuClock,simosConf.intrClockFrequency);
596 rpb->rpb_counter = simosConf.cpuClock * 1000 * 1000;
597
598 /*
599 * By definition, the rpb_clock is scaled by 4096 (in hz)
600 */
601 rpb->rpb_clock = simosConf.intrClockFrequency * 4096;
602
603
604
605 /*
606 * Per CPU Slots. Multiprocessor support.
607 */
608 {
609 int i;
610 int size = ROUNDUP128(sizeof(struct rpb_percpu));
611
612 printf("Booting with %d processor(s) \n",simosConf.numCPUs);
613
614 rpb->rpb_numprocs = simosConf.numCPUs;
615 rpb->rpb_slotsize = size;
616 rpb_percpu = (struct rpb_percpu *)
617 ROUNDUP128(((ul) tbb) +(sizeof(xxm_tbb)));
618
619 rpb->rpb_percpu_off = (ul)rpb_percpu - (ul)rpb;
620
621 for (i=0;i<simosConf.numCPUs;i++) {
622 struct rpb_percpu *thisCPU = (struct rpb_percpu*)
623 ((ul)rpb_percpu + size*i);
624
625 bzero((char *)thisCPU, size);
626 bcopy((char *)&xxm_rpb_percpu,
627 (char *)thisCPU,
628 sizeof(struct rpb_percpu));
629
630 thisCPU->rpb_pcb.rpb_ksp = ksp;
631 thisCPU->rpb_pcb.rpb_ptbr = PFN(first);
632
633 thisCPU->rpb_logout = KSEG_TO_PHYS(percpu_logout);
634 thisCPU->rpb_logout_len = 8192;
635
636/* thisCPU->rpb_pcb.rpb_ptbr = PFN(second);*/
637
638 printf("KSP: 0x%x PTBR 0x%x\n", thisCPU->rpb_pcb.rpb_ksp, thisCPU->rpb_pcb.rpb_ptbr);
639
640 if (i) {
641 bootStrapImpure[i] = (ul)unix_boot_alloc(1);
642 }
643
644 }
645
646 nextPtr = (ul)rpb_percpu + size*simosConf.numCPUs;
647 }
648
649 /*
650 * Console Terminal Block
651 */
652
653
654 rpb_ctb = (struct rpb_ctb *) nextPtr;
655 ctb_tt = (struct ctb_tt*) rpb_ctb;
656
657 rpb->rpb_ctb_off = ((ul)rpb_ctb) - (ul)rpb;
658 rpb->rpb_ctb_size = sizeof(struct rpb_ctb);
659
660 bzero((char *)rpb_ctb, sizeof(struct ctb_tt));
661
662#ifdef original_xxm
663 if (tga_slot == -1)
664 rpb_ctb->rpb_type = CONS_DZ;
665 else {
666 rpb_ctb->rpb_type = CONS_GRPH;
667 rpb_ctb->rpb_unit = (SLOTINFO_PCI << 16) | (0 << 8) | tga_slot;
668 }
669#else
670 rpb_ctb->rpb_type = CONS_DZ;
671#endif
672
673 rpb_ctb->rpb_length = sizeof(ctb_tt)-sizeof(rpb_ctb);
674
675 /*
676 * uart initizliation
677 */
678 ctb_tt->ctb_csr = 0;
679 ctb_tt->ctb_tivec = 0x6c0; /* matches tlaser pal code */
680 ctb_tt->ctb_rivec = 0x680; /* matches tlaser pal code */
681 ctb_tt->ctb_baud = 9600;
682 ctb_tt->ctb_put_sts = 0;
683 ctb_tt->ctb_get_sts = 0;
684
685
686 rpb_crb = (struct rpb_crb *) (((ul)rpb_ctb) + sizeof(struct ctb_tt));
687 rpb->rpb_crb_off = ((ul)rpb_crb) - (ul)rpb;
688
689 bzero((char *)rpb_crb, sizeof(struct rpb_crb));
690 /*
691 * console callback stuff (simos)
692 */
693
694 rpb_crb->rpb_num = 1;
695 rpb_crb->rpb_mapped_pages = HWRPB_PAGES;
696 rpb_crb->rpb_map[0].rpb_virt = 0x10000000;
697 rpb_crb->rpb_map[0].rpb_phys = ((ul)rpb) & ~0x1fff;
698 rpb_crb->rpb_map[0].rpb_pgcount = HWRPB_PAGES;
699
700
701 printf("Console Callback at 0x%x, fixup at 0x%x \n",
702 rpb_crb->rpb_va_disp,
703 rpb_crb->rpb_va_fixup );
704
705 rpb_mdt = (struct _xxm_rpb_mdt *) (((ul)rpb_crb) + sizeof(struct rpb_crb));
706 rpb->rpb_mdt_off = (ul)rpb_mdt - (ul)rpb;
707 bcopy((char *)&xxm_rpb_mdt, (char *)rpb_mdt, sizeof(struct _xxm_rpb_mdt));
708
709
710 cl = 0;
711#ifdef undef
712 /* Until Digital Unix can handle it, account all pages below the kernel
713 * as "console" memory. */
714 rpb_mdt->rpb_cluster[cl].rpb_pfncount = cons_pages;
715#endif
716 rpb_mdt->rpb_cluster[cl].rpb_pfncount = kern_first_page;
717 cl++;
718
719 rpb_mdt->rpb_cluster[cl].rpb_pfn = kern_first_page;
720 rpb_mdt->rpb_cluster[cl].rpb_pfncount = mem_pages - kern_first_page;
721 rpb_mdt->rpb_cluster[cl].rpb_pfntested=rpb_mdt->rpb_cluster[cl].rpb_pfncount;
722 rpb_mdt->rpb_cluster[cl].rpb_pa = KSEG_TO_PHYS(mdt_bitmap);
723 rpb_mdt->rpb_cluster[cl].rpb_va = 0x10000000 + HWRPB_PAGES * 8192;
724 cl++;
725
726#ifdef undef
727 /* The stupid Unix kernel needs to have all mdt clusters in ascending
728 * order, and the last cluster is used to compute the top of memory.
729 * It can't make use of memory between the console and the kernel.
730 */
731 rpb_mdt->rpb_cluster[cl].rpb_pfn = cons_pages;
732 rpb_mdt->rpb_cluster[cl].rpb_pfncount = kern_first_page - cons_pages;
733 rpb_mdt->rpb_cluster[cl].rpb_pfntested=rpb_mdt->rpb_cluster[cl].rpb_pfncount;
734 rpb_mdt->rpb_cluster[cl].rpb_pa = KSEG_TO_PHYS(mdt_bitmap);
735 rpb_mdt->rpb_cluster[cl].rpb_va = 0x10000000 + HWRPB_PAGES * 8192;
736 cl++;
737#endif
738
739 rpb_mdt->rpb_numcl = cl;
740
741 for (i = 0; i < cl; i++)
742 printf("Memory cluster %d [%d - %d]\n", i, rpb_mdt->rpb_cluster[i].rpb_pfn, rpb_mdt->rpb_cluster[i].rpb_pfncount);
743
744
745
746 /* Checksum the rpb for good luck */
747 sum = 0;
748 lp1 = (long *)&rpb_mdt->rpb_impaddr;
749 lp2 = (long *)&rpb_mdt->rpb_cluster[cl];
750 while (lp1 < lp2) sum += *lp1++;
751 rpb_mdt->rpb_checksum = sum;
752
753 /* XXX should checksum the cluster descriptors */
754
755 bzero((char *)mdt_bitmap, MDT_BITMAP_PAGES * 8192);
756 for (i = 0; i < mem_pages/8; i++) ((unsigned char *)mdt_bitmap)[i] = 0xff;
757
758 printf("Initalizing mdt_bitmap addr 0x%x mem_pages %x \n",
759 (long)mdt_bitmap,(long)mem_pages);
760
761 xxm_rpb.rpb_config_off = 0;
762 xxm_rpb.rpb_fru_off = 0;
763
764 rpb_dsr = (struct rpb_dsr *) (((ul)rpb_mdt) + sizeof(struct _xxm_rpb_mdt));
765 rpb->rpb_dsr_off = ((ul)rpb_dsr) - (ul)rpb;
766 bzero((char *)rpb_dsr, sizeof(struct rpb_dsr));
767 rpb_dsr->rpb_smm = 1578; /* Official XXM SMM number as per SRM */
768 rpb_dsr->rpb_smm = 1089; /* Official Alcor SMM number as per SRM */
769
770 rpb_lurt = (int *) ROUNDUP8(((ul)rpb_dsr) + sizeof(struct rpb_dsr));
771 rpb_dsr->rpb_lurt_off = ((ul) rpb_lurt) - (ul) rpb_dsr;
772 bcopy((char *)xxm_lurt, (char *)rpb_lurt, sizeof(xxm_lurt));
773
774 rpb_name = (char *) ROUNDUP8(((ul)rpb_lurt) + sizeof(xxm_lurt));
775 rpb_dsr->rpb_sysname_off = ((ul) rpb_name) - (ul) rpb_dsr;
776#define THENAME " SimOS ALPHA/EV5"
777 sum = sizeof(THENAME);
778 bcopy(THENAME, rpb_name, sum);
779 *(ul *)rpb_name = sizeof(THENAME); /* put in length field */
780
781 /* calculate size of rpb */
782 rpb->rpb_size = ((ul) &rpb_name[sum]) - (ul)rpb;
783
784 if (rpb->rpb_size > 8192*HWRPB_PAGES) {
785 panic("HWRPB_PAGES=%d too small for HWRPB !!! \n");
786 }
787
788
789 {
790 ul *ptr = (ul*)((char*)rpb_dsr + sizeof(struct rpb_dsr ));
791 rpb_crb->rpb_pa_disp = KSEG_TO_PHYS(ptr);
792#if 0
780 rpb_crb->rpb_va_disp = 0x10000000 + ((ul)ptr&(0x2000*HWRPB_PAGES-1));
793 rpb_crb->rpb_va_disp = 0x10000000 + ((ul)ptr&(0x2000*HWRPB_PAGES-1));
794#else
795 rpb_crb->rpb_va_disp = 0x10000000 + ((ul)ptr & 0x1fff);
796#endif
781 printf("ConsoleDispatch at virt %x phys %x val %x\n",
782 rpb_crb->rpb_va_disp,
783 rpb_crb->rpb_pa_disp,
784 consoleCallback);
785 *ptr++ = 0;
786 *ptr++ = (ul) consoleCallback;
787 rpb_crb->rpb_pa_fixup = KSEG_TO_PHYS(ptr);
797 printf("ConsoleDispatch at virt %x phys %x val %x\n",
798 rpb_crb->rpb_va_disp,
799 rpb_crb->rpb_pa_disp,
800 consoleCallback);
801 *ptr++ = 0;
802 *ptr++ = (ul) consoleCallback;
803 rpb_crb->rpb_pa_fixup = KSEG_TO_PHYS(ptr);
804#if 0
788 rpb_crb->rpb_va_fixup = 0x10000000 + ((ul)ptr& (0x2000*HWRPB_PAGES-1));
805 rpb_crb->rpb_va_fixup = 0x10000000 + ((ul)ptr& (0x2000*HWRPB_PAGES-1));
806#else
807 rpb_crb->rpb_va_fixup = 0x10000000 + ((ul)ptr & 0x1fff);
808#endif
789 *ptr++ = 0;
790 *ptr++ = (ul) consoleFixup;
791 }
792
793
794 /* Checksum the rpb for good luck */
795 sum = 0;
796 lp1 = (long *)rpb;
797 lp2 = &rpb->rpb_checksum;
798 while (lp1 < lp2)
799 sum += *lp1++;
800 *lp2 = sum;
801
802
803 /*
804 * MP bootstrap
805 */
806
807 {
808 int i;
809 for (i=1;i<simosConf.numCPUs;i++) {
809 *ptr++ = 0;
810 *ptr++ = (ul) consoleFixup;
811 }
812
813
814 /* Checksum the rpb for good luck */
815 sum = 0;
816 lp1 = (long *)rpb;
817 lp2 = &rpb->rpb_checksum;
818 while (lp1 < lp2)
819 sum += *lp1++;
820 *lp2 = sum;
821
822
823 /*
824 * MP bootstrap
825 */
826
827 {
828 int i;
829 for (i=1;i<simosConf.numCPUs;i++) {
810 volatile AlphaAccess *k1Conf = (volatile AlphaAccess *)
830 volatile struct AlphaAccess *k1Conf = (volatile struct AlphaAccess *)
811 (__MAGIC_ZONE(0, 0, MAGIC_ZONE_EV5_ALIAS));
812 SpinLock(&theLock);
813 printf("Bootstraping CPU %d with sp=0x%x \n",
814 i,bootStrapImpure[i]);
815 SpinUnlock(&theLock);
816 k1Conf->bootStrapImpure = bootStrapImpure[i];
817 k1Conf->bootStrapCPU = i;
818 }
819 }
820
821 /*
822 * Make sure that we are not stepping on the kernel
823 */
824 if ((ul)unix_boot_mem >= (ul)simosConf.kernStart) {
825 panic("CONSOLE: too much memory. Smashing kernel \n");
826 } else {
827 SpinLock(&theLock);
828 printf("unix_boot_mem ends at %x \n",unix_boot_mem);
829 SpinUnlock(&theLock);
830 }
831
832
833#ifdef undef
834#define CSERVE_K_JTOKERN 0x18
835 cServe(bootadr, (ul) rpb_percpu, CSERVE_K_JTOKERN, free_pfn);
836#endif
837
838 if (go) JToKern(bootadr, rpb_percpu, free_pfn, kargc, kargv, NULL);
839}
840
841
842#if 0
843aoutfixup(char *p)
844{
845 int i;
846 unsigned long rem, len, off, dst;
847
848
849 struct new_aouthdr *ao = (struct new_aouthdr *) &p[NEW_FILHSZ];
850#if 0
851 struct scnhdr *s = (struct scnhdr *) &p[FILHSZ + AOUTHSZ];
852 struct scnhdr *t, *d, *b;
853 printf("aoutfixup: %d sections \n",fh->f_nscns);
854#endif
855
856
857 aout_text_start = ((ul)ao->text_start_hi<<32) + ao->text_start;
858 aout_data_addr = ((ul)ao->data_start_hi<<32) + ao->data_start;
859 aout_bss_addr = ((ul)ao->bss_start_hi<<32) + ao->bss_start;
860 aout_bss_size = ((ul)ao->bsize_hi<<32) + ao->bsize;
861 aout_entry = ((ul)ao->entry_hi<<32) + ao->entry;
862
863 printf("_text 0x%16x %8d @ %08d\n", aout_text_start, ao->tsize,0 /* t->s_scnptr*/);
864 printf("_data 0x%16x %8d @ %08d\n", aout_data_addr, ao->dsize,0/* d->s_scnptr*/);
865 printf("_bss 0x%16x %8d\n", aout_bss_addr, ao->bsize);
866 printf("entry 0x%16x\n", aout_entry);
867#if 0
868 for (i = 0; i < fh->f_nscns; i++) {
869 printf("section %d %s \n",i,s[i].s_name);
870 if (!strcmp(s[i].s_name, ".text")) t = &s[i];
871 else if (!strcmp(s[i].s_name, ".data")) d = &s[i];
872 else if (!strcmp(s[i].s_name, ".bss")) b = &s[i];
873 }
874 bcopy(&p[t->s_scnptr], (char *)ao->text_start, ao->tsize);
875 bcopy(&p[d->s_scnptr], (char *)ao->data_start, ao->dsize);
876#endif
877}
878#endif
879
880extern ui palJToKern[];
881
882JToKern(bootadr, rpb_percpu, free_pfn, k_argc, k_argv, envp)
883char * bootadr;
884ul rpb_percpu;
885ul free_pfn;
886ul k_argc;
887char **k_argv;
888char **envp;
889{
890 struct _kernel_params *kernel_params = (struct _kernel_params *) KSEG;
891 int i;
892
893 printf("k_argc = %d ", k_argc);
894 for (i = 0; i < k_argc; i++) {
895 printf("'%s' ", k_argv[i]);
896 }
897 printf("\n");
898
899/* rpb_percpu |= 0xfffffc0000000000;*/
900 kernel_params->bootadr = bootadr;
901 kernel_params->rpb_percpu = KSEG_TO_PHYS(rpb_percpu);
902 kernel_params->free_pfn = free_pfn;
903 kernel_params->argc = k_argc;
904 kernel_params->argv = (ul)k_argv;
905 kernel_params->envp = (ul)envp;
906 printf("jumping to kernel at 0x%x, (PCBB 0x%x pfn %d)\n", bootadr, rpb_percpu, free_pfn);
907 jToPal(KSEG_TO_PHYS((ul)palJToKern));
908 printf("returned from jToPal. Looping\n");
909 while(1) continue;
910}
911
912
913void jToPal(ul bootadr)
914{
915 cServe(bootadr, 0, CSERVE_K_JTOPAL);
916
917/*
918 * Make sure that floating point is enabled incase
919 * it was disabled by the user program.
920 */
921 wrfen(1);
922}
923
924
925int strcpy(char *dst, char *src)
926{
927 int i=0;
928 while(*src) {
929 *dst++ = *src++;
930 i++;
931 }
932 return i;
933}
934
935
936
937
938/* *****************************************
939 * Console I/O
940 * ******************************************/
941
942int numOpenDevices = 11;
943struct {
944 char name[128];
945} deviceState[32];
946
831 (__MAGIC_ZONE(0, 0, MAGIC_ZONE_EV5_ALIAS));
832 SpinLock(&theLock);
833 printf("Bootstraping CPU %d with sp=0x%x \n",
834 i,bootStrapImpure[i]);
835 SpinUnlock(&theLock);
836 k1Conf->bootStrapImpure = bootStrapImpure[i];
837 k1Conf->bootStrapCPU = i;
838 }
839 }
840
841 /*
842 * Make sure that we are not stepping on the kernel
843 */
844 if ((ul)unix_boot_mem >= (ul)simosConf.kernStart) {
845 panic("CONSOLE: too much memory. Smashing kernel \n");
846 } else {
847 SpinLock(&theLock);
848 printf("unix_boot_mem ends at %x \n",unix_boot_mem);
849 SpinUnlock(&theLock);
850 }
851
852
853#ifdef undef
854#define CSERVE_K_JTOKERN 0x18
855 cServe(bootadr, (ul) rpb_percpu, CSERVE_K_JTOKERN, free_pfn);
856#endif
857
858 if (go) JToKern(bootadr, rpb_percpu, free_pfn, kargc, kargv, NULL);
859}
860
861
862#if 0
863aoutfixup(char *p)
864{
865 int i;
866 unsigned long rem, len, off, dst;
867
868
869 struct new_aouthdr *ao = (struct new_aouthdr *) &p[NEW_FILHSZ];
870#if 0
871 struct scnhdr *s = (struct scnhdr *) &p[FILHSZ + AOUTHSZ];
872 struct scnhdr *t, *d, *b;
873 printf("aoutfixup: %d sections \n",fh->f_nscns);
874#endif
875
876
877 aout_text_start = ((ul)ao->text_start_hi<<32) + ao->text_start;
878 aout_data_addr = ((ul)ao->data_start_hi<<32) + ao->data_start;
879 aout_bss_addr = ((ul)ao->bss_start_hi<<32) + ao->bss_start;
880 aout_bss_size = ((ul)ao->bsize_hi<<32) + ao->bsize;
881 aout_entry = ((ul)ao->entry_hi<<32) + ao->entry;
882
883 printf("_text 0x%16x %8d @ %08d\n", aout_text_start, ao->tsize,0 /* t->s_scnptr*/);
884 printf("_data 0x%16x %8d @ %08d\n", aout_data_addr, ao->dsize,0/* d->s_scnptr*/);
885 printf("_bss 0x%16x %8d\n", aout_bss_addr, ao->bsize);
886 printf("entry 0x%16x\n", aout_entry);
887#if 0
888 for (i = 0; i < fh->f_nscns; i++) {
889 printf("section %d %s \n",i,s[i].s_name);
890 if (!strcmp(s[i].s_name, ".text")) t = &s[i];
891 else if (!strcmp(s[i].s_name, ".data")) d = &s[i];
892 else if (!strcmp(s[i].s_name, ".bss")) b = &s[i];
893 }
894 bcopy(&p[t->s_scnptr], (char *)ao->text_start, ao->tsize);
895 bcopy(&p[d->s_scnptr], (char *)ao->data_start, ao->dsize);
896#endif
897}
898#endif
899
900extern ui palJToKern[];
901
902JToKern(bootadr, rpb_percpu, free_pfn, k_argc, k_argv, envp)
903char * bootadr;
904ul rpb_percpu;
905ul free_pfn;
906ul k_argc;
907char **k_argv;
908char **envp;
909{
910 struct _kernel_params *kernel_params = (struct _kernel_params *) KSEG;
911 int i;
912
913 printf("k_argc = %d ", k_argc);
914 for (i = 0; i < k_argc; i++) {
915 printf("'%s' ", k_argv[i]);
916 }
917 printf("\n");
918
919/* rpb_percpu |= 0xfffffc0000000000;*/
920 kernel_params->bootadr = bootadr;
921 kernel_params->rpb_percpu = KSEG_TO_PHYS(rpb_percpu);
922 kernel_params->free_pfn = free_pfn;
923 kernel_params->argc = k_argc;
924 kernel_params->argv = (ul)k_argv;
925 kernel_params->envp = (ul)envp;
926 printf("jumping to kernel at 0x%x, (PCBB 0x%x pfn %d)\n", bootadr, rpb_percpu, free_pfn);
927 jToPal(KSEG_TO_PHYS((ul)palJToKern));
928 printf("returned from jToPal. Looping\n");
929 while(1) continue;
930}
931
932
933void jToPal(ul bootadr)
934{
935 cServe(bootadr, 0, CSERVE_K_JTOPAL);
936
937/*
938 * Make sure that floating point is enabled incase
939 * it was disabled by the user program.
940 */
941 wrfen(1);
942}
943
944
945int strcpy(char *dst, char *src)
946{
947 int i=0;
948 while(*src) {
949 *dst++ = *src++;
950 i++;
951 }
952 return i;
953}
954
955
956
957
958/* *****************************************
959 * Console I/O
960 * ******************************************/
961
962int numOpenDevices = 11;
963struct {
964 char name[128];
965} deviceState[32];
966
947#define BOOTDEVICE_NAME "SCSI 1 0 0 1 100"
967#define BOOTDEVICE_NAME "SCSI 1 0 0 1 100 0"
948
968
949void DeviceOperation(long op,long channel, long count, long address, long block)
969void
970DeviceOperation(long op, long channel, long count, long address, long block)
950{
971{
951 AlphaAccess *k1Conf = (AlphaAccess *)
972 struct AlphaAccess *k1Conf = (struct AlphaAccess *)
952 (__MAGIC_ZONE(0, 0, MAGIC_ZONE_EV5_ALIAS));
953
954 long pAddr;
955
956#if 0
957 printf("Console::DeviceRead count=0x%x address=0x%x block=0x%x\n",
958 count,address,block);
959#endif
960
961 if (strcmp(deviceState[channel].name, BOOTDEVICE_NAME )) {
962 panic("DeviceRead: only implemented for root disk \n");
963 }
964 pAddr = KSEG_TO_PHYS(address);
965 if (pAddr + count > simosConf.mem_size) {
966 panic("DeviceRead: request out of range \n");
967 }
968
969 k1Conf->diskCount = count;
970 k1Conf->diskPAddr = pAddr;
971 k1Conf->diskBlock = block;
972 k1Conf->diskOperation = op; /* launch */
973}
974
975
976
977/* *************************************************************************
978 * SimoS Console callbacks
979 * **************************************************/
980
981/* AXP manual 2-31 */
982#define CONSCB_GETC 0x1
983#define CONSCB_PUTS 0x2
984#define CONSCB_RESET_TERM 0x3
985#define CONSCB_SET_TERM_INT 0x4
986#define CONSCB_SET_TERM_CTL 0x5
987#define CONSCB_PROCESS_KEY 0x6
988
989#define CONSCB_OPEN 0x10
990#define CONSCB_CLOSE 0x11
991#define CONSCB_READ 0x13
992
993#define CONSCB_GETENV 0x22
994
995/* AXP manual 2-26 */
973 (__MAGIC_ZONE(0, 0, MAGIC_ZONE_EV5_ALIAS));
974
975 long pAddr;
976
977#if 0
978 printf("Console::DeviceRead count=0x%x address=0x%x block=0x%x\n",
979 count,address,block);
980#endif
981
982 if (strcmp(deviceState[channel].name, BOOTDEVICE_NAME )) {
983 panic("DeviceRead: only implemented for root disk \n");
984 }
985 pAddr = KSEG_TO_PHYS(address);
986 if (pAddr + count > simosConf.mem_size) {
987 panic("DeviceRead: request out of range \n");
988 }
989
990 k1Conf->diskCount = count;
991 k1Conf->diskPAddr = pAddr;
992 k1Conf->diskBlock = block;
993 k1Conf->diskOperation = op; /* launch */
994}
995
996
997
998/* *************************************************************************
999 * SimoS Console callbacks
1000 * **************************************************/
1001
1002/* AXP manual 2-31 */
1003#define CONSCB_GETC 0x1
1004#define CONSCB_PUTS 0x2
1005#define CONSCB_RESET_TERM 0x3
1006#define CONSCB_SET_TERM_INT 0x4
1007#define CONSCB_SET_TERM_CTL 0x5
1008#define CONSCB_PROCESS_KEY 0x6
1009
1010#define CONSCB_OPEN 0x10
1011#define CONSCB_CLOSE 0x11
1012#define CONSCB_READ 0x13
1013
1014#define CONSCB_GETENV 0x22
1015
1016/* AXP manual 2-26 */
1017#define ENV_AUTO_ACTION 0X01
1018#define ENV_BOOT_DEV 0X02
1019#define ENV_BOOTDEF_DEV 0X03
1020#define ENV_BOOTED_DEV 0X04
1021#define ENV_BOOT_FILE 0X05
1022#define ENV_BOOTED_FILE 0X06
1023#define ENV_BOOT_OSFLAGS 0X07
1024#define ENV_BOOTED_OSFLAGS 0X08
1025#define ENV_BOOT_RESET 0X09
1026#define ENV_DUMP_DEV 0X0A
1027#define ENV_ENABLE_AUDIT 0X0B
1028#define ENV_LICENSE 0X0C
1029#define ENV_CHAR_SET 0X0D
1030#define ENV_LANGUAGE 0X0E
1031#define ENV_TTY_DEV 0X0F
1032#define ENV_SCSIID 0X42
1033#define ENV_SCSIFAST 0X43
1034#define ENV_COM1_BAUD 0X44
1035#define ENV_COM1_MODEM 0X45
1036#define ENV_COM1_FLOW 0X46
1037#define ENV_COM1_MISC 0X47
1038#define ENV_COM2_BAUD 0X48
1039#define ENV_COM2_MODEM 0X49
1040#define ENV_COM2_FLOW 0X4A
1041#define ENV_COM2_MISC 0X4B
1042#define ENV_PASSWORD 0X4C
1043#define ENV_SECURE 0X4D
1044#define ENV_LOGFAIL 0X4E
1045#define ENV_SRM2DEV_ID 0X4F
996
1046
997#define ENV_BOOTED_DEV 0x4
998#define ENV_BOOTED_OSFLAGS 0x8
1047#define MAX_ENVLEN 32
999
1048
1000long CallBackDispatcher(long a0, long a1, long a2, long a3, long a4)
1049char env_booted_dev[MAX_ENVLEN] = BOOTDEVICE_NAME;
1050char env_booted_osflags[MAX_ENVLEN] = "";
1051char env_com1_baud[MAX_ENVLEN] = "";
1052char env_secure[MAX_ENVLEN] = "";
1053
1054#if 0
1055char env_auto_action[MAX_ENVLEN] = "";
1056char env_boot_dev[MAX_ENVLEN] = "";
1057char env_bootdef_dev[MAX_ENVLEN] = "";
1058char env_boot_file[MAX_ENVLEN] = "";
1059char env_booted_file[MAX_ENVLEN] = "";
1060char env_boot_osflags[MAX_ENVLEN] = "";
1061char env_boot_reset[MAX_ENVLEN] = "";
1062char env_dump_dev[MAX_ENVLEN] = "";
1063char env_enable_audit[MAX_ENVLEN] = "";
1064char env_license[MAX_ENVLEN] = "";
1065char env_char_set[MAX_ENVLEN] = "";
1066int env_language = 0;
1067char env_tty_dev[MAX_ENVLEN] = "";
1068char env_scsiid[MAX_ENVLEN] = "";
1069char env_scsifast[MAX_ENVLEN] = "";
1070char env_com1_modem[MAX_ENVLEN] = "";
1071char env_com1_flow[MAX_ENVLEN] = "";
1072char env_com1_misc[MAX_ENVLEN] = "";
1073char env_com2_baud[MAX_ENVLEN] = "";
1074char env_com2_modem[MAX_ENVLEN] = "";
1075char env_com2_flow[MAX_ENVLEN] = "";
1076char env_com2_misc[MAX_ENVLEN] = "";
1077char env_password[MAX_ENVLEN] = "";
1078char env_logfail[MAX_ENVLEN] = "";
1079char env_srm2dev_id[MAX_ENVLEN] = "";
1080#endif
1081
1082long
1083CallBackDispatcher(long a0, long a1, long a2, long a3, long a4)
1001{
1084{
1002 int i;
1085 long i;
1003 switch (a0) {
1086 switch (a0) {
1087 case CONSCB_GETC:
1088 break;
1089
1004 case CONSCB_PUTS:
1090 case CONSCB_PUTS:
1005 for(i=0;i<a3;i++) {
1091 for(i = 0; i < a3; i++) {
1006 PutChar(*(char *)a2+i);
1007 }
1008 return a3;
1092 PutChar(*(char *)a2+i);
1093 }
1094 return a3;
1095
1009 case CONSCB_GETENV:
1010 switch (a1) {
1011 case ENV_BOOTED_DEV:
1096 case CONSCB_GETENV:
1097 switch (a1) {
1098 case ENV_BOOTED_DEV:
1012 i = strcpy((char*)a2,BOOTDEVICE_NAME);
1013 break;
1099 i = strcpy((char*)a2, env_booted_dev);
1100 break;
1101
1014 case ENV_BOOTED_OSFLAGS:
1102 case ENV_BOOTED_OSFLAGS:
1015 /*
1016 * 'c':ignores the sysconfigtab
1017 *
1018 * i= strcpy((char*)a2,"c");
1019 */
1020 i = strcpy((char*)a2,"");
1021 break;
1103 i = strcpy((char*)a2, env_booted_osflags);
1104 break;
1105
1106 case ENV_COM1_BAUD:
1107 i = strcpy((char*)a2, env_com1_baud);
1108 break;
1109
1110 case ENV_SECURE:
1111 i = strcpy((char *)a2, env_secure);
1112 break;
1113
1114#if 0
1115 case ENV_AUTO_ACTION:
1116 case ENV_BOOT_DEV:
1117 case ENV_BOOTDEF_DEV:
1118 case ENV_BOOT_FILE:
1119 case ENV_BOOTED_FILE:
1120 case ENV_BOOT_OSFLAGS:
1121 case ENV_BOOT_RESET:
1122 case ENV_DUMP_DEV:
1123 case ENV_ENABLE_AUDIT:
1124 case ENV_LICENSE:
1125 case ENV_CHAR_SET:
1126 case ENV_LANGUAGE:
1127 case ENV_TTY_DEV:
1128 case ENV_SCSIID:
1129 case ENV_SCSIFAST:
1130 case ENV_COM1_MODEM:
1131 case ENV_COM1_FLOW:
1132 case ENV_COM1_MISC:
1133 case ENV_COM2_BAUD:
1134 case ENV_COM2_MODEM:
1135 case ENV_COM2_FLOW:
1136 case ENV_COM2_MISC:
1137 case ENV_PASSWORD:
1138 case ENV_LOGFAIL:
1139 case ENV_SRM2DEV_ID:
1140#endif
1022 default:
1141 default:
1023 i = strcpy((char*)a2,"");
1024 printf ("GETENV unsupported option %d\n", a1);
1142 strcpy((char*)a2,"");
1143 i = (long)0xc000000000000000;
1144 if (a1 >= 0 && a1 < 100)
1145 printf ("GETENV unsupported option %d\n", a1);
1146 else
1147 printf ("GETENV unsupported option %s\n", a1);
1025 break;
1026 }
1027 if (i > a3) {
1028 panic("CONSCB_GETENV overwrote buffer \n");
1029 }
1030 return i;
1031 case CONSCB_OPEN:
1032 bcopy((char*)a1,deviceState[numOpenDevices].name,a2);
1033 deviceState[numOpenDevices].name[a2] = '\0';
1034 printf("CONSOLE OPEN : %s --> success \n",
1035 deviceState[numOpenDevices].name);
1036 return numOpenDevices++;
1037
1038 case CONSCB_READ:
1039 DeviceOperation(a0,a1,a2,a3,a4);
1040 break;
1041 case CONSCB_CLOSE:
1042 break;
1043 default:
1044 panic("cher (%x,%x,%x,%x) \n",
1045 a0,a1,a2,a3);
1046 }
1047 return 0;
1048}
1049
1050long CallBackFixup(int a0, int a1, int a2)
1051{
1052 printf("CallbackFixup %x %x \n",a0,a1);
1053
1054#if 0
1055 if (first[FIRST(a1)]==0) {
1056 first[FIRST(a1)] = KPTE(PFN(reservedFixup));
1057 } else {
1058 panic("CallBakcfixup\n");
1059 }
1060 second[SECOND(a1)] = KPTE(PFN(third_rpb)); /* Region 0 */
1061 printf("Fixup: FISRT(a1)=0x%x SECOND(a1)=0x%x THIRD(a1)=0x%x\n",
1062 FIRST(a1),SECOND(a1),THIRD(a1));
1063
1064#endif
1065 return 0;
1066}
1067
1068
1069
1070
1071
1072void SlaveCmd(int cpu, struct rpb_percpu *my_rpb)
1073{
1074/* extern void palJToSlave[]; */
1075 extern unsigned int palJToSlave[];
1076
1077
1078 my_rpb->rpb_state |= STATE_BIP;
1079 my_rpb->rpb_state &= ~STATE_RC;
1080
1081 SpinLock(&theLock);
1082 printf("SlaveCmd: restart %x %x vptb %x my_rpb %x my_rpb_phys %x\n",
1083 rpb->rpb_restart,
1084 rpb->rpb_restart_pv,
1085 rpb->rpb_vptb, my_rpb,
1086 KSEG_TO_PHYS(my_rpb));
1087 SpinUnlock(&theLock);
1088
1089 cServe(KSEG_TO_PHYS((ul)palJToSlave),
1090 (ul)rpb->rpb_restart,
1091 CSERVE_K_JTOPAL,
1092 rpb->rpb_restart_pv,
1093 rpb->rpb_vptb,
1094 KSEG_TO_PHYS(my_rpb));
1095}
1096
1097void SlaveLoop( int cpu)
1098{
1099 int size = ROUNDUP128(sizeof(struct rpb_percpu));
1100 struct rpb_percpu *my_rpb = (struct rpb_percpu*)
1101 ((ul)rpb_percpu + size*cpu);
1102
1103
1104 SpinLock(&theLock);
1105 if (cpu==0) {
1106 panic("CPU�0 entering slaveLoop. Reenetering the console. HOSED \n");
1107 } else {
1108 printf("Entering slaveloop for cpu %d my_rpb=%x \n",cpu,my_rpb);
1109 }
1110 SpinUnlock(&theLock);
1111 while(1) {
1112 int i;
1113 for (i=0; i < 1000000 ; i++) {
1114 if (my_rpb->rpb_iccb.iccb_rxlen) {
1115 SpinLock(&theLock);
1116 printf("Slave CPU %d console command %s",
1117 cpu,my_rpb->rpb_iccb.iccb_rxbuf);
1118 SpinUnlock(&theLock);
1119 SlaveCmd(cpu,my_rpb);
1120 panic("SlaveCmd returned \n");
1121 }
1122 }
1123 printf("*");
1124 }
1125}
1126
1148 break;
1149 }
1150 if (i > a3) {
1151 panic("CONSCB_GETENV overwrote buffer \n");
1152 }
1153 return i;
1154 case CONSCB_OPEN:
1155 bcopy((char*)a1,deviceState[numOpenDevices].name,a2);
1156 deviceState[numOpenDevices].name[a2] = '\0';
1157 printf("CONSOLE OPEN : %s --> success \n",
1158 deviceState[numOpenDevices].name);
1159 return numOpenDevices++;
1160
1161 case CONSCB_READ:
1162 DeviceOperation(a0,a1,a2,a3,a4);
1163 break;
1164 case CONSCB_CLOSE:
1165 break;
1166 default:
1167 panic("cher (%x,%x,%x,%x) \n",
1168 a0,a1,a2,a3);
1169 }
1170 return 0;
1171}
1172
1173long CallBackFixup(int a0, int a1, int a2)
1174{
1175 printf("CallbackFixup %x %x \n",a0,a1);
1176
1177#if 0
1178 if (first[FIRST(a1)]==0) {
1179 first[FIRST(a1)] = KPTE(PFN(reservedFixup));
1180 } else {
1181 panic("CallBakcfixup\n");
1182 }
1183 second[SECOND(a1)] = KPTE(PFN(third_rpb)); /* Region 0 */
1184 printf("Fixup: FISRT(a1)=0x%x SECOND(a1)=0x%x THIRD(a1)=0x%x\n",
1185 FIRST(a1),SECOND(a1),THIRD(a1));
1186
1187#endif
1188 return 0;
1189}
1190
1191
1192
1193
1194
1195void SlaveCmd(int cpu, struct rpb_percpu *my_rpb)
1196{
1197/* extern void palJToSlave[]; */
1198 extern unsigned int palJToSlave[];
1199
1200
1201 my_rpb->rpb_state |= STATE_BIP;
1202 my_rpb->rpb_state &= ~STATE_RC;
1203
1204 SpinLock(&theLock);
1205 printf("SlaveCmd: restart %x %x vptb %x my_rpb %x my_rpb_phys %x\n",
1206 rpb->rpb_restart,
1207 rpb->rpb_restart_pv,
1208 rpb->rpb_vptb, my_rpb,
1209 KSEG_TO_PHYS(my_rpb));
1210 SpinUnlock(&theLock);
1211
1212 cServe(KSEG_TO_PHYS((ul)palJToSlave),
1213 (ul)rpb->rpb_restart,
1214 CSERVE_K_JTOPAL,
1215 rpb->rpb_restart_pv,
1216 rpb->rpb_vptb,
1217 KSEG_TO_PHYS(my_rpb));
1218}
1219
1220void SlaveLoop( int cpu)
1221{
1222 int size = ROUNDUP128(sizeof(struct rpb_percpu));
1223 struct rpb_percpu *my_rpb = (struct rpb_percpu*)
1224 ((ul)rpb_percpu + size*cpu);
1225
1226
1227 SpinLock(&theLock);
1228 if (cpu==0) {
1229 panic("CPU�0 entering slaveLoop. Reenetering the console. HOSED \n");
1230 } else {
1231 printf("Entering slaveloop for cpu %d my_rpb=%x \n",cpu,my_rpb);
1232 }
1233 SpinUnlock(&theLock);
1234 while(1) {
1235 int i;
1236 for (i=0; i < 1000000 ; i++) {
1237 if (my_rpb->rpb_iccb.iccb_rxlen) {
1238 SpinLock(&theLock);
1239 printf("Slave CPU %d console command %s",
1240 cpu,my_rpb->rpb_iccb.iccb_rxbuf);
1241 SpinUnlock(&theLock);
1242 SlaveCmd(cpu,my_rpb);
1243 panic("SlaveCmd returned \n");
1244 }
1245 }
1246 printf("*");
1247 }
1248}
1249