home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / n / n002 / 4.ddi / ECLSRCA.ZIP / I86.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-08-24  |  9.0 KB  |  277 lines

  1. ;
  2. ;       i86.asm       INTEL 8086 primitives
  3. ;
  4. ;       (C) Copyright 19896 SOuth Mountain Software Inc.
  5. ;           All Rights Reserved
  6. ;
  7. ;       ====================================
  8. ;               Microsoft C interface
  9. ;       ====================================
  10. ;
  11. ;       i86_int            Execute the software interrupt 
  12. ;       i86_peek           Read the byte of logical 8086 memory
  13. ;       i86_poke           Write the byte of logical 8086 memory
  14. ;       i86_in             Read the port (new for revision 2.0)
  15. ;       i86_out            Write the port value  (new for revision 2.0)
  16. ;
  17. ;       Please include the I86.h file when compiling C programs
  18. ;       using the i86 functions.
  19. ;
  20. ;       revision history:
  21. ;
  22. ;       1.0     10/12/86    6196    Original code
  23. ;       1.1     08/21/87            Saving the DI register with INT calls
  24. ;       2.0                         Renamed <Label> reserved symbol to <GotoL>
  25. ;                                       (for MASM rev 5.0)
  26. ;                                   Added i86_in and i86_out
  27.  
  28.         INCLUDE ECLMACRO.INC
  29.         modstart        i86
  30.  
  31.  
  32.  
  33. ;       ===============================================================
  34. ;       i86_int         Execute the software interrupt 
  35. ;       ===============================================================
  36. ;
  37. ;       C invocation:
  38. ;               #include "i86.h"
  39. ;
  40. ;               int int_no, flags;
  41. ;               struct i86_reg       packet;
  42. ;               flags = i86_int(int_no, &packet);
  43. ;
  44. ;       Stack:                      i86_reg type:
  45. ;               +------------+          +------------+
  46. ;               |   packet --|----+     |     DX     | + 06
  47. ;               |------------|    |     +------------|
  48. ;               |   int_no   |    |     |     CX     | + 04
  49. ;               |------------|    |     |------------|
  50. ;               | return IP  |    |     |     BX     | + 02
  51. ;               |------------|    |     |------------|
  52. ;               | return BP  |    +---->|     AX     | + 00
  53. ;               |------------|          +------------+
  54. ;               |      |     |
  55. ;                      V
  56. ;
  57. ;
  58. ;       Input           Description
  59. ;       --------------  ---------------------------
  60. ;       Stack as above
  61. ;
  62. ;       Output          Description
  63. ;       --------------  ---------------------------
  64. ;       AX              Full 8086 flag word value
  65. ;       packet.wreg.AX  register AX after the software interrupt
  66. ;       packet.wreg.BX  register BX after the software interrupt
  67. ;       packet.wreg.CX  register CX after the software interrupt
  68. ;       packet.wreg.DX  register DX after the software interrupt
  69. ;
  70. ;       Registers used  Description
  71. ;       --------------  ---------------------------
  72. ;       Not applicable
  73. ;       ==============================================================
  74.  
  75.         entry   i86_int
  76.                 pushreg
  77.                 PUSH    DI                      ; *** Revision 1.1 ***
  78.                 PUSH    SI
  79.                 PUSH    DS
  80.                 loadint1 AX                     ; Store the given INTerrupt
  81.                 MOV     BYTE PTR CS:[GotoL-1], AL
  82.  
  83.                 loadptr2                        ; Unload registers into DX:BX
  84.                 MOV     SI, BX
  85.                 MOV     DS, DX
  86.                 PUSH    SI
  87.                 PUSH    DS
  88.  
  89.                 MOV     AX, [SI]
  90.                 MOV     BX, [SI+2]
  91.                 MOV     CX, [SI+4]
  92.                 MOV     DX, [SI+6]
  93.  
  94.         JMP     CAUSE_RELOAD_CACHE
  95. CAUSE_RELOAD_CACHE:
  96.         INT     00
  97. GotoL:
  98.                 POP     DS
  99.                 POP     SI
  100.                 MOV     [SI], AX
  101.                 MOV     [SI+2], BX
  102.                 MOV     [SI+4], CX
  103.                 MOV     [SI+6], DX
  104.  
  105.                 PUSHF
  106.                 POP     AX                      ; Restore flags in return AX
  107.                 POP     DS
  108.                 POP     SI
  109.                 POP     DI                      ; *** Revision 1.1 ***
  110.                 popreg
  111.                 RET
  112.         endit   i86_int
  113.  
  114.  
  115. ;       ===============================================================
  116. ;       i86_peek           Read the byte of logical 8086 memory
  117. ;       ===============================================================
  118. ;
  119. ;       C invocation:
  120. ;               #include "i86.h"
  121. ;
  122. ;               unsigned int offset, segment;
  123. ;               unsigned char byte;
  124. ;               byte  = i86_peek(offset, segment);
  125. ;
  126. ;       Input           Description
  127. ;       --------------  ---------------------------
  128. ;       first arg int   Offset word
  129. ;       second arg int  Segment word
  130. ;
  131. ;       Output          Description
  132. ;       --------------  ---------------------------
  133. ;       AL              Byte read from memory
  134. ;       AH              00
  135. ;
  136. ;       Registers used  Description
  137. ;       --------------  ---------------------------
  138. ;       Not applicable
  139. ;       ==============================================================
  140.  
  141.         entry   i86_peek
  142.                 pushreg
  143.                 PUSH    DS
  144.                 PUSH    BX
  145.                 loadint2 BX
  146.                 MOV     DS, BX
  147.                 loadint1 BX
  148.                 MOV     AL, [BX]
  149.                 MOV     AH, 0
  150.                 POP     BX
  151.                 POP     DS
  152.                 popreg
  153.                 RET
  154.         endit   i86_peek
  155.  
  156.  
  157. ;       ===============================================================
  158. ;       i86_poke           Write the byte of logical 8086 memory
  159. ;       ===============================================================
  160. ;
  161. ;       C invocation:
  162. ;               #include "i86.h"
  163. ;
  164. ;               unsigned int offset, segment;
  165. ;               unsigned char byte;
  166. ;               i86_poke(offset, segment, byte);
  167. ;
  168. ;       Input           Description
  169. ;       --------------  ---------------------------
  170. ;       first arg int   Offset word
  171. ;       second arg int  Segment word
  172. ;       third arg int   Byte to write
  173. ;
  174. ;       Output          Description
  175. ;       --------------  ---------------------------
  176. ;       Not applicable
  177. ;
  178. ;       Registers used  Description
  179. ;       --------------  ---------------------------
  180. ;       Not applicable
  181. ;       ==============================================================
  182.  
  183.         entry   i86_poke
  184.                 pushreg
  185.                 PUSH    DS
  186.                 PUSH    BX
  187.  
  188.                 loadint2    BX
  189.                 MOV     DS, BX
  190.                 loadint1    BX
  191.                 loadint3    AL
  192.                 MOV     [BX], AL
  193.  
  194.                 POP     BX
  195.                 POP     DS
  196.                 popreg
  197.                 RET
  198.         endit   i86_poke
  199.  
  200. ;       ===============================================================
  201. ;       i86_in             Read the byte from I/O space
  202. ;       ===============================================================
  203. ;
  204. ;       C invocation:
  205. ;               #include "i86.h"
  206. ;
  207. ;               unsigned int io_address;  /* 12 bits only */
  208. ;               unsigned char byte;
  209. ;               byte  = i86_in(io_address);
  210. ;
  211. ;       Input           Description
  212. ;       --------------  ---------------------------
  213. ;       first arg int   I/O 12-bit address
  214. ;
  215. ;       Output          Description
  216. ;       --------------  ---------------------------
  217. ;       AL              Byte read from memory
  218. ;       AH              00
  219. ;
  220. ;       Registers used  Description
  221. ;       --------------  ---------------------------
  222. ;       Not applicable
  223. ;       ==============================================================
  224.  
  225.         entry   i86_in
  226.                 pushreg
  227.                 PUSH    DX
  228.                 loadint1 DX
  229.                 IN      AL, DX
  230.                 MOV     AH, 0
  231.                 POP     DX
  232.                 popreg
  233.                 RET
  234.         endit   i86_in
  235.  
  236.  
  237. ;       ===============================================================
  238. ;       i86_out            Write the byte to I/O space
  239. ;       ===============================================================
  240. ;
  241. ;       C invocation:
  242. ;               #include "i86.h"
  243. ;
  244. ;               unsigned int io_address;  /* 12 bits only */
  245. ;               unsigned char byte;
  246. ;               i86_out(io_address, byte);
  247. ;
  248. ;       Input           Description
  249. ;       --------------  ---------------------------
  250. ;       first arg int   I/O 12-bit address
  251. ;       2nd arg int     byte to write
  252. ;
  253. ;       Output          Description
  254. ;       --------------  ---------------------------
  255. ;       not applicable
  256. ;
  257. ;       Registers used  Description
  258. ;       --------------  ---------------------------
  259. ;       Not applicable
  260. ;       ==============================================================
  261.  
  262.         entry   i86_out
  263.                 pushreg
  264.                 PUSH    DX
  265.                 loadint1 DX
  266.                 loadint2 AX
  267.                 OUT     DX, AL
  268.                 MOV     AX, 0
  269.                 POP     DX
  270.                 popreg
  271.                 RET
  272.         endit   i86_out
  273.  
  274.         modend  i86
  275.         END
  276.  
  277.