Subversion Repositories Kolibri OS

Rev

Rev 6 | Rev 9 | 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.         jmp   @f
  69.      .do_not_change_task:
  70.         mov   [noct], 1
  71.        @@:
  72.  
  73.         call  _rdtsc
  74.         mov   [edi+0x18],eax
  75.  
  76.         cmp   [0xffff],byte 0
  77.         je    @f
  78.         dec   byte [0xffff]
  79.        @@:
  80.  
  81.  
  82.         shl   ebx, 3
  83.         xor   eax, eax
  84.         add   ebx, tss0
  85.         mov   word  [0xB004], bx   ; selector
  86.         mov   dword [0xB000], eax  ; offset
  87.  
  88.         mov   al,0x20   ; send End Of Interrupt signal
  89.         mov   dx,0x20
  90.         out   dx,al
  91.  
  92.         cmp   [noct], 1
  93.         je    @f
  94. .switch:
  95.         jmp   pword [0xB000]
  96.         inc [context_counter] ;noname & halyavin
  97.        @@:
  98.         mov   [noct], 0
  99.        
  100.         pop   es ds
  101.         popad
  102.         iret
  103.  
  104.  
  105.  
  106. uglobal
  107. context_counter dd 0 ;noname & halyavin
  108. noct db 0
  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.