home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 October / VPR9710A.ISO / BENCH / DJ1SRC_K / 105 / TABLES.ASM < prev    next >
Assembly Source File  |  1997-05-01  |  3KB  |  163 lines

  1. ; This is file TABLES.ASM
  2. ;
  3. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. ;
  5. ; This file is distributed under the terms listed in the document
  6. ; "copying.dj", available from DJ Delorie at the address above.
  7. ; A copy of "copying.dj" should accompany this file; if not, a copy
  8. ; should be available from where this file was obtained.  This file
  9. ; may not be distributed without a verbatim copy of "copying.dj".
  10. ;
  11. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. ;
  14. ; 97/05/01 Kimio Itoh(kitoh@nn.iij4u.or.jp) modified
  15. ; for reduce binary size and for dead code elimination.
  16.  
  17. ;    History:20,1
  18.     title    tables
  19.     .386p
  20.  
  21.     include    build.inc
  22.     include    segdefs.inc
  23.     include tss.inc
  24.     include gdt.inc
  25.     include idt.inc
  26.  
  27. ;------------------------------------------------------------------------
  28.  
  29.     start_data16
  30.  
  31.     extrn    _tss_ptr:word
  32.     extrn    _was_exception:word
  33.     extrn    _npx:byte
  34.  
  35.     public    ivec_number
  36. ivec_number    dw    ?
  37.  
  38. has_error    db    0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0
  39.  
  40.     end_data16
  41.  
  42. ;------------------------------------------------------------------------
  43.  
  44.     .286c
  45.     start_bss
  46.  
  47.     public    _gdt
  48. _gdt    label    gdt_s
  49.     db    type gdt_s * g_num dup (?)
  50.  
  51.     public    _idt
  52. _idt    label    idt_s
  53.     db    type idt_s * 256 dup (?)
  54.  
  55.     public    _i_tss
  56. _i_tss    label    tss_s
  57.     db    type tss_s dup (?)
  58.  
  59.     end_bss
  60.     .386p
  61.  
  62. ;------------------------------------------------------------------------
  63.  
  64.     start_code16
  65.  
  66. sound    macro
  67.     local    wait_loop
  68.     local    wait_loop1
  69.     mov    al,033h
  70.     out    061h,al
  71.     mov    ecx,100000h
  72. wait_loop:
  73.     loopd    wait_loop
  74.     mov    al,032h
  75.     out    61h,al
  76.     mov    ecx,100000h
  77. wait_loop1:
  78.     loop    wait_loop1
  79.     endm
  80.  
  81.     public  _ivec0, _ivec1
  82. _ivec0:
  83.     push    ds        ;  1 byte
  84.     call    ivec_common    ;  3 bytes
  85. _ivec1:
  86. rept 255
  87.     push    ds        ;  1 byte
  88.     call    ivec_common    ;  3 bytes
  89. endm
  90.  
  91. ivec_common:
  92.     push    g_rdata
  93.     pop    ds
  94.     pop    ivec_number
  95.     sub    ivec_number, offset _ivec1;  pushes address *after* call
  96.     shr    ivec_number, 2
  97.     pop    ds
  98.     jmpt    g_itss
  99.  
  100.     public    _interrupt_common
  101. _interrupt_common:
  102.     cli
  103.     mov    bx,g_rdata
  104.     mov    ds,bx
  105.     mov    bx,_tss_ptr
  106.     mov    ax,ivec_number
  107.     mov    [bx].tss_irqn,al
  108.     mov    esi,[bx].tss_esp
  109.     mov    fs,[bx].tss_ss        ; fs:esi -> stack
  110.     cmp    al,16
  111.     ja    has_no_error
  112.     mov di,ax
  113.     cmp    has_error[di],0
  114.     je    has_no_error
  115.     mov    eax,fs:[esi]
  116.     mov    [bx].tss_error,eax
  117.     add    esi,4
  118. has_no_error:
  119.     mov    eax,fs:[esi]        ; eip
  120.     mov    [bx].tss_eip,eax
  121.     mov    eax,fs:[esi+4]
  122.     mov    [bx].tss_cs,ax
  123.     mov    eax,fs:[esi+8]
  124.     mov    [bx].tss_eflags,eax
  125.     add    esi,12
  126.     mov    [bx].tss_esp,esi    ; store corrected stack pointer
  127.     mov    _was_exception,1
  128.     jmpt    g_ctss            ; pass control back to real mode
  129.     cli
  130.     jmp    _interrupt_common    ; it's a task
  131.  
  132.     extrn    graphics_fault:near
  133.  
  134.     public    _page_fault
  135. _page_fault:
  136.     cli
  137.     mov    bx,g_rdata
  138.     mov    ds,bx
  139.     mov    es,bx
  140.     mov    eax,cr2
  141.     cmp    eax,0e0000000h
  142.     jb    regular_pf
  143.     cmp    eax,0e0300000h
  144.     ja    regular_pf
  145.     jmp    graphics_fault
  146. regular_pf:
  147.     mov    bx,_tss_ptr
  148.     mov    [bx].tss_irqn,14    ; page fault
  149.     mov    [bx].tss_cr2,eax
  150.     pop    eax
  151.     mov    [bx].tss_error,eax
  152.     mov    eax,0
  153.     mov    cr2,eax            ; so we can tell INT 0D from page fault
  154.     mov    _was_exception,1
  155.     jmpt    g_ctss
  156.     jmp    _page_fault
  157.  
  158.     end_code16
  159.  
  160. ;------------------------------------------------------------------------
  161.  
  162.     end
  163.