Errors when compile asm file

Asked by Mitko

Getting errors with some asm commands, tried compiling with as and gcc:

MSR CPSR_c, #Mode_UND|I_Bit|F_Bit

wb_init.s:114: Error: invalid operands (*UND* and *UND* sections) for `|'

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#1

Hi Mitko,

MSR with an immediate value is an ARM only instruction. Are you using a Cortex-R or Cortex-A processor? If not you need to move the bits first into a register (let's say r0) and then use msr CPSR_c, r0 to load into the CPSR. If you are indeed using an ARM processor having an ARM execution mode, I believe you just have to define the Mode_UND, I_Bit and F_Bit to their hex values.

Best regards,

Thomas

Revision history for this message
Mitko (asdfgga12) said :
#2

Hi Thomas,

Thanks about the recommendation. The processor is ARM926ej, and I am porting a Keil code to GCC. After fixing the definitions as you recommended - no errors on those lines, but getting the following errors:

../wb_init.s(45): error: internal_relocation (type: OFFSET_IMM) not fixed up

As well as there is this C code that provides errors too (on Keil it compiles with no errors):

__value_in_regs struct R0_R3 {unsigned heap_base, stack_base, heap_limit, stack_limit;}
    __user_initial_stackheap(unsigned int R0, unsigned int SP, unsigned int R2, unsigned int SL)
{
    struct R0_R3 config;

    //config.heap_base = 0x00060000;
    config.heap_base = (unsigned int)&Image$$ZI$$Limit;
    config.stack_base = SP;

/*

../standalone.c(32): error: expected '=', ',', ';', 'asm' or '__attribute__' before 'struct'
../standalone.c: In function '__user_initial_stackheap':
../standalone.c(38): error: 'struct R0_R3' has no member named 'heap_base'
../standalone.c(39): error: 'struct R0_R3' has no member named 'stack_base'

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#3

Hi Mitko,

I'm not aware of an exact equivalent to __value_in_regs for GCC but you put an optimize attribute that tells to return the struct un general registers. Note that this is a function attribute so you would need to set it on each function returning this struct R0_R3. This actually quite make sense since this is concern how a function is called and returned from. You would do it this way:

struct R0_R3 {unsigned heap_base, stack_base, heap_limit, stack_limit;}
__user_initial_stackheap (unsigned int R0, unsigned int SP, unsigned int R2, unsigned int SL) __attribute ((optimize ("reg-struct-return")))
{
  struct R0_R3 config;
  // rest of code here
}

As to your relocation error, could you provide us with a simple testcase? I see from the code that this error happens when a section doesn't have rela but would need more info to diagnose more precisely what is the problem.

Best regards,

Thomas

Revision history for this message
Mitko (asdfgga12) said :
#4

Hi Thomas,

Unfortunately, your recommendation didn't fix the problem, currently getting the following error:

../standalone.c(34): error: expected ',' or ';' before '{' token

32 struct R0_R3 {unsigned heap_base, stack_base, heap_limit, stack_limit;}
33 __user_initial_stackheap (unsigned int R0, unsigned int SP, unsigned int R2, unsigned int SL) __attribute ((optimize ("reg-struct-return")))
34 {
35 struct R0_R3 config;

Regarding the relocation error, I changed the compiler to gcc-arm-none-eabi-4_9-2014q4-20141203 and the relocation error is not shown so far, but getting other types of errors:

../wb_init.s: Assembler messages:
Error: ../wb_init.s: Error: .size expression for Prefetch_Handler does not evaluate to a constant
Error: ../wb_init.s: Error: .size expression for SWI_Handler1 does not evaluate to a constant

# ************************
# Exception Handlers
# ************************

# The following dummy handlers do not do anything useful in this example.
# They are set up here for completeness.

#Undefined_Handler
# B Undefined_Handler
        .weak Undef_Handler
        .type Undef_Handler, %function
Undef_Handler: B Undef_Handler
        .size Undef_Handler, . - Undef_Handler
#SWI_Handler1
# B
        .weak SWI_Handler1
        .type SWI_Handler1, %function
SWI_Handler: B SWI_Handler1
        .size SWI_Handler1, . - SWI_Handler1
#Prefetch_Handler
# B Prefetch_Handler
        .weak Prefetch_Handler
        .type Prefetch_Handler, %function
PAbt_Handler: B Prefetch_Handler
        .size Prefetch_Handler, . - Prefetch_Handler
#Abort_Handler
# B Abort_Handler
        .weak Abort_Handler
        .type Abort_Handler, %function
Abort_Handler: B Abort_Handler
        .size Abort_Handler, . - Abort_Handler
#IRQ_Handler
# B IRQ_Handler
        .weak IRQ_Handler
        .type IRQ_Handler, %function
IRQ_Handler: B IRQ_Handler
        .size IRQ_Handler, . - IRQ_Handler
#FIQ_Handler
# B FIQ_Handler
        .weak FIQ_Handler
        .type FIQ_Handler, %function
FIQ_Handler: B FIQ_Handler
        .size FIQ_Handler, . - FIQ_Handler

I do understand that is quite difficult just to look at some pieces of the code and wondered if you might be willing to look at the whole project if uploaded somewhere ?

Regards,
Mitko

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#5

Hi Mitko,

My apologize, I tried the attribute on a prototype where I should have tried on a definition as in the example I gave. For function definition the attribute must be before the return type. Thus the correct example is:

__attribute ((optimize ("reg-struct-return"))) struct R0_R3 {unsigned heap_base, stack_base, heap_limit, stack_limit;}
__user_initial_stackheap (unsigned int R0, unsigned int SP, unsigned int R2, unsigned int SL)
{
  struct R0_R3 config;
  // rest of code here
}

As to the errors you get with .size this is because you didn't declare a label for these symbols. So the assembler doesn't see their address and cannot compute the difference between the current location and the start. You should do something like this:

#Prefetch_Handler
# B Prefetch_Handler
        .weak Prefetch_Handler
        .type Prefetch_Handler, %function
PAbt_Handler: B Prefetch_Handler
Prefetch_Handler:
        .size Prefetch_Handler, . - Prefetch_Handler

Best regards.

Can you help with this problem?

Provide an answer of your own, or ask Mitko for more information if necessary.

To post a message you must log in.