libspe2  0.9a
Macros | Functions
lib_builtin.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "spebase.h"
#include "lib_builtin.h"
#include "default_c99_handler.h"
#include "default_posix1_handler.h"
#include "default_libea_handler.h"
Include dependency graph for lib_builtin.c:

Go to the source code of this file.

Macros

#define HANDLER_IDX(x)   (x & 0xff)
 

Functions

int _base_spe_callback_handler_register (void *handler, unsigned int callnum, unsigned int mode)
 
int _base_spe_callback_handler_deregister (unsigned int callnum)
 
void * _base_spe_callback_handler_query (unsigned int callnum)
 
int _base_spe_handle_library_callback (struct spe_context *spe, int callnum, unsigned int npc)
 

Macro Definition Documentation

#define HANDLER_IDX (   x)    (x & 0xff)

Definition at line 29 of file lib_builtin.c.

Function Documentation

int _base_spe_callback_handler_deregister ( unsigned int  callnum)

unregister a handler function for the specified number NOTE: unregistering a handler from call zero and one is ignored.

Definition at line 78 of file lib_builtin.c.

References MAX_CALLNUM, and RESERVED.

79 {
80  errno = 0;
81  if (callnum > MAX_CALLNUM) {
82  errno = EINVAL;
83  return -1;
84  }
85  if (callnum < RESERVED) {
86  errno = EACCES;
87  return -1;
88  }
89  if (handlers[callnum] == NULL) {
90  errno = ESRCH;
91  return -1;
92  }
93 
94  handlers[callnum] = NULL;
95  return 0;
96 }
void* _base_spe_callback_handler_query ( unsigned int  callnum)

query a handler function for the specified number

Definition at line 98 of file lib_builtin.c.

References MAX_CALLNUM.

99 {
100  errno = 0;
101 
102  if (callnum > MAX_CALLNUM) {
103  errno = EINVAL;
104  return NULL;
105  }
106  if (handlers[callnum] == NULL) {
107  errno = ESRCH;
108  return NULL;
109  }
110  return handlers[callnum];
111 }
int _base_spe_callback_handler_register ( void *  handler,
unsigned int  callnum,
unsigned int  mode 
)

register a handler function for the specified number NOTE: registering a handler to call zero and one is ignored.

Definition at line 40 of file lib_builtin.c.

References MAX_CALLNUM, RESERVED, SPE_CALLBACK_NEW, and SPE_CALLBACK_UPDATE.

41 {
42  errno = 0;
43 
44  if (callnum > MAX_CALLNUM) {
45  errno = EINVAL;
46  return -1;
47  }
48 
49  switch(mode){
50  case SPE_CALLBACK_NEW:
51  if (callnum < RESERVED) {
52  errno = EACCES;
53  return -1;
54  }
55  if (handlers[callnum] != NULL) {
56  errno = EACCES;
57  return -1;
58  }
59  handlers[callnum] = handler;
60  break;
61 
63  if (handlers[callnum] == NULL) {
64  errno = ESRCH;
65  return -1;
66  }
67  handlers[callnum] = handler;
68  break;
69  default:
70  errno = EINVAL;
71  return -1;
72  break;
73  }
74  return 0;
75 
76 }
int _base_spe_handle_library_callback ( struct spe_context spe,
int  callnum,
unsigned int  npc 
)

Definition at line 113 of file lib_builtin.c.

References spe_context::base_private, DEBUG_PRINTF, spe_context_base_priv::flags, spe_context_base_priv::mem_mmap_base, SPE_EMULATE_PARAM_BUFFER, and SPE_ISOLATE_EMULATE.

Referenced by _base_spe_context_run().

115 {
116  int (*handler)(void *, unsigned int);
117  int rc;
118 
119  errno = 0;
120  if (!handlers[callnum]) {
121  DEBUG_PRINTF ("No SPE library handler registered for this call.\n");
122  errno=ENOSYS;
123  return -1;
124  }
125 
126  handler=handlers[callnum];
127 
128  /* For emulated isolation mode, position the
129  * npc so that the buffer for the PPE-assisted
130  * library calls can be accessed. */
133 
134  rc = handler(spe->base_private->mem_mmap_base, npc);
135  if (rc) {
136  DEBUG_PRINTF ("SPE library call unsupported.\n");
137  errno=ENOSYS;
138  return rc;
139  }
140  return 0;
141 }