1/* 2 * Copyright (c) 2021 KT-Elektronik, Klaucke und Partner GmbH 3 * Copyright (c) 2024 Renesas Electronics Corporation 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7#include <zephyr/toolchain.h> 8 9.list 10.section .text 11GTEXT(__start) 12__start : 13 14/* during initialization (before the main thread is started), z_initialization_process_stacks 15 * is used to do the kernel initialization. 16 */ 17 mvtc #(_z_initialization_process_stacks + CONFIG_INITIALIZATION_STACK_SIZE),USP 18 19/* initialise interrupt stack pointer */ 20 mvtc #(_z_interrupt_stacks + CONFIG_ISR_STACK_SIZE),ISP 21 22/* set exception vector address (_ExceptVectors is defined in vects.c) */ 23#if CONFIG_HAS_EXCEPT_VECTOR_TABLE 24 mvtc #_ExceptVectors, extb 25#endif 26 27/* set interrupt vector address (_rvectors_start is defined in vects.c) */ 28 mvtc #_rvectors_start, intb 29 30/* load data section from ROM to RAM */ 31 32 mov #_image_ram_start,r2 /* src ROM address of data section in R2 */ 33 mov #__data_start,r1 /* dest start RAM address of data section in R1 */ 34 mov #__data_region_end,r3 /* end RAM address of data section in R3 */ 35 sub r1,r3 /* size of data section in R3 (R3=R3-R1) */ 36#ifdef __RX_ALLOW_STRING_INSNS__ 37 smovf /* block copy R3 bytes from R2 to R1 */ 38#else 39 cmp #0, r3 40 beq 2f 41 421: mov.b [r2+], r5 43 mov.b r5, [r1+] 44 sub #1, r3 45 bne 1b 462: 47#endif 48 49/* bss initialisation: zero out bss */ 50 mov #0,r2 /* load R2 reg with zero */ 51 mov #_ebss, r3 /* store the end address of bss in R3 */ 52 mov #_bss, r1 /* store the start address of bss in R1 */ 53 sub r1,r3 /* size of bss section in R3 (R3=R3-R1) */ 54 sstr.b 55 56#ifdef CONFIG_INIT_STACKS 57 /* initialize the irq stack (it is located in the bss section) */ 58 mov #0xaa,r2 /* initialization value 0xaa */ 59 mov #_z_interrupt_stacks, r1 /* start address */ 60 mov #CONFIG_ISR_STACK_SIZE, r3 /* stack size */ 61 sstr.b 62#endif 63 64/* setup PSW - use user stack register and lock interrupts during initialization */ 65 mvtc #0x20000, psw 66 67#ifdef CPPAPP 68 bsr __rx_init 69#endif 70 71/* start user program */ 72 bsr _z_cstart 73 bsr _exit 74 75#ifdef CPPAPP 76 .global _rx_run_preinit_array 77 .type _rx_run_preinit_array,@function 78_rx_run_preinit_array: 79 mov #__preinit_array_start,r1 80 mov #__preinit_array_end,r2 81 mov #_rx_run_inilist,r7 82 jsr r7 83 84 .global _rx_run_init_array 85 .type _rx_run_init_array,@function 86_rx_run_init_array: 87 mov #__init_array_start,r1 88 mov #__init_array_end,r2 89 mov #4, r3 90 mov #_rx_run_inilist,r7 91 jsr r7 92 93 .global _rx_run_fini_array 94 .type _rx_run_fini_array,@function 95_rx_run_fini_array: 96 mov #__fini_array_start,r2 97 mov #__fini_array_end,r1 98 mov #-4, r3 99 /* fall through */ 100 101_rx_run_inilist: 102next_inilist: 103 cmp r1,r2 104 beq.b done_inilist 105 mov.l [r1],r4 106 cmp #-1, r4 107 beq.b skip_inilist 108 cmp #0, r4 109 beq.b skip_inilist 110 pushm r1-r3 111 jsr r4 112 popm r1-r3 113skip_inilist: 114 add r3,r1 115 mov #next_inilist,r7 116 jsr r7 117done_inilist: 118 rts 119 120 .section .init,"ax" 121 .balign 4 122 123 .global __rx_init 124__rx_init: 125 126 .section .fini,"ax" 127 .balign 4 128 129 .global __rx_fini 130__rx_fini: 131 mov #_rx_run_fini_array,r7 132 jsr r7 133 134 .section .sdata 135 .balign 4 136 .global __gp 137 .weak __gp 138__gp: 139 140 .section .data 141 .global ___dso_handle 142 .weak ___dso_handle 143___dso_handle: 144 .long 0 145 146 .section .init,"ax" 147 mov #_rx_run_preinit_array,r7 148 jsr r7 149 mov #_rx_run_init_array,r7 150 jsr r7 151 rts 152 153 .global __rx_init_end 154__rx_init_end: 155 156 .section .fini,"ax" 157 158 rts 159 .global __rx_fini_end 160__rx_fini_end: 161 162#endif 163 164/* call to exit*/ 165_exit: 166 bra _loop_here 167_loop_here: 168 bra _loop_here 169 170 .text 171 .end 172