home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / tc20 / rules.asi < prev    next >
Text File  |  1988-08-28  |  11KB  |  533 lines

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