libspe2  0.9a
lib_builtin.c
Go to the documentation of this file.
1 /*
2  * libspe2 - A wrapper library to adapt the JSRE SPU usage model to SPUFS
3  * Copyright (C) 2005 IBM Corp.
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation; either version 2.1 of the License,
8  * or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13  * License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <errno.h>
22 
23 #include "spebase.h"
24 #include "lib_builtin.h"
25 #include "default_c99_handler.h"
26 #include "default_posix1_handler.h"
27 #include "default_libea_handler.h"
28 
29 #define HANDLER_IDX(x) (x & 0xff)
30 
31 /*
32  * Default SPE library call handlers for 21xx stop-and-signal.
33  */
34 static void *handlers[256] = {
35  [HANDLER_IDX(SPE_C99_CLASS)] = _base_spe_default_c99_handler,
36  [HANDLER_IDX(SPE_POSIX1_CLASS)] = _base_spe_default_posix1_handler,
37  [HANDLER_IDX(SPE_LIBEA_CLASS)] = _base_spe_default_libea_handler
38 };
39 
40 int _base_spe_callback_handler_register(void * handler, unsigned int callnum, unsigned int mode)
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 }
77 
78 int _base_spe_callback_handler_deregister(unsigned int callnum )
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 }
97 
98 void * _base_spe_callback_handler_query(unsigned int 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 }
112 
113 int _base_spe_handle_library_callback(struct spe_context *spe, int callnum,
114  unsigned int npc)
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 }
142 
int _base_spe_handle_library_callback(struct spe_context *spe, int callnum, unsigned int npc)
Definition: lib_builtin.c:113
#define MAX_CALLNUM
Definition: lib_builtin.h:25
#define SPE_CALLBACK_NEW
void * _base_spe_callback_handler_query(unsigned int callnum)
Definition: lib_builtin.c:98
#define DEBUG_PRINTF(fmt, args...)
Definition: elf_loader.c:45
int _base_spe_callback_handler_deregister(unsigned int callnum)
Definition: lib_builtin.c:78
#define HANDLER_IDX(x)
Definition: lib_builtin.c:29
#define RESERVED
Definition: lib_builtin.h:26
int _base_spe_callback_handler_register(void *handler, unsigned int callnum, unsigned int mode)
Definition: lib_builtin.c:40
#define SPE_CALLBACK_UPDATE
#define SPE_EMULATE_PARAM_BUFFER
Definition: spebase.h:132
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
#define SPE_ISOLATE_EMULATE
unsigned int flags
Definition: spebase.h:74
void * mem_mmap_base
Definition: spebase.h:85