This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/PROCESSOR-SDK-AM335X: Illegal instruction

Other Parts Discussed in Thread: AM3358

Tool/software: Linux

Here is the description of the problem (C code presented):

#include <stdio.h>

static void asm_read_attr_reg4(void) {
        unsigned int reg_value;

        printf("Start\n");
        __asm ("mrc p15, 0, %0, c0, c2, 4" : "=r"(reg_value) );
        printf("Instruction Set Attributes Register 4: 0x%08x\n", reg_value);
        if (0x000f0000 & reg_value) {
                printf("The processor does support DMB, DSB and ISB instructions\n");
        }
        else {
                printf("The processor does NOT support DMB, DSB and ISB instructions\n");
                return;
        }

        return;
}

void main(void) {
        asm_read_attr_reg4();
}

Here are the compilation options and execution of this code:

root@beaglebone:~/projects/LKM/cp15_smc# gcc --machine=arm -march=armv7-a+fp -mfpu=vfp -mfloat-abi=hard test.c -o test
root@beaglebone:~/projects/LKM/cp15_smc# ./test
Start
Illegal instruction
root@beaglebone:~/projects/LKM/cp15_smc#

Why the __asm ("mrc p15, 0, %0, c0, c2, 4" : "=r"(reg_value) ); is after all Illegal Instruction???

Thank you,

_nobody_

  • Hello Wolfgang,

    Could you, please, tune your voice VERY down??? I am asking you very politely.

    Your observation is useless/worthless. You are blind... You do NOT see what is the initial context.

    Please, in The Future, refrain to answer ANY of my posts. You have no clue what are you talking about! Please, please! :)

    _nobody_

  • Clueless garbage!

    _nobody_

  • You wrote:

    "Your observation is useless/worthless. You are blind... You do NOT see what is the initial context."

    This is not correct. The link I give you explains the problem very well: in a userspace linux context, you are not allowed to access these registers.

    Moreover, you do not need to know if the processor has DMB, DSB and ISB instructions in a userspace linux context.

    If you want to do hardware related stuff in Linux, you need to write a kernel device driver. 

    In Linux kernel space, there are macros provided to do synchronisation barriers.

    https://elixir.bootlin.com/linux/latest/source/arch/arm/include/asm/barrier.h

  • > In Linux kernel space, there are macros provided to do synchronisation barriers.

    > https://elixir.bootlin.com/linux/latest/source/arch/arm/include/asm/barrier.h

    This is much better answer. Much more useful. Since I could MOT compile even as (in the context of the device driver code) the following:

            __asm ("dsb");                                  // data synchronization barrier operation   
            __asm ("isb");                                  // instruction synchronization barrier operation
            __asm ("dmb");                                  // data memory barrier operation
    

    IT produces the following:

    /tmp/ccNTvPrS.s: Assembler messages:
    /tmp/ccNTvPrS.s:109: Error: selected processor does not support `dsb' in ARM mode
    /tmp/ccNTvPrS.s:113: Error: selected processor does not support `isb' in ARM mode
    /tmp/ccNTvPrS.s:117: Error: selected processor does not support `dmb' in ARM mode
    /tmp/ccNTvPrS.s:233: Error: selected processor does not support `dsb' in ARM mode
    /tmp/ccNTvPrS.s:237: Error: selected processor does not support `isb' in ARM mode
    /tmp/ccNTvPrS.s:241: Error: selected processor does not support `dmb' in ARM mode
    make[2]: *** [scripts/Makefile.build:283: /home/root/projects/LKM/cp15_smc/cp15_smc.o] Error 1
    make[1]: *** [Makefile:1577: _module_/home/root/projects/LKM/cp15_smc] Error 2
    

    I need to experiment with tis pointer and my driver code: https://elixir.bootlin.com/linux/latest/source/arch/arm/include/asm/barrier.h

    Please, stay tuned!

    _nobody_

  • Again, you are missing the point (I know how to write drivers)! Why I am not surprised???

    _______

    Here is the problem: I have created very simplistic driver for am3358:

    #include <linux/module.h>        /* Needed by all modules */
    #include <linux/kernel.h>        /* Needed for KERN_INFO */
    #include <linux/init.h>            /* Needed for the macros */
    // #include "barrier.h"
    // #include <asm-generic/barrier.h>
    
    #if 0
    #define isb()    __asm__ __volatile__ ("mcr    p15, 0, %0, c7,  c5, 4" : : "r" (0) : "memory")
    #define dsb()    __asm__ __volatile__ ("mcr    p15, 0, %0, c7, c10, 4" : : "r" (0) : "memory")
    #define dmb()    __asm__ __volatile__ ("mcr    p15, 0, %0, c7, c10, 5" : : "r" (0) : "memory")
    #endif
    
    static inline void asm_test(void) {
        printk(KERN_INFO "TEST\n");
    
        dsb();        // data synchronization barrier operation
        isb();        // instruction synchronization barrier operation
        dmb();        // data memory barrier operation
    }
    
    static int __init cp15_test_init(void) {
        printk(KERN_INFO "cp15_test init\n");
        asm_test();
        return 0;
    }
    
    static void __exit cp15_test_exit(void) {
        asm_test();
        printk(KERN_INFO "cp15_test exit\n");
    }
    
    module_init(cp15_test_init);
    module_exit(cp15_test_exit);
    

    Do note thtat #if preprocessor directive is set to 0.

    This code produces the following errors:

      CC [M]  /home/root/projects/LKM/cp15_smc/cp15_test.o
    /tmp/ccf61Lw5.s: Assembler messages:
    /tmp/ccf61Lw5.s:52: Error: selected processor does not support `dsb ' in ARM mode
    /tmp/ccf61Lw5.s:56: Error: selected processor does not support `isb ' in ARM mode
    /tmp/ccf61Lw5.s:60: Error: selected processor does not support `dmb ' in ARM mode
    /tmp/ccf61Lw5.s:113: Error: selected processor does not support `dsb ' in ARM mode
    /tmp/ccf61Lw5.s:117: Error: selected processor does not support `isb ' in ARM mode
    /tmp/ccf61Lw5.s:121: Error: selected processor does not support `dmb ' in ARM mode
    make[2]: *** [scripts/Makefile.build:283: /home/root/projects/LKM/cp15_smc/cp15_test.o] Error 1
    make[1]: *** [Makefile:1577: _module_/home/root/projects/LKM/cp15_smc] Error 2
    make[1]: Leaving directory '/lib/modules/5.0.15-jumpnow/build'
    make: *** [Makefile:4: all] Error 2
    

    If I change directive to #iif 1, the following warnings poped up:

      CC [M]  /home/root/projects/LKM/cp15_smc/cp15_test.o
    /home/root/projects/LKM/cp15_smc/cp15_test.c:8: warning: "isb" redefined
     #define isb __asm__ __volatile__ ("mcr p15, 0, %0, c7,  c5, 4" : : "r" (0) : "memory")
     
    In file included from ./include/linux/compiler.h:250,
                     from ./include/linux/kernel.h:10,
                     from ./include/linux/list.h:9,
                     from ./include/linux/module.h:9,
                     from /home/root/projects/LKM/cp15_smc/cp15_test.c:1:
    ./arch/arm/include/asm/barrier.h:19: note: this is the location of the previous definition
     #define isb(option) __asm__ __volatile__ ("isb " #option : : : "memory")
     
    /home/root/projects/LKM/cp15_smc/cp15_test.c:9: warning: "dsb" redefined
     #define dsb __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" : : "r" (0) : "memory")
     
    In file included from ./include/linux/compiler.h:250,
                     from ./include/linux/kernel.h:10,
                     from ./include/linux/list.h:9,
                     from ./include/linux/module.h:9,
                     from /home/root/projects/LKM/cp15_smc/cp15_test.c:1:
    ./arch/arm/include/asm/barrier.h:20: note: this is the location of the previous definition
     #define dsb(option) __asm__ __volatile__ ("dsb " #option : : : "memory")
     
    /home/root/projects/LKM/cp15_smc/cp15_test.c:10: warning: "dmb" redefined
     #define dmb __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 5" : : "r" (0) : "memory")
     
    In file included from ./include/linux/compiler.h:250,
                     from ./include/linux/kernel.h:10,
                     from ./include/linux/list.h:9,
                     from ./include/linux/module.h:9,
                     from /home/root/projects/LKM/cp15_smc/cp15_test.c:1:
    ./arch/arm/include/asm/barrier.h:21: note: this is the location of the previous definition
     #define dmb(option) __asm__ __volatile__ ("dmb " #option : : : "memory")
     
      Building modules, stage 2.
      MODPOST 1 modules
    WARNING: modpost: missing MODULE_LICENSE() in /home/root/projects/LKM/cp15_smc/cp15_test.o
    see include/linux/module.h for more information
      CC      /home/root/projects/LKM/cp15_smc/cp15_test.mod.o
      LD [M]  /home/root/projects/LKM/cp15_smc/cp15_test.ko
    make[1]: Leaving directory '/lib/modules/5.0.15-jumpnow/build'

    We have here circular dependencies, it seems: ./arch/arm/include/asm/barrier.h:21: note: this is the location of the previous definition

    How to solve this (I know very effective method, but I would like to redefine these calls in the existing .h hierarchy context)???

    I did compile on the target (BBB) platform, using gcc 8.3.0 .

     

    Thank you,

    _nobody_

  • Hello Wolfgang,

    Yes, this solves the problem. I have two questions here: why you, guys, did not submit this patch already?

    I see, the discussion of this problem goes from July 2018 till March 2019... When do you plan to submit this patch (if you plan it at all)?

    Thank you,

    _nobody_