📄 crtbegin.spp
字号:
/*
* crtbegin.spp
*
* ST9+ Software Development Toolchain - Version 6.0.0 Apr 5 2000
*
* This file is part of GNU C Compiler for ST9+ Micro-controllers.
*
* This file described initialization part for an application.
* All instructions go to the '.init' ELF standard sections.
* This document is organized as follow:
*
* Part 1: MACROS DEFINITION
* Define and describe cpp macros to be used later in
* the implementation part of the startup,
*
* Part 2: INTERRUPT VECTOR DECLARATION
* It defines the default interrupt vectors.
*
* Part 3: DEFAULT HANDLERS
* It defines the following two default handlers:
* (1) divide by zero trap,
* (2) interrupt handler (just doing iret)
*
* Part 4: SYSTEM SETUP
* Reset some registers to be up to date according to
* the programming models to be used,
* This part not including the MMU setup.
*
* Part 5: MEMORY/REGISTER FILE INITIALIZATION
* Initialize all memories and register files areas
* using the 'secinfo table' mechanism
* (see Libraries and Startup Files Reference Guide
* for more details on this mechanism).
*
* Part 6: MMU SETUP
* Set MMU registers according to the programming
* models used, and initialize DPRs.
*
* Part 7: CALL MAIN
* Call 'main' routine after having enabled interruption.
*
* Part 8: TERMINATION
* Terminate program by looping indefinitely.
*
* IMPORTANT NOTE: all parts are divided using comments.
* Refer to the 'Libraries and Startup Files
* Reference Guide for more details on default
* startup codes and how to customize this
* generic startup file.
*/
/* +------------------------------------------------------------+
| PART 1 : MACROS DEFINITION |
+------------------------------------------------------------+
Here is the list of macros used in this file, how the value
is set and which is the default value:
+---------------------+--------------------------------------+
| NAME | DESCRIPTION |
+---------------------+--------------------------------------+
| SPECMED | defined specific instruction for the |
| | specmedprogramming model. |
| | Set: -mspecmed command line |
| | Default: undefined. |
+---------------------+--------------------------------------+
| MEDIUM | defined specific instruction for the |
| | medium programming model. |
| | Set: -mmedium command line |
| | Default: undefined. |
+---------------------+--------------------------------------+
| PARMUSP | defined specific instruction when |
| | user stack is used. |
| | Set: -mparmusp command line |
| | Default: undefined. |
+---------------------+--------------------------------------+
| UNDERSCORE | add underscore of global symbols. |
| | Set: -munderscore command line |
| | Default: undefined |
+---------------------+--------------------------------------+
| NDEBUG | when this macro is defined, all |
| | intermediate symbols used for loops |
| | are declared as temporary symbols |
| | (prefixed by a '.L_'). |
| | Set: -DNDEBUG on command line |
| | or by uncommented the |
| | specific below. |
| | Default: undefined. |
+---------------------+--------------------------------------+
| DIVIDE_BY_ZERO_TRAP | define the routine name for the |
| | default by zero trap handler. |
| | Set: -DDIVIDE_BY_ZERO_TRAP=... |
| | on command line |
| | Default: undefined. |
+---------------------+--------------------------------------+
| NO_SECINFO | remove code generation for memory |
| | and register file area initializa- |
| | tion using the secinfo table |
| | mechanism. |
| | Set: -DNO_SECINFO on command |
| | line |
| | Default: undefined. |
+---------------------+--------------------------------------+ */
#include "config.spp"
/* Prepend an additional underscore before external
symbols , depending on '-munderscore' command line
option. */
#define _CONCATIFY(x,y) x ## y
#define CONCATIFY(x,y) _CONCATIFY(x,y)
#if defined(UNDERSCORE)
#define M_(x) CONCATIFY(_,x)
#else /* UNDERSCORE */
#define M_(x) x
#endif /* UNDERSCORE */
/* Name of the divide by zero trap handler. */
#if !defined(DIVIDE_BY_ZERO_TRAP)
#define DIVIDE_BY_ZERO_TRAP_DEFAULT __Divide_by_Zero_Trap
#define DIVIDE_BY_ZERO_TRAP_LABEL DIVIDE_BY_ZERO_TRAP_DEFAULT
#else /* !DIVIDE_BY_ZERO_TRAP */
#define DIVIDE_BY_ZERO_TRAP_LABEL DIVIDE_BY_ZERO_TRAP
#endif /* !DIVIDE_BY_ZERO_TRAP */
/* Define macro HAS_SECINFO if macro NO_SECINFO
is not defined. */
#if !defined(NO_SECINFO)
#define HAS_SECINFO
#endif /* !NO_SECINFO */
/* Required include files */
#include <sys/page_0.spp>
#include <sys/system.spp>
#include <sys/mmu.spp>
#include <sys/rccu.spp>
PROGRAMMING_MODEL
;
; Start initialization process
;
.section .init
.global __initialize_begin
.global ___initialize_begin
__initialize_begin:
___initialize_begin:
/* +------------------------------------------------------------+
| PART 2 : INTERRUPT VECTOR DECLARATION |
+------------------------------------------------------------+ */
;
; Interrupt vector definition
; Absolute address 0 is assumed (. == 0x0000)
;
.word __Reset ; address of reset routine
.word DIVIDE_BY_ZERO_TRAP_LABEL ; address of the divide by zero
; trap routine
.rept 13
.word __Default_Interrupt_Handler
.endr
.word usb_int
.word ep0_int
.word ep1_int
.word ep2_int
.word ep3_int
.word ep4_int
.word ep5_int
.word ep6_int
.word ep7_int
.rept 104
.word __Default_Interrupt_Handler
.endr
;
; ST9+V6_TUTORIAL: end of modification
;
/* +------------------------------------------------------------+
| PART 3 : DEFAULT HANDLERS |
+------------------------------------------------------------+ */
/* Definition of the default divide-by-zero trap
handler. */
#if !defined(DIVIDE_BY_ZERO_TRAP)
.global CONCATIFY(_,DIVIDE_BY_ZERO_TRAP_DEFAULT)
.global DIVIDE_BY_ZERO_TRAP_DEFAULT
.proc DIVIDE_BY_ZERO_TRAP_DEFAULT
CONCATIFY(_,DIVIDE_BY_ZERO_TRAP_DEFAULT):
DIVIDE_BY_ZERO_TRAP_DEFAULT:
jx __Halt ; loop forever
.endproc
#endif /* !DIVIDE_BY_ZERO_TRAP */
/* Definition of the default routine handler. */
.global ___Default_Interrupt_Handler
.global __Default_Interrupt_Handler
.proc __Default_Interrupt_Handler
___Default_Interrupt_Handler:
__Default_Interrupt_Handler:
iret ; just return from interrupt
.endproc
/* +------------------------------------------------------------+
| PART 4 : SYSTEM SETUP |
+------------------------------------------------------------+ */
.global __Reset
.global ___Reset
;
; Reset routine
;
.proc __Reset
__Reset:
___Reset:
;
; WCR = 0x42 => 2 wait state for lower memory + watchdog disabled
;
#if !defined(INIT_WCR)
#define INIT_WCR 0x42
#endif /* !INIT_WCR */
spp #WDT_PG ; select register page 0
ld WCR, #INIT_WCR ; WCR = zero wait state
;
; System registers initialization in group 0xE (R224 to R239)
; init clock mode and select external stacks in data memory
; Set register pointer to group 0xD
;
; CICR = IT disabled + Nested Mode + CPL = 7
; MODER = both stacks in memory + clock divided by 2
;
#if !defined(INIT_CICR)
; #define INIT_CICR 0x8f
#define INIT_CICR 0x87
#endif /* !INIT_CICR */
;
; MODER = 0x00 => oscill clock divided by 1
;
#if !defined(INIT_MODER)
#define INIT_MODER 0x00
#endif /* !INIT_MODER */
ld MODER, #INIT_MODER ; init clock and select external
; stacks
ld CICR, #INIT_CICR ; disable interrupt
srp #0x1a ; working register in group D
;
; Using data memory mode by default
;
sdm ; select data memory
;
; Initialize system stack pointer
;
ldw SSPR, #dpr:pof(_stack_end) ; setup system stack pointer
#if defined(PARMUSP)
;
; Routine parameters are passed by user stack pointer.
; Initialize user stack pointer
;
ldw USPR, #dpr:pof(_user_stack_end) ; setup user system stack
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -