Subversion Repositories Kolibri OS

Rev

Rev 3481 | Rev 3820 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3481 Rev 3761
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line -... Line 8...
-
 
8
$Revision: 3761 $
-
 
9
 
8
$Revision: 3481 $
10
iglobal
-
 
11
  szKernel            db 'KERNEL', 0
Line 9... Line 12...
9
 
12
  szVersion           db 'version',0
10
include 'export.inc'
-
 
11
 
-
 
12
align 4
-
 
13
 
-
 
14
proc load_PE stdcall, file_name:dword
-
 
15
           locals
-
 
16
             image  dd ?
-
 
17
             entry  dd ?
-
 
18
             base   dd ?
-
 
19
           endl
-
 
20
 
-
 
21
        stdcall load_file, [file_name]
-
 
22
        test    eax, eax
-
 
23
        jz      .fail
-
 
24
 
-
 
25
        mov     [image], eax
-
 
26
 
-
 
27
        mov     edx, [eax+60]
-
 
28
 
-
 
29
        stdcall kernel_alloc, [eax+80+edx]
-
 
30
        test    eax, eax
-
 
31
        jz      .cleanup
-
 
32
 
-
 
33
        mov     [base], eax
-
 
34
 
-
 
35
        stdcall map_PE, eax, [image]
-
 
36
 
-
 
37
        mov     [entry], eax
-
 
38
        test    eax, eax
-
 
39
        jnz     .cleanup
-
 
40
 
-
 
41
        stdcall kernel_free, [base]
-
 
42
.cleanup:
-
 
43
        stdcall kernel_free, [image]
-
 
44
        mov     eax, [entry]
-
 
45
        ret
-
 
46
.fail:
-
 
47
        xor     eax, eax
-
 
48
        ret
-
 
49
endp
-
 
50
 
-
 
51
DWORD equ dword
-
 
52
PTR   equ
-
 
53
 
-
 
54
align 4
-
 
55
map_PE:                    ;stdcall base:dword, image:dword
-
 
56
        cld
-
 
57
        push    ebp
-
 
58
        push    edi
-
 
59
        push    esi
-
 
60
        push    ebx
-
 
61
        sub     esp, 60
-
 
62
        mov     ebx, DWORD PTR [esp+84]
-
 
63
        mov     ebp, DWORD PTR [esp+80]
-
 
64
        mov     edx, ebx
-
 
65
        mov     esi, ebx
-
 
66
        add     edx, DWORD PTR [ebx+60]
-
 
67
        mov     edi, ebp
-
 
68
        mov     DWORD PTR [esp+32], edx
-
 
69
        mov     ecx, DWORD PTR [edx+84]
-
 
70
 
-
 
71
        shr     ecx, 2
-
 
72
        rep movsd
-
 
73
 
-
 
74
        movzx   eax, WORD PTR [edx+6]
-
 
75
        mov     DWORD PTR [esp+36], 0
-
 
76
        mov     DWORD PTR [esp+16], eax
-
 
77
        jmp     L2
-
 
78
L3:
-
 
79
        mov     eax, DWORD PTR [edx+264]
-
 
80
        test    eax, eax
-
 
81
        je      L4
-
 
82
        mov     esi, ebx
-
 
83
        mov     edi, ebp
-
 
84
        add     esi, DWORD PTR [edx+268]
-
 
85
        mov     ecx, eax
-
 
86
        add     edi, DWORD PTR [edx+260]
-
 
87
 
-
 
88
        shr     ecx, 2
-
 
89
        rep movsd
-
 
90
 
-
 
91
L4:
-
 
92
        mov     ecx, DWORD PTR [edx+256]
-
 
93
        add     ecx, 4095
-
 
94
        and     ecx, -4096
-
 
95
        cmp     ecx, eax
-
 
96
        jbe     L6
-
 
97
        sub     ecx, eax
-
 
98
        add     eax, DWORD PTR [edx+260]
-
 
99
        lea     edi, [eax+ebp]
-
 
100
 
-
 
101
        xor     eax, eax
-
 
102
        rep stosb
-
 
103
 
-
 
104
L6:
-
 
105
        inc     DWORD PTR [esp+36]
-
 
106
        add     edx, 40
-
 
107
L2:
-
 
108
        mov     esi, DWORD PTR [esp+16]
-
 
109
        cmp     DWORD PTR [esp+36], esi
-
 
110
        jne     L3
-
 
111
        mov     edi, DWORD PTR [esp+32]
-
 
112
        cmp     DWORD PTR [edi+164], 0
-
 
113
        je      L9
-
 
114
        mov     esi, ebp
-
 
115
        mov     ecx, ebp
-
 
116
        sub     esi, DWORD PTR [edi+52]
-
 
117
        add     ecx, DWORD PTR [edi+160]
-
 
118
        mov     eax, esi
-
 
119
        shr     eax, 16
-
 
120
        mov     DWORD PTR [esp+12], eax
-
 
121
        jmp     L11
-
 
122
L12:
-
 
123
        lea     ebx, [eax-8]
-
 
124
        xor     edi, edi
-
 
125
        shr     ebx, 1
-
 
126
        jmp     L13
-
 
127
L14:
-
 
128
        movzx   eax, WORD PTR [ecx+8+edi*2]
-
 
129
        mov     edx, eax
-
 
130
        shr     eax, 12
-
 
131
        and     edx, 4095
-
 
132
        add     edx, DWORD PTR [ecx]
-
 
133
        cmp     ax, 2
-
 
134
        je      L17
-
 
135
        cmp     ax, 3
-
 
136
        je      L18
-
 
137
        dec     ax
-
 
138
        jne     L15
-
 
139
        mov     eax, DWORD PTR [esp+12]
-
 
140
        add     WORD PTR [edx+ebp], ax
-
 
141
L17:
-
 
142
        add     WORD PTR [edx+ebp], si
-
 
143
L18:
-
 
144
        add     DWORD PTR [edx+ebp], esi
-
 
145
L15:
-
 
146
        inc     edi
-
 
147
L13:
-
 
148
        cmp     edi, ebx
-
 
149
        jne     L14
-
 
150
        add     ecx, DWORD PTR [ecx+4]
-
 
151
L11:
-
 
152
        mov     eax, DWORD PTR [ecx+4]
-
 
153
        test    eax, eax
-
 
154
        jne     L12
-
 
155
L9:
-
 
156
        mov     edx, DWORD PTR [esp+32]
-
 
157
        cmp     DWORD PTR [edx+132], 0
-
 
158
        je      L20
-
 
159
        mov     eax, ebp
-
 
160
        add     eax, DWORD PTR [edx+128]
-
 
161
        mov     DWORD PTR [esp+40], 0
-
 
162
        add     eax, 20
-
 
163
        mov     DWORD PTR [esp+56], eax
-
 
164
L22:
-
 
165
        mov     ecx, DWORD PTR [esp+56]
-
 
166
        cmp     DWORD PTR [ecx-16], 0
-
 
167
        jne     L23
-
 
168
        cmp     DWORD PTR [ecx-8], 0
-
 
169
        je      L25
-
 
170
L23:
-
 
171
        mov     edi, DWORD PTR [__exports+32]
-
 
172
        mov     esi, DWORD PTR [__exports+28]
-
 
173
        mov     eax, DWORD PTR [esp+56]
-
 
174
        mov     DWORD PTR [esp+20], edi
-
 
175
        add     edi, OS_BASE
-
 
176
        add     esi, OS_BASE
-
 
177
        mov     DWORD PTR [esp+44], esi
-
 
178
        mov     ecx, DWORD PTR [eax-4]
-
 
179
        mov     DWORD PTR [esp+48], edi
-
 
180
        mov     edx, DWORD PTR [eax-20]
-
 
181
        mov     DWORD PTR [esp+52], 0
-
 
182
        add     ecx, ebp
-
 
183
        add     edx, ebp
-
 
184
        mov     DWORD PTR [esp+24], edx
-
 
185
        mov     DWORD PTR [esp+28], ecx
-
 
186
L26:
-
 
187
        mov     esi, DWORD PTR [esp+52]
-
 
188
        mov     edi, DWORD PTR [esp+24]
-
 
189
        mov     eax, DWORD PTR [edi+esi*4]
-
 
190
        test    eax, eax
-
 
191
        je      L27
-
 
192
        test    eax, eax
-
 
193
        js      L27
-
 
194
        lea     edi, [ebp+eax]
-
 
195
        mov     eax, DWORD PTR [esp+28]
-
 
196
        mov     DWORD PTR [eax+esi*4], 0
-
 
197
        lea     esi, [edi+2]
-
 
198
        push    eax
-
 
199
        push    32
-
 
200
        movzx   eax, WORD PTR [edi]
-
 
201
        mov     edx, DWORD PTR [esp+56]
-
 
202
        mov     eax, DWORD PTR [edx+eax*4]
-
 
203
        add     eax, OS_BASE
-
 
204
        push    eax
-
 
205
        push    esi
-
 
206
        call    strncmp
-
 
207
        pop     ebx
-
 
208
        xor     ebx, ebx
-
 
209
        test    eax, eax
-
 
210
        jne     L32
-
 
211
        jmp     L30
-
 
212
L33:
-
 
213
        push    ecx
-
 
214
        push    32
-
 
215
        mov     ecx, DWORD PTR [esp+28]
-
 
216
        mov     eax, DWORD PTR [ecx+OS_BASE+ebx*4]
-
 
217
        add     eax, OS_BASE
-
 
218
        push    eax
-
 
219
        push    esi
-
 
220
        call    strncmp
-
 
221
        pop     edx
-
 
222
        test    eax, eax
-
 
223
        jne     L34
-
 
224
        mov     esi, DWORD PTR [esp+44]
-
 
225
        mov     edx, DWORD PTR [esp+52]
-
 
226
        mov     ecx, DWORD PTR [esp+28]
-
 
227
        mov     eax, DWORD PTR [esi+ebx*4]
-
 
228
        add     eax, OS_BASE
-
 
229
        mov     DWORD PTR [ecx+edx*4], eax
-
 
230
        jmp     L36
-
 
231
L34:
-
 
232
        inc     ebx
-
 
233
L32:
-
 
234
        cmp     ebx, DWORD PTR [__exports+24]
-
 
235
        jb      L33
-
 
236
L36:
-
 
237
        cmp     ebx, DWORD PTR [__exports+24]
-
 
238
        jne     L37
-
 
239
 
-
 
240
        mov     esi, msg_unresolved
-
 
241
        call    sys_msg_board_str
-
 
242
        lea     esi, [edi+2]
-
 
243
        call    sys_msg_board_str
-
 
244
        mov     esi, msg_CR
-
 
245
        call    sys_msg_board_str
-
 
246
 
-
 
247
        mov     DWORD PTR [esp+40], 1
-
 
248
        jmp     L37
-
 
249
L30:
-
 
250
        movzx   eax, WORD PTR [edi]
-
 
251
        mov     esi, DWORD PTR [esp+44]
-
 
252
        mov     edi, DWORD PTR [esp+52]
-
 
253
        mov     edx, DWORD PTR [esp+28]
-
 
254
        mov     eax, DWORD PTR [esi+eax*4]
-
 
255
        add     eax, OS_BASE
-
 
256
        mov     DWORD PTR [edx+edi*4], eax
-
 
257
L37:
-
 
258
        inc     DWORD PTR [esp+52]
-
 
259
        jmp     L26
-
 
260
L27:
-
 
261
        add     DWORD PTR [esp+56], 20
-
 
262
        jmp     L22
-
 
263
L25:
-
 
264
        xor     eax, eax
-
 
265
        cmp     DWORD PTR [esp+40], 0
-
 
266
        jne     L40
-
 
267
L20:
-
 
268
        mov     ecx, DWORD PTR [esp+32]
-
 
269
        mov     eax, ebp
-
 
270
        add     eax, DWORD PTR [ecx+40]
-
 
271
L40:
-
 
272
        add     esp, 60
-
 
273
        pop     ebx
-
 
274
        pop     esi
-
 
275
        pop     edi
-
 
276
        pop     ebp
-
 
277
        ret     8
13
endg
278
 
14
 
279
 align 16
15
 align 4
280
__exports:
16
__exports:
281
          export 'KERNEL',   \
17
          export 'KERNEL',   \
282
          alloc_kernel_space,    'AllocKernelSpace',   \      ; stdcall
18
          alloc_kernel_space,    'AllocKernelSpace',   \      ; stdcall
283
          alloc_page,            'AllocPage',          \      ; gcc ABI
19
          alloc_page,            'AllocPage',          \      ; gcc ABI
284
          alloc_pages,           'AllocPages',         \      ; stdcall
20
          alloc_pages,           'AllocPages',         \      ; stdcall
-
 
21
          commit_pages,          'CommitPages',        \      ; eax, ebx, ecx
285
          commit_pages,          'CommitPages',        \      ; eax, ebx, ecx
22
\
286
\
23
          disk_add,              'DiskAdd',            \      ;stdcall
287
          disk_add,              'DiskAdd',            \      ;stdcall
24
          disk_del,              'DiskDel',            \
288
          disk_media_changed,    'DiskMediaChanged',   \      ;stdcall
25
          disk_media_changed,    'DiskMediaChanged',   \      ;stdcall
289
\
26
\
290
          create_event,          'CreateEvent',        \      ; ecx, esi
27
          create_event,          'CreateEvent',        \      ; ecx, esi
291
          destroy_event,         'DestroyEvent',       \      ;
28
          destroy_event,         'DestroyEvent',       \      ;
292
          raise_event,           'RaiseEvent',         \      ; eax, ebx, edx, esi
29
          raise_event,           'RaiseEvent',         \      ; eax, ebx, edx, esi
-
 
30
          wait_event,            'WaitEvent',          \      ; eax, ebx
-
 
31
          wait_event_timeout,    'WaitEventTimeout',   \      ; eax, ebx, ecx
293
          wait_event,            'WaitEvent',          \      ; eax, ebx
32
          get_event_ex,          'GetEvent',           \      ; edi
294
          wait_event_timeout,    'WaitEventTimeout',   \      ; eax, ebx, ecx
33
          clear_event,           'ClearEvent',         \      ;see EVENT.inc for specification
295
          get_event_ex,          'GetEvent',           \      ; edi
34
          send_event,            'SendEvent',          \      ;see EVENT.inc for specification
296
\
35
\
297
          create_kernel_object,  'CreateObject',       \
36
          create_kernel_object,  'CreateObject',       \
Line 304... Line 43...
304
          malloc,                'Kmalloc',            \
43
          malloc,                'Kmalloc',            \
305
          free,                  'Kfree',              \
44
          free,                  'Kfree',              \
306
          map_io_mem,            'MapIoMem',           \      ; stdcall
45
          map_io_mem,            'MapIoMem',           \      ; stdcall
307
          map_page,              'MapPage',            \      ; stdcall
46
          map_page,              'MapPage',            \      ; stdcall
308
          get_pg_addr,           'GetPgAddr',          \      ; eax
47
          get_pg_addr,           'GetPgAddr',          \      ; eax
-
 
48
          map_space,             'MapSpace',           \
-
 
49
          release_pages,         'ReleasePages',       \
309
\
50
\
310
          mutex_init,            'MutexInit',          \      ; gcc fastcall
51
          mutex_init,            'MutexInit',          \      ; gcc fastcall
311
          mutex_lock,            'MutexLock',          \      ; gcc fastcall
52
          mutex_lock,            'MutexLock',          \      ; gcc fastcall
312
          mutex_unlock,          'MutexUnlock',        \      ; gcc fastcall
53
          mutex_unlock,          'MutexUnlock',        \      ; gcc fastcall
313
\
54
\
Line 328... Line 69...
328
          attach_int_handler,    'AttachIntHandler',   \      ; stdcall
69
          attach_int_handler,    'AttachIntHandler',   \      ; stdcall
329
          user_alloc,            'UserAlloc',          \      ; stdcall
70
          user_alloc,            'UserAlloc',          \      ; stdcall
330
          user_free,             'UserFree',           \      ; stdcall
71
          user_free,             'UserFree',           \      ; stdcall
331
          unmap_pages,           'UnmapPages',         \      ; eax, ecx
72
          unmap_pages,           'UnmapPages',         \      ; eax, ecx
332
          sys_msg_board_str,     'SysMsgBoardStr',     \
73
          sys_msg_board_str,     'SysMsgBoardStr',     \
-
 
74
          sys_msg_board,         'SysMsgBoard',        \
333
          get_timer_ticks,       'GetTimerTicks',      \
75
          get_timer_ticks,       'GetTimerTicks',      \
334
          get_stack_base,        'GetStackBase',       \
76
          get_stack_base,        'GetStackBase',       \
335
          delay_hs,              'Delay',              \      ; ebx
77
          delay_hs,              'Delay',              \      ; ebx
336
          set_mouse_data,        'SetMouseData',       \      ;
78
          set_mouse_data,        'SetMouseData',       \      ;
337
          set_keyboard_data,     'SetKeyboardData',    \      ; gcc fastcall
79
          set_keyboard_data,     'SetKeyboardData',    \      ; gcc fastcall
-
 
80
          register_keyboard,     'RegKeyboard',        \
-
 
81
          delete_keyboard,       'DelKeyboard',        \
-
 
82
          get_cpu_freq,          'GetCpuFreq',         \
-
 
83
\
-
 
84
          srv_handler,           'ServiceHandler',     \
-
 
85
          fpu_save,              'FpuSave',            \
-
 
86
          fpu_restore,           'FpuRestore',         \
-
 
87
          r_f_port_area,         'ReservePortArea',    \
-
 
88
          boot_log,              'Boot_Log',           \
-
 
89
\
338
          timer_hs,              'TimerHs',            \      ; stdcall
90
          load_cursor,           'LoadCursor',         \      ;stdcall
-
 
91
\
339
          get_cpu_freq,          'GetCpuFreq'
92
          get_curr_task,         'GetCurrentTask',     \
-
 
93
          load_file,             'LoadFile',           \      ;retval eax, ebx
-
 
94
          delay_ms,              'Sleep',              \
-
 
95
\
-
 
96
          strncat,               'strncat',            \
-
 
97
          strncpy,               'strncpy',            \
-
 
98
          strncmp,               'strncmp',            \
-
 
99
          strnlen,               'strnlen',            \
-
 
100
          strchr,                'strchr',             \
-
 
101
          strrchr,               'strrchr',            \
-
 
102
\
-
 
103
          timer_hs,              'TimerHS',            \
-
 
104
          cancel_timer_hs,       'CancelTimerHS',      \
340
105
\
-
 
106
          reg_usb_driver,        'RegUSBDriver',       \
-
 
107
          usb_open_pipe,         'USBOpenPipe',        \
-
 
108
          usb_close_pipe,        'USBClosePipe',       \
-
 
109
          usb_normal_transfer_async, 'USBNormalTransferAsync', \
-
 
110
          usb_control_async,     'USBControlTransferAsync', \
-
 
111
          usb_get_param,         'USBGetParam',        \
341
112
\
-
 
113
          NET_add_device,        'NetRegDev',          \
-
 
114
          NET_remove_device,     'NetUnRegDev',        \
-
 
115
          NET_ptr_to_num,        'NetPtrToNum',        \
-
 
116
          NET_link_changed,      'NetLinkChanged',     \
-
 
117
          ETH_input,             'Eth_input',          \
342
118
\
-
 
119
          0,                     'LFBAddress' ; must be the last one
-
 
120
load kernel_exports_count dword from __exports + 24
-
 
121
load kernel_exports_addresses dword from __exports + 28
-
 
122
exp_lfb = OS_BASE + kernel_exports_addresses + (kernel_exports_count - 1) * 4 - 4