Subversion Repositories Kolibri OS

Rev

Rev 2 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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