subrata_modak | de78ad0 | 2008-09-04 12:29:33 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
| 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_modak | dce4aa7 | 2008-09-11 07:06:06 +0000 | [diff] [blame^] | 23 | /* File: endian_switch01.c */ |
subrata_modak | de78ad0 | 2008-09-04 12:29:33 +0000 | [diff] [blame] | 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 | /* */ |
subrata_modak | dce4aa7 | 2008-09-11 07:06:06 +0000 | [diff] [blame^] | 30 | /* Test Name: endian_switch01 */ |
subrata_modak | de78ad0 | 2008-09-04 12:29:33 +0000 | [diff] [blame] | 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 | |
| 57 | static void setup(); |
| 58 | static void cleanup(); |
| 59 | |
subrata_modak | dce4aa7 | 2008-09-11 07:06:06 +0000 | [diff] [blame^] | 60 | char *TCID = "endian_switch01"; /* Test program identifier. */ |
subrata_modak | de78ad0 | 2008-09-04 12:29:33 +0000 | [diff] [blame] | 61 | int TST_TOTAL = 1; /* Total number of test cases. */ |
| 62 | extern int Tst_count; /* Test Case counter for tst_* routines */ |
| 63 | |
| 64 | void setup() { |
| 65 | |
| 66 | /* capture signals */ |
| 67 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 68 | |
subrata_modak | de78ad0 | 2008-09-04 12:29:33 +0000 | [diff] [blame] | 69 | /* Pause if that option was specified */ |
| 70 | TEST_PAUSE; |
| 71 | |
| 72 | } |
| 73 | |
| 74 | |
| 75 | void 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 | |
| 94 | volatile int got_sigill; |
| 95 | sigjmp_buf jb; |
| 96 | |
| 97 | void sigill(int sig) { |
| 98 | got_sigill = 1; |
| 99 | siglongjmp(jb, 1); |
| 100 | } |
| 101 | |
| 102 | void 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 | |
| 111 | int main(int ac, char **av, char **envp, unsigned long *auxv) { |
subrata_modak | 7dd48f3 | 2008-09-08 12:51:38 +0000 | [diff] [blame] | 112 | setup(); |
subrata_modak | de78ad0 | 2008-09-04 12:29:33 +0000 | [diff] [blame] | 113 | 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_modak | cb3cae1 | 2008-09-05 06:29:14 +0000 | [diff] [blame] | 126 | tst_resm(TPASS, "endian_switch() syscall tests passed"); |
subrata_modak | de78ad0 | 2008-09-04 12:29:33 +0000 | [diff] [blame] | 127 | tst_exit(); |
| 128 | } |
| 129 | |
| 130 | #else |
| 131 | |
| 132 | int main() { |
| 133 | |
| 134 | tst_brkm(TCONF, cleanup, "This system does not support running of switch() syscall"); |
| 135 | tst_exit(); |
subrata_modak | 7dd48f3 | 2008-09-08 12:51:38 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | #endif |
| 139 | |