1 /* $NetBSD: locore.s,v 1.91 2026/03/29 03:24:58 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1988 University of Utah. 5 * Copyright (c) 1980, 1990, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * the Systems Programming Group of the University of Utah Computer 10 * Science Department. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * from: Utah $Hdr: locore.s 1.66 92/12/22$ 37 * @(#)locore.s 8.6 (Berkeley) 5/27/94 38 */ 39 40 #include "opt_compat_netbsd.h" 41 #include "opt_compat_sunos.h" 42 #include "opt_kgdb.h" 43 #include "opt_lockdebug.h" 44 45 #include "assym.h" 46 #include <machine/asm.h> 47 #include <machine/trap.h> 48 49 | Remember this is a fun project! 50 51 .data 52 GLOBAL(mon_crp) 53 .long 0,0 54 55 | This is for kvm_mkdb, and should be the address of the beginning 56 | of the kernel text segment (not necessarily the same as kernbase). 57 .text 58 GLOBAL(kernel_text) 59 60 | This is the entry point, as well as the end of the temporary stack 61 | used during process switch (one 8K page ending at start) 62 ASGLOBAL(tmpstk) 63 ASGLOBAL(start) 64 65 | The first step, after disabling interrupts, is to map enough of the kernel 66 | into high virtual address space so that we can use position dependent code. 67 | This is a tricky task on the sun3x because the MMU is already enabled and 68 | the ROM monitor provides no indication of where the root MMU table is mapped. 69 | Therefore we must use one of the 68030's 'transparent translation' registers 70 | to define a range in the address space where the MMU translation is 71 | turned off. Once this is complete we can modify the MMU table directly 72 | without the need for it to be mapped into virtual memory. 73 | All code must be position independent until otherwise noted, as the 74 | boot loader has loaded us into low memory but all the symbols in this 75 | code have been linked high. 76 movw #PSL_HIGHIPL,%sr | no interrupts 77 movl #KERNBASE3X,%a5 | for vtop conversion 78 lea _C_LABEL(mon_crp),%a0 | where to store the CRP 79 subl %a5,%a0 80 | Note: borrowing mon_crp for tt0 setup... 81 movl #0x3F8107,%a0@ | map the low 1GB v=p with the 82 .long 0xf0100800 | transparent translation reg0 83 | [ pmove a0@, tt0 ] 84 | In order to map the kernel into high memory we will copy the root table 85 | entry which maps the 16 megabytes of memory starting at 0x0 into the 86 | entry which maps the 16 megabytes starting at KERNBASE. 87 pmove %crp,%a0@ | Get monitor CPU root pointer 88 movl %a0@(4),%a1 | 2nd word is PA of level A table 89 90 movl %a1,%a0 | compute the descriptor address 91 addl #0x3e0,%a1 | for VA starting at KERNBASE 92 movl %a0@,%a1@ | copy descriptor type 93 movl %a0@(4),%a1@(4) | copy physical address 94 95 | Kernel is now double mapped at zero and KERNBASE. 96 | Force a long jump to the relocated code (high VA). 97 movl #IC_CLEAR,%d0 | Flush the I-cache 98 movc %d0,%cacr 99 jmp L_high_code:l | long jump 100 101 L_high_code: 102 | We are now running in the correctly relocated kernel, so 103 | we are no longer restricted to position-independent code. 104 | It is handy to leave transparent translation enabled while 105 | for the low 1GB while _bootstrap() is doing its thing. 106 107 | Do bootstrap stuff needed before main() gets called. 108 | Our boot loader leaves a copy of the kernel's exec header 109 | just before the start of the kernel text segment, so the 110 | kernel can sanity-check the DDB symbols at [end...esym]. 111 | Pass the struct exec at tmpstk-32 to _bootstrap(). 112 | Also, make sure the initial frame pointer is zero so that 113 | the backtrace algorithm used by KGDB terminates nicely. 114 | 115 | _bootstrap() returns lwp0 SP in %a0 116 lea _ASM_LABEL(tmpstk)-32,%sp 117 jsr _C_LABEL(_bootstrap) | See locore2.c 118 movl %a0,%sp | now running on lwp0's stack 119 movl #0,%a6 | terminate the stack back trace 120 121 | Now turn off the transparent translation of the low 1GB. 122 | (this also flushes the ATC) 123 clrl %sp@- 124 .long 0xf0170800 | pmove sp@,tt0 125 addql #4,%sp 126 127 jra _C_LABEL(main) | main() (never returns) 128 129 | That is all the assembly startup code we need on the sun3x! 130 | The rest of this is like the hp300/locore.s where possible. 131 132 /* 133 * Interrupt handlers. Most are auto-vectored, 134 * and hard-wired the same way on all sun3 models. 135 * Format in the stack is: 136 * %d0,%d1,%a0,%a1, sr, pc, vo 137 */ 138 139 /* clock: see clock.c */ 140 #ifdef __ELF__ 141 .align 4 142 #else 143 .align 2 144 #endif 145 GLOBAL(_isr_clock) 146 INTERRUPT_SAVEREG 147 jbsr _C_LABEL(clock_intr) 148 INTERRUPT_RESTOREREG 149 jra _ASM_LABEL(rei) 150 151 /* 152 * Initialization is at the beginning of this file, because the 153 * kernel entry point needs to be at zero for compatibility with 154 * the Sun boot loader. This works on Sun machines because the 155 * interrupt vector table for reset is NOT at address zero. 156 * (The MMU has a "boot" bit that forces access to the PROM) 157 */ 158 159 #ifdef DEBUG 160 .data 161 ASGLOBAL(fulltflush) 162 .long 0 163 ASGLOBAL(fullcflush) 164 .long 0 165 .text 166 #endif 167 168 /* 169 * Load a new CPU Root Pointer (CRP) into the MMU. 170 * void loadcrp(struct mmu_rootptr *); 171 */ 172 ENTRY(loadcrp) 173 movl %sp@(4),%a0 | arg1: &CRP 174 movl #CACHE_CLR,%d0 175 movc %d0,%cacr | invalidate cache(s) 176 pflusha | flush entire TLB 177 pmove %a0@,%crp | load new user root pointer 178 rts 179 180 ENTRY(getcrp) 181 movl %sp@(4),%a0 | arg1: &crp 182 pmove %crp,%a0@ | *crpp = %crp 183 rts 184 185 /* 186 * Get the physical address of the PTE for a given VA. 187 */ 188 ENTRY(ptest_addr) 189 movl %sp@(4),%a1 | VA 190 ptestr #5,%a1@,#7,%a0 | %a0 = addr of PTE 191 movl %a0,%d0 | Result in %d0 (not a pointer return) 192 rts 193 194 | Define some addresses, mostly so DDB can print useful info. 195 | Not using _C_LABEL() here because these symbols are never 196 | referenced by any C code, and if the leading underscore 197 | ever goes away, these lines turn into syntax errors... 198 .set _KERNBASE3X,KERNBASE3X 199 .set _MONSTART,SUN3X_MONSTART 200 .set _PROM_BASE,SUN3X_PROM_BASE 201 .set _MONEND,SUN3X_MONEND 202 203 |The end! 204