Integrating own assembly file returns no bytes from target

Hi everyone,

I am trying to add my own assembly file(s) to my project and try to get a power trace from the function inside this assembly file. Having no assembly files and using only C functions works perfectly fine.
I can send and receive bytes and get a power trace.
However, adding an assembly file has the effect that no bytes are returned when i try to read it from my python script. I guess the binary/assembly function just crashes/does not behave as expected and thus nothing is returned.
There exist some posts (here) related to assembly file integration but they did not solve my problem.

First of all here are my files:

  • Foo.S
.syntax unified  // removing/changing any of the next four lines does not change the behavior
.cpu cortex-m4
.thumb
.text
.global Foo

Foo: 
push {r0}
pop {r0}
bx lr
  • Foo.h
#ifndef FOO_H
#define FOO_H

void Foo();

#endif /* FOO_H */
  • makefile
# Target file name (without extension).
# This is the name of the compiled .hex file.
TARGET = foo_communication

# List C source files here.
# Header files (.h) are automatically pulled in.
SRC += foo_communication.c
ASRC+= Foo.S //added the new assembly file here 

# -----------------------------------------------------------------------------

ifeq ($(CRYPTO_OPTIONS),)
CRYPTO_OPTIONS = AES128C
endif

#Add simpleserial project to build
include ../../hardware/victims/firmware/simpleserial/Makefile.simpleserial

FIRMWAREPATH = ../../hardware/victims/firmware
include $(FIRMWAREPATH)/Makefile.inc
  • foo_communication.c

#include <stdint.h>
#include <stdlib.h>
#include "simpleserial.h"
#include "Foo.h"

void push_and_pop_r0() {
    asm(
        "push {r0}\n"  
        "pop {r0}\n"   
    );
}

uint8_t get_pt(uint8_t* pt, uint8_t len)
{

    /**********************************
	* Start user-specific code here. */
	trigger_high();

    Foo();
    //push_and_pop_r0();


    
	trigger_low();
	/* End user-specific code here. *
	********************************/
    
	simpleserial_put('r', 12, pt);
	return 0x00;
}

int main(void)
{
    platform_init();
	init_uart();
	trigger_setup();

	simpleserial_init();

	simpleserial_addcmd('i', 12, get_pt);

	while(1)
		simpleserial_get();
}
  • Note in get_pt() the function push_pop_r0(). This function implements the same functionality like Foo() just with inline assembly. When I comment Foo() and uncomment push_pop_r0() it returnes bytes, i.e., works as expected. Thus I suspect that there might be something wrong with the detection/linking of the assembly file itself?

  • I compared the objdump between the binary with push_pop_r0 and Foo and there was no logical difference. In both cases the functions could be found inside the binary and both had the same instructions.

  • I also looked at the examples on github where assembly files are used (e.g. in bootloader_aesccm) and tried to copy the structure, but this was also not successful.

  • I tried to change the Foo() function itself, i.e., also pushed the link register and popping the PC, but it did not change the behavior.

Does anyone have a idea what the problem might be? It is probably super obviouse but I just cant see it.
Any help is very much appreciated :slight_smile:

Cheers :slight_smile:

I would try a debugger to see what’s going on.
You can even use ChipWhisperer as a debugger: Debugging with ChipWhisperer — ChipWhisperer 5.7.0 documentation