Subversion Repositories Kolibri OS

Rev

Rev 2 | Rev 4 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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