ARM VERSION 1.2 Guide de l'utilisateur Page 58

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 133
  • Table des matières
  • DEPANNAGE
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 57
From C/C++, declare the SWI as an __SWI function, and call it. For example:
__swi(0) void my_swi(int);
.
.
.
my_swi(65);
This allows a SWI to compiled inline, without additional calling overhead, provided that:
any arguments are passed in r0-r3 only
any results are returned in r0-r3 only.
The parameters are passed to the SWI as if the SWI were a real function call. However, if there are between two and
four return values, you must tell the compiler that the return values are being returned in a structure, and use the
__value_in_regs directive. This is because a struct-valued function is usually treated as if it were a void function
whose first argument is the address where the result structure should be placed.
Example 5-9 and Example 5-10 show a SWI handler that provides SWI numbers 0x0, 0x1, 0x2 and 0x3. SWIs 0x0
and 0x1 each take two integer parameters and return a single result. SWI 0x2 takes four parameters and returns a
single result. SWI 0x3 takes four parameters and returns four results. This example is in Examples\SWI\main.c.
and Examples\SWI\swi.h.
Example 5-9 main.c
#include <stdio.h>
#include "swi.h"
unsigned *swi_vec = (unsigned *)0x08;
extern void SWI_Handler(void);
int main( void )
{
int result1, result2;
struct four_results res_3;
Install_Handler( (unsigned) SWI_Handler, swi_vec );
printf("result1 = multiply_two(2,4) = %d\n", result1 = multiply_two(2,4));
printf("result2 = multiply_two(3,6) = %d\n", result2 = multiply_two(3,6));
printf("add_two( result1, result2 ) = %d\n", add_two( result1, result2 ));
printf("add_multiply_two(2,4,3,6) = %d\n", add_multiply_two(2,4,3,6));
res_3 = many_operations( 12, 4, 3, 1 );
printf("res_3.a = %d\n", res_3.a );
printf("res_3.b = %d\n", res_3.b );
printf("res_3.c = %d\n", res_3.c );
printf("res_3.d = %d\n", res_3.d );
return 0;
}
Example 5-10 swi.h
__swi(0) int multiply_two(int, int);
__swi(1) int add_two(int, int);
__swi(2) int add_multiply_two(int, int, int, int);
struct four_results
{
int a;
int b;
int c;
int d;
};
__swi(3) __value_in_regs struct four_results
many_operations(int, int, int, int);
5.4.5 Calling SWIs dynamically from an application
In some circumstances it can be necessary to call a SWI whose number is not known until runtime. This situation can
Handling Processor Exceptions
Copyright ?1999 2001 ARM Limited 5-11
Vue de la page 57
1 2 ... 53 54 55 56 57 58 59 60 61 62 63 ... 132 133

Commentaires sur ces manuels

Pas de commentaire