|
|
Power 6/32 Unix version 1.2b
/* init.s */ /* This file is a diagnostic version of locore.s. */ /* It contains the following: */ /* *system data area = scb, dump buffer, interrupt stack, */ /* *system page table,user page tables,pcbs,iomap, & io buffers. */ /* */ /* *system code = interrupt vectors, initialization of system data,*/ /* *memory size calculation,initialization of SPT, zeroing of */ /* *unused memory, & loading of SBR & SLR. */ /* * */ /* *at the end of this code, you are ready to go to virtual mode. */ /* * --- GOOD LUCK! */ /* privileged registers addresses */ #include "prvreg.h" /* program status long word definition */ #include "psl.h" /* page table entry definition */ #include "pte.h" /* process control block offsets */ #include "pcboffset.h" /* fundamental constants for globl use */ #include "const.h" /* system control block offsets*/ #include "scboffset.h" /* SPT offsets */ #include "sptoffset.h" /* trap numbers*/ #include "trap.h" #define V_TRAP 0 #define V_SYSCALL 4 .set HIGH,0x1f /*mask for disabling all interrupts */ .set MCKVEC,4 /*scb offset for machinecheck vector */ .set NISP,2 /*no. of interrupt stack pages */ .set DONE,255 /*user process done code */ .set TTRAP,0x32 .set TRANS,0x30 .set PRIVS,0x2c .text /* PROCESSOR STORAGE AREA */ #include "pstorage.s" .globl _Entry _Entry: jmp begin .space (1024-6) /* globl dump buffer to be used for communication */ /* between tests & interrupt handlers, & other misc. */ /* purposes. */ /* Physical page 3 : Used for global variables */ .set NLWU,35 /*no. of longwords already used */ /*this must be changed when you define */ /*additional variables below before */ /*_dbuf */ .globl _Codek _Codek: .long 0 /* Code cache key */ .globl _restart _restart: .space 4 /*contains restart address for restarting*/ /*after power is restored (loaded by */ /*power fail interrupt handler & used by*/ /*CPU 2 */ .globl _maxmem _maxmem: .space 4 /*memory size in no of bytes */ .globl _maxpages _maxpages: .space 4 /*memory size in no. of physical pages */ .globl _lastadd _lastadd: .space 4 /*address of the last long word */ .globl _unused _unused: .space 4 /*first unused page in system space */ .globl _ctlblk _ctlblk: .long 0 /* pointer to SCB */ .globl _savvec0 /*save vectors area */ _savvec0: .space 4 .globl _savvec1 /*save vectors area */ _savvec1: .space 4 .globl _savvec2 /*save vectors area */ _savvec2: .space 4 .globl _savvec3 /*save vectors area */ _savvec3: .space 4 .globl _savvec4 /*save vectors area */ _savvec4: .space 4 .globl _savvec5 /*save vectors area */ _savvec5: .space 4 .globl _savvec6 /*save vectors area */ _savvec6: .space 4 .globl _savvec7 /*save vectors area */ _savvec7: .space 4 .globl _savvec8 /*save vectors area */ _savvec8: .space 4 .globl _r_no _r_no: .long 0 .globl _pt_base _pt_base: .long 0 .globl _saved_psl _saved_psl: .long 0 .globl _saved_sp _saved_sp: .long 0 .globl _saved_fp _saved_fp: .long 0 .globl _ret_adr _ret_adr: .long 0 .globl _exp_par0 _exp_par0: .long 0 .globl _exp_par1 _exp_par1: .long 0 .globl _f_vaddr _f_vaddr: .long 0 /* VA that caused fault */ .globl _f_ptr _f_ptr: .long 0 /* Pointer to fault parameters */ .globl _df_cnt _df_cnt: .long 0 /* Count of data fault */ .globl _if_cnt _if_cnt: .long 0 /* Count of Instruction fault */ .globl _newepc _newepc: .long 0 .globl _act_pc _act_pc: .long 0 /* Actual PC */ .globl _exp_pc _exp_pc: .long 0 /* Expected PC */ .globl _ttcnt _ttcnt: .long 0 /* Count of Trap exception */ .globl _trcnt _trcnt: .long 0 /* Count of Translation fault */ .globl _Ufpte _Ufpte: .long 0 .globl _Ulpte _Ulpte: .long 0 .globl _dbuf /*dump buffer left out of 1K */ _dbuf: .space NBPG - (NLWU *4) edbuf: .globl _intstack /* Interrupt stack */ _intstack: /* Physical pages 4 & 5 */ .space NISP*NBPG eintstack: .set SYSPTSIZE,512 /* No. of entries in SPT */ /* System Page Table -- physical page 6 & 7 */ .align 2 .globl _Sysmap _Sysmap: .space SYSPTSIZE*4 /* 512 max pages allowed for system */ eSysmap: .globl _Syssize .set _Syssize,(eSysmap-_Sysmap)/4 /* should be SYSPTSIZE */ .globl _iomap /* Physical page 8 */ _iomap: .space 1024 /* IOMAP - unused */ .globl _eiomap _eiomap: .globl _pcb0 /* Physical page 9 */ _pcb0: .space 128 /*process control block 0 */ .globl _pcb1 _pcb1: .space 128 /*process control block 1 */ .globl _pcb2 _pcb2: .space 128 /*process control block 2 */ .globl _pcb3 _pcb3: .space 128 /*process control block 3 */ .globl _pcb4 _pcb4: .space 128 /*process control block 4 */ .globl _pcb5 _pcb5: .space 128 /*process control block 5 */ .globl _pcb6 _pcb6: .space 128 /*process control block 6 */ .globl _pcb7 _pcb7: .space 128 /*process control block 7 */ /* *user #0 page tables -- P0PT, P1PT, P2PT *physical memory -- page10, 11, & 12 respectively */ .align 2 .globl _u0p0pt _u0p0pt: .space 1024 /*255 max pages for user #0 text */ .globl _u0p1pt _u0p1pt: .space 1024 /*255 max pages for user #0 data */ .globl _u0p2pt _u0p2pt: .space 1020 /*255 max pages for user #0 stack */ eu0p2pt: .space 4 /* *user #1 page tables -- P0PT, P1PT, P2PT *physical memory -- page13 ,14, & 15 respectively */ .align 2 .globl _u1p0pt _u1p0pt: .space 1024 /*255 max pages for user #1 text */ .globl _u1p1pt _u1p1pt: .space 1024 /*255 max pages for user #1 data */ .globl _u1p2pt _u1p2pt: .space 1020 /*255 max pages for user #1 stack */ eu1p2pt: .space 4 /* *user #2 page tables -- P0PT, P1PT, P2PT *physical memory -- page 16, 17 , & 18 respectively */ .align 2 .globl _u2p0pt _u2p0pt: .space 1024 /*255 max pages for user #2 text */ .globl _u2p1pt _u2p1pt: .space 1024 /*255 max pages for user #2 data */ .globl _u2p2pt _u2p2pt: .space 1020 /*255 max pages for user #2 stack */ eu2p2pt: .space 4 /* *user #3 page tables -- P0PT, P1PT, P2PT *physical memory -- page 19, 20 , & 21 respectively */ .align 2 .globl _u3p0pt _u3p0pt: .space 1024 /*255 max pages for user #3 text */ .globl _u3p1pt _u3p1pt: .space 1024 /*255 max pages for user #3 data */ .globl _u3p2pt _u3p2pt: .space 1020 /*255 max pages for user #3 stack */ eu3p2pt: .space 4 /* *user #4 thru 6 page tables *physical memory -- pages 22 thru 30 */ .globl _u4p0pt _u4p0pt: .space (9*NBPG) - 4 eu6p2pt: .space 4 /* Area used for Kernel stack physical memory -- page 31, 32 , 33 */ .align 2 .globl _Kstack /* Kernel stack */ _Kstack: /* Physical pages 31,32,33 */ .space 3*NBPG ekstack: .globl _iob0 /*io buffer 0 */ _iob0: .space 1024 .globl _iob1 /*io buffer 1 */ _iob1: .space 1024 .globl _iob2 /*io buffer 2 */ _iob2: .space 1024 .globl _iob3 /*io buffer 3 */ _iob3: .space 1024 .globl _iob4 /*io buffer 4 */ _iob4: .space 1024 .globl _iob5 /*io buffer 5 */ _iob5: .space 1024 .globl _iob6 /*io buffer 6 */ _iob6: .space 1024 esysdata: /* SYSTEM CONTROL BLOCK */ #include "scblock.s" #include "evthandlers.s" #define ACBL(_n1,_n2,_n3,_n4) \ addl2 _n2,_n3;\ cmpl _n3,_n1;\ bleq _n4; /* *INITIALIZATION CODE * * MME off; mode = k; IPL = 31; IS = 1 * */ .globl begin begin: movl $0,sr0 /* Save r0, r1, r2 */ movl $0,sr1 movl $0,sr2 mtpr $0,$MME /* Disable MME */ movab _scb,r0 andl2 $0x3ffffc00,r0 mtpr r0,$SCBB /* Set SCBB */ mtpr $0x1f,$IPL /* Set IPL to HIGH */ movpsl r1 andl2 $0xffffff00,r1 /* Mask out flags */ cmpl r1,$0x041f0000 /*IS on,modes =k & IPL = 31? */ beql 1f 2: movl $1,r0 movl $0x041f0000,r2 halt /* PSL not initialized as expected */ 1: movl $_intstack+NISP*NBPG,r0 andl2 $0x3fffffff,r0 /* Mask out bit 30,31 */ mtpr r0,$ISP /* init. ISP */ movl r0,sp /* in case we get exception */ movab (sp),fp /* Initialize FP */ /* Clear system data area all the way upto system code this includes dump buffer,interrupt stack,spt,iomap,pcbs,user page tables, & io buffer area. */ 3: movab esysdata,r7 movab _restart,r6 1: clrl (r6) ACBL(r7,$4,r6,1b) /* Initialize System Page Table */ 5: clrl r2 movab esysdata,r1 /* R1 = Last address in system data area */ andl2 $0x3fffffff,r1 /* Mask out bit 30,31 */ shar $PGSHIFT,r1,r1 /* Get page no. of last system data addr */ /* Map systm data area 1 to 1,kernel writable */ 1: orl3 $PG_V|PG_KW,r2,_Sysmap[r2] aoblss r1,r2,1b /* Map system text area 1 to 1, Kernel read/write. For this to work, the label _etext must exist at the end of system code; Add in 4 more pages for data area used in C */ movab _Esys,r1 /* Map System text 1 to 1; Kernel R/W */ andl2 $0x3fffffff,r1 shar $PGSHIFT,r1,r1 1: orl3 $PG_V|PG_KW,r2,_Sysmap[r2] aobleq r1,r2,1b /* Map from here to last page used by user : invalid, User access, & virtual = physical */ movl r2,_unused /* Save first unused physical page no */ movl r2,_Ufpte /* First PTE of User */ movl $0x80000,r1 /* Allow this much memory for User */ shar $PGSHIFT,r1,r1 movl r1,_Ulpte /* Last PTE of User */ 1: orl3 $PG_UW,r2,_Sysmap[r2] /* User Read/Write */ aoblss r1,r2,1b /* Initialize SBR, SLR */ sysrdy: mtpr $_Sysmap,$SBR /* Set SYSTEM BASE REG */ mtpr $_Syssize,$SLR mtpr $64,$DCR /* Enable fault */ /* GO TO VIRTUAL MODE Double map the kernel into user addresses : This will enable system to go to virtual mode the 1st time !! */ orl3 $0xc0000000,$_Sysmap,r0 mtpr r0,$P0BR /* Double map P0BR to SBR */ mtpr $_Syssize,$P0LR mtpr $1,$PADC /* Purge all data cache */ mtpr $1,$TBIA /* Purge all Trans. buffer */ mtpr $1,$MME /* Turn on MME */ jmp *$vmode vmode: clrl _ttcnt clrl _trcnt clrl _if_cnt clrl _df_cnt mfpr $SCBB,r0 movab _Ttrap,TTRAP*4(r0) /* Set new trap handler */ movab _Trans,TRANS*4(r0) /* Set new trans. fault handler */ movab _Prvis,PRIVS*4(r0) /* Set new priv. ins. fault handler */ mtpr $_pcb0,$0xe /* Init. PCBB to PCB_0 */ movab _pcb0,r0 movab ekstack,PCB_KSP(r0) /* Init. PCB_KSP */ movab eustack,PCB_USP(r0) /* Init. PCB_USP */ mfpr $P0BR,PCB_P0BR(r0) /* " PCB_P0BR */ mfpr $P0LR,PCB_P0LR(r0) /* " PCB_P0LR */ movab _monitor,PCB_PC(r0) /* Set PCB_PC */ movab _monitor,_exp_pc /* 1st PC that has Translation fault */ movl $1,_newepc cmpl $0xf,r12 /* Run process in KERNEL mode ? */ beql 1f movl $0x1000010,PCB_PSL(r0) /* Set PCB_PSL : User, Trace ON ! */ brb 2f 1: movl $0x0000010,PCB_PSL(r0) /* Set PCB_PSL : Kernel, Trace ON ! */ 2: movl $1,_Codek mtpr _Codek,$CCK /* Set code cache key */ ldpctx /* Load user context : switch to KSP */ movl sr0,r0 movl sr1,r1 movl sr2,r2 /* Restore r0, r1, r2 */ rei /* Switch to excecute User code */ halt /* ****************************************** Trace trap exception handler Set expected PC that have Translation fault Increment Trace trap count Invalidate all User PTE's Purge Translation buffer ****************************************** */ .align 2 .globl _Ttrap _Ttrap: mtpr $1,$IPL /* For REI in clock handler to work */ incl _ttcnt /* Inc. trap count */ movl (sp),_savvec0 /* PC that will have trans. fault */ svpctx cmpl $1,_newepc /* Did I get a Trans. fault ? */ bneq 1f movl $0xeeeeeeee,r0 /* Miss 1 translation fault */ movl _exp_pc,r1 /* at this address !!! */ halt 1: movl _savvec0,_exp_pc incl _newepc /* New expected PC is set */ movl _Ufpte,r2 /* First PTE of User */ movl _Ulpte,r1 /* Last PTE of User */ 1: andl2 $0x7fffffff,_Sysmap[r2] /* Mask out V_bit */ aoblss r1,r2,1b mtpr $1,$TBIA incl _Codek /* Bump code cache key */ cmpl _Codek,$255 /* Last key yet ? */ jlss 1f movl $1,_Codek /* Reset Code key to 1 */ mtpr $1,$PACC /* Purge all code cache */ 1: mtpr _Codek,$CCK /* Set new key */ ldpctx rei /* ************************************ Translation exception handler Increment counts Validate Page that is invalid Purge Translation buffer ************************************ */ .align 2 .globl _Trans _Trans: mtpr $1,$IPL /* For REI in clock handler to work */ movl (sp)+,_f_ptr /* Ignore 1st fault parameter */ movl (sp)+,_f_vaddr /* Get VA that caused fault */ movl (sp),_act_pc /* PC at fault */ svpctx incl _trcnt /* Increment translation fault count */ movl _act_pc,r1 /* R1 = Actual PC at fault */ cmpl r1,_f_vaddr /* Is instruction or data fault ? */ beql 1f incl _df_cnt /* Increment data fault count */ brw 2f /* Check Expected PC */ 1: incl _if_cnt /* Increment instruction fault count */ cmpl $1,_newepc /* Have Trap hdlr set new expected PC */ jneq 1f /* Donot check PC if not !! */ 2: movl _exp_pc,r2 /* R2 = Expected PC */ cmpl r1,r2 beql 1f movl $0xffffffff,r0 halt /* Cannot restart inst. with wrong PC */ 1: clrl _newepc /* Tell Trap hdlr to set new expected PC */ shar $PGSHIFT,_f_vaddr,r11 /* R11 = PTE at fault */ orl2 $0x80000000,_Sysmap[r11] /* Turn V_bit on */ mtpr _f_vaddr,$TBIS movb (r1),r2 andl2 $0xff,r2 cmpl r2,$0x9b /* Is next inst. a BICPSW ? */ jneq 2f /* If not then skip */ andl3 $0x3ff,r1,r2 cmpl $0x3ff,r2 /* Is this addr is on last byte of the page ? */ bneq 1f addl3 $1,r1,r2 /* Yes,it is then validate the next page also */ shar $PGSHIFT,r2,r11 /* R11 = PTE of next page */ orl2 $0x80000000,_Sysmap[r11] /* Turn V_bit on */ mtpr r2,$TBIS 1: incb r1 /* Added 5/31/84 */ movb (r1),r2 /* Get operand of BICPSW */ andl2 $0xf0,r2 /* Check if direct register mode */ cmpl $0x50,r2 jeql 2f /* If yes then skip */ andb2 $0xef,(r1) /* Not allow to clear T_bit */ incl _Codek /* Bump code cache key */ cmpl _Codek,$255 /* Last key yet ? */ jlss 5f movl $1,_Codek /* Reset Code key to 1 */ mtpr $1,$PACC /* Purge all code cache */ 5: mtpr _Codek,$CCK /* Set new key */ 2: ldpctx rei /* Restart instruction */ /* ********************************************** Privilege instruction fault handler ********************************************** */ .align 2 .globl _Prvis _Prvis: # storer $0xfff,sr0 cmpl $0xcafebabe,r0 jeql 1f # pushab tn /* Write test name */ # callf $8,_writes # pushl sr11 # callf $8,_writes halt /* Error HALT : error codes in r0 - r7 */ 1: movl _trcnt,r1 /* R1 : No of demand page faults occured */ movl _ttcnt,r2 /* R2 : No of Trace traps occured */ movl _if_cnt,r3 /* R3 : No of transl. fault on inst. fetch */ movl _df_cnt,r4 /* R4 : No of transl. fault on data access */ halt .align 2 sr0: .long 0 sr1: .long 0 sr2: .long 0 .long 0 .long 0 .long 0 .long 0 .long 0 .long 0 .long 0 .long 0 sr11: .long 0 .align 1 tn: .ascii "\ntest no \0" ec: .ascii "\nerror code \0" .globl _Esys _Esys: .space NBPG # # .globl _Ustack /* User stack */ _Ustack: /* 2 pages */ .space (2*NBPG)-4 eustack: .long 0 .text .globl U_area U_area:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.