home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / mint / mint095s / intr.s < prev    next >
Text File  |  1993-08-03  |  6KB  |  246 lines

  1. |
  2. | interrupt wrapping routines; these should just save registers and call
  3. | the appropriate C handlers, unless speed is a major problem
  4. |
  5.  
  6. |
  7. | first, utilities for setting processor status level
  8. |
  9.     .globl    _spl7, _spl
  10. _spl7:
  11.     movew    sr, d0
  12.     oriw    #0x0700, sr
  13.     rts
  14. _spl:
  15.     movew    sp@(4), d0
  16.     movew    d0, sr
  17.     rts
  18.  
  19.     .globl    _mint_5ms
  20.     .globl    _mint_timer
  21.     .globl    _mint_vbl
  22.     .globl    _timeout    | C time routine
  23.     .globl    _old_timer    | old GEMDOS time vector
  24.     .globl    _old_vbl    | old GEMDOS vbl vector
  25.     .globl    _old_5ms
  26.     .globl    _build_context
  27.     .globl    _restore_context
  28.     .globl    _proc_clock        | controls process' allocation of CPU time
  29.     .globl    _curproc
  30.     .globl    _in_kernel
  31.  
  32. | AKP: this code is hit once every 5ms; it updates the time fields of curproc.
  33. _mint_5ms:
  34.     movel    a0,sp@-
  35.     movel    _curproc,a0
  36.     addw    #0x364,a0        | $364 is offset to curproc->systime;
  37.     tstw    _in_kernel
  38.     bne    L_5a            | usrtime is the branch-not-taken case
  39.     addql    #4,a0
  40. L_5a:    addql    #5,a0@
  41.     movel    sp@+,a0
  42.     movel    _old_5ms+8,sp@-
  43.     rts
  44.  
  45. _mint_timer:
  46.     moveml    d0-d2/a0-a2, sp@-    | save C registers
  47.     jsr    _timeout
  48.     moveml    sp@+, d0-d2/a0-a2
  49.     movel    _old_timer+8, sp@-    | jump to GEMDOS time vector
  50.     rts
  51.  
  52. _mint_vbl:
  53.     tstw    0x59e            | test longframe (AKP)
  54.     beq    L_short1
  55.     clrw    sp@-            | yes, long frames: push a frame word
  56. L_short1:
  57.     pea    L_comeback        | push fake PC
  58.     movew    sr, sp@-        | push status register
  59.     movel    _old_vbl+8, sp@-    | go service the interrupt
  60.     rts
  61.  
  62. L_comeback:
  63.     tstw    _proc_clock        | has time expired yet?
  64.     beq    L_expired        | yes -- maybe go switch processes
  65. L_out:
  66.     rte                | no -- just return
  67.  
  68. L_expired:
  69.     btst    #13, sp@        | user mode?
  70.     bne    L_out            | no -- switching is not possible
  71. L_switch:
  72.     movel    _curproc, sp@-
  73.     addl    #4, sp@            | to get &curproc->ctxt[SYSCALL]
  74.     jsr    _build_context        | build context
  75.     movel    _curproc, a0
  76.     movel    a0@, sp            | use curproc->sysstack
  77.     jsr    _enter_kernel        | enter kernel
  78.     jsr    _preempt        | yield processor
  79.     oriw    #0x0700, sr        | spl7()
  80.     jsr    _leave_kernel        | restore vectors
  81.     movel    _curproc, a0
  82.     pea    a0@(4)
  83.     jsr    _restore_context    | back to user
  84. |
  85. | reset routine -- called on a warm boot. Note that TOS sends the
  86. | address to which we should return in register a6. Also note that
  87. | the stack pointer is in an unknown state, so we set up our own
  88. |
  89.     .globl    _reset
  90.     .globl    _tmpstack        | see main.c
  91.  
  92. _reset:
  93.     movew    #0x2700, sr        | avoid interruption here
  94.     movel    sp, _tmpstack        | save A7
  95.     lea    _tmpstack, sp        | set up temporary stack
  96.     lea    sp@(256), sp
  97.     moveml    d0-d2/a0-a2, sp@-    | save C registers
  98.     jsr    _restr_intr        | restore interrupts
  99.     moveml    sp@+, d0-d2/a0-a2    | restore registers
  100.     movel    _tmpstack, sp
  101.     jmp    a6@            | reset again
  102.  
  103. |
  104. | routine for doing a reboot
  105. |
  106.     .globl    _reboot
  107. _reboot:
  108.     movew    #0x2700, sr        | avoid interrupts
  109.     movel    0x00, sp        | get sp after reboot
  110.     movel    0x04, a6        | get new reboot address
  111.     jmp    _reset
  112.  
  113. |
  114. | routine for mouse packet handling
  115. |
  116.     .globl    _newmvec
  117. _newmvec:
  118.     movel    a0, sp@-
  119.     jsr    _mouse_handler
  120.     movel    sp@+, a0
  121.     rts
  122.  
  123. |
  124. | new ikbd keyboard interrupt vector
  125. | kintr is a global variable that should be non-zero if a keyboard
  126. | event occured
  127. |
  128.     .globl    _new_ikbd
  129. _new_ikbd:
  130.     movew    #1, _kintr
  131.     movel    _old_ikbd+8, sp@-
  132.     rts            | jump to system interrupt routine
  133.  
  134. |
  135. | simple signal handlers
  136. | global variables referenced:
  137. | in_kernel: (main.c): flag to indicate that we're in the MiNT kernel
  138. | sig_routine: (signal.c): pointer to which signal catching routine to
  139. |          call (e.g. for SIGBUS, or whatever)
  140. |
  141.     .globl    _new_bus, _new_addr, _new_ill, _new_divzero, _new_priv
  142.     .globl    _new_trace
  143.     .globl    _in_kernel, _sig_routine
  144. _new_bus:
  145.     movel    #_sigbus, _sig_routine
  146. Do_sig:
  147.     tstw    _in_kernel        | are we already in the kernel?
  148.     bne    Kernel            | yes
  149.     movel    _curproc, sp@-
  150.     addl    #4, sp@            | push offset of save area
  151.     jsr    _build_context
  152.     movel    _curproc, a4
  153.     movel    a4@, sp            | put us in the system stack
  154.     jsr    _enter_kernel        | set up kernel vectors
  155.     movel    _sig_routine, a1    | get signal handling routine
  156.     jsr    a1@            | go do it
  157.     oriw    #0x0700, sr        | spl7()
  158.     jsr    _leave_kernel        | leave kernel
  159.     lea    a4@(4), a4        | get context save area address
  160.     movel    a4, sp@-        | push it
  161.     jsr    _restore_context    | restore the context
  162. |
  163. | here's what we do if we already were in the kernel
  164. |
  165. Kernel:
  166.     moveml    d0-d2/a0-a2, sp@-    | save reggies
  167.     movel    _sig_routine, a1    | get handler
  168.     jsr    a1@            | go do it
  169.     moveml    sp@+, d0-d2/a0-a2
  170.     rte    
  171. _new_addr:
  172.     movel    #_sigaddr, _sig_routine
  173.     bra    Do_sig
  174. _new_ill:
  175.     movel    #_sigill, _sig_routine
  176.     bra    Do_sig
  177. _new_divzero:
  178.     movel    #_sigfpe, _sig_routine
  179.     bra    Do_sig
  180. _new_priv:
  181.     movel    #_sigpriv, _sig_routine
  182.     bra    Do_sig
  183. _new_trace:
  184.     movel    #_sigtrap, _sig_routine
  185.     bra    Do_sig
  186.  
  187. |
  188. | BIOS disk vectors for pseudo-disks like U: and X:; these are present
  189. | just in case some program (foolishly) attempts to access these drives
  190. | directly and gets horribly confused
  191. |
  192.     .globl    _old_getbpb    | old Getbpb vector
  193.     .globl    _old_mediach    | old Mediach vector
  194.     .globl    _old_rwabs    | old Rwabs vector
  195.  
  196.     .globl    _new_getbpb
  197. _new_getbpb:
  198.     movew    sp@(4), d0    | check the drive
  199.     cmpw    #0x10, d0    | drive Q:?
  200.     beq    nobpb        | yes, no BPB available
  201.     cmpw    #0x14, d0    | drive U:?
  202.     beq    nobpb        | yes, no BPB available
  203.     cmpw    #0x15, d0    | drive V:?
  204.     beq    nobpb
  205.     cmpw    #0x17, d0    | drive X:?
  206.     beq    nobpb
  207.     movel    _old_getbpb+8, a0    | not our drive
  208.     jmp    a0@        | call the old vector for it
  209. nobpb:
  210.     moveql    #0, d0        | 0 means "no BPB read"
  211.     rts
  212.  
  213.     .globl    _new_mediach
  214. _new_mediach:
  215.     movew    sp@(4), d0    | check the drive
  216.     cmpw    #0x10, d0    | drive Q:?
  217.     beq    nochng        | yes, no change
  218.     cmpw    #0x14, d0    | drive U:?
  219.     beq    nochng        | yes, no change
  220.     cmpw    #0x15, d0    | drive V:?
  221.     beq    nochng
  222.     cmpw    #0x17, d0    | drive X:?
  223.     beq    nochng
  224.     movel    _old_mediach+8, a0    | not our drive
  225.     jmp    a0@        | call the old vector for it
  226. nochng:
  227.     moveql    #0, d0        | 0 means "definitely no change"
  228.     rts
  229.  
  230.     .globl    _new_rwabs
  231. _new_rwabs:
  232.     movew    sp@(0xe), d0    | check the drive
  233.     cmpw    #0x10, d0    | drive Q:?
  234.     beq    rwdone        | yes, fake a successful I/O operation
  235.     cmpw    #0x14, d0    | drive U:?
  236.     beq    rwdone        | yes, fake it
  237.     cmpw    #0x15, d0    | drive V:?
  238.     beq    rwdone
  239.     cmpw    #0x17, d0    | drive X:?
  240.     beq    rwdone
  241.     movel    _old_rwabs+8, a0 | not our drive
  242.     jmp    a0@        | call the old vector for it
  243. rwdone:
  244.     moveql    #0, d0        | 0 means "successful operation"
  245.     rts
  246.