home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 7.ddi / EMUSRC.ZIP / EMURULES.ASI < prev    next >
Encoding:
Text File  |  1992-06-10  |  15.6 KB  |  525 lines

  1. ;[]-----------------------------------------------------------------[]
  2. ;|      EMURULES.ASI  --  Rules & Structures for assembler           |
  3. ;[]-----------------------------------------------------------------[]
  4.  
  5. ;
  6. ;       C/C++ Run Time Library - Version 5.0
  7. ;       Copyright (c) 1987, 1992 by Borland International
  8. ;       All Rights Reserved.
  9.  
  10.         PAGE
  11.  
  12. ;*** First we begin with a few of the major constants of C.
  13.  
  14. false   equ     0       ; Beware !  For incoming parameters, non-false = true.
  15. true    equ     1       ; For results, we generate the proper numbers.
  16.  
  17. lesser  equ     -1      ; Incoming, lesser < 0
  18. equal   equ      0
  19. greater equ      1      ; Incoming, greater > 0
  20.  
  21. ; Small Code - Small Data
  22.     LPROG           equ     false
  23.     LDATA           equ     false
  24.  
  25.  
  26. ;[]------------------------------------------------------------[]
  27. ;|                                                              |
  28. ;|      C Naming Convention Macros                              |
  29. ;|                                                              |
  30. ;[]------------------------------------------------------------[]
  31.  
  32. UNDERSCORE      EQU     1
  33.  
  34. ExtSym@ MACRO   Sym, sType, sName
  35.         IFNB    <sName>
  36.         IFIDN   <sName>, <__PASCAL__>
  37. NAMING      =       0
  38.         ELSE
  39. NAMING      =       UNDERSCORE
  40.         ENDIF
  41.         ENDIF
  42.         IF      NAMING
  43.         EXTRN   _&Sym : sType
  44. Sym&@   equ     _&Sym
  45.         ELSE
  46.         EXTRN   Sym : sType
  47. Sym&@   equ     Sym
  48.         ENDIF
  49.         ENDM
  50.  
  51. PubSym@ MACRO   Sym, Definition, sName
  52.         IFNB    <sName>
  53.         IFIDN   <sName>, <__PASCAL__>
  54. NAMING      =       0
  55.         ELSE
  56. NAMING      =       UNDERSCORE
  57.         ENDIF
  58.         ENDIF
  59.         IF      NAMING
  60.         PUBLIC  _&Sym
  61. _&Sym   Definition
  62. Sym&@   equ     _&Sym
  63.         ELSE
  64.         PUBLIC  Sym
  65. Sym     Definition
  66. Sym&@   equ     Sym
  67.         ENDIF
  68.         ENDM
  69.  
  70. Static@ MACRO   Sym, Definition, sName
  71.         IFNB    <sName>
  72.         IFIDN   <sName>, <__PASCAL__>
  73. NAMING      =       0
  74.         ELSE
  75. NAMING      =       UNDERSCORE
  76.         ENDIF
  77.         ENDIF
  78.         IF      NAMING
  79. _&Sym   Definition
  80. Sym&@   equ     _&Sym
  81.         ELSE
  82. Sym     Definition
  83. Sym&@   equ     Sym
  84.         ENDIF
  85.         ENDM
  86.         PAGE
  87. ;[]------------------------------------------------------------[]
  88. ;|                                                              |
  89. ;|      Macros which are Data Size Dependent                    |
  90. ;|                                                              |
  91. ;[]------------------------------------------------------------[]
  92.  
  93. IF      LDATA
  94. DPTR_           equ     DWORD PTR
  95. dPtrSize        equ     4
  96. LES_            equ     LES
  97. ES_             equ     ES:
  98. SS_             equ     SS:
  99. LDS_            equ     LDS
  100.  
  101. pushDS_         MACRO
  102.                 PUSH    DS
  103.                 ENDM
  104.  
  105. popDS_          MACRO
  106.                 POP    DS
  107.                 ENDM
  108.  
  109. PushPtr         MACRO   dPtrOff, dPtrSeg
  110.                 PUSH    dPtrSeg
  111.                 PUSH    dPtrOff
  112.                 ENDM
  113.  
  114.  
  115. dPtr@           MACRO   Sym, VALUE, sName       ;; Static Data pointer
  116. Static@         Sym, <DD        VALUE>, sName
  117.                 ENDM
  118.  
  119. dPtrPub@        MACRO   Sym, VALUE, sName       ;; Global Data Pointer
  120. PubSym@         Sym, <DD        VALUE>, sName
  121.                 ENDM
  122.  
  123. dPtrExt@        MACRO   Sym, sName      ;; External Data Pointer
  124. ExtSym@         Sym, DWORD, sName
  125.                 ENDM
  126. ELSE
  127. DPTR_           equ     WORD PTR
  128. dPtrSize        equ     2
  129. LES_            equ     MOV
  130. ES_             equ     DS:
  131. SS_             equ     DS:
  132. LDS_            equ     MOV
  133.  
  134. pushDS_         MACRO
  135.                 ENDM
  136.  
  137. popDS_          MACRO
  138.                 ENDM
  139.  
  140. PushPtr         MACRO   dPtrOff, dPtrSeg
  141.                 PUSH    dPtrOff
  142.                 ENDM
  143.  
  144. dPtr@           MACRO   Sym, VALUE, sName       ;; Static Data pointer
  145. Static@         Sym, <DW        VALUE>, sName
  146.                 ENDM
  147.  
  148. dPtrPub@        MACRO   Sym, VALUE, sName       ;; Global Data Pointer
  149. PubSym@         Sym, <DW        VALUE>, sName
  150.                 ENDM
  151.  
  152. dPtrExt@        MACRO   Sym, sName      ;; External Data Pointer
  153. ExtSym@         Sym, WORD, sName
  154.                 ENDM
  155. ENDIF
  156.         PAGE
  157. ;[]------------------------------------------------------------[]
  158. ;|                                                              |
  159. ;|      Macros which are Code Size Dependent                    |
  160. ;|                                                              |
  161. ;[]------------------------------------------------------------[]
  162.  
  163. IF      LPROG
  164. CPTR_           equ     DWORD PTR
  165. cPtrSize        equ     4
  166.  
  167. Proc@           MACRO   Sym, sName      ;; Open a Static function
  168. Static@         Sym, <PROC      FAR>, sName
  169.                 ENDM
  170.  
  171. PubProc@        MACRO   Sym, sName      ;; Open a Public function
  172. PubSym@         Sym, <PROC      FAR>, sName
  173.                 ENDM
  174.  
  175. ExtProc@        MACRO   Sym, sName      ;; External Function
  176. ExtSym@         Sym, FAR, sName
  177.                 ENDM
  178.  
  179. cPtr@           MACRO   Sym, VALUE, sName       ;; Static Function pointer
  180. Static@         Sym, <DD        VALUE>, sName
  181.                 ENDM
  182.  
  183. cPtrPub@        MACRO   Sym, VALUE, sName;; Global Function Pointer
  184. PubSym@         Sym, <DD        VALUE>, sName
  185.                 ENDM
  186.  
  187. cPtrExt@        MACRO   Sym, sName      ;; External Function Pointer
  188. ExtSym@         Sym, DWORD, sName
  189.                 ENDM
  190. ELSE
  191. CPTR_           equ     WORD PTR
  192. cPtrSize        equ     2
  193.  
  194. Proc@           MACRO   Sym, sName      ;; Open a Static function
  195. Static@         Sym, <PROC      NEAR>, sName
  196.                 ENDM
  197.  
  198. PubProc@        MACRO   Sym, sName      ;; Open a Public function
  199. PubSym@         Sym, <PROC      NEAR>, sName
  200.                 ENDM
  201.  
  202. ExtProc@        MACRO   Sym, sName      ;; External Function
  203. ExtSym@         Sym, NEAR, sName
  204.                 ENDM
  205.  
  206. cPtr@           MACRO   Sym, VALUE, sName       ;; Static Function pointer
  207. Static@         Sym, <DW        VALUE>, sName
  208.                 ENDM
  209.  
  210. cPtrPub@        MACRO   Sym, VALUE, sName       ;; Global Function Pointer
  211. PubSym@         Sym, <DW        VALUE>, sName
  212.                 ENDM
  213.  
  214. cPtrExt@        MACRO   Sym, sName      ;; External Function Pointer
  215. ExtSym@         Sym, WORD, sName
  216.                 ENDM
  217. ENDIF
  218.  
  219. EndProc@        MACRO   Sym, sName      ;; Close a function
  220. Static@         Sym, ENDP, sName
  221.                 ENDM
  222.         PAGE
  223. ;[]------------------------------------------------------------[]
  224. ;|                                                              |
  225. ;|      Miscellaneous Definitions                               |
  226. ;|                                                              |
  227. ;[]------------------------------------------------------------[]
  228.  
  229. ;*** Set up some macros for procedure parameters and export/import
  230.  
  231. nearCall        STRUC
  232. nearBP          dw      ?
  233. nearIP          dw      ?
  234. nearParam       dw      ?
  235. nearCall        ENDS
  236.  
  237. farCall         STRUC
  238. farBP           dw      ?
  239. farCSIP         dd      ?
  240. aParam          dw      ?
  241. farCall         ENDS
  242.  
  243. ;*** Next, we define some convenient structures to access the parts
  244. ;       of larger objects.
  245.  
  246. _twoBytes       STRUC
  247. BY0     db      ?
  248. BY1     db      ?
  249. _twoBytes       ENDS
  250.  
  251. _fourWords      STRUC
  252. W0      dw      ?
  253. W1      dw      ?
  254. W2      dw      ?
  255. W3      dw      ?
  256. _fourWords      ENDS
  257.  
  258. _twoDwords      STRUC
  259. DD0     dd      ?
  260. DD1     dd      ?
  261. _twoDwords      ENDS
  262.  
  263. _aFloat         STRUC
  264. double          dq      ?
  265. _aFloat         ENDS
  266.  
  267. ; How to invoke MSDOS.
  268.  
  269. MSDOS@  MACRO
  270.         int     21h
  271.         ENDM
  272.         PAGE
  273. ;[]------------------------------------------------------------[]
  274. ;|                                                              |
  275. ;|      Emulator Segments and Definitions                       |
  276. ;|                                                              |
  277. ;|      The Emu287 module is in  a separate model from other    |
  278. ;|      code. It uses  the DSeg@ data segment, but  since it    |
  279. ;|      does not actually share data the important aspect of    |
  280. ;|      the Data  is the class  name 'DATA'. It  has its own    |
  281. ;|      stack inside  the data segment. The  code segment is    |
  282. ;|      completely  separate from  other code  segments. The    |
  283. ;|      only contact  between Emu287 and  other code is  via    |
  284. ;|      soft interrupts 34h..3Eh.                               |
  285. ;|                                                              |
  286. ;[]------------------------------------------------------------[]
  287.  
  288. EmuSeg@  MACRO
  289. EMU_PROG SEGMENT  PARA  PUBLIC "CODE"
  290. ASSUME   CS : EMU_PROG
  291.          ENDM
  292.  
  293. EmuSegEnd@ MACRO
  294. EMU_PROG ENDS
  295.          ENDM
  296.  
  297. E87Seg@  MACRO
  298. E87_PROG SEGMENT  PARA  PUBLIC "CODE"
  299. ASSUME   CS : E87_PROG
  300.          ENDM
  301.  
  302. E87SegEnd@ MACRO
  303. E87_PROG ENDS
  304.          ENDM
  305.  
  306.  
  307.  
  308. ; The next section concerns the use of registers.  SI and DI are used
  309. ;       for register variables, and must be conserved.
  310.  
  311. ; Registers AX, BX, CX, DX will not be preserved across function calls.
  312.  
  313. ; Firstly, the registers to be conserved through function calls, including
  314. ;       the setup of local variables.
  315.  
  316. link@   MACRO   _si,_di,_ES,locals
  317.         push    bp
  318.         mov     bp, sp
  319.         IFNB    <locals>
  320.                 lea     sp, locals
  321.         ENDIF
  322.         IFNB    <_si>
  323.                 push    si
  324.         ENDIF
  325.         IFNB    <_di>
  326.                 push    di
  327.         ENDIF
  328. ENDM
  329.  
  330. unLink@ MACRO   _si,_di,_ES,locals
  331.         IFNB    <_di>
  332.                 pop     di
  333.         ENDIF
  334.         IFNB    <_si>
  335.                 pop     si
  336.         ENDIF
  337.         IFNB    <locals>
  338.                 mov     sp, bp
  339.         ENDIF
  340.         pop     bp
  341. ENDM
  342.  
  343. ; Remainder of file only used for language denpendent
  344. ; initialization and trapping.
  345.  
  346.         PAGE
  347. ;[]------------------------------------------------------------[]
  348. ;|                                                              |
  349. ;|      iNDP Status and Control words definitions               |
  350. ;|                                                              |
  351. ;[]------------------------------------------------------------[]
  352.  
  353. ;/* 8087/80287 Status Word format   */
  354.  
  355. SW_INVALID              equ     00001h  ;/* Invalid operation            */
  356. SW_DENORMAL             equ     00002h  ;/* Denormalized operand         */
  357. SW_ZERODIVIDE           equ     00004h  ;/* Zero divide                  */
  358. SW_OVERFLOW             equ     00008h  ;/* Overflow                     */
  359. SW_UNDERFLOW            equ     00010h  ;/* Underflow                    */
  360. SW_INEXACT              equ     00020h  ;/* Precision (Inexact result)   */
  361.  
  362. ;/* 8087/80287 Control Word format */
  363.  
  364. MCW_EM                  equ     0003Fh  ;/* interrupt Exception Masks    */
  365.     EM_INVALID          equ     00001h  ;/*   invalid                    */
  366.     EM_DENORMAL         equ     00002h  ;/*   denormal                   */
  367.     EM_ZERODIVIDE       equ     00004h  ;/*   zero divide                */
  368.     EM_OVERFLOW         equ     00008h  ;/*   overflow                   */
  369.     EM_UNDERFLOW        equ     00010h  ;/*   underflow                  */
  370.     EM_INEXACT          equ     00020h  ;/*   inexact (precision)        */
  371.  
  372. MCW_IC                  equ     01000h  ;/* Infinity Control             */
  373.     IC_AFFINE           equ     01000h  ;/*   affine                     */
  374.     IC_PROJECTIVE       equ     00000h  ;/*   projective                 */
  375.  
  376. MCW_RC                  equ     00C00h  ;/* Rounding Control             */
  377.     RC_CHOP             equ     00C00h  ;/*   chop                       */
  378.     RC_UP               equ     00800h  ;/*   up                         */
  379.     RC_DOWN             equ     00400h  ;/*   down                       */
  380.     RC_NEAR             equ     00000h  ;/*   near                       */
  381.  
  382. MCW_PC                  equ     00300h  ;/* Precision Control            */
  383.     PC_24               equ     00000h  ;/*    24 bits                   */
  384.     PC_53               equ     00200h  ;/*    53 bits                   */
  385.     PC_64               equ     00300h  ;/*    64 bits                   */
  386.  
  387. ;/* 8087/80287 Initial Control Word */
  388. ;/* use affine infinity, mask underflow and precision exceptions */
  389. ;/* should be same as in float.h  */
  390. ; No longer used!
  391. ;CW_DEFAULT     equ     (RC_NEAR+PC_64+IC_AFFINE+EM_UNDERFLOW+EM_INEXACT)
  392.  
  393.  
  394. ;[]------------------------------------------------------------[]
  395. ;|                                                              |
  396. ;|      Segment Declarations Macros                             |
  397. ;|                                                              |
  398. ;[]------------------------------------------------------------[]
  399.  
  400. CSeg@           MACRO           ;; Open a Code Segment
  401. _TEXT   SEGMENT BYTE PUBLIC 'CODE'
  402.         ASSUME  CS:_TEXT
  403.                 ENDM
  404.  
  405. CSegEnd@        MACRO           ;; Close a Code Segment
  406. _TEXT   ENDS
  407.                 ENDM
  408.  
  409. DSeg@           MACRO           ;; Open a Data Segment  (initialized)
  410. _DATA   SEGMENT PARA PUBLIC 'DATA'
  411.                 ENDM
  412.  
  413. DSegEnd@        MACRO           ;; Close a Data Segment (initialized)
  414. _DATA   ENDS
  415.                 ENDM
  416.  
  417. IFDEF __BSS__
  418.     IFNDEF __HUGE__
  419.         BSeg@           MACRO   ;; Open a Data Segment  (un-initialized)
  420.         _BSS    SEGMENT WORD PUBLIC 'BSS'
  421.                 ENDM
  422.  
  423.         BSegEnd@        MACRO   ;; Close a Data Segment (un-initialized)
  424.         _BSS    ENDS
  425.                         ENDM
  426.     ENDIF
  427. ENDIF
  428.  
  429. Header@ MACRO
  430. _TEXT   SEGMENT BYTE PUBLIC 'CODE'
  431. _TEXT   ENDS
  432. _DATA   SEGMENT PARA PUBLIC 'DATA'
  433. _DATA   ENDS
  434. IFDEF __BSS__
  435.     IFNDEF  __HUGE__
  436.         _BSS    SEGMENT WORD PUBLIC 'BSS'
  437.         _BSS    ENDS
  438.     ENDIF
  439. ENDIF
  440.  
  441. IFDEF __BSS__
  442.     IFDEF   __TINY__
  443.         DGROUP  GROUP   _TEXT, _DATA, _BSS
  444.     ELSE
  445.         IFDEF __HUGE__
  446.             DGROUP  GROUP   _DATA
  447.         ELSE
  448.             DGROUP  GROUP   _DATA, _BSS
  449.         ENDIF
  450.     ENDIF
  451. ELSE
  452.     IFDEF   __TINY__
  453.         DGROUP  GROUP   _TEXT, _DATA
  454.     ELSE
  455.         DGROUP  GROUP   _DATA
  456.     ENDIF
  457. ENDIF
  458.         ASSUME  CS:_TEXT, DS:DGROUP
  459.         ENDM
  460.         PAGE
  461. ;[]------------------------------------------------------------[]
  462. ;|                                                              |
  463. ;|      C Naming Convention Macros                              |
  464. ;|                                                              |
  465. ;[]------------------------------------------------------------[]
  466.  
  467. UNDERSCORE      EQU     1
  468.  
  469. ExtSym@ MACRO   Sym, sType, sName
  470.         IFNB    <sName>
  471.         IFIDN   <sName>, <__PASCAL__>
  472. NAMING      =       0
  473.         ELSE
  474. NAMING      =       UNDERSCORE
  475.         ENDIF
  476.         ENDIF
  477.         IF      NAMING
  478.         EXTRN   _&Sym : sType
  479. Sym&@   equ     _&Sym
  480.         ELSE
  481.         EXTRN   Sym : sType
  482. Sym&@   equ     Sym
  483.         ENDIF
  484.         ENDM
  485.  
  486. PubSym@ MACRO   Sym, Definition, sName
  487.         IFNB    <sName>
  488.         IFIDN   <sName>, <__PASCAL__>
  489. NAMING      =       0
  490.         ELSE
  491. NAMING      =       UNDERSCORE
  492.         ENDIF
  493.         ENDIF
  494.         IF      NAMING
  495.         PUBLIC  _&Sym
  496. _&Sym   Definition
  497. Sym&@   equ     _&Sym
  498.         ELSE
  499.         PUBLIC  Sym
  500. Sym     Definition
  501. Sym&@   equ     Sym
  502.         ENDIF
  503.         ENDM
  504.  
  505. Static@ MACRO   Sym, Definition, sName
  506.         IFNB    <sName>
  507.         IFIDN   <sName>, <__PASCAL__>
  508. NAMING      =       0
  509.         ELSE
  510. NAMING      =       UNDERSCORE
  511.         ENDIF
  512.         ENDIF
  513.         IF      NAMING
  514. _&Sym   Definition
  515. Sym&@   equ     _&Sym
  516.         ELSE
  517. Sym     Definition
  518. Sym&@   equ     Sym
  519.         ENDIF
  520.         ENDM
  521.  
  522. .LIST
  523.