Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                            ;;
  3. ;;                   SYSTEM CALL ENTRY                        ;;
  4. ;;                                                            ;;
  5. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6. uglobal
  7.   task_tss rd 1
  8. endg
  9. align 32
  10. i40:
  11.       pushad
  12.  
  13.       push  ds
  14.       mov   ax,word os_data
  15.       mov   ds,ax
  16.       mov   es,ax
  17.       mov   [task_tss],esp
  18.       add   dword [task_tss],4
  19.       cli
  20.  
  21.       mov    edi,[0x3000]
  22.       mov    eax,edi
  23.       shl    edi, 3
  24. ;clear busy flag in application's TSS      
  25.       mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
  26.  
  27.  
  28.       shl    edi,5
  29.       mov    [edi+0x80000+0xB0],eax  ; used i40 handler
  30.  
  31.       ; for syscall trace function
  32.       call  save_registers
  33.  
  34. ;      mov   esi, [0x3000]
  35. ;      imul  esi, tss_step
  36. ;      add   esi, tss_data
  37.       mov   esi,[task_tss]
  38. ;      sub   esi,0x28
  39.       ; esi holds address of TSS of interupted program
  40.       ; load first 3 registers
  41.       mov   eax,[esi+28];+l.eax-tss_sceleton]
  42.       mov   ebx,[esi+16];l.ebx-tss_sceleton]
  43.       mov   ecx,[esi+24];l.ecx-tss_sceleton]
  44.  
  45.       ; save current registers
  46.       ; stack may be modified by a system function to return some value to caller!
  47.       pushad
  48.  
  49.       ; load all registers from TSS of the application, in crossed order (why?)
  50.       mov   edi,[esi+28];l.eax-tss_sceleton]
  51.       mov   eax,[esi+16];l.ebx-tss_sceleton]
  52.       mov   ebx,[esi+24];l.ecx-tss_sceleton]
  53.       mov   ecx,[esi+20];l.edx-tss_sceleton]
  54.       mov   edx,[esi+4];l.esi-tss_sceleton]
  55.       mov   esi,[esi+0];l.edi-tss_sceleton]
  56.  
  57.       ; enable interupts  -  a task switch or an IRQ _CAN_ interrupt i40 handler
  58.       sti
  59.       ; eax doesn't need to be saved, but...
  60.       push   eax
  61.       and    edi,0xff
  62.       call   dword [servetable+edi*4]
  63.       pop    eax
  64.       cli
  65.        
  66.       ; return saved and probably even changed regs
  67.       popad
  68.  
  69.  ; <Ivan 05.03.2005> esi already loaded  -  look above "pusha"
  70.       ;mov   esi,[0x3000]
  71.       ;imul  esi,tss_step
  72.       ;add   esi,tss_data
  73.  ; </Ivan 05.03.2005>
  74.  
  75.       ; modify 3 program's registers (in its TSS)
  76.       mov   [esi+28],eax;[esi+l.eax-tss_sceleton], eax    
  77.       mov   [esi+16],ebx;[esi+l.ebx-tss_sceleton], ebx
  78.       mov   [esi+24],ecx;[esi+l.ecx-tss_sceleton], ecx
  79.  
  80.       xor    eax, eax
  81.       mov    edi, [0x3000]          ; no syscall interrupt in use anymore
  82.       shl    edi, 8
  83.       mov    [edi+0x80000+0xB0],eax
  84.  
  85.       pop     eax
  86.       mov     ds,ax
  87.       mov     es,ax
  88.      
  89.       popad
  90.       iretd
  91.  
  92.       jmp    i40
  93.  
  94. label reg1    dword at 0x6000
  95. label reg2    dword at 0x6400
  96. label usedi40 byte  at 0x6800
  97.  
  98. uglobal
  99.   schd dd 0x0
  100. endg
  101.  
  102. align 4
  103. save_registers:
  104.  
  105.       mov   esi,[0x3000]
  106.       imul  esi,tss_step
  107.       add   esi,tss_data
  108.  
  109.       mov   eax,[esi+l.eax-tss_sceleton]
  110.       mov   ebx,[esi+l.ebx-tss_sceleton]
  111.       mov   ecx,[esi+l.ecx-tss_sceleton]
  112.       mov   edx,[esi+l.edx-tss_sceleton]
  113.       mov   edi,[esi+l.edi-tss_sceleton]
  114.       mov   ebp,[esi+l.ebp-tss_sceleton]
  115.  
  116.       mov   esi,[esi+l.esi-tss_sceleton]
  117.  
  118.       push  eax ecx esi edi
  119.       mov   esi,[0x3010]
  120.       mov   eax,[esi+0x4]
  121.       mov   esi,esp
  122.       inc   [save_syscall_count]
  123.       mov   edi,[save_syscall_count]
  124.       and   edi,0xF
  125.       shl   edi,6
  126.       add   edi,save_syscall_data+32
  127.       mov   [edi-32],eax
  128.       mov   ecx,32 / 4
  129.       cld
  130.       rep   movsd
  131.       pop   edi esi ecx eax
  132.       ret
  133.  
  134. uglobal
  135.   save_syscall_count  dd 0x0
  136. endg
  137.  
  138. label save_syscall_data dword at 0x5000
  139.  
  140.  
  141. iglobal
  142.   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  143.   ;; SYSTEM FUNCTIONS TABLE ;;
  144.   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  145.  
  146.   align 4
  147.   servetable:
  148.  
  149.       dd sys_drawwindow          ; 0-DrawWindow
  150.       dd syscall_setpixel        ; 1-SetPixel
  151.       dd sys_getkey              ; 2-GetKey
  152.       dd sys_clock               ; 3-GetTime
  153.       dd syscall_writetext       ; 4-WriteText
  154.       dd delay_hs                ; 5-DelayHs
  155.       dd syscall_openramdiskfile ; 6-OpenRamdiskFile
  156.       dd syscall_putimage        ; 7-PutImage
  157.       dd sys_button              ; 8-DefineButton
  158.       dd sys_cpuusage            ; 9-GetProcessInfo
  159.       dd sys_waitforevent        ; 10-WaitForEvent
  160.       dd sys_getevent            ; 11-CheckForEvent
  161.       dd sys_redrawstat          ; 12-BeginDraw and EndDraw
  162.       dd syscall_drawrect        ; 13-DrawRect
  163.       dd syscall_getscreensize   ; 14-GetScreenSize
  164.       dd sys_background          ; 15-bgr
  165.       dd sys_cachetodiskette     ; 16-FlushFloppyCache
  166.       dd sys_getbutton           ; 17-GetButton
  167.       dd syscall_system          ; 18-Shutdown,KillApp,WindowActivate
  168.       dd syscall_startapp        ; 19-StartApp
  169.       dd sys_midi                ; 20-ResetMidi and OutputMidi
  170.       dd sys_setup               ; 21-SetMidiBase,SetKeymap,SetShiftKeymap,.
  171.       dd sys_settime             ; 22-setting date,time,clock and alarm-clock
  172.       dd sys_wait_event_timeout  ; 23-TimeOutWaitForEvent
  173.       dd syscall_cdaudio         ; 24-PlayCdTrack,StopCd and GetCdPlaylist
  174.       dd sys_sb16                ; 25-SetSb16
  175.       dd sys_getsetup            ; 26-GetMidiBase,GetKeymap,GetShiftKeymap,.
  176.       dd sys_wss                 ; 27-SetWssMainVol and SetWssCdVol
  177.       dd sys_sb16II              ; 28-SetSb16
  178.       dd sys_date                ; 29-GetDate
  179.       dd syscall_readhd          ; 30-ReadHd
  180.       dd syscall_starthdapp      ; 31-StartHdApp
  181.       dd syscall_delramdiskfile  ; 32-DelRamdiskFile
  182.       dd syscall_writeramdiskfile; 33-WriteRamdiskFile
  183.       dd read_floppy_file        ; 34-ReadFloppyDrive
  184.       dd syscall_getpixel        ; 35-GetPixel
  185.       dd syscall_readstring      ; 36-ReadString (not yet ready)
  186.       dd readmousepos            ; 37-GetMousePosition_ScreenRelative,.
  187.       dd syscall_drawline        ; 38-DrawLine
  188.       dd sys_getbackground       ; 39-GetBackgroundSize,ReadBgrData,.
  189.       dd set_app_param           ; 40-WantEvents
  190.       dd syscall_getirqowner     ; 41-GetIrqOwner
  191.       dd get_irq_data            ; 42-ReadIrqData
  192.       dd sys_outport             ; 43-SendDeviceData
  193.       dd sys_programirq          ; 44-ProgramIrqs
  194.       dd reserve_free_irq        ; 45-ReserveIrq and FreeIrq
  195.       dd syscall_reserveportarea ; 46-ReservePortArea and FreePortArea
  196.       dd display_number          ; 47-WriteNum
  197.       dd display_settings        ; 48-SetRedrawType and SetButtonType
  198.       dd syscall_appints         ; 49-AppInts
  199.       dd random_shaped_window    ; 50-Window shape & scale
  200.       dd syscall_threads         ; 51-Threads
  201.       dd stack_driver_stat       ; 52-Stack driver status
  202.       dd socket                  ; 53-Socket interface
  203.       dd user_events             ; 54-User events
  204.       dd sound_interface         ; 55-Sound interface
  205.       dd write_to_hd             ; 56-Write a file to hd
  206.       dd delete_from_hd          ; 57-Delete a file from hd
  207.       dd file_system             ; 58-Common file system interface
  208.       dd sys_trace               ; 59-System call trace
  209.       dd new_sys_ipc             ; 60-Inter Process Communication
  210.       dd sys_gs                  ; 61-Direct graphics access
  211.       dd sys_pci                 ; 62-PCI functions
  212.       dd sys_msg_board           ; 63-System message board
  213.       dd sys_resize_app_memory   ; 64-Resize application memory usage
  214.       dd undefined_syscall       ; 65-UTF
  215.       dd sys_process_def         ; 66-Process definitions - keyboard
  216.       dd sys_window_move         ; 67-Window move or resize
  217.       dd sys_internal_services   ; 68-Some internal services
  218.  
  219.   times 255 - ( ($-servetable) /4 )  dd undefined_syscall
  220.  
  221.       dd sys_end                 ; -1-end application
  222. endg
  223.  
  224.