141488Smckusick /* 241488Smckusick * Copyright (c) 1988 University of Utah. 341488Smckusick * Copyright (c) 1982, 1990 The Regents of the University of California. 441488Smckusick * All rights reserved. 541488Smckusick * 641488Smckusick * This code is derived from software contributed to Berkeley by 741488Smckusick * the Systems Programming Group of the University of Utah Computer 841488Smckusick * Science Department. 941488Smckusick * 1041488Smckusick * %sccs.include.redist.c% 1141488Smckusick * 12*54073Shibler * from: Utah $Hdr: srt0.c 1.15 92/06/18$ 1341488Smckusick * 14*54073Shibler * @(#)srt0.c 7.6 (Berkeley) 06/18/92 1541488Smckusick */ 1641488Smckusick 1741488Smckusick /* 1841488Smckusick * Startup code for standalone system 1941488Smckusick */ 2041488Smckusick 2141488Smckusick .globl begin 2241488Smckusick .globl _end 2341488Smckusick .globl _edata 2441488Smckusick .globl _main 2541488Smckusick .globl _configure 2649157Sbostic .globl _firstopen 2741488Smckusick .globl __rtt 28*54073Shibler .globl _bootdev,_howto,_lowram,_machineid 29*54073Shibler .globl _internalhpib 3041488Smckusick 3141488Smckusick STACK = 0xfffff000 | below the ROM page 3241488Smckusick BOOTTYPE = 0xfffffdc0 3341488Smckusick LOWRAM = 0xfffffdce 3442378Smckusick SYSFLAG = 0xfffffed2 | system flags 3541488Smckusick MSUS = 0xfffffedc | MSUS (?) structure 3641488Smckusick VECTORS = 0xfffffee0 | beginning of jump vectors 3741488Smckusick NMIRESET = 0xffffff9c | reset vector 3841488Smckusick BUSERR = 0xfffffffc 3941488Smckusick MAXADDR = 0xfffff000 4041488Smckusick NBPG = 4096 4149333Shibler MMUCMD = 0x005f400c | MMU command/status register 4241488Smckusick 4341488Smckusick .data 4449157Sbostic _bootdev: 4541488Smckusick .long 0 4641488Smckusick _howto: 4741488Smckusick .long 0 4849157Sbostic _lowram: 4941488Smckusick .long 0 5049333Shibler _machineid: 5149333Shibler .long 0 5241488Smckusick 5341488Smckusick .text 5441488Smckusick begin: 5541488Smckusick movl #STACK,sp 5641488Smckusick moveq #47,d0 | # of vectors - 1 5741488Smckusick movl #VECTORS+2,a0 | addr part of first vector 5841488Smckusick vecloop: 5941488Smckusick movl #trap,a0@ | make it direct to trap 6041488Smckusick addql #6,a0 | move to next vector addr 6141488Smckusick dbf d0,vecloop | go til done 6241488Smckusick movl #NMIRESET,a0 | NMI keyboard reset addr 6341488Smckusick movl #nmi,a0@ | catch in reset routine 6449333Shibler /* 6549333Shibler * Determine our CPU type and look for internal HP-IB 6649333Shibler * (really only care about detecting 320 (no DIO-II) right now). 6749333Shibler */ 6849333Shibler lea _machineid,a0 6949333Shibler movl #0x808,d0 7049333Shibler movc d0,cacr | clear and disable on-chip cache(s) 7149333Shibler movl #0x200,d0 | data freeze bit 7249333Shibler movc d0,cacr | only exists on 68030 7349333Shibler movc cacr,d0 | read it back 7449333Shibler tstl d0 | zero? 75*54073Shibler jeq not68030 | yes, we have 68020/68040 7649333Shibler movl #0x808,d0 7749333Shibler movc d0,cacr | clear data freeze bit again 78*54073Shibler 7949333Shibler movl #0x80,MMUCMD | set magic cookie 8049333Shibler movl MMUCMD,d0 | read it back 8149333Shibler btst #7,d0 | cookie still on? 8249333Shibler jeq not370 | no, 360 or 375 8349333Shibler movl #4,a0@ | consider a 370 for now 8449333Shibler movl #0,MMUCMD | clear magic cookie 8549333Shibler movl MMUCMD,d0 | read it back 8649333Shibler btst #7,d0 | still on? 8749333Shibler jeq ihpibcheck | no, a 370 8849333Shibler movl #5,a0@ | yes, must be a 340 8949333Shibler jra ihpibcheck 9049333Shibler not370: 9149333Shibler movl #3,a0@ | type is at least a 360 9249333Shibler movl #0,MMUCMD | clear magic cookie2 9349333Shibler movl MMUCMD,d0 | read it back 9449333Shibler btst #16,d0 | still on? 9549333Shibler jeq ihpibcheck | no, a 360 9649333Shibler movl #6,a0@ | yes, must be a 345/375/400 9749333Shibler jra ihpibcheck 98*54073Shibler not68030: 99*54073Shibler bset #31,d0 | data cache enable bit 100*54073Shibler movc d0,cacr | only exists on 68040 101*54073Shibler movc cacr,d0 | read it back 102*54073Shibler tstl d0 | zero? 103*54073Shibler beq is68020 | yes, we have 68020 104*54073Shibler moveq #0,d0 | now turn it back off 105*54073Shibler movec d0,cacr | before we access any data 106*54073Shibler .long 0x4e7b0004 | movc d0,itt0 107*54073Shibler .long 0x4e7b0005 | movc d0,itt1 108*54073Shibler .long 0x4e7b0006 | movc d0,dtt0 109*54073Shibler .long 0x4e7b0007 | movc d0,dtt1 110*54073Shibler movl #7,a0@ | we have a 380 111*54073Shibler jra ihpibcheck 11249333Shibler is68020: 11349333Shibler movl #1,a0@ | consider a 330 for now 11449333Shibler movl #1,MMUCMD | a 68020, write HP MMU location 11549333Shibler movl MMUCMD,d0 | read it back 11649333Shibler btst #0,d0 | zero? 11749333Shibler jeq ihpibcheck | yes, a 330 11849333Shibler movl #0,a0@ | no, consider a 320 for now 11949333Shibler movl #0x80,MMUCMD | set magic cookie 12049333Shibler movl MMUCMD,d0 | read it back 12149333Shibler btst #7,d0 | cookie still on? 12249333Shibler jeq ihpibcheck | no, just a 320 12349333Shibler movl #2,a0@ | yes, a 350 12449333Shibler ihpibcheck: 12549333Shibler movl #0,MMUCMD | make sure MMU is off 12642378Smckusick btst #5,SYSFLAG | do we have an internal HP-IB? 12742378Smckusick jeq boottype | yes, continue 12842378Smckusick clrl _internalhpib | no, clear the internal address 12949333Shibler /* 130*54073Shibler * If this is a reboot, extract howto/bootdev stored by kernel 13149333Shibler */ 13242378Smckusick boottype: 13341488Smckusick cmpw #12,BOOTTYPE | is this a reboot (REQ_REBOOT)? 13441488Smckusick jne notreboot | no, skip 135*54073Shibler lea MAXADDR,a0 | find last page 136*54073Shibler movl a0@+,d7 | and extract howto, bootdev 13741488Smckusick movl a0@+,d6 | from where doboot() left them 13841488Smckusick jra boot1 13941488Smckusick /* 140*54073Shibler * At this point we do not know which logical device the MSUS select 141*54073Shibler * code refers to so we cannot construct bootdev. So we just punt 142*54073Shibler * and let configure() construct it. 14341488Smckusick */ 14441488Smckusick notreboot: 145*54073Shibler moveq #0,d6 | make sure bootdev is invalid 14641488Smckusick cmpw #18,BOOTTYPE | does the user want to interact? 14741488Smckusick jeq askme | yes, go to it 14841488Smckusick moveq #0,d7 | default to RB_AUTOBOOT 14941488Smckusick jra boot1 15041488Smckusick askme: 15141488Smckusick moveq #3,d7 | default to RB_SINGLE|RB_ASKNAME 15241488Smckusick boot1: 153*54073Shibler movl d6,_bootdev | save bootdev and howto 15441488Smckusick movl d7,_howto | globally so all can access 15541488Smckusick movl LOWRAM,d0 | read lowram value from bootrom 15641488Smckusick addl #NBPG,d0 | must preserve this for bootrom to reboot 15741488Smckusick andl #0xfffff000,d0 | round to next page 15841488Smckusick movl d0,_lowram | stash that value 15941488Smckusick start: 16041488Smckusick movl #_edata,a2 | start of BSS 16141488Smckusick movl #_end,a3 | end 16241488Smckusick clr: 16341488Smckusick clrb a2@+ | clear BSS 16441488Smckusick cmpl a2,a3 | done? 16541488Smckusick bne clr | no, keep going 16641488Smckusick jsr _configure | configure critical devices 16749157Sbostic movl #1,_firstopen | mark this as the first open 16841488Smckusick jsr _main | lets go 16941488Smckusick __rtt: 17041488Smckusick movl #3,_howto | restarts get RB_SINGLE|RB_ASKNAME 17141488Smckusick jmp start 17241488Smckusick 17341488Smckusick /* 17441488Smckusick * probe a location and see if it causes a bus error 17541488Smckusick */ 17641488Smckusick .globl _badaddr 17741488Smckusick _badaddr: 17841488Smckusick movl BUSERR,__bsave | save ROM bus error handler address 17941488Smckusick movl sp,__ssave | and current stack pointer 18041488Smckusick movl #catchbad,BUSERR| plug in our handler 18141488Smckusick movl sp@(4),a0 | address to probe 18241488Smckusick movw a0@,d1 | do it 183*54073Shibler movl __bsave,BUSERR | if we got here, it did not fault 18441488Smckusick clrl d0 | return that this was not a bad addr 18541488Smckusick rts 18641488Smckusick 18741488Smckusick catchbad: 18841488Smckusick movl __bsave,BUSERR | got a bus error, so restore old handler 18941488Smckusick movl __ssave,sp | manually restore stack 19041488Smckusick moveq #1,d0 | indicate that we got a fault 19141488Smckusick rts | return to caller of badaddr() 19241488Smckusick 19341488Smckusick __bsave: 19441488Smckusick .long 0 19541488Smckusick __ssave: 19641488Smckusick .long 0 19741488Smckusick 19841488Smckusick .globl _trap 19941488Smckusick trap: 20041488Smckusick moveml #0xFFFF,sp@- | save registers 20141488Smckusick movl sp,sp@- | push pointer to frame 20241488Smckusick jsr _trap | call C routine to deal with it 203*54073Shibler tstl d0 204*54073Shibler jeq Lstop 205*54073Shibler addql #4,sp 206*54073Shibler moveml sp@+,#0x7FFF 207*54073Shibler addql #8,sp 208*54073Shibler rte 209*54073Shibler Lstop: 21041488Smckusick stop #0x2700 | stop cold 21141488Smckusick 21241488Smckusick nmi: 21341488Smckusick movw #18,BOOTTYPE | mark as system switch 21441488Smckusick jsr _kbdnmi | clear the interrupt 21541488Smckusick jra begin | start over 21641488Smckusick 21741488Smckusick #ifdef ROMPRF 21841488Smckusick .globl _romout 21941488Smckusick _romout: 22041488Smckusick movl sp@(4),d0 | line number 22141488Smckusick movl sp@(8),a0 | string 22241488Smckusick jsr 0x150 | do it 22341488Smckusick rts 22441488Smckusick #endif 225