Subversion Repositories Kolibri OS

Rev

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

Rev 3555 Rev 3908
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 8... Line 8...
8
$Revision: 3555 $
8
$Revision: 3908 $
9
 
9
 
Line 32... Line 32...
32
@@:
32
@@:
33
        call    change_task
33
        call    change_task
34
        jmp     .wait
34
        jmp     .wait
35
endp
35
endp
Line 36... Line -...
36
 
-
 
37
align 4
-
 
38
proc pci_read32 stdcall, bus:dword, devfn:dword, reg:dword
-
 
39
        push    ebx
-
 
40
        xor     eax, eax
-
 
41
        xor     ebx, ebx
-
 
42
        mov     ah, byte [bus]
-
 
43
        mov     al, 6
-
 
44
        mov     bh, byte [devfn]
-
 
45
        mov     bl, byte [reg]
-
 
46
        call    pci_read_reg
-
 
47
        pop     ebx
-
 
48
        ret
-
 
49
endp
-
 
50
 
-
 
51
align 4
-
 
52
proc pci_read16 stdcall, bus:dword, devfn:dword, reg:dword
-
 
53
        push    ebx
-
 
54
        xor     eax, eax
-
 
55
        xor     ebx, ebx
-
 
56
        mov     ah, byte [bus]
-
 
57
        mov     al, 5
-
 
58
        mov     bh, byte [devfn]
-
 
59
        mov     bl, byte [reg]
-
 
60
        call    pci_read_reg
-
 
61
        pop     ebx
-
 
62
        ret
-
 
63
endp
-
 
64
 
-
 
65
align 4
-
 
66
proc pci_read8 stdcall, bus:dword, devfn:dword, reg:dword
-
 
67
        push    ebx
-
 
68
        xor     eax, eax
-
 
69
        xor     ebx, ebx
-
 
70
        mov     ah, byte [bus]
-
 
71
        mov     al, 4
-
 
72
        mov     bh, byte [devfn]
-
 
73
        mov     bl, byte [reg]
-
 
74
        call    pci_read_reg
-
 
75
        pop     ebx
-
 
76
        ret
-
 
77
endp
-
 
78
 
-
 
79
align 4
-
 
80
proc pci_write8 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
-
 
81
        push    ebx
-
 
82
        xor     eax, eax
-
 
83
        xor     ebx, ebx
-
 
84
        mov     ah, byte [bus]
-
 
85
        mov     al, 8
-
 
86
        mov     bh, byte [devfn]
-
 
87
        mov     bl, byte [reg]
-
 
88
        mov     ecx, [val]
-
 
89
        call    pci_write_reg
-
 
90
        pop     ebx
-
 
91
        ret
-
 
92
endp
-
 
93
 
-
 
94
align 4
-
 
95
proc pci_write16 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
-
 
96
        push    ebx
-
 
97
        xor     eax, eax
-
 
98
        xor     ebx, ebx
-
 
99
        mov     ah, byte [bus]
-
 
100
        mov     al, 9
-
 
101
        mov     bh, byte [devfn]
-
 
102
        mov     bl, byte [reg]
-
 
103
        mov     ecx, [val]
-
 
104
        call    pci_write_reg
-
 
105
        pop     ebx
-
 
106
        ret
-
 
107
endp
-
 
108
 
-
 
109
align 4
-
 
110
proc pci_write32 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
-
 
111
        push    ebx
-
 
112
        xor     eax, eax
-
 
113
        xor     ebx, ebx
-
 
114
        mov     ah, byte [bus]
-
 
115
        mov     al, 10
-
 
116
        mov     bh, byte [devfn]
-
 
117
        mov     bl, byte [reg]
-
 
118
        mov     ecx, [val]
-
 
119
        call    pci_write_reg
-
 
120
        pop     ebx
-
 
121
        ret
-
 
Line 122... Line 36...
122
endp
36
 
123
 
37
 
124
handle     equ  IOCTL.handle
38
handle     equ  IOCTL.handle
125
io_code    equ  IOCTL.io_code
39
io_code    equ  IOCTL.io_code
Line 507... Line 421...
507
        pop     edi
421
        pop     edi
508
        pop     esi
422
        pop     esi
509
        ret
423
        ret
510
endp
424
endp
Line -... Line 425...
-
 
425
 
-
 
426
; description
-
 
427
;  allocate user memory and loads the specified file
-
 
428
;
-
 
429
; param
-
 
430
;  file_name= path to file
-
 
431
;
-
 
432
; retval
-
 
433
;  eax= file image in user memory
-
 
434
;  ebx= size of file
-
 
435
;
-
 
436
; warging
-
 
437
;  You mast call kernel_free() to delete each file
-
 
438
;  loaded by the load_file() function
-
 
439
 
-
 
440
align 4
-
 
441
proc load_file_umode stdcall, file_name:dword
-
 
442
           locals
-
 
443
             attr       dd ?
-
 
444
             flags      dd ?
-
 
445
             cr_time    dd ?
-
 
446
             cr_date    dd ?
-
 
447
             acc_time   dd ?
-
 
448
             acc_date   dd ?
-
 
449
             mod_time   dd ?
-
 
450
             mod_date   dd ?
-
 
451
             file_size  dd ?
-
 
452
 
-
 
453
             km_file    dd ?
-
 
454
             um_file    dd ?
-
 
455
           endl
-
 
456
 
-
 
457
        push    esi
-
 
458
        push    edi
-
 
459
        push    ebx
-
 
460
 
-
 
461
 
-
 
462
        lea     eax, [attr]
-
 
463
        stdcall get_fileinfo, [file_name], eax   ;find file and get info
-
 
464
        test    eax, eax
-
 
465
        jnz     .err_1
-
 
466
 
-
 
467
        mov     eax, [file_size]
-
 
468
        cmp     eax, 1024*1024*16                ;to be enough for anybody (c)
-
 
469
        ja      .err_1
-
 
470
                                                 ;it is very likely that the file is packed
-
 
471
        stdcall kernel_alloc, [file_size]        ;with kpack, so allocate memory from kernel heap
-
 
472
        mov     [km_file], eax
-
 
473
        test    eax, eax
-
 
474
        jz      .err_1
-
 
475
 
-
 
476
        stdcall read_file, [file_name], eax, dword 0, [file_size]
-
 
477
        cmp     ebx, [file_size]
-
 
478
 
-
 
479
        jne     .err_2
-
 
480
 
-
 
481
        mov     eax, [km_file]
-
 
482
        cmp     dword [eax], 0x4B43504B          ; check kpack signature
-
 
483
        jne     .raw_file
-
 
484
 
-
 
485
        mov     ebx, [eax+4]                     ;get real size of file
-
 
486
        mov     [file_size], ebx
-
 
487
        stdcall user_alloc, ebx                  ;and allocate memory from user heap
-
 
488
        mov     [um_file], eax
-
 
489
        test    eax, eax
-
 
490
        jz      .err_2
-
 
491
 
-
 
492
        pushad
-
 
493
        mov     ecx, unpack_mutex
-
 
494
        call    mutex_lock
-
 
495
 
-
 
496
        stdcall unpack, [km_file], [um_file]
-
 
497
 
-
 
498
        mov     ecx, unpack_mutex
-
 
499
        call    mutex_unlock
-
 
500
        popad
-
 
501
 
-
 
502
        stdcall kernel_free, [km_file]           ;we don't need packed file anymore
-
 
503
.exit:
-
 
504
        mov     eax, [um_file]
-
 
505
        mov     edx, [file_size]
-
 
506
 
-
 
507
        pop     ebx
-
 
508
        pop     edi
-
 
509
        pop     esi
-
 
510
        ret
-
 
511
 
-
 
512
 
-
 
513
.raw_file:                                       ; sometimes we load unpacked file
-
 
514
        stdcall user_alloc, ebx                  ; allocate space from user heap
-
 
515
        mov     [um_file], eax
-
 
516
 
-
 
517
        test    eax, eax
-
 
518
        jz      .err_2
-
 
519
 
-
 
520
        shr     eax, 10                          ; and remap pages.
-
 
521
 
-
 
522
        mov     ecx, [file_size]
-
 
523
        add     ecx, 4095
-
 
524
        shr     ecx, 12
-
 
525
 
-
 
526
        mov     esi, [km_file]
-
 
527
        shr     esi, 10
-
 
528
        add     esi, page_tabs
-
 
529
 
-
 
530
        lea     edi, [page_tabs+eax]
-
 
531
 
-
 
532
        cld
-
 
533
@@:
-
 
534
        lodsd
-
 
535
        and     eax, 0xFFFFF000
-
 
536
        or      eax, PG_USER
-
 
537
        stosd
-
 
538
        loop    @B
-
 
539
 
-
 
540
        stdcall free_kernel_space, [km_file]     ; release allocated kernel space
-
 
541
        jmp     .exit                            ; physical pages still in use
-
 
542
 
-
 
543
.err_2:
-
 
544
        stdcall kernel_free, [km_file]
-
 
545
.err_1:
-
 
546
        xor     eax, eax
-
 
547
        xor     edx, edx
-
 
548
 
-
 
549
        pop     ebx
-
 
550
        pop     edi
-
 
551
        pop     esi
-
 
552
        ret
-
 
553
endp
-
 
554
 
511
 
555
 
512
uglobal
556
uglobal
513
align 4
557
align 4
514
unpack_mutex MUTEX
558
unpack_mutex MUTEX
Line 515... Line 559...
515
endg
559
endg
516
 
560
 
517
align 4
-
 
518
proc get_proc_ex stdcall, proc_name:dword, imports:dword
-
 
519
 
561
align 4
520
.look_up:
-
 
521
        mov     edx, [imports]
-
 
522
        test    edx, edx
-
 
523
        jz      .end
562
proc get_proc_ex stdcall uses ebx esi, proc_name:dword, imports:dword
524
        mov     edx, [edx]
563
        mov     ebx, [imports]
525
        test    edx, edx
-
 
526
        jz      .end
564
        test    ebx, ebx
527
.next:
-
 
528
        mov     eax, [edx]
565
        jz      .end
Line -... Line 566...
-
 
566
        xor     esi, esi
-
 
567
.look_up:
529
        test    eax, eax
568
 
530
        jz      .next_table
569
        mov     eax, [ebx+32]
531
 
-
 
532
        push    edx
570
        mov     eax, [OS_BASE+eax+esi*4]
533
        stdcall strncmp, eax, [proc_name], 256
571
        add     eax, OS_BASE
Line 534... Line 572...
534
        pop     edx
572
        stdcall strncmp, eax, [proc_name], 256
535
        test    eax, eax
573
        test    eax, eax
536
        jz      .ok
-
 
537
 
-
 
538
        add     edx, 8
574
        jz      .ok
539
        jmp     .next
-
 
540
.next_table:
-
 
541
        add     [imports], 4
-
 
542
        jmp     .look_up
575
 
543
.ok:
576
        inc     esi
544
        mov     eax, [edx+4]
577
        cmp     esi, [ebx+24]
-
 
578
        jb      .look_up
-
 
579
.end:
-
 
580
        xor     eax, eax
-
 
581
        ret
-
 
582
.ok:
545
        ret
583
        mov     eax, [ebx+28]
Line 546... Line 584...
546
.end:
584
        mov     eax, [OS_BASE+eax+esi*4]
547
        xor     eax, eax
585
        add     eax, OS_BASE
548
        ret
586
        ret
Line 711... Line 749...
711
             strings   dd ?
749
             strings   dd ?
712
             img_size  dd ?
750
             img_size  dd ?
713
             img_base  dd ?
751
             img_base  dd ?
714
             start     dd ?
752
             start     dd ?
Line 715... Line -...
715
 
-
 
716
             exports   dd ?   ;fake exports table
-
 
717
                       dd ?
753
 
718
             file_name rb 13+16+4+1      ; '/sys/drivers/.obj'
754
             file_name rb 13+16+4+1      ; '/sys/drivers/.obj'
Line 719... Line 755...
719
           endl
755
           endl
720
 
756
 
Line 801... Line 837...
801
        add     ecx, ecx
837
        add     ecx, ecx
802
        lea     ecx, [ecx+ecx*8];ecx*=18 = nSymbols*CSYM_SIZE
838
        lea     ecx, [ecx+ecx*8];ecx*=18 = nSymbols*CSYM_SIZE
803
        add     ecx, [sym]
839
        add     ecx, [sym]
804
        mov     [strings], ecx
840
        mov     [strings], ecx
Line 805... Line -...
805
 
-
 
806
        lea     ebx, [exports]
-
 
807
        mov     dword [ebx], kernel_export
-
 
808
        mov     dword [ebx+4], 0
841
 
Line 809... Line 842...
809
        lea     eax, [edx+20]
842
        lea     eax, [edx+20]
810
 
843
 
811
        stdcall fix_coff_symbols, eax, [sym], [edx+COFF_HEADER.nSymbols], \
844
        stdcall fix_coff_symbols, eax, [sym], [edx+COFF_HEADER.nSymbols], \
812
                [strings], ebx
845
                [strings], __exports
Line 813... Line 846...
813
        test    eax, eax
846
        test    eax, eax
814
        jz      .link_fail
847
        jz      .link_fail
Line 909... Line 942...
909
             fileinfo  rb 40
942
             fileinfo  rb 40
910
             coff      dd ?
943
             coff      dd ?
911
             img_base  dd ?
944
             img_base  dd ?
912
           endl
945
           endl
Line 913... Line -...
913
 
-
 
914
        cli
-
 
915
 
946
 
916
; resolve file name
947
; resolve file name
917
        mov     ebx, [file_name]
948
        mov     ebx, [file_name]
918
        lea     edi, [fullname+1]
949
        lea     edi, [fullname+1]
919
        mov     byte [edi-1], '/'
950
        mov     byte [edi-1], '/'
920
        stdcall get_full_file_name, edi, 259
951
        stdcall get_full_file_name, edi, 259
921
        test    al, al
952
        test    al, al
Line 922... Line 953...
922
        jz      .fail
953
        jz      .fail
923
 
954
 
-
 
955
; scan for required DLL in list of already loaded for this process,
-
 
956
; ignore timestamp
924
; scan for required DLL in list of already loaded for this process,
957
        cli
925
; ignore timestamp
958
 
926
        mov     esi, [CURRENT_TASK]
959
        mov     esi, [CURRENT_TASK]
927
        shl     esi, 8
960
        shl     esi, 8
928
        lea     edi, [fullname]
961
        lea     edi, [fullname]
Line 944... Line 977...
944
        mov     ecx, [esi+HDLL.parent]
977
        mov     ecx, [esi+HDLL.parent]
945
        inc     [ecx+DLLDESCR.refcount]
978
        inc     [ecx+DLLDESCR.refcount]
946
        mov     eax, [ecx+DLLDESCR.exports]
979
        mov     eax, [ecx+DLLDESCR.exports]
947
        sub     eax, [ecx+DLLDESCR.defaultbase]
980
        sub     eax, [ecx+DLLDESCR.defaultbase]
948
        add     eax, [esi+HDLL.base]
981
        add     eax, [esi+HDLL.base]
-
 
982
        sti
949
        ret
983
        ret
950
.next_in_process:
984
.next_in_process:
951
        mov     esi, [esi+HDLL.fd]
985
        mov     esi, [esi+HDLL.fd]
952
        jmp     .scan_in_process
986
        jmp     .scan_in_process
953
.not_in_process:
987
.not_in_process:
Line 954... Line 988...
954
 
988
 
-
 
989
; scan in full list, compare timestamp
955
; scan in full list, compare timestamp
990
        sti
956
        lea     eax, [fileinfo]
991
        lea     eax, [fileinfo]
957
        stdcall get_fileinfo, edi, eax
992
        stdcall get_fileinfo, edi, eax
958
        test    eax, eax
993
        test    eax, eax
-
 
994
        jnz     .fail
959
        jnz     .fail
995
        cli
960
        mov     esi, [dll_list.fd]
996
        mov     esi, [dll_list.fd]
961
.scan_for_dlls:
997
.scan_for_dlls:
962
        cmp     esi, dll_list
998
        cmp     esi, dll_list
963
        jz      .load_new
999
        jz      .load_new
Line 976... Line 1012...
976
        mov     esi, [esi+DLLDESCR.fd]
1012
        mov     esi, [esi+DLLDESCR.fd]
977
        jmp     .scan_for_dlls
1013
        jmp     .scan_for_dlls
Line 978... Line 1014...
978
 
1014
 
979
; new DLL
1015
; new DLL
-
 
1016
.load_new:
980
.load_new:
1017
        sti
981
; load file
1018
; load file
982
        stdcall load_file, edi
1019
        stdcall load_file, edi
983
        test    eax, eax
1020
        test    eax, eax
984
        jz      .fail
1021
        jz      .fail
Line 1003... Line 1040...
1003
        mov     esi, eax
1040
        mov     esi, eax
1004
        mov     eax, dword [fileinfo+24]
1041
        mov     eax, dword [fileinfo+24]
1005
        mov     dword [esi+DLLDESCR.timestamp], eax
1042
        mov     dword [esi+DLLDESCR.timestamp], eax
1006
        mov     eax, dword [fileinfo+28]
1043
        mov     eax, dword [fileinfo+28]
1007
        mov     dword [esi+DLLDESCR.timestamp+4], eax
1044
        mov     dword [esi+DLLDESCR.timestamp+4], eax
1008
; initialize DLLDESCR struct
-
 
1009
        and     dword [esi+DLLDESCR.refcount], 0; no HDLLs yet; later it will be incremented
-
 
1010
        mov     [esi+DLLDESCR.fd], dll_list
-
 
1011
        mov     eax, [dll_list.bk]
-
 
1012
        mov     [dll_list.bk], esi
-
 
1013
        mov     [esi+DLLDESCR.bk], eax
-
 
1014
        mov     [eax+DLLDESCR.fd], esi
-
 
Line 1015... Line 1045...
1015
 
1045
 
1016
; calculate size of loaded DLL
1046
; calculate size of loaded DLL
1017
        mov     edx, [coff]
1047
        mov     edx, [coff]
1018
        movzx   ecx, [edx+COFF_HEADER.nSections]
1048
        movzx   ecx, [edx+COFF_HEADER.nSections]
Line 1179... Line 1209...
1179
        sub     eax, [esi+DLLDESCR.defaultbase]
1209
        sub     eax, [esi+DLLDESCR.defaultbase]
1180
        stdcall fix_coff_relocs, ebx, [esi+DLLDESCR.symbols_ptr], eax
1210
        stdcall fix_coff_relocs, ebx, [esi+DLLDESCR.symbols_ptr], eax
Line 1181... Line 1211...
1181
 
1211
 
Line -... Line 1212...
-
 
1212
        stdcall kernel_free, [coff]
-
 
1213
 
-
 
1214
        cli
-
 
1215
; initialize DLLDESCR struct
-
 
1216
        and     dword [esi+DLLDESCR.refcount], 0; no HDLLs yet; later it will be incremented
-
 
1217
        mov     [esi+DLLDESCR.fd], dll_list
-
 
1218
        mov     eax, [dll_list.bk]
-
 
1219
        mov     [dll_list.bk], esi
1182
        stdcall kernel_free, [coff]
1220
        mov     [esi+DLLDESCR.bk], eax
1183
 
1221
        mov     [eax+DLLDESCR.fd], esi
1184
.dll_already_loaded:
1222
.dll_already_loaded:
1185
        inc     [esi+DLLDESCR.refcount]
1223
        inc     [esi+DLLDESCR.refcount]
1186
        push    esi
1224
        push    esi
Line 1251... Line 1289...
1251
@@:
1289
@@:
Line 1252... Line 1290...
1252
 
1290
 
1253
        mov     eax, [esi+DLLDESCR.exports]
1291
        mov     eax, [esi+DLLDESCR.exports]
1254
        sub     eax, [esi+DLLDESCR.defaultbase]
1292
        sub     eax, [esi+DLLDESCR.defaultbase]
-
 
1293
        add     eax, [img_base]
1255
        add     eax, [img_base]
1294
        sti
1256
        ret
1295
        ret
1257
.fail_and_free_data:
1296
.fail_and_free_data:
1258
        stdcall kernel_free, [esi+DLLDESCR.data]
1297
        stdcall kernel_free, [esi+DLLDESCR.data]
1259
.fail_and_free_dll:
1298
.fail_and_free_dll:
Line 1267... Line 1306...
1267
.fail_and_free_user:
1306
.fail_and_free_user:
1268
        stdcall user_free, [img_base]
1307
        stdcall user_free, [img_base]
1269
.fail_and_dereference:
1308
.fail_and_dereference:
1270
        mov     eax, 1  ; delete 1 reference
1309
        mov     eax, 1  ; delete 1 reference
1271
        call    dereference_dll
1310
        call    dereference_dll
-
 
1311
        sti
1272
        xor     eax, eax
1312
        xor     eax, eax
1273
        ret
1313
        ret
1274
endp
1314
endp
Line 1275... Line 1315...
1275
 
1315