/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72X src/bos/kernel/sys/POWER/debug.h 1.15.1.3                       */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1989,2021              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)96      1.15.1.3  src/bos/kernel/sys/POWER/debug.h, cmddbx, bos72X, x2021_27B2 6/30/21 09:43:31 */ 
/*
 * COMPONENT_NAME: SYSPROC
 *
 * FUNCTIONS: none
 *
 * ORIGINS: 27
 *
 */

#ifndef _H_debug
#define _H_debug

/* Traceback table, one per procedure usually.              */
/* Table is marked by word-aligned word of zeroes in instruction space    */
/* Traceback table is also referred to as "procedure-end table." */

struct tbtable_short {
    /* Byte 1 */
	unsigned version:8; 	/* traceback format version               */
    /* Byte 2 */
	unsigned lang:8;  	/* See language values below              */
    /* Byte 3 */
	unsigned globallink:1;	/* Set if routine is global linkage 	  */
	unsigned is_eprol:1;	/* Set if is out-of-line epilog/prologue  */
	unsigned has_tboff:1;	/* Set if offset from start of proc stored */
	unsigned int_proc:1;	/* Set if routine is internal		  */
	unsigned has_ctl:1;	/* Set if routine involves controlled storage */
	unsigned tocless:1;	/* Set if routine contains no TOC 	  */
	unsigned fp_present:1;  /* Set if routine performs FP operations  */
	unsigned log_abort:1;   /* Set if routine logs or aborts FP ops   */
    /* Byte 4 */
	unsigned int_hndl:1;    /* Set if routine is interrupt handler    */
	unsigned name_present:1;/* Set if name is present in proc table */
	unsigned uses_alloca:1; /* Set if alloca used to allocate storage */
	unsigned cl_dis_inv:3;  /* On-condition directives, see below */
	unsigned saves_cr:1;    /* Set if procedure saves the condition reg */
	unsigned saves_lr:1;    /* Set if procedure saves the link reg */
    /* Byte 5 */
	unsigned stores_bc:1;   /* Set if procedure stores the backchain */
	unsigned fixup:1;	/* Set if code is generated fixup code. */
	unsigned fpr_saved:6;   /* Number of FPRs saved, max of 32 */
    /* Byte 6 */
	unsigned longtbtable:1; /* Set if xtbtable extension exists. */
	unsigned has_vec:1; 	/* Set if optional vector info is present */
	unsigned gpr_saved:6;   /* Number of GPRs saved, max of 32 */
    /* Byte 7 */
	unsigned fixedparms:8;  /* Number of fixed point parameters */
    /* Byte 8 */
	unsigned floatparms:7;  /* Number of floating point parameters */
	unsigned parmsonstk:1;  /* Set if all parameters placed on stack */
};

#ifdef _TB_UNION
/* Provide a view of the traceback table as an array of 2 integers
   or a single long long, so that multiple bits can be tested easily.
*/
union tbtable_short_u {
    struct tbtable_short tbtable;
    unsigned int tbtable_int[2];
#ifdef _LONG_LONG
    unsigned long long tbtable_longlong;
#define _TBLL_(_n_) _n_ ## LL
#elif defined(__64BIT__)
    unsigned long tbtable_longlong;
#define _TBLL_(_n_) _n_ ## L
#endif
};

#define TB_VERSION_MASK		0xFF000000    
#define TB_VERSION_SHIFT	24
#define TB_LANG_MASK		0x00FF0000
#define TB_LANG_SHIFT		12

#define TB_GLOBALLINK		0x00008000
#define TB_IS_EPROL		0x00004000
#define TB_HAS_TBOFF		0x00002000
#define TB_INT_PROC		0x00001000
#define TB_HAS_CTL		0x00000800
#define TB_TOCLESS		0x00000400
#define TB_FP_PRESENT		0x00000200
#define TB_LOG_ABORT		0x00000100

#define TB_INT_HNDL		0x00000080
#define TB_NAME_PRESENT		0x00000040
#define TB_USES_ALLOCA		0x00000020
#define TB_CL_DIS_INV_MASK	0x0000001C
#define TB_CL_DIS_INV_SHIFT	2
#define TB_SAVES_CR		0x00000002
#define TB_SAVES_LR		0x00000001

#define TB_STORES_BC		0x80000000
#define TB_FIXUP		0x40000000
#define TB_FPR_SAVED_MASK	0x3F000000
#define TB_FPR_SAVED_SHIFT	24

#define TB_LONGTBTABLE		0x00800000
#define TB_HAS_VEC		0x00400000
#define TB_GPR_SAVED_MASK	0x003F0000
#define TB_GPR_SAVED_SHIFT	16

#define TB_FIXEDPARMS_MASK	0x0000FF00
#define TB_FIXEDPARMS_SHIFT	8

#define TB_FLOATPARMS_MASK	0x000000FE
#define TB_FLOATPARMS_SHIFT	1
#define TB_PARMSONSTK		0x00000001

#if defined(__64BIT__) || defined(_LONG_LONG)

#define TBLL_VERSION_MASK	_TBLL_(0xFF00000000000000)
#define TBLL_VERSION_SHIFT	56
#define TBLL_LANG_MASK		_TBLL_(0x00FF000000000000)
#define TBLL_LANG_SHIFT		48

#define TBLL_GLOBALLINK		_TBLL_(0x0000800000000000)
#define TBLL_IS_EPROL		_TBLL_(0x0000400000000000)
#define TBLL_HAS_TBOFF		_TBLL_(0x0000200000000000)
#define TBLL_INT_PROC		_TBLL_(0x0000100000000000)
#define TBLL_HAS_CTL		_TBLL_(0x0000080000000000)
#define TBLL_TOCLESS		_TBLL_(0x0000040000000000)
#define TBLL_FP_PRESENT		_TBLL_(0x0000020000000000)
#define TBLL_LOG_ABORT		_TBLL_(0x0000010000000000)

#define TBLL_INT_HNDL		_TBLL_(0x0000008000000000)
#define TBLL_NAME_PRESENT	_TBLL_(0x0000004000000000)
#define TBLL_USES_ALLOCA	_TBLL_(0x0000002000000000)
#define TBLL_CL_DIS_INV_MASK	_TBLL_(0x0000001C00000000)
#define TBLL_CL_DIS_INV_SHIFT	34
#define TBLL_SAVES_CR		_TBLL_(0x0000000200000000)
#define TBLL_SAVES_LR		_TBLL_(0x0000000100000000)

#define TBLL_STORES_BC		_TBLL_(0x0000000080000000)
#define TBLL_FIXUP		_TBLL_(0x0000000040000000)
#define TBLL_FPR_SAVED_MASK	_TBLL_(0x000000003F000000)
#define TBLL_FPR_SAVED_SHIFT	24

#define TBLL_LONGTBTABLE	_TBLL_(0x0000000000800000)
#define TBLL_HAS_VEC		_TBLL_(0x0000000000400000)
#define TBLL_GPR_SAVED_MASK	_TBLL_(0x00000000003F0000)
#define TBLL_GPR_SAVED_SHIFT	16

#define TBLL_FIXEDPARMS_MASK	_TBLL_(0x000000000000FF00)
#define TBLL_FIXEDPARMS_SHIFT	8

#define TBLL_FLOATPARMS_MASK	_TBLL_(0x00000000000000FE)
#define TBLL_FLOATPARMS_SHIFT	1
#define TBLL_PARMSONSTK		_TBLL_(0x0000000000000001)
#endif	/* defined(__64BIT__) || defined(_LONG_LONG) */

#endif /* _TB_UNION_ */

/*
 * Vector extension portion of the optional table (if has_vec is set).
 */
struct vec_ext {
	unsigned vr_saved:6;	/* Number of non-volatile vector regs saved */
				/* first register saved is assumed to be */
				/* 32 - vr_saved                         */
	unsigned saves_vrsave:1;/* Set if vrsave is saved on the stack */
	unsigned has_varargs:1;
	unsigned vectorparms:7;	/* number of vector parameters */
	unsigned vec_present:1; /* Set if routine performs vmx instructions */
	unsigned char vecparminfo[4];/* bitmask array for each vector parm in */
				 /* order as found in the original parminfo, */
				 /* describes the type of vector:            */
				 /*       b'00 = vector char                 */
				 /*       b'01 = vector short                */
				 /*       b'10 = vector int                  */
				 /*       b'11 = vector float                */
};

/*
 * Structure of the exception handling info. It is available if longtbtable and
 * xtbtable bit TB_EH_INFO are set and can be accessed through member
 * eh_info_disp of structure tbtable_ext.
 */
struct eh_info_t {
	unsigned int version;	/* EH info version, currently 0 */
#if defined(__64BIT__)
	char _pad[4];		/* padding */
#endif
	unsigned long lsda;     /* Pointer to Language Specific Data Area */
	unsigned long personality; /* Pointer to the personality routine */
};

struct eh_info_32t {
	unsigned int version;	/* EH info version, currently 0 */
	unsigned int lsda;	/* Pointer to Language Specific Data Area */
	unsigned int personality; /* Pointer to the personality routine */
};

struct eh_info_64t { 
	unsigned int version;	/* EH info version, currently 0 */
	char _pad[4];		/* padding */
        long long lsda;	/* Pointer to Language Specific Data Area */
        long long personality; /* Pointer to the personality routine */
};

/*
 * Optional portions of procedure-end table.  
 *
 * Optional portions exist in the following order independently, not as
 * a structure or an union. Whether or not portions exist is determinable
 * from bit-fields within the base procedure-end table.  
 *
 * parminfo      exists if fixedparms or floatparms != 0.
 * tb_offset     exists if has_tboff bit is set.
 * hand_mask     exists if int_hndl bit is set.
 * ctl_info      exists if has_ctl bit is set.
 * ctl_info_disp exists if ctl_info exists.
 * name_len      exists if name_present bit is set.
 * name          exists if name_len exists.
 * alloca_reg    exists if uses_alloca bit is set.
 * vec_ext	 exists if has_vec bit is set.
 * xtbtable	 exists if longtbtable is set.
 * eh_info_disp  exists if extended TB table flag TB_EH_INFO is set.
 */
struct tbtable_ext {
	unsigned int parminfo;  /* Order and type encoding of parameters:
				 * Left-justified bit-encoding as follows:
				 * '0'  ==> fixed parameter
				 * '10' ==> single-precision float parameter
				 * '11' ==> double-precision float parameter 
				 * 
				 * if has_vec is set, encoded as follows:
				 * '00' ==> fixed parameter
				 * '01' ==> vector parameter
				 * '10' ==> single-precision float parameter
				 * '11' ==> double-precision float parameter
				 */
	unsigned int tb_offset; /* Offset from start of code to tb table */
	int hand_mask;		/* What interrupts are handled by */
	int ctl_info;		/* Number of CTL anchors, followed by */ 
	int ctl_info_disp[1];	/* Actually ctl_info_disp[ctl_info] */
				/* Displacements into stack of each anchor */
	short name_len;		/* Length of procedure name */
	char name[1];		/* Actually char[name_len] (no NULL) */
	char alloca_reg;	/* Register for alloca automatic storage */
	struct vec_ext vec_ext; /* Vector extension (if has_vec is set) */
	unsigned char xtbtable; /* More tbtable fields, if longtbtable is set*/
	unsigned int eh_info_disp[1]; /* Actually
				 * eh_info_disp[ptr_size_in_words].
				 * Displacement of the TOC for the exception
				 * handling info from the start of the TOC
				 * table of the module (if longtbtable
				 * and xtbtable bit TB_EH_INFO are set).
				 * In 32-bit, ptr_size_in_words is 1. In 64-bit,
				 * ptr_size_in_words is 2.
				 */
};

/* Extended TB Table Flags: */
#define TB_OS1		0x80	/* Reserved for OS use */
#define TB_RESERVED	0x40	/* Reserved for compiler. */
#define TB_SSP_CANARY	0x20	/* stack smasher canary present on stack */
#define TB_OS2		0x10	/* Reserved for OS use */
#define TB_EH_INFO	0x08    /* Exception handling info present */
#define TB_LONGTBTABLE2 0x01	/* Additional tbtable extension exists. */
				/* (not yet defined).			*/

struct tbtable {
	struct tbtable_short tb;
	struct tbtable_ext tb_ext;
};

/* Language indicators */
#define TB_C		 0
#define TB_FORTRAN	 1
#define TB_PASCAL	 2
#define TB_ADA		 3
#define TB_PL1		 4
#define TB_BASIC	 5
#define TB_LISP		 6
#define TB_COBOL	 7
#define TB_MODULA2	 8
#define TB_CPLUSPLUS	 9
#define TB_RPG		10	
#define TB_PL8		11
#define TB_ASM		12
#define TB_HPJ		13
#define TB_OBJECTIVEC	14
#define TB_UPC		15

/* On-condition directives */
#define WALK_ONCOND	0	/* Walk the stack without restoring state */
#define DISCARD_ONCOND	1	/* Walk the stack and discard */
#define INVOKE_ONCOND	2	/* Invoke a specific system routine */

#endif	/*_H_debug*/
