Subversion Repositories Kolibri OS

Rev

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