From ed2e35a24c5d079f3d038fa3c7720f8768bf0b29 Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Fri, 4 Jul 2008 20:44:53 +0000 Subject: [PATCH] 1) unmap_pages 2) code cleanup git-svn-id: svn://kolibrios.org@819 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/core/dll.inc | 8 ++-- kernel/trunk/core/exports.inc | 2 +- kernel/trunk/core/heap.inc | 12 +++--- kernel/trunk/core/memory.inc | 77 +++++++++++++++++++++++++--------- kernel/trunk/core/peload.inc | 6 ++- kernel/trunk/core/taskman.inc | 15 +++---- kernel/trunk/drivers/ati2d.asm | 2 +- kernel/trunk/video/cursors.inc | 2 - 8 files changed, 78 insertions(+), 46 deletions(-) diff --git a/kernel/trunk/core/dll.inc b/kernel/trunk/core/dll.inc index 8f0b1c797b..d54157fc61 100644 --- a/kernel/trunk/core/dll.inc +++ b/kernel/trunk/core/dll.inc @@ -388,7 +388,9 @@ endp align 4 proc reg_service stdcall, name:dword, handler:dword - xor eax, eax + push ebx + + xor eax, eax cmp [name], eax je .fail @@ -396,14 +398,11 @@ proc reg_service stdcall, name:dword, handler:dword cmp [handler], eax je .fail - push ebx mov eax, SRV_SIZE call malloc ;call alloc_service - pop ebx test eax, eax jz .fail - push ebx push esi push edi mov edi, eax @@ -429,6 +428,7 @@ proc reg_service stdcall, name:dword, handler:dword ret .fail: xor eax, eax + pop ebx ret endp diff --git a/kernel/trunk/core/exports.inc b/kernel/trunk/core/exports.inc index a79ff1b036..61812fc160 100644 --- a/kernel/trunk/core/exports.inc +++ b/kernel/trunk/core/exports.inc @@ -121,7 +121,7 @@ kernel_export: dd szUserFree , user_free ;stdcall dd szKmalloc , malloc dd szKfree , free - dd szCreateRingBuffer, create_ring_buffer + dd szCreateRingBuffer, create_ring_buffer ;stdcall dd szGetPid , get_pid dd szCreateObject , create_kernel_object diff --git a/kernel/trunk/core/heap.inc b/kernel/trunk/core/heap.inc index c54c97710a..89933a3e8b 100644 --- a/kernel/trunk/core/heap.inc +++ b/kernel/trunk/core/heap.inc @@ -164,7 +164,7 @@ endp ; ebx= descriptor index align 4 -get_block: +get_small_block: mov ecx, eax shr ecx, 12 dec ecx @@ -211,7 +211,7 @@ get_block: ret align 4 -proc alloc_mem_block +alloc_mem_block: mov ebx, [mem_block_start] mov ecx, [mem_block_end] @@ -233,9 +233,8 @@ found: add eax, [mem_block_arr] dec [free_blocks] ret -endp - -proc free_mem_block +align 4 +free_mem_block: mov dword [eax], 0 mov dword [eax+4], 0 mov dword [eax+8], 0 @@ -263,7 +262,6 @@ proc free_mem_block .err: xor eax, eax ret -endp align 4 proc alloc_kernel_space stdcall, size:dword @@ -284,7 +282,7 @@ proc alloc_kernel_space stdcall, size:dword cmp eax, [heap_free] ja .error - call get_block ; eax + call get_small_block ; eax test edi, edi jz .error diff --git a/kernel/trunk/core/memory.inc b/kernel/trunk/core/memory.inc index 779c72ad82..16adfec298 100644 --- a/kernel/trunk/core/memory.inc +++ b/kernel/trunk/core/memory.inc @@ -126,12 +126,12 @@ proc free_page ;arg: eax page address pushfd cli - shr eax, 12 ;page index - bts dword [sys_pgmap], eax ;that's all! + shr eax, 12 ;page index + bts dword [sys_pgmap], eax ;that's all! cmc adc [pg_data.pages_free], 0 shr eax, 3 - and eax, not 3 ;dword offset from page_map + and eax, not 3 ;dword offset from page_map add eax, sys_pgmap cmp [page_start], eax ja @f @@ -166,7 +166,9 @@ proc map_io_mem stdcall, base:dword, size:dword, flags:dword or edx, [flags] @@: mov [page_tabs+eax*4], edx - invlpg [ebx] + ; push eax + ; invlpg [ebx] + ; pop eax inc eax add ebx, edi add edx, edi @@ -184,7 +186,7 @@ endp ; param ; eax= page base + page flags -; ebx= liear address +; ebx= linear address ; ecx= count align 4 @@ -202,7 +204,9 @@ commit_pages: shr ebx, 12 @@: mov [page_tabs+ebx*4], eax - invlpg [edi] + ; push eax + ; invlpg [edi] + ; pop eax add edi, edx add eax, edx inc ebx @@ -263,6 +267,32 @@ release_pages: popad ret +; param +; eax= base +; ecx= count + +align 4 +unmap_pages: + + push edi + + mov edi, eax + mov edx, eax + + shr edi, 10 + add edi, page_tabs + + xor eax, eax +@@: + stosd + invlpg [edx] + add edx, 0x1000 + loop @b + + pop edi + ret + + align 4 proc map_page_table stdcall, lin_addr:dword, phis_addr:dword push ebx @@ -1085,6 +1115,27 @@ new_services: mov [esp+36], eax ret +align 4 +proc load_pe_driver stdcall, file:dword + + stdcall load_PE, [file] + test eax, eax + jz .fail + + mov esi, eax + stdcall eax, DRV_ENTRY + test eax, eax + jz .fail + + mov [eax+SRV.entry], esi + ret + +.fail: + xor eax, eax + ret +endp + + align 4 proc init_mtrr @@ -1159,8 +1210,6 @@ proc set_mtrr stdcall, reg:dword,base:dword,size:dword,mem_type:dword ret endp - - align 4 proc stall stdcall, delay:dword push ecx @@ -1228,8 +1277,6 @@ proc create_ring_buffer stdcall, size:dword, flags:dword @@: mov [page_tabs+edi], eax mov [page_tabs+edi+edx], eax - invlpg [ebx] - invlpg [ebx+esi] add eax, 0x1000 add ebx, 0x1000 add edi, 4 @@ -1248,14 +1295,4 @@ proc create_ring_buffer stdcall, size:dword, flags:dword ret endp -if 0 - push eax - push edx - mov edx, 0x400 ;bochs - mov al,0xff ;bochs - out dx, al ;bochs - pop edx - pop eax -end if - diff --git a/kernel/trunk/core/peload.inc b/kernel/trunk/core/peload.inc index 96d0ae6c9a..ac1e38e2eb 100644 --- a/kernel/trunk/core/peload.inc +++ b/kernel/trunk/core/peload.inc @@ -280,7 +280,9 @@ L40: __exports: export 'KERNEL', \ alloc_kernel_space, 'AllocKernelSpace', \ ; stdcall + commit_pages, 'CommitPages', \ ; eax, ebx, ecx create_kernel_object, 'CreateObject', \ + create_ring_buffer, 'CreateRingBuffer', \ ; stdcall destroy_kernel_object, 'DestroyObject', \ free_kernel_space, 'FreeKernelSpace', \ ; stdcall kernel_alloc, 'KernelAlloc', \ ; stdcall @@ -288,6 +290,7 @@ __exports: malloc, 'Kmalloc', \ free, 'Kfree', \ map_io_mem, 'MapIoMem', \ ; stdcall + get_pg_addr, 'GetPgAddr', \ ; eax \ select_hw_cursor, 'SelectHwCursor', \ ; stdcall set_hw_cursor, 'SetHwCursor', \ ; stdcall @@ -303,9 +306,10 @@ __exports: pci_write16, 'PciWrite16', \ ; stdcall pci_write32, 'PciWrite32', \ ; stdcall \ - reg_service, 'RegService', \ + reg_service, 'RegService', \ ; stdcall user_alloc, 'UserAlloc', \ ; stdcall user_free, 'UserFree', \ ; stdcall + unmap_pages, 'UnmapPages', \ ; eax, ecx sys_msg_board_str, 'SysMsgBoardStr' diff --git a/kernel/trunk/core/taskman.inc b/kernel/trunk/core/taskman.inc index 941c79f765..28579cde38 100644 --- a/kernel/trunk/core/taskman.inc +++ b/kernel/trunk/core/taskman.inc @@ -212,8 +212,7 @@ else jna @F xor eax, eax - ; add edi, new_app_base - cld + cld rep stosb @@: end if @@ -453,12 +452,7 @@ proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword if GREEDY_KERNEL mov eax, 0x02 -.reserve: - stosd - invlpg [edx] - add edx, 4096 - dec ecx - jnz .reserve + rep stosd else .alloc: @@ -507,6 +501,8 @@ proc destroy_page_table stdcall, pg_tab:dword mov eax, [esi] test eax, 1 jz .next + test eax, 1 shl 9 + jnz .next ;skip shared pages call free_page .next: add esi, 4 @@ -576,9 +572,8 @@ endp align 4 get_pid: - ;mov eax, [TASK_DATA] ; I think it's the bug. (Rus) mov eax, [TASK_BASE] - mov eax, [eax+4] + mov eax, [eax+TASKDATA.pid] ret pid_to_slot: diff --git a/kernel/trunk/drivers/ati2d.asm b/kernel/trunk/drivers/ati2d.asm index 3b295df05a..4bed5f0bd0 100644 --- a/kernel/trunk/drivers/ati2d.asm +++ b/kernel/trunk/drivers/ati2d.asm @@ -178,7 +178,7 @@ macro OUT_PACKET0 reg, count inc edx } -macro OUT_PACKET3 pkt, count \ +macro OUT_PACKET3 pkt, count { mov eax, (RADEON_CP_PACKET3 or pkt or (count shl 16)) mov [edi+edx*4], eax diff --git a/kernel/trunk/video/cursors.inc b/kernel/trunk/video/cursors.inc index 82c9b995f3..b7618c05f2 100644 --- a/kernel/trunk/video/cursors.inc +++ b/kernel/trunk/video/cursors.inc @@ -468,8 +468,6 @@ proc init_cursors .init: mov [cur_def_interl], ebx - ; stdcall load_pe_driver, szAtiHW - stdcall load_driver, szHwMouse mov [hw_cursor], eax test eax, eax