📄 start12.c
字号:
/* DO NOT DOWNLOAD, USE, COPY, MODIFY OR DISTRIBUTE THIS CODE OR ANY PORTIONS */
/* THEREOF UNLESS YOU AGREE TO THE FOLLOWING: */
/* This code is provided "AS IS" without warranty of any kind, to the full */
/* extent permitted by law. You may copy, use modify and distribute the code */
/* (including modifications) provided you agree to these terms and conditions,*/
/* however you do so at your own risk and you agree to indemnify Metrowerks */
/* for any claim resulting from your activities relating to the code. You must*/
/* include all Metrowerks notices with the code. If you make any */
/* modifications, you must identify yourself as co-author in the modified */
/* code. */
/* (C) Copyright. 2002 Metrowerks Corp. ALL RIGHTS RESERVED. */
/* */
/*****************************************************
start12.c - standard startup code
The startup code may be optimized to special user requests
----------------------------------------------------
Copyright (c) HIWARE AG, Basel, Switzerland
All rights reserved
Do not modify!
Note: ROM libraries are not implemented in this startup code
Note: C++ destructors of global objects are NOT yet supported in the HIWARE Object File Format.
To use this feature, please build your application with the ELF object file format.
*****************************************************/
#include "hidef.h"
#include "start12.h"
#if defined(__PROCESSOR_X4__) || defined(__HC12S__) /* In some early version DBNE/... did not work. */
#define DO_NOT_USE_TEST_BRANCHES 1 /* Do not use DBNE/TBEQ,.... */
#else
#define DO_NOT_USE_TEST_BRANCHES 0 /* Do use DBNE/TBEQ,.... */
#endif
#if defined(__HC12S__) && (defined(FAR_DATA) || defined(__BANKED__))
#error /* no banked support */
#endif
#pragma DATA_SEG __NEAR_SEG STARTUP_DATA /* _startupData can be accessed using 16 bit accesses. This is needed because it contains the stack top, and without stack, far data cannot be accessed */
struct _tagStartup _startupData; // read-only:
// _startupData is allocated in ROM and
// initialized by the linker
#pragma DATA_SEG DEFAULT
#if defined(FAR_DATA)
#include "non_bank.sgm"
// the init function must be in non banked memory if banked variables are used
// because _SET_PAGE is called, which may change any page register.
#ifdef __cplusplus
extern "C"
#endif
void _SET_PAGE(void); // the inline assembler needs a prototype
// this is a runtime routine with a special
// calling convention, dont use it in c code!
static void Init(void);
static void Fini(void);
#else
#include "default.sgm"
#if defined( __BANKED__) || defined(__LARGE__)
static void __far Init(void);
static void __far Fini(void);
#endif // defined( __BANKED__) || defined(__LARGE__)
#endif // FAR_DATA
/* define value and bits for Windef Register */
#define WINDEF (*(volatile unsigned char*) 0x37)
#if defined( __BANKED__) || defined(__LARGE__) || defined(__PPAGE__)
#define __ENABLE_PPAGE__ 0x40
#else
#define __ENABLE_PPAGE__ 0x0
#endif
#if defined(__DPAGE__)
#define __ENABLE_DPAGE__ 0x80
#else
#define __ENABLE_DPAGE__ 0x0
#endif
#if defined(__EPAGE__)
#define __ENABLE_EPAGE__ 0x20
#else
#define __ENABLE_EPAGE__ 0x0
#endif
#if !defined(FAR_DATA) && (defined( __BANKED__) || defined(__LARGE__))
static void __far Init(void)
#else
static void Init(void)
#endif
{
// purpose: 1) zero out RAM-areas where data is allocated
// 2) copy initialization data from ROM to RAM
// 3) call global constructors in C++
// called from: _Startup, LibInits
__asm {
ZeroOut:
#if defined(__HIWARE_OBJECT_FILE_FORMAT__) && defined(__LARGE__)
LDX _startupData.pZeroOut:1 ; in the large memory model in the HIWARE format, pZeroOut is a 24 bit pointer
#else
LDX _startupData.pZeroOut ; *pZeroOut
#endif
LDY _startupData.nofZeroOuts ; nofZeroOuts
BEQ CopyDown ; if nothing to zero out
NextZeroOut: PSHY ; save nofZeroOuts
#ifdef __HC12S__
LDY 0,X ; start address and advance *pZeroOut (X = X+4)
LDD 2,X ; byte count
LEAX 4,X
NextWord: CLR 0,Y ; clear memory byte
INY
#else /* __HC12S__ */
#ifdef FAR_DATA
LDAB 1,X+ ; load page of destination address
LDY 2,X+ ; load offset of destination address
__PIC_JSR(_SET_PAGE) ; sets the page in the correct page register
#else /* FAR_DATA */
LDY 2,X+ ; start address and advance *pZeroOut (X = X+4)
#endif /* FAR_DATA */
LDD 2,X+ ; byte count
NextWord: CLR 1,Y+ ; clear memory byte
#endif /* __HC12S__ */
#if DO_NOT_USE_TEST_BRANCHES
SUBD #1 ; for processor version which does not support DBNE
BNE NextWord
#else
DBNE D, NextWord ; dec byte count
#endif
PULY ; restore nofZeroOuts
DEY ; dec nofZeroOuts
BNE NextZeroOut
CopyDown:
#ifdef __ELF_OBJECT_FILE_FORMAT__
LDX _startupData.toCopyDownBeg ; load address of copy down desc.
#else
LDX _startupData.toCopyDownBeg:2 ; load address of copy down desc.
#endif
NextBlock:
#ifdef __HC12S__
LDD 0,X ; size of init-data -> D
BEQ funcInits ; end of copy down desc.
LDY 2,X ; load destination address
LEAX 4,X ; increment pointer
#else /* __HC12S__ */
LDD 2,X+ ; size of init-data -> D
BEQ funcInits ; end of copy down desc.
#ifdef FAR_DATA
PSHD ; save counter
LDAB 1,X+ ; load destination page
LDY 2,X+ ; destination address
__PIC_JSR(_SET_PAGE) ; sets the destinations page register
PULD ; restore counter
#else /* FAR_DATA */
LDY 2,X+ ; load destination address
#endif /* FAR_DATA */
#endif /* __HC12S__ */
Copy:
#ifdef __HC12S__
PSHA ; move a byte from ROM to the data area
LDAA 0,X
STAA 0,Y
PULA
INX
INY
#else /* __HC12S__ */
MOVB 1,X+,1,Y+ ; move a byte from ROM to the data area
#endif /* __HC12S__ */
#if DO_NOT_USE_TEST_BRANCHES
SUBD #1 ; for processor version which does not support DBNE
BNE Copy
#else
DBNE D,Copy ; copy-byte loop
#endif
BRA NextBlock
funcInits: ; call of global construtors is only in c++ necessary
#if defined(__cplusplus)
#if defined(__ELF_OBJECT_FILE_FORMAT__)
#if defined( __BANKED__) || defined(__LARGE__)
LDY _startupData.nofInitBodies; load number of cpp.
BEQ done ; if cppcount == 0, goto done
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -