Subversion Repositories Kolibri OS

Rev

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