blob: 98584badef5c7c22adc4e17c318fd7901b459b1c [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 */
Wanlong Gao4548c6c2012-10-19 18:03:36 +080018/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
subrata_modakde78ad02008-09-04 12:29:33 +000019/* */
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"
subrata_modakde78ad02008-09-04 12:29:33 +000047#include <errno.h>
48#include <sys/stat.h>
49#include <sys/types.h>
50#include <sys/syscall.h>
51#include <fcntl.h>
52#include <sys/utsname.h>
53#include <unistd.h>
54#include "linux_syscall_numbers.h"
55
subrata_modakb15aafd2008-10-20 06:30:32 +000056#if defined (__powerpc64__) || (__powerpc__)
subrata_modakde78ad02008-09-04 12:29:33 +000057static void setup();
subrata_modakb15aafd2008-10-20 06:30:32 +000058#endif
59
subrata_modakde78ad02008-09-04 12:29:33 +000060static void cleanup();
61
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020062char *TCID = "endian_switch01";
63int TST_TOTAL = 1;
subrata_modakde78ad02008-09-04 12:29:33 +000064
subrata_modakb15aafd2008-10-20 06:30:32 +000065#if defined (__powerpc64__) || (__powerpc__)
Mike Frysingerc57fba52014-04-09 18:56:30 -040066void setup(void)
subrata_modak56207ce2009-03-23 13:35:39 +000067{
subrata_modakde78ad02008-09-04 12:29:33 +000068
subrata_modak56207ce2009-03-23 13:35:39 +000069 tst_sig(FORK, DEF_HANDLER, cleanup);
subrata_modakde78ad02008-09-04 12:29:33 +000070
subrata_modak56207ce2009-03-23 13:35:39 +000071 TEST_PAUSE;
subrata_modakde78ad02008-09-04 12:29:33 +000072
73}
subrata_modak086c14f2008-10-29 05:48:09 +000074
75extern int main4(int ac, char **av, char **envp, unsigned long *auxv)
subrata_modak56207ce2009-03-23 13:35:39 +000076__asm("main");
subrata_modakb15aafd2008-10-20 06:30:32 +000077#endif
subrata_modakde78ad02008-09-04 12:29:33 +000078
Mike Frysingerc57fba52014-04-09 18:56:30 -040079void cleanup(void)
subrata_modak56207ce2009-03-23 13:35:39 +000080{
subrata_modakde78ad02008-09-04 12:29:33 +000081
Garrett Cooper2c282152010-12-16 00:55:50 -080082}
subrata_modakde78ad02008-09-04 12:29:33 +000083
84#if defined (__powerpc64__) || (__powerpc__)
85#ifndef PPC_FEATURE_TRUE_LE
subrata_modak56207ce2009-03-23 13:35:39 +000086#define PPC_FEATURE_TRUE_LE 0x00000002
subrata_modakde78ad02008-09-04 12:29:33 +000087#endif
88
89#include <asm/cputable.h>
90
91volatile int got_sigill;
92sigjmp_buf jb;
93
subrata_modak56207ce2009-03-23 13:35:39 +000094void sigill(int sig)
95{
subrata_modakde78ad02008-09-04 12:29:33 +000096 got_sigill = 1;
97 siglongjmp(jb, 1);
98}
99
subrata_modak56207ce2009-03-23 13:35:39 +0000100void do_le_switch(void)
101{
subrata_modakde78ad02008-09-04 12:29:33 +0000102 register int r0 asm("r0");
103
104 r0 = 0x1ebe;
subrata_modak56207ce2009-03-23 13:35:39 +0000105 asm volatile ("sc; .long 0x02000044":"=&r" (r0):"0"(r0)
106 :"cr0", "r9", "r10", "r11", "r12");
subrata_modakde78ad02008-09-04 12:29:33 +0000107}
108
subrata_modak56207ce2009-03-23 13:35:39 +0000109int main4(int ac, char **av, char **envp, unsigned long *auxv)
110{
subrata_modak5d540f72009-01-06 07:21:52 +0000111
subrata_modak56207ce2009-03-23 13:35:39 +0000112 if ((tst_kvercmp(2, 6, 26)) < 0) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100113 tst_brkm(TCONF,
114 NULL,
subrata_modak56207ce2009-03-23 13:35:39 +0000115 "This test can only run on kernels that are 2.6.26 and higher");
subrata_modak56207ce2009-03-23 13:35:39 +0000116 }
117 setup();
118 for (; *auxv != AT_NULL && *auxv != AT_HWCAP; auxv += 2) ;
subrata_modakde78ad02008-09-04 12:29:33 +0000119 if (!(auxv[0] == AT_HWCAP && (auxv[1] & PPC_FEATURE_TRUE_LE))) {
subrata_modak56207ce2009-03-23 13:35:39 +0000120 tst_brkm(TCONF, cleanup,
121 "Processor does not support little-endian mode");
subrata_modakde78ad02008-09-04 12:29:33 +0000122 }
123 signal(SIGILL, sigill);
124 if (sigsetjmp(jb, 1) == 0)
125 do_le_switch();
126 if (got_sigill) {
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100127 tst_brkm(TFAIL, NULL, "Got SIGILL - test failed");
subrata_modakde78ad02008-09-04 12:29:33 +0000128 }
subrata_modak56207ce2009-03-23 13:35:39 +0000129 tst_resm(TPASS, "endian_switch() syscall tests passed");
130 tst_exit();
subrata_modakde78ad02008-09-04 12:29:33 +0000131}
132
133#else
134
Mike Frysingerc57fba52014-04-09 18:56:30 -0400135int main(void)
subrata_modak56207ce2009-03-23 13:35:39 +0000136{
subrata_modakde78ad02008-09-04 12:29:33 +0000137
subrata_modak56207ce2009-03-23 13:35:39 +0000138 tst_brkm(TCONF, cleanup,
139 "This system does not support running of switch() syscall");
subrata_modak7dd48f32008-09-08 12:51:38 +0000140}
141
Chris Dearmanec6edca2012-10-17 19:54:01 -0700142#endif