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

📄 start.s.svn-base

📁 我们自己开发的一个OSEK操作系统!不知道可不可以?
💻 SVN-BASE
字号:
/*
 * File:		start.S
 *
 * Discription:		startup code
 *
 */
 
#include "board_mpc555.h"
#include "mpc555.h"
#include "ppc_asm.h"

		.org EXC_OFF_SYS_RESET				.globl _start
  		
_start:
	
/*Set the msr register*/	
		lis r3, CFG_MSR@h
		ori r3, r3, CFG_MSR@l
		mtmsr r3		
		mtspr SRR1, r3  

/*Set the bbcmcr register*/	
		lis r3, CFG_BBCMCR@h
		ori r3, r3, CFG_BBCMCR@l
		mtspr BBCMCR, r3		/*Set the immr register, 638 is its number*/
		lis r3, CFG_IMMR_SET@h
		ori r3, r3, CFG_IMMR_SET@l
		mtspr IMMR, r3			
/* Set up the stack in internal SRAM */         	
		lis	r1, __SP_INIT@h
		ori	r1, r1, __SP_INIT@l	 
		
/*Make r0 be 0*/
		xor r0, r0, r0
		
/*Clear final stack frame so that stack backtraces terminate cleanly*/
		stwu	r0, -4(r1)			
		stwu	r0, -4(r1)	
		
/*initalize some cpu internal memory space registers, r3 is immr*/
		bl cpu_init_f			/*run low-level board init code, and it's empty right now! (from Flash)
* Maybe we have no external RAM, so check it! If we just have small 
* external RAM, what can I do?
*/
/*		#if defined(EXTERNAL_RAM)
		bl board_init_f	
		#endif
*/		
/*board_init_f will never return, so if we don't execute it, it means that 
* we don't need to relocate the code, therefore let's just jump to the entry
* point of OS.
*/
		lis r3, jump2OS@h
		ori r3, r3, jump2OS@l
		mtlr r3
		blrl
							
/*Exception handler*/		
		.globl _start_of_vectors
_start_of_vectors:

/*	Machine Check
 *	Override the behavior by over-writing the handler code in RAM.
 */	
		.org 	0x200
		b	_start

/*	 Data Storage
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x300
		b	_start

/*	 Instruction Storage
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x400
		b	_start

/*	 External Interrupt
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x500
		b    Interrupt_ESR

/*    Alignment
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x600
		b	_start

/*    Program
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x700
		b	_start

/*	Floating Point Unavailable
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x800
		b	_start

/* Decrementer Interrupt
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x900
		stwu     r1,-80(r1) #47条指令
            stw      r0,32(r1) #save working register
   
            mfsrr0    r0        #0=sr0
            stw     r0,12(1) #memory[1+12]=s0
            mfsrr1    r0       #save s1,0=s1
            stw    r0,16(r1) #memory[1+16]=s1 
            mtspr    81,r3    #set msr[ee]=0,msr[ri]=1
   
            mflr   r0          #get lr
            stw    r0,8(r1)    #save lr
            mfxer  r0
            stw    r0,20(r1)   #save xer
            mfspr  r0,CTR      #save ctr
            stw    r0,24(r1)
            mfcr   r0
            stw    r0,28(r1)    #save cr,以上15

            stw    r3,36(r1)    #save r3-12
            stw    r4,40(r1)  
            stw    r5,44(r1)    
            stw    r6,48(r1)
            stw    r7,52(r1) 
            stw    r8,56(r1)
            stw    r9,60(r1) 
            stw    10,64(r1)
            stw    r11,68(r1)
            stw    r12,72(r1)    
            lis  r4, OSTimeTick@h  #跳转到节拍处理函数
            ori  r4,r4,OSTimeTick@l 
            blr                    
   
            lis r5, 0x3           # 0x00030000 ,计数器重置。
            addi r5, r5, 0x0D40 # 0x30000 + 0xD40 = 0x30D40 = 200,000
            mtdec	r5       #  Re-load decrementer ,以上16条
   
            lwz    12,72(r1) #restore 12-5,16条指令
            lwz    r11,68(r1)
            lwz    10,64(r1)
            lwz    r9, 60(r1) 
            lwz    r8, 56(r1)
            lwz    r7, 52(r1)
            lwz    r6, 48(r1)
            lwz    r5, 44(r1)

            lwz    r0, 28(r1)#restore cr
            mtcr   r0   
            lwz    r0, 24(r1)#restore xer
            mtxer  r0 
            lwz    r0, 20(r1)#restore ctr
            mtspr  CTR, r0
            lwz    r0, 8(r1)#restore lr
            mtlr   r0 

            mtspr    82,r3    # clear recoverable bit,msr[RI]=0=msr[EE]
            lwz      r0,16(r1) #0=memory[1+16]
            mtsrr1   r0        #s1=0
            lwz    r0,12(r1)
            mtsrr0   r0        #restore s0	
            lwz    r4,40(r1) #restore working regster
            lwz    r3,36(r1)   
            lwz    r0,8(r1)  
            addi   r1,r1,80
            rfi

/*	 System Call
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0xC00
		b	_start

/*	 Trace
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0xD00
		b	_start

/*	 FP Assist
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0xE00
		b	_start

/*	Performance Monitor
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0xF00
		b	_start

/*	 	Software Emulation	Instruction TLB Miss
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x1000
		b	_start

/*	Instruction TLB Miss		Data Load TLB Miss
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x1100
		b	_start

/*	Data TLB Miss		Data Store TLB Miss
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x1200
		b	_start

/*	Instruction TLB Error Instruction address breakpoint
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x1300
		b	_start

/*	Data TLB Error	System management
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x1400
		b	_start

/*	Data breakpoint
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x1C00
		b	_start

/*	Instruction breakpoint
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x1D00
		b	_start

		
/*	Peripheral breakpoint
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x1E00
		b	_start

/*	Non-maskable development port
 *	Override the behavior by over-writing the handler code in RAM.
 */
		.org	0x1F00
		b	_start

		.globl _end_of_vectors
_end_of_vectors:
		.=0x2000			/*Maybe other*/
		

/*
 * void relocate_code (addr_sp, des_addr)
 *
 * This "function" does not return, instead it continues in RAM
 * after relocating the  code.
 *
 * r3 = dest
 * r4 = src
 * r5 = length in bytes
 */

		.globl relocate_code
relocate_code:
		
 /*Set new stack pointer in RAM*/
		mr r1, r3
		
/*Save copy of destination address in RAM*/
		mr r3, r4 
		
/*Source address*/
		lis r4, CFG_FLASH_BASE@h
		ori r4, r4, CFG_FLASH_BASE@l
		
/*???How can I get the length of code??? Assume that r5 is the length.
* Assume that init_end is the end of the code which will be defined in
* the linker file.
*/
        lis r5, init_end@h
        ori r5, r5, init_end@l
        sub r5, r5, r4
		
/* Now relocate code */
	      cmplw	cr1, r3, r4
		addi	r0, r5, 3 /*Set the immr register, 638 is its number*/
		lis r3, CFG_IMMR_SET@h
		ori r3, r3, CFG_IMMR_SET@l
		mtspr IMMR, r3	
		srwi.	r0, r0, 2
		beq	cr1, 4f	 	/* In place copy is not necessary	*/
		beq	4f		/* Protect against 0 count		*/
		mtctr	r0
		bge	cr1, 2f

		la	r8, -4(r4)
		la	r7, -4(r3)
	1:	lwzu	r0, 4(r8)
		stwu	r0, 4(r7)
		bdnz	1b
		b	4f

	2:	slwi	r0, r0, 2
		add	r8, r4, r0
		add	r7, r3, r0
	3:	lwzu	r0, -4(r8)
		stwu	r0, -4(r7)
		bdnz	3b

	4:	sync
		isync

/* We are done. Do not return, instead branch to OS initialization, now 
 * running from RAM. 
 */
		lis r3, jump2OS@h
		ori r3, r3, jump2OS@l
		mtlr r3
		blrl

/*Interrupt handler, add your code here*/		.globl Interrupt_ESR
 Interrupt_ESR:
 
 /*OSTimeTick()*/ 		.globl OSTimeTick
 OSTimeTick:

		
/*jump to entry point of OS*/			.globl jump2OS	 

jump2OS:
		lis      r3, test@ha
		addi     r3, r3, test@l
		mtlr     r3
		blrl 
		


⌨️ 快捷键说明

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