Subversion Repositories Kolibri OS

Rev

Rev 8 | Rev 10 | 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.         xor   esi,esi           ;esi - should we change task?
  44.         cmp   [0xffff], byte 1
  45.         je    .do_not_change_task
  46.  
  47.       .waiting_for_termination:
  48.       .waiting_for_reuse:
  49.         add   edi,0x20
  50.         inc   ebx
  51.  
  52.         mov   al, byte [edi+0xA]
  53.         cmp   al, 3
  54.         je    .waiting_for_termination
  55.         cmp   al, 4
  56.         je    .waiting_for_termination
  57.         cmp   al, 9
  58.         je    .waiting_for_reuse
  59.  
  60.         cmp   ebx,[0x3004]
  61.         jbe   @f
  62.         mov   ebx,1
  63.         mov   edi,0x3020
  64.        @@:
  65.  
  66.         mov   [0x3000],ebx
  67.         mov   [0x3010],edi
  68.  
  69.         jmp   @f
  70.      .do_not_change_task:
  71.         inc   esi          ;set don't change task flag
  72.        @@:
  73.  
  74.         call  _rdtsc
  75.         mov   [edi+0x18],eax
  76.  
  77.         cmp   [0xffff],byte 0
  78.         je    @f
  79.         dec   byte [0xffff]
  80.        @@:
  81.  
  82.  
  83.         shl   ebx, 3
  84.         xor   eax, eax
  85.         add   ebx, tss0
  86.         mov   word  [0xB004], bx   ; selector
  87.         mov   dword [0xB000], eax  ; offset
  88.  
  89.         mov   al,0x20   ; send End Of Interrupt signal
  90.         mov   dx,0x20
  91.         out   dx,al
  92.  
  93.         test  esi,esi   ; skip jmp to TSS if we aren't going to switch tasks
  94.         jnz    @f
  95.        
  96. .switch:
  97.         inc   [context_counter] ;noname & halyavin
  98.         jmp   pword [0xB000]
  99.  
  100.        @@:
  101.         pop   es ds
  102.         popad
  103.         iret
  104.  
  105.  
  106.  
  107. uglobal
  108. context_counter dd 0 ;noname & halyavin
  109. endg
  110.  
  111.  
  112. align 4
  113. change_task:
  114.  
  115.         mov   [0xffff],byte 2
  116.  
  117.         dec   dword [timer_ticks]  ; because irq0 will increase it
  118.  
  119.         int   0x20   ; irq0 handler
  120.  
  121.         ret
  122.  
  123.  
  124.  
  125. align 4
  126. updatecputimes:
  127.  
  128.         mov  eax,[idleuse]
  129.         mov  [idleusesec],eax
  130.         mov  [idleuse],dword 0
  131.         mov  ecx, [0x3004]
  132.         mov  edi, 0x3020
  133.       .newupdate:
  134.         mov  ebx,[edi+0x14]
  135.         mov  [edi+0x1c],ebx
  136.         mov  [edi+0x14],dword 0
  137.         add  edi,0x20
  138.         dec  ecx
  139.         jnz  .newupdate
  140.  
  141.         ret
  142.