home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / INCLUDE.ZIP / EMURULES.ASI < prev    next >
Encoding:
Text File  |  1990-06-07  |  11.1 KB  |  525 lines

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