Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 2381 → Rev 2382

/kernel/branches/net/core/apic.inc
0,0 → 1,417
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
iglobal
IRQ_COUNT dd 24
endg
 
uglobal
irq_mode rd 1
IOAPIC_base rd 1
LAPIC_BASE rd 1
endg
 
APIC_ID equ 0x20
APIC_TPR equ 0x80
APIC_EOI equ 0xb0
APIC_LDR equ 0xd0
APIC_DFR equ 0xe0
APIC_SVR equ 0xf0
APIC_ISR equ 0x100
APIC_ESR equ 0x280
APIC_ICRL equ 0x300
APIC_ICRH equ 0x310
APIC_LVT_LINT0 equ 0x350
APIC_LVT_LINT1 equ 0x360
APIC_LVT_err equ 0x370
 
; APIC timer
APIC_LVT_timer equ 0x320
APIC_timer_div equ 0x3e0
APIC_timer_init equ 0x380
APIC_timer_cur equ 0x390
; IOAPIC
IOAPIC_ID equ 0x0
IOAPIC_VER equ 0x1
IOAPIC_ARB equ 0x2
IOAPIC_REDTBL equ 0x10
 
align 4
APIC_init:
mov [irq_mode], IRQ_PIC
 
cmp [acpi_ioapic_base], 0
jz .no_apic
 
cmp [acpi_lapic_base], 0
jz .no_apic
 
stdcall load_file, dev_data_path
test eax, eax
jz .no_apic
 
mov [acpi_dev_data], eax
mov [acpi_dev_size], ebx
 
call IRQ_mask_all
 
; IOAPIC init
stdcall map_io_mem, [acpi_ioapic_base], 0x20, PG_SW
mov [IOAPIC_base], eax
 
mov eax, IOAPIC_VER
call IOAPIC_read
shr eax, 16
inc al
movzx eax, al
cmp al, IRQ_RESERVED
jbe @f
 
mov al, IRQ_RESERVED
@@:
mov [IRQ_COUNT], eax
 
; Reroute IOAPIC & mask all interrupts
xor ecx, ecx
mov eax, IOAPIC_REDTBL
@@:
mov ebx, eax
call IOAPIC_read
mov ah, 0x09; Delivery Mode: Lowest Priority, Destination Mode: Logical
mov al, cl
add al, 0x20; vector
or eax, 0x10000; Mask Interrupt
cmp ecx, 16
jb .set
 
or eax, 0xa000;<<< level-triggered active-low for IRQ16+
.set:
xchg eax, ebx
call IOAPIC_write
inc eax
mov ebx, eax
call IOAPIC_read
or eax, 0xff000000; Destination Field
xchg eax, ebx
call IOAPIC_write
inc eax
inc ecx
cmp ecx, [IRQ_COUNT]
jb @b
 
call LAPIC_init
 
mov [irq_mode], IRQ_APIC
 
mov al, 0x70
out 0x22, al
mov al, 1
out 0x23, al
 
call pci_irq_fixup
.no_apic:
 
ret
 
;===========================================================
align 4
LAPIC_init:
; Check MSR support
;....
; Get LAPIC base address
; mov ecx, 0x1b
; rdmsr ; it may be replaced to
; and ax, 0xf000 ; mov eax, 0xfee00000
 
stdcall map_io_mem, [acpi_lapic_base], 0x1000, PG_SW
mov [LAPIC_BASE], eax
mov esi, eax
 
; Program Destination Format Register for Flat mode.
mov eax, [esi + APIC_DFR]
or eax, 0xf0000000
mov [esi + APIC_DFR], eax
 
; Program Logical Destination Register.
mov eax, [esi + APIC_LDR]
;and eax, 0xff000000
and eax, 0x00ffffff
or eax, 0x01000000;!!!!!!!!!!!!
mov [esi + APIC_LDR], eax
 
; Task Priority Register initialization.
mov eax, [esi + APIC_TPR]
and eax, 0xffffff00
mov [esi + APIC_TPR], eax
 
; Flush the queue
mov edx, 0
.nxt2:
mov ecx, 32
mov eax, [esi + APIC_ISR + edx]
.nxt:
shr eax, 1
jnc @f
mov dword [esi + APIC_EOI], 0; EOI
@@:
loop .nxt
 
add edx, 0x10
cmp edx, 0x170
jbe .nxt2
 
; Spurious-Interrupt Vector Register initialization.
mov eax, [esi + APIC_SVR]
or eax, 0x1ff
and eax, 0xfffffdff
mov [esi + APIC_SVR], eax
 
; Initialize LVT LINT0 register. (INTR)
mov eax, 0x00700
; mov eax, 0x10700
mov [esi + APIC_LVT_LINT0], eax
 
; Initialize LVT LINT1 register. (NMI)
mov eax, 0x00400
mov [esi + APIC_LVT_LINT1], eax
 
; Initialize LVT Error register.
mov eax, [esi + APIC_LVT_err]
or eax, 0x10000; bit 16
mov [esi + APIC_LVT_err], eax
 
; LAPIC timer
; pre init
mov dword[esi + APIC_timer_div], 1011b; 1
mov dword[esi + APIC_timer_init], 0xffffffff; max val
push esi
mov esi, 640 ; wait 0.64 sec
call delay_ms
pop esi
mov eax, [esi + APIC_timer_cur]; read current tick couner
xor eax, 0xffffffff ; eax = 0xffffffff - eax
shr eax, 6 ; eax /= 64; APIC ticks per 0.01 sec
 
; Start (every 0.01 sec)
mov dword[esi + APIC_LVT_timer], 0x30020; periodic int 0x20
mov dword[esi + APIC_timer_init], eax
ret
 
;===========================================================
; IOAPIC implementation
align 4
IOAPIC_read:
; in : EAX - IOAPIC register
; out: EAX - readed value
push esi
mov esi, [IOAPIC_base]
mov [esi], eax
mov eax, [esi + 0x10]
pop esi
ret
 
align 4
IOAPIC_write:
; in : EAX - IOAPIC register
; EBX - value
; out: none
push esi
mov esi, [IOAPIC_base]
mov [esi], eax
mov [esi + 0x10], ebx
pop esi
ret
;===========================================================
; Remap all IRQ to 0x20+ Vectors
; IRQ0 to vector 0x20, IRQ1 to vector 0x21....
align 4
PIC_init:
cli
mov al, 0x11 ; icw4, edge triggered
out 0x20, al
out 0xA0, al
 
mov al, 0x20 ; generate 0x20 +
out 0x21, al
mov al, 0x28 ; generate 0x28 +
out 0xA1, al
 
mov al, 0x04 ; slave at irq2
out 0x21, al
mov al, 0x02 ; at irq9
out 0xA1, al
 
mov al, 0x01 ; 8086 mode
out 0x21, al
out 0xA1, al
 
call IRQ_mask_all
; mov dword[irq_type_to_set], IRQ_TYPE_PIC
ret
 
; -----------------------------------------
; TIMER SET TO 1/100 S
align 4
PIT_init:
mov al, 0x34 ; set to 100Hz
out 0x43, al
mov al, 0x9b ; lsb 1193180 / 1193
out 0x40, al
mov al, 0x2e ; msb
out 0x40, al
ret
 
; -----------------------------------------
align 4
unmask_timer:
cmp [irq_mode], IRQ_APIC
je @f
 
stdcall enable_irq, 0
ret
@@:
; use PIT
; in some systems PIT no connected to IOAPIC
; mov eax, 0x14
; call IOAPIC_read
; mov ah, 0x09 ; Delivery Mode: Lowest Priority, Destination Mode: Logical
; mov al, 0x20
; or eax, 0x10000 ; Mask Interrupt
; mov ebx, eax
; mov eax, 0x14
; call IOAPIC_write
; stdcall enable_irq, 2
; ret
 
; use LAPIC timer
mov esi, [LAPIC_BASE]
mov eax, [esi + APIC_LVT_timer]
and eax, 0xfffeffff
mov [esi + APIC_LVT_timer], eax
ret
 
; -----------------------------------------
; Disable all IRQ
align 4
IRQ_mask_all:
cmp [irq_mode], IRQ_APIC
je .APIC
 
mov al, 0xFF
out 0x21, al
out 0xA1, al
mov ecx, 0x1000
ret
.APIC:
mov ecx, [IRQ_COUNT]
mov eax, 0x10
@@:
mov ebx, eax
call IOAPIC_read
or eax, 0x10000; bit 16
xchg eax, ebx
call IOAPIC_write
inc eax
inc eax
loop @b
ret
 
; -----------------------------------------
; End Of Interrupt
; cl - IRQ number
align 4
irq_eoi: ; __fastcall
cmp [irq_mode], IRQ_APIC
je .APIC
 
cmp cl, 8
mov al, 0x20
jb @f
out 0xa0, al
@@:
out 0x20, al
ret
 
.APIC:
mov eax, [LAPIC_BASE]
mov dword [eax + APIC_EOI], 0; EOI
ret
 
; -----------------------------------------
; from dll.inc
align 4
proc enable_irq stdcall, irq_line:dword
mov ebx, [irq_line]
cmp [irq_mode], IRQ_APIC
je .APIC
 
mov edx, 0x21
cmp ebx, 8
jb @F
 
mov edx, 0xA1
sub ebx, 8
@@:
in al, dx
btr eax, ebx
out dx, al
ret
.APIC:
shl ebx, 1
add ebx, 0x10
mov eax, ebx
call IOAPIC_read
and eax, 0xfffeffff; bit 16
xchg eax, ebx
call IOAPIC_write
ret
endp
 
align 4
pci_irq_fixup:
 
push ebp
 
mov esi, [acpi_dev_data]
mov ebx, [acpi_dev_size]
 
lea edi, [esi+ebx]
 
.iterate:
 
cmp esi, edi
jae .done
 
mov eax, [esi]
 
cmp eax, -1
je .done
 
movzx ebx, al
movzx ebp, ah
 
stdcall pci_read32, ebp, ebx, 0
 
cmp eax, [esi+4]
jne .skip
 
mov eax, [esi+8]
stdcall pci_write8, ebp, ebx, 0x3C, eax
.skip:
add esi, 16
jmp .iterate
 
.done:
.fail:
pop ebp
ret
 
 
 
 
 
/kernel/branches/net/core/conf_lib.inc
13,7 → 13,8
$Revision$
 
iglobal
conf_path_sect: db 'path',0
conf_path_sect:
db 'path',0
 
conf_fname db '/sys/sys.conf',0
endg
75,62 → 76,7
udev_midibase db 'midibase',0
udev_midibase_def db '0x320',0
endg
;set up netvork configuration
proc set_network_conf
locals
par db 30 dup(?)
endl
pushad
 
;[net]
;active
lea eax,[par]
invoke ini.get_int,conf_fname, unet, unet_active, 0
or eax,eax
jz .do_not_set_net
mov eax, [stack_config]
and eax, 0xFFFFFF80
add eax, 3
mov [stack_config], eax
call ash_eth_enable
 
;addr
lea eax,[par]
push eax
invoke ini.get_str,conf_fname, unet, unet_addr, eax,30, unet_def
pop eax
stdcall do_inet_adr,eax
mov [stack_ip], eax
 
;mask
lea eax,[par]
push eax
invoke ini.get_str,conf_fname, unet, unet_mask, eax,30, unet_def
pop eax
stdcall do_inet_adr,eax
mov [subnet_mask], eax
 
;gate
lea eax,[par]
push eax
invoke ini.get_str,conf_fname, unet, unet_gate, eax,30, unet_def
pop eax
stdcall do_inet_adr,eax
mov [gateway_ip], eax
.do_not_set_net:
popad
ret
 
 
endp
iglobal
unet db 'net',0
unet_active db 'active',0
unet_addr db 'addr',0
unet_mask db 'mask',0
unet_gate db 'gate',0
unet_def db 0
endg
; convert string to DWord
proc strtoint stdcall,strs
pushad
262,36 → 208,3
popad
ret
endp
 
 
; convert string to DWord for IP addres
proc do_inet_adr stdcall,strs
pushad
 
mov esi,[strs]
mov ebx,0
.next:
push esi
@@:
lodsb
or al,al
jz @f
cmp al,'.'
jz @f
jmp @b
@@:
mov cl, al
mov [esi-1],byte 0
;pop eax
call strtoint_dec
rol eax,24
ror ebx,8
add ebx,eax
or cl,cl
jz @f
jmp .next
@@:
mov [esp+28],ebx
popad
ret
endp
/kernel/branches/net/core/debug.inc
13,7 → 13,8
cmp ebx, 9
ja @f
jmp dword [sys_debug_services_table+ebx*4]
@@: ret
@@:
ret
iglobal
align 4
sys_debug_services_table:
93,7 → 94,8
cmp cl, 5
jnz .ret
mov cl, 2
.2: mov [CURRENT_TASK+eax+TASKDATA.state], cl
.2:
mov [CURRENT_TASK+eax+TASKDATA.state], cl
.ret:
sti
ret
108,9 → 110,12
cmp cl, 2
jnz .ret
mov cl, 5
.2: mov [CURRENT_TASK+eax+TASKDATA.state], cl
.ret: ret
.1: dec ecx
.2:
mov [CURRENT_TASK+eax+TASKDATA.state], cl
.ret:
ret
.1:
dec ecx
jmp .2
 
debug_resume:
122,7 → 127,8
shl eax, 5
jz .ret
call do_resume
.ret: sti
.ret:
sti
ret
 
debug_getcontext:
323,7 → 329,7
call get_debuggee_slot
jc .err
shr eax, 5
; mov ebx, esi
mov ecx, edi
call read_process_memory
sti
mov dword [esp+32], eax
349,7 → 355,7
call get_debuggee_slot
jc debug_read_process_memory.err
shr eax, 5
; mov ebx, esi
mov ecx, edi
call write_process_memory
sti
mov [esp+32], eax
368,8 → 374,8
.1:
mov eax, ebp
shl eax, 8
mov edx, [SLOT_BASE+eax+APPDATA.dbg_event_mem]
test edx, edx
mov esi, [SLOT_BASE+eax+APPDATA.dbg_event_mem]
test esi, esi
jz .ret
; read buffer header
push ecx
376,15 → 382,15
push eax
push eax
mov eax, ebp
mov ebx, esp
mov ecx, 8
mov ecx, esp
mov edx, 8
call read_process_memory
cmp eax, ecx
cmp eax, edx
jz @f
add esp, 12
jmp .ret
@@:
cmp dword [ebx], 0
cmp dword [ecx], 0
jg @f
.2:
pop ecx
400,26 → 406,26
cli
jmp .1
@@:
mov ecx, [ebx+8]
add ecx, [ebx+4]
cmp ecx, [ebx]
mov edx, [ecx+8]
add edx, [ecx+4]
cmp edx, [ecx]
ja .2
; advance buffer position
push ecx
mov ecx, 4
sub ebx, ecx
push edx
mov edx, 4
sub ecx, edx
mov eax, ebp
add edx, ecx
add esi, edx
call write_process_memory
pop eax
; write message
mov eax, ebp
add edx, ecx
add edx, [ebx+8]
add ebx, 20
pop ecx
pop ecx
pop ecx
add esi, edx
add esi, [ecx+8]
add ecx, 20
pop edx
pop edx
pop edx
call write_process_memory
; new debug event
mov eax, ebp
/kernel/branches/net/core/dll.inc
9,190 → 9,14
 
 
DRV_COMPAT equ 5 ;minimal required drivers version
DRV_CURRENT equ 5 ;current drivers model version
DRV_CURRENT equ 6 ;current drivers model version
 
DRV_VERSION equ (DRV_COMPAT shl 16) or DRV_CURRENT
PID_KERNEL equ 1 ;os_idle thread
 
align 4
proc attach_int_handler stdcall, irq:dword, handler:dword, access_rights:dword
 
push ebx
 
mov ebx, [irq] ;irq num
test ebx, ebx
jz .err
cmp ebx, 15 ; hidnplayr says: we only have 16 IRQ's
ja .err
mov eax, [handler]
test eax, eax
jz .err
cmp [irq_owner + 4 * ebx], 0
je @f
 
mov ecx, [irq_rights + 4 * ebx] ; Rights : 0 - full access, 1 - read only, 2 - forbidden
test ecx, ecx
jnz .err
 
@@:
mov [irq_tab+ebx*4], eax
 
mov eax, [access_rights]
mov [irq_rights + 4 * ebx], eax
 
mov [irq_owner + 4 * ebx], PID_KERNEL ; all handlers belong to a kernel
 
stdcall enable_irq, [irq]
pop ebx
mov eax, 1
ret
.err:
pop ebx
xor eax, eax
ret
endp
 
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
 
align 4
proc detach_int_handler
 
ret
endp
 
align 4
proc enable_irq stdcall, irq_line:dword
mov ebx, [irq_line]
mov edx, 0x21
cmp ebx, 8
jb @F
mov edx, 0xA1
sub ebx,8
@@:
in al,dx
btr eax, ebx
out dx, al
ret
endp
 
align 16
;; proc irq_serv
 
irq_serv:
 
.irq_1:
push 1
jmp .main
align 4
.irq_2:
push 2
jmp .main
align 4
.irq_3:
push 3
jmp .main
align 4
.irq_4:
push 4
jmp .main
align 4
.irq_5:
push 5
jmp .main
; align 4
; .irq_6:
; push 6
; jmp .main
align 4
.irq_7:
push 7
jmp .main
align 4
.irq_8:
push 8
jmp .main
align 4
.irq_9:
push 9
jmp .main
align 4
.irq_10:
push 10
jmp .main
align 4
.irq_11:
push 11
jmp .main
align 4
.irq_12:
push 12
jmp .main
; align 4
; .irq_13:
; push 13
; jmp .main
; align 4
; .irq_14:
; push 14
; jmp .main
; align 4
; .irq_15:
; push 15
; jmp .main
 
align 16
.main:
save_ring3_context
mov eax, [esp + 32]
mov bx, app_data ;os_data
mov ds, bx
mov es, bx
 
cmp [v86_irqhooks+eax*8], 0
jnz v86_irq
 
mov ebx, [irq_tab+eax*4]
test ebx, ebx
jz .exit
 
call ebx
mov [check_idle_semaphore],5
 
.exit:
 
cmp dword [esp + 32], 8
mov al, 0x20
jb @f
out 0xa0, al
@@:
out 0x20, al
 
restore_ring3_context
add esp, 4
 
iret
 
align 4
proc get_notify stdcall, p_ev:dword
 
.wait:
212,7 → 36,7
 
align 4
proc pci_read32 stdcall, bus:dword, devfn:dword, reg:dword
push ebx edx
push ebx
xor eax, eax
xor ebx, ebx
mov ah, byte [bus]
220,13 → 44,13
mov bh, byte [devfn]
mov bl, byte [reg]
call pci_read_reg
pop edx ebx
pop ebx
ret
endp
 
align 4
proc pci_read16 stdcall, bus:dword, devfn:dword, reg:dword
push ebx edx
push ebx
xor eax, eax
xor ebx, ebx
mov ah, byte [bus]
234,13 → 58,13
mov bh, byte [devfn]
mov bl, byte [reg]
call pci_read_reg
pop edx ebx
pop ebx
ret
endp
 
align 4
proc pci_read8 stdcall, bus:dword, devfn:dword, reg:dword
push ebx edx
push ebx
xor eax, eax
xor ebx, ebx
mov ah, byte [bus]
248,13 → 72,13
mov bh, byte [devfn]
mov bl, byte [reg]
call pci_read_reg
pop edx ebx
pop ebx
ret
endp
 
align 4
proc pci_write8 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
push ebx edx
push ebx
xor eax, eax
xor ebx, ebx
mov ah, byte [bus]
263,13 → 87,13
mov bl, byte [reg]
mov ecx, [val]
call pci_write_reg
pop edx ebx
pop ebx
ret
endp
 
align 4
proc pci_write16 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
push ebx edx
push ebx
xor eax, eax
xor ebx, ebx
mov ah, byte [bus]
278,13 → 102,13
mov bl, byte [reg]
mov ecx, [val]
call pci_write_reg
pop edx ebx
pop ebx
ret
endp
 
align 4
proc pci_write32 stdcall, bus:dword, devfn:dword, reg:dword, val:dword
push ebx edx
push ebx
xor eax, eax
xor ebx, ebx
mov ah, byte [bus]
293,7 → 117,7
mov bl, byte [reg]
mov ecx, [val]
call pci_write_reg
pop edx ebx
pop ebx
ret
endp
 
544,10 → 368,8
mov [name], ebx
 
pushad
push eax
lea eax, [cmd]
lea ebx, [cmd]
call file_system_lfn
pop eax
popad
ret
endp
597,6 → 419,8
 
stdcall kernel_alloc, [file_size]
mov [file], eax
test eax, eax
jz .fail
 
stdcall read_file, [file_name], eax, dword 0, [file_size]
cmp ebx, [file_size]
797,6 → 621,7
ret
endp
 
align 4
proc rebase_coff stdcall uses ebx esi, coff:dword, sym:dword, \
delta:dword
locals
1620,70 → 1445,3
 
call free ;release object memory
ret
 
 
 
if 0
 
irq:
 
.irq0:
pusfd
pushad
push IRQ_0
jmp .master
.irq_1:
pusfd
pushad
push IRQ_1
jmp .master
 
.master:
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
 
.slave:
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
.restart:
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
 
end if
 
 
 
 
/kernel/branches/net/core/export.inc
28,7 → 28,8
local name
dd (name-OS_BASE)
common
ordinal: count = 0
ordinal:
count = 0
forward
dw count
count = count+1
/kernel/branches/net/core/exports.inc
16,12 → 16,16
szGetService db 'GetService',0
szServiceHandler db 'ServiceHandler',0
szAttachIntHandler db 'AttachIntHandler',0
szGetIntHandler db 'GetIntHandler', 0
; szGetIntHandler db 'GetIntHandler', 0
szFpuSave db 'FpuSave',0
szFpuRestore db 'FpuRestore',0
szReservePortArea db 'ReservePortArea',0
szBoot_Log db 'Boot_Log',0
 
szMutexInit db 'MutexInit',0
szMutexLock db 'MutexLock',0
szMutexUnlock db 'MutexUnlock',0
 
szPciApi db 'PciApi', 0
szPciRead32 db 'PciRead32', 0
szPciRead16 db 'PciRead16', 0
71,6 → 75,9
szSleep db 'Sleep',0
szGetTimerTicks db 'GetTimerTicks',0
 
szGetDisplay db 'GetDisplay',0
szSetScreen db 'SetScreen',0
 
szStrncat db 'strncat',0
szStrncpy db 'strncpy',0
szstrncmp db 'strncmp',0
78,6 → 85,13
szStrchr db 'strchr',0
szStrrchr db 'strrchr',0
 
szDiskAdd db 'DiskAdd',0
szDiskDel db 'DiskDel',0
szDiskMediaChanged db 'DiskMediaChanged',0
 
szTimerHS db 'TimerHS',0
szCancelTimerHS db 'CancelTimerHS',0
 
szNetRegDev db 'NetRegDev',0
szNetUnRegDev db 'NetUnRegDev',0
szNetPtrToNum db 'NetPtrToNum',0
91,13 → 105,17
dd szGetService , get_service
dd szServiceHandler , srv_handler
dd szAttachIntHandler, attach_int_handler
dd szGetIntHandler , get_int_handler
; dd szGetIntHandler , get_int_handler
dd szFpuSave , fpu_save
dd szFpuRestore , fpu_restore
dd szReservePortArea , r_f_port_area
dd szBoot_Log , boot_log
 
dd szPciApi , pci_api
dd szMutexInit , mutex_init ;gcc fastcall
dd szMutexLock , mutex_lock ;gcc fastcall
dd szMutexUnlock , mutex_unlock ;gcc fastcall
 
dd szPciApi , pci_api_drv
dd szPciRead32 , pci_read32
dd szPciRead16 , pci_read16
dd szPciRead8 , pci_read8
145,6 → 163,9
dd szSleep , delay_ms
dd szGetTimerTicks , get_timer_ticks
 
dd szGetDisplay , get_display
dd szSetScreen , set_screen
 
dd szStrncat , strncat
dd szStrncpy , strncpy
dd szstrncmp , strncmp
152,6 → 173,13
dd szStrchr , strchr
dd szStrrchr , strrchr
 
dd szDiskAdd , disk_add
dd szDiskDel , disk_del
dd szDiskMediaChanged, disk_media_changed
 
dd szTimerHS , timer_hs
dd szCancelTimerHS , cancel_timer_hs
 
dd szNetRegDev , NET_add_device
dd szNetUnRegDev , NET_remove_device
dd szNetPtrToNum , NET_ptr_to_num
/kernel/branches/net/core/ext_lib.inc
158,7 → 158,8
 
proc dll.Load, import_table:dword
mov esi,[import_table]
.next_lib: mov edx,[esi]
.next_lib:
mov edx, [esi]
or edx,edx
jz .exit
push esi
168,7 → 169,8
mov al, '/'
stosb
mov esi,sysdir_path
@@: lodsb
@@:
lodsb
stosb
or al,al
jnz @b
179,7 → 181,8
pop esi
push esi
mov esi,[esi+4]
@@: lodsb
@@:
lodsb
stosb
or al,al
jnz @b
195,9 → 198,11
pop esi
add esi,8
jmp .next_lib
.exit: xor eax,eax
.exit:
xor eax, eax
ret
.fail: add esp,4
.fail:
add esp, 4
xor eax,eax
inc eax
ret
208,7 → 213,8
mov esi,[imp]
test esi,esi
jz .done
.next: lodsd
.next:
lodsd
test eax,eax
jz .done
stdcall dll.GetProcAddress,[exp],eax
216,8 → 222,10
jz @f
mov [esi-4],eax
jmp .next
@@: mov dword[esp],0
.done: pop eax
@@:
mov dword[esp], 0
.done:
pop eax
ret
endp
 
234,7 → 242,8
 
proc dll.GetProcAddress, exp:dword,sz_name:dword
mov edx,[exp]
.next: test edx,edx
.next:
test edx, edx
jz .end
stdcall strncmp,[edx],[sz_name], dword -1
test eax,eax
241,8 → 250,10
jz .ok
add edx,8
jmp .next
.ok: mov eax,[edx+4]
.end: ret
.ok:
mov eax, [edx+4]
.end:
ret
endp
 
;-----------------------------------------------------------------------------
276,7 → 287,8
add ecx,-4
cmp ecx,[eax-4]
je .exit
@@: mov eax,ebx
@@:
mov eax, ebx
call mem.Alloc
xchg eax,[esp]
or eax,eax
288,7 → 300,8
cmp ecx,[edi-4]
jbe @f
mov ecx,[edi-4]
@@: add ecx,3
@@:
add ecx, 3
shr ecx,2
cld
rep movsd
/kernel/branches/net/core/heap.inc
9,17 → 9,17
 
 
struc MEM_BLOCK
{ .next_block dd ?
{
.list LHEAD
.next_block dd ? ;+8
.prev_block dd ? ;+4
.list_fd dd ? ;+8
.list_bk dd ? ;+12
.base dd ? ;+16
.size dd ? ;+20
.flags dd ? ;+24
.handle dd ? ;+28
.sizeof:
}
 
MEM_LIST_OFFSET equ 8
FREE_BLOCK equ 4
USED_BLOCK equ 8
DONT_FREE_BLOCK equ 10h
28,12 → 28,11
MEM_BLOCK MEM_BLOCK
end virtual
 
MEM_BLOCK_SIZE equ 8*4
 
block_next equ MEM_BLOCK.next_block
block_prev equ MEM_BLOCK.prev_block
list_fd equ MEM_BLOCK.list_fd
list_bk equ MEM_BLOCK.list_bk
list_fd equ MEM_BLOCK.list.next
list_bk equ MEM_BLOCK.list.prev
block_base equ MEM_BLOCK.base
block_size equ MEM_BLOCK.size
block_flags equ MEM_BLOCK.flags
47,69 → 46,94
@@:
}
 
macro remove_from_list op
{ mov edx, [op+list_fd]
mov ecx, [op+list_bk]
test edx, edx
jz @f
mov [edx+list_bk], ecx
@@:
test ecx, ecx
jz @f
mov [ecx+list_fd], edx
@@:
mov [op+list_fd],0
mov [op+list_bk],0
}
align 4
md:
.add_to_used:
mov eax, [esi+block_base]
mov ebx, [esi+block_base]
shr ebx, 6
add eax, ebx
shr ebx, 6
add eax, ebx
shr eax, 12
and eax, 63
inc [mem_hash_cnt+eax*4]
 
macro remove_from_free op
{
remove_from_list op
lea ecx, [mem_used_list+eax*8]
list_add esi, ecx
mov [esi+block_flags], USED_BLOCK
mov eax, [esi+block_size]
sub [heap_free], eax
ret
align 4
.find_used:
mov ecx, eax
mov ebx, eax
shr ebx, 6
add ecx, ebx
shr ebx, 6
add ecx, ebx
shr ecx, 12
and ecx, 63
 
mov eax, [op+block_size]
calc_index eax
cmp [mem_block_list+eax*4], op
jne @f
mov [mem_block_list+eax*4], edx
@@:
cmp [mem_block_list+eax*4], 0
jne @f
btr [mem_block_mask], eax
@@:
}
lea ebx, [mem_used_list+ecx*8]
mov esi, ebx
.next:
mov esi, [esi+list_fd]
cmp esi, ebx
je .fail
 
macro remove_from_used op
{
mov edx, [op+list_fd]
mov ecx, [op+list_bk]
mov [edx+list_bk], ecx
mov [ecx+list_fd], edx
mov [op+list_fd], 0
mov [op+list_bk], 0
}
cmp eax, [esi+block_base]
jne .next
 
ret
.fail:
xor esi, esi
ret
 
align 4
.del_from_used:
call .find_used
test esi, esi
jz .done
 
cmp [esi+block_flags], USED_BLOCK
jne .fatal
 
dec [mem_hash_cnt+ecx*4]
list_del esi
.done:
ret
.fatal: ;FIXME panic here
xor esi, esi
ret
 
;Initial heap state
;
;+heap_size terminator USED_BLOCK
;+4096*MEM_BLOCK.sizeof free space FREE_BLOCK
;HEAP_BASE heap_descriptors USED_BLOCK
;
 
align 4
proc init_kernel_heap
 
mov ecx, 64
mov edi, mem_block_list
xor eax, eax
cld
rep stosd
@@:
mov eax, edi
stosd
stosd
loop @B
 
mov ecx, 512/4
mov edi, mem_block_map
not eax
rep stosd
mov ecx, 64
mov edi, mem_used_list
@@:
mov eax, edi
stosd
stosd
loop @B
 
mov [mem_block_start], mem_block_map
mov [mem_block_end], mem_block_map+512
mov [mem_block_arr], HEAP_BASE
 
mov eax, mem_used.fd-MEM_LIST_OFFSET
mov [mem_used.fd], eax
mov [mem_used.bk], eax
 
stdcall alloc_pages, dword 32
mov ecx, 32
mov edx, eax
121,8 → 145,10
dec ecx
jnz .l1
 
mov edi, HEAP_BASE
mov ebx, HEAP_BASE+MEM_BLOCK_SIZE
mov edi, HEAP_BASE ;descriptors
mov ebx, HEAP_BASE+MEM_BLOCK.sizeof ;free space
mov ecx, HEAP_BASE+MEM_BLOCK.sizeof*2 ;terminator
 
xor eax, eax
mov [edi+block_next], ebx
mov [edi+block_prev], eax
129,18 → 155,24
mov [edi+list_fd], eax
mov [edi+list_bk], eax
mov [edi+block_base], HEAP_BASE
mov [edi+block_size], 4096*MEM_BLOCK_SIZE
mov [edi+block_size], 4096*MEM_BLOCK.sizeof
mov [edi+block_flags], USED_BLOCK
 
mov [ebx+block_next], eax
mov [ebx+block_prev], eax
mov [ebx+list_fd], eax
mov [ebx+list_bk], eax
mov [ebx+block_base], HEAP_BASE+4096*MEM_BLOCK_SIZE
mov [ecx+block_next], eax
mov [ecx+block_prev], ebx
mov [edi+list_fd], eax
mov [edi+list_bk], eax
mov [edi+block_base], eax
mov [edi+block_size], eax
mov [edi+block_flags], USED_BLOCK
 
mov [ebx+block_next], ecx
mov [ebx+block_prev], edi
mov [ebx+block_base], HEAP_BASE+4096*MEM_BLOCK.sizeof
 
mov ecx, [pg_data.kernel_pages]
shl ecx, 12
sub ecx, HEAP_BASE-OS_BASE+4096*MEM_BLOCK_SIZE
sub ecx, HEAP_BASE-OS_BASE+4096*MEM_BLOCK.sizeof
mov [heap_size], ecx
mov [heap_free], ecx
mov [ebx+block_size], ecx
149,11 → 181,24
mov [mem_block_mask], eax
mov [mem_block_mask+4],0x80000000
 
mov [mem_block_list+63*4], ebx
mov byte [mem_block_map], 0xFC
and [heap_mutex], 0
mov [heap_blocks], 4095
mov [free_blocks], 4094
mov ecx, mem_block_list+63*8
list_add ebx, ecx
 
mov ecx, 4096-3-1
mov eax, HEAP_BASE+MEM_BLOCK.sizeof*4
 
mov [next_memblock], HEAP_BASE+MEM_BLOCK.sizeof*3
@@:
mov [eax-MEM_BLOCK.sizeof], eax
add eax, MEM_BLOCK.sizeof
loop @B
 
mov [eax-MEM_BLOCK.sizeof], dword 0
 
mov ecx, heap_mutex
call mutex_init
mov [heap_blocks], 4094
mov [free_blocks], 4093
ret
endp
 
190,11 → 235,18
bsf edi, edx
jz .high_mask
add ebx, edi
mov edi, [mem_block_list+ebx*4]
.check_size:
lea ecx, [mem_block_list+ebx*8]
mov edi, ecx
.next:
mov edi, [edi+list_fd]
cmp edi, ecx
je .err
cmp eax, [edi+block_size]
ja .next
ret
.err:
xor edi, edi
ret
 
.high_mask:
add esi, 4
203,66 → 255,24
add ebx, 32
mov edx, [esi]
jmp .find
.next:
mov edi, [edi+list_fd]
test edi, edi
jnz .check_size
.err:
xor edi, edi
ret
 
align 4
alloc_mem_block:
 
mov ebx, [mem_block_start]
mov ecx, [mem_block_end]
.l1:
bsf eax,[ebx];
jnz found
add ebx,4
cmp ebx, ecx
jb .l1
xor eax,eax
ret
 
found:
btr [ebx], eax
mov [mem_block_start],ebx
sub ebx, mem_block_map
lea eax,[eax+ebx*8]
shl eax, 5
add eax, [mem_block_arr]
dec [free_blocks]
ret
align 4
free_mem_block:
mov dword [eax], 0
mov dword [eax+4], 0
mov dword [eax+8], 0
mov dword [eax+12], 0
mov dword [eax+16], 0
; mov dword [eax+20], 0
mov dword [eax+24], 0
mov dword [eax+28], 0
mov ebx, [next_memblock]
mov [eax], ebx
mov [next_memblock], eax
xor ebx, ebx
 
sub eax, [mem_block_arr]
shr eax, 5
 
mov ebx, mem_block_map
bts [ebx], eax
mov dword [eax+4], ebx
mov dword [eax+8], ebx
mov dword [eax+12], ebx
mov dword [eax+16], ebx
; mov dword [eax+20], 0 ;don't clear block size
mov dword [eax+24], ebx
mov dword [eax+28], ebx
inc [free_blocks]
shr eax, 3
and eax, not 3
add eax, ebx
cmp [mem_block_start], eax
ja @f
ret
@@:
mov [mem_block_start], eax
ret
.err:
xor eax, eax
ret
 
align 4
proc alloc_kernel_space stdcall, size:dword
277,18 → 287,20
and eax, not 4095
mov [size], eax
 
mov ebx, heap_mutex
call wait_mutex ;ebx
 
cmp eax, [heap_free]
ja .error
 
mov ecx, heap_mutex
call mutex_lock
 
mov eax, [size]
 
call get_small_block ; eax
test edi, edi
jz .error
jz .error_unlock
 
cmp [edi+block_flags], FREE_BLOCK
jne .error
jne .error_unlock
 
mov [block_ind], ebx ;index of allocated block
 
296,11 → 308,13
cmp eax, [size]
je .m_eq_size
 
call alloc_mem_block
and eax, eax
jz .error
mov esi, [next_memblock] ;new memory block
test esi, esi
jz .error_unlock
 
mov esi, eax ;esi - splitted block
dec [free_blocks]
mov eax, [esi]
mov [next_memblock], eax
 
mov [esi+block_next], edi
mov eax, [edi+block_prev]
308,10 → 322,8
mov [edi+block_prev], esi
mov [esi+list_fd], 0
mov [esi+list_bk], 0
and eax, eax
jz @f
mov [eax+block_next], esi
@@:
 
mov ebx, [edi+block_base]
mov [esi+block_base], ebx
mov edx, [size]
320,75 → 332,48
sub [edi+block_size], edx
 
mov eax, [edi+block_size]
shr eax, 12
sub eax, 1
cmp eax, 63
jna @f
mov eax, 63
@@:
calc_index eax
cmp eax, [block_ind]
je .m_eq_ind
je .add_used
 
remove_from_list edi
list_del edi
 
mov ecx, [block_ind]
mov [mem_block_list+ecx*4], edx
 
test edx, edx
lea edx, [mem_block_list+ecx*8]
cmp edx, [edx]
jnz @f
btr [mem_block_mask], ecx
@@:
mov edx, [mem_block_list+eax*4]
mov [edi+list_fd], edx
test edx, edx
jz @f
mov [edx+list_bk], edi
@@:
mov [mem_block_list+eax*4], edi
bts [mem_block_mask], eax
.m_eq_ind:
mov ecx, mem_used.fd-MEM_LIST_OFFSET
mov edx, [ecx+list_fd]
mov [esi+list_fd], edx
mov [esi+list_bk], ecx
mov [ecx+list_fd], esi
mov [edx+list_bk], esi
lea edx, [mem_block_list+eax*8] ;edx= list head
list_add edi, edx
.add_used:
 
mov [esi+block_flags], USED_BLOCK
call md.add_to_used
 
mov ecx, heap_mutex
call mutex_unlock
mov eax, [esi+block_base]
mov ebx, [size]
sub [heap_free], ebx
and [heap_mutex], 0
pop edi
pop esi
pop ebx
ret
 
.m_eq_size:
remove_from_list edi
mov [mem_block_list+ebx*4], edx
and edx, edx
list_del edi
lea edx, [mem_block_list+ebx*8]
cmp edx, [edx]
jnz @f
btr [mem_block_mask], ebx
@@:
mov ecx, mem_used.fd-MEM_LIST_OFFSET
mov edx, [ecx+list_fd]
mov [edi+list_fd], edx
mov [edi+list_bk], ecx
mov [ecx+list_fd], edi
mov [edx+list_bk], edi
mov esi, edi
jmp .add_used
 
mov [edi+block_flags], USED_BLOCK
mov eax, [edi+block_base]
mov ebx, [size]
sub [heap_free], ebx
and [heap_mutex], 0
pop edi
pop esi
pop ebx
ret
.error_unlock:
mov ecx, heap_mutex
call mutex_unlock
.error:
xor eax, eax
mov [heap_mutex], eax
pop edi
pop esi
pop ebx
397,66 → 382,49
 
align 4
proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword
push ebx
push esi
push edi
mov ebx, heap_mutex
call wait_mutex ;ebx
 
mov ecx, heap_mutex
call mutex_lock
 
mov eax, [base]
mov esi, [mem_used.fd]
@@:
cmp esi, mem_used.fd-MEM_LIST_OFFSET
je .fail
 
cmp [esi+block_base], eax
je .found
mov esi, [esi+list_fd]
jmp @b
.found:
cmp [esi+block_flags], USED_BLOCK
jne .fail
call md.del_from_used
test esi, esi
jz .fail
 
mov eax, [esi+block_size]
add [heap_free], eax
 
mov edi, [esi+block_next]
test edi, edi
jz .prev
 
cmp [edi+block_flags], FREE_BLOCK
jne .prev
 
remove_from_free edi
list_del edi
 
mov edx, [edi+block_next]
mov [esi+block_next], edx
test edx, edx
jz @f
 
mov [edx+block_prev], esi
@@:
mov ecx, [edi+block_size]
add [esi+block_size], ecx
 
calc_index ecx
 
lea edx, [mem_block_list+ecx*8]
cmp edx, [edx]
jne @F
btr [mem_block_mask], ecx
@@:
mov eax, edi
call free_mem_block
.prev:
mov edi, [esi+block_prev]
test edi, edi
jz .insert
 
cmp [edi+block_flags], FREE_BLOCK
jne .insert
 
remove_from_used esi
 
mov edx, [esi+block_next]
mov [edi+block_next], edx
test edx, edx
jz @f
mov [edx+block_prev], edi
@@:
 
mov eax, esi
call free_mem_block
 
465,67 → 433,40
add eax, ecx
mov [edi+block_size], eax
 
calc_index eax
calc_index ecx
calc_index eax ;new index
calc_index ecx ;old index
cmp eax, ecx
je .m_eq
 
push ecx
remove_from_list edi
list_del edi
pop ecx
 
cmp [mem_block_list+ecx*4], edi
jne @f
mov [mem_block_list+ecx*4], edx
@@:
cmp [mem_block_list+ecx*4], 0
jne @f
lea edx, [mem_block_list+ecx*8]
cmp edx, [edx]
jne .add_block
btr [mem_block_mask], ecx
@@:
mov esi, [mem_block_list+eax*4]
mov [mem_block_list+eax*4], edi
mov [edi+list_fd], esi
test esi, esi
jz @f
mov [esi+list_bk], edi
@@:
.add_block:
bts [mem_block_mask], eax
lea edx, [mem_block_list+eax*8]
list_add edi, edx
.m_eq:
mov ecx, heap_mutex
call mutex_unlock
xor eax, eax
mov [heap_mutex], eax
dec eax
pop edi
pop esi
pop ebx
not eax
ret
.insert:
remove_from_used esi
 
mov [esi+block_flags], FREE_BLOCK
mov eax, [esi+block_size]
calc_index eax
mov edi, esi
jmp .add_block
 
mov edi, [mem_block_list+eax*4]
mov [mem_block_list+eax*4], esi
mov [esi+list_fd], edi
test edi, edi
jz @f
mov [edi+list_bk], esi
@@:
bts [mem_block_mask], eax
mov [esi+block_flags],FREE_BLOCK
xor eax, eax
mov [heap_mutex], eax
dec eax
pop edi
pop esi
pop ebx
ret
.fail:
mov ecx, heap_mutex
call mutex_unlock
xor eax, eax
mov [heap_mutex], eax
pop edi
pop esi
pop ebx
ret
endp
 
605,37 → 546,31
 
align 4
proc kernel_free stdcall, base:dword
 
push ebx esi
 
mov ebx, heap_mutex
call wait_mutex ;ebx
mov ecx, heap_mutex
call mutex_lock
 
mov eax, [base]
mov esi, [mem_used.fd]
@@:
cmp esi, mem_used.fd-MEM_LIST_OFFSET
je .fail
call md.find_used
 
cmp [esi+block_base], eax
je .found
mov esi, [esi+list_fd]
jmp @b
.found:
mov ecx, heap_mutex
cmp [esi+block_flags], USED_BLOCK
jne .fail
 
and [heap_mutex], 0
call mutex_unlock
 
push ecx
mov ecx, [esi+block_size];
mov eax, [esi+block_base]
mov ecx, [esi+block_size]
shr ecx, 12
call release_pages ;eax, ecx
pop ecx
stdcall free_kernel_space, [base]
pop esi ebx
ret
.fail:
and [heap_mutex], 0
call mutex_unlock
xor eax, eax
pop esi ebx
ret
endp
1521,7 → 1456,7
test edi, edi
jz .next
 
lea eax, [edi+SMEM.name]
lea edi, [edi+SMEM.name]
stdcall strncmp, [name], edi, 32
test eax, eax
jne .next
1528,6 → 1463,7
 
stdcall user_free, [esi+SMAP.base]
 
mov eax, esi
call [esi+APPOBJ.destroy]
@@:
popfd
/kernel/branches/net/core/irq.inc
0,0 → 1,229
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
IRQ_RESERVED equ 24
 
IRQ_POOL_SIZE equ 48
 
uglobal
 
align 16
irqh_tab rd LHEAD.sizeof * IRQ_RESERVED / 4
 
irqh_pool rd IRQH.sizeof * IRQ_POOL_SIZE /4
next_irqh rd 1
 
irq_active_set rd 1
irq_failed rd IRQ_RESERVED
 
endg
 
align 4
init_irqs:
 
mov ecx, IRQ_RESERVED
mov edi, irqh_tab
@@:
mov eax, edi
stosd
stosd
loop @B
 
mov ecx, IRQ_POOL_SIZE-1
mov eax, irqh_pool+IRQH.sizeof
mov [next_irqh], irqh_pool
@@:
mov [eax-IRQH.sizeof], eax
add eax, IRQH.sizeof
loop @B
 
mov [eax-IRQH.sizeof], dword 0
ret
 
 
align 4
proc attach_int_handler stdcall, irq:dword, handler:dword, user_data:dword
locals
.irqh dd ?
endl
 
and [.irqh], 0
 
push ebx
 
mov ebx, [irq] ;irq num
test ebx, ebx
jz .err
 
cmp ebx, IRQ_RESERVED
jae .err
 
mov edx, [handler]
test edx, edx
jz .err
 
pushfd
cli
 
;allocate handler
 
mov ecx, [next_irqh]
test ecx, ecx
jz .fail
 
mov eax, [ecx]
mov [next_irqh], eax
mov [.irqh], ecx
 
mov [irq_failed+ebx*4], 0;clear counter
 
mov eax, [user_data]
mov [ecx+IRQH.handler], edx
mov [ecx+IRQH.data], eax
 
lea edx, [irqh_tab+ebx*8]
list_add_tail ecx, edx ;clobber eax
stdcall enable_irq, ebx
 
.fail:
popfd
.err:
pop ebx
mov eax, [.irqh]
ret
 
endp
 
if 0
align 4
proc get_int_handler stdcall, irq:dword
 
mov eax, [irq]
cmp eax, 15
ja .fail
mov eax, [irq_tab + 4 * eax]
ret
.fail:
xor eax, eax
ret
endp
end if
 
 
align 4
proc detach_int_handler
 
ret
endp
 
 
macro irq_serv_h [num] {
forward
align 4
.irq_#num :
push num
jmp .main
}
 
align 16
irq_serv:
 
; .irq_1:
; push 1
; jmp .main
; etc...
 
irq_serv_h 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15
irq_serv_h 16, 17, 18, 19, 20, 21, 22, 23
 
purge irq_serv_h
 
align 16
.main:
save_ring3_context
 
mov ebp, [esp + 32]
mov bx, app_data;os_data
mov ds, bx
mov es, bx
 
cmp [v86_irqhooks+ebp*8], 0
jnz v86_irq
 
cmp bp, 6
jnz @f
push ebp
call [fdc_irq_func]
pop ebp
@@:
 
cmp bp, 14
jnz @f
push ebp
call [irq14_func]
pop ebp
@@:
cmp bp, 15
jnz @f
push ebp
call [irq15_func]
pop ebp
@@:
bts [irq_active_set], ebp
 
lea esi, [irqh_tab+ebp*8] ; esi= list head
mov ebx, esi
.next:
mov ebx, [ebx+IRQH.list.next]; ebx= irqh pointer
cmp ebx, esi
je .done
 
push ebx ; FIX THIS
push edi
push esi
 
push [ebx+IRQH.data]
call [ebx+IRQH.handler]
add esp, 4
 
pop esi
pop edi
pop ebx
 
test eax, eax
jz .next
 
btr [irq_active_set], ebp
jmp .next
 
.done:
btr [irq_active_set], ebp
jnc .exit
 
inc [irq_failed+ebp*4]
.exit:
mov [check_idle_semaphore], 5
 
mov ecx, ebp
call irq_eoi
 
restore_ring3_context
add esp, 4
iret
 
align 4
irqD:
push eax
push ecx
xor eax, eax
out 0xf0, al
mov cl, 13
call irq_eoi
pop ecx
pop eax
iret
 
/kernel/branches/net/core/malloc.inc
20,7 → 20,7
; esi= nb
; ebx= idx
;
align 16
align 4
malloc:
push esi
 
31,8 → 31,8
and esi, -8
add esi, 8
 
mov ebx, mst.mutex
call wait_mutex ;ebx
mov ecx, mst.mutex
call mutex_lock
 
cmp esi, 256
jae .large
92,9 → 92,13
pop edi
pop ebp
.done:
mov esi, eax
mov ecx, mst.mutex
call mutex_unlock
mov eax, esi
pop esi
mov [mst.mutex], 0
ret
 
.split:
lea ebx, [edx+8] ;ebx=mem
 
133,10 → 137,10
mov [edx+12], eax ; F->bk = r;
mov [eax+8], edx ; r->fd = F;
mov [eax+12], ecx ; r->bk = B;
 
mov eax, ebx
pop esi
mov [mst.mutex], 0
ret
jmp .done
 
.small:
 
; if (ms.treemap != 0 && (mem = malloc_small(nb)) != 0)
150,9 → 154,8
call malloc_small
test eax, eax
jz .from_top
pop esi
and [mst.mutex], 0
ret
jmp .done
 
.large:
 
; if (ms.treemap != 0 && (mem = malloc_large(nb)) != 0)
189,19 → 192,19
mov [edx+4], eax
mov [ecx+4], esi
lea eax, [ecx+8]
pop esi
and [mst.mutex], 0
ret
jmp .done
 
.fail:
xor eax, eax
pop esi
and [mst.mutex], 0
ret
jmp .done
 
; param
; eax= mem
align 4
free:
test eax, eax
jz .exit
 
free:
push edi
mov edi, eax
add edi, -8
211,8 → 214,8
test byte [edi+4], 2
je .fail
 
mov ebx, mst.mutex
call wait_mutex ;ebx
mov ecx, mst.mutex
call mutex_lock
 
; psize = p->head & (~3);
 
289,11 → 292,16
mov [mst.top], edi
mov [edi+4], eax
.fail2:
and [mst.mutex], 0
mov esi, eax
mov ecx, mst.mutex
call mutex_unlock
mov eax, esi
pop esi
.fail:
pop edi
.exit:
ret
 
@@:
 
; nsize = next->head & ~INUSE_BITS;
410,13 → 418,15
mov [esi+8], edx ;P->fd = F
mov [esi+12], eax ;P->bk = B
pop esi
and [mst.mutex], 0
mov ecx, mst.mutex
call mutex_unlock
ret
.large:
mov ebx, eax
call insert_large_chunk
pop esi
and [mst.mutex], 0
mov ecx, mst.mutex
call mutex_unlock
ret
 
 
1025,5 → 1035,8
cmp eax, mst.smallbins+512
jb @B
 
mov ecx, mst.mutex
call mutex_init
 
ret
 
/kernel/branches/net/core/memory.inc
171,9 → 171,14
push ebx
push edi
mov eax, [size]
add eax, [base]
add eax, 4095
and eax, -4096
mov ecx, [base]
and ecx, -4096
sub eax, ecx
mov [size], eax
 
stdcall alloc_kernel_space, eax
test eax, eax
jz .fail
189,9 → 194,7
or edx, [flags]
@@:
mov [page_tabs+eax*4], edx
; push eax
invlpg [ebx]
; pop eax
inc eax
add ebx, edi
add edx, edi
214,30 → 217,32
 
align 4
commit_pages:
push edi
test ecx, ecx
jz .fail
 
push edi
push eax
push ecx
mov ecx, pg_data.mutex
call mutex_lock
pop ecx
pop eax
 
mov edi, ebx
mov ebx, pg_data.pg_mutex
call wait_mutex ;ebx
shr edi, 12
lea edi, [page_tabs+edi*4]
@@:
stosd
invlpg [ebx]
add eax, 0x1000
add ebx, 0x1000
loop @B
 
mov edx, 0x1000
mov ebx, edi
shr ebx, 12
@@:
mov [page_tabs+ebx*4], eax
; push eax
invlpg [edi]
; pop eax
add edi, edx
add eax, edx
inc ebx
dec ecx
jnz @B
mov [pg_data.pg_mutex],ecx
pop edi
 
mov ecx, pg_data.mutex
call mutex_unlock
.fail:
pop edi
ret
 
 
248,16 → 253,22
align 4
release_pages:
 
pushad
mov ebx, pg_data.pg_mutex
call wait_mutex ;ebx
push ebp
push esi
push edi
push ebx
 
mov esi, eax
mov edi, eax
 
shr esi, 10
add esi, page_tabs
shr esi, 12
lea esi, [page_tabs+esi*4]
 
push ecx
mov ecx, pg_data.mutex
call mutex_lock
pop ecx
 
mov ebp, [pg_data.pages_free]
mov ebx, [page_start]
mov edx, sys_pgmap
264,9 → 275,7
@@:
xor eax, eax
xchg eax, [esi]
push eax
invlpg [edi]
pop eax
 
test eax, 1
jz .next
285,11 → 294,16
.next:
add edi, 0x1000
add esi, 4
dec ecx
jnz @B
loop @B
 
mov [pg_data.pages_free], ebp
and [pg_data.pg_mutex],0
popad
mov ecx, pg_data.mutex
call mutex_unlock
 
pop ebx
pop edi
pop esi
pop ebp
ret
 
; param
423,8 → 437,8
align 4
proc new_mem_resize stdcall, new_size:dword
 
mov ebx, pg_data.pg_mutex
call wait_mutex ;ebx
mov ecx, pg_data.mutex
call mutex_lock
 
mov edi, [new_size]
add edi,4095
456,7 → 470,8
pop eax
call free_page
 
.next: add edi, 1
.next:
add edi, 1
cmp edi, esi
jb @B
 
464,8 → 479,10
mov ebx, [new_size]
call update_mem_size
 
mov ecx, pg_data.mutex
call mutex_unlock
 
xor eax, eax
dec [pg_data.pg_mutex]
ret
.expand:
 
539,9 → 556,11
pop edi
pop esi
.exit:
mov ecx, pg_data.mutex
call mutex_unlock
 
xor eax, eax
inc eax
dec [pg_data.pg_mutex]
ret
endp
 
779,7 → 798,8
; and eax, 0xFFFFF000
; stdcall map_page, edi, eax
 
@@: mov edi, [lin_addr]
@@:
mov edi, [lin_addr]
and edi, 0xFFFFF000
mov ecx, [buf_size]
add ecx, 4095
839,7 → 859,8
jz .exit
stdcall map_page,edi,eax,PG_UW
 
@@: mov edi, [lin_addr]
@@:
mov edi, [lin_addr]
and edi, 0xFFFFF000
mov ecx, [buf_size]
add ecx, 4095
970,7 → 991,8
add edx, 4095
and edx, not 4095
 
.touch: mov eax, [ecx]
.touch:
mov eax, [ecx]
add ecx, 0x1000
cmp ecx, edx
jb .touch
/kernel/branches/net/core/peload.inc
283,10 → 283,18
alloc_page, 'AllocPage', \ ; gcc ABI
alloc_pages, 'AllocPages', \ ; stdcall
commit_pages, 'CommitPages', \ ; eax, ebx, ecx
\
create_event, 'CreateEvent', \ ; ecx, esi
destroy_event, 'DestroyEvent', \ ;
raise_event, 'RaiseEvent', \ ; eax, ebx, edx, esi
wait_event, 'WaitEvent', \ ; eax, ebx
get_event_ex, 'GetEvent', \ ; edi
\
create_kernel_object, 'CreateObject', \
create_ring_buffer, 'CreateRingBuffer', \ ; stdcall
destroy_kernel_object, 'DestroyObject', \
free_kernel_space, 'FreeKernelSpace', \ ; stdcall
free_page, 'FreePage', \ ; eax
kernel_alloc, 'KernelAlloc', \ ; stdcall
kernel_free, 'KernelFree', \ ; stdcall
malloc, 'Kmalloc', \
294,9 → 302,14
map_io_mem, 'MapIoMem', \ ; stdcall
get_pg_addr, 'GetPgAddr', \ ; eax
\
mutex_init, 'MutexInit', \ ; gcc fastcall
mutex_lock, 'MutexLock', \ ; gcc fastcall
mutex_unlock, 'MutexUnlock', \ ; gcc fastcall
\
get_display, 'GetDisplay', \
set_screen, 'SetScreen', \
pci_api, 'PciApi', \
window._.get_rect, 'GetWindowRect', \ ; gcc fastcall
pci_api_drv, 'PciApi', \
pci_read8, 'PciRead8', \ ; stdcall
pci_read16, 'PciRead16', \ ; stdcall
pci_read32, 'PciRead32', \ ; stdcall
304,6 → 317,7
pci_write16, 'PciWrite16', \ ; stdcall
pci_write32, 'PciWrite32', \ ; stdcall
\
get_pid, 'GetPid', \
get_service, 'GetService', \ ;
reg_service, 'RegService', \ ; stdcall
attach_int_handler, 'AttachIntHandler', \ ; stdcall
311,8 → 325,12
user_free, 'UserFree', \ ; stdcall
unmap_pages, 'UnmapPages', \ ; eax, ecx
sys_msg_board_str, 'SysMsgBoardStr', \
get_timer_ticks, 'GetTimerTicks', \
get_stack_base, 'GetStackBase', \
delay_hs, 'Delay', \ ; ebx
set_mouse_data, 'SetMouseData'
set_mouse_data, 'SetMouseData', \ ;
set_keyboard_data, 'SetKeyboardData', \ ; gcc fastcall
timer_hs, 'TimerHs' ; stdcall
 
 
 
/kernel/branches/net/core/sched.inc
27,8 → 27,8
add [next_usage_update],100
call updatecputimes
.nocounter:
mov al,0x20 ; send End Of Interrupt signal
out 0x20,al
xor ecx, ecx ; send End Of Interrupt signal
call irq_eoi
btr dword[DONT_SWITCH], 0
jc .return
call find_next_task
60,7 → 60,8
end if
call find_next_task
jz .return ; the same task -> skip switch
@@: mov byte[DONT_SWITCH], 1
@@:
mov byte[DONT_SWITCH], 1
call do_change_task
.return:
popad
121,7 → 122,8
jb @f
xor bh, bh
mov edi,CURRENT_TASK
@@: inc bh ; ebx += APPDATA.size
@@:
inc bh ; ebx += APPDATA.size
add edi,0x20 ; edi += TASKDATA.size
mov al, [edi+TASKDATA.state]
test al, al
140,7 → 142,8
sub ecx, [ebx+APPDATA.wait_begin]
cmp ecx, [ebx+APPDATA.wait_timeout]
jb .loop
@@: mov [ebx+APPDATA.wait_param], eax ; retval for wait
@@:
mov [ebx+APPDATA.wait_param], eax ; retval for wait
mov [edi+TASKDATA.state], 0
.found:
mov [CURRENT_TASK],bh
214,10 → 217,96
mov reg,eax
} lodsReg dr0, dr1, dr2, dr3, dr7
purge lodsReg
@@: ret
@@:
ret
;end.
 
 
 
struct MUTEX_WAITER
list LHEAD
task dd ?
ends
 
;void __fastcall mutex_init(struct mutex *lock)
 
align 4
mutex_init:
mov [ecx+MUTEX.lhead.next], ecx
mov [ecx+MUTEX.lhead.prev], ecx
mov [ecx+MUTEX.count], 1
ret
 
 
;void __fastcall mutex_lock(struct mutex *lock)
 
align 4
mutex_lock:
 
dec [ecx+MUTEX.count]
jns .done
 
pushfd
cli
 
sub esp, sizeof.MUTEX_WAITER
 
list_add_tail esp, ecx ;esp= new waiter, ecx= list head
 
mov edx, [TASK_BASE]
mov [esp+MUTEX_WAITER.task], edx
 
.forever:
 
mov eax, -1
xchg eax, [ecx+MUTEX.count]
dec eax
jz @F
 
mov [edx+TASKDATA.state], 1
call change_task
jmp .forever
@@:
mov edx, [esp+MUTEX_WAITER.list.next]
mov eax, [esp+MUTEX_WAITER.list.prev]
 
mov [eax+MUTEX_WAITER.list.next], edx
mov [edx+MUTEX_WAITER.list.prev], eax
cmp [ecx+MUTEX.lhead.next], ecx
jne @F
 
mov [ecx+MUTEX.count], 0
@@:
add esp, sizeof.MUTEX_WAITER
 
popfd
.done:
ret
 
;void __fastcall mutex_unlock(struct mutex *lock)
 
align 4
mutex_unlock:
 
pushfd
cli
 
mov eax, [ecx+MUTEX.lhead.next]
cmp eax, ecx
mov [ecx+MUTEX.count], 1
je @F
 
mov eax, [eax+MUTEX_WAITER.task]
mov [eax+TASKDATA.state], 0
@@:
popfd
ret
 
 
purge MUTEX_WAITER
 
if 0
 
struc TIMER
{
.next dd ?
/kernel/branches/net/core/sys32.inc
20,7 → 20,8
mov esi, sys_int
mov ecx, 0x40
mov eax, (10001110b shl 24) + os_code
@@: movsw ;low word of code-entry
@@:
movsw ;low word of code-entry
stosd ;interrupt gate type : os_code selector
movsw ;high word of code-entry
loop @b
39,17 → 40,22
times 12 dd unknown_interrupt ;int_20..int_31
 
;interrupt handlers addresses (for interrupt gate construction)
; 0x20 .. 0x2F - IRQ handlers
dd irq0, irq_serv.irq_1, irq_serv.irq_2
if USE_COM_IRQ
dd irq_serv.irq_3, irq_serv.irq_4
else
dd p_irq3, p_irq4 ;??? íåñòûêîâêà
end if
dd irq_serv.irq_5, p_irq6, irq_serv.irq_7
dd irq_serv.irq_5, irq_serv.irq_6, irq_serv.irq_7
dd irq_serv.irq_8, irq_serv.irq_9, irq_serv.irq_10
dd irq_serv.irq_11, irq_serv.irq_12, irqD,p_irq14,p_irq15
times 16 dd unknown_interrupt ;int_0x30..int_0x3F
dd irq_serv.irq_11, irq_serv.irq_12, irqD, irq_serv.irq_14, irq_serv.irq_15
dd irq_serv.irq_16
dd irq_serv.irq_17
dd irq_serv.irq_18
dd irq_serv.irq_19
dd irq_serv.irq_20
dd irq_serv.irq_21
dd irq_serv.irq_22
dd irq_serv.irq_23
 
times 32 - IRQ_RESERVED dd unknown_interrupt
;int_0x40 gate trap (for directly copied)
dw i40 and 0xFFFF, os_code, 11101111b shl 8, i40 shr 16
 
122,8 → 128,9
reg_esi equ esp+0x04
reg_edi equ esp+0x00
 
Mov ds,ax,app_data ; çàãðóçèì ïðàâèëüíûå çíà÷åíèÿ
mov es,ax ; â ñåãìåíòíûå ðåãèñòðû
mov ax, app_data ;èñêëþ÷åíèå
mov ds, ax ;çàãðóçèì ïðàâèëüíûå çíà÷åíèÿ
mov es, ax ;â ðåãèñòðû
cld ; è ïðèâîäèì DF ê ñòàíäàðòó
movzx ebx,bl
; redirect to V86 manager? (EFLAGS & 0x20000) != 0?
132,13 → 139,15
cmp bl,14 ; #PF
jne @f
call page_fault_handler ; SEE: core/memory.inc
@@: mov esi, [current_slot]
@@:
mov esi, [current_slot]
btr [esi+APPDATA.except_mask], ebx
jnc @f
mov eax,[esi+APPDATA.exc_handler]
test eax, eax
jnz IRetToUserHook
@@: cli
@@:
cli
mov eax, [esi+APPDATA.debugger_slot]
test eax, eax
jnz .debug
159,10 → 168,12
mov dr6, edx
mov edx, dr7
mov cl, not 8
.l1: shl dl,2
.l1:
shl dl, 2
jc @f
and bl, cl
@@: sar cl,1
@@:
sar cl, 1
jc .l1
mov cl, 3 ; debug_message code=debug_exception
.notify:
186,11 → 197,21
stosd
mov [edi], ebx
restore_ring3_context
; simply return control to interrupted process
unknown_interrupt:
iretd
 
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; bl - error vector
show_error_parameters:
cmp bl, 0x06
jnz .no_ud
push ebx
mov ebx, ud_user_message
mov ebp, notifyapp
call fs_execute_from_sysdir_param
pop ebx
.no_ud:
mov edx,[TASK_BASE] ;not scratched below
DEBUGF 1, "K : Process - forced terminate PID: %x\n", [edx+TASKDATA.pid]
cmp bl, 0x08
197,8 → 218,10
jb .l0
cmp bl, 0x0e
jbe .l1
.l0: mov bl, 0x09
.l1: mov eax,[msg_fault_sel+ebx*4 - 0x08*4]
.l0:
mov bl, 0x09
.l1:
mov eax, [msg_fault_sel+ebx*4 - 0x08*4]
DEBUGF 1, "K : %s\n", eax
mov eax, [reg_cs3+4]
mov edi, msg_sel_app
207,7 → 230,8
je @f
mov edi, msg_sel_ker
mov ebx, [reg_esp0+4]
@@: DEBUGF 1, "K : EAX : %x EBX : %x ECX : %x\n", [reg_eax+4], [reg_ebx+4], [reg_ecx+4]
@@:
DEBUGF 1, "K : EAX : %x EBX : %x ECX : %x\n", [reg_eax+4], [reg_ebx+4], [reg_ecx+4]
DEBUGF 1, "K : EDX : %x ESI : %x EDI : %x\n", [reg_edx+4], [reg_esi+4], [reg_edi+4]
DEBUGF 1, "K : EBP : %x EIP : %x ESP : %x\n", [reg_ebp+4], [reg_eip+4], ebx
DEBUGF 1, "K : Flags : %x CS : %x (%s)\n", [reg_eflags+4], eax, edi
228,154 → 252,8
restore reg_esi
restore reg_edi
 
; irq1 -> hid/keyboard.inc
macro irqh [num] {
p_irq#num :
mov edi, num
jmp irqhandler
}
 
 
 
p_irq6:
save_ring3_context
mov ax, app_data ;os_data
mov ds, ax
mov es, ax
mov edi, 6
cmp [v86_irqhooks+edi*8], 0
jnz v86_irq2
call fdc_irq
call ready_for_next_irq
restore_ring3_context
iret
 
 
p_irq14:
save_ring3_context
mov ax, app_data ;os_data
mov ds, ax
mov es, ax
mov edi, 14
cmp [v86_irqhooks+edi*8], 0
jnz v86_irq2
; mov byte [BOOT_VAR + 0x48E], 0xFF
call [irq14_func]
call ready_for_next_irq_1
restore_ring3_context
iret
p_irq15:
save_ring3_context
mov ax, app_data ;os_data
mov ds, ax
mov es, ax
mov edi, 15
cmp [v86_irqhooks+edi*8], 0
jnz v86_irq2
; mov byte [BOOT_VAR + 0x48E], 0xFF
call [irq15_func]
call ready_for_next_irq_1
restore_ring3_context
iret
 
ready_for_next_irq:
mov eax,5
mov [check_idle_semaphore],eax
; mov al, 0x20
add eax,(0x20-0x5)
 
out 0x20, al
ret
;destroy eax
ready_for_next_irq_1:
mov eax,5
mov [check_idle_semaphore],eax
; mov al, 0x20
add eax,(0x20-0x5)
out 0xa0,al
out 0x20, al
ret
 
irqD:
push eax
xor eax,eax
out 0xf0,al
mov al,0x20
out 0xa0,al
out 0x20,al
pop eax
iret
 
 
irqh 2,3,4,5,7,8,9,10,11
 
irqhandler:
 
mov esi,edi ; 1
shl esi,6 ; 1
add esi,irq00read ; 1
shl edi,12 ; 1
add edi,IRQ_SAVE
mov ecx,16
 
irqnewread:
dec ecx
js irqover
 
movzx edx, word [esi] ; 2+
 
test edx, edx ; 1
jz irqover
 
 
mov ebx, [edi] ; address of begin of buffer in edi ; + 0x0 dword - data size
mov eax, 4000 ; + 0x4 dword - data begin offset
cmp ebx, eax
je irqfull
add ebx, [edi + 0x4] ; add data size to data begin offset
cmp ebx, eax ; if end of buffer, begin cycle again
jb @f
 
xor ebx, ebx
 
@@:
add ebx, edi
movzx eax, byte[esi + 3] ; get type of data being received 1 - byte, 2 - word
dec eax
jz irqbyte
dec eax
jnz noirqword
 
in ax,dx
cmp ebx, 3999 ; check for address odd in the end of buffer
jne .odd
mov [ebx + 0x10], ax
jmp .add_size
.odd:
mov [ebx + 0x10], al ; I could make mistake here :)
mov [edi + 0x10], ah
.add_size:
add dword [edi], 2
jmp nextport
 
 
irqbyte:
in al,dx
mov [ebx + 0x10],al
inc dword [edi]
nextport:
add esi,4
jmp irqnewread
 
 
noirqword:
irqfull:
irqover:
 
ret
 
 
 
align 4
set_application_table_status:
push eax
 
390,7 → 268,7
 
ret
 
 
align 4
clear_application_table_status:
push eax
 
416,6 → 294,7
; * eax = 0 - óñïåøíî
; * eax = 1 - íåäîñòàòî÷íî ïàìÿòè
 
align 4
sys_resize_app_memory:
; ebx = 1 - resize
; ecx = new amount of memory
437,6 → 316,7
; param
; esi= slot
 
align 4
terminate: ; terminate application
 
.slot equ esp ;locals
708,25 → 588,6
and [bgrlock], 0
@@:
 
pusha ; remove all irq reservations
mov eax,esi
shl eax, 5
mov eax,[eax+CURRENT_TASK+TASKDATA.pid]
mov edi,irq_owner
xor ebx, ebx
xor edx, edx
newirqfree:
cmp [edi + 4 * ebx], eax
jne nofreeirq
mov [edi + 4 * ebx], edx ; remove irq reservation
mov [irq_tab + 4 * ebx], edx ; remove irq handler
mov [irq_rights + 4 * ebx], edx ; set access rights to full access
nofreeirq:
inc ebx
cmp ebx, 16
jb newirqfree
popa
 
pusha ; remove all port reservations
mov edx,esi
shl edx, 5
812,17 → 673,18
and [application_table_status],0
;mov esi,process_terminated
;call sys_msg_board_str
 
mov eax, [.slot]
call SOCKET_process_end
 
add esp, 4
ret
restore .slot
 
iglobal
if lang eq ru
boot_sched_1 db '‘®§¤ ­¨¥ GDT TSS 㪠§ â¥«ï',0
boot_sched_2 db '‘®§¤ ­¨¥ IDT â ¡«¨æë',0
else
boot_sched_1 db 'Building gdt tss pointer',0
boot_sched_2 db 'Building IDT table',0
end if
endg
 
 
/kernel/branches/net/core/syscall.inc
1,6 → 1,6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17,6 → 17,7
mov edx, esi
mov esi, edi
movzx edi, byte[esp+28 + 4]
sub edi, 53
call dword [servetable+edi*4]
ret
 
101,78 → 102,17
 
align 4
servetable:
 
dd 0
dd 0
dd 0
dd 0
dd 0
dd file_system ; 58-Common file system interface
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd 0
dd sound_interface ; 55-Sound interface
dd 0
dd 0
dd file_system ; 58-Common file system interface
dd 0
dd sys_IPC ; 60-Inter Process Communication
dd sys_gs ; 61-Direct graphics access
dd sys_pci ; 62-PCI functions
dd 0 ; 62-PCI functions
dd sys_msg_board ; 63-System message board
dd 0
dd syscall_putimage_palette; 65-PutImagePalette
dd sys_process_def ; 66-Process definitions - keyboard
dd sys_window_move ; 67-Window move or resize
dd 0
dd 0
dd file_system_lfn ; 70-Common file system interface, version 2
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NEW SYSTEM FUNCTIONS TABLE ;;
180,7 → 120,7
align 4
servetable2:
 
dd sys_drawwindow ; 0-DrawWindow
dd syscall_draw_window ; 0-DrawWindow
dd syscall_setpixel ; 1-SetPixel
dd sys_getkey ; 2-GetKey
dd sys_clock ; 3-GetTime
221,11 → 161,11
dd syscall_drawline ; 38-DrawLine
dd sys_getbackground ; 39-GetBackgroundSize,ReadBgrData,.
dd set_app_param ; 40-WantEvents
dd syscall_getirqowner ; 41-GetIrqOwner
dd get_irq_data ; 42-ReadIrqData
dd undefined_syscall ; 41- deprecated GetIrqOwner
dd undefined_syscall ; 42- deprecated ReadIrqData
dd sys_outport ; 43-SendDeviceData
dd sys_programirq ; 44-ProgramIrqs
dd reserve_free_irq ; 45-ReserveIrq and FreeIrq
dd undefined_syscall ; 44- deprecated ProgramIrqs
dd undefined_syscall ; 45- deprecated ReserveIrq and FreeIrq
dd syscall_reserveportarea ; 46-ReservePortArea and FreePortArea
dd display_number ; 47-WriteNum
dd syscall_display_settings ; 48-SetRedrawType and SetButtonType
232,28 → 172,28
dd sys_apm ; 49-Advanced Power Management (APM)
dd syscall_set_window_shape ; 50-Window shape & scale
dd syscall_threads ; 51-Threads
dd undefined_syscall ; 52-Stack driver status
dd undefined_syscall ; 53-Socket interface
dd undefined_syscall ; 52 old network stack
dd undefined_syscall ; 53 old network stack
dd undefined_syscall ; 54-reserved
dd cross_order ; 55-Sound interface
dd sound_interface ; 55-Sound interface
dd undefined_syscall ; 56-reserved
dd sys_pcibios ; 57-PCI BIOS32
dd cross_order ; 58-Common file system interface
dd undefined_syscall ; 59-reserved
dd cross_order ; 60-Inter Process Communication
dd cross_order ; 61-Direct graphics access
dd cross_order ; 62-PCI functions
dd sys_IPC ; 60-Inter Process Communication
dd sys_gs ; 61-Direct graphics access
dd pci_api ;cross_order ; 62-PCI functions
dd cross_order ; 63-System message board
dd sys_resize_app_memory ; 64-Resize application memory usage
dd cross_order ; 65-PutImagePalette
dd cross_order ; 66-Process definitions - keyboard
dd cross_order ; 67-Window move or resize
dd sys_putimage_palette ; 65-PutImagePalette
dd sys_process_def ; 66-Process definitions - keyboard
dd syscall_move_window ; 67-Window move or resize
dd f68 ; 68-Some internal services
dd sys_debug_services ; 69-Debug
dd cross_order ; 70-Common file system interface, version 2
dd syscall_windowsettings ; 71-Window settings
dd file_system_lfn ; 70-Common file system interface, version 2
dd syscall_window_settings ; 71-Window settings
dd sys_sendwindowmsg ; 72-Send window message
dd undefined_syscall ; 73-reserved for blitter
dd blit_32 ; 73-blitter;
dd sys_network ; 74-Network stack
dd sys_socket ; 75-Sockets
dd sys_protocols ; 76-Protocols
/kernel/branches/net/core/taskman.inc
48,6 → 48,7
 
fs_execute_from_sysdir:
xor ebx, ebx
fs_execute_from_sysdir_param:
xor edx, edx
mov esi, sysdir_path
 
126,7 → 127,7
@@:
lea eax, [filename]
stdcall load_file, eax
mov ecx, -ERROR_FILE_NOT_FOUND
mov esi, -ERROR_FILE_NOT_FOUND
test eax, eax
jz .err_file
 
135,13 → 136,10
 
lea ebx, [hdr_cmdline]
call test_app_header
mov ecx, -0x1F
mov esi, -0x1F
test eax, eax
jz .err_hdr
 
;mov esi, new_process_loading
;call sys_msg_board_str ; write message to message board
 
.wait_lock:
cmp [application_table_status],0
je .get_lock
158,7 → 156,7
 
call get_new_process_place
test eax, eax
mov ecx, -0x20 ; too many processes
mov esi, -0x20 ; too many processes
jz .err
 
mov [slot], eax
193,7 → 191,7
mov [save_cr3], ebx
 
stdcall create_app_space,[hdr_mem],[file_base],[file_size]
mov ecx, -30 ; no memory
mov esi, -30; no memory
test eax, eax
jz .failed
 
249,7 → 247,7
.err_file:
xor eax, eax
mov [application_table_status],eax
mov eax, ecx
mov eax, esi
ret
endp
 
359,8 → 357,8
app_tabs dd ?
endl
 
mov ebx, pg_data.pg_mutex
call wait_mutex ;ebx
mov ecx, pg_data.mutex
call mutex_lock
 
xor eax, eax
mov [dir_addr], eax
479,11 → 477,13
.done:
stdcall map_page,[tmp_task_pdir],dword 0,dword PG_UNMAP
 
dec [pg_data.pg_mutex]
mov ecx, pg_data.mutex
call mutex_unlock
mov eax, [dir_addr]
ret
.fail:
dec [pg_data.pg_mutex]
mov ecx, pg_data.mutex
call mutex_unlock
cmp [dir_addr], 0
je @f
stdcall destroy_app_space, [dir_addr], 0
553,10 → 553,10
jg .ret
;if there isn't threads then clear memory.
mov esi, [dlls_list]
call destroy_all_hdlls
call destroy_all_hdlls;ecx=APPDATA
 
mov ebx, pg_data.pg_mutex
call wait_mutex ;ebx
mov ecx, pg_data.mutex
call mutex_lock
 
mov eax, [pg_dir]
and eax, not 0xFFF
582,7 → 582,8
.exit:
stdcall map_page,[tmp_task_ptab],0,PG_UNMAP
stdcall map_page,[tmp_task_pdir],0,PG_UNMAP
dec [pg_data.pg_mutex]
mov ecx, pg_data.mutex
call mutex_unlock
.ret:
ret
endp
955,25 → 956,7
ret
endp
 
; param
; ebx=mutex
 
align 4
wait_mutex:
;;Maxis use atomic bts for mutex 4.4.2009
push eax
push ebx
.do_wait:
bts dword [ebx],0
jnc .locked
call change_task
jmp .do_wait
.locked:
pop ebx
pop eax
ret
 
align 4
tls_app_entry:
 
call init_heap
1166,4 → 1149,13
ret
endp
 
 
align 4
 
get_stack_base:
mov eax, [current_slot]
mov eax, [eax+APPDATA.pl0_stack]
ret
 
 
include "debug.inc"
/kernel/branches/net/core/timers.inc
0,0 → 1,205
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2011. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
$Revision: 2381 $
 
; Simple implementation of timers. All timers are organized in a double-linked
; list, and the OS loop after every timer tick processes the list.
 
; This structure describes a timer for the kernel.
struct TIMER
Next dd ?
Prev dd ?
; These fields organize a double-linked list of all timers.
TimerFunc dd ?
; Function to be called when the timer is activated.
UserData dd ?
; The value that is passed as is to .TimerFunc.
Time dd ?
; Time at which the timer should be activated.
Interval dd ?
; Interval between activations of the timer, in 0.01s.
ends
 
iglobal
align 4
; The head of timer list.
timer_list:
dd timer_list
dd timer_list
endg
uglobal
; These two variables are used to synchronize access to the global list.
; Logically, they form an recursive mutex. Physically, the first variable holds
; the slot number of the current owner or 0, the second variable holds the
; recursion count.
; The mutex should be recursive to allow a timer function to add/delete other
; timers or itself.
timer_list_owner dd 0
timer_list_numlocks dd 0
; A timer function can delete any timer, including itself and the next timer in
; the chain. To handle such situation correctly, we keep the next timer in a
; global variable, so the removing operation can update it.
timer_next dd 0
endg
 
; This internal function acquires the lock for the global list.
lock_timer_list:
mov edx, [CURRENT_TASK]
@@:
xor eax, eax
lock cmpxchg [timer_list_owner], edx
jz @f
cmp eax, edx
jz @f
call change_task
jmp @b
@@:
inc [timer_list_numlocks]
ret
 
; This internal function releases the lock for the global list.
unlock_timer_list:
dec [timer_list_numlocks]
jnz .nothing
mov [timer_list_owner], 0
.nothing:
ret
 
; This function adds a timer.
; If deltaStart is nonzero, the timer is activated after deltaStart hundredths
; of seconds starting from the current time. If interval is nonzero, the timer
; is activated every deltaWork hundredths of seconds starting from the first
; activation. The activated timer calls timerFunc as stdcall function with one
; argument userData.
; Return value is NULL if something has failed or some value which is opaque
; for the caller. Later this value can be used for cancel_timer_hs.
proc timer_hs stdcall uses ebx, deltaStart:dword, interval:dword, \
timerFunc:dword, userData:dword
; 1. Allocate memory for the TIMER structure.
; 1a. Call the allocator.
push sizeof.TIMER
pop eax
call malloc
; 1b. If allocation failed, return (go to 5) with eax = 0.
test eax, eax
jz .nothing
; 2. Setup the TIMER structure.
xchg ebx, eax
; 2a. Copy values from the arguments.
mov ecx, [interval]
mov [ebx+TIMER.Interval], ecx
mov ecx, [timerFunc]
mov [ebx+TIMER.TimerFunc], ecx
mov ecx, [userData]
mov [ebx+TIMER.UserData], ecx
; 2b. Get time of the next activation.
mov ecx, [deltaStart]
test ecx, ecx
jnz @f
mov ecx, [interval]
@@:
add ecx, [timer_ticks]
mov [ebx+TIMER.Time], ecx
; 3. Insert the TIMER structure to the global list.
; 3a. Acquire the lock.
call lock_timer_list
; 3b. Insert an item at ebx to the tail of the timer_list.
mov eax, timer_list
mov ecx, [eax+TIMER.Prev]
mov [ebx+TIMER.Next], eax
mov [ebx+TIMER.Prev], ecx
mov [eax+TIMER.Prev], ebx
mov [ecx+TIMER.Next], ebx
; 3c. Release the lock.
call unlock_timer_list
; 4. Return with eax = pointer to TIMER structure.
xchg ebx, eax
.nothing:
; 5. Returning.
ret
endp
 
; This function removes a timer.
; The only argument is [esp+4] = the value which was returned from timer_hs.
cancel_timer_hs:
push ebx ; save used register to be stdcall
; 1. Remove the TIMER structure from the global list.
; 1a. Acquire the lock.
call lock_timer_list
mov ebx, [esp+4+4]
; 1b. Delete an item at ebx from the double-linked list.
mov eax, [ebx+TIMER.Next]
mov ecx, [ebx+TIMER.Prev]
mov [eax+TIMER.Prev], ecx
mov [ecx+TIMER.Next], eax
; 1c. If we are removing the next timer in currently processing chain,
; the next timer for this timer becomes new next timer.
cmp ebx, [timer_next]
jnz @f
mov [timer_next], eax
@@:
; 1d. Release the lock.
call unlock_timer_list
; 2. Free the TIMER structure.
xchg eax, ebx
call free
; 3. Return.
pop ebx ; restore used register to be stdcall
ret 4 ; purge one dword argument to be stdcall
 
; This function is regularly called from osloop. It processes the global list
; and activates the corresponding timers.
check_timers:
; 1. Acquire the lock.
call lock_timer_list
; 2. Loop over all registered timers, checking time.
; 2a. Get the first item.
mov eax, [timer_list+TIMER.Next]
mov [timer_next], eax
.loop:
; 2b. Check for end of list.
cmp eax, timer_list
jz .done
; 2c. Get and store the next timer.
mov edx, [eax+TIMER.Next]
mov [timer_next], edx
; 2d. Check time for timer activation.
; We can't just compare [timer_ticks] and [TIMER.Time], since overflows are
; possible: if the current time is 0FFFFFFFFh ticks and timer should be
; activated in 3 ticks, the simple comparison will produce incorrect result.
; So we calculate the difference [timer_ticks] - [TIMER.Time]; if it is
; non-negative, the time is over; if it is negative, then either the time is
; not over or we have not processed this timer for 2^31 ticks, what is very
; unlikely.
mov edx, [timer_ticks]
sub edx, [eax+TIMER.Time]
js .next
; The timer should be activated now.
; 2e. Store the timer data in the stack. This is required since 2f can delete
; the timer, invalidating the content.
push [eax+TIMER.UserData] ; parameter for TimerFunc
push [eax+TIMER.TimerFunc] ; to be restored in 2g
; 2f. Calculate time of next activation or delete the timer if it is one-shot.
mov ecx, [eax+TIMER.Interval]
add [eax+TIMER.Time], ecx
test ecx, ecx
jnz .nodelete
stdcall cancel_timer_hs, eax
.nodelete:
; 2g. Activate timer, using data from the stack.
pop eax
call eax
.next:
; 2h. Advance to the next timer and continue the loop.
mov eax, [timer_next]
jmp .loop
.done:
; 3. Release the lock.
call unlock_timer_list
; 4. Return.
ret
/kernel/branches/net/core/v86.inc
91,10 → 91,10
; now V86 specific: initialize known addresses in first Mb
pop eax
; first page - BIOS data (shared between all machines!)
; physical address = 0x2f0000
; linear address = BOOT_VAR = OS_BASE + 0x2f0000
mov dword [eax], (BOOT_VAR - OS_BASE) or 111b
mov dword [eax+800h], BOOT_VAR
; physical address = 0
; linear address = OS_BASE
mov dword [eax], 111b
mov dword [eax+800h], OS_BASE
; page before 0xA0000 - Extended BIOS Data Area (shared between all machines!)
; physical address = 0x9C000
; linear address = 0x8009C000
219,12 → 219,12
mov [sys_v86_machine], eax
test eax, eax
jz .ret
mov byte [BOOT_VAR + 0x500], 0xCD
mov byte [BOOT_VAR + 0x501], 0x13
mov byte [BOOT_VAR + 0x502], 0xF4
mov byte [BOOT_VAR + 0x503], 0xCD
mov byte [BOOT_VAR + 0x504], 0x10
mov byte [BOOT_VAR + 0x505], 0xF4
mov byte [OS_BASE + 0x500], 0xCD
mov byte [OS_BASE + 0x501], 0x13
mov byte [OS_BASE + 0x502], 0xF4
mov byte [OS_BASE + 0x503], 0xCD
mov byte [OS_BASE + 0x504], 0x10
mov byte [OS_BASE + 0x505], 0xF4
mov esi, eax
mov ebx, [eax+V86_machine.pagedir]
; one page for stack, two pages for results (0x2000 bytes = 16 sectors)
328,7 → 328,7
cmp edx, -1
jz .noirqhook
uglobal
v86_irqhooks rd 16*2
v86_irqhooks rd IRQ_RESERVED * 2
endg
cmp [v86_irqhooks+edx*8], 0
jz @f
371,7 → 371,8
jne @f
xor eax, eax
mov dr6, eax
@@: mov eax, [esp+v86_regs.size+10h+18h]
@@:
mov eax, [esp+v86_regs.size+10h+18h]
cmp word [esp+v86_regs.eip], ax
jnz @f
shr eax, 16
805,7 → 806,6
mov dword [SLOT_BASE+ecx+APPDATA.io_map], ebx
mov dword [page_tabs + (tss._io_map_0 shr 10)], ebx
mov cr3, eax
; mov [irq_tab+5*4], 0
sti
 
popad
839,9 → 839,10
; mov byte [BOOT_VAR + 48Eh], 0FFh
; ret
 
align 4
v86_irq:
; push irq/pushad/jmp v86_irq
; eax = irq
; ebp = irq
lea esi, [esp+1Ch]
lea edi, [esi+4]
mov ecx, 8
848,7 → 849,7
std
rep movsd
cld
mov edi, eax
mov edi, ebp
pop eax
v86_irq2:
mov esi, [v86_irqhooks+edi*8] ; get VM handle
898,12 → 899,8
pop ecx
.cont:
loop .scan
mov al, 20h
out 20h, al
cmp edi, 8
jb @f
out 0A0h, al
@@:
mov ecx, edi
call irq_eoi
popad
iretd
.found: