ras1.c revision 1.4 1 1.4 martin /* $NetBSD: ras1.c,v 1.4 2004/01/07 19:42:22 martin Exp $ */
2 1.2 gmcgarry
3 1.2 gmcgarry /*-
4 1.2 gmcgarry * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.2 gmcgarry * All rights reserved.
6 1.2 gmcgarry *
7 1.2 gmcgarry * Redistribution and use in source and binary forms, with or without
8 1.2 gmcgarry * modification, are permitted provided that the following conditions
9 1.2 gmcgarry * are met:
10 1.2 gmcgarry * 1. Redistributions of source code must retain the above copyright
11 1.2 gmcgarry * notice, this list of conditions and the following disclaimer.
12 1.2 gmcgarry * 2. Redistributions in binary form must reproduce the above copyright
13 1.2 gmcgarry * notice, this list of conditions and the following disclaimer in the
14 1.2 gmcgarry * documentation and/or other materials provided with the distribution.
15 1.2 gmcgarry * 3. All advertising materials mentioning features or use of this software
16 1.2 gmcgarry * must display the following acknowledgement:
17 1.2 gmcgarry * This product includes software developed by the NetBSD
18 1.2 gmcgarry * Foundation, Inc. and its contributors.
19 1.2 gmcgarry * 4. Neither the name of The NetBSD Foundation nor the names of its
20 1.2 gmcgarry * contributors may be used to endorse or promote products derived
21 1.2 gmcgarry * from this software without specific prior written permission.
22 1.2 gmcgarry *
23 1.2 gmcgarry * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.2 gmcgarry * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.2 gmcgarry * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.2 gmcgarry * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.2 gmcgarry * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.2 gmcgarry * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.2 gmcgarry * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.2 gmcgarry * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.2 gmcgarry * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.2 gmcgarry * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.2 gmcgarry * POSSIBILITY OF SUCH DAMAGE.
34 1.2 gmcgarry */
35 1.2 gmcgarry
36 1.1 gmcgarry #include <stdio.h>
37 1.1 gmcgarry #include <signal.h>
38 1.1 gmcgarry #include <sys/ras.h>
39 1.1 gmcgarry #include <sys/time.h>
40 1.1 gmcgarry
41 1.1 gmcgarry #define COUNT 10
42 1.1 gmcgarry
43 1.1 gmcgarry __volatile int handled = 0;
44 1.1 gmcgarry __volatile int count = 0;
45 1.1 gmcgarry struct itimerval itv;
46 1.1 gmcgarry
47 1.1 gmcgarry void handler(int);
48 1.1 gmcgarry
49 1.1 gmcgarry void
50 1.1 gmcgarry handler(int sig)
51 1.1 gmcgarry {
52 1.1 gmcgarry
53 1.1 gmcgarry handled++;
54 1.1 gmcgarry }
55 1.1 gmcgarry
56 1.1 gmcgarry int
57 1.1 gmcgarry main(void)
58 1.1 gmcgarry {
59 1.1 gmcgarry
60 1.3 martin #ifndef __HAVE_RAS
61 1.3 martin printf("RAS is not supported on this architecture\n");
62 1.3 martin return 0;
63 1.3 martin #endif
64 1.3 martin
65 1.1 gmcgarry signal(SIGVTALRM, handler);
66 1.1 gmcgarry
67 1.1 gmcgarry itv.it_interval.tv_sec = 0;
68 1.1 gmcgarry itv.it_interval.tv_usec = 0;
69 1.1 gmcgarry itv.it_value.tv_sec = 10;
70 1.1 gmcgarry itv.it_value.tv_usec = 0;
71 1.1 gmcgarry setitimer(ITIMER_VIRTUAL, &itv, NULL);
72 1.1 gmcgarry
73 1.1 gmcgarry if (rasctl((caddr_t)&&start, (caddr_t)&&end - (caddr_t)&&start,
74 1.1 gmcgarry RAS_INSTALL) < 0)
75 1.1 gmcgarry return (1);
76 1.4 martin
77 1.4 martin __insn_barrier();
78 1.1 gmcgarry start:
79 1.1 gmcgarry count++;
80 1.1 gmcgarry if (count > COUNT)
81 1.1 gmcgarry goto end;
82 1.1 gmcgarry
83 1.1 gmcgarry while (!handled) {
84 1.1 gmcgarry continue;
85 1.1 gmcgarry }
86 1.1 gmcgarry end:
87 1.4 martin __insn_barrier();
88 1.1 gmcgarry
89 1.1 gmcgarry return (handled != 0);
90 1.1 gmcgarry }
91