Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
709 diamond 3
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
431 serge 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
164 serge 7
 
593 mikedld 8
$Revision: 740 $
9
 
10
 
465 serge 11
DRV_COMPAT   equ  5  ;minimal required drivers version
12
DRV_CURRENT  equ  5  ;current drivers model version
214 serge 13
 
227 serge 14
DRV_VERSION equ (DRV_COMPAT shl 16) or DRV_CURRENT
15
 
164 serge 16
align 4
17
proc attach_int_handler stdcall, irq:dword, handler:dword
18
 
709 diamond 19
         mov  ebx, [irq]        ;irq num
20
         test ebx, ebx
21
         jz   .err
22
         cmp  ebx, 15           ; hidnplayr says: we only have 16 IRQ's
23
         ja   .err
24
         mov  eax, [handler]
25
         test eax, eax
26
         jz   .err
27
         mov  [irq_tab+ebx*4], eax
28
         stdcall enable_irq, [irq]
29
         ret
164 serge 30
.err:
709 diamond 31
         xor eax, eax
32
         ret
164 serge 33
endp
34
 
35
align 4
36
proc  detach_int_handler
37
 
38
	   ret
39
endp
40
 
41
align 4
42
proc enable_irq stdcall, irq_line:dword
672 hidnplayr 43
	   mov ebx, [irq_line]
44
	   mov edx, 0x21
45
	   cmp ebx, 8
46
	   jb @F
47
	   mov edx, 0xA1
48
	   sub ebx,8
164 serge 49
@@:
672 hidnplayr 50
	   in al,dx
51
	   btr eax, ebx
52
	   out dx, al
53
	   ret
164 serge 54
endp
55
 
56
align 16
57
;; proc irq_serv
58
 
59
irq_serv:
60
 
61
.irq_1:
62
	   push eax
63
	   mov eax, 1
64
	   jmp .main
65
align 4
66
.irq_2:
67
	   push eax
68
	   mov eax, 2
69
	   jmp .main
70
align 4
71
.irq_3:
72
	   push eax
73
	   mov eax, 3
74
	   jmp .main
75
align 4
76
.irq_4:
77
	   push eax
78
	   mov eax, 4
79
	   jmp .main
80
align 4
81
.irq_5:
82
	   push eax
83
	   mov eax, 5
84
	   jmp .main
85
align 4
86
.irq_6:
87
	   push eax
88
	   mov eax, 6
89
	   jmp .main
90
align 4
91
.irq_7:
92
	   push eax
93
	   mov eax, 7
94
	   jmp .main
95
align 4
96
.irq_8:
97
	   push eax
98
	   mov eax, 8
99
	   jmp .main
100
align 4
101
.irq_9:
102
	   push eax
103
	   mov eax, 9
104
	   jmp .main
105
align 4
106
.irq_10:
107
	   push eax
108
	   mov eax, 10
109
	   jmp .main
110
align 4
111
.irq_11:
112
	   push eax
113
	   mov eax, 11
114
	   jmp .main
115
align 4
116
.irq_12:
117
	   push eax
118
	   mov eax, 12
119
	   jmp .main
120
align 4
121
.irq_13:
122
	   push eax
123
	   mov eax, 13
124
	   jmp .main
125
align 4
126
.irq_14:
127
	   push eax
128
	   mov eax, 14
129
	   jmp .main
130
align 4
131
.irq_15:
132
	   push eax
133
	   mov eax, 15
134
	   jmp .main
135
 
136
align 16
137
.main:
138
	   save_ring3_context
672 hidnplayr 139
	   mov	 bx, app_data  ;os_data
164 serge 140
	   mov	 ds, bx
141
	   mov	 es, bx
142
 
709 diamond 143
           cmp   [v86_irqhooks+eax*8], 0
144
           jnz   v86_irq
145
 
164 serge 146
	   mov ebx, [irq_tab+eax*4]
147
	   test ebx, ebx
148
	   jz .exit
149
 
672 hidnplayr 150
	   call ebx
151
	   mov	[check_idle_semaphore],5
164 serge 152
 
153
.exit:
154
	   restore_ring3_context
155
 
672 hidnplayr 156
	   cmp eax, 8
164 serge 157
	   mov al, 0x20
672 hidnplayr 158
	   jb @f
164 serge 159
	   out 0xa0, al
160
@@:
672 hidnplayr 161
	   out 0x20, al
164 serge 162
 
672 hidnplayr 163
	   pop eax
164 serge 164
	   iret
165
 
166
align 4
167
proc get_notify stdcall, p_ev:dword
168
 
169
.wait:
672 hidnplayr 170
	   mov ebx,[current_slot]
171
	   test dword [ebx+APPDATA.event_mask],EVENT_NOTIFY
164 serge 172
	   jz @f
672 hidnplayr 173
	   and dword [ebx+APPDATA.event_mask], not EVENT_NOTIFY
164 serge 174
	   mov edi, [p_ev]
175
	   mov dword [edi], EV_INTR
672 hidnplayr 176
	   mov eax, [ebx+APPDATA.event]
164 serge 177
	   mov dword [edi+4], eax
178
	   ret
179
@@:
180
	   call change_task
181
	   jmp .wait
182
endp
183
 
184
align 4
185
proc pci_read32 stdcall, bus:dword, devfn:dword, reg:dword
740 serge 186
           push ebx
164 serge 187
	   xor eax, eax
188
	   xor ebx, ebx
189
	   mov ah, byte [bus]
672 hidnplayr 190
	   mov al, 6
164 serge 191
	   mov bh, byte [devfn]
192
	   mov bl, byte [reg]
193
	   call pci_read_reg
740 serge 194
           pop ebx
164 serge 195
	   ret
196
endp
197
 
198
align 4
557 serge 199
proc pci_read16 stdcall, bus:dword, devfn:dword, reg:dword
200
	   xor eax, eax
201
	   xor ebx, ebx
202
	   mov ah, byte [bus]
672 hidnplayr 203
	   mov al, 5
557 serge 204
	   mov bh, byte [devfn]
205
	   mov bl, byte [reg]
206
	   call pci_read_reg
207
	   ret
208
endp
209
 
210
align 4
164 serge 211
proc pci_read8 stdcall, bus:dword, devfn:dword, reg:dword
212
	   xor eax, eax
213
	   xor ebx, ebx
214
	   mov ah, byte [bus]
672 hidnplayr 215
	   mov al, 4
164 serge 216
	   mov bh, byte [devfn]
217
	   mov bl, byte [reg]
218
	   call pci_read_reg
219
	   ret
220
endp
221
 
222
align 4
223
proc pci_write8 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
224
	   xor eax, eax
225
	   xor ebx, ebx
226
	   mov ah, byte [bus]
672 hidnplayr 227
	   mov al, 8
164 serge 228
	   mov bh, byte [devfn]
229
	   mov bl, byte [reg]
672 hidnplayr 230
	   mov ecx, [val]
231
	   call pci_write_reg
164 serge 232
	   ret
233
endp
234
 
557 serge 235
align 4
236
proc pci_write16 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
237
	   xor eax, eax
238
	   xor ebx, ebx
239
	   mov ah, byte [bus]
672 hidnplayr 240
	   mov al, 9
557 serge 241
	   mov bh, byte [devfn]
242
	   mov bl, byte [reg]
672 hidnplayr 243
	   mov ecx, [val]
244
	   call pci_write_reg
557 serge 245
	   ret
246
endp
247
 
672 hidnplayr 248
align 4
249
proc pci_write32 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
250
	   xor eax, eax
251
	   xor ebx, ebx
252
	   mov ah, byte [bus]
253
	   mov al, 10
254
	   mov bh, byte [devfn]
255
	   mov bl, byte [reg]
256
	   mov ecx, [val]
257
	   call pci_write_reg
258
	   ret
259
endp
164 serge 260
 
672 hidnplayr 261
handle	   equ	IOCTL.handle
262
io_code    equ	IOCTL.io_code
263
input	   equ	IOCTL.input
264
inp_size   equ	IOCTL.inp_size
265
output	   equ	IOCTL.output
266
out_size   equ	IOCTL.out_size
164 serge 267
 
672 hidnplayr 268
 
164 serge 269
align 4
270
proc srv_handler stdcall, ioctl:dword
672 hidnplayr 271
	   mov esi, [ioctl]
272
	   test esi, esi
273
	   jz .err
164 serge 274
 
672 hidnplayr 275
	   mov edi, [esi+handle]
276
	   cmp [edi+SRV.magic], ' SRV'
164 serge 277
	   jne .fail
278
 
672 hidnplayr 279
	   cmp [edi+SRV.size], SRV_SIZE
164 serge 280
	   jne .fail
281
 
672 hidnplayr 282
	   stdcall [edi+SRV.srv_proc], esi
283
	   ret
164 serge 284
.fail:
672 hidnplayr 285
	   xor eax, eax
286
	   not eax
287
	   mov [esi+output], eax
288
	   mov [esi+out_size], 4
289
	   ret
164 serge 290
.err:
672 hidnplayr 291
	   xor eax, eax
292
	   not eax
293
	   ret
164 serge 294
endp
295
 
377 serge 296
; param
297
;  ebx= io_control
298
;
299
; retval
300
;  eax= error code
301
 
164 serge 302
align 4
377 serge 303
srv_handlerEx:
672 hidnplayr 304
	   cmp ebx, OS_BASE
305
	   jae .fail
164 serge 306
 
672 hidnplayr 307
	   mov eax, [ebx+handle]
308
	   cmp [eax+SRV.magic], ' SRV'
164 serge 309
	   jne .fail
310
 
672 hidnplayr 311
	   cmp [eax+SRV.size], SRV_SIZE
164 serge 312
	   jne .fail
313
 
672 hidnplayr 314
	   stdcall [eax+SRV.srv_proc], ebx
315
	   ret
164 serge 316
.fail:
672 hidnplayr 317
	   or eax, -1
318
	   ret
164 serge 319
 
320
restore  handle
321
restore  io_code
322
restore  input
323
restore  inp_size
324
restore  output
325
restore  out_size
326
 
327
align 4
328
proc get_service stdcall, sz_name:dword
672 hidnplayr 329
	   mov eax, [sz_name]
330
	   test eax, eax
331
	   jnz @F
332
	   ret
164 serge 333
@@:
672 hidnplayr 334
	   mov edx, [srv.fd]
188 serge 335
@@:
672 hidnplayr 336
	   cmp edx, srv.fd-SRV_FD_OFFSET
337
	   je .not_load
278 serge 338
 
672 hidnplayr 339
	   stdcall strncmp, edx, [sz_name], 16
340
	   test eax, eax
341
	   je .ok
164 serge 342
 
672 hidnplayr 343
	   mov edx, [edx+SRV.fd]
344
	   jmp @B
164 serge 345
.not_load:
672 hidnplayr 346
	   pop ebp
347
	   jmp load_driver
164 serge 348
.ok:
672 hidnplayr 349
	   mov eax, edx
350
	   ret
164 serge 351
endp
352
 
353
align 4
740 serge 354
proc reg_service stdcall, name:dword, handler:dword
164 serge 355
 
740 serge 356
           xor eax, eax
164 serge 357
 
740 serge 358
           cmp [name], eax
359
           je .fail
360
 
361
           cmp [handler], eax
362
           je .fail
363
 
364
           push ebx
672 hidnplayr 365
	   mov eax, SRV_SIZE
366
	   call malloc		 ;call alloc_service
740 serge 367
           pop ebx
164 serge 368
	   test eax, eax
369
	   jz .fail
370
 
740 serge 371
           push ebx
372
           push esi
373
           push edi
164 serge 374
	   mov edi, eax
740 serge 375
           mov esi, [name]
672 hidnplayr 376
	   mov ecx, 16/4
377
	   rep movsd
740 serge 378
           pop edi
379
           pop esi
164 serge 380
 
672 hidnplayr 381
	   mov [eax+SRV.magic], ' SRV'
382
	   mov [eax+SRV.size], SRV_SIZE
278 serge 383
 
672 hidnplayr 384
	   mov ebx, srv.fd-SRV_FD_OFFSET
385
	   mov edx, [ebx+SRV.fd]
386
	   mov [eax+SRV.fd], edx
387
	   mov [eax+SRV.bk], ebx
388
	   mov [ebx+SRV.fd], eax
389
	   mov [edx+SRV.bk], eax
278 serge 390
 
740 serge 391
           mov ecx, [handler]
672 hidnplayr 392
	   mov [eax+SRV.srv_proc], ecx
740 serge 393
           pop ebx
394
           ret
164 serge 395
.fail:
396
	   xor eax, eax
740 serge 397
           ret
398
endp
164 serge 399
 
400
align 4
401
proc get_proc stdcall, exp:dword, sz_name:dword
402
 
672 hidnplayr 403
	   mov edx, [exp]
164 serge 404
.next:
672 hidnplayr 405
	   mov eax, [edx]
406
	   test eax, eax
407
	   jz .end
164 serge 408
 
672 hidnplayr 409
	   push edx
410
	   stdcall strncmp, eax, [sz_name], 16
411
	   pop edx
412
	   test eax, eax
413
	   jz .ok
164 serge 414
 
672 hidnplayr 415
	   add edx,8
416
	   jmp .next
164 serge 417
.ok:
672 hidnplayr 418
	   mov eax, [edx+4]
164 serge 419
.end:
672 hidnplayr 420
	   ret
164 serge 421
endp
422
 
423
align 4
424
proc get_coff_sym stdcall, pSym:dword,count:dword, sz_sym:dword
425
 
426
@@:
427
	   stdcall strncmp, [pSym], [sz_sym], 8
428
	   test eax,eax
429
	   jz .ok
430
	   add [pSym], 18
431
	   dec [count]
432
	   jnz @b
433
	   xor eax, eax
434
	   ret
435
.ok:
436
	   mov ebx, [pSym]
437
	   mov eax, [ebx+8]
438
	   ret
439
endp
440
 
441
align 4
188 serge 442
proc get_curr_task
672 hidnplayr 443
	   mov eax,[CURRENT_TASK]
444
	   shl eax, 8
445
	   ret
188 serge 446
endp
164 serge 447
 
188 serge 448
align 4
449
proc get_fileinfo stdcall, file_name:dword, info:dword
672 hidnplayr 450
	   locals
451
	     cmd     dd ?
452
	     offset  dd ?
453
		     dd ?
454
	     count   dd ?
455
	     buff    dd ?
456
		     db ?
457
	     name    dd ?
458
	   endl
164 serge 459
 
672 hidnplayr 460
	   xor eax, eax
461
	   mov ebx, [file_name]
462
	   mov ecx, [info]
164 serge 463
 
672 hidnplayr 464
	   mov [cmd], 5
465
	   mov [offset], eax
466
	   mov [offset+4], eax
467
	   mov [count], eax
468
	   mov [buff], ecx
469
	   mov byte [buff+4], al
470
	   mov [name], ebx
164 serge 471
 
672 hidnplayr 472
	   mov eax, 70
473
	   lea ebx, [cmd]
474
	   int 0x40
475
	   ret
188 serge 476
endp
164 serge 477
 
188 serge 478
align 4
479
proc read_file stdcall,file_name:dword, buffer:dword, off:dword,\
672 hidnplayr 480
				     bytes:dword
481
	   locals
482
	     cmd     dd ?
483
	     offset  dd ?
484
		     dd ?
485
	     count   dd ?
486
	     buff    dd ?
487
		     db ?
488
	     name    dd ?
489
	   endl
164 serge 490
 
672 hidnplayr 491
	   xor eax, eax
492
	   mov ebx, [file_name]
493
	   mov ecx, [off]
494
	   mov edx, [bytes]
495
	   mov esi, [buffer]
164 serge 496
 
672 hidnplayr 497
	   mov [cmd], eax
498
	   mov [offset], ecx
499
	   mov [offset+4], eax
500
	   mov [count], edx
501
	   mov [buff], esi
502
	   mov byte [buff+4], al
503
	   mov [name], ebx
188 serge 504
 
672 hidnplayr 505
	   pushad
506
	   push eax
507
	   lea eax, [cmd]
508
	   call file_system_lfn
509
	   pop eax
510
	   popad
511
	   ret
188 serge 512
endp
513
 
363 serge 514
; description
515
;  allocate kernel memory and loads the specified file
516
;
517
; param
518
;  file_name= full path to file
519
;
520
; retval
521
;  eax= file image in kernel memory
522
;  ebx= size of file
523
;
524
; warging
525
;  You mast call kernel_free() to delete each file
526
;  loaded by the load_file() function
527
 
188 serge 528
align 4
529
proc load_file stdcall, file_name:dword
672 hidnplayr 530
	   locals
531
	     attr	dd ?
532
	     flags	dd ?
533
	     cr_time	dd ?
534
	     cr_date	dd ?
535
	     acc_time	dd ?
536
	     acc_date	dd ?
537
	     mod_time	dd ?
538
	     mod_date	dd ?
539
	     file_size	dd ?
188 serge 540
 
672 hidnplayr 541
	     file	dd ?
542
	     file2	dd ?
543
	   endl
188 serge 544
 
672 hidnplayr 545
	   push esi
546
	   push edi
662 serge 547
 
672 hidnplayr 548
	   lea eax, [attr]
549
	   stdcall get_fileinfo, [file_name], eax
550
	   test eax, eax
551
	   jnz .fail
164 serge 552
 
672 hidnplayr 553
	   mov eax, [file_size]
554
	   cmp eax, 1024*1024*16
555
	   ja .fail
206 serge 556
 
672 hidnplayr 557
	   stdcall kernel_alloc, [file_size]
558
	   mov [file], eax
164 serge 559
 
672 hidnplayr 560
	   stdcall read_file, [file_name], eax, dword 0, [file_size]
561
	   cmp ebx, [file_size]
562
	   jne .cleanup
211 serge 563
 
672 hidnplayr 564
	   mov eax, [file]
565
	   cmp dword [eax], 0x4B43504B
566
	   jne .exit
567
	   mov ebx, [eax+4]
568
	   mov [file_size], ebx
569
	   stdcall kernel_alloc, ebx
211 serge 570
 
672 hidnplayr 571
	   test eax, eax
572
	   jz .cleanup
211 serge 573
 
672 hidnplayr 574
	   mov [file2], eax
575
	   stdcall unpack, [file], eax
576
	   stdcall kernel_free, [file]
577
	   mov eax, [file2]
578
	   mov ebx, [file_size]
211 serge 579
.exit:
672 hidnplayr 580
	   push eax
581
	   lea edi, [eax+ebx]	  ;cleanup remain space
582
	   mov ecx, 4096	  ;from file end
583
	   and ebx, 4095
584
	   jz  @f
585
	   sub ecx, ebx
586
	   xor eax, eax
587
	   cld
588
	   rep stosb
521 diamond 589
@@:
672 hidnplayr 590
	   mov ebx, [file_size]
591
	   pop eax
592
	   pop edi
593
	   pop esi
594
	   ret
188 serge 595
.cleanup:
672 hidnplayr 596
	   stdcall kernel_free, [file]
188 serge 597
.fail:
672 hidnplayr 598
	   xor eax, eax
599
	   xor ebx, ebx
600
	   pop edi
601
	   pop esi
602
	   ret
188 serge 603
endp
164 serge 604
 
188 serge 605
align 4
606
proc get_proc_ex stdcall, proc_name:dword, imports:dword
607
 
608
.look_up:
672 hidnplayr 609
	   mov edx, [imports]
610
	   test edx, edx
611
	   jz .end
612
	   mov edx, [edx]
613
	   test edx, edx
614
	   jz .end
188 serge 615
.next:
672 hidnplayr 616
	   mov eax, [edx]
617
	   test eax, eax
618
	   jz .next_table
164 serge 619
 
672 hidnplayr 620
	   push edx
621
	   stdcall strncmp, eax, [proc_name], 16
622
	   pop edx
623
	   test eax, eax
624
	   jz .ok
164 serge 625
 
672 hidnplayr 626
	   add edx,8
627
	   jmp .next
188 serge 628
.next_table:
672 hidnplayr 629
	   add [imports], 4
630
	   jmp .look_up
188 serge 631
.ok:
672 hidnplayr 632
	   mov eax, [edx+4]
633
	   ret
188 serge 634
.end:
672 hidnplayr 635
	   xor eax, eax
636
	   ret
188 serge 637
endp
164 serge 638
 
188 serge 639
align 4
640
proc fix_coff_symbols stdcall, sec:dword, symbols:dword,\
672 hidnplayr 641
		      sym_count:dword, strings:dword, imports:dword
642
	   locals
643
	     retval dd ?
644
	   endl
164 serge 645
 
672 hidnplayr 646
	   mov edi, [symbols]
647
	   mov [retval], 1
188 serge 648
.fix:
672 hidnplayr 649
	   movzx ebx, [edi+CSYM.SectionNumber]
650
	   test ebx, ebx
651
	   jnz .internal
652
	   mov eax, dword [edi+CSYM.Name]
653
	   test eax, eax
654
	   jnz @F
164 serge 655
 
672 hidnplayr 656
	   mov edi, [edi+4]
657
	   add edi, [strings]
188 serge 658
@@:
672 hidnplayr 659
	   push edi
660
	   stdcall get_proc_ex, edi,[imports]
661
	   pop edi
164 serge 662
 
672 hidnplayr 663
	   xor ebx, ebx
664
	   test eax, eax
665
	   jnz @F
164 serge 666
 
672 hidnplayr 667
	   mov esi, msg_unresolved
668
	   call sys_msg_board_str
669
	   mov esi, edi
670
	   call sys_msg_board_str
671
	   mov esi, msg_CR
672
	   call sys_msg_board_str
164 serge 673
 
672 hidnplayr 674
	   mov [retval],0
188 serge 675
@@:
672 hidnplayr 676
	   mov edi, [symbols]
677
	   mov [edi+CSYM.Value], eax
678
	   jmp .next
188 serge 679
.internal:
672 hidnplayr 680
	   cmp bx, -1
681
	   je .next
682
	   cmp bx, -2
683
	   je .next
541 serge 684
 
672 hidnplayr 685
	   dec ebx
686
	   shl ebx, 3
687
	   lea ebx, [ebx+ebx*4]
688
	   add ebx, [sec]
188 serge 689
 
672 hidnplayr 690
	   mov eax, [ebx+CFS.VirtualAddress]
691
	   add [edi+CSYM.Value], eax
188 serge 692
.next:
672 hidnplayr 693
	   add edi, CSYM_SIZE
694
	   mov [symbols], edi
695
	   dec [sym_count]
696
	   jnz .fix
697
	   mov eax, [retval]
698
	   ret
164 serge 699
endp
700
 
701
align 4
188 serge 702
proc fix_coff_relocs stdcall, coff:dword, sec:dword, sym:dword
164 serge 703
	   locals
672 hidnplayr 704
	     n_sec     dd ?
164 serge 705
	   endl
706
 
672 hidnplayr 707
	   mov eax, [coff]
708
	   movzx ebx, [eax+CFH.nSections]
709
	   mov [n_sec], ebx
188 serge 710
.fix_sec:
672 hidnplayr 711
	   mov esi, [sec]
164 serge 712
	   mov edi, [esi+CFS.PtrReloc]
672 hidnplayr 713
	   add edi, [coff]
164 serge 714
 
672 hidnplayr 715
	   movzx ecx, [esi+CFS.NumReloc]
716
	   test ecx, ecx
717
	   jz .next
188 serge 718
.next_reloc:
164 serge 719
	   mov ebx, [edi+CRELOC.SymIndex]
720
	   add ebx,ebx
721
	   lea ebx,[ebx+ebx*8]
672 hidnplayr 722
	   add ebx, [sym]
164 serge 723
 
672 hidnplayr 724
	   mov edx, [ebx+CSYM.Value]
164 serge 725
 
672 hidnplayr 726
	   cmp [edi+CRELOC.Type], 6
727
	   je .dir_32
164 serge 728
 
672 hidnplayr 729
	   cmp [edi+CRELOC.Type], 20
730
	   jne .next_reloc
188 serge 731
.rel_32:
164 serge 732
	   mov eax, [edi+CRELOC.VirtualAddress]
672 hidnplayr 733
	   add eax, [esi+CFS.VirtualAddress]
734
	   sub edx, eax
735
	   sub edx, 4
736
	   jmp .fix
188 serge 737
.dir_32:
738
	   mov eax, [edi+CRELOC.VirtualAddress]
672 hidnplayr 739
	   add eax, [esi+CFS.VirtualAddress]
188 serge 740
.fix:
672 hidnplayr 741
	   add [eax], edx
742
	   add edi, 10
743
	   dec ecx
744
	   jnz .next_reloc
188 serge 745
.next:
672 hidnplayr 746
	   add [sec], COFF_SECTION_SIZE
747
	   dec [n_sec]
748
	   jnz .fix_sec
164 serge 749
.exit:
750
	   ret
751
endp
752
 
188 serge 753
align 4
346 diamond 754
proc load_driver stdcall, driver_name:dword
672 hidnplayr 755
	   locals
756
	     coff      dd ?
757
	     sym       dd ?
758
	     strings   dd ?
759
	     img_size  dd ?
760
	     img_base  dd ?
761
	     start     dd ?
188 serge 762
 
672 hidnplayr 763
	     exports   dd ?   ;fake exports table
764
		       dd ?
765
	     file_name rb 13+16+4+1	 ; '/sys/drivers/.obj'
766
	   endl
188 serge 767
 
672 hidnplayr 768
	   lea	   edx, [file_name]
769
	   mov	   dword [edx], '/sys'
770
	   mov	   dword [edx+4], '/dri'
771
	   mov	   dword [edx+8], 'vers'
772
	   mov	   byte [edx+12], '/'
773
	   mov	   esi, [driver_name]
774
	   lea	   edi, [edx+13]
775
	   mov	   ecx, 16
346 diamond 776
@@:
672 hidnplayr 777
	   lodsb
778
	   test    al, al
779
	   jz	   @f
780
	   stosb
781
	   loop    @b
346 diamond 782
@@:
672 hidnplayr 783
	   mov	   dword [edi], '.obj'
784
	   mov	   byte [edi+4], 0
785
	   stdcall load_file, edx
214 serge 786
 
672 hidnplayr 787
	   test eax, eax
788
	   jz .exit
188 serge 789
 
672 hidnplayr 790
	   mov [coff], eax
188 serge 791
 
672 hidnplayr 792
	   movzx ecx, [eax+CFH.nSections]
793
	   xor ebx, ebx
188 serge 794
 
672 hidnplayr 795
	   lea edx, [eax+20]
188 serge 796
@@:
672 hidnplayr 797
	   add ebx, [edx+CFS.SizeOfRawData]
798
	   add ebx, 15
799
	   and ebx, not 15
800
	   add edx, COFF_SECTION_SIZE
801
	   dec ecx
802
	   jnz @B
803
	   mov [img_size], ebx
188 serge 804
 
672 hidnplayr 805
	   stdcall kernel_alloc, ebx
806
	   test eax, eax
807
	   jz .fail
808
	   mov [img_base], eax
188 serge 809
 
672 hidnplayr 810
	   mov edi, eax
811
	   xor eax, eax
812
	   mov ecx, [img_size]
813
	   add ecx, 4095
814
	   and ecx, not 4095
815
	   shr ecx, 2
816
	   cld
817
	   rep stosd
188 serge 818
 
672 hidnplayr 819
	   mov edx, [coff]
820
	   movzx ebx, [edx+CFH.nSections]
821
	   mov edi, [img_base]
822
	   lea eax, [edx+20]
188 serge 823
@@:
672 hidnplayr 824
	   mov [eax+CFS.VirtualAddress], edi
825
	   mov esi, [eax+CFS.PtrRawData]
826
	   test esi, esi
827
	   jnz .copy
828
	   add edi, [eax+CFS.SizeOfRawData]
829
	   jmp .next
188 serge 830
.copy:
672 hidnplayr 831
	   add esi, edx
832
	   mov ecx, [eax+CFS.SizeOfRawData]
833
	   cld
834
	   rep movsb
188 serge 835
.next:
672 hidnplayr 836
	   add edi, 15
837
	   and edi, not 15
838
	   add eax, COFF_SECTION_SIZE
839
	   dec ebx
840
	   jnz @B
188 serge 841
 
672 hidnplayr 842
	   mov ebx, [edx+CFH.pSymTable]
843
	   add ebx, edx
844
	   mov [sym], ebx
845
	   mov ecx, [edx+CFH.nSymbols]
846
	   add ecx,ecx
847
	   lea ecx,[ecx+ecx*8] ;ecx*=18 = nSymbols*CSYM_SIZE
848
	   add ecx, [sym]
849
	   mov [strings], ecx
188 serge 850
 
672 hidnplayr 851
	   lea ebx, [exports]
852
	   mov dword [ebx], kernel_export
853
	   mov dword [ebx+4], 0
854
	   lea eax, [edx+20]
188 serge 855
 
672 hidnplayr 856
	   stdcall fix_coff_symbols, eax, [sym], [edx+CFH.nSymbols],\
857
				     [strings], ebx
858
	   test eax, eax
859
	   jz .link_fail
188 serge 860
 
672 hidnplayr 861
	   mov ebx, [coff]
862
	   add ebx, 20
863
	   stdcall fix_coff_relocs, [coff], ebx, [sym]
188 serge 864
 
672 hidnplayr 865
	   mov ebx, [coff]
866
	   stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],szVersion
867
	   test eax, eax
868
	   jz .link_fail
227 serge 869
 
672 hidnplayr 870
	   mov eax, [eax]
871
	   shr eax, 16
872
	   cmp eax, DRV_COMPAT
873
	   jb .ver_fail
227 serge 874
 
672 hidnplayr 875
	   cmp eax, DRV_CURRENT
876
	   ja .ver_fail
227 serge 877
 
672 hidnplayr 878
	   mov ebx, [coff]
879
	   stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],szSTART
880
	   mov [start], eax
188 serge 881
 
672 hidnplayr 882
	   stdcall kernel_free, [coff]
188 serge 883
 
672 hidnplayr 884
	   mov ebx, [start]
885
	   stdcall ebx, DRV_ENTRY
886
	   test eax, eax
887
	   jnz .ok
188 serge 888
 
672 hidnplayr 889
	   stdcall kernel_free, [img_base]
890
	   xor eax, eax
891
	   ret
188 serge 892
.ok:
672 hidnplayr 893
	   mov ebx, [img_base]
894
	   mov [eax+SRV.base], ebx
895
	   mov ecx, [start]
896
	   mov [eax+SRV.entry], ecx
897
	   ret
227 serge 898
 
899
.ver_fail:
672 hidnplayr 900
	   mov esi, msg_CR
901
	   call sys_msg_board_str
902
	   mov esi, [driver_name]
903
	   call sys_msg_board_str
904
	   mov esi, msg_CR
905
	   call sys_msg_board_str
906
	   mov esi, msg_version
907
	   call sys_msg_board_str
908
	   mov esi, msg_www
909
	   call sys_msg_board_str
910
	   jmp .cleanup
227 serge 911
 
912
.link_fail:
672 hidnplayr 913
	   mov esi, msg_module
914
	   call sys_msg_board_str
915
	   mov esi, [driver_name]
916
	   call sys_msg_board_str
917
	   mov esi, msg_CR
918
	   call sys_msg_board_str
227 serge 919
.cleanup:
672 hidnplayr 920
	   stdcall kernel_free,[img_base]
188 serge 921
.fail:
672 hidnplayr 922
	   stdcall kernel_free, [coff]
227 serge 923
.exit:
672 hidnplayr 924
	   xor eax, eax
925
	   ret
164 serge 926
endp
927
 
198 serge 928
align 4
929
proc load_library stdcall, file_name:dword
672 hidnplayr 930
	   locals
931
	     coff      dd ?
932
	     sym       dd ?
933
	     strings   dd ?
934
	     img_size  dd ?
935
	     img_base  dd ?
936
	     exports   dd ?
937
	   endl
198 serge 938
 
672 hidnplayr 939
	   cli
198 serge 940
 
672 hidnplayr 941
	   stdcall load_file, [file_name]
942
	   test eax, eax
943
	   jz .fail
198 serge 944
 
672 hidnplayr 945
	   mov [coff], eax
946
	   movzx ecx, [eax+CFH.nSections]
947
	   xor ebx, ebx
198 serge 948
 
672 hidnplayr 949
	   lea edx, [eax+20]
198 serge 950
@@:
672 hidnplayr 951
	   add ebx, [edx+CFS.SizeOfRawData]
952
	   add ebx, 15
953
	   and ebx, not 15
954
	   add edx, COFF_SECTION_SIZE
955
	   dec ecx
956
	   jnz @B
957
	   mov [img_size], ebx
198 serge 958
 
672 hidnplayr 959
	   call init_heap
960
	   stdcall user_alloc, [img_size]
198 serge 961
 
672 hidnplayr 962
	   test eax, eax
963
	   jz .fail
964
	   mov [img_base], eax
198 serge 965
 
672 hidnplayr 966
	   mov edx, [coff]
967
	   movzx ebx, [edx+CFH.nSections]
968
	   mov edi, [img_base]
969
	   lea eax, [edx+20]
198 serge 970
@@:
672 hidnplayr 971
	   mov [eax+CFS.VirtualAddress], edi
972
	   mov esi, [eax+CFS.PtrRawData]
973
	   test esi, esi
974
	   jnz .copy
975
	   add edi, [eax+CFS.SizeOfRawData]
976
	   jmp .next
198 serge 977
.copy:
672 hidnplayr 978
	   add esi, edx
465 serge 979
    ;       add edi, new_app_base
672 hidnplayr 980
	   mov ecx, [eax+CFS.SizeOfRawData]
981
	   cld
982
	   rep movsb
198 serge 983
.next:
672 hidnplayr 984
	   add edi, 15 ;-new_app_base
985
	   and edi, -16
986
	   add eax, COFF_SECTION_SIZE
987
	   dec ebx
988
	   jnz @B
198 serge 989
 
672 hidnplayr 990
	   mov ebx, [edx+CFH.pSymTable]
991
	   add ebx, edx
992
	   mov [sym], ebx
993
	   mov ecx, [edx+CFH.nSymbols]
994
	   add ecx,ecx
995
	   lea ecx,[ecx+ecx*8] ;ecx*=18 = nSymbols*CSYM_SIZE
996
	   add ecx, [sym]
997
	   mov [strings], ecx
198 serge 998
 
672 hidnplayr 999
	   lea eax, [edx+20]
198 serge 1000
 
672 hidnplayr 1001
	   stdcall fix_coff_symbols, eax, [sym], [edx+CFH.nSymbols],\
1002
				     [strings], dword 0
1003
	   test eax, eax
1004
	   jnz @F
198 serge 1005
 
1006
@@:
672 hidnplayr 1007
	   mov edx, [coff]
1008
	   movzx ebx, [edx+CFH.nSections]
1009
	   mov edi, new_app_base
1010
	   lea eax, [edx+20]
198 serge 1011
@@:
672 hidnplayr 1012
	   add [eax+CFS.VirtualAddress], edi  ;patch user space offset
1013
	   add eax, COFF_SECTION_SIZE
1014
	   dec ebx
1015
	   jnz @B
198 serge 1016
 
672 hidnplayr 1017
	   add edx, 20
1018
	   stdcall fix_coff_relocs, [coff], edx, [sym]
198 serge 1019
 
672 hidnplayr 1020
	   mov ebx, [coff]
1021
	   stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],szEXPORTS
1022
	   mov [exports], eax
198 serge 1023
 
672 hidnplayr 1024
	   stdcall kernel_free, [coff]
1025
	   mov eax, [exports]
1026
	   ret
198 serge 1027
.fail:
672 hidnplayr 1028
	   xor eax, eax
1029
	   ret
198 serge 1030
endp
1031
 
214 serge 1032
align 4
1033
proc stop_all_services
278 serge 1034
 
672 hidnplayr 1035
	   mov edx, [srv.fd]
214 serge 1036
.next:
672 hidnplayr 1037
	   cmp edx,  srv.fd-SRV_FD_OFFSET
1038
	   je .done
1039
	   cmp [edx+SRV.magic], ' SRV'
1040
	   jne .next
1041
	   cmp [edx+SRV.size], SRV_SIZE
1042
	   jne .next
732 serge 1043
 
1044
           mov ebx, [edx+SRV.entry]
672 hidnplayr 1045
	   mov edx, [edx+SRV.fd]
732 serge 1046
           test ebx, ebx
1047
           jz .next
1048
 
1049
           push edx
672 hidnplayr 1050
	   stdcall ebx, dword -1
1051
	   pop edx
1052
	   jmp .next
278 serge 1053
.done:
672 hidnplayr 1054
	   ret
214 serge 1055
endp
198 serge 1056
 
281 serge 1057
; param
291 serge 1058
;  eax= size
1059
;  ebx= pid
214 serge 1060
 
281 serge 1061
align 4
1062
create_kernel_object:
1063
 
672 hidnplayr 1064
	   push ebx
1065
	   call malloc
1066
	   pop ebx
1067
	   test eax, eax
1068
	   jz .fail
281 serge 1069
 
672 hidnplayr 1070
	   mov ecx,[current_slot]
1071
	   add ecx, APP_OBJ_OFFSET
281 serge 1072
 
672 hidnplayr 1073
	   pushfd
1074
	   cli
1075
	   mov edx, [ecx+APPOBJ.fd]
1076
	   mov [eax+APPOBJ.fd], edx
1077
	   mov [eax+APPOBJ.bk], ecx
1078
	   mov [eax+APPOBJ.pid], ebx
281 serge 1079
 
672 hidnplayr 1080
	   mov [ecx+APPOBJ.fd], eax
1081
	   mov [edx+APPOBJ.bk], eax
1082
	   popfd
281 serge 1083
.fail:
672 hidnplayr 1084
	   ret
281 serge 1085
 
1086
; param
1087
;  eax= object
1088
 
1089
align 4
1090
destroy_kernel_object:
1091
 
672 hidnplayr 1092
	   pushfd
1093
	   cli
1094
	   mov ebx, [eax+APPOBJ.fd]
1095
	   mov ecx, [eax+APPOBJ.bk]
1096
	   mov [ebx+APPOBJ.bk], ecx
1097
	   mov [ecx+APPOBJ.fd], ebx
1098
	   popfd
281 serge 1099
 
672 hidnplayr 1100
	   xor edx, edx        ;clear common header
1101
	   mov [eax], edx
1102
	   mov [eax+4], edx
1103
	   mov [eax+8], edx
1104
	   mov [eax+12], edx
1105
	   mov [eax+16], edx
281 serge 1106
 
672 hidnplayr 1107
	   call free	       ;release object memory
1108
	   ret
281 serge 1109
 
1110
 
164 serge 1111
 
465 serge 1112
if 0
164 serge 1113
 
465 serge 1114
irq:
188 serge 1115
 
465 serge 1116
.irq0:
672 hidnplayr 1117
	   pusfd
1118
	   pushad
1119
	   push IRQ_0
1120
	   jmp .master
465 serge 1121
.irq_1:
672 hidnplayr 1122
	   pusfd
1123
	   pushad
1124
	   push IRQ_1
1125
	   jmp .master
465 serge 1126
 
1127
.master:
672 hidnplayr 1128
	   mov ax, app_data
1129
	   mov ds, eax
1130
	   mov es, eax
1131
	   mov ebx, [esp+4]  ;IRQ_xx
1132
	   mov eax, [irq_handlers+ebx+4]
1133
	   call intr_handler
1134
	   mov ecx, [esp+4]
1135
	   cmp [irq_actids+ecx*4], 0
1136
	   je @F
1137
	   in al, 0x21
1138
	   bts eax, ecx
1139
	   out 0x21, al
1140
	   mov al, 0x20
1141
	   out 0x20, al
1142
	   jmp .restart
465 serge 1143
 
1144
.slave:
672 hidnplayr 1145
	   mov ax, app_data
1146
	   mov ds, eax
1147
	   mov es, eax
1148
	   mov ebx, [esp+4]  ;IRQ_xx
1149
	   mov eax, [irq_handlers+ebx+4]
1150
	   call intr_handler
1151
	   mov ecx, [esp+4]
1152
	   sub ecx, 8
1153
	   cmp [irq_actids+ecx*4], 0
1154
	   je @F
1155
	   in al, 0xA1
1156
	   bts eax, ecx
1157
	   out 0xA1, al
1158
	   mov al, 0x20
1159
	   out 0xA0, al
1160
	   out 0x20, al
465 serge 1161
.restart:
672 hidnplayr 1162
	   mov ebx, [next_slot]
1163
	   test ebx, ebx
1164
	   jz @F
1165
	   mov [next_task],0
1166
	   mov esi, [prev_slot]
1167
	   call do_change_task
1168
	   add esp, 4
1169
	   iretd
465 serge 1170
 
1171
end if
1172