diff --git a/kernel/trunk/core/apic.inc b/kernel/trunk/core/apic.inc index 755796f10b..0e0c5ebdfc 100644 --- a/kernel/trunk/core/apic.inc +++ b/kernel/trunk/core/apic.inc @@ -5,60 +5,35 @@ ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -align 4 -pic_delay: - - jmp pdl1 -pdl1: ret - align 4 rerouteirqs: cli - mov al,0x11 ; icw4, edge triggered out 0x20,al - call pic_delay out 0xA0,al - call pic_delay mov al,0x20 ; generate 0x20 + out 0x21,al - call pic_delay mov al,0x28 ; generate 0x28 + out 0xA1,al - call pic_delay mov al,0x04 ; slave at irq2 out 0x21,al - call pic_delay mov al,0x02 ; at irq9 out 0xA1,al - call pic_delay mov al,0x01 ; 8086 mode out 0x21,al - call pic_delay out 0xA1,al - call pic_delay mov al,255 ; mask all irq's out 0xA1,al - call pic_delay out 0x21,al - call pic_delay - - mov ecx,0x1000 - cld -picl1: call pic_delay - loop picl1 mov al,255 ; mask all irq's out 0xA1,al - call pic_delay out 0x21,al - call pic_delay - ret diff --git a/kernel/trunk/core/heap.inc b/kernel/trunk/core/heap.inc index 5c7fe45eb4..5b28803698 100644 --- a/kernel/trunk/core/heap.inc +++ b/kernel/trunk/core/heap.inc @@ -46,15 +46,67 @@ macro calc_index op @@: } -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 -} +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] + + 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 + + lea ebx, [mem_used_list+ecx*8] + mov esi, ebx +.next: + mov esi, [esi+list_fd] + cmp esi, ebx + je .fail + + 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 ; @@ -74,9 +126,13 @@ proc init_kernel_heap stosd loop @B - mov eax, mem_used.fd - mov [mem_used.fd], eax - mov [mem_used.bk], eax + mov ecx, 64 + mov edi, mem_used_list +@@: + mov eax, edi + stosd + stosd + loop @B stdcall alloc_pages, dword 32 mov ecx, 32 @@ -139,7 +195,6 @@ proc init_kernel_heap mov [eax-MEM_BLOCK.sizeof], dword 0 - mov ecx, heap_mutex call mutex_init mov [heap_blocks], 4094 @@ -279,7 +334,7 @@ proc alloc_kernel_space stdcall, size:dword mov eax, [edi+block_size] calc_index eax cmp eax, [block_ind] - je .m_eq_ind + je .add_used list_del edi @@ -292,17 +347,10 @@ proc alloc_kernel_space stdcall, size:dword bts [mem_block_mask], eax lea edx, [mem_block_list+eax*8] ;edx= list head list_add edi, edx -.m_eq_ind: - mov ecx, mem_used.fd - 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 +.add_used: + + call md.add_to_used - mov [esi+block_flags], USED_BLOCK - mov ebx, [size] - sub [heap_free], ebx mov ecx, heap_mutex call mutex_unlock mov eax, [esi+block_base] @@ -310,6 +358,7 @@ proc alloc_kernel_space stdcall, size:dword pop esi pop ebx ret + .m_eq_size: list_del edi lea edx, [mem_block_list+ebx*8] @@ -317,23 +366,8 @@ proc alloc_kernel_space stdcall, size:dword jnz @f btr [mem_block_mask], ebx @@: - mov ecx, mem_used.fd - 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 [edi+block_flags], USED_BLOCK - mov ebx, [size] - sub [heap_free], ebx - mov ecx, heap_mutex - call mutex_unlock - mov eax, [edi+block_base] - pop edi - pop esi - pop ebx - ret + mov esi, edi + jmp .add_used .error_unlock: mov ecx, heap_mutex @@ -353,18 +387,10 @@ proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword call mutex_lock mov eax, [base] - mov esi, [mem_used.fd] -@@: - cmp esi, mem_used.fd - 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 @@ -395,8 +421,6 @@ proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword cmp [edi+block_flags], FREE_BLOCK jne .insert - remove_from_used esi - mov edx, [esi+block_next] mov [edi+block_next], edx mov [edx+block_prev], edi @@ -433,7 +457,6 @@ proc free_kernel_space stdcall uses ebx ecx edx esi edi, base:dword not eax ret .insert: - remove_from_used esi mov [esi+block_flags], FREE_BLOCK mov eax, [esi+block_size] calc_index eax @@ -523,22 +546,16 @@ endp align 4 proc kernel_free stdcall, base:dword + push ebx esi mov ecx, heap_mutex call mutex_lock mov eax, [base] - mov esi, [mem_used.fd] -@@: - cmp esi, mem_used.fd - 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 diff --git a/kernel/trunk/core/peload.inc b/kernel/trunk/core/peload.inc index 809926d93f..9856b070ac 100644 --- a/kernel/trunk/core/peload.inc +++ b/kernel/trunk/core/peload.inc @@ -314,6 +314,7 @@ __exports: pci_write16, 'PciWrite16', \ ; stdcall pci_write32, 'PciWrite32', \ ; stdcall \ + get_pid, 'GetPid', \ get_service, 'GetService', \ ; reg_service, 'RegService', \ ; stdcall attach_int_handler, 'AttachIntHandler', \ ; stdcall diff --git a/kernel/trunk/core/sched.inc b/kernel/trunk/core/sched.inc index f2fa695ea3..7612a0df94 100644 --- a/kernel/trunk/core/sched.inc +++ b/kernel/trunk/core/sched.inc @@ -27,7 +27,7 @@ irq0: add [next_usage_update],100 call updatecputimes .nocounter: - xor ecx, ecx + xor ecx, ecx ; send End Of Interrupt signal call irq_eoi btr dword[DONT_SWITCH], 0 jc .return diff --git a/kernel/trunk/core/sys32.inc b/kernel/trunk/core/sys32.inc index a05ccbf469..210a37450f 100644 --- a/kernel/trunk/core/sys32.inc +++ b/kernel/trunk/core/sys32.inc @@ -120,8 +120,9 @@ exc_c: ; 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? diff --git a/kernel/trunk/core/v86.inc b/kernel/trunk/core/v86.inc index 1b8d984230..1c96fe475b 100644 --- a/kernel/trunk/core/v86.inc +++ b/kernel/trunk/core/v86.inc @@ -805,7 +805,6 @@ end if 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 diff --git a/kernel/trunk/data32.inc b/kernel/trunk/data32.inc index 98c555c2c4..cf4c866162 100644 --- a/kernel/trunk/data32.inc +++ b/kernel/trunk/data32.inc @@ -298,21 +298,19 @@ cur_saved_data rb 4096 fpu_data: rb 512 mem_block_list rd 64*2 -mem_block_mask rd 2 - -mem_used.fd rd 1 -mem_used.bk rd 1 - +mem_used_list rd 64*2 mem_hash_cnt rd 64 -next_memblock rd 1 - heap_mutex MUTEX heap_size rd 1 heap_free rd 1 heap_blocks rd 1 free_blocks rd 1 +mem_block_mask rd 2 +next_memblock rd 1 + + mst MEM_STATE page_start rd 1 diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index 54d3a15c51..5eb6dc103a 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -922,7 +922,7 @@ first_app_found: and al,00000010b loopnz @b - ; mov al, 0xED ; svetodiody - only for testing! + ; mov al, 0xED ; Keyboard LEDs - only for testing! ; call kb_write ; call kb_read ; mov al, 111b @@ -992,27 +992,6 @@ if preboot_blogesc jne .bll1 end if -; mov [ENABLE_TASKSWITCH],byte 1 ; multitasking enabled - -; UNMASK ALL IRQ'S - -; mov esi,boot_allirqs -; call boot_log -; -; cli ;guarantee forbidance of interrupts. -; mov al,0 ; unmask all irq's -; out 0xA1,al -; out 0x21,al -; -; mov ecx,32 -; -; ready_for_irqs: -; -; mov al,0x20 ; ready for irqs -; out 0x20,al -; out 0xa0,al -; -; loop ready_for_irqs ; flush the queue stdcall attach_int_handler, 1, irq1, 0 @@ -1158,8 +1137,9 @@ endg set_variables: - mov ecx,0x100 ; flush port 0x60 -.fl60: in al,0x60 + mov ecx,0x16 ; flush port 0x60 +.fl60: + in al,0x60 loop .fl60 push eax @@ -4126,8 +4106,6 @@ _rdtsc: ret end if - - sys_msg_board_str: pushad