📄 cstartup.s43
字号:
/**************************************************
*
* System initialization code for the MSP430 IAR Systems C/EC++ Compiler.
*
* Copyright 2002-2003 IAR Systems. All rights reserved.
*
* $Revision: 1.19 $
*
**************************************************/
//
// There are two libraries provided with compilers from IAR Systems,
// CLib and DLib. This file is designed to work with both libraries.
// Some parts of it is DLib-specific. However, those parts will not
// be included when building an appplication using CLib.
//
//
// Please define one of the following preprocessor symbols in order to
// costomize the system initialization process.
//
// IGNORE_SEG_INIT -- To remove segment initialization.
// IGNORE_DATA16_DATA -- To remove segment initialization for DATA16 data.
//
// Note: In the current version the symbols "IGNORE_SEG_INIT" and
// "IGNORE_DATA16_DATA" will perform the same task. However, both are
// supported in order to be compatible with other IAR Compilers.
//
#include "macros.m43"
#include "cfi.m43"
#define XRSEGCSTART RSEG CSTART:CODE:NOROOT(1)
XCFI_NAMES libNames
XCFI_COMMON libCommon, libNames
// ---------------------------------------------------------
// Define reset vector.
//
MODULE ?reset_vector
RSEG RESET:CONST:NOROOT(1)
PUBLIC ?reset_vector
EXTERN __program_start
?reset_vector:
DC16 __program_start
ENDMOD
// ---------------------------------------------------------
// The cstartup code -- call __low_level_init, perform initialization,
// call constructors and call main. If main returns the exit system
// is started.
//
MODULE ?cstart
//
// Ensure that this is build with the same "positions independent
// code" settings as the compiler uses.
//
XPICRTMODEL
//
// Forward declarations of segments.
//
RSEG HEAP:DATA:NOROOT(1)
RSEG CSTACK:DATA:NOROOT
RSEG DATA16_Z:DATA:NOROOT
RSEG DATA16_I:DATA:NOROOT
RSEG DATA16_C:DATA:NOROOT
RSEG DATA16_ID:DATA:NOROOT
// ---------------------------------------------------------
// System initialization.
//
XRSEGCSTART
PUBLIC __program_start
EXTERN ?reset_vector
REQUIRE ?reset_vector
__program_start:
PUBLIC ?cstart_begin
?cstart_begin:
//
// Initialize SP to point to the top of the stack.
//
MOV #SFE(CSTACK), SP
//
// Ensure that main is called.
//
REQUIRE ?cstart_call_main
// -----------------------------------------------
// Call __low_level_init to perform initialization before initializing
// segments and calling main. If the function returns 0 no segment
// initialization should take place.
//
// Link with your own version of __low_level_init to override the
// default action: to do nothing but return 1.
//
XRSEGCSTART
PUBLIC ?cstart_call_low_level_init
EXTERN __low_level_init
?cstart_call_low_level_init:
XCALL #__low_level_init
CMP #0, W0
JEQ ?cstart_call_main
// -----------------------------------------------
// Segment initialization:
//
// xxx_Z -- uninitialized data that are filled with zeros.
// xxx_I -- initialized data that gets the values from the corresponding
// xxx_ID segment.
//
#ifndef IGNORE_SEG_INIT
#ifndef IGNORE_DATA16_DATA
//
// Clear DATA16_Z.
//
XRSEGCSTART
PUBLIC ?cstart_init_zero
EXTERN __data16_memzero
?cstart_init_zero:
MOV #SFB DATA16_Z, W0
MOV #sizeof DATA16_Z, W1
XCALL #__data16_memzero
//
// Copy DATA16_ID to DATA16_I
//
XRSEGCSTART
PUBLIC ?cstart_init_copy
EXTERN __data16_memcpy
?cstart_init_copy:
MOV #SFB DATA16_I, W0
MOV #SFB DATA16_ID, W1
PUSH.W #sizeof DATA16_I
XCALL #__data16_memcpy
ADD #2, SP
#endif // IGNORE_DATA16_DATA
#endif // IGNORE_SEG_INIT
// -----------------------------------------------
// Call constructors of static objects.
//
RSEG DIFUNCT:CONST:NOROOT(1)
XRSEGCSTART
PUBLIC ?cstart_call_ctors
EXTERN __call_ctors
?cstart_call_ctors:
MOV.W #SFB DIFUNCT & 0xffff, R12
MOV.W #SFE DIFUNCT & 0xffff, R14
#if __CORE__==__430X_CORE__
MOV.W #SFB DIFUNCT >> 16, R13
MOV.W #SFE DIFUNCT >> 16, R15
#endif
XCALL #__call_ctors
// -----------------------------------------------
// Call main() with no arguments and then exit using the return value
// of main as the parameter.
//
XRSEGCSTART
PUBLIC ?cstart_call_main
EXTERN main
EXTERN exit
?cstart_call_main:
XCALL #main
XCALL #exit
PUBLIC ?cstart_end
?cstart_end:
// Note: "ENDMOD label" means code that this module is the
// start of the application.
ENDMOD __program_start
// ---------------------------------------------------------
// __low_level_init
//
// The only action of this default version of __low_level_init is to
// return 1. By doing so it signals that normal initialization of data
// segments should be done.
//
// A customized version of __low_level_init may be created in order to
// perform initialization before initializing segments and calling main
// and/or to skip initialization of data segments under certain
// circumstances.
//
// For further details see sample file lowinit.c
//
MODULE lowinit
PUBLIC __low_level_init
RSEG CODE:CODE:NOROOT(1)
__low_level_init:
MOV #1, W0 // By returning 1 this function
XRET // indicates that the normal
// initialization should take place
ENDMOD
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -