Subversion Repositories Kolibri OS

Rev

Rev 11 | Rev 21 | 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.         cmp   eax,[next_usage_update]
  22.         jb    .nocounter
  23.         add   eax,100
  24.         mov   [next_usage_update],eax
  25.         call  updatecputimes
  26.      .nocounter:
  27.  
  28.         call  playNote           ; <<<--- Speaker driver
  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.  
  40.         cmp   [0xffff], byte 1
  41.         je    .do_not_change_task
  42.  
  43.       .waiting_for_termination:
  44.       .waiting_for_reuse:
  45.         add   edi,0x20
  46.         inc   ebx
  47.  
  48.         mov   al, byte [edi+0xA]
  49.         cmp   al, 3
  50.         je    .waiting_for_termination
  51.         cmp   al, 4
  52.         je    .waiting_for_termination
  53.         cmp   al, 9
  54.         je    .waiting_for_reuse
  55.  
  56.         cmp   ebx,[0x3004]
  57.         jbe   @f
  58.         mov   ebx,1
  59.         mov   edi,0x3020
  60.        @@:
  61.  
  62.         mov   [0x3000],ebx
  63.         mov   [0x3010],edi
  64.  
  65.      .do_not_change_task:
  66.  
  67.         call  _rdtsc
  68.         mov   [edi+0x18],eax
  69.  
  70.         shl   ebx, 3
  71.         xor   eax, eax
  72.         add   ebx, tss0
  73.         mov   word  [far_jump.sel],  bx   ; selector
  74.         mov   dword [far_jump.offs], eax  ; offset
  75.  
  76.         mov   al,0x20   ; send End Of Interrupt signal
  77.         mov   dx,0x20
  78.         out   dx,al
  79.  
  80.         cmp   [0xffff],byte 0
  81.         je    .switch
  82.         dec   byte [0xffff]
  83.         jz    @f
  84.      .switch:
  85.         jmp   pword [far_jump]
  86.         inc   [context_counter] ;noname & halyavin
  87.        @@:
  88.        
  89.         pop   es ds
  90.         popad
  91.         iret
  92.  
  93.  
  94. uglobal
  95.    far_jump:
  96.     .offs dd ?
  97.     .sel  dw ?
  98.    context_counter     dd ? ;noname & halyavin
  99.    next_usage_update   dd ?
  100.    timer_ticks         dd ?
  101. endg
  102.  
  103.  
  104. align 4
  105. change_task:
  106.  
  107.         mov   [0xffff],byte 2
  108.  
  109.         dec   dword [timer_ticks]  ; because irq0 will increase it
  110.  
  111.         int   0x20   ; irq0 handler
  112.  
  113.         ret
  114.  
  115.  
  116.  
  117. align 4
  118. updatecputimes:
  119.  
  120.         mov  eax,[idleuse]
  121.         mov  [idleusesec],eax
  122.         mov  [idleuse],dword 0
  123.         mov  ecx, [0x3004]
  124.         mov  edi, 0x3020
  125.       .newupdate:
  126.         mov  ebx,[edi+0x14]
  127.         mov  [edi+0x1c],ebx
  128.         mov  [edi+0x14],dword 0
  129.         add  edi,0x20
  130.         dec  ecx
  131.         jnz  .newupdate
  132.  
  133.         ret
  134.