1 /*
2  * Copyright (c) 2019, The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef HAL_COMDEF_H
18 #define HAL_COMDEF_H
19 /*===========================================================================
20 
21                    S T A N D A R D    D E C L A R A T I O N S
22 
23 DESCRIPTION
24   This header file contains general types and macros that are of use
25   to all modules.  The values or definitions are dependent on the specified
26   target.  T_WINNT specifies Windows NT based targets, otherwise the
27   default is for ARM targets.
28 
29        T_WINNT  Software is hosted on an NT platforn, triggers macro and
30                 type definitions, unlike definition above which triggers
31                 actual OS calls
32 
33 DEFINED TYPES
34 
35        Name      Definition
36        -------   --------------------------------------------------------
37        byte      8  bit unsigned value
38        word      16 bit unsigned value
39        dword     32 bit unsigned value
40 
41        uint1     byte
42        uint2     word
43        uint4     dword
44 
45        uint8     8  bit unsigned value
46        uint16    16 bit unsigned value
47        uint32    32 bit unsigned value
48        uint64    64 bit unsigned value
49 
50        uint8_t     8  bit unsigned value
51        uint16_t    16 bit unsigned value
52        uint32_t    32 bit unsigned value
53        uint64_t    64 bit unsigned value
54 
55        int8      8  bit signed value
56        int16     16 bit signed value
57        int32     32 bit signed value
58        int64    64 bit signed value
59 
60        sint31    32 bit signed value
61        sint15    16 bit signed value
62        sint7     8  bit signed value
63 
64        int1      8  bit signed value
65        int2      16 bit signed value
66        int4      32 bit signed value
67 
68        boolean   8 bit boolean value
69 
70 DEFINED CONSTANTS
71 
72        Name      Definition
73        -------   --------------------------------------------------------
74        TRUE      Asserted boolean condition (Logical 1)
75        FALSE     Deasserted boolean condition (Logical 0)
76 
77        ON        Asserted condition
78        OFF       Deasserted condition
79 
80        NULL      Pointer to nothing
81 
82        PACKED    Used to indicate structures which should use packed
83                  alignment
84 
85        INLINE    Used to inline functions for compilers which support this
86 
87 ===========================================================================*/
88 
89 
90 /*===========================================================================
91 
92                       EDIT HISTORY FOR FILE
93 
94 This section contains comments describing changes made to this file.
95 Notice that changes are listed in reverse chronological order.
96 
97 when       who     what, where, why
98 --------   ---     ----------------------------------------------------------
99 01/27/16    rl     (c_lewisr) fix logic issues with int's
100 06/11/01    gr     Added MOD_BY_POWER_OF_TWO macro.
101 04/12/01    sq     Added inpdw and outpdw macros
102            vas     Added solaris support
103 04/06/01    gr     Removed the definitions of abs and labs.
104 01/25/01   day     Merged from MSM5105_COMMON.00.00.05.
105 					 Added include for stdlib.h within WINNT ifdef
106 					 Added support for ARM_ASM
107 					 Added support SWIG preprocessor.
108 09/09/99   tac     Merged in a bunch of panther changes.
109 08/11/99   jct     Corrected conditional compilation around labs to check for
110                    labs instead of abs
111 06/30/99   jct     Added PC_EMULATOR capability for INTLOCK and INTLOCKSAV
112 06/15/99   jct     Cleanup to make work in Windows NT environment.  Addition
113                    of int(n) types where n is 8,16,32,64 and addition of
114                    unit64.  Removal of OS comments and defines as this is replaced
115                    by T_WINNT.  Conditional inclusion of MAX, MIN, labs, abs,
116                    NULL definitions.  Removal of volatile from packed definition
117                    stdlib.h included for Win32 based targets since this replaces several
118                    of the define here.  Changed out uts calls to be comet calls.
119                    Added a defines for Windows NT targets to define away symbols
120                    no longer supported
121 04/09/99    ms     Lint cleanup.
122 04/01/99    ms     Lint cleanup.
123 02/17/99    ms     Parenthesized abs and labs.
124                    Defined __packed to volatile to exploit lint.
125 12/16/98   jct     Removed 80186 support
126 12/01/98    ms     Removed definition of bsp_io_base.
127 11/20/98    ms     Typecast to volatile pointers in inp,outp,inpw and outpw.
128 10/10/98   jct     Honing of OS and T_ definitions, added T_WINNT as a target
129                    which triggers something different then which OS since
130                    we may be running REX on an NT platform, but strictly
131                    speaking, the application software is using REX, not NT
132                    as the OS.  Changed ROM for WINNT/ARM targets to be nothing
133                    instead of const
134 09/09/98   jct     Updates to merge ARM support with 186 support, added some
135                    new type aliases, added some segmented architecture macros,
136                    updated comments, removed unused code, updated declaration
137                    of inp/outp to have cdecl
138 08/01/98   jct     Updates to support ARM processor
139 03/25/96   jah     Moved SET_VECT to 80186.h
140 02/06/96   fkm     Put ()s around Macros to Make Lint Happy
141 01/12/95   jah     Updated dependency in MACRO INTLOCK_SAV / INTFREE_SAV.
142 12/20/94   jah     Corrected typo in ARR_SIZE() macro comments
143 03/11/94   jah     Added #ifdef _lint of NULL as 0 for near/far lint problem.
144 06/11/93   jah     Changed FPOS() to cast the pointer to 'near' to avoid the
145                    compiler complaints about lost segments.
146 01/28/93   twp     Added ARR_SIZE macro to return number of array elements.
147 07/17/92   jah     Changed int1 from 'char' to 'signed char'
148 06/10/92   jah     Added WORD_LO/HI, INC_SAT
149 05/19/92   jah     Added header comments for macros & made them lint-friendly
150 05/04/92   jah     Added define for ROM
151 03/02/92   jah     Added in/outp prototypes, INT* Macro comments w/lint
152 02/20/92   arh     Added LOCAL macro and ifdef/endif around file
153 
154 ===========================================================================*/
155 
156 
157 /*===========================================================================
158 
159                             Data Declarations
160 
161 ===========================================================================*/
162 
163 /* -----------------------------------------------------------------------
164 ** We include target.h to get FEATURE definitions used for macro defines.
165 ** Note we only include this if TG is defined and target.h has not been
166 ** previously included.  This allows comdef.h to be reused outside the
167 ** scope of the target/customer featurization paradigm
168 ** ----------------------------------------------------------------------- */
169 #ifdef TG
170   #include "target.h"
171 #endif
172 
173 /* For NT apps we want to use the Win32 definitions and/or those
174 ** supplied by the Win32 compiler for things like NULL, MAX, MIN
175 ** abs, labs, etc.
176 */
177 #ifdef T_WINNT
178    #ifndef WIN32
179       #define WIN32
180    #endif
181    #include <stdlib.h>
182 #endif
183 #ifdef __KERNEL__
184 #include <linux/types.h>
185 #else
186 #include <stdint.h>
187 #endif
188 
189 /* ------------------------------------------------------------------------
190 ** Constants
191 ** ------------------------------------------------------------------------ */
192 
193 #ifdef TRUE
194 #undef TRUE
195 #endif
196 
197 #ifdef FALSE
198 #undef FALSE
199 #endif
200 
201 #define TRUE   1   /* Boolean true value. */
202 #define FALSE  0   /* Boolean false value. */
203 
204 #define  ON   1    /* On value. */
205 #define  OFF  0    /* Off value. */
206 
207 #ifdef _lint
208   #define NULL 0
209 #endif
210 
211 #ifndef NULL
212   #define NULL  0
213 #endif
214 
215 /* -----------------------------------------------------------------------
216 ** Standard Types
217 ** ----------------------------------------------------------------------- */
218 
219 /* The following definitions are the same accross platforms.  This first
220 ** group are the sanctioned types.
221 */
222 #ifndef _ARM_ASM_
223 typedef  unsigned char      boolean;     /* Boolean value type. */
224 #if defined(VV_FEATURE_COMPILING_64BIT)
225 typedef unsigned long       uint32;
226 #else
227 typedef  unsigned int       uint32;      /* Unsigned 32 bit value */
228 #endif
229 typedef  unsigned short     uint16;      /* Unsigned 16 bit value */
230 typedef  unsigned char      uint8;       /* Unsigned 8  bit value */
231 
232 #if defined(VV_FEATURE_COMPILING_64BIT)
233 typedef  signed long int    int32;       /* Signed 32 bit value */
234 #else
235 typedef  signed int         int32;       /* Signed 32 bit value */
236 #endif
237 typedef  signed short       int16;       /* Signed 16 bit value */
238 typedef  signed char        int8;        /* Signed 8  bit value */
239 
240 /* This group are the deprecated types.  Their use should be
241 ** discontinued and new code should use the types above
242 */
243 typedef  unsigned char     byte;         /* Unsigned 8  bit value type. */
244 typedef  unsigned short    word;         /* Unsinged 16 bit value type. */
245 #if defined(VV_FEATURE_COMPILING_64BIT)
246 typedef  unsigned int      dword;        /* Unsigned 32 bit value type. */
247 #else
248 typedef  unsigned long     dword;        /* Unsigned 32 bit value type. */
249 #endif
250 
251 typedef  unsigned char     uint1;        /* Unsigned 8  bit value type. */
252 typedef  unsigned short    uint2;        /* Unsigned 16 bit value type. */
253 #if defined(VV_FEATURE_COMPILING_64BIT)
254 typedef  unsigned int      uint4;        /* Unsigned 32 bit value type. */
255 #else
256 typedef  unsigned long     uint4;        /* Unsigned 32 bit value type. */
257 #endif
258 
259 typedef  signed char       int1;         /* Signed 8  bit value type. */
260 typedef  signed short      int2;         /* Signed 16 bit value type. */
261 #if defined(VV_FEATURE_COMPILING_64BIT)
262 typedef  int               int4;         /* Signed 32 bit value type. */
263 #else
264 typedef  long int          int4;         /* Signed 32 bit value type. */
265 #endif
266 
267 #if defined(VV_FEATURE_COMPILING_64BIT)
268 typedef  signed int        sint31;       /* Signed 32 bit value */
269 #else
270 typedef  signed long       sint31;       /* Signed 32 bit value */
271 #endif
272 typedef  signed short      sint15;       /* Signed 16 bit value */
273 typedef  signed char       sint7;        /* Signed 8  bit value */
274 
275 #if defined(HASTINGS) || defined(PHYDEVLIB_PRODUCT_HAWKEYE) || defined(PHYDEVLIB_PRODUCT_HAWKEYE2) || defined(CYPRESS) || defined (HASTINGSPRIME) || defined(PHYDEVLIB_PRODUCT_PINE)
276 typedef uint16 UWord16;
277 typedef uint32 UWord32;
278 typedef int32  Word32;
279 typedef int16  Word16;
280 typedef uint8  UWord8;
281 typedef int8   Word8;
282 typedef int32  Vect32;
283 #endif
284 
285 /* ---------------------------------------------------------------------
286 ** Compiler Keyword Macros
287 ** --------------------------------------------------------------------- */
288 #if (! defined T_WINNT) && (! defined TARGET_OS_SOLARIS)
289 #ifndef SWIG  /* The SWIG preprocessor gets confused by these */
290   /* Non WinNT Targets
291   */
292 #if defined(VV_FEATURE_COMPILING_64BIT)
293   typedef  signed long        int64;       /* Signed 64 bit value */
294   typedef  unsigned long      uint64;      /* Unsigned 64 bit value */
295 #else
296   typedef  signed long long   int64;       /* Signed 64 bit value */
297   typedef  unsigned long long uint64;      /* Unsigned 64 bit value */
298 #endif
299   #define PACKED __packed
300 #ifndef INLINE
301   #define INLINE __inline
302 #endif
303   #define CDECL
304 #endif /* SWIG */
305   #define far
306   #define near
307   #define _far
308   #define _near
309   #define _cdecl
310   #define cdecl
311   #define _pascal
312   #define _interrupt
313 
314 #else /* T_WINNT || TARGET_OS_SOLARIS */
315 
316   /* WINNT or SOLARIS based targets
317   */
318 #if (defined __GNUC__) || (defined TARGET_OS_SOLARIS)
319 #if defined(VV_FEATURE_COMPILING_64BIT)
320   typedef long                int64;
321   typedef unsigned long       uint64;
322 #else
323   typedef long long           int64;
324   typedef unsigned long long  uint64;
325 #endif
326 #else
327   typedef  __int64            int64;       /* Signed 64 bit value */
328   typedef  unsigned __int64   uint64;      /* Unsigned 64 bit value */
329 #endif
330   #define PACKED
331   /* INLINE is defined to __inline because WINNT targets work fine with it
332    * and defining it to nothing does not work because the inline function
333    * definition is then multiply defined.  Solaris may need a different value.
334    */
335   #define INLINE __inline
336   #ifndef CDECL
337      #define CDECL __cdecl
338   #endif
339   #define _pascal
340   #define _far
341   #define far
342   #define near
343   #define _near
344   #define cdecl
345   #define _cdecl
346   #define _interrupt
347   #define __packed
348   #define _fmemcpy memcpy
349 
350 #endif /* T_WINNT */
351 #endif // #ifndef _ARM_ASM_
352 
353 /* ----------------------------------------------------------------------
354 ** Lint does not understand __packed, so we define it away here.  In the
355 ** past we did this:
356 **   This helps us catch non-packed pointers accessing packed structures,
357 **   for example, (although lint thinks it is catching non-volatile pointers
358 **   accessing volatile structures).
359 **   This does assume that volatile is not being used with __packed anywhere
360 **   because that would make Lint see volatile volatile (grrr).
361 ** but found it to be more trouble than it was worth as it would emit bogus
362 ** errors
363 ** ---------------------------------------------------------------------- */
364 #ifdef _lint
365   #define __packed
366 #endif
367 
368 /* ----------------------------------------------------------------------
369 **                          STANDARD MACROS
370 ** ---------------------------------------------------------------------- */
371 
372 #ifndef SWIG /* these confuse the SWIG preprocessor and aren't needed for it */
373 
374 
375 /*===========================================================================
376 
377 MACRO MEM_B
378 MACRO MEM_W
379 
380 DESCRIPTION
381   Take an address and dereference it as a byte/word, allowing access to an
382   arbitrary memory byte/word.
383 
384 PARAMETERS
385   x     address to be dereferenced
386 
387 DEPENDENCIES
388   None
389 
390 RETURN VALUE
391   MEM_B byte at the given address
392   MEM_W word at the given address
393 
394 SIDE EFFECTS
395   None
396 
397 ===========================================================================*/
398 
399 #define  MEM_B( x )  ( *( (uint8 *) (x) ) )
400 #define  MEM_W( x )  ( *( (uint16 *) (x) ) )
401 
402 
403 
404 /*===========================================================================
405 
406 MACRO MAX
407 MACRO MIN
408 
409 DESCRIPTION
410   Evaluate the maximum/minimum of 2 specified arguments.
411 
412 PARAMETERS
413   x     parameter to compare to 'y'
414   y     parameter to compare to 'x'
415 
416 DEPENDENCIES
417   'x' and 'y' are referenced multiple times, and should remain the same
418   value each time they are evaluated.
419 
420 RETURN VALUE
421   MAX   greater of 'x' and 'y'
422   MIN   lesser of 'x' and 'y'
423 
424 SIDE EFFECTS
425   None
426 
427 ===========================================================================*/
428 #ifndef MAX
429    #define  MAX( x, y ) ( ((x) > (y)) ? (x) : (y) )
430 #endif
431 
432 #ifndef MIN
433    #define  MIN( x, y ) ( ((x) < (y)) ? (x) : (y) )
434 #endif
435 
436 
437 
438 /*===========================================================================
439 
440 MACRO FPOS
441 
442 DESCRIPTION
443   This macro computes the offset, in bytes, of a specified field
444   of a specified structure or union type.
445 
446 PARAMETERS
447   type          type of the structure or union
448   field         field in the structure or union to get the offset of
449 
450 DEPENDENCIES
451   None
452 
453 RETURN VALUE
454   The byte offset of the 'field' in the structure or union of type 'type'.
455 
456 SIDE EFFECTS
457   The lint error "Warning 545: Suspicious use of &" is suppressed within
458   this macro.  This is due to the desire to have lint not complain when
459   'field' is an array.
460 
461 ===========================================================================*/
462 
463 #define FPOS( type, field ) \
464     /*lint -e545 */ ( (dword) &(( type *) 0)-> field ) /*lint +e545 */
465 
466 
467 
468 /*===========================================================================
469 
470 MACRO FSIZ
471 
472 DESCRIPTION
473   This macro computes the size, in bytes, of a specified field
474   of a specified structure or union type.
475 
476 PARAMETERS
477   type          type of the structure or union
478   field         field in the structure or union to get the size of
479 
480 DEPENDENCIES
481   None
482 
483 RETURN VALUE
484   size in bytes of the 'field' in a structure or union of type 'type'
485 
486 SIDE EFFECTS
487   None
488 
489 ===========================================================================*/
490 
491 #define FSIZ( type, field ) sizeof( ((type *) 0)->field )
492 
493 
494 /*===========================================================================
495 
496 MACRO FLIPW
497 
498 DESCRIPTION
499   Takes a 2 byte array, with the most significant byte first, followed
500   by the least significant byte, and converts the quantity into a word
501   with Intel byte order (LSB first)
502 
503 PARAMETERS
504   ray   array of 2 bytes to be converted to a word
505 
506 DEPENDENCIES
507   None
508 
509 RETURN VALUE
510   word in Intel byte order comprised of the 2 bytes of ray.
511 
512 SIDE EFFECTS
513   None
514 
515 ===========================================================================*/
516 
517 #define  FLIPW( ray ) ( (((word) (ray)[0]) * 256) + (ray)[1] )
518 
519 
520 
521 /*===========================================================================
522 
523 MACRO FLOPW
524 
525 DESCRIPTION
526   Reverses bytes of word value and writes them to a 2 byte array.
527   Effectively the reverse of the FLIPW macro.
528 
529 PARAMETERS
530   ray   array to receive the 2 bytes from 'val'
531   val   word to break into 2 bytes and put into 'ray'
532 
533 DEPENDENCIES
534   None
535 
536 RETURN VALUE
537   None
538 
539 SIDE EFFECTS
540   None
541 
542 ===========================================================================*/
543 #define  FLOPW( ray, val ) \
544   (ray)[0] = ((val) / 256); \
545   (ray)[1] = ((val) & 0xFF)
546 
547 
548 
549 /*===========================================================================
550 
551 MACRO B_PTR
552 MACRO W_PTR
553 
554 DESCRIPTION
555   Casts the address of a specified variable as a pointer to byte/word,
556   allowing byte/word-wise access, e.g.
557   W_PTR ( xyz )[ 2 ] = 0x1234;  -or-    B_PTR ( xyz )[ 2 ] = 0xFF;
558 
559 PARAMETERS
560   var   the datum to get a word pointer to
561 
562 DEPENDENCIES
563   None
564 
565 RETURN VALUE
566   Word pointer to var
567 
568 SIDE EFFECTS
569   None
570 
571 ===========================================================================*/
572 
573 #define  B_PTR( var )  ( (byte *) (void *) &(var) )
574 #define  W_PTR( var )  ( (word *) (void *) &(var) )
575 
576 
577 /*===========================================================================
578 
579 MACRO WORD_LO
580 MACRO WORD_HI
581 
582 DESCRIPTION
583   Take a word and extract the least-significant or most-significant byte.
584 
585 PARAMETERS
586   xxx   word to extract the Low/High from
587 
588 DEPENDENCIES
589   None
590 
591 RETURN VALUE
592   WORD_LO       Least significant byte of xxx.
593   WORD_HI       Most significant byte of xxx.
594 
595 SIDE EFFECTS
596   None
597 
598 ===========================================================================*/
599 
600 #define  WORD_LO(xxx)  ((uint8) ((uint16)(xxx) & 255))
601 #define  WORD_HI(xxx) \
602   /*lint -e572 */  ((uint8) ((uint16)(xxx) >> 8))  /*lint +e572 */
603 
604 
605 /*===========================================================================
606 
607 MACRO RND8
608 
609 DESCRIPTION
610   RND8 rounds a number up to the nearest multiple of 8.
611 
612 PARAMETERS
613   x     Number to be rounded up
614 
615 DEPENDENCIES
616   None
617 
618 RETURN VALUE
619   x rounded up to the nearest multiple of 8.
620 
621 SIDE EFFECTS
622   None
623 
624 ===========================================================================*/
625 
626 #define RND8( x )       ((((x) + 7) / 8 ) * 8 )
627 
628 
629 /*===========================================================================
630 
631 MACRO INTLOCK / INTFREE
632 
633 DESCRIPTION
634   INTLOCK Saves current interrupt state on stack then disables interrupts.
635   Used in conjunction with INTFREE.
636 
637   INTFREE Restores previous interrupt state from stack.  Used in conjunction
638   with INTLOCK.
639 
640 PARAMETERS
641   None
642 
643 DEPENDENCIES
644   The stack level when INTFREE is called must be as it was just after INTLOCK
645   was called.  The Microsoft C compiler does not always pop the stack after a
646   subroutine call, but instead waits to do a 'big' pop after several calls.
647   This causes these macros to fail.  Do not place subroutine calls between
648   these macros.  Use INTLOCK/FREE_SAV in those cases.
649 
650 RETURN VALUE
651   None
652 
653 SIDE EFFECTS
654   INTLOCK turn off interrupts
655   INTFREE restore the interrupt mask saved previously
656 
657 ===========================================================================*/
658 #if defined(PC_EMULATOR_H) && ! defined(T_REXNT)
659 
660    #define PC_EMULATOR_INTLOCK
661    #include PC_EMULATOR_H
662    #undef PC_EMULATOR_INTLOCK
663 
664 #elif defined(T_WINNT)
665 
666    #define INTLOCK()
667    #define INTFREE()
668 
669 #elif !defined( _ARM_ASM_)
670 
671 //  #include "rex.h"
672 //  #define  INTLOCK( )  { dword sav = rex_int_lock();
673 //  #define  INTFREE( )  if(!sav) (void)rex_int_free();}
674 
675    #define INTLOCK()
676    #define INTFREE()
677 
678 #endif
679 
680 
681 
682 /*===========================================================================
683 
684 MACRO INTLOCK_SAV / INTFREE_SAV
685 
686 DESCRIPTION
687   INTLOCK_SAV Saves current interrupt state in specified variable sav_var
688   then disables interrupts.  Used in conjunction with INTFREE_SAV.
689 
690   INTFREE_SAV Restores previous interrupt state from specified variable
691   sav_var.  Used in conjunction with INTLOCK_SAV.
692 
693 PARAMETERS
694   sav_var       Current flags register, including interrupt status
695 
696 DEPENDENCIES
697   None.
698 
699 RETURN VALUE
700   None
701 
702 SIDE EFFECTS
703   INTLOCK_SAV turn off interrupts
704   INTFREE_SAV restore the interrupt mask saved previously
705 
706 ===========================================================================*/
707 
708 
709 #ifdef _lint    /* get lint to 'know' the parameter is accessed */
710 
711   #define  INTLOCK_SAV(sav_var)   (sav_var = 1)
712   #define  INTFREE_SAV(sav_var)   (sav_var = sav_var + 1)
713 
714 #else
715 
716    #if defined( PC_EMULATOR_H) && !defined( T_REXNT)
717 
718       #define PC_EMULATOR_INTLOCKSAV
719       #include PC_EMULATOR_H
720       #undef  PC_EMULATOR_INTLOCKSAV
721 
722    #elif defined (T_WINNT)
723 
724      #define  INTLOCK_SAV( sav_var )
725      #define  INTFREE_SAV( sav_var )
726 
727    #elif !defined( _ARM_ASM_)
728 
729 //     #include "rex.h"
730 //     #define  INTLOCK_SAV( sav_var )  sav_var = rex_int_lock()
731 //     #define  INTFREE_SAV( sav_var )  if(!sav_var) rex_int_free()
732      #define  INTLOCK_SAV(sav_var)   (sav_var = 1)
733      #define  INTFREE_SAV(sav_var)   (sav_var = sav_var + 1)
734 
735    #else
736 
737      #define  INTLOCK_SAV(sav_var)   (sav_var = 1)
738      #define  INTFREE_SAV(sav_var)   (sav_var = sav_var + 1)
739 
740    #endif
741 
742 #endif /* END if _lint */
743 
744 
745 
746 /*===========================================================================
747 
748 MACRO UPCASE
749 
750 DESCRIPTION
751   Convert a character to uppercase, the character does not have to
752   be printable or a letter.
753 
754 PARAMETERS
755   c             Character to be converted
756 
757 DEPENDENCIES
758   'c' is referenced multiple times, and should remain the same value
759   each time it is evaluated.
760 
761 RETURN VALUE
762   Uppercase equivalent of the character parameter
763 
764 SIDE EFFECTS
765   None
766 
767 ===========================================================================*/
768 
769 #define  UPCASE( c ) ( ((c) >= 'a' && (c) <= 'z') ? ((c) - 0x20) : (c) )
770 
771 
772 /*===========================================================================
773 
774 MACRO DECCHK
775 MACRO HEXCHK
776 
777 DESCRIPTION
778   These character attribute macros are similar to the standard 'C' macros
779   (isdec and ishex), but do not rely on the character attributes table used
780   by Microsoft 'C'.
781 
782 PARAMETERS
783   c             Character to be examined
784 
785 DEPENDENCIES
786   None
787 
788 RETURN VALUE
789   DECCHK        True if the character is a decimal digit, else False
790   HEXCHK        True if the chacters is a hexidecimal digit, else False
791 
792 SIDE EFFECTS
793   None
794 
795 ===========================================================================*/
796 
797 #define  DECCHK( c ) ((c) >= '0' && (c) <= '9')
798 
799 #define  HEXCHK( c ) ( ((c) >= '0' && (c) <= '9') ||\
800                        ((c) >= 'A' && (c) <= 'F') ||\
801                        ((c) >= 'a' && (c) <= 'f') )
802 
803 
804 /*===========================================================================
805 
806 MACRO INC_SAT
807 
808 DESCRIPTION
809   Increment a value, but saturate it at its maximum positive value, do not
810   let it wrap back to 0 (unsigned) or negative (signed).
811 
812 PARAMETERS
813   val           value to be incremented with saturation
814 
815 DEPENDENCIES
816   None
817 
818 RETURN VALUE
819   val
820 
821 SIDE EFFECTS
822   val is updated to the new value
823 
824 ===========================================================================*/
825 
826 #define  INC_SAT( val )  (val = ((val)+1 > (val)) ? (val)+1 : (val))
827 
828 
829 /*===========================================================================
830 
831 MACRO ARR_SIZE
832 
833 DESCRIPTION
834   Return the number of elements in an array.
835 
836 PARAMETERS
837   a             array name
838 
839 DEPENDENCIES
840   None
841 
842 RETURN VALUE
843   Number of elements in array a
844 
845 SIDE EFFECTS
846   None.
847 
848 ===========================================================================*/
849 
850 #define  ARR_SIZE( a )  ( sizeof( (a) ) / sizeof( (a[0]) ) )
851 
852 /*===========================================================================
853                      MACRO MOD_BY_POWER_OF_TWO
854 
855      Will calculate x % y, where x is a non-negative integer and
856      y is a power of 2 from 2^0..2^32.
857 
858      Will work for 2^0, 2^1, 2^2, 2^3, 2^4, ... 2^32
859       ie.            1,   2,   4,   8,  16, ... 4294967296
860 ===========================================================================*/
861 
862 #define MOD_BY_POWER_OF_TWO( val, mod_by ) \
863            ( (dword)(val) & (dword)((mod_by)-1) )
864 
865 /* -------------------------------------------------------------------------
866 **                       Debug Declarations
867 ** ------------------------------------------------------------------------- */
868 
869 /* Define 'SHOW_STAT' in order to view static's as globals
870 ** (e.g. cl /DSHOW_STAT foo.c) If 'SHOW_STAT' is not defined,
871 ** it gets defined as 'static'
872 */
873 #ifdef LOCAL
874 #undef LOCAL
875 #endif
876 
877 #ifdef SHOW_STAT
878   #define LOCAL
879 #else
880   #define LOCAL static
881 #endif
882 
883 
884 /*===========================================================================
885 
886                       FUNCTION DECLARATIONS
887 
888 ===========================================================================*/
889 
890 
891 
892 /*===========================================================================
893 
894 FUNCTION inp, outp, inpw, outpw, inpdw, outpdw
895 
896 DESCRIPTION
897   IN/OUT port macros for byte and word ports, typically inlined by compilers
898   which support these routines
899 
900 PARAMETERS
901   inp(   xx_addr )
902   inpw(  xx_addr )
903   inpdw( xx_addr )
904   outp(   xx_addr, xx_byte_val  )
905   outpw(  xx_addr, xx_word_val  )
906   outpdw( xx_addr, xx_dword_val )
907       xx_addr      - Address of port to read or write (may be memory mapped)
908       xx_byte_val  - 8 bit value to write
909       xx_word_val  - 16 bit value to write
910       xx_dword_val - 32 bit value to write
911 
912 DEPENDENCIES
913   None
914 
915 RETURN VALUE
916   inp/inpw/inpdw: the byte, word or dword read from the given address
917   outp/outpw/outpdw: the byte, word or dword written to the given address
918 
919 SIDE EFFECTS
920   None.
921 
922 ===========================================================================*/
923 
924 #ifdef PC_EMULATOR_H
925 
926   /* For PC emulation, include a header which defines inp/outp/inpw/outpw
927   ** with the semantics above
928   */
929   #define PC_EMULATOR_IO
930   #include PC_EMULATOR_H
931   #undef  PC_EMULATOR_IO
932 
933 #else
934 
935   /* ARM based targets use memory mapped i/o, so the inp/outp calls are
936   ** macroized to access memory directly
937   */
938 
939 #ifndef CDVI_SVTB
940 #if defined(VV_FEATURE_COMPILING_64BIT)
941     #define inp(port)         (*((volatile dword *)  (port)))
942     #define inpb(port)        (*((volatile byte *)   (port)))
943     #define inpw(port)        (*((volatile word *)   (port)))
944     #define inpdw(port)       (*((volatile dword *)  (port)))
945     #define inp64(port)       (*((volatile uint64 *) (port)))
946 
947     #define outp(port, val)   (*((volatile dword *)  (port)) = ((dword)  (val)))
948     #define outpb(port, val)  (*((volatile byte *)   (port)) = ((byte)   (val)))
949     #define outpw(port, val)  (*((volatile word *)   (port)) = ((word)   (val)))
950     #define outpdw(port, val) (*((volatile dword *)  (port)) = ((dword)  (val)))
951     #define outp64(port, val) (*((volatile uint64 *) (port)) = ((uint64) (val)))
952 #else
953     #define inp(port)         (*((volatile byte *) (port)))
954     #define inpw(port)        (*((volatile word *) (port)))
955     #define inpdw(port)       (*((volatile dword *)(port)))
956 
957     #define outp(port, val)   (*((volatile byte *) (port)) = ((byte) (val)))
958     #define outpw(port, val)  (*((volatile word *) (port)) = ((word) (val)))
959     #define outpdw(port, val) (*((volatile dword *) (port)) = ((dword) (val)))
960 #endif // VV_FEATURE_COMPILING_64BIT
961 
962 #else  // CDVI_SVTB
963 #ifdef CDVI_SVTB_VERBOSE
964   #define inp(port)         ((printf("CDVI_SVTB_VERBOSE: Calling bus_read from %s:%0d\n", __FILE__,__LINE__)&0) + bus_read(port))
965 #else
966   #define inp(port)         bus_read(port)
967 #endif
968   #define inpw(port)        inp(port)
969   #define inpdw(port)       inp(port)
970 
971 #ifdef CDVI_SVTB_VERBOSE
972   #define outp(port, val)   ((printf("CDVI_SVTB_VERBOSE: Calling bus_write from %s:%0d\n",__FILE__,__LINE__)&0) + bus_write (port, val))
973 #else
974   #define outp(port, val)   bus_write (port, val)
975 #endif
976   #define outpw(port, val)  outp (port, val)
977   #define outpdw(port, val) outp (port, val)
978 #endif
979   #define outp32  outpdw
980 
981 #endif
982 
983 
984 /*===========================================================================
985 
986 FUNCTION enable, disable
987 
988 DESCRIPTION
989   Interrupt enable and disable routines.  Enable should cause the CPU to
990   allow interrupts and disable should cause the CPU to disallow
991   interrupts
992 
993 PARAMETERS
994   None
995 
996 DEPENDENCIES
997   None
998 
999 RETURN VALUE
1000   None
1001 
1002 SIDE EFFECTS
1003   None.
1004 
1005 ===========================================================================*/
1006 
1007 #ifndef T_WINNT
1008 
1009   /* Common definitions */
1010   #define VV_ENABLE 1
1011   #define VV_DISABLE 0
1012   #define VV_REG_MASK_BIT0 0x0001
1013   #define VV_REG_MASK_BIT1 0x0002
1014   #define VV_REG_MASK_BIT2 0x0004
1015   #define VV_REG_MASK_BIT3 0x0008
1016   #define VV_REG_MASK_BIT4 0x0010
1017   #define VV_REG_MASK_BIT5 0x0020
1018   #define VV_REG_MASK_BIT6 0x0040
1019   #define VV_REG_MASK_BIT7 0x0080
1020 
1021   /* ARM has no such definition, so we provide one here to enable/disable
1022   ** interrupts
1023   */
1024   #define _disable() (void)rex_int_lock()
1025   #define _enable()  (void)rex_int_free()
1026 
1027 #endif
1028 
1029 #endif /* SWIG */
1030 #endif
1031 
1032 
1033