Skip to content

Commit

Permalink
cpu/avr8_common: supports CPUs with missing CALL and JMP instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
hugueslarrive committed Jun 22, 2023
1 parent 996ff9b commit b94cd39
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cpu/avr8_common/startup.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
* 2021 Gerson Fernando Budke
* 2023 Hugues Larrive
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
Expand All @@ -18,6 +19,7 @@
* @author Josua Arndt <jarndt@ias.rwth-aachen.de>
* @author Steffen Robertz <steffen.robertz@rwth-aachen.de>
* @author Gerson Fernando Budke <nandojve@gmail.com>
* @author Hugues Larrive <hugues.larrive@pm.me>
* @}
*/

Expand Down Expand Up @@ -48,7 +50,7 @@ extern void __libc_init_array(void);
* avr-libc normally uses the .init9 section for a call to main. This call
* seems to be not replaceable without hacking inside the library. We
* circumvent the call to main by using section .init7 to call the function
* reset_handler which therefore is the real entry point and section .init8
* reset_handler which therefore is the real entry point and section .init8
* which should never be reached but just in case jumps to exit.
* This way there should be no way to call main directly.
*/
Expand All @@ -57,12 +59,20 @@ void init8_ovr(void) __attribute__((section(".init8")));

__attribute__((used, naked)) void init7_ovr(void)
{
#if (FLASHEND <= 0x1FFF)
__asm__ ("rjmp reset_handler");
#else
__asm__ ("call reset_handler");
#endif
}

__attribute__((used, naked)) void init8_ovr(void)
{
#if (FLASHEND <= 0x1FFF)
__asm__ ("rjmp exit");
#else
__asm__ ("jmp exit");
#endif
}

/**
Expand Down

0 comments on commit b94cd39

Please sign in to comment.