Subversion Repositories Kolibri OS

Rev

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

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