2007-03-26 14:18:08 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2008-02-04 16:31:59 +01:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
|
2007-03-26 14:18:08 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2006-11-20 08:06:00 +01:00
|
|
|
|
2007-07-27 15:52:03 +02:00
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
DRV_COMPAT equ 5 ;minimal required drivers version
|
|
|
|
DRV_CURRENT equ 5 ;current drivers model version
|
2006-12-02 09:18:48 +01:00
|
|
|
|
|
|
|
DRV_VERSION equ (DRV_COMPAT shl 16) or DRV_CURRENT
|
2008-05-02 09:27:54 +02:00
|
|
|
PID_KERNEL equ 1 ;os_idle thread
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
align 4
|
2008-03-18 18:19:08 +01:00
|
|
|
proc attach_int_handler stdcall, irq:dword, handler:dword, access_rights:dword
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2008-06-09 14:12:09 +02:00
|
|
|
mov ebx, [irq] ;irq num
|
2008-03-13 21:23:15 +01:00
|
|
|
test ebx, ebx
|
|
|
|
jz .err
|
2008-06-09 14:12:09 +02:00
|
|
|
cmp ebx, 15 ; hidnplayr says: we only have 16 IRQ's
|
2008-03-13 21:23:15 +01:00
|
|
|
ja .err
|
|
|
|
mov eax, [handler]
|
|
|
|
test eax, eax
|
|
|
|
jz .err
|
|
|
|
cmp [irq_owner + 4 * ebx], 0
|
2008-03-18 18:19:08 +01:00
|
|
|
je @f
|
|
|
|
|
2008-06-09 14:12:09 +02:00
|
|
|
mov ecx, [irq_rights + 4 * ebx] ; Rights : 0 - full access, 1 - read only, 2 - forbidden
|
2008-03-18 18:19:08 +01:00
|
|
|
test ecx, ecx
|
|
|
|
jnz .err
|
|
|
|
|
2008-06-09 14:12:09 +02:00
|
|
|
@@:
|
2008-03-13 21:23:15 +01:00
|
|
|
mov [irq_tab+ebx*4], eax
|
|
|
|
|
2008-03-18 18:19:08 +01:00
|
|
|
mov eax, [access_rights]
|
|
|
|
mov [irq_rights + 4 * ebx], eax
|
|
|
|
|
2008-06-09 14:12:09 +02:00
|
|
|
mov [irq_owner + 4 * ebx], PID_KERNEL ; all handlers belong to a kernel
|
2008-03-13 21:23:15 +01:00
|
|
|
|
|
|
|
stdcall enable_irq, [irq]
|
2008-06-09 14:12:09 +02:00
|
|
|
mov eax, 1
|
2008-03-13 21:23:15 +01:00
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
.err:
|
2008-03-13 21:23:15 +01:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
2008-03-18 18:19:08 +01:00
|
|
|
uglobal
|
|
|
|
|
|
|
|
irq_rights rd 16
|
|
|
|
|
|
|
|
endg
|
|
|
|
|
|
|
|
proc get_int_handler stdcall, irq:dword
|
|
|
|
|
|
|
|
mov eax, [irq]
|
|
|
|
|
|
|
|
cmp [irq_rights + 4 * eax], dword 1
|
|
|
|
ja .err
|
|
|
|
|
|
|
|
mov eax, [irq_tab + 4 * eax]
|
|
|
|
ret
|
|
|
|
|
|
|
|
.err:
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
|
|
|
|
endp
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
align 4
|
|
|
|
proc detach_int_handler
|
|
|
|
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc enable_irq stdcall, irq_line:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ebx, [irq_line]
|
|
|
|
mov edx, 0x21
|
|
|
|
cmp ebx, 8
|
|
|
|
jb @F
|
|
|
|
mov edx, 0xA1
|
|
|
|
sub ebx,8
|
2006-10-06 08:09:41 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
in al,dx
|
|
|
|
btr eax, ebx
|
|
|
|
out dx, al
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
align 16
|
|
|
|
;; proc irq_serv
|
|
|
|
|
|
|
|
irq_serv:
|
|
|
|
|
|
|
|
.irq_1:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 1
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_2:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 2
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_3:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 3
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_4:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 4
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_5:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 5
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_6:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 6
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_7:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 7
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_8:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 8
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_9:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 9
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_10:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 10
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_11:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 11
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_12:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 12
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_13:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 13
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_14:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 14
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
align 4
|
|
|
|
.irq_15:
|
2008-03-13 21:23:15 +01:00
|
|
|
push 15
|
2006-10-06 08:09:41 +02:00
|
|
|
jmp .main
|
|
|
|
|
|
|
|
align 16
|
|
|
|
.main:
|
|
|
|
save_ring3_context
|
2008-03-13 21:23:15 +01:00
|
|
|
mov eax, [esp + 32]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov bx, app_data ;os_data
|
2006-10-06 08:09:41 +02:00
|
|
|
mov ds, bx
|
|
|
|
mov es, bx
|
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
cmp [v86_irqhooks+eax*8], 0
|
|
|
|
jnz v86_irq
|
2008-02-04 16:31:59 +01:00
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
mov ebx, [irq_tab+eax*4]
|
|
|
|
test ebx, ebx
|
|
|
|
jz .exit
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
call ebx
|
|
|
|
mov [check_idle_semaphore],5
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
.exit:
|
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
cmp dword [esp + 32], 8
|
2006-10-06 08:09:41 +02:00
|
|
|
mov al, 0x20
|
2007-11-15 20:43:35 +01:00
|
|
|
jb @f
|
2006-10-06 08:09:41 +02:00
|
|
|
out 0xa0, al
|
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
out 0x20, al
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
restore_ring3_context
|
|
|
|
add esp, 4
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
iret
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc get_notify stdcall, p_ev:dword
|
|
|
|
|
|
|
|
.wait:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ebx,[current_slot]
|
|
|
|
test dword [ebx+APPDATA.event_mask],EVENT_NOTIFY
|
2006-10-06 08:09:41 +02:00
|
|
|
jz @f
|
2007-11-15 20:43:35 +01:00
|
|
|
and dword [ebx+APPDATA.event_mask], not EVENT_NOTIFY
|
2006-10-06 08:09:41 +02:00
|
|
|
mov edi, [p_ev]
|
|
|
|
mov dword [edi], EV_INTR
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [ebx+APPDATA.event]
|
2006-10-06 08:09:41 +02:00
|
|
|
mov dword [edi+4], eax
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
call change_task
|
|
|
|
jmp .wait
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc pci_read32 stdcall, bus:dword, devfn:dword, reg:dword
|
2008-03-13 21:23:15 +01:00
|
|
|
push ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
mov ah, byte [bus]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov al, 6
|
2006-10-06 08:09:41 +02:00
|
|
|
mov bh, byte [devfn]
|
|
|
|
mov bl, byte [reg]
|
|
|
|
call pci_read_reg
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2007-06-27 01:33:43 +02:00
|
|
|
align 4
|
|
|
|
proc pci_read16 stdcall, bus:dword, devfn:dword, reg:dword
|
2008-03-13 21:23:15 +01:00
|
|
|
push ebx
|
2007-06-27 01:33:43 +02:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
mov ah, byte [bus]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov al, 5
|
2007-06-27 01:33:43 +02:00
|
|
|
mov bh, byte [devfn]
|
|
|
|
mov bl, byte [reg]
|
|
|
|
call pci_read_reg
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
2007-06-27 01:33:43 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
align 4
|
|
|
|
proc pci_read8 stdcall, bus:dword, devfn:dword, reg:dword
|
2008-03-13 21:23:15 +01:00
|
|
|
push ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
mov ah, byte [bus]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov al, 4
|
2006-10-06 08:09:41 +02:00
|
|
|
mov bh, byte [devfn]
|
|
|
|
mov bl, byte [reg]
|
|
|
|
call pci_read_reg
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc pci_write8 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
|
2008-03-13 21:23:15 +01:00
|
|
|
push ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
mov ah, byte [bus]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov al, 8
|
2006-10-06 08:09:41 +02:00
|
|
|
mov bh, byte [devfn]
|
|
|
|
mov bl, byte [reg]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ecx, [val]
|
|
|
|
call pci_write_reg
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
2006-10-06 08:09:41 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2007-06-27 01:33:43 +02:00
|
|
|
align 4
|
|
|
|
proc pci_write16 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
|
2008-03-13 21:23:15 +01:00
|
|
|
push ebx
|
2007-06-27 01:33:43 +02:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
mov ah, byte [bus]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov al, 9
|
2007-06-27 01:33:43 +02:00
|
|
|
mov bh, byte [devfn]
|
|
|
|
mov bl, byte [reg]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ecx, [val]
|
|
|
|
call pci_write_reg
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
2007-06-27 01:33:43 +02:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
align 4
|
|
|
|
proc pci_write32 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
|
2008-03-13 21:23:15 +01:00
|
|
|
push ebx
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
mov ah, byte [bus]
|
|
|
|
mov al, 10
|
|
|
|
mov bh, byte [devfn]
|
|
|
|
mov bl, byte [reg]
|
|
|
|
mov ecx, [val]
|
|
|
|
call pci_write_reg
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
2007-11-15 20:43:35 +01:00
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
handle equ IOCTL.handle
|
|
|
|
io_code equ IOCTL.io_code
|
|
|
|
input equ IOCTL.input
|
|
|
|
inp_size equ IOCTL.inp_size
|
|
|
|
output equ IOCTL.output
|
|
|
|
out_size equ IOCTL.out_size
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc srv_handler stdcall, ioctl:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
mov esi, [ioctl]
|
|
|
|
test esi, esi
|
|
|
|
jz .err
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edi, [esi+handle]
|
|
|
|
cmp [edi+SRV.magic], ' SRV'
|
2006-10-06 08:09:41 +02:00
|
|
|
jne .fail
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp [edi+SRV.size], SRV_SIZE
|
2006-10-06 08:09:41 +02:00
|
|
|
jne .fail
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall [edi+SRV.srv_proc], esi
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
.fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
not eax
|
|
|
|
mov [esi+output], eax
|
|
|
|
mov [esi+out_size], 4
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
.err:
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
not eax
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
2007-02-26 13:40:37 +01:00
|
|
|
; param
|
|
|
|
; ebx= io_control
|
|
|
|
;
|
|
|
|
; retval
|
|
|
|
; eax= error code
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
align 4
|
2007-02-26 13:40:37 +01:00
|
|
|
srv_handlerEx:
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp ebx, OS_BASE
|
|
|
|
jae .fail
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [ebx+handle]
|
|
|
|
cmp [eax+SRV.magic], ' SRV'
|
2006-10-06 08:09:41 +02:00
|
|
|
jne .fail
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp [eax+SRV.size], SRV_SIZE
|
2006-10-06 08:09:41 +02:00
|
|
|
jne .fail
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall [eax+SRV.srv_proc], ebx
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
.fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
or eax, -1
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
restore handle
|
|
|
|
restore io_code
|
|
|
|
restore input
|
|
|
|
restore inp_size
|
|
|
|
restore output
|
|
|
|
restore out_size
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc get_service stdcall, sz_name:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [sz_name]
|
|
|
|
test eax, eax
|
|
|
|
jnz @F
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [srv.fd]
|
2006-10-20 16:02:26 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp edx, srv.fd-SRV_FD_OFFSET
|
|
|
|
je .not_load
|
2007-01-18 03:06:00 +01:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall strncmp, edx, [sz_name], 16
|
|
|
|
test eax, eax
|
|
|
|
je .ok
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [edx+SRV.fd]
|
|
|
|
jmp @B
|
2006-10-06 08:09:41 +02:00
|
|
|
.not_load:
|
2007-11-15 20:43:35 +01:00
|
|
|
pop ebp
|
|
|
|
jmp load_driver
|
2006-10-06 08:09:41 +02:00
|
|
|
.ok:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, edx
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
2008-02-15 17:15:47 +01:00
|
|
|
proc reg_service stdcall, name:dword, handler:dword
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2008-07-04 22:44:53 +02:00
|
|
|
push ebx
|
|
|
|
|
|
|
|
xor eax, eax
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
cmp [name], eax
|
|
|
|
je .fail
|
2008-02-15 17:15:47 +01:00
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
cmp [handler], eax
|
|
|
|
je .fail
|
2008-02-15 17:15:47 +01:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, SRV_SIZE
|
|
|
|
call malloc ;call alloc_service
|
2006-10-06 08:09:41 +02:00
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
push esi
|
|
|
|
push edi
|
2006-10-06 08:09:41 +02:00
|
|
|
mov edi, eax
|
2008-03-13 21:23:15 +01:00
|
|
|
mov esi, [name]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ecx, 16/4
|
|
|
|
rep movsd
|
2008-03-13 21:23:15 +01:00
|
|
|
pop edi
|
|
|
|
pop esi
|
2007-11-15 20:43:35 +01:00
|
|
|
|
|
|
|
mov [eax+SRV.magic], ' SRV'
|
|
|
|
mov [eax+SRV.size], SRV_SIZE
|
|
|
|
|
|
|
|
mov ebx, srv.fd-SRV_FD_OFFSET
|
|
|
|
mov edx, [ebx+SRV.fd]
|
|
|
|
mov [eax+SRV.fd], edx
|
|
|
|
mov [eax+SRV.bk], ebx
|
|
|
|
mov [ebx+SRV.fd], eax
|
|
|
|
mov [edx+SRV.bk], eax
|
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
mov ecx, [handler]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov [eax+SRV.srv_proc], ecx
|
2008-03-13 21:23:15 +01:00
|
|
|
pop ebx
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
.fail:
|
|
|
|
xor eax, eax
|
2008-07-04 22:44:53 +02:00
|
|
|
pop ebx
|
2008-03-13 21:23:15 +01:00
|
|
|
ret
|
2008-02-15 17:15:47 +01:00
|
|
|
endp
|
2006-10-06 08:09:41 +02:00
|
|
|
|
|
|
|
align 4
|
|
|
|
proc get_proc stdcall, exp:dword, sz_name:dword
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [exp]
|
2006-10-06 08:09:41 +02:00
|
|
|
.next:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [edx]
|
|
|
|
test eax, eax
|
|
|
|
jz .end
|
|
|
|
|
|
|
|
push edx
|
|
|
|
stdcall strncmp, eax, [sz_name], 16
|
|
|
|
pop edx
|
|
|
|
test eax, eax
|
|
|
|
jz .ok
|
|
|
|
|
|
|
|
add edx,8
|
|
|
|
jmp .next
|
2006-10-06 08:09:41 +02:00
|
|
|
.ok:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [edx+4]
|
2006-10-06 08:09:41 +02:00
|
|
|
.end:
|
2007-11-15 20:43:35 +01:00
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc get_coff_sym stdcall, pSym:dword,count:dword, sz_sym:dword
|
|
|
|
|
|
|
|
@@:
|
|
|
|
stdcall strncmp, [pSym], [sz_sym], 8
|
|
|
|
test eax,eax
|
|
|
|
jz .ok
|
|
|
|
add [pSym], 18
|
|
|
|
dec [count]
|
|
|
|
jnz @b
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
.ok:
|
|
|
|
mov ebx, [pSym]
|
|
|
|
mov eax, [ebx+8]
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
2006-10-20 16:02:26 +02:00
|
|
|
proc get_curr_task
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax,[CURRENT_TASK]
|
|
|
|
shl eax, 8
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
endp
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
align 4
|
|
|
|
proc get_fileinfo stdcall, file_name:dword, info:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
locals
|
|
|
|
cmd dd ?
|
|
|
|
offset dd ?
|
|
|
|
dd ?
|
|
|
|
count dd ?
|
|
|
|
buff dd ?
|
|
|
|
db ?
|
|
|
|
name dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov ebx, [file_name]
|
|
|
|
mov ecx, [info]
|
|
|
|
|
|
|
|
mov [cmd], 5
|
|
|
|
mov [offset], eax
|
|
|
|
mov [offset+4], eax
|
|
|
|
mov [count], eax
|
|
|
|
mov [buff], ecx
|
|
|
|
mov byte [buff+4], al
|
|
|
|
mov [name], ebx
|
|
|
|
|
|
|
|
mov eax, 70
|
|
|
|
lea ebx, [cmd]
|
|
|
|
int 0x40
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
endp
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
align 4
|
|
|
|
proc read_file stdcall,file_name:dword, buffer:dword, off:dword,\
|
2007-11-15 20:43:35 +01:00
|
|
|
bytes:dword
|
|
|
|
locals
|
|
|
|
cmd dd ?
|
|
|
|
offset dd ?
|
|
|
|
dd ?
|
|
|
|
count dd ?
|
|
|
|
buff dd ?
|
|
|
|
db ?
|
|
|
|
name dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov ebx, [file_name]
|
|
|
|
mov ecx, [off]
|
|
|
|
mov edx, [bytes]
|
|
|
|
mov esi, [buffer]
|
|
|
|
|
|
|
|
mov [cmd], eax
|
|
|
|
mov [offset], ecx
|
|
|
|
mov [offset+4], eax
|
|
|
|
mov [count], edx
|
|
|
|
mov [buff], esi
|
|
|
|
mov byte [buff+4], al
|
|
|
|
mov [name], ebx
|
|
|
|
|
|
|
|
pushad
|
|
|
|
push eax
|
|
|
|
lea eax, [cmd]
|
|
|
|
call file_system_lfn
|
|
|
|
pop eax
|
|
|
|
popad
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
endp
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-02-19 09:22:55 +01:00
|
|
|
; description
|
|
|
|
; allocate kernel memory and loads the specified file
|
|
|
|
;
|
|
|
|
; param
|
|
|
|
; file_name= full path to file
|
|
|
|
;
|
|
|
|
; retval
|
|
|
|
; eax= file image in kernel memory
|
|
|
|
; ebx= size of file
|
|
|
|
;
|
|
|
|
; warging
|
|
|
|
; You mast call kernel_free() to delete each file
|
|
|
|
; loaded by the load_file() function
|
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
align 4
|
|
|
|
proc load_file stdcall, file_name:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
locals
|
|
|
|
attr dd ?
|
|
|
|
flags dd ?
|
|
|
|
cr_time dd ?
|
|
|
|
cr_date dd ?
|
|
|
|
acc_time dd ?
|
|
|
|
acc_date dd ?
|
|
|
|
mod_time dd ?
|
|
|
|
mod_date dd ?
|
|
|
|
file_size dd ?
|
|
|
|
|
|
|
|
file dd ?
|
|
|
|
file2 dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
push esi
|
|
|
|
push edi
|
|
|
|
|
|
|
|
lea eax, [attr]
|
|
|
|
stdcall get_fileinfo, [file_name], eax
|
|
|
|
test eax, eax
|
|
|
|
jnz .fail
|
|
|
|
|
|
|
|
mov eax, [file_size]
|
|
|
|
cmp eax, 1024*1024*16
|
|
|
|
ja .fail
|
|
|
|
|
|
|
|
stdcall kernel_alloc, [file_size]
|
|
|
|
mov [file], eax
|
|
|
|
|
|
|
|
stdcall read_file, [file_name], eax, dword 0, [file_size]
|
|
|
|
cmp ebx, [file_size]
|
|
|
|
jne .cleanup
|
|
|
|
|
|
|
|
mov eax, [file]
|
|
|
|
cmp dword [eax], 0x4B43504B
|
|
|
|
jne .exit
|
|
|
|
mov ebx, [eax+4]
|
|
|
|
mov [file_size], ebx
|
|
|
|
stdcall kernel_alloc, ebx
|
|
|
|
|
|
|
|
test eax, eax
|
|
|
|
jz .cleanup
|
|
|
|
|
|
|
|
mov [file2], eax
|
|
|
|
stdcall unpack, [file], eax
|
|
|
|
stdcall kernel_free, [file]
|
|
|
|
mov eax, [file2]
|
|
|
|
mov ebx, [file_size]
|
2006-11-16 06:47:31 +01:00
|
|
|
.exit:
|
2007-11-15 20:43:35 +01:00
|
|
|
push eax
|
|
|
|
lea edi, [eax+ebx] ;cleanup remain space
|
|
|
|
mov ecx, 4096 ;from file end
|
|
|
|
and ebx, 4095
|
|
|
|
jz @f
|
|
|
|
sub ecx, ebx
|
|
|
|
xor eax, eax
|
|
|
|
cld
|
|
|
|
rep stosb
|
2007-05-24 13:27:05 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ebx, [file_size]
|
|
|
|
pop eax
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
.cleanup:
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall kernel_free, [file]
|
2006-10-20 16:02:26 +02:00
|
|
|
.fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
xor ebx, ebx
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
endp
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
align 4
|
|
|
|
proc get_proc_ex stdcall, proc_name:dword, imports:dword
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
.look_up:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [imports]
|
|
|
|
test edx, edx
|
|
|
|
jz .end
|
|
|
|
mov edx, [edx]
|
|
|
|
test edx, edx
|
|
|
|
jz .end
|
2006-10-20 16:02:26 +02:00
|
|
|
.next:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [edx]
|
|
|
|
test eax, eax
|
|
|
|
jz .next_table
|
|
|
|
|
|
|
|
push edx
|
|
|
|
stdcall strncmp, eax, [proc_name], 16
|
|
|
|
pop edx
|
|
|
|
test eax, eax
|
|
|
|
jz .ok
|
|
|
|
|
|
|
|
add edx,8
|
|
|
|
jmp .next
|
2006-10-20 16:02:26 +02:00
|
|
|
.next_table:
|
2007-11-15 20:43:35 +01:00
|
|
|
add [imports], 4
|
|
|
|
jmp .look_up
|
2006-10-20 16:02:26 +02:00
|
|
|
.ok:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [edx+4]
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
.end:
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
endp
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
align 4
|
|
|
|
proc fix_coff_symbols stdcall, sec:dword, symbols:dword,\
|
2007-11-15 20:43:35 +01:00
|
|
|
sym_count:dword, strings:dword, imports:dword
|
|
|
|
locals
|
|
|
|
retval dd ?
|
|
|
|
endl
|
2006-10-20 16:02:26 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edi, [symbols]
|
|
|
|
mov [retval], 1
|
2006-10-20 16:02:26 +02:00
|
|
|
.fix:
|
2007-11-15 20:43:35 +01:00
|
|
|
movzx ebx, [edi+CSYM.SectionNumber]
|
|
|
|
test ebx, ebx
|
|
|
|
jnz .internal
|
|
|
|
mov eax, dword [edi+CSYM.Name]
|
|
|
|
test eax, eax
|
|
|
|
jnz @F
|
|
|
|
|
|
|
|
mov edi, [edi+4]
|
|
|
|
add edi, [strings]
|
2006-10-20 16:02:26 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
push edi
|
|
|
|
stdcall get_proc_ex, edi,[imports]
|
|
|
|
pop edi
|
|
|
|
|
|
|
|
xor ebx, ebx
|
|
|
|
test eax, eax
|
|
|
|
jnz @F
|
|
|
|
|
|
|
|
mov esi, msg_unresolved
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, edi
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, msg_CR
|
|
|
|
call sys_msg_board_str
|
|
|
|
|
|
|
|
mov [retval],0
|
2006-10-20 16:02:26 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edi, [symbols]
|
|
|
|
mov [edi+CSYM.Value], eax
|
|
|
|
jmp .next
|
2006-10-20 16:02:26 +02:00
|
|
|
.internal:
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp bx, -1
|
|
|
|
je .next
|
|
|
|
cmp bx, -2
|
|
|
|
je .next
|
|
|
|
|
|
|
|
dec ebx
|
|
|
|
shl ebx, 3
|
|
|
|
lea ebx, [ebx+ebx*4]
|
|
|
|
add ebx, [sec]
|
|
|
|
|
|
|
|
mov eax, [ebx+CFS.VirtualAddress]
|
|
|
|
add [edi+CSYM.Value], eax
|
2006-10-20 16:02:26 +02:00
|
|
|
.next:
|
2007-11-15 20:43:35 +01:00
|
|
|
add edi, CSYM_SIZE
|
|
|
|
mov [symbols], edi
|
|
|
|
dec [sym_count]
|
|
|
|
jnz .fix
|
|
|
|
mov eax, [retval]
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
|
|
|
align 4
|
2006-10-20 16:02:26 +02:00
|
|
|
proc fix_coff_relocs stdcall, coff:dword, sec:dword, sym:dword
|
2006-10-06 08:09:41 +02:00
|
|
|
locals
|
2007-11-15 20:43:35 +01:00
|
|
|
n_sec dd ?
|
2006-10-06 08:09:41 +02:00
|
|
|
endl
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov eax, [coff]
|
|
|
|
movzx ebx, [eax+CFH.nSections]
|
|
|
|
mov [n_sec], ebx
|
2006-10-20 16:02:26 +02:00
|
|
|
.fix_sec:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov esi, [sec]
|
2006-10-06 08:09:41 +02:00
|
|
|
mov edi, [esi+CFS.PtrReloc]
|
2007-11-15 20:43:35 +01:00
|
|
|
add edi, [coff]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
movzx ecx, [esi+CFS.NumReloc]
|
|
|
|
test ecx, ecx
|
|
|
|
jz .next
|
2006-10-20 16:02:26 +02:00
|
|
|
.next_reloc:
|
2006-10-06 08:09:41 +02:00
|
|
|
mov ebx, [edi+CRELOC.SymIndex]
|
|
|
|
add ebx,ebx
|
|
|
|
lea ebx,[ebx+ebx*8]
|
2007-11-15 20:43:35 +01:00
|
|
|
add ebx, [sym]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [ebx+CSYM.Value]
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp [edi+CRELOC.Type], 6
|
|
|
|
je .dir_32
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp [edi+CRELOC.Type], 20
|
|
|
|
jne .next_reloc
|
2006-10-20 16:02:26 +02:00
|
|
|
.rel_32:
|
2006-10-06 08:09:41 +02:00
|
|
|
mov eax, [edi+CRELOC.VirtualAddress]
|
2007-11-15 20:43:35 +01:00
|
|
|
add eax, [esi+CFS.VirtualAddress]
|
|
|
|
sub edx, eax
|
|
|
|
sub edx, 4
|
|
|
|
jmp .fix
|
2006-10-20 16:02:26 +02:00
|
|
|
.dir_32:
|
|
|
|
mov eax, [edi+CRELOC.VirtualAddress]
|
2007-11-15 20:43:35 +01:00
|
|
|
add eax, [esi+CFS.VirtualAddress]
|
2006-10-20 16:02:26 +02:00
|
|
|
.fix:
|
2007-11-15 20:43:35 +01:00
|
|
|
add [eax], edx
|
|
|
|
add edi, 10
|
|
|
|
dec ecx
|
|
|
|
jnz .next_reloc
|
2006-10-20 16:02:26 +02:00
|
|
|
.next:
|
2007-11-15 20:43:35 +01:00
|
|
|
add [sec], COFF_SECTION_SIZE
|
|
|
|
dec [n_sec]
|
|
|
|
jnz .fix_sec
|
2006-10-06 08:09:41 +02:00
|
|
|
.exit:
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
align 4
|
2007-02-14 17:01:07 +01:00
|
|
|
proc load_driver stdcall, driver_name:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
locals
|
|
|
|
coff dd ?
|
|
|
|
sym dd ?
|
|
|
|
strings dd ?
|
|
|
|
img_size dd ?
|
|
|
|
img_base dd ?
|
|
|
|
start dd ?
|
|
|
|
|
|
|
|
exports dd ? ;fake exports table
|
|
|
|
dd ?
|
|
|
|
file_name rb 13+16+4+1 ; '/sys/drivers/<up-to-16-chars>.obj'
|
|
|
|
endl
|
|
|
|
|
|
|
|
lea edx, [file_name]
|
|
|
|
mov dword [edx], '/sys'
|
|
|
|
mov dword [edx+4], '/dri'
|
|
|
|
mov dword [edx+8], 'vers'
|
|
|
|
mov byte [edx+12], '/'
|
|
|
|
mov esi, [driver_name]
|
|
|
|
lea edi, [edx+13]
|
|
|
|
mov ecx, 16
|
2007-02-14 17:01:07 +01:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
lodsb
|
|
|
|
test al, al
|
|
|
|
jz @f
|
|
|
|
stosb
|
|
|
|
loop @b
|
2007-02-14 17:01:07 +01:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov dword [edi], '.obj'
|
|
|
|
mov byte [edi+4], 0
|
|
|
|
stdcall load_file, edx
|
2006-11-20 08:06:00 +01:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
test eax, eax
|
|
|
|
jz .exit
|
2006-10-20 16:02:26 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov [coff], eax
|
2006-10-20 16:02:26 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
movzx ecx, [eax+CFH.nSections]
|
|
|
|
xor ebx, ebx
|
2006-10-20 16:02:26 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
lea edx, [eax+20]
|
2006-10-20 16:02:26 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
add ebx, [edx+CFS.SizeOfRawData]
|
|
|
|
add ebx, 15
|
|
|
|
and ebx, not 15
|
|
|
|
add edx, COFF_SECTION_SIZE
|
|
|
|
dec ecx
|
|
|
|
jnz @B
|
|
|
|
mov [img_size], ebx
|
|
|
|
|
|
|
|
stdcall kernel_alloc, ebx
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
mov [img_base], eax
|
|
|
|
|
|
|
|
mov edi, eax
|
|
|
|
xor eax, eax
|
|
|
|
mov ecx, [img_size]
|
|
|
|
add ecx, 4095
|
|
|
|
and ecx, not 4095
|
|
|
|
shr ecx, 2
|
|
|
|
cld
|
|
|
|
rep stosd
|
|
|
|
|
|
|
|
mov edx, [coff]
|
|
|
|
movzx ebx, [edx+CFH.nSections]
|
|
|
|
mov edi, [img_base]
|
|
|
|
lea eax, [edx+20]
|
2006-10-20 16:02:26 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov [eax+CFS.VirtualAddress], edi
|
|
|
|
mov esi, [eax+CFS.PtrRawData]
|
|
|
|
test esi, esi
|
|
|
|
jnz .copy
|
|
|
|
add edi, [eax+CFS.SizeOfRawData]
|
|
|
|
jmp .next
|
2006-10-20 16:02:26 +02:00
|
|
|
.copy:
|
2007-11-15 20:43:35 +01:00
|
|
|
add esi, edx
|
|
|
|
mov ecx, [eax+CFS.SizeOfRawData]
|
|
|
|
cld
|
|
|
|
rep movsb
|
2006-10-20 16:02:26 +02:00
|
|
|
.next:
|
2007-11-15 20:43:35 +01:00
|
|
|
add edi, 15
|
|
|
|
and edi, not 15
|
|
|
|
add eax, COFF_SECTION_SIZE
|
|
|
|
dec ebx
|
|
|
|
jnz @B
|
|
|
|
|
|
|
|
mov ebx, [edx+CFH.pSymTable]
|
|
|
|
add ebx, edx
|
|
|
|
mov [sym], ebx
|
|
|
|
mov ecx, [edx+CFH.nSymbols]
|
|
|
|
add ecx,ecx
|
|
|
|
lea ecx,[ecx+ecx*8] ;ecx*=18 = nSymbols*CSYM_SIZE
|
|
|
|
add ecx, [sym]
|
|
|
|
mov [strings], ecx
|
|
|
|
|
|
|
|
lea ebx, [exports]
|
|
|
|
mov dword [ebx], kernel_export
|
|
|
|
mov dword [ebx+4], 0
|
|
|
|
lea eax, [edx+20]
|
|
|
|
|
|
|
|
stdcall fix_coff_symbols, eax, [sym], [edx+CFH.nSymbols],\
|
|
|
|
[strings], ebx
|
|
|
|
test eax, eax
|
|
|
|
jz .link_fail
|
|
|
|
|
|
|
|
mov ebx, [coff]
|
|
|
|
add ebx, 20
|
|
|
|
stdcall fix_coff_relocs, [coff], ebx, [sym]
|
|
|
|
|
|
|
|
mov ebx, [coff]
|
|
|
|
stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],szVersion
|
|
|
|
test eax, eax
|
|
|
|
jz .link_fail
|
|
|
|
|
|
|
|
mov eax, [eax]
|
|
|
|
shr eax, 16
|
|
|
|
cmp eax, DRV_COMPAT
|
|
|
|
jb .ver_fail
|
|
|
|
|
|
|
|
cmp eax, DRV_CURRENT
|
|
|
|
ja .ver_fail
|
|
|
|
|
|
|
|
mov ebx, [coff]
|
|
|
|
stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],szSTART
|
|
|
|
mov [start], eax
|
|
|
|
|
|
|
|
stdcall kernel_free, [coff]
|
|
|
|
|
|
|
|
mov ebx, [start]
|
|
|
|
stdcall ebx, DRV_ENTRY
|
|
|
|
test eax, eax
|
|
|
|
jnz .ok
|
|
|
|
|
|
|
|
stdcall kernel_free, [img_base]
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
2006-10-20 16:02:26 +02:00
|
|
|
.ok:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ebx, [img_base]
|
|
|
|
mov [eax+SRV.base], ebx
|
|
|
|
mov ecx, [start]
|
|
|
|
mov [eax+SRV.entry], ecx
|
|
|
|
ret
|
2006-12-02 09:18:48 +01:00
|
|
|
|
|
|
|
.ver_fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov esi, msg_CR
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, [driver_name]
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, msg_CR
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, msg_version
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, msg_www
|
|
|
|
call sys_msg_board_str
|
|
|
|
jmp .cleanup
|
2006-12-02 09:18:48 +01:00
|
|
|
|
|
|
|
.link_fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov esi, msg_module
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, [driver_name]
|
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, msg_CR
|
|
|
|
call sys_msg_board_str
|
2006-12-02 09:18:48 +01:00
|
|
|
.cleanup:
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall kernel_free,[img_base]
|
2006-10-20 16:02:26 +02:00
|
|
|
.fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall kernel_free, [coff]
|
2006-12-02 09:18:48 +01:00
|
|
|
.exit:
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2006-10-06 08:09:41 +02:00
|
|
|
endp
|
|
|
|
|
2006-10-27 17:08:19 +02:00
|
|
|
align 4
|
|
|
|
proc load_library stdcall, file_name:dword
|
2007-11-15 20:43:35 +01:00
|
|
|
locals
|
|
|
|
coff dd ?
|
|
|
|
sym dd ?
|
|
|
|
strings dd ?
|
|
|
|
img_size dd ?
|
|
|
|
img_base dd ?
|
|
|
|
exports dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
cli
|
|
|
|
|
|
|
|
stdcall load_file, [file_name]
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
mov [coff], eax
|
|
|
|
movzx ecx, [eax+CFH.nSections]
|
|
|
|
xor ebx, ebx
|
|
|
|
|
|
|
|
lea edx, [eax+20]
|
2006-10-27 17:08:19 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
add ebx, [edx+CFS.SizeOfRawData]
|
|
|
|
add ebx, 15
|
|
|
|
and ebx, not 15
|
|
|
|
add edx, COFF_SECTION_SIZE
|
|
|
|
dec ecx
|
|
|
|
jnz @B
|
|
|
|
mov [img_size], ebx
|
|
|
|
|
|
|
|
call init_heap
|
|
|
|
stdcall user_alloc, [img_size]
|
|
|
|
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
mov [img_base], eax
|
|
|
|
|
|
|
|
mov edx, [coff]
|
|
|
|
movzx ebx, [edx+CFH.nSections]
|
|
|
|
mov edi, [img_base]
|
|
|
|
lea eax, [edx+20]
|
2006-10-27 17:08:19 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov [eax+CFS.VirtualAddress], edi
|
|
|
|
mov esi, [eax+CFS.PtrRawData]
|
|
|
|
test esi, esi
|
|
|
|
jnz .copy
|
|
|
|
add edi, [eax+CFS.SizeOfRawData]
|
|
|
|
jmp .next
|
2006-10-27 17:08:19 +02:00
|
|
|
.copy:
|
2007-11-15 20:43:35 +01:00
|
|
|
add esi, edx
|
2007-04-18 08:37:14 +02:00
|
|
|
; add edi, new_app_base
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ecx, [eax+CFS.SizeOfRawData]
|
|
|
|
cld
|
|
|
|
rep movsb
|
2006-10-27 17:08:19 +02:00
|
|
|
.next:
|
2007-11-15 20:43:35 +01:00
|
|
|
add edi, 15 ;-new_app_base
|
|
|
|
and edi, -16
|
|
|
|
add eax, COFF_SECTION_SIZE
|
|
|
|
dec ebx
|
|
|
|
jnz @B
|
|
|
|
|
|
|
|
mov ebx, [edx+CFH.pSymTable]
|
|
|
|
add ebx, edx
|
|
|
|
mov [sym], ebx
|
|
|
|
mov ecx, [edx+CFH.nSymbols]
|
|
|
|
add ecx,ecx
|
|
|
|
lea ecx,[ecx+ecx*8] ;ecx*=18 = nSymbols*CSYM_SIZE
|
|
|
|
add ecx, [sym]
|
|
|
|
mov [strings], ecx
|
|
|
|
|
|
|
|
lea eax, [edx+20]
|
|
|
|
|
|
|
|
stdcall fix_coff_symbols, eax, [sym], [edx+CFH.nSymbols],\
|
|
|
|
[strings], dword 0
|
|
|
|
test eax, eax
|
|
|
|
jnz @F
|
2006-10-27 17:08:19 +02:00
|
|
|
|
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [coff]
|
|
|
|
movzx ebx, [edx+CFH.nSections]
|
|
|
|
mov edi, new_app_base
|
|
|
|
lea eax, [edx+20]
|
2006-10-27 17:08:19 +02:00
|
|
|
@@:
|
2007-11-15 20:43:35 +01:00
|
|
|
add [eax+CFS.VirtualAddress], edi ;patch user space offset
|
|
|
|
add eax, COFF_SECTION_SIZE
|
|
|
|
dec ebx
|
|
|
|
jnz @B
|
2006-10-27 17:08:19 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
add edx, 20
|
|
|
|
stdcall fix_coff_relocs, [coff], edx, [sym]
|
2006-10-27 17:08:19 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ebx, [coff]
|
|
|
|
stdcall get_coff_sym,[sym],[ebx+CFH.nSymbols],szEXPORTS
|
|
|
|
mov [exports], eax
|
2006-10-27 17:08:19 +02:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall kernel_free, [coff]
|
|
|
|
mov eax, [exports]
|
|
|
|
ret
|
2006-10-27 17:08:19 +02:00
|
|
|
.fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2006-10-27 17:08:19 +02:00
|
|
|
endp
|
|
|
|
|
2006-11-20 08:06:00 +01:00
|
|
|
align 4
|
|
|
|
proc stop_all_services
|
2007-01-18 03:06:00 +01:00
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [srv.fd]
|
2006-11-20 08:06:00 +01:00
|
|
|
.next:
|
2007-11-15 20:43:35 +01:00
|
|
|
cmp edx, srv.fd-SRV_FD_OFFSET
|
|
|
|
je .done
|
|
|
|
cmp [edx+SRV.magic], ' SRV'
|
|
|
|
jne .next
|
|
|
|
cmp [edx+SRV.size], SRV_SIZE
|
|
|
|
jne .next
|
2008-02-11 13:24:57 +01:00
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
mov ebx, [edx+SRV.entry]
|
2007-11-15 20:43:35 +01:00
|
|
|
mov edx, [edx+SRV.fd]
|
2008-03-13 21:23:15 +01:00
|
|
|
test ebx, ebx
|
|
|
|
jz .next
|
2008-02-11 13:24:57 +01:00
|
|
|
|
2008-03-13 21:23:15 +01:00
|
|
|
push edx
|
2007-11-15 20:43:35 +01:00
|
|
|
stdcall ebx, dword -1
|
|
|
|
pop edx
|
|
|
|
jmp .next
|
2007-01-18 03:06:00 +01:00
|
|
|
.done:
|
2007-11-15 20:43:35 +01:00
|
|
|
ret
|
2006-11-20 08:06:00 +01:00
|
|
|
endp
|
|
|
|
|
2007-01-19 04:58:46 +01:00
|
|
|
; param
|
2007-01-23 15:55:03 +01:00
|
|
|
; eax= size
|
|
|
|
; ebx= pid
|
2007-01-19 04:58:46 +01:00
|
|
|
|
|
|
|
align 4
|
|
|
|
create_kernel_object:
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
push ebx
|
|
|
|
call malloc
|
|
|
|
pop ebx
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
|
|
|
|
mov ecx,[current_slot]
|
|
|
|
add ecx, APP_OBJ_OFFSET
|
|
|
|
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
mov edx, [ecx+APPOBJ.fd]
|
|
|
|
mov [eax+APPOBJ.fd], edx
|
|
|
|
mov [eax+APPOBJ.bk], ecx
|
|
|
|
mov [eax+APPOBJ.pid], ebx
|
|
|
|
|
|
|
|
mov [ecx+APPOBJ.fd], eax
|
|
|
|
mov [edx+APPOBJ.bk], eax
|
|
|
|
popfd
|
2007-01-19 04:58:46 +01:00
|
|
|
.fail:
|
2007-11-15 20:43:35 +01:00
|
|
|
ret
|
2007-01-19 04:58:46 +01:00
|
|
|
|
|
|
|
; param
|
|
|
|
; eax= object
|
|
|
|
|
|
|
|
align 4
|
|
|
|
destroy_kernel_object:
|
|
|
|
|
2007-11-15 20:43:35 +01:00
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
mov ebx, [eax+APPOBJ.fd]
|
|
|
|
mov ecx, [eax+APPOBJ.bk]
|
|
|
|
mov [ebx+APPOBJ.bk], ecx
|
|
|
|
mov [ecx+APPOBJ.fd], ebx
|
|
|
|
popfd
|
|
|
|
|
|
|
|
xor edx, edx ;clear common header
|
|
|
|
mov [eax], edx
|
|
|
|
mov [eax+4], edx
|
|
|
|
mov [eax+8], edx
|
|
|
|
mov [eax+12], edx
|
|
|
|
mov [eax+16], edx
|
|
|
|
|
|
|
|
call free ;release object memory
|
|
|
|
ret
|
2007-01-19 04:58:46 +01:00
|
|
|
|
2006-10-27 17:08:19 +02:00
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2007-04-18 08:37:14 +02:00
|
|
|
if 0
|
|
|
|
|
|
|
|
irq:
|
|
|
|
|
|
|
|
.irq0:
|
2007-11-15 20:43:35 +01:00
|
|
|
pusfd
|
|
|
|
pushad
|
|
|
|
push IRQ_0
|
|
|
|
jmp .master
|
2007-04-18 08:37:14 +02:00
|
|
|
.irq_1:
|
2007-11-15 20:43:35 +01:00
|
|
|
pusfd
|
|
|
|
pushad
|
|
|
|
push IRQ_1
|
|
|
|
jmp .master
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
|
|
.master:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ax, app_data
|
|
|
|
mov ds, eax
|
|
|
|
mov es, eax
|
|
|
|
mov ebx, [esp+4] ;IRQ_xx
|
|
|
|
mov eax, [irq_handlers+ebx+4]
|
|
|
|
call intr_handler
|
|
|
|
mov ecx, [esp+4]
|
|
|
|
cmp [irq_actids+ecx*4], 0
|
|
|
|
je @F
|
|
|
|
in al, 0x21
|
|
|
|
bts eax, ecx
|
|
|
|
out 0x21, al
|
|
|
|
mov al, 0x20
|
|
|
|
out 0x20, al
|
|
|
|
jmp .restart
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
|
|
.slave:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ax, app_data
|
|
|
|
mov ds, eax
|
|
|
|
mov es, eax
|
|
|
|
mov ebx, [esp+4] ;IRQ_xx
|
|
|
|
mov eax, [irq_handlers+ebx+4]
|
|
|
|
call intr_handler
|
|
|
|
mov ecx, [esp+4]
|
|
|
|
sub ecx, 8
|
|
|
|
cmp [irq_actids+ecx*4], 0
|
|
|
|
je @F
|
|
|
|
in al, 0xA1
|
|
|
|
bts eax, ecx
|
|
|
|
out 0xA1, al
|
|
|
|
mov al, 0x20
|
|
|
|
out 0xA0, al
|
|
|
|
out 0x20, al
|
2007-04-18 08:37:14 +02:00
|
|
|
.restart:
|
2007-11-15 20:43:35 +01:00
|
|
|
mov ebx, [next_slot]
|
|
|
|
test ebx, ebx
|
|
|
|
jz @F
|
|
|
|
mov [next_task],0
|
|
|
|
mov esi, [prev_slot]
|
|
|
|
call do_change_task
|
|
|
|
add esp, 4
|
|
|
|
iretd
|
2007-04-18 08:37:14 +02:00
|
|
|
|
|
|
|
end if
|
|
|
|
|
|
|
|
|
2006-10-06 08:09:41 +02:00
|
|
|
|
2006-10-20 16:02:26 +02:00
|
|
|
|