diff --git a/kernel/trunk/core/debug.inc b/kernel/trunk/core/debug.inc index f0aa56981e..7bd97bfa38 100644 --- a/kernel/trunk/core/debug.inc +++ b/kernel/trunk/core/debug.inc @@ -10,71 +10,71 @@ $Revision$ ; diamond, 2006 sys_debug_services: - cmp eax, 9 - ja @f - jmp dword [sys_debug_services_table+eax*4] -@@: ret + cmp eax, 9 + ja @f + jmp dword [sys_debug_services_table+eax*4] +@@: ret sys_debug_services_table: - dd debug_set_event_data - dd debug_getcontext - dd debug_setcontext - dd debug_detach - dd debug_suspend - dd debug_resume - dd debug_read_process_memory - dd debug_write_process_memory - dd debug_terminate - dd debug_set_drx + dd debug_set_event_data + dd debug_getcontext + dd debug_setcontext + dd debug_detach + dd debug_suspend + dd debug_resume + dd debug_read_process_memory + dd debug_write_process_memory + dd debug_terminate + dd debug_set_drx debug_set_event_data: ; in: ebx = pointer ; destroys eax mov eax, [current_slot] mov [eax+APPDATA.dbg_event_mem], ebx - ret + ret get_debuggee_slot: ; in: ebx=PID ; out: CF=1 if error ; CF=0 and eax=slot*0x20 if ok ; out: interrupts disabled - cli - mov eax, ebx - call pid_to_slot - test eax, eax - jz .ret_bad - shl eax, 5 - push ebx + cli + mov eax, ebx + call pid_to_slot + test eax, eax + jz .ret_bad + shl eax, 5 + push ebx mov ebx, [CURRENT_TASK] cmp [SLOT_BASE+eax*8+APPDATA.debugger_slot], ebx - pop ebx - jnz .ret_bad -; clc ; automatically - ret + pop ebx + jnz .ret_bad +; clc ; automatically + ret .ret_bad: - stc - ret + stc + ret debug_detach: ; in: ebx=pid ; destroys eax,ebx - call get_debuggee_slot - jc .ret + call get_debuggee_slot + jc .ret and dword [eax*8+SLOT_BASE+APPDATA.debugger_slot], 0 - call do_resume + call do_resume .ret: - sti - ret + sti + ret debug_terminate: ; in: ebx=pid - call get_debuggee_slot - jc debug_detach.ret - mov ecx, eax - shr ecx, 5 - push 2 - pop ebx - jmp sys_system + call get_debuggee_slot + jc debug_detach.ret + mov ecx, eax + shr ecx, 5 + push 2 + pop ebx + jmp sys_system debug_suspend: ; in: ebx=pid @@ -85,30 +85,30 @@ debug_suspend: shl eax, 5 jz .ret mov bl, [CURRENT_TASK+eax+TASKDATA.state] ; process state - test bl, bl - jz .1 - cmp bl, 5 - jnz .ret - mov bl, 2 + test bl, bl + jz .1 + cmp bl, 5 + jnz .ret + mov bl, 2 .2: mov [CURRENT_TASK+eax+TASKDATA.state], bl .ret: - sti - ret + sti + ret .1: - inc ebx - jmp .2 + inc ebx + jmp .2 do_resume: mov bl, [CURRENT_TASK+eax+TASKDATA.state] - cmp bl, 1 - jz .1 - cmp bl, 2 - jnz .ret - mov bl, 5 + cmp bl, 1 + jz .1 + cmp bl, 2 + jnz .ret + mov bl, 5 .2: mov [CURRENT_TASK+eax+TASKDATA.state], bl -.ret: ret -.1: dec ebx - jmp .2 +.ret: ret +.1: dec ebx + jmp .2 debug_resume: ; in: ebx=pid @@ -119,8 +119,8 @@ debug_resume: shl eax, 5 jz .ret call do_resume -.ret: sti - ret +.ret: sti + ret debug_getcontext: ; in: @@ -128,16 +128,16 @@ debug_getcontext: ; ecx=sizeof(CONTEXT) ; edx->CONTEXT ; destroys eax,ecx,edx,esi,edi - cmp ecx, 28h - jnz .ret - push ebx - mov ebx, edx - call check_region - pop ebx - dec eax - jnz .ret - call get_debuggee_slot - jc .ret + cmp ecx, 28h + jnz .ret + push ebx + mov ebx, edx + call check_region + pop ebx + dec eax + jnz .ret + call get_debuggee_slot + jc .ret mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack] lea esi, [eax+RING0_STACK_SIZE] mov edi, edx @@ -147,30 +147,30 @@ debug_getcontext: ; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), pushad sub esi, 8+12+20h lodsd ;edi - mov [edi+24h], eax + mov [edi+24h], eax lodsd ;esi - mov [edi+20h], eax + mov [edi+20h], eax lodsd ; ebp - mov [edi+1Ch], eax + mov [edi+1Ch], eax lodsd ;esp lodsd ;ebx - mov [edi+14h], eax + mov [edi+14h], eax lodsd ;edx - mov [edi+10h], eax + mov [edi+10h], eax lodsd ;ecx - mov [edi+0Ch], eax + mov [edi+0Ch], eax lodsd ;eax - mov [edi+8], eax + mov [edi+8], eax lodsd ;eip - mov [edi], eax + mov [edi], eax lodsd ;cs lodsd ;eflags - mov [edi+4], eax + mov [edi+4], eax lodsd ;esp - mov [edi+18h], eax + mov [edi+18h], eax .ret: - sti - ret + sti + ret debug_setcontext: ; in: @@ -178,120 +178,120 @@ debug_setcontext: ; ecx=sizeof(CONTEXT) ; edx->CONTEXT ; destroys eax,ecx,edx,esi,edi - cmp ecx, 28h - jnz .ret - push ebx - mov ebx, edx - call check_region - pop ebx - dec eax - jnz .ret - call get_debuggee_slot - jc .stiret + cmp ecx, 28h + jnz .ret + push ebx + mov ebx, edx + call check_region + pop ebx + dec eax + jnz .ret + call get_debuggee_slot + jc .stiret mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack] lea edi, [eax+RING0_STACK_SIZE] mov esi, edx .ring0: sub edi, 8+12+20h mov eax, [esi+24h] ;edi - stosd + stosd mov eax, [esi+20h] ;esi - stosd + stosd mov eax, [esi+1Ch] ;ebp - stosd + stosd scasd mov eax, [esi+14h] ;ebx - stosd + stosd mov eax, [esi+10h] ;edx - stosd + stosd mov eax, [esi+0Ch] ;ecx - stosd + stosd mov eax, [esi+8] ;eax - stosd + stosd mov eax, [esi] ;eip - stosd - scasd + stosd + scasd mov eax, [esi+4] ;eflags - stosd + stosd mov eax, [esi+18h] ;esp - stosd + stosd .stiret: - sti + sti .ret: - ret + ret debug_set_drx: - call get_debuggee_slot - jc .errret - mov ebp, eax + call get_debuggee_slot + jc .errret + mov ebp, eax lea eax, [eax*8+SLOT_BASE+APPDATA.dbg_regs] ; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3 ; [eax+10]=dr7 cmp edx, OS_BASE jae .errret - cmp cl, 3 - ja .errret - mov ebx, dr7 - shr ebx, cl - shr ebx, cl - test ebx, 2 ; bit 1+2*index = G0..G3, global break enable - jnz .errret2 - test ch, ch - jns .new + cmp cl, 3 + ja .errret + mov ebx, dr7 + shr ebx, cl + shr ebx, cl + test ebx, 2 ; bit 1+2*index = G0..G3, global break enable + jnz .errret2 + test ch, ch + jns .new ; clear breakpoint - movzx ecx, cl - add ecx, ecx - and dword [eax+ecx*2], 0 ; clear DR - btr dword [eax+10h], ecx ; clear L bit - test byte [eax+10h], 55h - jnz .okret + movzx ecx, cl + add ecx, ecx + and dword [eax+ecx*2], 0 ; clear DR + btr dword [eax+10h], ecx ; clear L bit + test byte [eax+10h], 55h + jnz .okret ; imul eax, ebp, tss_step/32 ; and byte [eax + tss_data + TSS._trap], not 1 and [ebp*8 + SLOT_BASE+APPDATA.dbg_state], not 1 .okret: - and dword [esp+36], 0 - sti - ret + and dword [esp+36], 0 + sti + ret .errret: - sti - mov dword [esp+36], 1 - ret + sti + mov dword [esp+36], 1 + ret .errret2: - sti - mov dword [esp+36], 2 - ret + sti + mov dword [esp+36], 2 + ret .new: ; add new breakpoint ; cl=index; ch=flags; edx=address - test ch, 0xF0 - jnz .errret - mov bl, ch - and bl, 3 - cmp bl, 2 - jz .errret - mov bl, ch - shr bl, 2 - cmp bl, 2 - jz .errret - test dl, bl - jnz .errret - or byte [eax+10h+1], 3 ; set GE and LE flags - movzx ebx, ch - movzx ecx, cl - add ecx, ecx - bts dword [eax+10h], ecx ; set L flag - add ecx, ecx - mov [eax+ecx], edx ; set DR - shl ebx, cl - mov edx, 0xF - shl edx, cl - not edx - and [eax+10h+2], dx - or [eax+10h+2], bx ; set R/W and LEN fields + test ch, 0xF0 + jnz .errret + mov bl, ch + and bl, 3 + cmp bl, 2 + jz .errret + mov bl, ch + shr bl, 2 + cmp bl, 2 + jz .errret + test dl, bl + jnz .errret + or byte [eax+10h+1], 3 ; set GE and LE flags + movzx ebx, ch + movzx ecx, cl + add ecx, ecx + bts dword [eax+10h], ecx ; set L flag + add ecx, ecx + mov [eax+ecx], edx ; set DR + shl ebx, cl + mov edx, 0xF + shl edx, cl + not edx + and [eax+10h+2], dx + or [eax+10h+2], bx ; set R/W and LEN fields ; imul eax, ebp, tss_step/32 ; or byte [eax + tss_data + TSS._trap], 1 or [ebp*8 + SLOT_BASE+APPDATA.dbg_state], 1 - jmp .okret + jmp .okret debug_read_process_memory: ; in: @@ -301,23 +301,23 @@ debug_read_process_memory: ; edx=address in debuggee ; out: [esp+36]=sizeof(read) ; destroys all - push ebx - mov ebx, esi - call check_region - pop ebx - dec eax - jnz .err - call get_debuggee_slot - jc .err - shr eax, 5 - mov ebx, esi - call read_process_memory - sti - mov dword [esp+36], eax - ret + push ebx + mov ebx, esi + call check_region + pop ebx + dec eax + jnz .err + call get_debuggee_slot + jc .err + shr eax, 5 + mov ebx, esi + call read_process_memory + sti + mov dword [esp+36], eax + ret .err: - or dword [esp+36], -1 - ret + or dword [esp+36], -1 + ret debug_write_process_memory: ; in: @@ -327,20 +327,20 @@ debug_write_process_memory: ; edx=address in debuggee ; out: [esp+36]=sizeof(write) ; destroys all - push ebx - mov ebx, esi - call check_region - pop ebx - dec eax - jnz debug_read_process_memory.err - call get_debuggee_slot - jc debug_read_process_memory.err - shr eax, 5 - mov ebx, esi - call write_process_memory - sti - mov [esp+36], eax - ret + push ebx + mov ebx, esi + call check_region + pop ebx + dec eax + jnz debug_read_process_memory.err + call get_debuggee_slot + jc debug_read_process_memory.err + shr eax, 5 + mov ebx, esi + call write_process_memory + sti + mov [esp+36], eax + ret debugger_notify: ; in: eax=debugger slot @@ -349,127 +349,96 @@ debugger_notify: ; interrupts must be disabled! ; destroys all general registers ; interrupts remain disabled - xchg ebp, eax - mov edi, [timer_ticks] - add edi, 500 ; 5 sec timeout + xchg ebp, eax + mov edi, [timer_ticks] + add edi, 500 ; 5 sec timeout .1: - mov eax, ebp - shl eax, 8 + mov eax, ebp + shl eax, 8 mov edx, [SLOT_BASE+eax+APPDATA.dbg_event_mem] - test edx, edx - jz .ret + test edx, edx + jz .ret ; read buffer header - push ecx - push eax - push eax - mov eax, ebp - mov ebx, esp - mov ecx, 8 - call read_process_memory - cmp eax, ecx - jz @f - add esp, 12 - jmp .ret + push ecx + push eax + push eax + mov eax, ebp + mov ebx, esp + mov ecx, 8 + call read_process_memory + cmp eax, ecx + jz @f + add esp, 12 + jmp .ret @@: - cmp dword [ebx], 0 - jg @f + cmp dword [ebx], 0 + jg @f .2: - pop ecx - pop ecx - pop ecx + pop ecx + pop ecx + pop ecx cmp dword [CURRENT_TASK], 1 - jnz .notos - cmp [timer_ticks], edi - jae .ret + jnz .notos + cmp [timer_ticks], edi + jae .ret .notos: - sti - call change_task - cli - jmp .1 + sti + call change_task + cli + jmp .1 @@: - mov ecx, [ebx+8] - add ecx, [ebx+4] - cmp ecx, [ebx] - ja .2 + mov ecx, [ebx+8] + add ecx, [ebx+4] + cmp ecx, [ebx] + ja .2 ; advance buffer position - push ecx - mov ecx, 4 - sub ebx, ecx - mov eax, ebp - add edx, ecx - call write_process_memory - pop eax + push ecx + mov ecx, 4 + sub ebx, ecx + mov eax, ebp + add edx, ecx + 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 - call write_process_memory + mov eax, ebp + add edx, ecx + add edx, [ebx+8] + add ebx, 20 + pop ecx + pop ecx + pop ecx + call write_process_memory ; new debug event - mov eax, ebp - shl eax, 8 + mov eax, ebp + shl eax, 8 or byte [SLOT_BASE+eax+APPDATA.event_mask+1], 1 ; set flag 100h .ret: - ret + ret -debug_exc: - test byte [esp+8+2], 2 - jnz v86_debug_exc -; int 1 = #DB - save_ring3_context - cld - mov ax, app_data ;os_data - mov ds, ax - mov es, ax - mov eax, dr6 - push eax - xor eax, eax - mov dr6, eax -; test if debugging - cli - mov eax, [current_slot] - mov eax, [eax+APPDATA.debugger_slot] - test eax, eax - jnz .debug - sti -; not debuggee => say error and terminate - add esp, 0x20+4 - mov [error_interrupt], 1 - call show_error_parameters - mov edx, [TASK_BASE] - mov byte [edx+TASKDATA.state], 4 - jmp change_task -.debug: +debug_ex: ; we are debugged process, notify debugger and suspend ourself ; eax=debugger PID - pop edx - mov ebx, dr7 - mov cl, not 1 -.l1: - test bl, 1 - jnz @f - and dl, cl -@@: - shr ebx, 2 - add cl, cl - inc ecx - cmp cl, not 10h - jnz .l1 - push edx ; DR6 image - mov ecx, [TASK_BASE] - push dword [ecx+TASKDATA.pid] ; PID - push 12 - pop ecx - push 3 ; 3 = debug exception - call debugger_notify - pop ecx - pop ecx - pop ecx + mov edx, dr6 ; debug_message data=DR6_image + xor ebx, ebx + mov dr6, ebx + mov ebx, dr7 + mov cl, not 8 + .l1: shl bl,2 + jc @f + and dl, cl + @@: sar cl,1 + jc .l1 + mov ecx,3 ; debug_message code=debug_exception +.notify: + push edx ; debug_message data + mov ebx, [TASK_BASE] + push [ebx+TASKDATA.pid] ; PID + push ecx ; debug_message code + mov ecx,12 ; debug_message size + call debugger_notify ;; only ONE using, inline ??? + add esp,12 mov edx, [TASK_BASE] - mov byte [edx+TASKDATA.state], 1 ; suspended - call change_task - restore_ring3_context - iretd + mov byte [edx+TASKDATA.state], 1 ; suspended + call change_task + restore_ring3_context + iretd diff --git a/kernel/trunk/core/fpu.inc b/kernel/trunk/core/fpu.inc index 15d901a10c..541efe2067 100644 --- a/kernel/trunk/core/fpu.inc +++ b/kernel/trunk/core/fpu.inc @@ -142,7 +142,7 @@ fpu_restore: ret align 4 -e7: ;#NM exception handler +except_7: ;#NM exception handler save_ring3_context clts mov ax, app_data ; @@ -180,7 +180,7 @@ e7: ;#NM exception handler iglobal fpu_owner dd 0 - endg +endg reg_eip equ ebp+4 reg_cs equ ebp+8 @@ -188,8 +188,8 @@ reg_eflags equ ebp+12 reg_esp equ ebp+16 reg_ss equ ebp+20 -align 4 -except_16: ;fpu native exceptions handler +align 4 ;not used now +proc except_16 ;fpu native exceptions handler test byte [esp+8+2], 2 jnz v86_except_16 push ebp @@ -233,9 +233,10 @@ except_16: ;fpu native exceptions handler mov bl, 16 jmp exc_c +endp -align 4 -except_19: ;sse exceptions handler +align 4 ;not used now +proc except_19 ;sse exceptions handler test byte [esp+8+2], 2 jnz v86_except_19 push ebp @@ -278,6 +279,7 @@ except_19: ;sse exceptions handler mov bl, 19 jmp exc_c +endp restore reg_eip restore reg_cs diff --git a/kernel/trunk/core/memory.inc b/kernel/trunk/core/memory.inc index 95fbcdc607..39095115af 100644 --- a/kernel/trunk/core/memory.inc +++ b/kernel/trunk/core/memory.inc @@ -544,24 +544,15 @@ get_pg_addr: align 4 +; Now it is called from sys32::exc_c (see stack frame there) proc page_fault_handler - test byte [esp+12+2], 2 - jnz v86_page_fault + .err_addr equ ebp-4 - .err_code equ ebp+32 - .err_addr equ ebp-4 - - pushad - mov ebp, esp - mov eax, cr2 - push eax - - mov ax, app_data - mov ds, ax - mov es, ax - - inc [pg_data.pages_faults] + mov ebp, esp + mov ebx, cr2 + push ebx ; that is locals: .err_addr = cr2 + inc [pg_data.pages_faults] ; push eax ; push edx @@ -571,129 +562,115 @@ proc page_fault_handler ; pop edx ; pop eax - mov ebx, [.err_addr] - mov eax, [.err_code] + mov eax, [pf_err_code] - cmp ebx, OS_BASE - jb .user_space ;страница в памяти приложения ; + cmp ebx, OS_BASE ;ebx == .err_addr + jb .user_space ;страница в памяти приложения ; - cmp ebx, page_tabs - jb .kernel_space ;страница в памяти ядра + cmp ebx, page_tabs + jb .kernel_space ;страница в памяти ядра - cmp ebx, kernel_tabs - jb .alloc;.app_tabs ;таблицы страниц приложения ; - ;просто создадим одну + cmp ebx, kernel_tabs + jb .alloc;.app_tabs ;таблицы страниц приложения ; + ;просто создадим одну +if 0 ;пока это просто лишнее + cmp ebx, LFB_BASE + jb .core_tabs ;таблицы страниц ядра + ;Ошибка + .lfb: + ;область LFB + ;Ошибка + jmp .fail +end if +.core_tabs: +.fail: ;simply return to caller + mov esp, ebp + mov bl, 14 ;#PF + ret - cmp ebx, LFB_BASE - jb .core_tabs ;таблицы страниц ядра - ;Ошибка -.lfb: - ;область LFB - ;Ошибка - jmp .fail - -align 4 .user_space: - test eax, PG_MAP - jnz .err_access ;Страница присутствует - ;Ошибка доступа ? + test eax, PG_MAP + jnz .err_access ;Страница присутствует + ;Ошибка доступа ? - shr ebx, 12 - mov ecx, ebx - shr ecx, 10 - mov edx, [master_tab+ecx*4] - test edx, PG_MAP - jz .fail ;таблица страниц не создана - ;неверный адрес в программе + shr ebx, 12 + mov ecx, ebx + shr ecx, 10 + mov edx, [master_tab+ecx*4] + test edx, PG_MAP + jz .fail ;таблица страниц не создана + ;неверный адрес в программе - mov eax, [page_tabs+ebx*4] - test eax, 2 - jz .fail ;адрес не зарезервирован для ; - ;использования. Ошибка + mov eax, [page_tabs+ebx*4] + test eax, 2 + jz .fail ;адрес не зарезервирован для ; + ;использования. Ошибка .alloc: - call alloc_page - test eax, eax - jz .fail + call alloc_page + test eax, eax + jz .fail - stdcall map_page,[ebp-4],eax,dword PG_UW + stdcall map_page,[.err_addr],eax,dword PG_UW - mov edi, [ebp-4] - and edi, 0xFFFFF000 - mov ecx, 1024 - xor eax, eax - cld - rep stosd -.exit: - mov esp, ebp - popad - add esp, 4 - iretd + mov edi, [.err_addr] + and edi, 0xFFFFF000 + mov ecx, 1024 + xor eax, eax + ;cld ;caller is duty for this + rep stosd +.exit: ;iret with repeat fault instruction + add esp,8 ; clear in stack: locals(.err_addr) + ret_to_caller + restore_ring3_context + iretd -.err_access: +.err_access = .fail ;никогда не происходит - jmp .fail + ;jmp .fail .kernel_space: - test eax, PG_MAP - jz .fail ;страница не присутствует + test eax, PG_MAP + jz .fail ;страница не присутствует - test eax, 4 ;U/S - jnz .fail ;приложение обратилось к памяти - ;ядра - test eax, 8 - jnz .fail ;установлен зарезервированный бит - ;в таблицах страниц. добавлено в P4/Xeon + test eax,12 ;U/S (+below) + jnz .fail ;приложение обратилось к памяти + ;ядра + ;test eax, 8 + ;jnz .fail ;установлен зарезервированный бит + ;в таблицах страниц. добавлено в P4/Xeon ;попытка записи в защищённую страницу ядра - cmp ebx, tss._io_map_0 - jb .fail + cmp ebx, tss._io_map_0 + jb .fail - cmp ebx, tss._io_map_0+8192 - jae .fail + cmp ebx, tss._io_map_0+8192 + jae .fail ; io permission map ; copy-on-write protection - call alloc_page - test eax, eax - jz .fail + call alloc_page + test eax, eax + jz .fail - push eax - stdcall map_page,[ebp-4],eax,dword PG_SW - pop eax - mov edi, [.err_addr] - and edi, -4096 - lea esi, [edi+(not tss._io_map_0)+1]; -tss._io_map_0 + push eax + stdcall map_page,[.err_addr],eax,dword PG_SW + pop eax + mov edi, [.err_addr] + and edi, -4096 + lea esi, [edi+(not tss._io_map_0)+1]; -tss._io_map_0 - mov ebx, esi - shr ebx, 12 - mov edx, [current_slot] - or eax, PG_SW - mov [edx+APPDATA.io_map+ebx*4], eax + mov ebx, esi + shr ebx, 12 + mov edx, [current_slot] + or eax, PG_SW + mov [edx+APPDATA.io_map+ebx*4], eax - add esi, [default_io_map] - mov ecx, 4096/4 - cld - rep movsd - jmp .exit - - -;не обрабатываем. Ошибка - -.core_tabs: -.fail: - mov esp, ebp - popad - add esp, 4 - -; iretd - - save_ring3_context ;debugger support - - mov bl, 14 - jmp exc_c - iretd + add esi, [default_io_map] + mov ecx, 4096/4 + ;cld ;caller is duty for this + rep movsd + jmp .exit endp align 4 @@ -1346,6 +1323,3 @@ proc create_ring_buffer stdcall, size:dword, flags:dword .fail: ret endp - - - diff --git a/kernel/trunk/core/sys32.inc b/kernel/trunk/core/sys32.inc index 3669f1ef0b..aef52b4d0a 100644 --- a/kernel/trunk/core/sys32.inc +++ b/kernel/trunk/core/sys32.inc @@ -14,212 +14,206 @@ $Revision$ -align 4 -idtreg: - dw 8*0x41-1 - dd idts+8 - +align 4 ;3A08 build_interrupt_table: - - mov edi, idts+8 - mov esi, sys_int - mov ecx, 0x40 - @@: - lodsd - mov [edi], ax ; lower part of offset - mov [edi+2], word os_code ; segment selector - mov ax, word 10001110b shl 8 ; type: interrupt gate - mov [edi+4], eax - add edi, 8 - loop @b - - ;mov edi,8*0x40+idts+8 - mov dword [edi], (i40 and 0xFFFF) or (os_code shl 16) - mov dword [edi+4], (11101111b shl 8) or (i40 and 0xFFFF0000) - ; type: trap gate - ret + mov edi, idts + mov esi, sys_int + mov ecx, 0x40 + mov eax, (10001110b shl 24) + os_code + @@: movsw ;low word of code-entry + stosd ;interrupt gate type : os_code selector + movsw ;high word of code-entry + loop @b + movsd ;copy low dword of trap gate for int 0x40 + movsd ;copy high dword of trap gate for int 0x40 + lidt [esi] + ret iglobal - - msg_sel_ker db "kernel", 0 - msg_sel_app db "application", 0 - + align 4 sys_int: - dd e0,debug_exc,e2,e3 - dd e4,e5,e6,e7 - dd e8,e9,e10,e11 - dd e12,e13,page_fault_handler,e15 + ;exception handlers addresses (for interrupt gate construction) + dd e0,e1,e2,e3,e4,e5,e6,except_7 + dd e8,e9,e10,e11,e12,e13,page_fault_exc,e15 + dd e16, e17,e18, e19 + times 12 dd unknown_interrupt ;int_20..int_31 - dd except_16, e17,e18, except_19 - times 12 dd unknown_interrupt + ;interrupt handlers addresses (for interrupt gate construction) + 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_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 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_8, irq_serv.irq_9, irq_serv.irq_10 - dd irq_serv.irq_11, irq_serv.irq_12,irqD ,p_irq14,p_irq15 + ;int_0x40 gate trap (for directly copied) + dw i40 and 0xFFFF, os_code, 11101111b shl 8, i40 shr 16 - times 16 dd unknown_interrupt + idtreg: ; data for LIDT instruction (must be immediately below sys_int data) + dw 2*($-sys_int-4)-1 + dd idts ;0x8000B100 + dw 0 ;просто выравнивание + + msg_fault_sel dd msg_exc_8,msg_exc_u,msg_exc_a,msg_exc_b + dd msg_exc_c,msg_exc_d,msg_exc_e + + msg_exc_8 db "Double fault", 0 + msg_exc_u db "Undefined Exception", 0 + msg_exc_a db "Invalid TSS", 0 + msg_exc_b db "Segment not present", 0 + msg_exc_c db "Stack fault", 0 + msg_exc_d db "General protection fault", 0 + msg_exc_e db "Page fault", 0 + + msg_sel_ker db "kernel", 0 + msg_sel_app db "application", 0 - dd i40 endg -macro save_ring3_context -{ - pushad +macro save_ring3_context { + pushad } -macro restore_ring3_context -{ - popad +macro restore_ring3_context { + popad } - -; simply return control to interrupted process -unknown_interrupt: - iret - -macro exc_wo_code [num] -{ - forward +macro exc_wo_code [num] { e#num : - save_ring3_context - mov bl, num - jmp exc_c -} + save_ring3_context + mov bl, num + jmp exc_c +} exc_wo_code 0,1,2,3,4,5,6,15,16,19 -macro exc_w_code [num] -{ - forward +macro exc_w_code [num] { e#num : - add esp, 4 - save_ring3_context - mov bl, num - jmp exc_c -} + add esp, 4 + save_ring3_context + mov bl, num + jmp exc_c +} exc_w_code 8,9,10,11,12,13,17,18 -exc_wo_code 0, 2, 3, 4, 5, 6, 9, 15, 18 -exc_w_code 8, 10, 11, 12, 13, 14, 17 -exc_c: - mov ax, app_data ;исключение - mov ds, ax ;загрузим правильные значени - mov es, ax ;в регистры +uglobal + pf_err_code dd ? +endg +page_fault_exc: + pop [pf_err_code] ;действительно до следующего #PF + save_ring3_context + mov bl,14 +exc_c: ;исключение +; Фрэйм стека при исключении/прерывании из 3-го кольца + pushad (т.е., именно здесь) + reg_ss equ esp+0x30 + reg_esp3 equ esp+0x2C + reg_eflags equ esp+0x28 + reg_cs3 equ esp+0x24 + reg_eip equ esp+0x20 + ; это фрэйм от pushad + reg_eax equ esp+0x1C + reg_ecx equ esp+0x18 + reg_edx equ esp+0x14 + reg_ebx equ esp+0x10 + reg_esp0 equ esp+0x0C + reg_ebp equ esp+0x08 + reg_esi equ esp+0x04 + reg_edi equ esp+0x00 + + Mov ds,ax,app_data ; загрузим правильные значения + mov es,ax ; в сегментные регистры + cld ; и приводим DF к стандарту ; redirect to V86 manager? (EFLAGS & 0x20000) != 0? - test byte [esp+20h+8+2], 2 - jnz v86_exc_c - -; test if debugging - cli - mov eax, [current_slot] - mov eax, [eax+APPDATA.debugger_slot] - test eax, eax - jnz .debug - sti + test byte[reg_eflags+2],2 + jnz v86_exc_c + cmp bl,14 ; #PF + jne .l0 + call page_fault_handler + .l0: mov esi, [current_slot] + mov eax,[esi+APPDATA.fpu_handler] + cmp bl,16 ; #MF + je .l1 + cmp bl,19 ; #XF + jne .l2 + mov eax,[esi+APPDATA.sse_handler] + .l1: test eax, eax + jnz IRetToUserHook + .l2: cli + mov eax, [esi+APPDATA.debugger_slot] + test eax, eax + jnz .debug + sti ; not debuggee => say error and terminate - movzx eax, bl - mov [error_interrupt], eax - call show_error_parameters - add esp, 0x20 - mov edx, [TASK_BASE] - mov [edx + TASKDATA.state], byte 4 - - jmp change_task - + call show_error_parameters ;; only ONE using, inline ??? + ;mov edx, [TASK_BASE] + mov [edx + TASKDATA.state], byte 4 ; terminate + jmp change_task ; stack - here it does not matter at all .debug: ; we are debugged process, notify debugger and suspend ourself ; eax=debugger PID - cld - movzx ecx, bl - push ecx - mov ecx, [TASK_BASE] - push dword [ecx+TASKDATA.pid] ; PID of current process - push 12 - pop ecx - push 1 ; 1=exception - call debugger_notify - pop ecx - pop ecx - pop ecx - mov edx, [TASK_BASE] - mov byte [edx+TASKDATA.state], 1 ; suspended - call change_task - restore_ring3_context - iretd + cmp bl,1 ; #DB + je debug_ex + movzx edx, bl ; debug_message data=Number_Of_Exception + mov ecx,1 ; debug_message code=other_exception + jmp debug_ex.notify ; notify debugger and suspend ourself -iglobal - hexletters db '0123456789ABCDEF' - error_interrupt dd -1 -endg +IRetToUserHook: + xchg eax, [reg_eip] + sub dword[reg_esp3], 4 + mov edi, [reg_esp3] + stosd + restore_ring3_context +unknown_interrupt: + iretd ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= show_error_parameters: - mov eax,[CURRENT_TASK] - shl eax, 5 - DEBUGF 1, "K : Process - forced terminate PID: %x\n", [CURRENT_TASK + TASKDATA.pid + eax] - mov eax, [error_interrupt] - cmp al, 0x08 - jne @f - DEBUGF 1, "K : Double fault\n" - jmp defined_error -@@: - cmp al, 0x0a - jne @f - DEBUGF 1, "K : Invalid TSS\n" - jmp defined_error -@@: - cmp al, 0x0b - jne @f - DEBUGF 1, "K : Segment not present\n" - jmp defined_error -@@: - cmp al, 0x0c - jne @f - DEBUGF 1, "K : Stack fault\n" - jmp defined_error -@@: - cmp al, 0x0d - jne @f - DEBUGF 1, "K : General protection fault\n" - jmp defined_error -@@: - cmp al, 0x0e - jne @f - DEBUGF 1, "K : Page fault\n" - jmp defined_error -@@: - DEBUGF 1, "K : Undefined Exception\n" -defined_error: - DEBUGF 1, "K : EAX : %x EBX : %x ECX : %x\n", [esp + 0x20], [esp - 12 + 0x20], [esp - 4 + 0x20] - DEBUGF 1, "K : EDX : %x ESI : %x EDI : %x\n", [esp - 8 + 0x20], [esp - 24 + 0x20], [esp - 28 + 0x20] - DEBUGF 1, "K : EBP : %x EIP : %x ", [esp - 20 + 0x20], [esp + 4 + 0x20] - - mov eax, [esp + 8 + 0x20] - mov edi, msg_sel_app - mov ebx, [esp + 16 + 0x20] - cmp eax, app_code - je @f - mov edi, msg_sel_ker - mov ebx, [esp - 16 + 0x20] -@@: - DEBUGF 1, "ESP : %x\nK : Flags : %x CS : %x (%s)\n", ebx, [esp + 12 + 0x20], eax, edi - ret + mov edx,[TASK_BASE] ;not scratched below + DEBUGF 1, "K : Process - forced terminate PID: %x\n", [edx+TASKDATA.pid] + cmp bl, 0x08 + jb .l0 + cmp bl, 0x0e + jbe .l1 + .l0: mov bl, 0x09 + .l1: movzx eax,bl + mov eax,[msg_fault_sel+eax*4 - 0x08*4] + DEBUGF 1, "K : %s\n", eax + mov eax, [reg_cs3+4] + mov edi, msg_sel_app + mov ebx, [reg_esp3+4] + cmp eax, app_code + 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 : 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 + ret ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + restore reg_ss + restore reg_esp3 + restore reg_eflags + restore reg_cs + restore reg_eip + restore reg_eax + restore reg_ecx + restore reg_edx + restore reg_ebx + restore reg_esp0 + restore reg_ebp + restore reg_esi + restore reg_edi ; irq1 -> hid/keyboard.inc -macro irqh [num] -{ - forward +macro irqh [num] { p_irq#num : - mov edi, num - jmp irqhandler + mov edi, num + jmp irqhandler } -irqh 2,3,4,5,7,8,9,10,11 p_irq6: @@ -237,72 +231,64 @@ p_irq6: 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 + 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 + 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 [check_idle_semaphore],5 - mov al, 0x20 - out 0x20, al - ret + mov [check_idle_semaphore],5 + mov al, 0x20 + out 0x20, al + ret ready_for_next_irq_1: - mov [check_idle_semaphore],5 - mov al, 0x20 - out 0xa0,al - out 0x20, al - ret + mov [check_idle_semaphore],5 + mov al, 0x20 + out 0xa0,al + out 0x20, al + ret irqD: - save_ring3_context - mov ax, app_data ;os_data - mov ds, ax - mov es, ax + push eax + mov al,0 + out 0xf0,al + mov al,0x20 + out 0xa0,al + out 0x20,al + pop eax + iret - mov dx,0xf0 - mov al,0 - out dx,al - - mov dx,0xa0 - mov al,0x20 - out dx,al - mov dx,0x20 - out dx,al - - restore_ring3_context - - iret +irqh 2,3,4,5,7,8,9,10,11 irqhandler: - mov esi,edi ; 1 - shl esi,6 ; 1 + mov esi,edi ; 1 + shl esi,6 ; 1 add esi,irq00read ; 1 - shl edi,12 ; 1 + shl edi,12 ; 1 add edi,IRQ_SAVE mov ecx,16 @@ -310,37 +296,37 @@ irqhandler: dec ecx js irqover - movzx edx, word [esi] ; 2+ + movzx edx, word [esi] ; 2+ - test edx, edx ; 1 + 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 + 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 + 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 + 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 + 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 [ebx + 0x10], al ; I could make mistake here :) mov [edi + 0x10], ah .add_size: add dword [edi], 2 @@ -365,50 +351,50 @@ irqhandler: set_application_table_status: - push eax + push eax - mov eax,[CURRENT_TASK] - shl eax, 5 - add eax,CURRENT_TASK+TASKDATA.pid - mov eax,[eax] + mov eax,[CURRENT_TASK] + shl eax, 5 + add eax,CURRENT_TASK+TASKDATA.pid + mov eax,[eax] - mov [application_table_status],eax + mov [application_table_status],eax - pop eax + pop eax - ret + ret clear_application_table_status: - push eax + push eax - mov eax,[CURRENT_TASK] - shl eax, 5 - add eax,CURRENT_TASK+TASKDATA.pid - mov eax,[eax] + mov eax,[CURRENT_TASK] + shl eax, 5 + add eax,CURRENT_TASK+TASKDATA.pid + mov eax,[eax] - cmp eax,[application_table_status] - jne apptsl1 - mov [application_table_status],0 + cmp eax,[application_table_status] + jne apptsl1 + mov [application_table_status],0 apptsl1: - pop eax + pop eax - ret + ret sys_resize_app_memory: - ; eax = 1 - resize - ; ebx = new amount of memory + ; eax = 1 - resize + ; ebx = new amount of memory - cmp eax,1 - jne .no_application_mem_resize + cmp eax,1 + jne .no_application_mem_resize - stdcall new_mem_resize, ebx - mov [esp+36], eax - ret + stdcall new_mem_resize, ebx + mov [esp+36], eax + ret .no_application_mem_resize: - ret + ret sys_threads: @@ -421,9 +407,9 @@ sys_threads: jmp new_sys_threads iglobal -; process_terminating db 'K : Process - terminating',13,10,0 -; process_terminated db 'K : Process - done',13,10,0 - msg_obj_destroy db 'K : destroy app object',13,10,0 +; process_terminating db 'K : Process - terminating',13,10,0 +; process_terminated db 'K : Process - done',13,10,0 + msg_obj_destroy db 'K : destroy app object',13,10,0 endg ; param @@ -431,125 +417,125 @@ endg terminate: ; terminate application - .slot equ esp ;locals + .slot equ esp ;locals - push esi ;save .slot + push esi ;save .slot - shl esi, 8 - cmp [SLOT_BASE+esi+APPDATA.dir_table], 0 - jne @F - pop esi - shl esi, 5 - mov [CURRENT_TASK+esi+TASKDATA.state], 9 - ret + shl esi, 8 + cmp [SLOT_BASE+esi+APPDATA.dir_table], 0 + jne @F + pop esi + shl esi, 5 + mov [CURRENT_TASK+esi+TASKDATA.state], 9 + ret @@: - ;mov esi,process_terminating - ;call sys_msg_board_str + ;mov esi,process_terminating + ;call sys_msg_board_str @@: - cli - cmp [application_table_status],0 - je term9 - sti - call change_task - jmp @b + cli + cmp [application_table_status],0 + je term9 + sti + call change_task + jmp @b term9: - call set_application_table_status + call set_application_table_status ; if the process is in V86 mode... - mov eax, [.slot] - shl eax, 8 - mov esi, [eax+SLOT_BASE+APPDATA.pl0_stack] - add esi, RING0_STACK_SIZE - cmp [eax+SLOT_BASE+APPDATA.saved_esp0], esi - jz .nov86 + mov eax, [.slot] + shl eax, 8 + mov esi, [eax+SLOT_BASE+APPDATA.pl0_stack] + add esi, RING0_STACK_SIZE + cmp [eax+SLOT_BASE+APPDATA.saved_esp0], esi + jz .nov86 ; ...it has page directory for V86 mode - mov esi, [eax+SLOT_BASE+APPDATA.saved_esp0] - mov ecx, [esi+4] - mov [eax+SLOT_BASE+APPDATA.dir_table], ecx + mov esi, [eax+SLOT_BASE+APPDATA.saved_esp0] + mov ecx, [esi+4] + mov [eax+SLOT_BASE+APPDATA.dir_table], ecx ; ...and I/O permission map for V86 mode - mov ecx, [esi+12] - mov [eax+SLOT_BASE+APPDATA.io_map], ecx - mov ecx, [esi+8] - mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx + mov ecx, [esi+12] + mov [eax+SLOT_BASE+APPDATA.io_map], ecx + mov ecx, [esi+8] + mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx .nov86: - mov esi, [.slot] - shl esi,8 - add esi, SLOT_BASE+APP_OBJ_OFFSET + mov esi, [.slot] + shl esi,8 + add esi, SLOT_BASE+APP_OBJ_OFFSET @@: - mov eax, [esi+APPOBJ.fd] - test eax, eax - jz @F + mov eax, [esi+APPOBJ.fd] + test eax, eax + jz @F - cmp eax, esi - je @F + cmp eax, esi + je @F - push esi - call [eax+APPOBJ.destroy] - DEBUGF 1,"%s",msg_obj_destroy - pop esi - jmp @B + push esi + call [eax+APPOBJ.destroy] + DEBUGF 1,"%s",msg_obj_destroy + pop esi + jmp @B @@: - mov eax, [.slot] - shl eax, 8 - mov eax,[SLOT_BASE+eax+APPDATA.dir_table] - stdcall destroy_app_space, eax + mov eax, [.slot] + shl eax, 8 + mov eax,[SLOT_BASE+eax+APPDATA.dir_table] + stdcall destroy_app_space, eax - mov esi, [.slot] - cmp [fpu_owner],esi ; if user fpu last -> fpu user = 1 - jne @F + mov esi, [.slot] + cmp [fpu_owner],esi ; if user fpu last -> fpu user = 1 + jne @F - mov [fpu_owner],1 - mov eax, [256+SLOT_BASE+APPDATA.fpu_state] - clts - bt [cpu_caps], CAPS_SSE - jnc .no_SSE - fxrstor [eax] - jmp @F + mov [fpu_owner],1 + mov eax, [256+SLOT_BASE+APPDATA.fpu_state] + clts + bt [cpu_caps], CAPS_SSE + jnc .no_SSE + fxrstor [eax] + jmp @F .no_SSE: - fnclex - frstor [eax] + fnclex + frstor [eax] @@: - mov [KEY_COUNT],byte 0 ; empty keyboard buffer - mov [BTN_COUNT],byte 0 ; empty button buffer + mov [KEY_COUNT],byte 0 ; empty keyboard buffer + mov [BTN_COUNT],byte 0 ; empty button buffer ; remove defined hotkeys - mov eax, hotkey_list + mov eax, hotkey_list .loop: - cmp [eax+8], esi - jnz .cont - mov ecx, [eax] - jecxz @f - push dword [eax+12] - pop dword [ecx+12] + cmp [eax+8], esi + jnz .cont + mov ecx, [eax] + jecxz @f + push dword [eax+12] + pop dword [ecx+12] @@: - mov ecx, [eax+12] - push dword [eax] - pop dword [ecx] - xor ecx, ecx - mov [eax], ecx - mov [eax+4], ecx - mov [eax+8], ecx - mov [eax+12], ecx + mov ecx, [eax+12] + push dword [eax] + pop dword [ecx] + xor ecx, ecx + mov [eax], ecx + mov [eax+4], ecx + mov [eax+8], ecx + mov [eax+12], ecx .cont: - add eax, 16 - cmp eax, hotkey_list+256*16 - jb .loop + add eax, 16 + cmp eax, hotkey_list+256*16 + jb .loop ; remove hotkeys in buffer - mov eax, hotkey_buffer + mov eax, hotkey_buffer .loop2: - cmp [eax], esi - jnz .cont2 - and dword [eax+4], 0 - and dword [eax], 0 + cmp [eax], esi + jnz .cont2 + and dword [eax+4], 0 + and dword [eax], 0 .cont2: - add eax, 8 - cmp eax, hotkey_buffer+120*8 - jb .loop2 + add eax, 8 + cmp eax, hotkey_buffer+120*8 + jb .loop2 - mov ecx,esi ; remove buttons + mov ecx,esi ; remove buttons bnewba2: mov edi,[BTN_ADDR] mov eax,edi @@ -558,7 +544,7 @@ term9: inc bx bnewba: dec bx - jz bnmba + jz bnmba add eax,0x10 cmp cx,[eax] jnz bnewba @@ -607,10 +593,10 @@ term9: shl edi, 5 mov eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot] test eax, eax - jz .nodebug + jz .nodebug push 8 pop ecx - push dword [CURRENT_TASK+edi+TASKDATA.pid] ; PID + push dword [CURRENT_TASK+edi+TASKDATA.pid] ; PID push 2 call debugger_notify pop ecx @@ -618,86 +604,86 @@ term9: .nodebug: popad - mov ebx, [.slot] - shl ebx, 8 - push ebx - mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack] + mov ebx, [.slot] + shl ebx, 8 + push ebx + mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack] - stdcall kernel_free, ebx + stdcall kernel_free, ebx - pop ebx - mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir] - stdcall kernel_free, ebx + pop ebx + mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir] + stdcall kernel_free, ebx - mov edi, [.slot] - shl edi,8 - add edi,SLOT_BASE + mov edi, [.slot] + shl edi,8 + add edi,SLOT_BASE - mov eax, [edi+APPDATA.io_map] - cmp eax, (tss._io_map_0-OS_BASE+PG_MAP) - je @F - call free_page + mov eax, [edi+APPDATA.io_map] + cmp eax, (tss._io_map_0-OS_BASE+PG_MAP) + je @F + call free_page @@: - mov eax, [edi+APPDATA.io_map+4] - cmp eax, (tss._io_map_1-OS_BASE+PG_MAP) - je @F - call free_page + mov eax, [edi+APPDATA.io_map+4] + cmp eax, (tss._io_map_1-OS_BASE+PG_MAP) + je @F + call free_page @@: - mov eax, 0x20202020 - stosd - stosd - stosd - mov ecx,244/4 - xor eax, eax - rep stosd + mov eax, 0x20202020 + stosd + stosd + stosd + mov ecx,244/4 + xor eax, eax + rep stosd ; activate window - movzx eax, word [WIN_STACK + esi*2] - cmp eax, [TASK_COUNT] - jne .dont_activate - pushad + movzx eax, word [WIN_STACK + esi*2] + cmp eax, [TASK_COUNT] + jne .dont_activate + pushad .check_next_window: - dec eax - cmp eax, 1 - jbe .nothing_to_activate - lea esi, [WIN_POS+eax*2] - movzx edi, word [esi] ; edi = process - shl edi, 5 - cmp [CURRENT_TASK + edi + TASKDATA.state], byte 9 ; skip dead slots - je .check_next_window - add edi, window_data + dec eax + cmp eax, 1 + jbe .nothing_to_activate + lea esi, [WIN_POS+eax*2] + movzx edi, word [esi] ; edi = process + shl edi, 5 + cmp [CURRENT_TASK + edi + TASKDATA.state], byte 9 ; skip dead slots + je .check_next_window + add edi, window_data ; \begin{diamond}[19.09.2006] ; skip minimized windows - test [edi + WDATA.fl_wstate], WSTATE_MINIMIZED - jnz .check_next_window + test [edi + WDATA.fl_wstate], WSTATE_MINIMIZED + jnz .check_next_window ; \end{diamond} - call waredraw + call waredraw .nothing_to_activate: - popad + popad .dont_activate: - push esi ; remove hd1 & cd & flp reservation - shl esi, 5 - mov esi, [esi+CURRENT_TASK+TASKDATA.pid] - cmp [hd1_status], esi - jnz @f - call free_hd_channel - mov [hd1_status], 0 + push esi ; remove hd1 & cd & flp reservation + shl esi, 5 + mov esi, [esi+CURRENT_TASK+TASKDATA.pid] + cmp [hd1_status], esi + jnz @f + call free_hd_channel + mov [hd1_status], 0 @@: - cmp [cd_status], esi - jnz @f - call free_cd_channel - mov [cd_status], 0 + cmp [cd_status], esi + jnz @f + call free_cd_channel + mov [cd_status], 0 @@: - cmp [flp_status], esi - jnz @f - mov [flp_status], 0 + cmp [flp_status], esi + jnz @f + mov [flp_status], 0 @@: - pop esi - cmp [bgrlockpid], esi - jnz @f - and [bgrlockpid], 0 - mov [bgrlock], 0 + pop esi + cmp [bgrlockpid], esi + jnz @f + and [bgrlockpid], 0 + mov [bgrlock], 0 @@: pusha ; remove all irq reservations @@ -710,16 +696,16 @@ term9: 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 + 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 + jb newirqfree popa - pusha ; remove all port reservations + pusha ; remove all port reservations mov edx,esi shl edx, 5 add edx,CURRENT_TASK @@ -730,7 +716,7 @@ term9: mov esi,[RESERVED_PORTS] cmp esi,0 - je rmpr9 + je rmpr9 rmpr3: @@ -739,7 +725,7 @@ term9: add edi,RESERVED_PORTS cmp edx,[edi] - je rmpr4 + je rmpr4 dec esi jnz rmpr3 @@ -764,7 +750,7 @@ term9: rmpr9: popa - mov edi,esi ; do not run this process slot + mov edi,esi ; do not run this process slot shl edi, 5 mov [edi+CURRENT_TASK + TASKDATA.state],byte 9 ; debugger test - terminate all debuggees @@ -772,7 +758,7 @@ term9: mov ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot .xd0: cmp eax, [TASK_COUNT] - ja .xd1 + ja .xd1 cmp dword [ecx], esi jnz @f and dword [ecx], 0 @@ -809,18 +795,18 @@ term9: restore .slot iglobal - boot_sched_1 db 'Building gdt tss pointer',0 - boot_sched_2 db 'Building IDT table',0 + boot_sched_1 db 'Building gdt tss pointer',0 + boot_sched_2 db 'Building IDT table',0 endg build_scheduler: - mov esi,boot_sched_1 - call boot_log + mov esi,boot_sched_1 + call boot_log ; call build_process_gdt_tss_pointer ; mov esi,boot_sched_2 ; call boot_log - ret + ret diff --git a/kernel/trunk/core/v86.inc b/kernel/trunk/core/v86.inc index 6a93aadf6d..56a94c4f59 100644 --- a/kernel/trunk/core/v86.inc +++ b/kernel/trunk/core/v86.inc @@ -203,7 +203,7 @@ v86_set_page: ; add edx, ecx ; cmp dword [edx], 0 ; free block? ; jnz .n -; cmp dword [edx+4], +; cmp dword [edx+4], ; and [esi+V86_machine.mutex], 0 ; pop edi edx ecx ebx ; ret @@ -351,47 +351,27 @@ endg ; a protected-mode interrupt handler (typically the general-protection ; exception handler, which in turn calls the virtual 8086-mode monitor). -v86_debug_exc: - pushad - xor eax, eax - mov dr6, eax - mov bl, 1 - jmp v86_exc_c - -v86_page_fault: - add esp, 4 - pushad - mov bl, 14 - jmp v86_exc_c - -v86_except_16: - pushad - mov bl, 16 - jmp v86_exc_c -v86_except_19: - pushad - mov bl, 19 - iglobal -v86_exc_str1 db 'V86 : unexpected exception ',0 -v86_exc_str2 db ' at ',0 -v86_exc_str3 db ':',0 -v86_exc_str4 db 13,10,'V86 : faulted code:',0 -v86_exc_str5 db ' (unavailable)',0 -v86_newline db 13,10,0 -v86_io_str1 db 'V86 : access to disabled i/o port ',0 -v86_io_byte db ' (byte)',13,10,0 -v86_io_word db ' (word)',13,10,0 -v86_io_dword db ' (dword)',13,10,0 -v86_irqerr db 'V86 : IRQ already hooked',13,10,0 + v86_exc_str1 db 'V86 : unexpected exception ',0 + v86_exc_str2 db ' at ',0 + v86_exc_str3 db ':',0 + v86_exc_str4 db 13,10,'V86 : faulted code:',0 + v86_exc_str5 db ' (unavailable)',0 + v86_newline db 13,10,0 + v86_io_str1 db 'V86 : access to disabled i/o port ',0 + v86_io_byte db ' (byte)',13,10,0 + v86_io_word db ' (word)',13,10,0 + v86_io_dword db ' (dword)',13,10,0 + v86_irqerr db 'V86 : IRQ already hooked',13,10,0 endg v86_exc_c: - mov ax, app_data - mov ds, ax - mov es, ax ; Did we all that we have wanted to do? - mov eax, [esp+v86_regs.size+10h+18h] + cmp bl,1 + jne @f + xor eax, eax + mov dr6, eax + @@: mov eax, [esp+v86_regs.size+10h+18h] cmp word [esp+v86_regs.eip], ax jnz @f shr eax, 16 diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index 85ce6bd718..1cf31afae6 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -454,8 +454,8 @@ high_code: ; LOAD IDT - call build_interrupt_table - lidt [idtreg] + call build_interrupt_table ;lidt is executed + ;lidt [idtreg] call init_kernel_heap stdcall kernel_alloc, RING0_STACK_SIZE+512 @@ -1296,6 +1296,7 @@ display_number_force: xor edx,edx call division_64_bits div ebx + hexletters = __fdo_hexdigits add edx,hexletters mov dl,[edx] mov [edi],dl diff --git a/kernel/trunk/memmap.inc b/kernel/trunk/memmap.inc index 53675c3f0c..4653627590 100644 --- a/kernel/trunk/memmap.inc +++ b/kernel/trunk/memmap.inc @@ -70,9 +70,9 @@ ; ; A400 -> B0FF free -; B100 -> B2FF IDT +; B100 -> B307 IDT for int_0x00..int_0x40 -; B300 -> BFFF free +; B308 -> BFFF free ; C000 -> C3FF window stack C000 no of windows - all in words ; C402 -> C7FF window position in stack