added from the comment: In C there is a function asm , with which you can make assembly inserts. As I understand it, this function accepts strings and converts them into commands. I need to execute a command that I pass to the module as a parameter.

I tried to do it through the char* pointer, which takes a parameter using module_param() , but the compiler produces an error:

"Expected string literal before ..."

  • one
    No Instructions are not strings, and they are not transmitted anywhere. What exactly do you want to do? - Abyx
  • @Abyx in C is a function asm, with which you can make assembler inserts. As I understand it, this function accepts strings and converts them into commands. I need to run the command that I pass to the module as a parameter - Edward Dankovsky
  • one
    @dsnk, asm is a keyword defined by the standard. - Anton Sazonov
  • one
    @dsnk, C standard. Can. J.5.10. open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf - Anton Sazonov
  • one
    @dsnk What does a bad standard mean? Then where to get good? Doing such ("asm is a crutch of GCC") statements are you guided by something other than personal convictions? The syntax is not defined by the standard, so the last question has no right to answer. - Anton Sazonov

1 answer 1

First of all, asm rightly said to you as non-standard, this is a GCC bun. Secondly, asm is not a function; it is such a compiler extension. But the main thing is that its argument is to be a string literal, that is, asm only accepts a hardcoded text, and does not accept pointers to a string. Actually the text of the error informs you of this.

But it is possible to transfer parameters from the runtime to the assembler code:

  int src = 1; int dst; asm("mov %1, %0\n\t" "add $1, %0" : "=r" (dst) : "r" (src) ); printf("%d\n", dst); 
  • Is there a way to pass a parameter as a string literal? In the sense that I could, through the parameter passed to the module, execute an arbitrary command - Edward Dankovsky
  • You will have to write your own milicompiler. Although it is possible to tame gcc, let it convert asm code to binary, and the kernel module will already execute. That's just here you need to work well. - KoVadim
  • @EdwardDankovsky You apparently jit want to do. Then you should use the appropriate tools libjit, llvm ... there are many options. - Cerbo