blob: 5e783c10d15ad30f1e488d484af37f00fa625ce8 [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/* */
subrata_modakdce4aa72008-09-11 07:06:06 +000023/* File: endian_switch01.c */
subrata_modakde78ad02008-09-04 12:29:33 +000024/* */
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/* */
subrata_modakdce4aa72008-09-11 07:06:06 +000030/* Test Name: endian_switch01 */
subrata_modakde78ad02008-09-04 12:29:33 +000031/* */
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
subrata_modakb15aafd2008-10-20 06:30:32 +000057#if defined (__powerpc64__) || (__powerpc__)
subrata_modakde78ad02008-09-04 12:29:33 +000058static void setup();
subrata_modakb15aafd2008-10-20 06:30:32 +000059#endif
60
subrata_modakde78ad02008-09-04 12:29:33 +000061static void cleanup();
62
subrata_modakdce4aa72008-09-11 07:06:06 +000063char *TCID = "endian_switch01"; /* Test program identifier. */
subrata_modakde78ad02008-09-04 12:29:33 +000064int TST_TOTAL = 1; /* Total number of test cases. */
65extern int Tst_count; /* Test Case counter for tst_* routines */
66
subrata_modakb15aafd2008-10-20 06:30:32 +000067#if defined (__powerpc64__) || (__powerpc__)
subrata_modakde78ad02008-09-04 12:29:33 +000068void setup() {
69
70 /* capture signals */
71 tst_sig(FORK, DEF_HANDLER, cleanup);
72
subrata_modakde78ad02008-09-04 12:29:33 +000073 /* Pause if that option was specified */
74 TEST_PAUSE;
75
76}
subrata_modak086c14f2008-10-29 05:48:09 +000077
78extern int main4(int ac, char **av, char **envp, unsigned long *auxv)
79__asm ("main");
subrata_modakb15aafd2008-10-20 06:30:32 +000080#endif
subrata_modakde78ad02008-09-04 12:29:33 +000081
82void cleanup() {
83 /*
84 * print timing stats if that option was specified.
85 * print errno log if that option was specified.
86 */
87 TEST_CLEANUP;
88
89 /* exit with return code appropriate for results */
90 tst_exit();
91} /* End cleanup() */
92
93
94#if defined (__powerpc64__) || (__powerpc__)
95#ifndef PPC_FEATURE_TRUE_LE
96 #define PPC_FEATURE_TRUE_LE 0x00000002
97#endif
98
99#include <asm/cputable.h>
100
101volatile int got_sigill;
102sigjmp_buf jb;
103
104void sigill(int sig) {
105 got_sigill = 1;
106 siglongjmp(jb, 1);
107}
108
109void do_le_switch(void) {
110 register int r0 asm("r0");
111
112 r0 = 0x1ebe;
113 asm volatile("sc; .long 0x02000044"
114 : "=&r" (r0) : "0" (r0)
115 : "cr0", "r9", "r10", "r11", "r12");
116}
117
subrata_modak086c14f2008-10-29 05:48:09 +0000118int main4(int ac, char **av, char **envp, unsigned long *auxv) {
subrata_modak5d540f72009-01-06 07:21:52 +0000119
120 if((tst_kvercmp(2, 6, 26)) < 0)
121 {
122 tst_resm(TCONF, "This test can only run on kernels that are 2.6.26 and higher");
123 tst_exit();
124 }
subrata_modak7dd48f32008-09-08 12:51:38 +0000125 setup();
subrata_modakde78ad02008-09-04 12:29:33 +0000126 for (; *auxv != AT_NULL && *auxv != AT_HWCAP; auxv += 2)
127 ;
128 if (!(auxv[0] == AT_HWCAP && (auxv[1] & PPC_FEATURE_TRUE_LE))) {
129 tst_brkm(TCONF, cleanup, "Processor does not support little-endian mode");
130 tst_exit();
131 }
132 signal(SIGILL, sigill);
133 if (sigsetjmp(jb, 1) == 0)
134 do_le_switch();
135 if (got_sigill) {
136 tst_resm(TFAIL, "Got SIGILL - test failed");
137 tst_exit();
138 }
subrata_modakcb3cae12008-09-05 06:29:14 +0000139 tst_resm(TPASS, "endian_switch() syscall tests passed");
subrata_modakde78ad02008-09-04 12:29:33 +0000140 tst_exit();
141}
142
143#else
144
145int main() {
146
147 tst_brkm(TCONF, cleanup, "This system does not support running of switch() syscall");
148 tst_exit();
subrata_modak7dd48f32008-09-08 12:51:38 +0000149}
150
151#endif
152