zipstart_init.s

来自「一个很好的嵌入式linux平台下的bootloader」· S 代码 · 共 686 行 · 第 1/2 页

S
686
字号
have_ram:	 /*	  * If this is the 64-bit version, turn on the KX bit	  * to allow 64-bit accesses.	  */#ifdef __long64		mfc0	t0,C0_SR		or	t0,t0,M_SR_KX		mtc0	t0,C0_SR#endif#------------------------------------------------------------------------------	/*	 * K0 contains the RAM size (and therefore the top of RAM 	 * offset).  Start there, and subtract the amount of memory	 * we expect to use.  If we have more than 256MB of	 * physical memory, work backwards from the 256MB 	 * boundary.	 */  __CalcMemTop:   li	MEMTOP,256		# 256MB boundary		bgt	k0,MEMTOP,1f		# use 256MB if k0 is greater		move	MEMTOP,k0		# otherwise keep top1:		sll	MEMTOP,20		# make into byte amount	/*	 * DRAM is now running, and we're alive in cacheable memory	 * on cpu0 in K0SEG.  Set up GP.	 */		la	gp,_gp#------------------------------------------------------------------------------	/*	 * Zero BSS         */		SETLEDS('Z','B','S','S')		la	a0,segment_table__ZeroBss:		LR	v0,R_SEG_FBSS(a0)		LR	v1,R_SEG_END(a0)1:		SR	zero,0(v0)		# Zero one cacheline at a time		SR	zero,(REGSIZE*1)(v0)		SR	zero,(REGSIZE*2)(v0)		SR	zero,(REGSIZE*3)(v0)		add	v0,REGSIZE*4		blt	v0,v1,1b#------------------------------------------------------------------------------	/*	 * Copy initialized data         */		SETLEDS('D','A','T','A')		la	a0,segment_table__CopyData:		LR	t1,R_SEG_ETEXT(a0)		li	t0,15		add	t1,t0		not	t0		and	t1,t0		# t1 = _etext rounded up to 16-byte boundary					LR	t2,R_SEG_FDATA(a0)		LR	t3,R_SEG_EDATA(a0)1:		LR	t4,0(t1)	# read one cache line		LR	t5,(REGSIZE*1)(t1)		LR	t6,(REGSIZE*2)(t1)		LR	t7,(REGSIZE*3)(t1)		SR	t4,0(t2)	# write one cache line		SR	t5,(REGSIZE*1)(t2)		SR	t6,(REGSIZE*2)(t2)		SR	t7,(REGSIZE*3)(t2)		add	t1,(REGSIZE*4)		add	t2,(REGSIZE*4)		bltu	t2,t3,1b#------------------------------------------------------------------------------	/*         * Remember total amount of memory.  This is *still* in k0	 * after all this time.  Hopefully.	 */__MemVars:		SR	k0,mem_totalsize		move	v0,zero		la	a0,segment_table	# trashed by l2 cache flush		LR	v0,R_SEG_FDATA(a0)		LR	v1,R_SEG_END(a0)		ADD	v1,7			# Realign _END so it 		and	v1,~7			# is on a 64-bit boundary.		SR	v0,mem_bottomofmem		SR	v1,mem_heapstart		add	v1,(CFG_HEAP_SIZE*1024)	# Otherwise		add	v1,STACK_SIZE		SR	v1,mem_topofmem		LR	t1,R_SEG_FTEXT(a0)		LR	t0,R_SEG_ETEXT(a0)		sub	t0,t0,t1		SR	t0,mem_textsize		SR	t1,mem_textbase#------------------------------------------------------------------------------#if CFG_MULTI_CPUS	/*	 * Let secondary CPU(s) run their idle loops.  Set the 	 * mailbox register to our relocation factor so we can read	 * it out of the mailbox register and relocate GP properly.	 */		move	a0,zero/*		CALLINIT_KSEG0(init_table,R_INIT_ALTCPU_START2) */#endif#------------------------------------------------------------------------------	/*	 * Set up the "C" stack and jump to the main routine.         */		SETLEDS('Z','L','D','R')		LR	sp,mem_heapstart		ADD	sp,((CFG_HEAP_SIZE*1024)+STACK_SIZE - 8)		li	a0,0			# call as "cfe_main(0,0)"		li	a1,0		li	a2,0		la	a3,_elf_start__LaunchMain:		jal	zs_main	/*	 * Terminate the simulator.	 */crash_sim:      li $2,1                li $4,0                syscall	0xCA		b	cpu_reset/*  *********************************************************************    *  CPU_KSEG0_SWITCH    *      *  Hack the return address so we will come back in KSEG0    *      *  Input parameters:     *  	   nothing    *  	       *  Return value:    *  	   nothing    ********************************************************************* */LEAF(cpu_kseg0_switch)		and	ra,(K0SIZE-1)		or	ra,K0BASE		jr	raEND(cpu_kseg0_switch)/*  *********************************************************************    *  CFE_LAUNCH    *      *  Start the user program.  The program is passed a handle    *  that must be passed back when calling the firmware.    *    *  Parameters passed to the called program are as follows:    *    *      a0 - memory size    *      a1 -     *      a2 -     *      a3 -     *      *  Input parameters:     *  	   a0 - entry vector    *  	       *  Return value:    *  	   does not return    ********************************************************************* */LEAF(cfe_launch)		sub	sp,8		SR	a0,0(sp)	/*	 * Mask all interrupts.	 */		mfc0	v0,C0_SR		# Get current interrupt flag		li	v1,M_SR_IE		# master interrupt control		not	v1			# disable interrupts		and	v0,v1			# SR now has IE=0		mtc0	v0,C0_SR		# put back into CP0	/*	 * Flush the D-Cache, since the program we loaded is "data".	 * Invalidate the I-Cache, so that addresses in the program	 * region will miss and need to be filled from the data we 	 * just flushed above.	 */		SETLEDS('L','1','2','F')		li	a0,CFE_CACHE_FLUSH_D | CFE_CACHE_FLUSH_L2		JAL(CPUCFG_CACHEOPS)		li	a0,CFE_CACHE_INVAL_I		JAL(CPUCFG_CACHEOPS)#ifdef _SB1250_PASS1_WORKAROUNDS_		SETCCAMODE(v0,K_CFG_K0COH_COHERENT) /* cacheable coherent */#endif			/*	 * Launch the firmware.	 */		LR	a0,mem_totalsize		move	a1,zero		move	a2,zero		move	a3,zero		LR	t0,0(sp)__Banzai:		jr	t0END(cfe_launch)/*  *********************************************************************    *  TLB Fill Exeption Handler    ********************************************************************* */cpu_tlbfill:			j	_exc_entry/*  *********************************************************************    *  XTLB Fill Exception Handler    ********************************************************************* */cpu_xtlbfill:			j	_exc_entry/*  *********************************************************************    *  Cache Error Exception Handler    ********************************************************************* */cpu_cacheerr:	/*	 * Force stack pointer to be uncached to discourage	 * future use of the cache.	 */		or	sp,K1BASE		j	_exc_entry/*  *********************************************************************    *  API entry    ********************************************************************* */		.globl cpu_apientrycpu_apientry:		li	t0,PHYS_TO_K0(CFE_LOCORE_GLOBAL_APIEPT)		LR	t0,0(t0)		beq	t0,zero,1f		jr	t0			# Jump to API vector1:		li	v0,-1			# No entry point installed		j	ra/*  *********************************************************************    *  General Exception Handler    ********************************************************************* */cpu_exception:		j	_exc_entry/*  *********************************************************************    *  General Interrupt Handler    ********************************************************************* */cpu_interrupt:		j	_exc_entry/*  *********************************************************************    *  EJTAG Debug Exception Handler    ********************************************************************* */cpu_ejtag:		.set push		.set mips64		deret		.set pop		nop		j	cpu_reset/*  *********************************************************************    *  End    ********************************************************************* */

⌨️ 快捷键说明

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