4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
30 #pragma ident "%Z%%M% %I% %E% SMI"
39 #include <sys/isa_defs.h>
40 #include <sys/types.h>
44 #define NDEBUG /* for assert() */
52 #define MAXSEQUENCE (128)
53 #define MAXREGID (256)
54 #define MAXNAMELENGTH (255)
60 #define ITM_IDENT_LEN (4)
61 #define ITM_IDENT_0 (0x49)
62 #define ITM_IDENT_1 (0x54)
63 #define ITM_IDENT_2 (0x4d)
64 #define ITM_IDENT_3 (0x00)
68 * ITM Platform Specification
71 #define ITM_SPEC_LEN (4)
72 #define ITM_SPEC_0 (0)
73 #define ITM_SPEC_1 (0)
74 #define ITM_SPEC_2 (0)
75 #define ITM_SPEC_3_UNSPECIFIED (0)
76 #define ITM_SPEC_3_32_BIG_ENDIAN (1)
77 #define ITM_SPEC_3_32_LITTLE_ENDIAN (2)
78 #define ITM_SPEC_3_64_BIG_ENDIAN (3)
79 #define ITM_SPEC_3_64_LITTLE_ENDIAN (4)
86 #define ITM_VER_LEN (4)
96 #define ITM_PAD_LEN (4)
100 * Generic offset&pointer/data/string
102 typedef uint32_t pad_t
;
103 typedef ulong_t itm_type_t
;
104 typedef uintptr_t itm_place2_t
; /* position of data */
105 typedef size_t itm_size_t
;
106 typedef long itm_num_t
;
107 typedef union itm_place_union
{
108 int64_t itm_64d
; /* positon of real data */
110 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
114 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
117 }itm_place_union_struct
;
120 #define itm_ptr itm_place_union_struct.ptr
121 #define itm_pad itm_place_union_struct.pad
125 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
128 itm_size_t size
; /* size in bytes */
129 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
133 itm_place_t place
; /* place of data */
138 * Generic place table information
142 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
145 itm_size_t size
; /* size in bytes */
146 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
150 itm_place_t place
; /* place of place table */
152 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
155 itm_num_t number
; /* number of entry */
156 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
159 } itm_place_tbl_info_t
;
163 * Generic place table section
167 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
170 itm_size_t size
; /* size in bytes */
171 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
175 itm_place_t place
; /* place of table section */
177 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
180 itm_num_t number
; /* number of table */
181 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
185 } itm_section_info_t
;
189 * Generic table header
192 #define ITM_TBL_MASK (0x000000ffUL)
194 #define ITM_TBL_NONE (0x00000000UL)
195 #define ITM_TBL_ITM (0x00000001UL)
196 #define ITM_TBL_DIREC (0x00000002UL)
197 #define ITM_TBL_COND (0x00000003UL)
198 #define ITM_TBL_MAP (0x00000004UL)
199 #define ITM_TBL_OP (0x00000005UL)
200 #define ITM_TBL_RANGE (0x00000006UL)
201 #define ITM_TBL_ESCAPESEQ (0x00000007UL)
203 #define ITM_TBL_NONE_NONE (ITM_TBL_NONE | 0x00000000UL)
204 #define ITM_TBL_DIREC_NONE (ITM_TBL_DIREC | 0x00000000UL)
205 #define ITM_TBL_DIREC_RESET (ITM_TBL_DIREC | 0x00000100UL)
206 #define ITM_TBL_COND_NONE (ITM_TBL_COND | 0x00000000UL)
207 #define ITM_TBL_MAP_NONE (ITM_TBL_MAP | 0x00000000UL)
208 #define ITM_TBL_MAP_INDEX_FIXED_1_1 (ITM_TBL_MAP | 0x00000100UL)
209 #define ITM_TBL_MAP_INDEX_FIXED (ITM_TBL_MAP | 0x00000200UL)
210 #define ITM_TBL_MAP_LOOKUP (ITM_TBL_MAP | 0x00000300UL)
211 #define ITM_TBL_MAP_HASH (ITM_TBL_MAP | 0x00000400UL)
212 #define ITM_TBL_MAP_DENSE_ENC (ITM_TBL_MAP | 0x00000500UL)
213 #define ITM_TBL_MAP_VAR (ITM_TBL_MAP | 0x00000600UL)
214 #define ITM_TBL_OP_NONE (ITM_TBL_OP | 0x00000000UL)
215 #define ITM_TBL_OP_INIT (ITM_TBL_OP | 0x00000100UL)
216 #define ITM_TBL_OP_RESET (ITM_TBL_OP | 0x00000200UL)
217 #define ITM_TBL_RANGE_NONE (ITM_TBL_RANGE | 0x00000000UL)
218 #define ITM_TBL_ESCAPESEQ_NONE (ITM_TBL_ESCAPESEQ | 0x00000000UL)
221 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
224 itm_type_t type
; /* type of table */
225 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
228 itm_place_t name
; /* name of table */
230 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
233 itm_size_t size
; /* size of table */
234 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
238 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
241 itm_num_t number
; /* number of entry */
242 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
249 * Iconv Code Set Translation Module (ITM) header
253 unsigned char ident
[ITM_IDENT_LEN
]; /* identifier */
254 unsigned char spec
[ITM_SPEC_LEN
]; /* platform specification */
255 unsigned char version
[ITM_VER_LEN
]; /* version */
256 unsigned char padding
[ITM_PAD_LEN
]; /* padding */
259 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
262 itm_size_t itm_hdr_size
; /* ITM header size */
263 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
267 itm_place_t itm_size
; /* size of ITM (file size) */
268 itm_data_t type_id
; /* type identifier */
269 itm_data_t interpreter
; /* interpreter */
270 itm_place_t op_init_tbl
; /* init operation table */
271 itm_place_t op_reset_tbl
; /* reset operation table */
272 itm_place_t direc_init_tbl
; /* initial direction table */
274 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
277 itm_num_t reg_num
; /* number of register */
278 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
282 itm_place_t info_hdr
; /* ITM Info header */
290 itm_section_info_t str_sec
; /* string section */
291 itm_section_info_t direc_tbl_sec
; /* direction table section */
292 itm_section_info_t cond_tbl_sec
; /* condition table section */
293 itm_section_info_t map_tbl_sec
; /* map table section */
294 itm_section_info_t op_tbl_sec
; /* operation table section */
295 itm_section_info_t range_tbl_sec
; /* range section */
296 itm_section_info_t escapeseq_tbl_sec
; /* escapeseq section */
297 itm_section_info_t data_sec
; /* data section */
298 itm_section_info_t name_sec
; /* name section */
300 itm_place_tbl_info_t str_plc_tbl
; /* string info */
301 itm_place_tbl_info_t direc_plc_tbl
; /* direction table info */
302 itm_place_tbl_info_t cond_plc_tbl
; /* condition table info */
303 itm_place_tbl_info_t map_plc_tbl
; /* map table info */
304 itm_place_tbl_info_t op_plc_tbl
; /* operation table info */
305 itm_place_tbl_info_t range_plc_tbl
; /* range info */
306 itm_place_tbl_info_t escapeseq_plc_tbl
; /* escape info */
307 itm_place_tbl_info_t data_plc_tbl
; /* data info */
308 itm_place_tbl_info_t name_plc_tbl
; /* name info */
309 itm_place_tbl_info_t reg_plc_tbl
; /* register name info */
318 ITM_ACTION_NONE
, /* not used */
319 ITM_ACTION_DIRECTION
, /* direction */
320 ITM_ACTION_MAP
, /* map */
321 ITM_ACTION_OPERATION
/* operation */
325 itm_place_t condition
;
335 ITM_COND_NONE
= 0, /* not used */
336 ITM_COND_BETWEEN
= 1, /* input data is inside of ranges */
337 ITM_COND_EXPR
= 2, /* expression */
338 ITM_COND_ESCAPESEQ
= 3 /* escape sequense */
343 itm_cond_type_t type
;
351 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
355 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
361 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
365 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
369 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
373 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
376 } itm_escapeseq_hdr_t
;
380 * Map table: octet-sequence to octet-sequence: index
384 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
387 itm_size_t source_len
; /* source length */
388 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
393 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
396 itm_size_t result_len
; /* result length */
397 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
401 itm_place_t start
; /* start offset */
402 itm_place_t end
; /* end offset */
404 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
407 itm_num_t default_error
;
410 * 0:with default value
412 * 2:without error table
414 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
418 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
422 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
427 } itm_map_idx_fix_hdr_t
;
430 * Map table: octet-sequence to octet-sequence: lookup
434 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
437 itm_size_t source_len
; /* source length */
438 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
442 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
445 itm_size_t result_len
; /* result length */
446 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
450 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
453 itm_num_t default_error
;
456 * 0:with default value
458 * 2:without error table
460 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
464 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
468 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
471 } itm_map_lookup_hdr_t
;
474 * Map table: octet-sequence to octet-sequence: hash
478 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
481 itm_size_t source_len
; /* source length */
482 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
486 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
489 itm_size_t result_len
; /* result length */
490 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
494 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
497 itm_size_t hash_tbl_size
; /* hash table size */
498 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
502 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
505 itm_num_t hash_tbl_num
; /* hash table entryies */
506 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
510 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
513 itm_size_t hash_of_size
; /* hash overflow table size */
514 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
518 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
521 itm_num_t hash_of_num
; /* hash overflow table entryies */
522 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
526 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
529 itm_num_t default_error
;
532 * 0:with default value
534 * 2:without error table
536 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
540 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
544 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
548 } itm_map_hash_hdr_t
;
551 * Map table: octet-sequence to octet-sequence: dense encoding
555 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
558 itm_size_t source_len
; /* source length */
559 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
563 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
566 itm_size_t result_len
; /* result length */
567 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
571 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
574 itm_num_t default_error
;
577 * 0:with default value
579 * 2:without error table
582 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
586 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
590 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
593 } itm_map_dense_enc_hdr_t
;
601 typedef enum { /* Operation Type */
602 ITM_OP_NONE
, /* not used */
603 ITM_OP_ERROR
, /* error */
604 ITM_OP_ERROR_D
, /* error */
605 ITM_OP_OUT
, /* output */
606 ITM_OP_OUT_D
, /* output */
607 ITM_OP_OUT_S
, /* output */
608 ITM_OP_OUT_R
, /* output */
609 ITM_OP_OUT_INVD
, /* output */
610 ITM_OP_DISCARD
, /* discard */
611 ITM_OP_DISCARD_D
, /* discard */
612 ITM_OP_EXPR
, /* expression */
614 ITM_OP_IF_ELSE
, /* if_else */
615 ITM_OP_DIRECTION
, /* switch direction */
616 ITM_OP_MAP
, /* use map */
617 ITM_OP_OPERATION
, /* invoke operation */
618 ITM_OP_INIT
, /* invoke init operation */
619 ITM_OP_RESET
, /* invoke reset operation */
620 ITM_OP_BREAK
, /* break */
621 ITM_OP_RETURN
, /* return */
622 ITM_OP_PRINTCHR
, /* print out argument as character */
623 ITM_OP_PRINTHD
, /* print out argument as hexadecimal */
624 ITM_OP_PRINTINT
/* print out argument as integer */
633 itm_place_t operand
[3];
636 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
640 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
646 #define itm_opnum itm_op_num.num
647 #define itm_oppad itm_op_num.pad_num
653 #define ITM_EXPR_PROTO(type, op0, op1) ITM_EXPR_##type##_##op0##_##op1
654 #define ITM_EXPR_BIN(type) \
655 ITM_EXPR_PROTO(type, E, E), \
656 ITM_EXPR_PROTO(type, E, D), \
657 ITM_EXPR_PROTO(type, E, R), \
658 ITM_EXPR_PROTO(type, E, INVD), \
659 ITM_EXPR_PROTO(type, D, E), \
660 ITM_EXPR_PROTO(type, D, D), \
661 ITM_EXPR_PROTO(type, D, R), \
662 ITM_EXPR_PROTO(type, D, INVD), \
663 ITM_EXPR_PROTO(type, R, E), \
664 ITM_EXPR_PROTO(type, R, D), \
665 ITM_EXPR_PROTO(type, R, R), \
666 ITM_EXPR_PROTO(type, R, INVD), \
667 ITM_EXPR_PROTO(type, INVD, E), \
668 ITM_EXPR_PROTO(type, INVD, D), \
669 ITM_EXPR_PROTO(type, INVD, R), \
670 ITM_EXPR_PROTO(type, INVD, INVD)
672 #define ITM_EXPR_PLUS ITM_EXPR_PLUS_E_E
673 #define ITM_EXPR_MINUS ITM_EXPR_MINUS_E_E
674 #define ITM_EXPR_MUL ITM_EXPR_MUL_E_E
675 #define ITM_EXPR_DIV ITM_EXPR_DIV_E_E
676 #define ITM_EXPR_MOD ITM_EXPR_MOD_E_E
677 #define ITM_EXPR_SHIFT_L ITM_EXPR_SHIFT_L_E_E
678 #define ITM_EXPR_SHIFT_R ITM_EXPR_SHIFT_R_E_E
679 #define ITM_EXPR_OR ITM_EXPR_OR_E_E
680 #define ITM_EXPR_XOR ITM_EXPR_XOR_E_E
681 #define ITM_EXPR_AND ITM_EXPR_AND_E_E
682 #define ITM_EXPR_EQ ITM_EXPR_EQ_E_E
683 #define ITM_EXPR_NE ITM_EXPR_NE_E_E
684 #define ITM_EXPR_GT ITM_EXPR_GT_E_E
685 #define ITM_EXPR_GE ITM_EXPR_GE_E_E
686 #define ITM_EXPR_LT ITM_EXPR_LT_E_E
687 #define ITM_EXPR_LE ITM_EXPR_LE_E_E
689 typedef enum { /* Expression Type */
690 ITM_EXPR_NONE
, /* not used */
691 ITM_EXPR_NOP
, /* not used */
692 ITM_EXPR_NAME
, /* not used */
693 ITM_EXPR_INT
, /* integer */
694 ITM_EXPR_SEQ
, /* byte sequence */
695 ITM_EXPR_REG
, /* register */
696 ITM_EXPR_IN_VECTOR
, /* in[expr] */
697 ITM_EXPR_IN_VECTOR_D
, /* in[DECIMAL] */
698 ITM_EXPR_OUT
, /* out */
699 ITM_EXPR_TRUE
, /* true */
700 ITM_EXPR_FALSE
, /* false */
701 ITM_EXPR_IN
, /* input data */
702 ITM_EXPR_UMINUS
, /* unary minus */
703 ITM_EXPR_BIN(PLUS
), /* A + B */
704 ITM_EXPR_BIN(MINUS
), /* A - B */
705 ITM_EXPR_BIN(MUL
), /* A * B */
706 ITM_EXPR_BIN(DIV
), /* A / B */
707 ITM_EXPR_BIN(MOD
), /* A % B */
708 ITM_EXPR_BIN(SHIFT_L
), /* A << B */
709 ITM_EXPR_BIN(SHIFT_R
), /* A >> B */
710 ITM_EXPR_BIN(OR
), /* A | B */
711 ITM_EXPR_BIN(XOR
), /* A ^ B */
712 ITM_EXPR_BIN(AND
), /* A & B */
713 ITM_EXPR_BIN(EQ
), /* A == B */
714 ITM_EXPR_BIN(NE
), /* A != B */
715 ITM_EXPR_BIN(GT
), /* A > B */
716 ITM_EXPR_BIN(GE
), /* A >= B */
717 ITM_EXPR_BIN(LT
), /* A < B */
718 ITM_EXPR_BIN(LE
), /* A <= B */
719 ITM_EXPR_NOT
, /* !A */
720 ITM_EXPR_NEG
, /* ~A */
721 ITM_EXPR_LOR
, /* A || B */
722 ITM_EXPR_LAND
, /* A && B */
723 ITM_EXPR_ASSIGN
, /* A = B */
724 ITM_EXPR_OUT_ASSIGN
, /* out = A */
725 ITM_EXPR_IN_EQ
, /* in == A */
726 ITM_EXPR_IF
, /* if */
727 ITM_EXPR_ELSE
/* else */
730 #define ITM_OPERAND_EXPR (0)
731 #define ITM_OPERAND_PLACE (1)
732 #define ITM_OPERAND_VALUE (2)
733 #define ITM_OPERAND_REGISTER (3)
737 itm_expr_type_t type
;
739 itm_place_t operand
[2];
742 #if !defined(_LP64) && !defined(_LITTLE_ENDIAN)
746 #if !defined(_LP64) && defined(_LITTLE_ENDIAN)
752 #define itm_exnum itm_ex_num.num
753 #define itm_expad itm_ex_num.pad_num
760 #endif /* !_ICONV_TM_H */