File: lib_builtin.c

package info (click to toggle)
libspe2 2.2.80-95-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 940 kB
  • ctags: 1,214
  • sloc: ansic: 9,316; makefile: 551; ada: 448; sh: 24
file content (142 lines) | stat: -rw-r--r-- 3,266 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * libspe2 - A wrapper library to adapt the JSRE SPU usage model to SPUFS
 * Copyright (C) 2005 IBM Corp.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License,
 * or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
#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"

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

/*
 * Default SPE library call handlers for 21xx stop-and-signal.
 */
static void *handlers[256] = {
	[HANDLER_IDX(SPE_C99_CLASS)]	= _base_spe_default_c99_handler,
	[HANDLER_IDX(SPE_POSIX1_CLASS)]	= _base_spe_default_posix1_handler,
	[HANDLER_IDX(SPE_LIBEA_CLASS)]	= _base_spe_default_libea_handler
};

int _base_spe_callback_handler_register(void * handler, unsigned int callnum, unsigned int mode)
{
	errno = 0;

	if (callnum > MAX_CALLNUM) {
		errno = EINVAL;
		return -1;
	}
	
	switch(mode){
	case SPE_CALLBACK_NEW:
		if (callnum < RESERVED) {
			errno = EACCES;
			return -1;
		}
		if (handlers[callnum] != NULL) {
			errno = EACCES;
			return -1;
		}
		handlers[callnum] = handler;
		break;

	case SPE_CALLBACK_UPDATE:
		if (handlers[callnum] == NULL) {
			errno = ESRCH;
			return -1;
		}
		handlers[callnum] = handler;
		break;
	default:
		errno = EINVAL;
		return -1;
		break;
	}
	return 0;

}

int _base_spe_callback_handler_deregister(unsigned int callnum )
{
	errno = 0;
	if (callnum > MAX_CALLNUM) {
		errno = EINVAL;
		return -1;
	}
	if (callnum < RESERVED) {
		errno = EACCES;
		return -1;
	}
	if (handlers[callnum] == NULL) {
		errno = ESRCH;
		return -1;
	}

	handlers[callnum] = NULL;
	return 0;
}

void * _base_spe_callback_handler_query(unsigned int callnum )
{
	errno = 0;

	if (callnum > MAX_CALLNUM) {
		errno = EINVAL;
		return NULL;
	}
	if (handlers[callnum] == NULL) {
		errno = ESRCH;
		return NULL;
	}
	return handlers[callnum];
}

int _base_spe_handle_library_callback(struct spe_context *spe, int callnum,
				      unsigned int npc)
{
	int (*handler)(void *, unsigned int);
	int rc;
	
	errno = 0;
	if (!handlers[callnum]) {
		DEBUG_PRINTF ("No SPE library handler registered for this call.\n");
		errno=ENOSYS;
		return -1;
	}

	handler=handlers[callnum];
	
	/* For emulated isolation mode, position the
	 * npc so that the buffer for the PPE-assisted
	 * library calls can be accessed. */
	if (spe->base_private->flags & SPE_ISOLATE_EMULATE)
		npc = SPE_EMULATE_PARAM_BUFFER;

	rc = handler(spe->base_private->mem_mmap_base, npc);
	if (rc) {
		DEBUG_PRINTF ("SPE library call unsupported.\n");
		errno=ENOSYS;
		return rc;
	}
	return 0;
}