⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 start.s

📁 MIPS处理器的bootloader,龙芯就是用的修改过的PMON2
💻 S
📖 第 1 页 / 共 2 页
字号:
/*	$Id: start.S,v 1.9 2002/11/07 15:05:24 pefo Exp $ *//* * Copyright (c) 2000-2002 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/gt64260reg.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	GT64260 macros * *   r12-r13	scratch *   r14	processor type (from PVR reg) *   r15	memory size accumulator *   r16	load offset *   r25	GT64260 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#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/* *  Link start is 0x10000. Pad up to reset vector. */	.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	cmpwi   r14, CPU_TYPE_750FX	beq     init_750FX	b	init_unknown_cpuinit_750FX:	li	r1, 0x0	mtspr	560, r1		/*	mtibatu	4, r1 */	mtspr	561, r1		/*	mtibatl	4, r1 */	mtspr	562, r1		/*	mtibatu	5, r1 */	mtspr	563, r1		/*	mtibatl	5, r1 */	mtspr	564, r1		/*	mtibatu	6, r1 */	mtspr	565, r1		/*	mtibatl	6, r1 */	mtspr	566, r1		/*	mtibatu	7, r1 */	mtspr	567, r1		/*	mtibatl	7, r1 */	mtspr	568, r1		/*	mtdbatu	4, r1 */	mtspr	569, r1		/*	mtdbatl	4, r1 */	mtspr	570, r1		/*	mtdbatu	5, r1 */	mtspr	571, r1		/*	mtdbatl	5, r1 */	mtspr	572, r1		/*	mtdbatu	6, r1 */	mtspr	573, r1		/*	mtdbatl	6, r1 */	mtspr	574, r1		/*	mtdbatu	7, r1 */	mtspr	575, r1		/*	mtdbatl	7, r1 */	isync	sync	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		/* 32MB default for 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 GT64260. 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        lis     r6, 0x100                       # no swapping        ori     r6, r6, (GT_BASE_ADDR >> 20)        stwbrx  r6, 0, (r5)        lis     r25, HI(GT_BASE_ADDR)/**/        GT_REGAD(CPU_CONF)		/*  CPU interface parameters, */        lwbrx   r6, 0, (r5)		/*  change from default */	oris	r6, r6, 0x4000		/* Sysclock synchronous */	ori	r6, r6, 0xa000		/* AACK and TA delays */        stwbrx  r6, 0, (r5)        sync/**/#ifdef GT_REV_A        GT_REGWR(GT_DEV0_PAR, 0x2020509b) /* CS0 - 32bit SRAM-MT58L256L18P1-6 */        GT_REGWR(GT_DEV1_PAR, 0x0fcfffff) /* CS1 - RTC-Dallas DS1501 */        GT_REGWR(GT_DEV2_PAR, 0x00059bd4) /* CS2 - UART-EXAR ST16C2552 */#else        GT_REGWR(GT_DEV0_PAR, 0xf02051a9) /* CS0 - 32bit SRAM-MT58L256L18P1-6 */        GT_REGWR(GT_DEV1_PAR, 0xffcfffff) /* CS1 - RTC-Dallas DS1501 */        GT_REGWR(GT_DEV2_PAR, 0xf0059bd4) /* CS2 - UART-EXAR ST16C2552 */#endif	GT_REGWR(CS_0_LOW_DECODE_ADDRESS, SRAM_BASE >> 20)	GT_REGWR(CS_0_HIGH_DECODE_ADDRESS, (SRAM_BASE + SRAM_SIZE - 1) >> 20)	GT_REGWR(CS_1_LOW_DECODE_ADDRESS, RTC_BASE >> 20)	GT_REGWR(CS_1_HIGH_DECODE_ADDRESS, (RTC_BASE + RTC_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)	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) */	PRINTSTR("\r\n\r\n\r\nPMON2000 PowerPC Initializing. Standby...\r\n")	GT_REGWR(CS_3_LOW_DECODE_ADDRESS, FLASH_BASE >> 20)	GT_REGWR(CS_3_HIGH_DECODE_ADDRESS, (FLASH_BASE + FLASH_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#ifdef GT_REV_A        GT_REGWR(GT_DEV3_PAR, 0x04a82f1c) /* CS3 - 32bit Flash-i28F640J3A-120 */        GT_REGWR(GT_BOOT_PAR, 0x000b5e7c) /* BootCS - 8bit Flash-AM29LV040B-120 */#else        GT_REGWR(GT_DEV3_PAR, 0xf4a8241c) /* CS3 - 32bit Flash-i28F640J3A-120 */        GT_REGWR(GT_BOOT_PAR, 0xf00b5e7c) /* BootCS - 8bit Flash-AM29LV040B-120 */#endif	DBGPRINTSTR("Boot 8 bit\r\n")        b       cont_initboot_32_bit:#ifdef GT_REV_A        GT_REGWR(GT_DEV3_PAR, 0x000b5e7c) /* CS3 - 8bit Flash-AM29LV040B-120 */        GT_REGWR(GT_BOOT_PAR, 0x04a82f1c) /* BootCS - 32bit Flash-i28F640J3A-120 */#else        GT_REGWR(GT_DEV3_PAR, 0xf00b5e7c) /* CS3 - 8bit Flash-AM29LV040B-120 */        GT_REGWR(GT_BOOT_PAR, 0xf4a8241c) /* BootCS - 32bit Flash-i28F640J3A-120 */#endif	DBGPRINTSTR("Boot 32 bit\r\n")cont_init:	xor	r0, r0, r0/* *  Configure SDRAM. Use SPD data to figure out module size and config. */	bl	boot_i2c_init		/* Yep, initialize the I2C interface */	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	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. */	GT_REGWR(SCS0_LOW, 0xfff)	/* Turn off all decoders first */        GT_REGWR(SCS0_HIGH, 0x0)        GT_REGWR(SCS1_LOW, 0xfff)        GT_REGWR(SCS1_HIGH, 0)        GT_REGWR(SCS2_LOW, 0xfff)        GT_REGWR(SCS2_HIGH, 0)        GT_REGWR(SCS3_LOW, 0xfff)        GT_REGWR(SCS3_HIGH, 0)/*  Configure MAIN SDRAM module if poulated */	cmpwi	r17, 0	beq	sdram_slot1_config	DBGPRINTSTR("INIT MAIN SDRAM module\r\n")	li	r3, 0x61f		/* Get bank density */	bl	boot_i2c_read	or	r12, r3, r3	li	r3, 0x604		/* Get bank density */	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	cmpwi	r3, 2	beq	sdram_slot0_2bank	DBGPRINTSTR("Single bank\r\n")	GT_REGWR(SCS0_LOW, 0)		/* Module starts at address 0 */	GT_REGAD(SCS0_HIGH)	srwi	r6, r17, 20		/* Make end value for GT reg */	addi	r6, r6, -1	stwbrx	r6, 0, (r5) 	b	sdram_slot1_configsdram_slot0_2bank:	DBGPRINTSTR("Dual bank\r\n")	GT_REGWR(SCS0_LOW, 0)		/* Module starts at address 0 */	GT_REGAD(SCS1_LOW)	srwi	r6, r17, 21	stwbrx	r6, 0, (r5) 	GT_REGAD(SCS0_HIGH)	addi	r6, r6, -1	stwbrx	r6, 0, (r5) 	GT_REGAD(SCS1_HIGH)	srwi	r6, r17, 20	addi	r6, r6, -1	stwbrx	r6, 0, (r5) /*  Configure SECONDARY SDRAM module if poulated */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -