#ifndef _IA64_ASM_H #define _IA64_ASM_H //++ // Module IA64_ASM.H "X-7" // // IA-64 Assembly Language Include File // /****************************************************************************/ // Copyright 2002 Compaq Information Technologies Group, L.P. // // Compaq and the Compaq logo are trademarks of Compaq Information // Technologies Group, L.P. in the U.S. and/or other countries. // // Confidential computer software. Valid license from Compaq required for // possession, use or copying. Consistent with FAR 12.211 and 12.212, // Commercial Computer Software, Computer Software Documentation, and // Technical Data for Commercial Items are licensed to the U.S. Government // under vendor's standard commercial license. /****************************************************************************/ // // Module Name: // // ia64_asm.h // // Abstract: // // This module contains generic macros for IA-64 assembly language code. // // Author: // // Revision History: // // X-7 GHJ Gregory H. Jordan 24-Aug-2005 // Add TR_PRINT macro for IA64 assembler. // // X-6 KLN3353 Karen L. Noel 12-Sep-2003 // Add EXC_PRINT macro. // // X-5 KLN3141 Karen L. Noel 20-Nov-2002 // Put code in $CODE$ psect. // // X-4 PJB0017 Paul Benoit 14-Oct-2002 // Add "bug_check" macro. // // X-3 DAG Doug Gordon 20-Sep-2002 // Added ias$$label and helper macros // //-- #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif #define PROCEDURE_ENTRY(name) .section $CODE$, "ax", "progbits";\ .type name, @function;\ .proc name; \ name:: #define PROCEDURE_EXIT(name) .endp name /* What follows is a bug_check_fatal macro for IA64 assembler programmers which can be used to generate a bugcheck. Note that you can not use this macro to generate non-fatal or cold-reboot type bugchecks. Example: (note the bugcheck type is upper case) bug_check_fatal (INCONSTATE); */ #define bug_check_fatal(code) \ .global BUG$_##code; \ movl r17 = BUG$_##code; \ or r17 = 4,r17; \ break.m BREAK$C_SYS_BUGCHECK; /* What follows is a bug_check macro for IA64 assembler programmers which can be used to generate a bugcheck. Example: bug_check (INCONSTATE, FATAL, WARM); */ #define BUGCHK_FATAL 4 #define BUGCHK_NONFATAL 0 #define BUGCHK_POWEROFF 2 #define BUGCHK_COLD 1 #define BUGCHK_WARM 0 #define bug_check(code, severity, reboot) \ .global BUG$_##code; \ movl r17 = BUG$_##code; \ or r17 = BUGCHK_##severity, r17; \ or r17 = BUGCHK_##reboot, r17; \ break.m BREAK$C_SYS_BUGCHECK; /* * Macro (and helpers) to generate unique labels within macros. * This macro will generate a unique set of labels every time * the calling macro is expanded assuming that the C #line * directive is not used. Use only inside of other macros. * It relies on the fact that C macros are always expanded * into one line. * * NOTE: requires /STANDARD=COMMON to work * * Many conditions can be predicated within macros to avoid * branching altogether, but one example is code that does * a consistency check and bugchecks on failure. Since * bugcheck is a macro itself, it cannot be easily predicated. * * Credit to note 3162.* in the DEC C notes conference * * Usage: * * ias$$label(labid) * * labid - unique label identifier. ias$$label will generate * the same label for the same identifier within the * same macro. Labels will have the form: * Ln_labid where "n" is line number of the calling * macro. * * define VALIDATION_SAMPLE\ * [code that sets P6=1 if everything is OK] * (p6) br ias$$label(1)\ * bug_check(INCONSTATE)\ * ias$$label(1): */ #define ias$$xcat(x,y) x ## y #define ias$$cat(x,y) ias$$xcat(x,y) #define ias$$label(labid) ias$$cat(ias$$cat(L,__LINE__), ias$$cat(_, labid)) /* * EXC_PRINT - Exception print to EXC trace buffer * * This macro adds an informational message to the EXC trace buffer. * The ctrstr argument has similar syntax to a "printf" statement. * * Inputs: prefix - Text string to append to the start of labels used * by this macro. * ctrstr - The text and optional formatting directives to be * saved in the trace ring buffer, only the following * directives are allowed (no width): * %s - zero-terminated string * %a - ascii string (pointer and length) * %d - decimal value * %X - hexadecimal longword * %L - hexadecimal quadword * * Implied inputs: * out1-out5 The corresponding values to be formatted. For the %s * directive, this is the address of the zero-terminated * string. For the %a directive, this requires 2 arguments, * first the address of the string buffer, then the length * of the string (by value). Other directives, are passed * by value. * Output: none * * Usage Examples: * * mov out1 = 1 * EXC_PRINT(IAS1$, "This is an IAS test, index %d") * * mov out1 = r3 * mov out2 = r5 * EXC_PRINT(IAS2$, "This is a hex number %X and a quadword %L") * * Notes: * o If EXC tracing has not been started, no call is made to the tracing * routine. (This attempts to minimize the performance impact.) * o SP must be properly aligned for a call when the macro is invoked. * o GP, R8 and R9 are preserved across the call to the tracing routine. * */ #define EXC_PRINT(prefix, ctrstr) \ .global EXC$GQ_DEBUG ;\ .pushsection $DATA$, "wa", "progbits" ;\ prefix##string: ;\ stringz ctrstr ;\ .popsection ;\ \ addl r25 = @ltoff(EXC$GQ_DEBUG), gp ;\ ld8 r25 = [r25] ;\ ld8 r25 = [r25] ;\ tbit.z p6 = r25, 0 ;\ (p6) br.cond.spnt prefix##label ;\ \ mov r26 = 0xf ;\ andcm r25 = r25, r26 ;\ ld4 r25 = [r25] ;\ sxt4 r25 = r25 ;\ \ add r12 = -8*8, r12 ;\ add r26 = 2*8,r12 ;\ st8 [r26] = gp,8 ;\ st8 [r26] = r8,8 ;\ st8 [r26] = r9 ;\ \ ld8 r26 = [r25],8 ;\ ld8 gp = [r25] ;\ mov b6 = r26 ;\ \ mov r25 = 6 ;\ movl out0 = prefix##string ;\ br.call.sptk b0 = b6 ;\ \ add r26 = 2*8,r12 ;\ ld8 gp=[r26],8 ;\ ld8 r8=[r26],8 ;\ ld8 r9=[r26] ;\ add r12 = 8*8, r12 ;\ prefix##label: /* * TR_PRINT - Print to TR trace buffer * * This macro adds an informational message to the TR trace buffer. * The ctrstr argument has similar syntax to a "printf" statement. * * Inputs: prefix - Text string to append to the start of labels used * by this macro. * ctrstr - The text and optional formatting directives to be * saved in the trace ring buffer, only the following * directives are allowed (no width): * %s - zero-terminated string * %a - ascii string (pointer and length) * %d - decimal value * %X - hexadecimal longword * %L - hexadecimal quadword * * Implied inputs: * out1-out5 The corresponding values to be formatted. For the %s * directive, this is the address of the zero-terminated * string. For the %a directive, this requires 2 arguments, * first the address of the string buffer, then the length * of the string (by value). Other directives, are passed * by value. * Output: none * * Usage Examples: * * mov out1 = 1 * TR_PRINT(IAS1$, "This is an IAS test, index %d") * * mov out1 = r3 * mov out2 = r5 * TR_PRINT(IAS2$, "This is a hex number %X and a quadword %L") * * Notes: * o If TR tracing has not been started, no call is made to the tracing * routine. (This attempts to minimize the performance impact.) * o SP must be properly aligned for a call when the macro is invoked. * o GP, R8 and R9 are preserved across the call to the tracing routine. * */ #define TR_PRINT(prefix, ctrstr) \ .global TR$GQ_DEBUG ;\ .pushsection $DATA$, "wa", "progbits" ;\ prefix##string: ;\ stringz ctrstr ;\ .popsection ;\ \ addl r25 = @ltoff(TR$GQ_DEBUG), gp ;\ ld8 r25 = [r25] ;\ ld8 r25 = [r25] ;\ tbit.z p6 = r25, 0 ;\ (p6) br.cond.spnt prefix##label ;\ \ mov r26 = 0xf ;\ andcm r25 = r25, r26 ;\ ld4 r25 = [r25] ;\ sxt4 r25 = r25 ;\ \ add r12 = -8*8, r12 ;\ add r26 = 2*8,r12 ;\ st8 [r26] = gp,8 ;\ st8 [r26] = r8,8 ;\ st8 [r26] = r9 ;\ \ ld8 r26 = [r25],8 ;\ ld8 gp = [r25] ;\ mov b6 = r26 ;\ \ mov r25 = 6 ;\ movl out0 = prefix##string ;\ br.call.sptk b0 = b6 ;\ \ add r26 = 2*8,r12 ;\ ld8 gp=[r26],8 ;\ ld8 r8=[r26],8 ;\ ld8 r9=[r26] ;\ add r12 = 8*8, r12 ;\ prefix##label: #endif /* _IA64_ASM_H */