From: Max Krummenacher Date: Mon, 14 Aug 2017 18:27:20 +0200 Subject: [U-Boot] [PATCH v2 2/2] hello_world.c: fix entry point in case of arm thumb binary In-Reply-To: <20170814162720.18731-1-max.krummenacher@toradex.com> References: <20170814162720.18731-1-max.krummenacher@toradex.com> Message-ID: <20170814162720.18731-3-max.krummenacher@toradex.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de For the ARM architecture the U-Boot 'go' command can not jump to code compiled for thumb instruction set. Thus provide a forwarder function to be used as the entry point and have the forwarder deal with how to jump to thumb code. Note that code which is calling back into the U-Boot binary needs to be compiled in the same instruction set as the U-Boot binary is compiled with. Signed-off-by: Max Krummenacher --- Changes in v2: - Don't confuse loadaddr with entry point as reported by Wolfgang. - Change the assembly magic to a C function and use __attribute__ to force arm instruction set. - Keep the entry point name hello_world as reported by Wolfgang. examples/standalone/hello_world.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/examples/standalone/hello_world.c b/examples/standalone/hello_world.c index bd8b392315..3b58b147ff 100644 --- a/examples/standalone/hello_world.c +++ b/examples/standalone/hello_world.c @@ -8,7 +8,25 @@ #include #include +/* + * Make thumb work by compiling the entry function for arm. + * Only do this if the target CPU is able to execute arm code. + * Note that code which calls back into the U-Boot binary + * must be compiled for thumb. + */ +#if defined(__thumb__) && defined(__ARM_ARCH_ISA_ARM) +static int _hello_world(int argc, char * const argv[]); + +__attribute__((target("arm"))) +int hello_world(int argc, char * const argv[]) +{ + return _hello_world(argc, argv); +} + +static noinline int _hello_world(int argc, char * const argv[]) +#else int hello_world (int argc, char * const argv[]) +#endif { int i; -- 2.13.1