HALcomdef.h 30 KB

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