Subversion Repositories Kolibri OS

Rev

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