|
|
1.1 root 1:
2: /* init.s */
3:
4:
5: /* This file is a diagnostic version of locore.s. */
6: /* It contains the following: */
7: /* *system data area = scb, dump buffer, interrupt stack, */
8: /* *system page table,user page tables,pcbs,iomap, & io buffers. */
9: /* */
10: /* *system code = interrupt vectors, initialization of system data,*/
11: /* *memory size calculation,initialization of SPT, zeroing of */
12: /* *unused memory, & loading of SBR & SLR. */
13: /* * */
14: /* *at the end of this code, you are ready to go to virtual mode. */
15: /* * --- GOOD LUCK! */
16:
17:
18: /* privileged registers addresses */
19: #include "prvreg.h"
20:
21: /* program status long word definition */
22: #include "psl.h"
23:
24: /* page table entry definition */
25: #include "pte.h"
26:
27: /* process control block offsets */
28: #include "pcboffset.h"
29:
30: /* fundamental constants for globl use */
31: #include "const.h"
32:
33: /* system control block offsets*/
34: #include "scboffset.h"
35: /* SPT offsets */
36: #include "sptoffset.h"
37:
38: /* trap numbers*/
39: #include "trap.h"
40:
41:
42: #define V_TRAP 0
43: #define V_SYSCALL 4
44:
45: .set HIGH,0x1f /*mask for disabling all interrupts */
46: .set MCKVEC,4 /*scb offset for machinecheck vector */
47: .set NISP,2 /*no. of interrupt stack pages */
48: .set DONE,255 /*user process done code */
49: .set TTRAP,0x32
50: .set TRANS,0x30
51: .set PRIVS,0x2c
52:
53: .text
54:
55: /* PROCESSOR STORAGE AREA */
56: #include "pstorage.s"
57:
58: .globl _Entry
59: _Entry:
60: jmp begin
61: .space (1024-6)
62:
63: /* globl dump buffer to be used for communication */
64: /* between tests & interrupt handlers, & other misc. */
65: /* purposes. */
66:
67: /* Physical page 3 : Used for global variables */
68:
69: .set NLWU,35 /*no. of longwords already used */
70: /*this must be changed when you define */
71: /*additional variables below before */
72: /*_dbuf */
73: .globl _Codek
74: _Codek: .long 0 /* Code cache key */
75:
76: .globl _restart
77: _restart:
78: .space 4 /*contains restart address for restarting*/
79: /*after power is restored (loaded by */
80: /*power fail interrupt handler & used by*/
81: /*CPU 2 */
82: .globl _maxmem
83: _maxmem:
84: .space 4 /*memory size in no of bytes */
85:
86: .globl _maxpages
87: _maxpages:
88: .space 4 /*memory size in no. of physical pages */
89:
90: .globl _lastadd
91: _lastadd:
92: .space 4 /*address of the last long word */
93:
94: .globl _unused
95: _unused:
96: .space 4 /*first unused page in system space */
97:
98: .globl _ctlblk
99: _ctlblk:
100: .long 0 /* pointer to SCB */
101:
102: .globl _savvec0 /*save vectors area */
103: _savvec0:
104: .space 4
105:
106: .globl _savvec1 /*save vectors area */
107: _savvec1:
108: .space 4
109:
110: .globl _savvec2 /*save vectors area */
111: _savvec2:
112: .space 4
113:
114: .globl _savvec3 /*save vectors area */
115: _savvec3:
116: .space 4
117:
118: .globl _savvec4 /*save vectors area */
119: _savvec4:
120: .space 4
121:
122: .globl _savvec5 /*save vectors area */
123: _savvec5:
124: .space 4
125: .globl _savvec6 /*save vectors area */
126: _savvec6:
127: .space 4
128: .globl _savvec7 /*save vectors area */
129: _savvec7:
130: .space 4
131:
132: .globl _savvec8 /*save vectors area */
133: _savvec8:
134: .space 4
135:
136: .globl _r_no
137: _r_no:
138: .long 0
139: .globl _pt_base
140: _pt_base:
141: .long 0
142: .globl _saved_psl
143: _saved_psl:
144: .long 0
145: .globl _saved_sp
146: _saved_sp:
147: .long 0
148: .globl _saved_fp
149: _saved_fp:
150: .long 0
151: .globl _ret_adr
152: _ret_adr:
153: .long 0
154: .globl _exp_par0
155: _exp_par0:
156: .long 0
157: .globl _exp_par1
158: _exp_par1:
159: .long 0
160: .globl _f_vaddr
161: _f_vaddr:
162: .long 0 /* VA that caused fault */
163:
164: .globl _f_ptr
165: _f_ptr:
166: .long 0 /* Pointer to fault parameters */
167: .globl _df_cnt
168: _df_cnt:
169: .long 0 /* Count of data fault */
170:
171: .globl _if_cnt
172: _if_cnt:
173: .long 0 /* Count of Instruction fault */
174:
175: .globl _newepc
176: _newepc:
177: .long 0
178:
179: .globl _act_pc
180: _act_pc:
181: .long 0 /* Actual PC */
182: .globl _exp_pc
183: _exp_pc:
184: .long 0 /* Expected PC */
185:
186: .globl _ttcnt
187: _ttcnt:
188: .long 0 /* Count of Trap exception */
189: .globl _trcnt
190: _trcnt:
191: .long 0 /* Count of Translation fault */
192:
193: .globl _Ufpte
194: _Ufpte: .long 0
195: .globl _Ulpte
196: _Ulpte: .long 0
197:
198: .globl _dbuf /*dump buffer left out of 1K */
199: _dbuf:
200: .space NBPG - (NLWU *4)
201: edbuf:
202:
203:
204: .globl _intstack /* Interrupt stack */
205: _intstack: /* Physical pages 4 & 5 */
206: .space NISP*NBPG
207: eintstack:
208:
209:
210: .set SYSPTSIZE,512 /* No. of entries in SPT */
211:
212: /*
213: System Page Table -- physical page 6 & 7
214: */
215: .align 2
216: .globl _Sysmap
217: _Sysmap:
218: .space SYSPTSIZE*4 /* 512 max pages allowed for system */
219: eSysmap:
220: .globl _Syssize
221: .set _Syssize,(eSysmap-_Sysmap)/4 /* should be SYSPTSIZE */
222:
223: .globl _iomap /* Physical page 8 */
224: _iomap: .space 1024 /* IOMAP - unused */
225: .globl _eiomap
226: _eiomap:
227:
228: .globl _pcb0 /* Physical page 9 */
229: _pcb0: .space 128 /*process control block 0 */
230: .globl _pcb1
231: _pcb1: .space 128 /*process control block 1 */
232: .globl _pcb2
233: _pcb2: .space 128 /*process control block 2 */
234: .globl _pcb3
235: _pcb3: .space 128 /*process control block 3 */
236: .globl _pcb4
237: _pcb4: .space 128 /*process control block 4 */
238: .globl _pcb5
239: _pcb5: .space 128 /*process control block 5 */
240: .globl _pcb6
241: _pcb6: .space 128 /*process control block 6 */
242: .globl _pcb7
243: _pcb7: .space 128 /*process control block 7 */
244:
245: /*
246: *user #0 page tables -- P0PT, P1PT, P2PT
247: *physical memory -- page10, 11, & 12 respectively
248: */
249: .align 2
250: .globl _u0p0pt
251: _u0p0pt:
252: .space 1024 /*255 max pages for user #0 text */
253: .globl _u0p1pt
254: _u0p1pt:
255: .space 1024 /*255 max pages for user #0 data */
256: .globl _u0p2pt
257: _u0p2pt:
258: .space 1020 /*255 max pages for user #0 stack */
259: eu0p2pt:
260: .space 4
261:
262: /*
263: *user #1 page tables -- P0PT, P1PT, P2PT
264: *physical memory -- page13 ,14, & 15 respectively
265: */
266: .align 2
267: .globl _u1p0pt
268: _u1p0pt:
269: .space 1024 /*255 max pages for user #1 text */
270: .globl _u1p1pt
271: _u1p1pt:
272: .space 1024 /*255 max pages for user #1 data */
273: .globl _u1p2pt
274: _u1p2pt:
275: .space 1020 /*255 max pages for user #1 stack */
276: eu1p2pt:
277: .space 4
278:
279:
280: /*
281: *user #2 page tables -- P0PT, P1PT, P2PT
282: *physical memory -- page 16, 17 , & 18 respectively
283: */
284: .align 2
285: .globl _u2p0pt
286: _u2p0pt:
287: .space 1024 /*255 max pages for user #2 text */
288: .globl _u2p1pt
289: _u2p1pt:
290: .space 1024 /*255 max pages for user #2 data */
291: .globl _u2p2pt
292: _u2p2pt:
293: .space 1020 /*255 max pages for user #2 stack */
294: eu2p2pt:
295: .space 4
296:
297:
298: /*
299: *user #3 page tables -- P0PT, P1PT, P2PT
300: *physical memory -- page 19, 20 , & 21 respectively
301: */
302: .align 2
303: .globl _u3p0pt
304: _u3p0pt:
305: .space 1024 /*255 max pages for user #3 text */
306: .globl _u3p1pt
307: _u3p1pt:
308: .space 1024 /*255 max pages for user #3 data */
309: .globl _u3p2pt
310: _u3p2pt:
311: .space 1020 /*255 max pages for user #3 stack */
312: eu3p2pt:
313: .space 4
314:
315: /*
316: *user #4 thru 6 page tables
317: *physical memory -- pages 22 thru 30
318: */
319: .globl _u4p0pt
320: _u4p0pt:
321: .space (9*NBPG) - 4
322: eu6p2pt:
323: .space 4
324:
325: /*
326: Area used for Kernel stack
327: physical memory -- page 31, 32 , 33
328: */
329:
330: .align 2
331: .globl _Kstack /* Kernel stack */
332: _Kstack: /* Physical pages 31,32,33 */
333: .space 3*NBPG
334: ekstack:
335:
336:
337: .globl _iob0 /*io buffer 0 */
338: _iob0: .space 1024
339: .globl _iob1 /*io buffer 1 */
340: _iob1: .space 1024
341: .globl _iob2 /*io buffer 2 */
342: _iob2: .space 1024
343: .globl _iob3 /*io buffer 3 */
344: _iob3: .space 1024
345: .globl _iob4 /*io buffer 4 */
346: _iob4: .space 1024
347: .globl _iob5 /*io buffer 5 */
348: _iob5: .space 1024
349: .globl _iob6 /*io buffer 6 */
350: _iob6: .space 1024
351: esysdata:
352:
353: /* SYSTEM CONTROL BLOCK */
354: #include "scblock.s"
355:
356:
357:
358: #include "evthandlers.s"
359:
360: #define ACBL(_n1,_n2,_n3,_n4) \
361: addl2 _n2,_n3;\
362: cmpl _n3,_n1;\
363: bleq _n4;
364:
365:
366:
367: /*
368: *INITIALIZATION CODE
369: *
370: * MME off; mode = k; IPL = 31; IS = 1
371: *
372: */
373:
374:
375: .globl begin
376: begin:
377: movl $0,sr0 /* Save r0, r1, r2 */
378: movl $0,sr1
379: movl $0,sr2
380: mtpr $0,$MME /* Disable MME */
381: movab _scb,r0
382: andl2 $0x3ffffc00,r0
383: mtpr r0,$SCBB /* Set SCBB */
384: mtpr $0x1f,$IPL /* Set IPL to HIGH */
385:
386: movpsl r1
387: andl2 $0xffffff00,r1 /* Mask out flags */
388: cmpl r1,$0x041f0000 /*IS on,modes =k & IPL = 31? */
389: beql 1f
390: 2: movl $1,r0
391: movl $0x041f0000,r2
392: halt /* PSL not initialized as expected */
393: 1:
394: movl $_intstack+NISP*NBPG,r0
395: andl2 $0x3fffffff,r0 /* Mask out bit 30,31 */
396: mtpr r0,$ISP /* init. ISP */
397: movl r0,sp /* in case we get exception */
398: movab (sp),fp /* Initialize FP */
399: /*
400: Clear system data area all the way upto system code
401: this includes dump buffer,interrupt stack,spt,iomap,pcbs,user
402: page tables, & io buffer area.
403: */
404: 3:
405: movab esysdata,r7
406: movab _restart,r6
407: 1: clrl (r6)
408: ACBL(r7,$4,r6,1b)
409: /*
410: Initialize System Page Table
411: */
412: 5:
413: clrl r2
414: movab esysdata,r1 /* R1 = Last address in system data area */
415: andl2 $0x3fffffff,r1 /* Mask out bit 30,31 */
416: shar $PGSHIFT,r1,r1 /* Get page no. of last system data addr */
417: /* Map systm data area 1 to 1,kernel writable */
418: 1:
419: orl3 $PG_V|PG_KW,r2,_Sysmap[r2]
420: aoblss r1,r2,1b
421: /*
422: Map system text area 1 to 1, Kernel read/write.
423: For this to work, the label _etext must exist at the end
424: of system code; Add in 4 more pages for data area used in C
425: */
426: movab _Esys,r1 /* Map System text 1 to 1; Kernel R/W */
427: andl2 $0x3fffffff,r1
428: shar $PGSHIFT,r1,r1
429: 1:
430: orl3 $PG_V|PG_KW,r2,_Sysmap[r2]
431: aobleq r1,r2,1b
432: /*
433: Map from here to last page used by user :
434: invalid, User access, & virtual = physical
435: */
436: movl r2,_unused /* Save first unused physical page no */
437: movl r2,_Ufpte /* First PTE of User */
438: movl $0x80000,r1 /* Allow this much memory for User */
439: shar $PGSHIFT,r1,r1
440: movl r1,_Ulpte /* Last PTE of User */
441: 1:
442: orl3 $PG_UW,r2,_Sysmap[r2] /* User Read/Write */
443: aoblss r1,r2,1b
444:
445: /*
446: Initialize SBR, SLR
447: */
448: sysrdy:
449: mtpr $_Sysmap,$SBR /* Set SYSTEM BASE REG */
450: mtpr $_Syssize,$SLR
451: mtpr $64,$DCR /* Enable fault */
452:
453: /* GO TO VIRTUAL MODE
454: Double map the kernel into user addresses :
455: This will enable system to go to virtual mode the 1st time !!
456: */
457:
458: orl3 $0xc0000000,$_Sysmap,r0
459: mtpr r0,$P0BR /* Double map P0BR to SBR */
460: mtpr $_Syssize,$P0LR
461: mtpr $1,$PADC /* Purge all data cache */
462: mtpr $1,$TBIA /* Purge all Trans. buffer */
463: mtpr $1,$MME /* Turn on MME */
464: jmp *$vmode
465: vmode:
466: clrl _ttcnt
467: clrl _trcnt
468: clrl _if_cnt
469: clrl _df_cnt
470: mfpr $SCBB,r0
471: movab _Ttrap,TTRAP*4(r0) /* Set new trap handler */
472: movab _Trans,TRANS*4(r0) /* Set new trans. fault handler */
473: movab _Prvis,PRIVS*4(r0) /* Set new priv. ins. fault handler */
474:
475: mtpr $_pcb0,$0xe /* Init. PCBB to PCB_0 */
476: movab _pcb0,r0
477: movab ekstack,PCB_KSP(r0) /* Init. PCB_KSP */
478: movab eustack,PCB_USP(r0) /* Init. PCB_USP */
479: mfpr $P0BR,PCB_P0BR(r0) /* " PCB_P0BR */
480: mfpr $P0LR,PCB_P0LR(r0) /* " PCB_P0LR */
481: movab _monitor,PCB_PC(r0) /* Set PCB_PC */
482: movab _monitor,_exp_pc /* 1st PC that has Translation fault */
483: movl $1,_newepc
484: cmpl $0xf,r12 /* Run process in KERNEL mode ? */
485: beql 1f
486:
487: movl $0x1000010,PCB_PSL(r0) /* Set PCB_PSL : User, Trace ON ! */
488: brb 2f
489: 1:
490: movl $0x0000010,PCB_PSL(r0) /* Set PCB_PSL : Kernel, Trace ON ! */
491: 2:
492: movl $1,_Codek
493: mtpr _Codek,$CCK /* Set code cache key */
494: ldpctx /* Load user context : switch to KSP */
495: movl sr0,r0
496: movl sr1,r1
497: movl sr2,r2 /* Restore r0, r1, r2 */
498: rei /* Switch to excecute User code */
499: halt
500:
501: /*
502: ******************************************
503: Trace trap exception handler
504: Set expected PC that have Translation fault
505: Increment Trace trap count
506: Invalidate all User PTE's
507: Purge Translation buffer
508: ******************************************
509: */
510: .align 2
511: .globl _Ttrap
512: _Ttrap:
513: mtpr $1,$IPL /* For REI in clock handler to work */
514: incl _ttcnt /* Inc. trap count */
515: movl (sp),_savvec0 /* PC that will have trans. fault */
516: svpctx
517: cmpl $1,_newepc /* Did I get a Trans. fault ? */
518: bneq 1f
519: movl $0xeeeeeeee,r0 /* Miss 1 translation fault */
520: movl _exp_pc,r1 /* at this address !!! */
521: halt
522:
523: 1:
524: movl _savvec0,_exp_pc
525: incl _newepc /* New expected PC is set */
526: movl _Ufpte,r2 /* First PTE of User */
527: movl _Ulpte,r1 /* Last PTE of User */
528: 1:
529: andl2 $0x7fffffff,_Sysmap[r2] /* Mask out V_bit */
530: aoblss r1,r2,1b
531:
532: mtpr $1,$TBIA
533: incl _Codek /* Bump code cache key */
534: cmpl _Codek,$255 /* Last key yet ? */
535: jlss 1f
536: movl $1,_Codek /* Reset Code key to 1 */
537: mtpr $1,$PACC /* Purge all code cache */
538: 1:
539: mtpr _Codek,$CCK /* Set new key */
540: ldpctx
541: rei
542:
543: /*
544: ************************************
545: Translation exception handler
546: Increment counts
547: Validate Page that is invalid
548: Purge Translation buffer
549: ************************************
550: */
551: .align 2
552: .globl _Trans
553: _Trans:
554: mtpr $1,$IPL /* For REI in clock handler to work */
555: movl (sp)+,_f_ptr /* Ignore 1st fault parameter */
556: movl (sp)+,_f_vaddr /* Get VA that caused fault */
557: movl (sp),_act_pc /* PC at fault */
558: svpctx
559:
560: incl _trcnt /* Increment translation fault count */
561: movl _act_pc,r1 /* R1 = Actual PC at fault */
562: cmpl r1,_f_vaddr /* Is instruction or data fault ? */
563: beql 1f
564: incl _df_cnt /* Increment data fault count */
565: brw 2f /* Check Expected PC */
566: 1:
567: incl _if_cnt /* Increment instruction fault count */
568: cmpl $1,_newepc /* Have Trap hdlr set new expected PC */
569: jneq 1f /* Donot check PC if not !! */
570: 2:
571: movl _exp_pc,r2 /* R2 = Expected PC */
572: cmpl r1,r2
573: beql 1f
574: movl $0xffffffff,r0
575: halt /* Cannot restart inst. with wrong PC */
576: 1:
577: clrl _newepc /* Tell Trap hdlr to set new expected PC */
578: shar $PGSHIFT,_f_vaddr,r11 /* R11 = PTE at fault */
579: orl2 $0x80000000,_Sysmap[r11] /* Turn V_bit on */
580: mtpr _f_vaddr,$TBIS
581:
582: movb (r1),r2
583: andl2 $0xff,r2
584: cmpl r2,$0x9b /* Is next inst. a BICPSW ? */
585: jneq 2f /* If not then skip */
586: andl3 $0x3ff,r1,r2
587: cmpl $0x3ff,r2 /* Is this addr is on last byte of the page ? */
588: bneq 1f
589: addl3 $1,r1,r2 /* Yes,it is then validate the next page also */
590: shar $PGSHIFT,r2,r11 /* R11 = PTE of next page */
591: orl2 $0x80000000,_Sysmap[r11] /* Turn V_bit on */
592: mtpr r2,$TBIS
593: 1:
594: incb r1
595: /* Added 5/31/84 */
596: movb (r1),r2 /* Get operand of BICPSW */
597: andl2 $0xf0,r2 /* Check if direct register mode */
598: cmpl $0x50,r2
599: jeql 2f /* If yes then skip */
600:
601: andb2 $0xef,(r1) /* Not allow to clear T_bit */
602:
603: incl _Codek /* Bump code cache key */
604: cmpl _Codek,$255 /* Last key yet ? */
605: jlss 5f
606: movl $1,_Codek /* Reset Code key to 1 */
607: mtpr $1,$PACC /* Purge all code cache */
608: 5:
609: mtpr _Codek,$CCK /* Set new key */
610: 2:
611: ldpctx
612: rei /* Restart instruction */
613:
614: /*
615: **********************************************
616: Privilege instruction fault handler
617: **********************************************
618: */
619: .align 2
620: .globl _Prvis
621: _Prvis:
622: # storer $0xfff,sr0
623: cmpl $0xcafebabe,r0
624: jeql 1f
625: # pushab tn /* Write test name */
626: # callf $8,_writes
627: # pushl sr11
628: # callf $8,_writes
629:
630: halt /* Error HALT : error codes in r0 - r7 */
631: 1:
632: movl _trcnt,r1 /* R1 : No of demand page faults occured */
633: movl _ttcnt,r2 /* R2 : No of Trace traps occured */
634: movl _if_cnt,r3 /* R3 : No of transl. fault on inst. fetch */
635: movl _df_cnt,r4 /* R4 : No of transl. fault on data access */
636: halt
637:
638: .align 2
639: sr0: .long 0
640: sr1: .long 0
641: sr2: .long 0
642: .long 0
643: .long 0
644: .long 0
645: .long 0
646: .long 0
647: .long 0
648: .long 0
649: .long 0
650: sr11: .long 0
651:
652: .align 1
653: tn: .ascii "\ntest no \0"
654: ec: .ascii "\nerror code \0"
655:
656: .globl _Esys
657: _Esys:
658: .space NBPG
659: #
660: #
661: .globl _Ustack /* User stack */
662: _Ustack: /* 2 pages */
663: .space (2*NBPG)-4
664: eustack:
665: .long 0
666: .text
667: .globl U_area
668: U_area:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.