Flaviu
Flaviu

Reputation: 1039

Recognizing ARM Software Interrupt (SWI) functions by Visual C++ compiler

Because I prefer Visual Studio editor instead of Keil and IAR editors, I tried to compile ARM based projects using VS 2017. A project includes RTL.h header of RealView Run-Time Library which declares Software Interrupt (SWI) functions. As I understand Visual C++ compiler supports SWI intrinsic function but I'm getting compile errors.

Also I tried this in a main-only application compiling using default compiler and Clang compiler too - both of Visual Studio:

1: void __swi(1) test1();
2: void __swi_2 test2();
3: 
4: void test3() __swi(3);
5: void test4() __swi_4;
6:
7: __swi(5) test5();
8: __swi_6 void test6();

The errors generated by default Visual C++ compiler are:

Is Visual C++ compiler capable to recognize these declarations? If yes, what should be changed?

Upvotes: 3

Views: 1421

Answers (1)

Peter Cordes
Peter Cordes

Reputation: 365517

From the docs you linked, both compilers have an __swi keyword or intrinsic, but it has a very different meaning in the two language extensions. So it doesn't appear to be possible to do what you want, unless you can set up VS2017 to use ARM's compiler instead of the MS compiler that comes with that IDE.

This is the price of using language extensions that are only provided by a single compiler, especially a non-free compiler, assuming that's really the case.


The details:

According to the MS doc you linked, __swi() is an intrinsic for the SVC instruction, for generating software interrupts, not for writing handlers for them.

__swi not an attribute you can use as part of declaring another function, it's a function of its own, with prototype unsigned int __swi(unsigned int, ...). You can use it from inside another function to make a system call like this:

int swi1(int a) {
    return __swi(1, a);    // I didn't check any system-call lists to find out what args actually make sense
}

void __swi(1) test1(); is the same kind of syntax error as
void sqrt(2.0) test1();. Similarly __swi_2 is just another unrecognized identifier.

Whatever you were trying to do, __swi() is not the right way in Visual Studio.


In ARM's compiler, __swi(8) is a function attribute meaning that callers should invoke it with swi 8 instead of BL function_name (the normal call instruction). It apparently also sets up the interrupt table to point to the functions defined with that attribute.

This is a totally different meaning and language-syntax usage from how MSVC defines it.

Upvotes: 2

Related Questions