1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/liboil/src/liboilcpu-arm.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,165 @@
1.4 +/*
1.5 + * LIBOIL - Library of Optimized Inner Loops
1.6 + * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
1.7 + * All rights reserved.
1.8 + *
1.9 + * Redistribution and use in source and binary forms, with or without
1.10 + * modification, are permitted provided that the following conditions
1.11 + * are met:
1.12 + * 1. Redistributions of source code must retain the above copyright
1.13 + * notice, this list of conditions and the following disclaimer.
1.14 + * 2. Redistributions in binary form must reproduce the above copyright
1.15 + * notice, this list of conditions and the following disclaimer in the
1.16 + * documentation and/or other materials provided with the distribution.
1.17 + *
1.18 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1.19 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1.20 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.21 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
1.22 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1.23 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.25 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1.26 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
1.27 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1.28 + * POSSIBILITY OF SUCH DAMAGE.
1.29 + */
1.30 +
1.31 +#ifdef HAVE_CONFIG_H
1.32 +#include "config.h"
1.33 +#endif
1.34 +#include <liboil/liboilfunction.h>
1.35 +#include <liboil/liboildebug.h>
1.36 +#include <liboil/liboilcpu.h>
1.37 +#include <liboil/liboilfault.h>
1.38 +#include <liboil/liboilutils.h>
1.39 +
1.40 +#include <unistd.h>
1.41 +#include <fcntl.h>
1.42 +#include <stdlib.h>
1.43 +#include <string.h>
1.44 +#include <stdio.h>
1.45 +#include <setjmp.h>
1.46 +#include <signal.h>
1.47 +#include <sys/time.h>
1.48 +#include <time.h>
1.49 +
1.50 +/***** arm *****/
1.51 +
1.52 +//#ifdef __arm__
1.53 +#if 0
1.54 +static unsigned long
1.55 +oil_profile_stamp_xscale(void)
1.56 +{
1.57 + unsigned int ts;
1.58 + __asm__ __volatile__ (
1.59 + " mrc p14, 0, %0, c1, c0, 0 \n"
1.60 + : "=r" (ts));
1.61 + return ts;
1.62 +}
1.63 +#endif
1.64 +
1.65 +static void
1.66 +oil_cpu_arm_getflags_cpuinfo (char *cpuinfo)
1.67 +{
1.68 + char *cpuinfo_flags;
1.69 + char **flags;
1.70 + char **f;
1.71 +
1.72 + cpuinfo_flags = get_cpuinfo_line(cpuinfo, "Features");
1.73 + if (cpuinfo_flags == NULL) {
1.74 + free (cpuinfo);
1.75 + return;
1.76 + }
1.77 +
1.78 + flags = strsplit(cpuinfo_flags);
1.79 + for (f = flags; *f; f++) {
1.80 + if (strcmp (*f, "edsp") == 0) {
1.81 + OIL_DEBUG ("cpu feature %s", *f);
1.82 + oil_cpu_flags |= OIL_IMPL_FLAG_EDSP;
1.83 + }
1.84 + if (strcmp (*f, "vfp") == 0) {
1.85 + OIL_DEBUG ("cpu feature %s", *f);
1.86 + oil_cpu_flags |= OIL_IMPL_FLAG_VFP;
1.87 + }
1.88 +
1.89 + free (*f);
1.90 + }
1.91 + free (flags);
1.92 + free (cpuinfo_flags);
1.93 +}
1.94 +
1.95 +static char *
1.96 +get_proc_cpuinfo (void)
1.97 +{
1.98 + char *cpuinfo;
1.99 + int fd;
1.100 + int n;
1.101 +
1.102 + cpuinfo = malloc(4096);
1.103 + if (cpuinfo == NULL) return NULL;
1.104 +
1.105 + fd = open("/proc/cpuinfo", O_RDONLY);
1.106 + if (fd < 0) {
1.107 + free (cpuinfo);
1.108 + return NULL;
1.109 + }
1.110 +
1.111 + n = read(fd, cpuinfo, 4095);
1.112 + if (n < 0) {
1.113 + free (cpuinfo);
1.114 + close (fd);
1.115 + return NULL;
1.116 + }
1.117 + cpuinfo[n] = 0;
1.118 +
1.119 + close (fd);
1.120 +
1.121 + return cpuinfo;
1.122 +}
1.123 +#ifdef __SYMBIAN32__
1.124 +EXPORT_C
1.125 +#endif
1.126 +void
1.127 +oil_cpu_detect_arch(void)
1.128 +{
1.129 +#ifdef __linux__
1.130 + int arm_implementer = 0;
1.131 + int arm_arch;
1.132 + char *cpuinfo;
1.133 + char *s;
1.134 +
1.135 + cpuinfo = get_proc_cpuinfo();
1.136 + if (cpuinfo == NULL) return;
1.137 +
1.138 + s = get_cpuinfo_line(cpuinfo, "CPU implementer");
1.139 + if (s) {
1.140 + arm_implementer = strtoul (s, NULL, 0);
1.141 + free(s);
1.142 + }
1.143 +
1.144 + switch(arm_implementer) {
1.145 + case 0x69: /* Intel */
1.146 + case 0x41: /* ARM */
1.147 + /* ARM chips are known to not have timestamping available from
1.148 + * user space */
1.149 + break;
1.150 + default:
1.151 + break;
1.152 + }
1.153 +
1.154 + s = get_cpuinfo_line(cpuinfo, "CPU architecture");
1.155 + if (s) {
1.156 + arm_arch = strtoul (s, NULL, 0);
1.157 + if (arm_arch >= 6)
1.158 + oil_cpu_flags |= OIL_IMPL_FLAG_ARM6;
1.159 + free(s);
1.160 + }
1.161 +
1.162 + oil_cpu_arm_getflags_cpuinfo (cpuinfo);
1.163 + free (cpuinfo);
1.164 +#endif
1.165 +}
1.166 +//#endif
1.167 +
1.168 +