📄 start.s
字号:
/* $Id: start.S,v 1.5 2002/11/07 15:05:24 pefo Exp $ *//* * Copyright (c) 2000-2001 Opsycon AB (www.opsycon.se) * Copyright (c) 2000-2001 Rtmx, Inc (www.rtmx.com) * Copyright (c) 2001 Allegro Networks, Inc.(www.allegronetworks.com) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed for Rtmx, Inc by * Opsycon Open System Consulting AB, Sweden. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */#include "target/pmon_target.h"#include <pmon/dev/gt96132reg.h>#include <pmon/dev/ns16550.h>#include <machine/mpc_regs.h>#include <machine/psl.h>#include <machine/cpu.h>#ifndef INT_MASK#define INT_MASK(src, des) rlwinm des, src, 0, r17, 15#endif /* INT_MASK */#define HID0 1008#define HID1 1009#define L2CR 1017#define CTR 9#define PVR 287#define HIADJ(x) (x)@ha#define HI(x) (x)@h#define LO(x) (x)@l/* * Register usage: * * r0 scratch * r1 stack pointer * r2 scratch * r3 - r4 BAT macros * r5 - r6 GT96132 macros * * r12-r13 scratch * r14 processor type (from PVR reg) * r15 memory size accumulator * r16 load offset * r25 GT96132 base address * r30-r31 serial port scratch registers. *//* * Use this macro to prevent reordering by as/ld and processor */#define IORDER eieio; sync/* * Macros used to setup BAT regs. */#define IBAT_SETUP(batno, batuval, batlval) \ lis r3, HIADJ(batuval); addi r3, r3, LO(batuval); \ lis r4, HIADJ(batlval); addi r4, r4, LO(batlval); \ isync; mtibatu batno, 3; isync; mtibatl batno, 4; sync#define DBAT_SETUP(batno, batuval, batlval) \ lis r3, HIADJ(batuval); addi r3, r3, LO(batuval); \ lis r4, HIADJ(batlval); addi r4, r4, LO(batlval); \ isync; mtdbatu batno, 3; isync; mtdbatl batno, 4; sync/* Delay macro */#define DELAY(cnt) \ lis 0, HI(cnt); \ ori 0,0,LO(cnt);\ mtctr 0; \1: \ bdnz 1b \/* * Use to print a string. Only when UART is around. * Note that this macro uses the link register so save * it before using this macro if a blr depends on it... */#if !defined(GT_UART)#define PRINTSTR(str) \ bl 9f; \ .asciz str; \ .align 2; \9: mflr r3; \ bl serial_out#else#define PRINTSTR(str)#endif#define BOOT_TRACE#ifdef BOOT_TRACE#define DBGPRINTSTR(str) PRINTSTR(str)#else#define DBGPRINTSTR(str)#endif/************************************************************* *NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE* ************************************************************* * Throughout this code r25 is used to hold the GT-chip base * address. DON'T use r25 for any purpose whatsoever! *//* * Macros to simplify setting up the Galileo controller */#define GT_REGAD(offs) \ ori r5, r25, offs#define GT_REGWR(offs, value) \ ori r5, r25, offs; \ lis r6, HIADJ(value); \ addi r6, r6, LO(value); \ stwbrx r6, 0, (r5); \ eieio; sync .space 0x100 .globl _start .globl start_start:start: .globl pmon_stackstack = start - 0x4000 /* 16K PMON stack */pmon_stack = start /* Top of stack */ .globl pmon_intstackintstack = stack - 0x2000 /* 8k PMON interrupt stack */pmon_intstack = stack /* Top of stack *//* Clear MSR to diable interrupts and checks */ andi. r1, r1, 0x0 sync mtmsr 1 /* Clear MSR, turns off any translation etc */ isync/* * Clear mapping registers to delete any unwanted mappings. */ li r1, 0x0 mtibatu 0, r1 mtibatl 0, r1 mtibatu 1, r1 mtibatl 1, r1 mtibatu 2, r1 mtibatl 2, r1 mtibatu 3, r1 mtibatl 3, r1 mtdbatu 0, r1 mtdbatl 0, r1 mtdbatu 1, r1 mtdbatl 1, r1 mtdbatu 2, r1 mtdbatl 2, r1 mtdbatu 3, r1 mtdbatl 3, r1 isync sync lis r1, 0x8000 isync mtsr sr0, r1 mtsr sr1, r1 mtsr sr2, r1 mtsr sr3, r1 mtsr sr4, r1 mtsr sr5, r1 mtsr sr6, r1 mtsr sr7, r1 mtsr sr8, r1 mtsr sr9, r1 mtsr sr10, r1 mtsr sr11, r1 mtsr sr12, r1 mtsr sr13, r1 mtsr sr14, r1 mtsr sr15, r1 isync sync sync/* * Get processor type */ mfspr r14, PVR rlwinm r14, r14, 16, 16, 31 /* Get 16 msb */ cmpwi r14, CPU_TYPE_750 beq init_750 cmpwi r14, CPU_TYPE_7400 beq init_750 b init_unknown_cpu init_750: mfspr r3, HID0 lis r4, 0xffff ori r4, r4, 0x3fff and r3, r3, r4 sync isync mtspr HID0, r3 /* Turn off L1 caches */ sync isync li r4, 0x0c00 or r3, r3, r4 mtspr HID0, r3 /* Clear L1 caches *//* Set r16 to the load vs link offset. */init_unknown_cpu: bl 1f1: mflr r3 lis r16, 0xffff and. r16, r16, r3 lis r4, HI(start) sub r16, r16, r4 /* R16 is now load offset *//* * Find out if executing in ROM or RAM. */ lis r4, 0xf000 /* Last 256Mb segment */ and. r4, r4, r3 lis r15, 0x0200 /* assume 32 MB if ramloaded */ beq in_ram /* We are ram loaded! *//* * We are executing from ROM. We have to create the WORLD as we want it! * Start by doing GT chip selects and SDRAM initilization. * * Set up the internal address for the GT96132. For a large memory * system we would like to have it high up in memory to allow the * lower memory space to hold a contigous area of our memory. * We also set up r25 to point at the base address. */ lis r5, HI(GT_BASE_ADDR_DEFAULT) ori r5, r5, INTERNAL_SPACE_DECODE li r6, (GT_BASE_ADDR >> 21) stwbrx r6, 0, (r5) lis r25, HI(GT_BASE_ADDR)/**/#ifdef notyet GT_REGAD(CPU_CONF) /* CPU interface parameters, */ lwbrx r6, 0, (r5) /* change from default */ stwbrx r6, 0, (r5) sync#endif/**/ GT_REGWR(GT_DEV0_PAR, 0x386fffff) /* CS0 - Flash on DEV module */ GT_REGWR(GT_DEV1_PAR, 0x386fffff) /* CS1 - Flash card */ GT_REGWR(GT_DEV2_PAR, 0x144fffff) /* CS2 - UART, clock & com */ GT_REGWR(GT_DEV3_PAR, 0x384fffff) /* CS3 - 0 WAN & PLD */ GT_REGWR(CS_2_0_LOW_DECODE_ADDRESS, IO_BASE >> 21) GT_REGWR(CS_2_0_HIGH_DECODE_ADDRESS, (IO_BASE + IO_SIZE - 1) >> 21) GT_REGWR(CS_0_LOW_DECODE_ADDRESS, FLASH_BASE >> 20) GT_REGWR(CS_0_HIGH_DECODE_ADDRESS, (FLASH_BASE + FLASH_SIZE - 1) >> 20) GT_REGWR(CS_1_LOW_DECODE_ADDRESS, FCRD_BASE >> 20) GT_REGWR(CS_1_HIGH_DECODE_ADDRESS, (FCRD_BASE + FCRD_SIZE - 1) >> 20) GT_REGWR(CS_2_LOW_DECODE_ADDRESS, UART_BASE >> 20) GT_REGWR(CS_2_HIGH_DECODE_ADDRESS, (UART_BASE + UART_SIZE - 1) >> 20) bl initdbglednum li r3, 0 bl dbglednum /* CODE 000 */ DELAY(1000000) /* Flash it shortly, 'lamp test' */ li r3, 7 bl dbglednum /* CODE 111 - ALIVE */ DELAY(1000000) /* Flash it shortly, 'lamp test' */ li r3, 1 bl dbglednum /* CODE 001 - Mapping setup *//* Now we can start to print on serial console (if present) */ bl init_serial PRINTSTR("\r\n\r\n\r\nPMON/2000 PPC Initializing. Standby...\r\n") GT_REGWR(CS_3_BOOTCS_LOW_DECODE_ADDRESS, WAN_BASE >> 21) GT_REGWR(CS_3_BOOTCS_HIGH_DECODE_ADDRESS, (0xffffffff) >> 21) GT_REGWR(CS_3_LOW_DECODE_ADDRESS, WAN_BASE >> 20) GT_REGWR(CS_3_HIGH_DECODE_ADDRESS, (WAN_BASE + WAN_SIZE - 1) >> 20) GT_REGWR(BOOTCS_LOW_DECODE_ADDRESS, BOOT_BASE >> 20) GT_REGWR(BOOTCS_HIGH_DECODE_ADDRESS, (BOOT_BASE + BOOT_SIZE - 1) >> 20) GT_REGAD(GT_BOOT_PAR) /* CS3 and BootCS width detection */ lwbrx r6, 0, r5 andis. r6, r6, 0x0030 cmpwi r6, 0x0 bne boot_32_bit GT_REGWR(GT_BOOT_PAR, 0x144fffff) /* BootCS - 8bit Flash-AM29LV040B-120 */ DBGPRINTSTR("Boot 8 bit\r\n") b cont_initboot_32_bit: GT_REGWR(GT_BOOT_PAR, 0xf4a8241c) /* BootCS - 32bit Flash-i28F640J3A-120 */ DBGPRINTSTR("Boot 32 bit\r\n")cont_init: xor r0, r0, r0/* * Configure SDRAM. Use SPD data to figure out module size and config. */#ifdef notyet bl boot_i2c_init /* Yep, initialize the I2C interface */#endif li r3, 2 bl dbglednum /* CODE 010 - Memory module probing */ DBGPRINTSTR("Probing MAIN SDRAM module\r\n") li r3, 0x600 bl probe_sdram_size /* Probe MAIN SDRAM module */ or r17, r3, r3 DBGPRINTSTR("Probing SECONDARY SDRAM module\r\n") li r3, 0x400 bl probe_sdram_size /* Probe SECONDARY SDRAM module */ or r18, r3, r3#ifndef notyet lis r17, HI(0x02000000) /* Assume 32 meg module */ li r18, 0#endif add. r15, r17, r18 /* Compute total memory size */ beq bootinit_nomem /* no module found */ li r3, 3 bl dbglednum/* * Note! We use r11, r12 and r13 to store some common config data. * This code assumes that both memory modules (if two are used) are * of the same type, size and speed. */ /* Turn off all decoders first */ GT_REGWR(SCS_1_0_LOW_DECODE_ADDRESS, 0xfff) GT_REGWR(SCS_1_0_HIGH_DECODE_ADDRESS, 0x0) GT_REGWR(SCS_3_2_LOW_DECODE_ADDRESS, 0xfff) GT_REGWR(SCS_3_2_HIGH_DECODE_ADDRESS, 0)/* Configure MAIN SDRAM module if poulated */ cmpwi r17, 0 beq sdram_slot1_config DBGPRINTSTR("INIT MAIN SDRAM module\r\n")#ifdef notyet li r3, 0x61f /* Get bank density */ bl boot_i2c_read or r12, r3, r3 li r3, 0x604 /* Get address lines */ bl boot_i2c_read or r13, r3, r3 li r3, 0x615 /* Get module type */ bl boot_i2c_read or r11, r3, r3 li r3, 0x605 /* Get number of module banks */ bl boot_i2c_read#else li r11, 0 li r12, 8 li r13, 9 li r3, 1#endif GT_REGWR(SCS_1_0_LOW_DECODE_ADDRESS, 0) /* Module starts at address 0 */ GT_REGAD(SCS_1_0_HIGH_DECODE_ADDRESS) srwi r6, r17, 21 /* Make end value for GT reg */ addi r6, r6, -1 stwbrx r6, 0, (r5) cmpwi r3, 2 beq sdram_slot0_2bank DBGPRINTSTR("Single bank\r\n") GT_REGWR(SCS_0_LOW_DECODE_ADDRESS, 0) /* Module starts at address 0 */ GT_REGAD(SCS_0_HIGH_DECODE_ADDRESS) srwi r6, r17, 20 addi r6, r6, -1 stwbrx r6, 0, (r5) GT_REGWR(SCS_1_LOW_DECODE_ADDRESS, 0xfff) /* disable */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -