blob: 9802273a87ecebf545c7e2dc1f2793e14d86666d [file] [log] [blame]
subrata_modakde78ad02008-09-04 12:29:33 +00001/******************************************************************************/
2/* */
3/* Copyright (c) International Business Machines Corp., 2008 */
4/* Copyright 2008 Paul Mackerras, IBM Corp. */
5/* */
6/* This program is free software; you can redistribute it and/or modify */
7/* it under the terms of the GNU General Public License as published by */
8/* the Free Software Foundation; either version 2 of the License, or */
9/* (at your option) any later version. */
10/* */
11/* This program is distributed in the hope that it will be useful, */
12/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
14/* the GNU General Public License for more details. */
15/* */
16/* You should have received a copy of the GNU General Public License */
17/* along with this program; if not, write to the Free Software */
18/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19/* */
20/******************************************************************************/
21/******************************************************************************/
22/* */
23/* File: switch01.c */
24/* */
25/* Description: Test little-endian mode switch system call. Requires a 64-bit */
26/* processor that supports little-endian mode,such as POWER6. */
27/* */
28/* Total Tests: 1 */
29/* */
30/* Test Name: switch01 */
31/* */
32/* Author: Paul Mackerras <paulus@samba.org> */
33/* */
34/* History: Created - Sep 02 2008 - Paul Mackerras <paulus@samba.org> */
35/* Ported to LTP */
36/* - Sep 02 2008 */
37/* - Subrata Modak <subrata@linux.vnet.ibm.com> */
38/* */
39/******************************************************************************/
40
41#include <stdio.h>
42#include <stdlib.h>
43#include <elf.h>
44#include <signal.h>
45#include <setjmp.h>
46#include "test.h"
47#include "usctest.h"
48#include <errno.h>
49#include <sys/stat.h>
50#include <sys/types.h>
51#include <sys/syscall.h>
52#include <fcntl.h>
53#include <sys/utsname.h>
54#include <unistd.h>
55#include "linux_syscall_numbers.h"
56
57static void setup();
58static void cleanup();
59
60char *TCID = "switch01"; /* Test program identifier. */
61int TST_TOTAL = 1; /* Total number of test cases. */
62extern int Tst_count; /* Test Case counter for tst_* routines */
63
64void setup() {
65
66 /* capture signals */
67 tst_sig(FORK, DEF_HANDLER, cleanup);
68
subrata_modakde78ad02008-09-04 12:29:33 +000069 /* Pause if that option was specified */
70 TEST_PAUSE;
71
72}
73
74
75void cleanup() {
76 /*
77 * print timing stats if that option was specified.
78 * print errno log if that option was specified.
79 */
80 TEST_CLEANUP;
81
82 /* exit with return code appropriate for results */
83 tst_exit();
84} /* End cleanup() */
85
86
87#if defined (__powerpc64__) || (__powerpc__)
88#ifndef PPC_FEATURE_TRUE_LE
89 #define PPC_FEATURE_TRUE_LE 0x00000002
90#endif
91
92#include <asm/cputable.h>
93
94volatile int got_sigill;
95sigjmp_buf jb;
96
97void sigill(int sig) {
98 got_sigill = 1;
99 siglongjmp(jb, 1);
100}
101
102void do_le_switch(void) {
103 register int r0 asm("r0");
104
105 r0 = 0x1ebe;
106 asm volatile("sc; .long 0x02000044"
107 : "=&r" (r0) : "0" (r0)
108 : "cr0", "r9", "r10", "r11", "r12");
109}
110
111int main(int ac, char **av, char **envp, unsigned long *auxv) {
subrata_modak7dd48f32008-09-08 12:51:38 +0000112 setup();
subrata_modakde78ad02008-09-04 12:29:33 +0000113 for (; *auxv != AT_NULL && *auxv != AT_HWCAP; auxv += 2)
114 ;
115 if (!(auxv[0] == AT_HWCAP && (auxv[1] & PPC_FEATURE_TRUE_LE))) {
116 tst_brkm(TCONF, cleanup, "Processor does not support little-endian mode");
117 tst_exit();
118 }
119 signal(SIGILL, sigill);
120 if (sigsetjmp(jb, 1) == 0)
121 do_le_switch();
122 if (got_sigill) {
123 tst_resm(TFAIL, "Got SIGILL - test failed");
124 tst_exit();
125 }
subrata_modakcb3cae12008-09-05 06:29:14 +0000126 tst_resm(TPASS, "endian_switch() syscall tests passed");
subrata_modakde78ad02008-09-04 12:29:33 +0000127 tst_exit();
128}
129
130#else
131
132int main() {
133
134 tst_brkm(TCONF, cleanup, "This system does not support running of switch() syscall");
135 tst_exit();
subrata_modak7dd48f32008-09-08 12:51:38 +0000136}
137
138#endif
139