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
|
/*
* Linux fbdev driver for Twin
*
* Copyright 2006 Benjamin Herrenschmidt <benh@kernel.crashing.org>
*
* This Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with the Twin Library; see the file COPYING. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <signal.h>
#include <setjmp.h>
#include "twinint.h"
static unsigned int _twin_features;
#ifdef HAVE_ALTIVEC
static jmp_buf _twin_feature_jmpbuf;
static void illegal_instruction(int sig)
{
longjmp(_twin_feature_jmpbuf, 1);
}
static int _twin_have_altivec(void)
{
volatile int altivec = 0;
void (*handler)(int sig);
handler = signal(SIGILL, illegal_instruction);
if ( setjmp(_twin_feature_jmpbuf) == 0 ) {
asm volatile ("mtspr 256, %0\n\t"
"vand %%v0, %%v0, %%v0"
:
: "r" (-1));
altivec = 1;
}
signal(SIGILL, handler);
return altivec;
}
#else
#define _twin_have_altivec() (0)
#endif /* HAVE_ALTIVEC */
int twin_has_feature(unsigned int feature)
{
return (_twin_features & feature) != 0;
}
void twin_feature_init(void)
{
if (_twin_have_altivec())
_twin_features |= TWIN_FEATURE_ALTIVEC;
_twin_draw_set_features();
}
|