home *** CD-ROM | disk | FTP | other *** search
/ Phoenix Heaven Sunny 2 / APPARE2.BIN / oh_towns / his / source / hisl1.asm < prev    next >
Assembly Source File  |  1995-06-20  |  6KB  |  310 lines

  1. ;*****************************************************************
  2. ;*                                                               *
  3. ;*             割り込み処理ライブラリ下請けプロシジャ            *
  4. ;*                                                               *
  5. ;*              ~ ハードウェア割り込みエントリ ~             *
  6. ;*                                                               *
  7. ;*    1995 / 6 / 12                              ちょもらんま    *
  8. ;*                                                               *
  9. ;*****************************************************************
  10.  
  11.         .386
  12.  
  13. NULL        equ    0
  14.  
  15. ;************** 割り込みハードウェア関係の定数 *************
  16. OCW1_M        equ    0002h
  17. OCW1_S        equ    0012h
  18. OCW2_M        equ    0000h
  19. OCW2_S        equ    0010h
  20. OCW3_M        equ    0000h
  21. OCW3_S        equ    0010h
  22. ISR_M        equ    0000h
  23. ISR_S        equ    0010h
  24. IRR_M        equ    0000h
  25. IRR_S        equ    0010h
  26. IMR_M        equ    0002h
  27. IMR_S        equ    0012h
  28. ReadIRR        equ    00001010b
  29. ReadISR        equ    00001011b
  30. EOIcommand    equ    00100000b
  31. WaitRegister    equ    006ch
  32.  
  33. extrn    topIntInfo:dword,userHandler:byte,stackAddress:dword
  34.  
  35. ;----- ユーザー割り込みハンドラ記録用構造体 ----
  36. userHandler_t    struc
  37. handlerAdr    dp    ?
  38. dataSegment    dw    ?
  39. userHandler_t    ends
  40.  
  41. ;------------ PICアクセス待ちウェイト -------------
  42. PicWait        macro
  43.         out    WaitRegister,al ; 1μ秒ウェイト
  44.         cmc
  45.         cmc
  46.         endm
  47.  
  48.         assume    cs:code
  49. code        segment    public use32 'CODE'
  50.  
  51. ;*****************************************************************
  52. ;*                        割り込みエントリ                       *
  53. ;*****************************************************************
  54.  
  55. HardIntEntry    proc    far
  56.  
  57. ;--- 割り込みエントリ(割り込み番号0)---
  58.  
  59.         public    HardIntEntry0
  60. HardIntEntry0:
  61.         pushad
  62.         mov    ebx,0
  63.         jmp    short #skipOthers
  64.  
  65. ;--- 割り込みエントリ(割り込み番号1)---
  66.  
  67.         public    HardIntEntry1
  68. HardIntEntry1:
  69.         pushad
  70.         mov    ebx,1
  71.         jmp    short #skipOthers
  72.  
  73. ;--- 割り込みエントリ(割り込み番号2)---
  74.  
  75.         public    HardIntEntry2
  76. HardIntEntry2:
  77.         pushad
  78.         mov    ebx,2
  79.         jmp    short #skipOthers
  80.  
  81. ;--- 割り込みエントリ(割り込み番号3)---
  82.  
  83.         public    HardIntEntry3
  84. HardIntEntry3:
  85.         pushad
  86.         mov    ebx,3
  87.         jmp    short #skipOthers
  88.  
  89. ;--- 割り込みエントリ(割り込み番号4)---
  90.  
  91.         public    HardIntEntry4
  92. HardIntEntry4:
  93.         pushad
  94.         mov    ebx,4
  95.         jmp    short #skipOthers
  96.  
  97. ;--- 割り込みエントリ(割り込み番号5)---
  98.  
  99.         public    HardIntEntry5
  100. HardIntEntry5:
  101.         pushad
  102.         mov    ebx,5
  103.         jmp    short #skipOthers
  104.  
  105. ;--- 割り込みエントリ(割り込み番号6)---
  106.  
  107.         public    HardIntEntry6
  108. HardIntEntry6:
  109.         pushad
  110.         mov    ebx,6
  111.         jmp    short #skipOthers
  112.  
  113. ;--- 割り込みエントリ(割り込み番号7)---
  114.  
  115.         public    HardIntEntry7
  116. HardIntEntry7:
  117.         pushad
  118.         mov    ebx,7
  119.         jmp    short #skipOthers
  120.  
  121. ;--- 割り込みエントリ(割り込み番号8)---
  122.  
  123.         public    HardIntEntry8
  124. HardIntEntry8:
  125.         pushad
  126.         mov    ebx,8
  127.         jmp    short #skipOthers
  128.  
  129. ;--- 割り込みエントリ(割り込み番号9)---
  130.  
  131.         public    HardIntEntry9
  132. HardIntEntry9:
  133.         pushad
  134.         mov    ebx,9
  135.         jmp    short #skipOthers
  136.  
  137. ;--- 割り込みエントリ(割り込み番号10)---
  138.  
  139.         public    HardIntEntry10
  140. HardIntEntry10:
  141.         pushad
  142.         mov    ebx,10
  143.         jmp    short #skipOthers
  144.  
  145. ;--- 割り込みエントリ(割り込み番号11)---
  146.  
  147.         public    HardIntEntry11
  148. HardIntEntry11:
  149.         pushad
  150.         mov    ebx,11
  151.         jmp    short #skipOthers
  152.  
  153. ;--- 割り込みエントリ(割り込み番号12)---
  154.  
  155.         public    HardIntEntry12
  156. HardIntEntry12:
  157.         pushad
  158.         mov    ebx,12
  159.         jmp    short #skipOthers
  160.  
  161. ;--- 割り込みエントリ(割り込み番号13)---
  162.  
  163.         public    HardIntEntry13
  164. HardIntEntry13:
  165.         pushad
  166.         mov    ebx,13
  167.         jmp    short #skipOthers
  168.  
  169. ;--- 割り込みエントリ(割り込み番号14)---
  170.  
  171.         public    HardIntEntry14
  172. HardIntEntry14:
  173.         pushad
  174.         mov    ebx,14
  175.         jmp    short #skipOthers
  176.  
  177. ;--- 割り込みエントリ(割り込み番号15)---
  178.  
  179.         public    HardIntEntry15
  180. HardIntEntry15:
  181.         pushad
  182.         mov    ebx,15
  183. ;        jmp    short #skipOthers
  184.  
  185. ;******************* 各割り込み共通の処理 ***********************
  186.  
  187. ; レジスタ表
  188. ;   EBX : 割り込みハンドラの情報
  189. ;   ESI : 汎用レジスタの保存先
  190. ;   EDI : セグメントレジスタの保存先
  191. ;    AX : データセグメントセレクタ
  192. ;    BP : 旧スタックセグメントセレクタ
  193. ;   EDX : スタック切り換え元
  194. ;   ECX : スタック切り換え先
  195.  
  196.  
  197. #skipOthers:
  198.         cli
  199.         cld
  200.  
  201. ; 割り込みハンドラが登録されているかチェック
  202.         cmp    cs:topIntInfo[ ebx * 4 ],NULL
  203.         je    #endInterrupt ; NULLポインタ
  204.  
  205. ; 汎用レジスタのアドレス
  206.         mov    esi,esp
  207.  
  208. ; セグメントレジスタ書換え
  209.         push    ds
  210.         push    es
  211.         push    fs
  212.         push    gs
  213.         mov    edi,esp
  214.  
  215.         lea    ebx,userHandler[ ebx * 8 ]
  216.  
  217.         xor    eax,eax
  218.         mov    ax,cs:[ ebx ].dataSegment
  219.         mov    ds,ax
  220.         mov    es,ax
  221.         mov    fs,ax
  222.         mov    gs,ax
  223.  
  224. ; 旧スタック退避
  225.         mov    edx,esp
  226.         xor    ebp,ebp
  227.         mov    bp,ss
  228. ; スタック切り換え
  229.         mov    ecx,stackAddress
  230.         cmp    ecx,NULL
  231.         jne    short #UserStack
  232. ; DOS|Extenderのスタックを使う
  233.         mov    ecx,esp
  234.         mov    ax,ss
  235. #UserStack:
  236.         mov    ss,ax
  237.         mov    esp,ecx
  238.         push    edx ; 旧ESP
  239.         push    ebp ; 旧SS
  240.  
  241. ; ユーザーハンドラをコール
  242.         push    edi ; セグメントレジスタ
  243.         push    esi ; 汎用レジスタ
  244.         call    dword ptr [ ebx ]
  245.         add    esp,dword*2
  246.  
  247. ; スタック復元
  248.         pop    ebp
  249.         pop    edx
  250.         mov    ss,bp
  251.         mov    esp,edx
  252.  
  253. ; セグメントレジスタ復元
  254.         pop    gs
  255.         pop    fs
  256.         pop    es
  257.         pop    ds
  258.  
  259. #endInterrupt:
  260.         call    sendEOI
  261.  
  262. ; 割り込み処理終了
  263.         popad
  264.         iretd
  265.  
  266. HardIntEntry    endp
  267.  
  268. ;************************* EOI発行 **************************
  269.  
  270. sendEOI        proc
  271.  
  272.         push    eax
  273.  
  274. ; スレーブ側
  275. ;  スレーブ側はアクティブか?
  276.         mov    al,ReadISR
  277.         out    OCW3_M,al
  278.         PicWait
  279.         in    al,ISR_S
  280.         and    al,7fh
  281.         jz    short #MasterEOI
  282.  
  283. ;  スレーブ側EOI発行
  284.         mov    al,EOIcommand
  285.         out    OCW2_S,al
  286.         PicWait
  287.  
  288. ;  スレーブ側にまだ残っている割り込みがあるか?
  289.         mov    al,ReadISR
  290.         out    OCW3_S,al
  291.         PicWait
  292.         in    al,ISR_S
  293.         cmp    al,0
  294.         jnz    short #skipMasterEOI
  295.         PicWait
  296.  
  297. ; マスタ側EOI発行
  298. #MasterEOI:
  299.         mov    al,EOIcommand
  300.         out    OCW2_M,al
  301.  
  302. #skipMasterEOI:
  303.         pop    eax
  304.         ret
  305. sendEOI        endp
  306.  
  307. code        ends
  308.  
  309.         end
  310.