Home | History | Annotate | Download | only in s390x
      1 #include<stdio.h>
      2 #include<stdlib.h>
      3 #include<asm/types.h>
      4 #include<stdint.h>
      5 #include<string.h>
      6 #include "table.h"
      7 
      8 uint8_t buff[40];
      9 
     10 void tr(uint8_t *codepage, uint8_t *addr, uint64_t len)
     11 {
     12    asm volatile(
     13                 "   larl    1,1f\n"
     14                 "1: tr      0(1,%0),0(%2)\n"
     15                 "   ex      %1,0(1)"
     16                 : "+&a" (addr), "+a" (len)
     17                 : "a" (codepage) : "cc", "memory", "1");
     18 }
     19 
     20 void run_test(void *tran_table, void *srcaddr, uint64_t len)
     21 {
     22    int i;
     23 
     24    tr(tran_table, buff, len);
     25    printf("the translated string is ");
     26    for (i = 0; i < len; i++) {
     27       printf("%c", buff[i]);
     28    }
     29    printf("\n");
     30 }
     31 
     32 int main()
     33 {
     34    /* Test 1: length = 0 */
     35    run_test((char *)&touppercase, &buff, 0);
     36    run_test((char *)&touppercase, &buff, 0);
     37 
     38    /* Test 2 : length > 0 */
     39    memset(buff, 'a', 1);
     40    run_test((char *)&touppercase, &buff, 1);
     41 
     42    memcpy(buff, "abcdefgh", 8);
     43    run_test((char *)&touppercase, &buff, 3);
     44    run_test((char *)&touppercase, &buff, 3);
     45    run_test((char *)&touppercase, &buff, 8);
     46 
     47    memcpy(buff, "ABCDEFGH", 8);
     48    run_test((char *)&tolowercase, &buff, 3);
     49    run_test((char *)&tolowercase, &buff, 3);
     50    run_test((char *)&tolowercase, &buff, 8);
     51 
     52    memcpy(buff, "0123456789", 9);
     53    run_test((char *)&touppercase, &buff, 9);
     54    run_test((char *)&tolowercase, &buff, 9);
     55    return 0;
     56 }
     57