locore.S revision 1.3
11.3Srin/* $NetBSD: locore.S,v 1.3 2022/05/07 04:12:54 rin Exp $ */ 21.1Srin 31.1Srin/* 41.1Srin * Taken from src/sys/arch/powerpc/ibm4xx/openbios/locore.s: 51.1Srin * NetBSD: locore.S,v 1.17 2021/03/30 01:57:20 rin Exp 61.1Srin */ 71.1Srin 81.1Srin/* 91.1Srin * Copyright 2001 Wasabi Systems, Inc. 101.1Srin * All rights reserved. 111.1Srin * 121.1Srin * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc. 131.1Srin * 141.1Srin * Redistribution and use in source and binary forms, with or without 151.1Srin * modification, are permitted provided that the following conditions 161.1Srin * are met: 171.1Srin * 1. Redistributions of source code must retain the above copyright 181.1Srin * notice, this list of conditions and the following disclaimer. 191.1Srin * 2. Redistributions in binary form must reproduce the above copyright 201.1Srin * notice, this list of conditions and the following disclaimer in the 211.1Srin * documentation and/or other materials provided with the distribution. 221.1Srin * 3. All advertising materials mentioning features or use of this software 231.1Srin * must display the following acknowledgement: 241.1Srin * This product includes software developed for the NetBSD Project by 251.1Srin * Wasabi Systems, Inc. 261.1Srin * 4. The name of Wasabi Systems, Inc. may not be used to endorse 271.1Srin * or promote products derived from this software without specific prior 281.1Srin * written permission. 291.1Srin * 301.1Srin * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 311.1Srin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 321.1Srin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 331.1Srin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 341.1Srin * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 351.1Srin * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 361.1Srin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 371.1Srin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 381.1Srin * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 391.1Srin * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 401.1Srin * POSSIBILITY OF SUCH DAMAGE. 411.1Srin */ 421.1Srin 431.1Srin/* 441.1Srin * Copyright (C) 1995, 1996 Wolfgang Solfrank. 451.1Srin * Copyright (C) 1995, 1996 TooLs GmbH. 461.1Srin * All rights reserved. 471.1Srin * 481.1Srin * Redistribution and use in source and binary forms, with or without 491.1Srin * modification, are permitted provided that the following conditions 501.1Srin * are met: 511.1Srin * 1. Redistributions of source code must retain the above copyright 521.1Srin * notice, this list of conditions and the following disclaimer. 531.1Srin * 2. Redistributions in binary form must reproduce the above copyright 541.1Srin * notice, this list of conditions and the following disclaimer in the 551.1Srin * documentation and/or other materials provided with the distribution. 561.1Srin * 3. All advertising materials mentioning features or use of this software 571.1Srin * must display the following acknowledgement: 581.1Srin * This product includes software developed by TooLs GmbH. 591.1Srin * 4. The name of TooLs GmbH may not be used to endorse or promote products 601.1Srin * derived from this software without specific prior written permission. 611.1Srin * 621.1Srin * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 631.1Srin * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 641.1Srin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 651.1Srin * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 661.1Srin * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 671.1Srin * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 681.1Srin * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 691.1Srin * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 701.1Srin * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 711.1Srin * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 721.1Srin */ 731.1Srin 741.1Srin#ifdef PPC_4XX_NOCACHE 751.1Srin#error Not tested. 761.1Srin#endif 771.1Srin 781.1Srin#include "assym.h" 791.1Srin#include "ksyms.h" 801.1Srin 811.1Srin#ifdef _KERNEL_OPT 821.1Srin#include "opt_ddb.h" 831.1Srin#include "opt_modular.h" 841.1Srin#include "opt_ppcparam.h" 851.1Srin#endif 861.1Srin 871.1Srin#include <machine/param.h> 881.1Srin#include <machine/asm.h> 891.1Srin#include <machine/psl.h> 901.1Srin#include <machine/trap.h> 911.1Srin 921.1Srin#include <powerpc/spr.h> 931.1Srin#include <powerpc/ibm4xx/spr.h> 941.1Srin 951.1Srin#include <powerpc/ibm4xx/dcr4xx.h> 961.1Srin 971.1Srin/* 981.1Srin * This symbol is here for the benefit of kvm_mkdb, and is supposed to 991.1Srin * mark the start of kernel text. 1001.1Srin */ 1011.1Srin .text 1021.1Srin .globl _C_LABEL(kernel_text) 1031.1Srin_C_LABEL(kernel_text): 1041.1Srin 1051.1Srin/* 1061.1Srin * Startup entry. Note, this must be the first thing in the text 1071.1Srin * segment! 1081.1Srin */ 1091.1Srin .text 1101.1Srin .globl __start 1111.1Srin__start: 1121.1Srin li %r0,0 1131.1Srin mtmsr %r0 /* Disable FPU/MMU/exceptions */ 1141.1Srin isync 1151.1Srin 1161.1Srin /* 1171.1Srin * Errata 213: Incorrect data may be flushed from the data cache. 1181.1Srin * Cores: PPC405D5X1, PPC405D5X2 1191.1Srin * Workaround: #1, CCR0 modification sequence #2 1201.1Srin * Note: Meaning of bits we need to set is undocumented. 1211.1Srin */ 1221.1Srin sync 1231.3Srin mfspr %r0,SPR_CCR0 /* XXXclang: mfccr0 %r0 */ 1241.1Srin oris %r0,%r0,0x50000000@h 1251.3Srin mtspr SPR_CCR0,%r0 /* XXXclang: mtccr0 %r0 */ 1261.1Srin isync 1271.1Srin 1281.1Srin /* PPC405GP errata, item #58. 1291.1Srin * Load string instructions may write incorrect data into the last GPR 1301.1Srin * targeted in the operation. 1311.1Srin * Workaround: set OCM0_DSCNTL[DSEN]=0 and OCM0_DSCNTL[DOF]=0 */ 1321.1Srin li %r0,0 1331.1Srin mtdcr DCR_OCM0_DSCNTL, %r0 /* Disable Data access to OCM */ 1341.1Srin mtdcr DCR_OCM0_ISCNTL, %r0 /* Disable Instruction access to OCM. 1351.1Srin Just in case */ 1361.1Srin#ifdef PPC_4XX_NOCACHE 1371.1Srin /* Disable all caches for physical addresses */ 1381.1Srin li %r0,0 1391.1Srin#else 1401.1Srin /* Allow cacheing for only the first 2GB of RAM */ 1411.1Srin lis %r0,0xffff 1421.1Srin#endif 1431.1Srin mtdccr %r0 1441.1Srin mticcr %r0 1451.1Srin 1461.1Srin /* Invalidate all TLB entries */ 1471.1Srin tlbia 1481.1Srin sync 1491.1Srin isync 1501.1Srin 1511.1Srin /* Get start of BSS */ 1521.1Srin lis %r3,_C_LABEL(_edata)-4@ha 1531.1Srin addi %r3,%r3,_C_LABEL(_edata)-4@l 1541.1Srin /* Get end of kernel memory */ 1551.1Srin lis %r8,_C_LABEL(end)@ha 1561.1Srin addi %r8,%r8,_C_LABEL(end)@l 1571.1Srin /* Zero BSS */ 1581.1Srin li %r4,0 1591.1Srin2: stwu %r4,4(%r3) 1601.1Srin cmpw %r3,%r8 1611.1Srin bne+ 2b 1621.1Srin 1631.1Srin#if NKSYMS > 0 || defined(DDB) || defined(MODULAR) 1641.1Srin /* 1651.1Srin * If we had symbol table location we'd store it here and would've 1661.1Srin * adjusted r8 here. 1671.1Srin */ 1681.1Srin lis %r7,_C_LABEL(startsym)@ha 1691.1Srin addi %r7,%r7,_C_LABEL(startsym)@l 1701.1Srin stw %r8,0(%r7) 1711.1Srin lis %r7,_C_LABEL(endsym)@ha 1721.1Srin addi %r7,%r7,_C_LABEL(endsym)@l 1731.1Srin stw %r8,0(%r7) 1741.1Srin#endif 1751.1Srin 1761.1Srin /* Set kernel MMU context. */ 1771.1Srin li %r0,KERNEL_PID 1781.1Srin mtpid %r0 1791.1Srin sync 1801.1Srin 1811.1Srin INIT_CPUINFO(%r8,%r1,%r9,%r0) 1821.1Srin mr %r4,%r8 1831.1Srin 1841.1Srin lis %r3,__start@ha 1851.1Srin addi %r3,%r3,__start@l 1861.1Srin 1871.1Srin mr %r6,%r31 /* info_block address */ 1881.1Srin bl _C_LABEL(initppc) 1891.1Srin bl _C_LABEL(main) 1901.1Srin 1911.1Srinloop: b loop /* XXX not reached */ 1921.1Srin 1931.1Srin#include <powerpc/ibm4xx/4xx_locore.S> 194