1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1999 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate #ifndef _ITMCOMP_H 29*7c478bd9Sstevel@tonic-gate #define _ITMCOMP_H 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 34*7c478bd9Sstevel@tonic-gate extern "C" { 35*7c478bd9Sstevel@tonic-gate #endif 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 38*7c478bd9Sstevel@tonic-gate #include "iconv_tm.h" 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate #define ITMC_STATUS_SUCCESS (0) 42*7c478bd9Sstevel@tonic-gate #define ITMC_STATUS_CMD (1) 43*7c478bd9Sstevel@tonic-gate #define ITMC_STATUS_CMD2 (2) 44*7c478bd9Sstevel@tonic-gate #define ITMC_STATUS_BT (3) 45*7c478bd9Sstevel@tonic-gate #define ITMC_STATUS_BT2 (4) 46*7c478bd9Sstevel@tonic-gate #define ITMC_STATUS_SYS (5) 47*7c478bd9Sstevel@tonic-gate #define ITMC_STATUS_SYS2 (6) 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate #define MAXOPNEST 16 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate /* 52*7c478bd9Sstevel@tonic-gate * exit status: 53*7c478bd9Sstevel@tonic-gate * ITMC_STATUS_SUCCESS 54*7c478bd9Sstevel@tonic-gate * ITMC_STATUS_CMD specified options are wrong 55*7c478bd9Sstevel@tonic-gate * ITMC_STATUS_CMD2 cannot access specified file 56*7c478bd9Sstevel@tonic-gate * ITMC_STATUS_BT Binary Table format error 57*7c478bd9Sstevel@tonic-gate * ITMC_STATUS_BT2 Binary Table against limitation 58*7c478bd9Sstevel@tonic-gate * ITMC_STATUS_SYS resource shortage (e.g.: malloc ) 59*7c478bd9Sstevel@tonic-gate * ITMC_STATUS_SYS2 internal error: never happen 60*7c478bd9Sstevel@tonic-gate */ 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate /* 63*7c478bd9Sstevel@tonic-gate * used later 64*7c478bd9Sstevel@tonic-gate */ 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate struct _itmc_ref; 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate /* 70*7c478bd9Sstevel@tonic-gate * command line option 71*7c478bd9Sstevel@tonic-gate */ 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate typedef enum { 74*7c478bd9Sstevel@tonic-gate ITMC_MAP_UNKNOWN = 0, 75*7c478bd9Sstevel@tonic-gate ITMC_MAP_AUTOMATIC, 76*7c478bd9Sstevel@tonic-gate ITMC_MAP_SIMPLE_INDEX, 77*7c478bd9Sstevel@tonic-gate ITMC_MAP_SIMPLE_HASH, 78*7c478bd9Sstevel@tonic-gate ITMC_MAP_BINARY_SEARCH, 79*7c478bd9Sstevel@tonic-gate ITMC_MAP_DENSE_ENCODING 80*7c478bd9Sstevel@tonic-gate } itmc_map_type_t; 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate typedef struct _itmc_map_name_type { 85*7c478bd9Sstevel@tonic-gate char *name; 86*7c478bd9Sstevel@tonic-gate itmc_map_type_t type; 87*7c478bd9Sstevel@tonic-gate int hash_factor; 88*7c478bd9Sstevel@tonic-gate struct _itmc_map_name_type *next; 89*7c478bd9Sstevel@tonic-gate } itmc_map_name_type_t; 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate typedef struct { 93*7c478bd9Sstevel@tonic-gate char *my_name; 94*7c478bd9Sstevel@tonic-gate char **input_file; 95*7c478bd9Sstevel@tonic-gate int input_file_num; 96*7c478bd9Sstevel@tonic-gate char *output_file; 97*7c478bd9Sstevel@tonic-gate char *interpreter; 98*7c478bd9Sstevel@tonic-gate char **cpp_opt; 99*7c478bd9Sstevel@tonic-gate int cpp_opt_num; 100*7c478bd9Sstevel@tonic-gate int cpp_opt_reserved; 101*7c478bd9Sstevel@tonic-gate char *preprocess_default; 102*7c478bd9Sstevel@tonic-gate char *preprocess_specified; 103*7c478bd9Sstevel@tonic-gate char *preprocess; 104*7c478bd9Sstevel@tonic-gate char *disassemble; 105*7c478bd9Sstevel@tonic-gate int binary_search; 106*7c478bd9Sstevel@tonic-gate itmc_map_name_type_t * 107*7c478bd9Sstevel@tonic-gate map_name_type; 108*7c478bd9Sstevel@tonic-gate int large_table; 109*7c478bd9Sstevel@tonic-gate int force_overwrite; 110*7c478bd9Sstevel@tonic-gate int strip; 111*7c478bd9Sstevel@tonic-gate int quiet; 112*7c478bd9Sstevel@tonic-gate int no_output; 113*7c478bd9Sstevel@tonic-gate char *trace; 114*7c478bd9Sstevel@tonic-gate } cmd_opt_t; 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate /* 118*7c478bd9Sstevel@tonic-gate * data list 119*7c478bd9Sstevel@tonic-gate */ 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate typedef struct { 122*7c478bd9Sstevel@tonic-gate void *obj; 123*7c478bd9Sstevel@tonic-gate itm_num_t num; 124*7c478bd9Sstevel@tonic-gate } obj_array_t; 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate typedef struct _itmc_obj { 127*7c478bd9Sstevel@tonic-gate itm_type_t type; 128*7c478bd9Sstevel@tonic-gate itm_data_t *name; 129*7c478bd9Sstevel@tonic-gate void *obj; 130*7c478bd9Sstevel@tonic-gate struct _itmc_ref *ref[3]; 131*7c478bd9Sstevel@tonic-gate struct _itmc_obj *next; 132*7c478bd9Sstevel@tonic-gate struct _itmc_obj *last; 133*7c478bd9Sstevel@tonic-gate } itmc_obj_t; 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate /* 137*7c478bd9Sstevel@tonic-gate * data pair: used for map and range 138*7c478bd9Sstevel@tonic-gate */ 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate typedef itm_data_t itmc_map_range_t; 141*7c478bd9Sstevel@tonic-gate typedef struct { 142*7c478bd9Sstevel@tonic-gate itm_data_t data0; 143*7c478bd9Sstevel@tonic-gate itm_data_t data1; 144*7c478bd9Sstevel@tonic-gate itmc_map_range_t range; 145*7c478bd9Sstevel@tonic-gate } itmc_data_pair_t; 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate /* 149*7c478bd9Sstevel@tonic-gate * map pair list 150*7c478bd9Sstevel@tonic-gate */ 151*7c478bd9Sstevel@tonic-gate typedef struct _itmc_map { 152*7c478bd9Sstevel@tonic-gate itmc_data_pair_t data_pair; 153*7c478bd9Sstevel@tonic-gate struct _itmc_map *next; 154*7c478bd9Sstevel@tonic-gate struct _itmc_map *last; 155*7c478bd9Sstevel@tonic-gate } itmc_map_t; 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate /* 159*7c478bd9Sstevel@tonic-gate * cross reference: used for relocation 160*7c478bd9Sstevel@tonic-gate */ 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate typedef struct _itmc_ref_link { 163*7c478bd9Sstevel@tonic-gate struct _itmc_ref *ref; 164*7c478bd9Sstevel@tonic-gate struct _itmc_ref_link *next; 165*7c478bd9Sstevel@tonic-gate } itmc_ref_link_t; 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate typedef struct _itmc_name { 168*7c478bd9Sstevel@tonic-gate itm_num_t id; 169*7c478bd9Sstevel@tonic-gate itm_num_t reg_id; 170*7c478bd9Sstevel@tonic-gate itm_data_t name; 171*7c478bd9Sstevel@tonic-gate itm_type_t type; 172*7c478bd9Sstevel@tonic-gate struct _itmc_ref *object; 173*7c478bd9Sstevel@tonic-gate itm_place_t reloc; 174*7c478bd9Sstevel@tonic-gate itmc_ref_link_t *ref_first; 175*7c478bd9Sstevel@tonic-gate itmc_ref_link_t *ref_last; 176*7c478bd9Sstevel@tonic-gate struct _itmc_name *next; 177*7c478bd9Sstevel@tonic-gate } itmc_name_t; 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate typedef struct _itmc_ref { 180*7c478bd9Sstevel@tonic-gate itmc_name_t *name; 181*7c478bd9Sstevel@tonic-gate void *referencee; 182*7c478bd9Sstevel@tonic-gate itm_place_t reloc; 183*7c478bd9Sstevel@tonic-gate itm_size_t size; 184*7c478bd9Sstevel@tonic-gate itm_place_t *referencer; 185*7c478bd9Sstevel@tonic-gate struct _itmc_ref *next; 186*7c478bd9Sstevel@tonic-gate int vertex_index; 187*7c478bd9Sstevel@tonic-gate } itmc_ref_t; 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate 190*7c478bd9Sstevel@tonic-gate /* 191*7c478bd9Sstevel@tonic-gate * action 192*7c478bd9Sstevel@tonic-gate */ 193*7c478bd9Sstevel@tonic-gate typedef struct { 194*7c478bd9Sstevel@tonic-gate itm_type_t type; 195*7c478bd9Sstevel@tonic-gate itm_tbl_hdr_t *tbl_hdr; 196*7c478bd9Sstevel@tonic-gate } itmc_action_t; 197*7c478bd9Sstevel@tonic-gate 198*7c478bd9Sstevel@tonic-gate /* 199*7c478bd9Sstevel@tonic-gate * map attribute 200*7c478bd9Sstevel@tonic-gate */ 201*7c478bd9Sstevel@tonic-gate typedef struct { 202*7c478bd9Sstevel@tonic-gate itm_size_t resultlen; 203*7c478bd9Sstevel@tonic-gate itm_data_t *type; 204*7c478bd9Sstevel@tonic-gate int hash_factor; 205*7c478bd9Sstevel@tonic-gate } itmc_map_attr_t; 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate /* 209*7c478bd9Sstevel@tonic-gate * operation hierarchy 210*7c478bd9Sstevel@tonic-gate */ 211*7c478bd9Sstevel@tonic-gate typedef struct itm_opt_outer { 212*7c478bd9Sstevel@tonic-gate struct itm_opt_outer *link; 213*7c478bd9Sstevel@tonic-gate struct itm_opt_inner *in; 214*7c478bd9Sstevel@tonic-gate itm_tbl_hdr_t *optbl; /* operation object address */ 215*7c478bd9Sstevel@tonic-gate itmc_ref_t *ref; /* corresponding object's ref */ 216*7c478bd9Sstevel@tonic-gate } itm_op_outer_t; 217*7c478bd9Sstevel@tonic-gate typedef struct itm_opt_inner { 218*7c478bd9Sstevel@tonic-gate struct itm_opt_inner *in; 219*7c478bd9Sstevel@tonic-gate itmc_ref_t *ref; /* corresponding object's ref */ 220*7c478bd9Sstevel@tonic-gate } itm_op_inner_t; 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate 223*7c478bd9Sstevel@tonic-gate /* 224*7c478bd9Sstevel@tonic-gate * itm compiler object type 225*7c478bd9Sstevel@tonic-gate */ 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_NONE (0) 228*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_FIRST (1) 229*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_ITM (1) 230*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_STRING (2) 231*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_DIREC (3) 232*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_COND (4) 233*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_MAP (5) 234*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_OP (6) 235*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_EXPR (7) 236*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_DATA (8) 237*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_ACTION (9) 238*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_RANGE (10) 239*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_REGISTER (11) 240*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_ESCAPESEQ (12) 241*7c478bd9Sstevel@tonic-gate #define ITMC_OBJ_LAST (12) 242*7c478bd9Sstevel@tonic-gate 243*7c478bd9Sstevel@tonic-gate 244*7c478bd9Sstevel@tonic-gate /* 245*7c478bd9Sstevel@tonic-gate * global variable 246*7c478bd9Sstevel@tonic-gate */ 247*7c478bd9Sstevel@tonic-gate 248*7c478bd9Sstevel@tonic-gate extern itmc_ref_t *ref_first[ITMC_OBJ_LAST + 1]; 249*7c478bd9Sstevel@tonic-gate extern itmc_ref_t *ref_last[ITMC_OBJ_LAST + 1]; 250*7c478bd9Sstevel@tonic-gate 251*7c478bd9Sstevel@tonic-gate extern itmc_name_t *name_first; 252*7c478bd9Sstevel@tonic-gate extern itmc_name_t *name_last; 253*7c478bd9Sstevel@tonic-gate 254*7c478bd9Sstevel@tonic-gate extern itm_num_t name_id; 255*7c478bd9Sstevel@tonic-gate extern itm_num_t reg_id; 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate extern itmc_name_t name_lookup_error; 258*7c478bd9Sstevel@tonic-gate extern int error_deferred; 259*7c478bd9Sstevel@tonic-gate 260*7c478bd9Sstevel@tonic-gate extern cmd_opt_t cmd_opt; 261*7c478bd9Sstevel@tonic-gate extern char *itm_input_file; 262*7c478bd9Sstevel@tonic-gate extern char *itm_output_file; 263*7c478bd9Sstevel@tonic-gate 264*7c478bd9Sstevel@tonic-gate extern struct itm_opt_outer *itm_op_outer; 265*7c478bd9Sstevel@tonic-gate /* 266*7c478bd9Sstevel@tonic-gate * macro definition 267*7c478bd9Sstevel@tonic-gate */ 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate #define NSPTR(n) (((n)->size <= (sizeof ((n)->place))) ? \ 270*7c478bd9Sstevel@tonic-gate ((void *)(&((n)->place.itm_64d))) : \ 271*7c478bd9Sstevel@tonic-gate ((void *)((n)->place.itm_ptr))) 272*7c478bd9Sstevel@tonic-gate #if !defined(ROUNDUP) 273*7c478bd9Sstevel@tonic-gate #define ROUNDUP(a, n) (((a) + ((n) - 1)) & ~((n) - 1)) 274*7c478bd9Sstevel@tonic-gate #endif 275*7c478bd9Sstevel@tonic-gate #define ITMROUNDUP(i) ROUNDUP(i, sizeof (uint64_t)) 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate 278*7c478bd9Sstevel@tonic-gate /* 279*7c478bd9Sstevel@tonic-gate * trace 280*7c478bd9Sstevel@tonic-gate */ 281*7c478bd9Sstevel@tonic-gate 282*7c478bd9Sstevel@tonic-gate #if defined(ENABLE_TRACE) 283*7c478bd9Sstevel@tonic-gate #define TRACE(c) ((cmd_opt.trace != 0) && \ 284*7c478bd9Sstevel@tonic-gate (0 != *(cmd_opt.trace + (c & 0x007f)))) 285*7c478bd9Sstevel@tonic-gate #define TRACE_MESSAGE(c, args) ((TRACE(c))? trace_message args: (void)0) 286*7c478bd9Sstevel@tonic-gate #else 287*7c478bd9Sstevel@tonic-gate #define TRACE(c) 288*7c478bd9Sstevel@tonic-gate #define TRACE_MESSAGE(c, args) 289*7c478bd9Sstevel@tonic-gate #endif 290*7c478bd9Sstevel@tonic-gate 291*7c478bd9Sstevel@tonic-gate /* 292*7c478bd9Sstevel@tonic-gate * error 293*7c478bd9Sstevel@tonic-gate */ 294*7c478bd9Sstevel@tonic-gate #define PERROR(s) if (cmd_opt.quiet == 0) perror(s) 295*7c478bd9Sstevel@tonic-gate 296*7c478bd9Sstevel@tonic-gate /* 297*7c478bd9Sstevel@tonic-gate * function prototype 298*7c478bd9Sstevel@tonic-gate */ 299*7c478bd9Sstevel@tonic-gate 300*7c478bd9Sstevel@tonic-gate extern int assemble(itm_hdr_t *); 301*7c478bd9Sstevel@tonic-gate extern void disassemble(char *); 302*7c478bd9Sstevel@tonic-gate 303*7c478bd9Sstevel@tonic-gate extern void *malloc_vital(size_t); 304*7c478bd9Sstevel@tonic-gate 305*7c478bd9Sstevel@tonic-gate extern char *name_to_str(itm_data_t *); 306*7c478bd9Sstevel@tonic-gate extern char *data_to_hexadecimal(itm_data_t *); 307*7c478bd9Sstevel@tonic-gate extern itm_data_t *str_to_data(int, char *); 308*7c478bd9Sstevel@tonic-gate 309*7c478bd9Sstevel@tonic-gate #if defined(ENABLE_TRACE) 310*7c478bd9Sstevel@tonic-gate extern void dump_itm_header(itm_hdr_t *, itm_info_hdr_t *); 311*7c478bd9Sstevel@tonic-gate 312*7c478bd9Sstevel@tonic-gate extern void trace_message(char *, ...); 313*7c478bd9Sstevel@tonic-gate #endif 314*7c478bd9Sstevel@tonic-gate 315*7c478bd9Sstevel@tonic-gate extern char *itm_name_type_name[]; 316*7c478bd9Sstevel@tonic-gate extern void itm_error(char *format, ...); 317*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 318*7c478bd9Sstevel@tonic-gate } 319*7c478bd9Sstevel@tonic-gate #endif 320*7c478bd9Sstevel@tonic-gate 321*7c478bd9Sstevel@tonic-gate #endif /* !_ITMCOMP_H */ 322