newlib-cygwin/libgloss/msp430/crt0.S

62 lines
2.7 KiB
ArmAsm
Raw Normal View History

/* 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
License. This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy of this license
is available at http://www.opensource.org/licenses. Any Red Hat trademarks that
are incorporated in the source code or documentation are not subject to the BSD
License and may only be used or replicated with the express permission of
Red Hat, Inc.
*/
#include "memmodel.h"
.section ".resetvec", "a"
__msp430_resetvec_hook:
.word __crt0_start
;; 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
MSP430: Remove .init/.fini sections The .init/.fini sections are not required for msp430-elf, and add unnecessary code bloat to the CRT library. These sections are specified as "unused" by the MSP430 EABI. .init existed to call __crt0_run_{init,preinit}_array which run through the functions in .{init,preinit}_array. __crt0_run_{init,preinit}_array are already dynamically included like the other crt0 functions, so these can be placed before the call to main, which ensures they are still called if needed. With these functions moved, .init has no purpose and can be removed. .fini existed to call __crt0_run_fini_array. However, the "__msp430_fini" symbol which marks the start of .fini has never been used, so no termination routines have ever been run for msp430. On returning from main(), _exit() is called which just loops forever. So there is no current expectation that __crt0_run_fini_array will get called by the CRT code. Further work is to ensure functions registered with atexit can be optionally called during program termination, and then __crt0_run_fini_array can be registered with atexit during program initialization. The mechanisms for supporting the "-minrt" option have also been removed. "-minrt" enabled a "minimum runtime environment" by removing calls to functions which run global static initializers and constructors. Since this behaviour is now dynamic, and these functions are only included when needed, the minrt versions of the CRT object files are no longer required.
2019-07-24 17:45:49 +08:00
.refsym __crt0_call_main
mov_ #__stack, R1
END_CRT_FUNC start
;; The CRT functions will only be present in the final linked
MSP430: Remove .init/.fini sections The .init/.fini sections are not required for msp430-elf, and add unnecessary code bloat to the CRT library. These sections are specified as "unused" by the MSP430 EABI. .init existed to call __crt0_run_{init,preinit}_array which run through the functions in .{init,preinit}_array. __crt0_run_{init,preinit}_array are already dynamically included like the other crt0 functions, so these can be placed before the call to main, which ensures they are still called if needed. With these functions moved, .init has no purpose and can be removed. .fini existed to call __crt0_run_fini_array. However, the "__msp430_fini" symbol which marks the start of .fini has never been used, so no termination routines have ever been run for msp430. On returning from main(), _exit() is called which just loops forever. So there is no current expectation that __crt0_run_fini_array will get called by the CRT code. Further work is to ensure functions registered with atexit can be optionally called during program termination, and then __crt0_run_fini_array can be registered with atexit during program initialization. The mechanisms for supporting the "-minrt" option have also been removed. "-minrt" enabled a "minimum runtime environment" by removing calls to functions which run global static initializers and constructors. Since this behaviour is now dynamic, and these functions are only included when needed, the minrt versions of the CRT object files are no longer required.
2019-07-24 17:45:49 +08:00
;; executable if the assembler decides they are needed. The assembler will
;; only define the symbol necessary to prevent them being garbage collected
;; by the linker if the file being assembled has a specific section,
;; or some other criteria is met.
;; The exception to this is __crt0_call_exit. GCC will include this function
;; if it detects that main() has an epilogue. For example, if main() has a
;; while(1) loop at the end, GCC will not generate an epilogue (since it won't
;; return) and __crt0_call_exit won't be included.