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

📄 cstartup.s90

📁 Mega8完美下载 包含源程序
💻 S90
字号:
;----------------------------------------------------------------------------
;		    CSTARTUP.S90
;
;	This module contains the AVR C and EC++ startup
;	routine and must usually be tailored to suit
;	customer's hardware.
;
;   File version:   $Revision: 1.2 $
;
;----------------------------------------------------------------------------
#include	"macros.m90"

;----------------------------------------------------------------------------
; Set up the INTVEC segment with a reset vector		
;----------------------------------------------------------------------------
        NAME	?RESET
;         NAME C_STARTUP   

        EXTERN  ?C_STARTUP
;        PUBLIC  __RESTART

	COMMON	INTVEC:CODE:ROOT(1)	; Align at an even address

;        EXTERN  ?C_STARTUP

	ORG	$0
;__RESTART:
	XJMP	?C_STARTUP

        ENDMOD

;----------------------------------------------------------------------------
; Forward declarations of segments used in initialization
;----------------------------------------------------------------------------
	RSEG	CSTACK(0)
	RSEG	RSTACK(0)

;----------------------------------------------------------------------------
; Perform C initialization
;----------------------------------------------------------------------------
	MODULE	?C_STARTUP

	EXTERN	__low_level_init
	EXTERN	__segment_init
#ifdef _ECLIB
	EXTERN	__call_ctors
#endif /* _ECLIB */
	EXTERN	main
	EXTERN	exit
	EXTERN	_exit

;----------------------------------------------------------------------------
; If the return address stack is located in external SRAM, make sure that
; you have uncommented the correct code in __low_level_init!!!
;----------------------------------------------------------------------------
	RSEG	CODE:CODE:NOROOT(1)
	PUBLIC	?C_STARTUP
	PUBLIC	__RESTART

__RESTART:
?C_STARTUP:
	REQUIRE	?SETUP_STACK

	RSEG	CODE:CODE:NOROOT(1)
	PUBLIC	__RSTACK_in_external_ram

__RSTACK_in_external_ram:
        LDI     R16,0xC0
        OUT     0x35,R16	;Enable the external SRAM with a wait state

;----------------------------------------------------------------------------
; Set up the CSTACK and RSTACK pointers.
;----------------------------------------------------------------------------
	RSEG	CODE:CODE:NOROOT(1)
?SETUP_STACK:
	;; Return address stack (RSTACK)
	LDI	R16,LOW(SFE(RSTACK))
        SUBI    R16,0x03
	OUT	0x3D,R16
#if A90_POINTER_REG_SIZE > 1
	LDI	R16,HIGH(SFE(RSTACK))
        SBCI    R16,0x00
	OUT	0x3E,R16
#endif

	;; Data stack (CSTACK)
	LDI	Y0,LOW(SFE(CSTACK))
#if A90_POINTER_REG_SIZE > 1
	LDI	Y1,HIGH(SFE(CSTACK))
#if A90_POINTER_REG_SIZE > 2
        LDI	Z0,HWRD(SFE(CSTACK))
        OUT     RAMPY,Z0
#endif
#endif

	REQUIRE	?call_low_level_init

;----------------------------------------------------------------------------
; Clear R15 so that it can be used as zero register by the code generator.
; The compiler will emit a "REQUIRE ?zero_reg_initialization" statement if
; this optimization has been enabled.
;----------------------------------------------------------------------------
	RSEG	CODE:CODE:NOROOT(1)
	PUBLIC	?zero_reg_initialization

?zero_reg_initialization:
	CLR	R15

;----------------------------------------------------------------------------
; Call __low_level_init to do low level initializatons. Modify the supplied
; __low_level_init module to add your own initialization code or to
; remove segment initialization (by returning 0).
;----------------------------------------------------------------------------
	RSEG	CODE:CODE:NOROOT(1)
	PUBLIC	?call_low_level_init

?call_low_level_init:
	XCALL	__low_level_init

	REQUIRE	?cstartup_call_main

;----------------------------------------------------------------------------
; Call __segment_init to initialize segments.
;----------------------------------------------------------------------------
	RSEG	CODE:CODE:NOROOT(1)
	PUBLIC	?need_segment_init

?need_segment_init:
	TST	P0
	BREQ	?skip_segment_init
	XCALL	__segment_init
?skip_segment_init:

;----------------------------------------------------------------------------
;	Call the constructors of all global objects. This code will only
;	be used if any EC++ modules defines global objects that need to
;	have its constructor called before main.
;----------------------------------------------------------------------------
#ifdef _ECLIB
	RSEG	DIFUNCT(0)
#endif /* _ECLIB */
	RSEG	CODE:CODE:NOROOT(1)

	PUBLIC	?call_ctors

?call_ctors:
#ifdef _ECLIB
	LDI	P0,LOW(SFB(DIFUNCT))
	LDI	P1,SFB(DIFUNCT) >> 8

	LDI	P2,LOW(SFE(DIFUNCT))
	LDI	P3,SFE(DIFUNCT) >> 8

	XCALL	__call_ctors
#endif /* _ECLIB */

;----------------------------------------------------------------------------
;	Call main
;----------------------------------------------------------------------------
	RSEG	CODE:CODE:NOROOT(1)

	PUBLIC	?cstartup_call_main

?cstartup_call_main:
#if MEMORY_MODEL != LARGE_MEMORY_MODEL
#if A90_PROC_OPTION > 1
	LDI	R16,0
	OUT	RAMPZ,R16
#if A90_POINTER_REG_SIZE > 2
	OUT	RAMPY,R16
	OUT	RAMPX,R16
#endif /* A90_POINTER_REG_SIZE > 2 */
#endif /* A90_PROC_OPTION > 1 */
#endif /* MEMORY_MODEL != LARGE_MEMORY_MODEL */

	XCALL	main
	XCALL	exit
	XJMP	_exit

	END

⌨️ 快捷键说明

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