diff options
author | Nick Clifton <nickc@redhat.com> | 2015-05-05 12:45:38 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2015-05-27 13:30:19 +0200 |
commit | baa681fd38b8484b36ba24399e7c5b9acdd61e65 (patch) | |
tree | 4c243bc65e40c51a9e0dac9ce73992d644276ca7 /libgloss/msp430/crt0.S | |
parent | 761a123a4f9de9f06b3cb8f348a5ec7d6c9a70a2 (diff) | |
download | newlib-baa681fd38b8484b36ba24399e7c5b9acdd61e65.zip newlib-baa681fd38b8484b36ba24399e7c5b9acdd61e65.tar.gz newlib-baa681fd38b8484b36ba24399e7c5b9acdd61e65.tar.bz2 |
Adds support for placing MSP430 code and data into either low memory or high memory.
* msp430/msp430.ld: Delete.
* msp430/msp430F5438A-l.ld: Delete.
* msp430/msp430F5438A-s.ld: Delete.
* msp430/crt_movedata.S: Delete.
* msp430/Makefile.in (SCRIPTS): Remove msp430.ld.
(CRT_OBJS): Add crt_move_highdata.o.
* msp430/memmodel.h (START_CRT_FUNC): New macro.
(END_CRT_FUNC): New macro.
(WEAK_DEF): New macro.
* msp430/crt0.S: Use new macros.
(move_highdata): New code to initialise the .data section if it is
held in high memory.
* msp430/msp430-sim.ld (.data): Add .either.data.
(.rodata2): Move some read-only data sections here.
(.text): Add .either.text.
(.rodata): Add .either.rodata.
(.bss): Add .either.bss.
* msp430/msp430xl-sim.ld (MEMORY): Add HIROM.
(.rodata2): Move some read-only data sections here.
(.upper.data): New section. Include notes about how to initialise
it.
Diffstat (limited to 'libgloss/msp430/crt0.S')
-rw-r--r-- | libgloss/msp430/crt0.S | 190 |
1 files changed, 143 insertions, 47 deletions
diff --git a/libgloss/msp430/crt0.S b/libgloss/msp430/crt0.S index c511959..375d476 100644 --- a/libgloss/msp430/crt0.S +++ b/libgloss/msp430/crt0.S @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2013 Red Hat, Inc. All rights reserved. +/* Copyright (c) 2012-2015 Red Hat, Inc. All rights reserved. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the BSD @@ -14,37 +14,64 @@ #include "memmodel.h" ;; The linker links all .crt_* sections in asciibetical order at the -;; same place. So, the four digits in .crt_NNNN determine the link -;; order, so, keep them in sequential order here. The first two -;; digits are set here, the second two allow users to insert code -;; between code fragments here. +;; same place. So, the four digits in .crt_NNNN_xxx name created by +;; the START_CRT_FUNC macro determine the link order, so, keep them +;; in sequential order here. The first two digits are set here, the +;; second two allow users to insert code between code fragments here. #if L0 .section ".resetvec", "a" __msp430_resetvec_hook: - .word __start + .word __crt0_start - .section ".crt_0000init", "ax", @progbits + ;; Here we provide weak definitions of the symbols used in the + ;; init_highbss and move_highdata blocks, in case they are not + ;; provided by the linker script. They are defined here because + ;; this block is always included in every executable, and because + ;; if there were defined in the blocks that need them their values + ;; would be used without giving the linker script a chance to + ;; override them. + ;; + ;; The weak definitions are needed if the user targets an MCU + ;; without high memory - and hence uses a linker script without + ;; a definition of the .upper.bss or .upper.data sections - and + ;; they have compiled their code with the -mdata-region=either + ;; command line option. That option causes the assembler to + ;; define the __crt0_move_highdata and/or crt0_init_highbss + ;; symbols, which in turn forces the inclusion of the + ;; move_highdata and/or init_highbss blocks in the startup code, + ;; regardless of the fact that the sections are not present in + ;; the linker script. + + WEAK_DEF __upper_data_init + WEAK_DEF __rom_highdatacopysize + WEAK_DEF __high_datastart + WEAK_DEF __rom_highdatastart + WEAK_DEF __high_bssstart + WEAK_DEF __high_bsssize + +START_CRT_FUNC 0000 start .refsym __msp430_resetvec_hook #ifdef MINRT .refsym __crt0_call_just_main #else .refsym __crt0_call_init_then_main #endif - .global __start -__start: mov_ #__stack, R1 ;; Disable watchdog timer. MOV #0x5a80, &0x15C +END_CRT_FUNC start #endif + #if Lbss - .section ".crt_0100bss", "ax", @progbits +;; Note - this section is only included in the startup code of the +;; application if it is needed. It is responsible for initializing +;; the contents of the .bss section. + +START_CRT_FUNC 0100 init_bss - .global __crt0_init_bss -__crt0_init_bss: - mov_ #__bssstart, R12 clr.w R13 mov.w #__bsssize, R14 @@ -52,32 +79,41 @@ __crt0_init_bss: clr.w R15 ; We assume that __bsssize is never > 64M #endif call_ #memset -#endif + +END_CRT_FUNC init_bss +#endif /* Lbss */ + #ifdef __MSP430X_LARGE__ #if Lhigh_bss -;; Note - this section is only included in the -;; startup code of the application if it is needed. +;; Note - this section is only included in the startup code of the +;; application if it is needed. It is responsible for initializing +;; the contents of the .upper.bss section. - .section ".crt_0150high_bss", "ax", @progbits - - .global __crt0_init_high_bss -__crt0_init_high_bss: +START_CRT_FUNC 0200 init_highbss - mov_ #llo(__high_bssstart), R12 - mov_ #lhi(__high_bssstart), R13 - mov.w #llo(__high_bsssize), R14 - mov.w #lhi(__high_bsssize), R15 + mov_ #__high_bssstart, R12 + mov.w #0, R13 + mov_ #__high_bsssize, R14 + ;; If __high_bsssize is zero then skip the call to memset. + ;; This can happen if all of the bss data was placed into .either.bss. + cmp.w #0, R14 + jeq 1f call_ #memset +1: +END_CRT_FUNC init_highbss #endif /* Lhigh_bss */ #endif /* __MSP430X_LARGE__ */ + #if Lmovedata - .section ".crt_0200movedata", "ax", @progbits +;; Note - this section is only included in the startup code of the +;; application if it is needed. It is responsible for copying the +;; contents of the .data section from its load address (in ROM) to +;; its run-time address (in RAM). + +START_CRT_FUNC 0300 movedata - .global __crt0_movedata -__crt0_movedata: - mov_ #__datastart, R12 mov_ #__romdatastart, R13 @@ -85,44 +121,104 @@ __crt0_movedata: cmp_ R12, R13 jeq 1f - mov.w #__romdatacopysize, R14 + mov_ #__romdatacopysize, R14 + + call_ #memmove +1: +END_CRT_FUNC movedata +#endif /* Lmovedata */ + + #ifdef __MSP430X_LARGE__ - clr.w R15 ; We assume that __romdatacopysize is never > 64M -#endif +#if Lmove_highdata +;; Note - this section is only included in the startup code of the application +;; if it is needed. It is responsible either for making sure that the +;; contents of the .upper.data section have their correct startup values. +;; If a copy of the .upper.data section is stored in ROM then this means +;; copying the contents into HIFRAM. If a copy of .upper.data is stored in a +;; shadow section in HIFRAM then this means copying from the shadow section +;; into the real section. + +START_CRT_FUNC 0400 move_highdata + ;; __rom_highdatacopysize may be zero. Test this first because + ;; its value may come from the weak definitions above and we do + ;; not want to access the memory at address 0 pointed to by the + ;; weak definition of __upper_data_init. + mov.w #__rom_highdatacopysize, R14 + cmp.w #0, R14 + jeq 3f + + /* Test our status word. */ + cmpx.w #0, &__upper_data_init + jeq 1f + /* Status word is non-zero - copy from shadow into upper. */ + mov_ #__high_datastart, R12 + mov_ #__rom_highdatastart, R13 + jmp 2f + +1: /* Status word is zero. Copy from upper to shadow and change status word. */ + movx.w #1, &__upper_data_init + mov_ #__rom_highdatastart, R12 + mov_ #__high_datastart, R13 + +2: ;; __rom_highdatacopysize may be zero. memmove should cope. + mov.w #__rom_highdatacopysize, R14 + call_ #memmove -1: -#endif +3: +END_CRT_FUNC move_highdata +#endif /* Lmove_highdata */ +#endif /* __MSP430X_LARGE__ */ + #if Lmain_minrt - .section ".crt_0300main", "ax", @progbits - .global __crt0_call_just_main -__crt0_call_just_main: +;; Note - this section is only included in the startup code of the +;; application if it is needed. It is responsible for just calling +;; main. No initialization code is called first, and main is not +;; expected to return. + +START_CRT_FUNC 0600 call_just_main + clr.w R12 ; Set argc == 0 call_ #main -#endif +END_CRT_FUNC call_just_main +#endif /* Lmain_minrt */ + #if Lmain - .section ".crt_0300main", "ax", @progbits - .global __crt0_call_init_then_main -__crt0_call_init_then_main: +;; Note - this section is only included in the startup code of the +;; application if it is needed. It is responsible for calling the +;; initialization code - constructors, etc - and then main. If main +;; returns then the following section should be present to catch it. + +START_CRT_FUNC 0700 call_init_then_main + call_ #__msp430_init clr.w R12 ; Set argc == 0 call_ #main -#endif + +END_CRT_FUNC call_init_then_main +#endif /* Lmain */ + #if Lcallexit - .section ".crt_0400main_exit", "ax", @progbits - .global __crt0_call_exit -__crt0_call_exit: +;; Note - this section is only included in the startup code of the +;; application if it is needed. It is responsible for calling exit +;; once main has finished. + +START_CRT_FUNC 0800 call_exit + call_ #_exit -#endif + +END_CRT_FUNC call_exit +#endif /* Lcallexit */ ;---------------------------------------- #ifndef MINRT #if L0 - .section ".crt_0500main_init", "ax", @progbits + .section ".crt_0900main_init", "ax", @progbits .global _msp430_run_init_array .type _msp430_run_init_array,@function _msp430_run_init_array: @@ -172,4 +268,4 @@ __msp430_fini: call_ #_msp430_run_fini_array #endif -#endif +#endif /* not MINRT */ |