1/* Startup code for ARC. 2 Copyright (C) 2020-2021 Free Software Foundation, Inc. 3 This file is part of the GNU C Library. 4 5 The GNU C Library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 The GNU C Library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with the GNU C Library. If not, see 17 <https://www.gnu.org/licenses/>. */ 18 19#define __ASSEMBLY__ 1 20#include <entry.h> 21#include <sysdep.h> 22 23#ifndef ENTRY_POINT 24# error ENTRY_POINT needs to be defined for ARC 25#endif 26 27/* When we enter this piece of code, the program stack looks like this: 28 argc argument counter (integer) 29 argv[0] program name (pointer) 30 argv[1...N] program args (pointers) 31 argv[argc-1] end of args (integer) 32 NULL 33 env[0...N] environment variables (pointers) 34 NULL. */ 35 36ENTRY (ENTRY_POINT) 37 38 /* Needed to make gdb backtraces stop here. */ 39 .cfi_label .Ldummy 40 cfi_undefined (blink) 41 42 mov fp, 0 43 ld_s r1, [sp] /* argc. */ 44 45 mov_s r5, r0 /* rltd_fini. */ 46 add_s r2, sp, 4 /* argv. */ 47 and sp, sp, -8 48 mov r6, sp 49 50 /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end). */ 51 52 mov_s r3, 0 /* Used to be init. */ 53 mov r4, 0 /* Used to be fini. */ 54 55#ifdef SHARED 56 ld r0, [pcl, @main@gotpc] 57 bl __libc_start_main@plt 58#else 59 mov_s r0, main 60 bl __libc_start_main 61#endif 62 63 /* Should never get here. */ 64 flag 1 65END (ENTRY_POINT) 66 67/* Define a symbol for the first piece of initialized data. */ 68 .data 69 .globl __data_start 70__data_start: 71 .long 0 72 .weak data_start 73 data_start = __data_start 74