Subversion Repositories Kolibri OS

Rev

Rev 2 | Rev 4 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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