Subversion Repositories Kolibri OS

Rev

Rev 26 | Rev 66 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;; IRQ0 HANDLER (TIMER INTERRUPT) ;;
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4.  
  5. align 32
  6. irq0:
  7.         save_ring3_context
  8.         mov   ax, os_data
  9.         mov   ds, ax
  10.         mov   es, ax
  11.  
  12.         mov   edi,[0x3000]
  13.         shl   edi, 3
  14.                          ; fields of TSS descriptor:
  15.         mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
  16.  
  17.         inc   dword [timer_ticks]
  18.  
  19.         mov   eax, [timer_ticks]
  20.         call  playNote           ; <<<--- Speaker driver
  21.  
  22.         cmp   eax,[next_usage_update]
  23.         jb    .nocounter
  24.         add   eax,100
  25.         mov   [next_usage_update],eax
  26.         call  updatecputimes
  27.      .nocounter:
  28.  
  29.         mov   edi, [0x3010]
  30.  
  31.         mov   ebx, [edi+0x18] ; time stamp counter add
  32.         call  _rdtsc
  33.         sub   eax, ebx
  34.         add   eax, [edi+0x14] ; counter sum
  35.         mov   [edi+0x14], eax
  36.  
  37.         mov   ebx,[0x3000]
  38.         mov   [prev_slot], ebx
  39.  
  40.         cmp   [0xffff], byte 1
  41.         je    .do_not_change_task
  42.  
  43.  
  44.       .waiting_for_termination:
  45.       .waiting_for_reuse:
  46.       .waiting_for_event:
  47.       .suspended:
  48.         cmp   ebx, [0x3004]
  49.         jb    @f
  50.         mov   edi, 0x3000
  51.         xor   ebx, ebx
  52.       @@:
  53.  
  54.         add   edi,0x20
  55.         inc   ebx
  56.  
  57.         mov   al, byte [edi+0xA]
  58.         cmp   al, 1
  59.         jz    .suspended
  60.         cmp   al, 2
  61.         jz    .suspended
  62.         cmp   al, 3
  63.         je    .waiting_for_termination
  64.         cmp   al, 4
  65.         je    .waiting_for_termination
  66.         cmp   al, 9
  67.         je    .waiting_for_reuse
  68.  
  69.         mov   [0x3000],ebx
  70.         mov   [0x3010],edi
  71.  
  72.         cmp   al, 5
  73.         jne   .noevents
  74.         call  get_event_for_app
  75.         test  eax, eax
  76.         jz    .waiting_for_event
  77.         mov   [event_sched], eax
  78.         mov   [edi+0xA], byte 0
  79.       .noevents:
  80.         cmp   ebx, [prev_slot]
  81.         sete  [0xffff]
  82.  
  83.  
  84.      .do_not_change_task:
  85.  
  86.         call  _rdtsc
  87.         mov   [edi+0x18],eax
  88.  
  89.         shl   ebx, 3
  90.         xor   eax, eax
  91.         add   ebx, tss0
  92.         mov   word  [far_jump.sel],  bx   ; selector
  93.         mov   dword [far_jump.offs], eax  ; offset
  94.  
  95.         mov   al,0x20   ; send End Of Interrupt signal
  96.         mov   dx,0x20
  97.         out   dx,al
  98.  
  99.         cmp   [0xffff],byte 0
  100.         je    .switch
  101.         dec   byte [0xffff]
  102.         jz    @f
  103.      .switch:
  104.         jmp   pword [far_jump]
  105.         inc   [context_counter] ;noname & halyavin
  106.        @@:
  107.        
  108.         restore_ring3_context
  109.         iret
  110.  
  111.  
  112. uglobal
  113.    align 4
  114.    far_jump:
  115.     .offs dd ?
  116.     .sel  dw ?
  117.    context_counter     dd ? ;noname & halyavin
  118.    next_usage_update   dd ?
  119.    timer_ticks         dd ?
  120.    prev_slot dd ?
  121.    event_sched dd ?
  122. endg
  123.  
  124.  
  125. align 4
  126. change_task:
  127.  
  128.         mov   [0xffff],byte 2
  129.  
  130.         dec   dword [timer_ticks]  ; because irq0 will increase it
  131.  
  132.         int   0x20   ; irq0 handler
  133.  
  134.         ret
  135.  
  136.  
  137.  
  138. align 4
  139. updatecputimes:
  140.  
  141.         mov  eax,[idleuse]
  142.         mov  [idleusesec],eax
  143.         mov  [idleuse],dword 0
  144.         mov  ecx, [0x3004]
  145.         mov  edi, 0x3020
  146.       .newupdate:
  147.         mov  ebx,[edi+0x14]
  148.         mov  [edi+0x1c],ebx
  149.         mov  [edi+0x14],dword 0
  150.         add  edi,0x20
  151.         dec  ecx
  152.         jnz  .newupdate
  153.  
  154.         ret
  155.