Added tag v0.15-rc1 for changeset 48680222d49b
[hvf.git] / include / ebcdic.h
blob57748fd39e3b2fe6c60f07dfa585c80ee7befe0c
1 /*
2 * (C) Copyright 2007-2011 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
5 * details.
6 */
8 #ifndef __EBCDIC_H
9 #define __EBCDIC_H
11 /* charset conversions */
12 extern u8 ascii2ebcdic_table[256];
13 extern u8 ebcdic2ascii_table[256];
15 /* ASCII transforms */
16 extern u8 ascii2upper_table[256];
19 * Generic translate buffer function.
21 static inline void __translate(u8 *buf, int len, const u8 *table)
23 asm volatile(
24 " sgr %%r0,%%r0\n" /* test byte = 0 */
25 " la %%r2,0(%0)\n" /* buffer */
26 " lgr %%r3,%2\n" /* length */
27 " la %%r4,0(%1)\n" /* table */
28 "0: tre %%r2,%%r4\n"
29 " brc 1,0b\n"
30 : /* output */
31 : /* input */
32 "a" (buf),
33 "a" (table),
34 "d" (len)
35 : /* clobbered */
36 "cc", "r0", "r2", "r3", "r4"
40 #define ascii2ebcdic(buf, len) \
41 __translate((buf), (len), ascii2ebcdic_table)
42 #define ebcdic2ascii(buf, len) \
43 __translate((buf), (len), ebcdic2ascii_table)
45 #define ascii2upper(buf, len) \
46 __translate((buf), (len), ascii2upper_table)
48 #endif