/kernel/trunk/core/debug.inc |
---|
27,9 → 27,8 |
debug_set_event_data: |
; in: ebx = pointer |
; destroys eax |
mov eax, [CURRENT_TASK] |
shl eax, 8 |
mov [eax+SLOT_BASE+APPDATA.dbg_event_mem], ebx |
mov eax, [current_slot] |
mov [eax+APPDATA.dbg_event_mem], ebx |
ret |
get_debuggee_slot: |
123,7 → 122,6 |
; destroys eax,ecx,edx,esi,edi |
cmp ecx, 28h |
jnz .ret |
add edx, std_application_base_address |
push ebx |
mov ebx, edx |
call check_region |
132,43 → 130,35 |
jnz .ret |
call get_debuggee_slot |
jc .ret |
imul eax, tss_step/32 |
add eax, tss_data |
mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack] |
lea esi, [eax+RING0_STACK_SIZE] |
mov edi, edx |
cmp [eax+TSS._cs], app_code |
jnz .ring0 |
lea esi, [eax+TSS._eip] |
shr ecx, 2 |
rep movsd |
jmp .ret |
.ring0: |
; note that following code assumes that all interrupt/exception handlers |
; saves ring-3 context by push ds es, pushad in this order |
mov esi, [eax+TSS._esp0] |
; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), ds, es, pushad |
sub esi, 8+12+8+20h |
lodsd |
; saves ring-3 context by pushad in this order |
; 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 |
lodsd |
lodsd ;esi |
mov [edi+20h], eax |
lodsd |
lodsd ; ebp |
mov [edi+1Ch], eax |
lodsd |
lodsd |
lodsd ;esp |
lodsd ;ebx |
mov [edi+14h], eax |
lodsd |
lodsd ;edx |
mov [edi+10h], eax |
lodsd |
lodsd ;ecx |
mov [edi+0Ch], eax |
lodsd |
lodsd ;eax |
mov [edi+8], eax |
add esi, 8 |
lodsd |
lodsd ;eip |
mov [edi], eax |
lodsd |
lodsd |
lodsd ;cs |
lodsd ;eflags |
mov [edi+4], eax |
lodsd |
lodsd ;esp |
mov [edi+18h], eax |
.ret: |
sti |
182,7 → 172,6 |
; destroys eax,ecx,edx,esi,edi |
cmp ecx, 28h |
jnz .ret |
add edx, std_application_base_address |
push ebx |
mov ebx, edx |
call check_region |
191,40 → 180,32 |
jnz .ret |
call get_debuggee_slot |
jc .stiret |
imul eax, tss_step/32 |
add eax, tss_data |
mov eax, [eax*8+SLOT_BASE+APPDATA.pl0_stack] |
lea edi, [eax+RING0_STACK_SIZE] |
mov esi, edx |
cmp [eax+TSS._cs], app_code |
jnz .ring0 |
lea edi, [eax+TSS._eip] |
shr ecx, 2 |
rep movsd |
jmp .stiret |
.ring0: |
mov edi, [eax+TSS._esp0] |
sub edi, 8+12+8+20h |
mov eax, [esi+24h] |
sub edi, 8+12+20h |
mov eax, [esi+24h] ;edi |
stosd |
mov eax, [esi+20h] |
mov eax, [esi+20h] ;esi |
stosd |
mov eax, [esi+1Ch] |
mov eax, [esi+1Ch] ;ebp |
stosd |
scasd |
mov eax, [esi+14h] |
mov eax, [esi+14h] ;ebx |
stosd |
mov eax, [esi+10h] |
mov eax, [esi+10h] ;edx |
stosd |
mov eax, [esi+0Ch] |
mov eax, [esi+0Ch] ;ecx |
stosd |
mov eax, [esi+8] |
mov eax, [esi+8] ;eax |
stosd |
add edi, 8 |
mov eax, [esi] |
mov eax, [esi] ;eip |
stosd |
scasd |
mov eax, [esi+4] |
mov eax, [esi+4] ;eflags |
stosd |
mov eax, [esi+18h] |
mov eax, [esi+18h] ;esp |
stosd |
.stiret: |
sti |
238,8 → 219,8 |
lea eax, [eax*8+SLOT_BASE+APPDATA.dbg_regs] |
; [eax]=dr0, [eax+4]=dr1, [eax+8]=dr2, [eax+C]=dr3 |
; [eax+10]=dr7 |
add edx, std_application_base_address |
jc .errret |
cmp edx, OS_BASE |
jae .errret |
cmp cl, 3 |
ja .errret |
mov ebx, dr7 |
256,8 → 237,9 |
btr dword [eax+10h], ecx ; clear L<i> bit |
test byte [eax+10h], 55h |
jnz .okret |
imul eax, ebp, tss_step/32 |
and byte [eax + tss_data + TSS._trap], not 1 |
; 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 |
298,8 → 280,9 |
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 |
; 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 |
debug_read_process_memory: |
310,7 → 293,6 |
; edx=address in debuggee |
; out: [esp+36]=sizeof(read) |
; destroys all |
add esi, std_application_base_address |
push ebx |
mov ebx, esi |
call check_region |
337,7 → 319,6 |
; edx=address in debuggee |
; out: [esp+36]=sizeof(write) |
; destroys all |
add esi, std_application_base_address |
push ebx |
mov ebx, esi |
call check_region |
430,45 → 411,22 |
; int 1 = #DB |
save_ring3_context |
cld |
mov ax, os_data |
mov ax, app_data ;os_data |
mov ds, ax |
mov es, ax |
mov eax, dr6 |
test ax, ax |
jns @f |
; this is exception from task switch |
; set DRx registers for task and continue |
mov eax, [CURRENT_TASK] |
shl eax, 8 |
add eax, SLOT_BASE+APPDATA.dbg_regs |
mov ecx, [eax+0] |
mov dr0, ecx |
mov ecx, [eax+4] |
mov dr1, ecx |
mov ecx, [eax+8] |
mov dr2, ecx |
mov ecx, [eax+0Ch] |
mov dr3, ecx |
xor ecx, ecx |
mov dr6, ecx |
mov ecx, [eax+10h] |
mov dr7, ecx |
restore_ring3_context |
iretd |
@@: |
push eax |
xor eax, eax |
mov dr6, eax |
; test if debugging |
cli |
mov eax, [CURRENT_TASK] |
shl eax, 8 |
mov eax, [SLOT_BASE+eax+APPDATA.debugger_slot] |
mov eax, [current_slot] |
mov eax, [eax+APPDATA.debugger_slot] |
test eax, eax |
jnz .debug |
sti |
; not debuggee => say error and terminate |
add esp, 28h+4 |
add esp, 0x20+4 |
mov [error_interrupt], 1 |
call show_error_parameters |
mov edx, [TASK_BASE] |
/kernel/trunk/core/dll.inc |
---|
6,10 → 6,8 |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
DRV_ENTRY equ 1 |
DRV_EXIT equ -1 |
DRV_COMPAT equ 4 ;minimal required drivers version |
DRV_CURRENT equ 4 ;current drivers model version |
DRV_COMPAT equ 5 ;minimal required drivers version |
DRV_CURRENT equ 5 ;current drivers model version |
DRV_VERSION equ (DRV_COMPAT shl 16) or DRV_CURRENT |
134,7 → 132,7 |
align 16 |
.main: |
save_ring3_context |
mov bx, os_data |
mov bx, app_data ;os_data |
mov ds, bx |
mov es, bx |
161,14 → 159,13 |
proc get_notify stdcall, p_ev:dword |
.wait: |
mov ebx,[CURRENT_TASK] |
shl ebx,8 |
test dword [ebx+SLOT_BASE+0xA8],EVENT_NOTIFY |
mov ebx,[current_slot] |
test dword [ebx+APPDATA.event_mask],EVENT_NOTIFY |
jz @f |
and dword [ebx+SLOT_BASE+0xA8], not EVENT_NOTIFY |
and dword [ebx+APPDATA.event_mask], not EVENT_NOTIFY |
mov edi, [p_ev] |
mov dword [edi], EV_INTR |
mov eax, [ebx+SLOT_BASE+APPDATA.event] |
mov eax, [ebx+APPDATA.event] |
mov dword [edi+4], eax |
ret |
@@: |
256,9 → 253,8 |
align 4 |
srv_handlerEx: |
test ebx, ebx |
jz .fail |
add ebx, new_app_base |
cmp ebx, OS_BASE |
jae .fail |
mov eax, [ebx+handle] |
cmp [eax+SRV.magic], ' SRV' |
267,9 → 263,6 |
cmp [eax+SRV.size], SRV_SIZE |
jne .fail |
add [ebx+input], new_app_base |
add [ebx+output], new_app_base |
stdcall [eax+SRV.srv_proc], ebx |
ret |
.fail: |
410,9 → 403,9 |
xor eax, eax |
mov ebx, [file_name] |
sub ebx, new_app_base |
; sub ebx, new_app_base |
mov ecx, [info] |
sub ecx, new_app_base |
; sub ecx, new_app_base |
mov [cmd], 5 |
mov [offset], eax |
424,7 → 417,7 |
mov eax, 70 |
lea ebx, [cmd] |
sub ebx, new_app_base |
; sub ebx, new_app_base |
int 0x40 |
ret |
endp |
447,8 → 440,6 |
mov ecx, [off] |
mov edx, [bytes] |
mov esi, [buffer] |
sub ebx, new_app_base |
sub esi, new_app_base |
mov [cmd], eax |
mov [offset], ecx |
461,7 → 452,6 |
pushad |
push eax |
lea eax, [cmd] |
sub eax, new_app_base |
call file_system_lfn |
pop eax |
popad |
919,13 → 909,13 |
jmp .next |
.copy: |
add esi, edx |
add edi, new_app_base |
; add edi, new_app_base |
mov ecx, [eax+CFS.SizeOfRawData] |
cld |
rep movsb |
.next: |
add edi, 15-new_app_base |
and edi, not 15 |
add edi, 15 ;-new_app_base |
and edi, -16 |
add eax, COFF_SECTION_SIZE |
dec ebx |
jnz @B |
1006,9 → 996,8 |
test eax, eax |
jz .fail |
mov ecx,[CURRENT_TASK] |
shl ecx,8 |
add ecx, SLOT_BASE+APP_OBJ_OFFSET |
mov ecx,[current_slot] |
add ecx, APP_OBJ_OFFSET |
pushfd |
cli |
1048,21 → 1037,68 |
ret |
;szSound db 'SOUND',0 |
;szInfinity db 'INFINITY',0 |
szHwMouse db 'ATI2D',0 |
szSTART db 'START',0 |
szEXPORTS db 'EXPORTS',0 |
szIMPORTS db 'IMPORTS',0 |
if 0 |
msg_unresolved db 'unresolved ',0 |
msg_module db 'in module ',0 |
msg_version db 'incompatible driver version',13,10,0 |
msg_www db 'please visit www.kolibrios.org',13,10,0 |
msg_CR db 13,10,0 |
irq: |
align 4 |
create_cursor dd 0 |
set_hw_cursor dd 0 |
hw_restore dd 0 |
.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/trunk/core/fpu.inc |
---|
143,7 → 143,7 |
e7: ;#NM exception handler |
save_ring3_context |
clts |
mov ax, os_data |
mov ax, app_data ; |
mov ds, ax |
mov es, ax |
196,10 → 196,10 |
push ecx |
push edx |
mov ebx, [ss:CURRENT_TASK] |
mov ebx, [CURRENT_TASK] |
shl ebx, 8 |
mov eax, [ss:ebx+SLOT_BASE+APPDATA.fpu_handler] |
mov eax, [ebx+SLOT_BASE+APPDATA.fpu_handler] |
test eax, eax |
jz .default |
206,7 → 206,7 |
mov ecx, [reg_eip] |
mov edx, [reg_esp] |
sub edx, 4 |
mov [ss:edx+new_app_base], ecx |
mov [edx], ecx |
mov [reg_esp], edx |
mov dword [reg_eip], eax |
240,10 → 240,9 |
push ecx |
push edx |
mov ebx, [ss:CURRENT_TASK] |
shl ebx, 8 |
mov ebx, [current_slot] |
mov eax, [ss:ebx+SLOT_BASE+APPDATA.sse_handler] |
mov eax, [ebx+APPDATA.sse_handler] |
test eax, eax |
jz .default |
250,7 → 249,7 |
mov ecx, [reg_eip] |
mov edx, [reg_esp] |
sub edx, 4 |
mov [ss:edx+new_app_base], ecx |
mov [edx], ecx |
mov [reg_esp], edx |
mov dword [reg_eip], eax |
/kernel/trunk/core/heap.inc |
---|
621,25 → 621,24 |
align 4 |
proc init_heap |
mov ebx,[CURRENT_TASK] |
shl ebx,8 |
mov eax, [SLOT_BASE+APPDATA.heap_top+ebx] |
mov ebx,[current_slot] |
mov eax, [ebx+APPDATA.heap_top] |
test eax, eax |
jz @F |
sub eax,[SLOT_BASE+APPDATA.heap_base+ebx] |
sub eax,[ebx+APPDATA.heap_base] |
sub eax, 4096 |
ret |
@@: |
mov esi, [SLOT_BASE+APPDATA.mem_size+ebx] |
mov esi, [ebx+APPDATA.mem_size] |
add esi, 4095 |
and esi, not 4095 |
mov [SLOT_BASE+APPDATA.mem_size+ebx], esi |
mov [ebx+APPDATA.mem_size], esi |
mov eax, HEAP_TOP |
mov [SLOT_BASE+APPDATA.heap_base+ebx], esi |
mov [SLOT_BASE+APPDATA.heap_top+ebx], eax |
mov [ebx+APPDATA.heap_base], esi |
mov [ebx+APPDATA.heap_top], eax |
sub eax, esi |
add esi, new_app_base |
; add esi, new_app_base |
shr esi, 10 |
mov ecx, eax |
sub eax, 4096 |
658,12 → 657,9 |
add ecx, (4095+4096) |
and ecx, not 4095 |
mov ebx, [CURRENT_TASK] |
shl ebx, 8 |
mov esi, dword [ebx+SLOT_BASE+APPDATA.heap_base]; heap_base |
mov edi, dword [ebx+SLOT_BASE+APPDATA.heap_top]; heap_top |
add esi, new_app_base |
add edi, new_app_base |
mov ebx, [current_slot] |
mov esi, dword [ebx+APPDATA.heap_base] ; heap_base |
mov edi, dword [ebx+APPDATA.heap_top] ; heap_top |
l_0: |
cmp esi, edi |
jae m_exit |
684,7 → 680,6 |
or eax, FREE_BLOCK |
shr edx, 12 |
mov [page_tabs+edx*4], eax |
@@: |
or ecx, USED_BLOCK |
mov [page_tabs+ebx*4], ecx |
697,17 → 692,15 |
dec ecx |
jnz @B |
mov edx, [CURRENT_TASK] |
shl edx, 8 |
mov edx, [current_slot] |
mov ebx, [alloc_size] |
add ebx, 0xFFF |
and ebx, not 0xFFF |
add ebx, [SLOT_BASE+APPDATA.mem_size+edx] |
add ebx, [edx+APPDATA.mem_size] |
call update_mem_size |
mov eax, esi |
add eax, 4096 |
sub eax, new_app_base |
ret |
m_next: |
add esi, eax |
760,11 → 753,10 |
dec ecx |
jnz .release |
.not_used: |
mov edx, [CURRENT_TASK] |
shl edx, 8 |
mov esi, dword [edx+SLOT_BASE+APPDATA.heap_base]; heap_base |
mov edi, dword [edx+SLOT_BASE+APPDATA.heap_top]; heap_top |
sub ebx, [edx+SLOT_BASE+APPDATA.mem_size] |
mov edx, [current_slot] |
mov esi, dword [edx+APPDATA.heap_base] |
mov edi, dword [edx+APPDATA.heap_top] |
sub ebx, [edx+APPDATA.mem_size] |
neg ebx |
call update_mem_size |
call user_normalize |
779,8 → 771,6 |
; in: esi=heap_base, edi=heap_top |
; out: eax=0 <=> OK |
; destroys: ebx,edx,esi,edi |
add esi, new_app_base |
add edi, new_app_base |
shr esi, 12 |
shr edi, 12 |
@@: |
835,7 → 825,7 |
ret |
@@: |
push ecx edx |
lea ecx, [eax + new_app_base - 0x1000] |
lea ecx, [eax - 0x1000] |
shr ecx, 12 |
mov edx, [page_tabs+ecx*4] |
test edx, USED_BLOCK |
874,16 → 864,15 |
jnz .nofreeall |
mov eax, [page_tabs+ecx*4] |
and eax, not 0xFFF |
mov edx, [CURRENT_TASK] |
shl edx, 8 |
mov ebx, [SLOT_BASE+APPDATA.mem_size+edx] |
mov edx, [current_slot] |
mov ebx, [APPDATA.mem_size+edx] |
sub ebx, eax |
add ebx, 0x1000 |
or al, FREE_BLOCK |
mov [page_tabs+ecx*4], eax |
push esi edi |
mov esi, [SLOT_BASE+APPDATA.heap_base+edx] |
mov edi, [SLOT_BASE+APPDATA.heap_top+edx] |
mov esi, [APPDATA.heap_base+edx] |
mov edi, [APPDATA.heap_top+edx] |
call update_mem_size |
call user_normalize |
pop edi esi |
896,14 → 885,13 |
shr ebx, 12 |
sub ebx, edx |
push ebx ecx edx |
mov edx, [CURRENT_TASK] |
shl edx, 8 |
mov edx, [current_slot] |
shl ebx, 12 |
sub ebx, [SLOT_BASE+APPDATA.mem_size+edx] |
sub ebx, [APPDATA.mem_size+edx] |
neg ebx |
call update_mem_size |
pop edx ecx ebx |
lea eax, [ecx+1-(new_app_base shr 12)] |
lea eax, [ecx+1] |
shl eax, 12 |
push eax |
add ecx, ebx |
911,9 → 899,8 |
shl ebx, 12 |
jz .ret |
push esi |
mov esi, [CURRENT_TASK] |
shl esi, 8 |
mov esi, [SLOT_BASE+APPDATA.heap_top+esi] |
mov esi, [current_slot] |
mov esi, [APPDATA.heap_top+esi] |
shr esi, 12 |
@@: |
cmp edx, esi |
935,10 → 922,8 |
ret |
.realloc_add: |
; get some additional memory |
mov eax, [CURRENT_TASK] |
shl eax, 8 |
mov eax, [SLOT_BASE+APPDATA.heap_top+eax] |
add eax, new_app_base |
mov eax, [current_slot] |
mov eax, [APPDATA.heap_top+eax] |
shr eax, 12 |
cmp edx, eax |
jae .cant_inplace |
958,7 → 943,7 |
shl eax, 12 |
or al, USED_BLOCK |
mov [page_tabs+ecx*4], eax |
lea eax, [ecx+1-(new_app_base shr 12)] |
lea eax, [ecx+1] |
shl eax, 12 |
push eax |
push edi |
969,21 → 954,17 |
cld |
rep stosd |
pop edi |
mov edx, [CURRENT_TASK] |
shl edx, 8 |
mov edx, [current_slot] |
shl ebx, 12 |
add ebx, [SLOT_BASE+APPDATA.mem_size+edx] |
add ebx, [APPDATA.mem_size+edx] |
call update_mem_size |
pop eax edx ecx |
ret |
.cant_inplace: |
push esi edi |
mov eax, [CURRENT_TASK] |
shl eax, 8 |
mov esi, [SLOT_BASE+APPDATA.heap_base+eax] |
mov edi, [SLOT_BASE+APPDATA.heap_top+eax] |
add esi, new_app_base |
add edi, new_app_base |
mov eax, [current_slot] |
mov esi, [APPDATA.heap_base+eax] |
mov edi, [APPDATA.heap_top+eax] |
shr esi, 12 |
shr edi, 12 |
sub ebx, ecx |
1022,7 → 1003,6 |
inc esi |
mov eax, esi |
shl eax, 12 |
sub eax, new_app_base |
push eax |
mov eax, [page_tabs+ecx*4] |
and eax, not 0xFFF |
1043,10 → 1023,9 |
dec edx |
jnz @b |
push ebx |
mov edx, [CURRENT_TASK] |
shl edx, 8 |
mov edx, [current_slot] |
shl ebx, 12 |
add ebx, [SLOT_BASE+APPDATA.mem_size+edx] |
add ebx, [APPDATA.mem_size+edx] |
call update_mem_size |
pop ebx |
@@: |
/kernel/trunk/core/malloc.inc |
---|
992,7 → 992,7 |
mov [eax+12], eax |
add eax, 16 |
cmp eax, mst.smallbins+512 |
jl @B |
jb @B |
ret |
/kernel/trunk/core/memory.inc |
---|
6,163 → 6,7 |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
tmp_page_tab equ HEAP_BASE |
align 4 |
proc mem_test |
mov eax, cr0 |
and eax, not (CR0_CD+CR0_NW) |
or eax, CR0_CD ;disable caching |
mov cr0, eax |
wbinvd ;invalidate cache |
xor edi, edi |
mov ebx, 'TEST' |
@@: |
add edi, 0x400000 |
xchg ebx, dword [edi] |
cmp dword [edi], 'TEST' |
xchg ebx, dword [edi] |
je @b |
mov [MEM_AMOUNT], edi |
and eax, not (CR0_CD+CR0_NW) ;enable caching |
mov cr0, eax |
mov eax, edi |
mov [LFBSize], 0x00800000 |
ret |
endp |
align 4 |
proc init_mem |
mov eax, [MEM_AMOUNT] |
mov [pg_data.mem_amount], eax |
mov [pg_data.kernel_max], eax |
shr eax, 12 |
mov edx, eax |
mov [pg_data.pages_count], eax |
mov [pg_data.kernel_pages], eax |
shr eax, 3 |
mov [pg_data.pagemap_size], eax |
shr edx, 10 |
cmp edx, 3 |
ja @f |
inc edx ;at least 4Mb for kernel heap |
@@: |
mov [pg_data.kernel_tables], edx |
xor eax, eax |
mov edi, sys_pgdir |
mov ecx, 2048 |
cld |
rep stosd |
mov edx, sys_pgdir |
bt [cpu_caps], CAPS_PSE |
jnc .no_PSE |
mov ebx, cr4 |
or ebx, CR4_PSE |
mov eax, PG_LARGE+PG_SW |
bt [cpu_caps], CAPS_PGE |
jnc @F |
or eax, PG_GLOBAL |
or ebx, CR4_PGE |
@@: |
mov cr4, ebx |
sub [pg_data.kernel_tables], 2 |
mov [edx], eax |
add eax, 0x00400000 |
mov [edx+4], eax |
add edx, 8 |
mov eax, 0x800000+PG_SW |
mov ecx, (HEAP_BASE-0x800000)/4096 |
jmp .map_low |
.no_PSE: |
mov eax, PG_SW |
mov ecx, HEAP_BASE/4096 |
.map_low: |
mov edi, tmp_page_tab |
@@: ; |
stosd |
add eax, 0x1000 |
dec ecx |
jnz @B |
mov ecx, [pg_data.kernel_tables] |
shl ecx, 10 |
xor eax, eax |
rep stosd |
mov ecx, [pg_data.kernel_tables] |
mov eax, tmp_page_tab+PG_SW |
mov edi, edx |
.map_kernel_tabs: |
stosd |
add eax, 0x1000 |
dec ecx |
jnz .map_kernel_tabs |
mov dword [sys_pgdir+(page_tabs shr 20)], sys_pgdir+PG_SW |
ret |
endp |
align 4 |
proc init_page_map |
mov edi, sys_pgmap |
mov ecx, (HEAP_BASE/4096)/32 ;384/4 |
mov ebx, ecx |
xor eax,eax |
cld |
rep stosd |
not eax |
mov ecx, [pg_data.pagemap_size] |
sub ecx, ebx |
shr ecx, 2 |
rep stosd |
lea edi, [sys_pgmap+ebx*4] ;+384 |
mov edx, [pg_data.pages_count] |
mov ecx, [pg_data.kernel_tables] |
add ecx, (HEAP_BASE/4096) and 31 |
sub edx, HEAP_BASE/4096 |
sub edx, ecx |
mov [pg_data.pages_free], edx |
xor eax, eax |
mov ebx, ecx |
shr ecx, 5 |
rep stosd |
not eax |
mov ecx, ebx |
and ecx, 31 |
shl eax, cl |
mov [page_start], edi; sys_pgmap+384 |
stosd |
mov ebx, sys_pgmap |
add ebx, [pg_data.pagemap_size] |
mov [page_end], ebx |
mov [pg_data.pg_mutex], 0 |
ret |
endp |
align 4 |
proc alloc_page |
pushfd |
400,7 → 244,7 |
@@: |
mov edx, LFB_BASE |
mov esi, [LFBAddress] |
mov edi, [LFBSize] |
mov edi, 0x00800000 |
mov dword [exp_lfb+4], edx |
shr edi, 12 |
410,10 → 254,9 |
bt [cpu_caps], CAPS_PSE |
jnc .map_page_tables |
or esi, PG_LARGE+PG_UW |
shr edx, 20 |
mov ecx, edx |
mov edx, sys_pgdir+(LFB_BASE shr 20) |
@@: |
mov [sys_pgdir+edx], esi |
mov [edx], esi |
add edx, 4 |
add esi, 0x00400000 |
dec edi |
421,7 → 264,7 |
bt [cpu_caps], CAPS_PGE |
jnc @F |
or dword [sys_pgdir+ecx], PG_GLOBAL |
or dword [sys_pgdir+(LFB_BASE shr 20)], PG_GLOBAL |
@@: |
mov dword [LFBAddress], LFB_BASE |
mov eax, cr3 ;flush TLB |
430,11 → 273,12 |
.map_page_tables: |
@@: |
call alloc_page |
stdcall map_page_table, edx, eax |
add edx, 0x00400000 |
dec edi |
jnz .map_page_tables |
jnz @B |
mov eax, [LFBAddress] |
mov edi, page_tabs + (LFB_BASE shr 10) |
465,12 → 309,11 |
and edi,not 4095 |
mov [new_size], edi |
mov edx,[CURRENT_TASK] |
shl edx,8 |
cmp [SLOT_BASE+APPDATA.heap_base+edx],0 |
mov edx,[current_slot] |
cmp [edx+APPDATA.heap_base],0 |
jne .exit |
mov esi, [SLOT_BASE+APPDATA.mem_size+edx] |
mov esi, [edx+APPDATA.mem_size] |
add esi, 4095 |
and esi, not 4095 |
500,10 → 343,7 |
xor eax, eax |
dec [pg_data.pg_mutex] |
ret |
.expand: |
add edi, new_app_base |
add esi, new_app_base |
push esi |
push edi |
567,14 → 407,14 |
endp |
update_mem_size: |
; in: edx = slot shl 8 |
; in: edx = slot base |
; ebx = new memory size |
; destroys eax,ecx,edx |
mov [SLOT_BASE+APPDATA.mem_size+edx],ebx |
mov [APPDATA.mem_size+edx],ebx |
;search threads and update |
;application memory size infomation |
mov ecx,[SLOT_BASE+APPDATA.dir_table+edx] |
mov ecx,[APPDATA.dir_table+edx] |
mov eax,2 |
.search_threads: |
610,53 → 450,75 |
and eax, 0xFFFFF000 |
ret |
align 4 |
proc page_fault_handler |
.err_code equ ebp+32 |
.err_addr equ ebp-4 |
pushad |
mov ebp, esp |
mov eax, cr2 |
push eax |
push ds |
push es |
mov ax, 0x10 |
mov ax, app_data |
mov ds, ax |
mov es, ax |
inc [pg_data.pages_faults] |
mov ebx, [ebp-4] |
; push eax |
; push edx |
; mov edx, 0x400 ;bochs |
; mov al,0xff ;bochs |
; out dx, al ;bochs |
; pop edx |
; pop eax |
cmp ebx, 0x80000000 |
jae .user_space |
mov ebx, [.err_addr] |
mov eax, [.err_code] |
cmp ebx, app_page_tabs |
jae .alloc |
cmp ebx, OS_BASE |
jb .user_space ;ñòðàíèöà â ïàìÿòè ïðèëîæåíèÿ ; |
cmp ebx, page_tabs |
jae .tab_space |
jb .kernel_space ;ñòðàíèöà â ïàìÿòè ÿäðà |
cmp ebx, 0x7DC00000 |
jae .lfb_addr |
cmp ebx, kernel_tabs |
jb .alloc;.app_tabs ;òàáëèöû ñòðàíèö ïðèëîæåíèÿ ; |
;ïðîñòî ñîçäàäèì îäíó |
jmp .kernel_space |
cmp ebx, LFB_BASE |
jb .core_tabs ;òàáëèöû ñòðàíèö ÿäðà |
;Îøèáêà |
.lfb: |
;îáëàñòü LFB |
;Îøèáêà |
jmp .fail |
align 4 |
.user_space: |
test eax, PG_MAP |
jnz .err_access ;Ñòðàíèöà ïðèñóòñòâóåò |
;Îøèáêà äîñòóïà ? |
shr ebx, 12 |
mov ecx, ebx |
shr ecx, 10 |
mov edx, [master_tab+ecx*4] |
test edx, 1 |
jz .fail |
test edx, PG_MAP |
jz .fail ;òàáëèöà ñòðàíèö íå ñîçäàíà |
;íåâåðíûé àäðåñ â ïðîãðàììå |
mov eax, [page_tabs+ebx*4] |
test eax, 2 |
jz .fail |
jz .fail ;àäðåñ íå çàðåçåðâèðîâàí äëÿ ; |
;èñïîëüçîâàíèÿ. Îøèáêà |
.alloc: |
call alloc_page |
and eax, eax |
jz .exit |
jz .fail |
stdcall map_page,[ebp-4],eax,dword PG_UW |
667,49 → 529,76 |
cld |
rep stosd |
.exit: |
pop es |
pop ds |
mov esp, ebp |
popad |
add esp, 4 |
iretd |
.err_access: |
;íèêîãäà íå ïðîèñõîäèò |
jmp .fail |
.kernel_space: |
test eax, PG_MAP |
jz .fail ;ñòðàíèöà íå ïðèñóòñòâóåò |
test eax, 4 ;U/S |
jnz .fail ;ïðèëîæåíèå îáðàòèëîñü ê ïàìÿòè |
;ÿäðà |
test eax, 8 |
jnz .fail ;óñòàíîâëåí çàðåçåðâèðîâàííûé áèò |
;â òàáëèöàõ ñòðàíèö. äîáàâëåíî â P4/Xeon |
;ïîïûòêà çàïèñè â çàùèù¸ííóþ ñòðàíèöó ÿäðà |
cmp ebx, tss._io_map_0 |
jb .fail |
cmp ebx, tss._io_map_0+8192 |
jae .fail |
; io permission map |
; copy-on-write protection |
call alloc_page |
and 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 |
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: |
pop es |
pop ds |
mov esp, ebp |
popad |
add esp, 4 |
; iretd |
save_ring3_context ;debugger support |
mov bl, 14 |
jmp exc_c |
iretd |
.kernel_space: |
; shr ebx, 12 |
; mov eax, [page_tabs+ebx*4] |
; shr ebx, 10 |
; mov eax, [master_tab+ebx*4] |
jmp .exit |
.old_addr: |
; shr ebx, 12 |
; mov eax, [page_tabs+ebx*4] |
; shr ebx, 10 |
; mov eax, [master_tab+ebx*4] |
jmp .exit |
.lfb_addr: |
; shr ebx, 22 |
; ;mov ecx, [sys_page_dir] |
; mov eax, [master_tab+ebx*4] |
jmp .exit |
.tab_space: |
; shr ebx, 12 |
; mov eax, [page_tabs+ebx*4] |
; shr ebx, 10 |
; ;mov ecx, [sys_page_dir] |
; mov eax, [master_tab+ebx*4] |
jmp .exit |
endp |
align 4 |
845,15 → 734,12 |
align 4 |
proc set_ipc_buff |
mov eax,[CURRENT_TASK] |
shl eax,8 |
add eax, SLOT_BASE |
mov eax,[current_slot] |
pushf |
cli |
mov [eax+0xA0],ebx ;set fields in extended information area |
mov [eax+0xA4],ecx |
mov [eax+APPDATA.ipc_start],ebx ;set fields in extended information area |
mov [eax+APPDATA.ipc_size],ecx |
add ebx, new_app_base |
add ecx, ebx |
add ecx, 4095 |
and ecx, not 4095 |
890,7 → 776,7 |
jz .no_ipc_area |
mov ebx, edi |
add edi, new_app_base |
; add edi, new_app_base |
and ebx, 0xFFF |
mov [dst_offset], ebx |
924,7 → 810,7 |
mov [edi+4], ecx |
add edi, 8 |
mov esi, [msg_addr] |
add esi, new_app_base |
; add esi, new_app_base |
cld |
rep movsb |
982,9 → 868,9 |
align 4 |
sysfn_meminfo: |
add ebx, new_app_base |
cmp ebx, new_app_base |
jb .fail |
; add ebx, new_app_base |
cmp ebx, OS_BASE |
jae .fail |
mov eax, [pg_data.pages_count] |
mov [ebx], eax |
1030,7 → 916,6 |
@@: |
cmp eax, 13 |
ja @f |
add ebx, new_app_base |
stdcall user_free, ebx |
mov [esp+36], eax |
ret |
1037,9 → 922,8 |
@@: |
cmp eax, 14 |
ja @f |
add ebx, new_app_base |
cmp ebx, new_app_base |
jb .fail |
cmp ebx, OS_BASE |
jae .fail |
stdcall get_event_ex, ebx, ecx |
mov [esp+36], eax |
ret |
1046,10 → 930,9 |
@@: |
cmp eax, 15 |
ja @f |
mov ecx, [CURRENT_TASK] |
shl ecx, 8 |
mov eax, [ecx+SLOT_BASE+APPDATA.fpu_handler] |
mov [ecx+SLOT_BASE+APPDATA.fpu_handler], ebx |
mov ecx, [current_slot] |
mov eax, [ecx+APPDATA.fpu_handler] |
mov [ecx+APPDATA.fpu_handler], ebx |
mov [esp+36], eax |
ret |
@@: |
1058,9 → 941,8 |
test ebx, ebx |
jz .fail |
add ebx, new_app_base |
cmp ebx, new_app_base |
jb .fail |
cmp ebx, OS_BASE |
jae .fail |
stdcall get_service, ebx |
mov [esp+36], eax |
ret |
1073,18 → 955,16 |
@@: |
cmp eax, 18 |
ja @f |
mov ecx, [CURRENT_TASK] |
shl ecx, 8 |
mov eax, [ecx+SLOT_BASE+APPDATA.sse_handler] |
mov [ecx+SLOT_BASE+APPDATA.sse_handler], ebx |
mov ecx, [current_slot] |
mov eax, [ecx+APPDATA.sse_handler] |
mov [ecx+APPDATA.sse_handler], ebx |
mov [esp+36], eax |
ret |
@@: |
cmp eax, 19 |
ja @f |
add ebx, new_app_base |
cmp ebx, new_app_base |
jb .fail |
cmp ebx, OS_BASE |
jae .fail |
stdcall load_library, ebx |
mov [esp+36], eax |
ret |
1103,144 → 983,6 |
ret |
align 4 |
proc strncmp stdcall, str1:dword, str2:dword, count:dword |
mov ecx,[count] |
jecxz .end |
mov ebx,ecx |
mov edi,[str1] |
mov esi,edi |
xor eax,eax |
repne scasb |
neg ecx ; cx = count - strlen |
add ecx,ebx ; strlen + count - strlen |
.okay: |
mov edi,esi |
mov esi,[str2] |
repe cmpsb |
mov al,[esi-1] |
xor ecx,ecx |
cmp al,[edi-1] |
ja .str2_big |
je .end |
.str1_big: |
sub ecx,2 |
.str2_big: |
not ecx |
.end: |
mov eax,ecx |
ret |
endp |
align 4 |
proc test_cpu |
locals |
cpu_type dd ? |
cpu_id dd ? |
cpu_Intel dd ? |
cpu_AMD dd ? |
endl |
mov [cpu_type], 0 |
xor eax, eax |
mov [cpu_caps], eax |
mov [cpu_caps+4], eax |
pushfd |
pop eax |
mov ecx, eax |
xor eax, 0x40000 |
push eax |
popfd |
pushfd |
pop eax |
xor eax, ecx |
mov [cpu_type], CPU_386 |
jz .end_cpuid |
push ecx |
popfd |
mov [cpu_type], CPU_486 |
mov eax, ecx |
xor eax, 0x200000 |
push eax |
popfd |
pushfd |
pop eax |
xor eax, ecx |
je .end_cpuid |
mov [cpu_id], 1 |
xor eax, eax |
cpuid |
mov [cpu_vendor], ebx |
mov [cpu_vendor+4], edx |
mov [cpu_vendor+8], ecx |
cmp ebx, dword [intel_str] |
jne .check_AMD |
cmp edx, dword [intel_str+4] |
jne .check_AMD |
cmp ecx, dword [intel_str+8] |
jne .check_AMD |
mov [cpu_Intel], 1 |
cmp eax, 1 |
jl .end_cpuid |
mov eax, 1 |
cpuid |
mov [cpu_sign], eax |
mov [cpu_info], ebx |
mov [cpu_caps], edx |
mov [cpu_caps+4],ecx |
shr eax, 8 |
and eax, 0x0f |
ret |
.end_cpuid: |
mov eax, [cpu_type] |
ret |
.check_AMD: |
cmp ebx, dword [AMD_str] |
jne .unknown |
cmp edx, dword [AMD_str+4] |
jne .unknown |
cmp ecx, dword [AMD_str+8] |
jne .unknown |
mov [cpu_AMD], 1 |
cmp eax, 1 |
jl .unknown |
mov eax, 1 |
cpuid |
mov [cpu_sign], eax |
mov [cpu_info], ebx |
mov [cpu_caps], edx |
mov [cpu_caps+4],ecx |
shr eax, 8 |
and eax, 0x0f |
ret |
.unknown: |
mov eax, 1 |
cpuid |
mov [cpu_sign], eax |
mov [cpu_info], ebx |
mov [cpu_caps], edx |
mov [cpu_caps+4],ecx |
shr eax, 8 |
and eax, 0x0f |
ret |
endp |
MEM_WB equ 6 ;write-back memory |
MEM_WC equ 1 ;write combined memory |
MEM_UC equ 0 ;uncached memory |
align 4 |
proc init_mtrr |
cmp [BOOT_VAR+0x901c],byte 2 |
1314,7 → 1056,44 |
ret |
endp |
align 4 |
proc strncmp stdcall, str1:dword, str2:dword, count:dword |
mov ecx,[count] |
jecxz .end |
mov ebx,ecx |
mov edi,[str1] |
mov esi,edi |
xor eax,eax |
repne scasb |
neg ecx ; cx = count - strlen |
add ecx,ebx ; strlen + count - strlen |
.okay: |
mov edi,esi |
mov esi,[str2] |
repe cmpsb |
mov al,[esi-1] |
xor ecx,ecx |
cmp al,[edi-1] |
ja .str2_big |
je .end |
.str1_big: |
sub ecx,2 |
.str2_big: |
not ecx |
.end: |
mov eax,ecx |
ret |
endp |
align 4 |
proc stall stdcall, delay:dword |
push ecx |
push edx |
1341,107 → 1120,7 |
ret |
endp |
iglobal |
align 4 |
intel_str db "GenuineIntel",0 |
AMD_str db "AuthenticAMD",0 |
endg |
uglobal |
align 16 |
irq_tab rd 16 |
MEM_FreeSpace rd 1 |
ipc_tmp rd 1 |
ipc_pdir rd 1 |
ipc_ptab rd 1 |
proc_mem_map rd 1 |
proc_mem_pdir rd 1 |
proc_mem_tab rd 1 |
tmp_task_pdir rd 1 |
tmp_task_ptab rd 1 |
fdd_buff rd 1 |
LFBSize rd 1 |
stall_mcs rd 1 |
;;CPUID information |
cpu_vendor rd 3 |
cpu_sign rd 1 |
cpu_info rd 1 |
;;;;; cursors data |
align 16 |
cur_saved_data rb 4096 |
def_cursor rd 1 |
hw_cursor rd 1 |
scr_width rd 1 |
scr_height rd 1 |
cur_def_interl rd 1 |
cur_saved_base rd 1 |
cur_saved_interl rd 1 |
cur_saved_w rd 1 |
cur_saved_h rd 1 |
endg |
uglobal |
align 16 |
fpu_data: |
rb 512 |
mst MEM_STATE |
mem_block_map rb 512 |
event_map rb 64 |
mem_block_list rd 64 |
mem_block_mask rd 2 |
srv.fd rd 1 |
srv.bk rd 1 |
mem_used.fd rd 1 |
mem_used.bk rd 1 |
mem_block_arr rd 1 |
mem_block_start rd 1 |
mem_block_end rd 1 |
heap_mutex rd 1 |
heap_size rd 1 |
heap_free rd 1 |
heap_blocks rd 1 |
free_blocks rd 1 |
page_start rd 1 |
page_end rd 1 |
events rd 1 |
event_start rd 1 |
event_end rd 1 |
event_uid rd 1 |
sys_page_map rd 1 |
os_stack rd 1 |
endg |
if 0 |
push eax |
push edx |
mov edx, 0x400 ;bocsh |
mov al,0xff ;bocsh |
out dx, al ;bocsh |
pop edx |
pop eax |
end if |
align 4 |
k_strrchr: |
push eax |
xor eax,eax |
1660,3 → 1339,15 |
ret |
end if |
if 0 |
push eax |
push edx |
mov edx, 0x400 ;bochs |
mov al,0xff ;bochs |
out dx, al ;bochs |
pop edx |
pop eax |
end if |
/kernel/trunk/core/sched.inc |
---|
10,10 → 10,12 |
;; IRQ0 HANDLER (TIMER INTERRUPT) ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
align 32 |
irq0: |
save_ring3_context |
mov ax, os_data |
; pushfd |
pushad |
mov ax, app_data ; |
mov ds, ax |
mov es, ax |
28,7 → 30,6 |
mov [next_usage_update],eax |
call updatecputimes |
.nocounter: |
cmp [DONT_SWITCH], byte 1 |
jne .change_task |
38,8 → 39,9 |
mov [DONT_SWITCH], byte 0 |
restore_ring3_context |
iret |
popad |
; popfd |
iretd |
.change_task: |
call update_counters |
57,8 → 59,9 |
call do_change_task |
.return: |
restore_ring3_context |
iret |
popad |
; popfd |
iretd |
align 4 |
69,6 → 72,9 |
pushad |
call update_counters |
if 0 |
; \begin{Mario79} |
cmp [dma_task_switched], 1 |
jne .find_next_task |
82,6 → 88,9 |
jmp @f |
.find_next_task: |
; \end{Mario79} |
end if |
call find_next_task |
test eax, eax ; the same task -> skip switch |
jnz .return |
92,7 → 101,6 |
.return: |
popad |
popfd |
ret |
112,7 → 120,7 |
update_counters: |
mov edi, [TASK_BASE] |
mov ebx, [edi+TASKDATA.counter_add] ; time stamp counter add |
call _rdtsc |
rdtsc |
sub eax, ebx |
add eax, [edi+TASKDATA.counter_sum] ; counter sum |
mov [edi+TASKDATA.counter_sum], eax |
159,12 → 167,6 |
mov [CURRENT_TASK],ebx |
mov [TASK_BASE],edi |
push ebx |
shl ebx, 8 |
mov ebx, [SLOT_BASE + ebx + APPDATA.pl0_stack] |
add ebx, RING0_STACK_SIZE |
mov [CURRENT_RING0_ESP], ebx |
pop ebx |
cmp al, 5 |
jne .noevents |
177,27 → 179,66 |
.found: |
mov [CURRENT_TASK],ebx |
mov [TASK_BASE],edi |
call _rdtsc |
rdtsc ;call _rdtsc |
mov [edi+TASKDATA.counter_add],eax |
mov esi, [prev_slot] |
xor eax, eax |
cmp ebx, [prev_slot] |
cmp ebx, esi |
sete al |
ret |
; in: ebx = TSS selector index |
; param |
; ebx = incoming task |
; esi = outcomig task |
do_change_task: |
shl ebx, 3 |
xor eax, eax |
add ebx, tss0 |
mov [far_jump.sel], bx ; selector |
mov [far_jump.offs], eax ; offset |
jmp pword [far_jump] |
shl ebx, 8 |
add ebx, SLOT_BASE |
mov [current_slot], ebx |
shl esi, 8 |
add esi, SLOT_BASE |
mov [esi+APPDATA.saved_esp], esp |
mov esp, [ebx+APPDATA.saved_esp] |
; set thread io map |
mov ecx, [ebx+APPDATA.io_map] |
mov edx, [ebx+APPDATA.io_map+4] |
mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)], ecx |
mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)], edx |
mov eax, [ebx+APPDATA.dir_table] |
mov cr3, eax |
mov ebx, [ebx+APPDATA.pl0_stack] |
add ebx, RING0_STACK_SIZE |
mov [tss._esp0], ebx |
mov ecx, cr0 |
or ecx, CR0_TS ;set task switch flag |
mov cr0, ecx |
inc [context_counter] ;noname & halyavin |
test [ebx+APPDATA.dbg_state], 1 |
jnz @F |
ret |
@@: |
mov eax, [ebx+APPDATA.dbg_regs.dr0] |
mov dr0, eax |
mov eax, [ebx+APPDATA.dbg_regs.dr1] |
mov dr1, eax |
mov eax, [ebx+APPDATA.dbg_regs.dr2] |
mov dr2, eax |
mov eax, [ebx+APPDATA.dbg_regs.dr3] |
mov dr3, eax |
xor eax, eax |
mov dr6, eax |
mov eax, [ebx+APPDATA.dbg_regs.dr7] |
mov dr7, eax |
ret |
align 4 |
updatecputimes: |
215,3 → 256,108 |
jnz .newupdate |
ret |
if 0 |
struc TIMER |
{ |
.next dd ? |
.exp_time dd ? |
.func dd ? |
.arg dd ? |
} |
MAX_PROIRITY 0 ; highest, used for kernel tasks |
MAX_USER_PRIORITY 0 ; highest priority for user processes |
USER_PRIORITY 7 ; default (should correspond to nice 0) |
MIN_USER_PRIORITY 14 ; minimum priority for user processes |
IDLE_PRIORITY 15 ; lowest, only IDLE process goes here |
NR_SCHED_QUEUES 16 ; MUST equal IDLE_PRIORYTY + 1 |
rdy_head rd 16 |
align 4 |
pick_task: |
xor eax, eax |
.pick: |
mov ebx, [rdy_head+eax*4] |
test ebx, ebx |
jz .next |
mov [next_task], ebx |
test [ebx+flags.billable] |
jz @F |
mov [bill_task], ebx |
@@: |
ret |
.next: |
inc eax |
jmp .pick |
; param |
; eax= task |
; |
; retval |
; eax= task |
; ebx= queue |
; ecx= front if 1 or back if 0 |
align 4 |
shed: |
cmp [eax+.tics_left], 0 ;signed compare |
mov ebx, [eax+.priority] |
setg ecx |
jg @F |
mov edx, [eax+.tics_quantum] |
mov [eax+.ticks_left], edx |
cmp ebx, (IDLE_PRIORITY-1) |
je @F |
inc ebx |
@@: |
ret |
; param |
; eax= task |
align 4 |
enqueue: |
call shed ;eax |
cmp [rdy_head+ebx*4],0 |
jnz @F |
mov [rdy_head+ebx*4], eax |
mov [rdy_tail+ebx*4], eax |
mov [eax+.next_ready], 0 |
jmp .pick |
@@: |
test ecx, ecx |
jz .back |
mov ecx, [rdy_head+ebx*4] |
mov [eax+.next_ready], ecx |
mov [rdy_head+ebx*4], eax |
jmp .pick |
.back: |
mov ecx, [rdy_tail+ebx*4] |
mov [ecx+.next_ready], eax |
mov [rdy_tail+ebx*4], eax |
mov [eax+.next_ready], 0 |
.pick: |
call pick_proc ;select next task |
ret |
end if |
/kernel/trunk/core/sys32.inc |
---|
17,25 → 17,6 |
dw 8*0x41-1 |
dd idts+8 |
build_process_gdt_tss_pointer: |
mov ecx,tss_data |
mov edi,0 |
setgdtl2: |
mov [edi+gdts+ tss0 +0], word tss_step |
mov [edi+gdts+ tss0 +2], cx |
mov eax,ecx |
shr eax,16 |
mov [edi+gdts+ tss0 +4], al |
mov [edi+gdts+ tss0 +7], ah |
mov [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b |
add ecx,tss_step |
add edi,8 |
cmp edi,8*(max_processes+5) |
jbe setgdtl2 |
ret |
build_interrupt_table: |
mov edi, idts+8 |
67,7 → 48,7 |
times 12 dd unknown_interrupt |
dd irq0 , irq_serv.irq_1, p_irq2 , p_irq3 ;irq_serv.irq_3 |
dd p_irq4 ,irq_serv.irq_5,p_irq6,irq_serv.irq_7 |
dd irq_serv.irq_4 ,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,p_irq12,irqD ,p_irq14,p_irq15 |
78,13 → 59,11 |
macro save_ring3_context |
{ |
push ds es |
pushad |
} |
macro restore_ring3_context |
{ |
popad |
pop es ds |
} |
; simply return control to interrupted process |
114,20 → 93,19 |
exc_w_code 8, 10, 11, 12, 13, 14, 17 |
exc_c: |
mov ax, os_data |
mov ds, ax |
mov es, ax |
mov ax, app_data ;èñêëþ÷åíèå |
mov ds, ax ;çàãðóçèì ïðàâèëüíûå çíà÷åíè |
mov es, ax ;â ðåãèñòðû |
; test if debugging |
cli |
mov eax, [CURRENT_TASK] |
shl eax, 8 |
mov eax, [SLOT_BASE+eax+APPDATA.debugger_slot] |
mov eax, [current_slot] |
mov eax, [eax+APPDATA.debugger_slot] |
test eax, eax |
jnz .debug |
sti |
; not debuggee => say error and terminate |
add esp, 28h |
add esp, 0x20 ;28h |
movzx eax, bl |
mov [error_interrupt], eax |
call show_error_parameters |
243,7 → 221,7 |
irqh 2,5,7,8,9,10,11 |
irq_c: |
mov ax, os_data |
mov ax, app_data ;os_data |
mov ds, ax |
mov es, ax |
call irqhandler |
252,7 → 230,7 |
p_irq6: |
save_ring3_context |
mov ax, os_data |
mov ax, app_data ;os_data |
mov ds, ax |
mov es, ax |
call fdc_irq |
262,7 → 240,7 |
p_irq3: |
save_ring3_context |
mov ax, os_data |
mov ax, app_data ;os_data |
mov ds, ax |
mov es, ax |
cmp [com2_mouse_detected],0 |
278,7 → 256,7 |
p_irq4: |
save_ring3_context |
mov ax, os_data |
mov ax, app_data ;os_data |
mov ds, ax |
mov es, ax |
cmp [com1_mouse_detected],0 |
294,7 → 272,7 |
p_irq12: |
save_ring3_context |
mov ax, os_data |
mov ax, app_data ;os_data |
mov ds, ax |
mov es, ax |
call check_mouse_data_ps2 |
303,7 → 281,7 |
p_irq14: |
save_ring3_context |
mov ax, os_data |
mov ax, app_data ;os_data |
mov ds, ax |
mov es, ax |
call [irq14_func] |
312,7 → 290,7 |
iret |
p_irq15: |
save_ring3_context |
mov ax, os_data |
mov ax, app_data ;os_data |
mov ds, ax |
mov es, ax |
call [irq15_func] |
335,7 → 313,7 |
irqD: |
save_ring3_context |
mov ax, os_data |
mov ax, app_data ;os_data |
mov ds, ax |
mov es, ax |
674,6 → 652,17 |
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+4] |
cmp eax, (tss._io_map_1-OS_BASE+PG_MAP) |
je @F |
call free_page |
@@: |
mov eax, 0x20202020 |
stosd |
stosd |
837,13 → 826,12 |
build_scheduler: |
; mov esi,boot_sched_1 |
; call boot_log |
call build_process_gdt_tss_pointer |
mov esi,boot_sched_1 |
call boot_log |
; call build_process_gdt_tss_pointer |
; mov esi,boot_sched_2 |
; call boot_log |
call build_interrupt_table |
ret |
/kernel/trunk/core/syscall.inc |
---|
12,17 → 12,16 |
;; ;; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
align 32 |
align 16 |
i40: |
; diamond, 27.03.2007: handler does not require disabled interrupts |
; so interrupts remain enabled when calling int 0x40 |
push ds es |
pushad |
cld |
mov ax,word os_data |
mov ds,ax |
mov es,ax |
; mov ax, word app_data |
; mov ds, ax |
; mov es, ax |
; load all registers in crossed order |
mov eax, ebx |
38,10 → 37,8 |
and edi,0xff |
call dword [servetable+edi*4] |
pop eax |
; cli |
popad |
pop es ds |
iretd |
67,18 → 64,13 |
; mov eax, [ss:SLOT_BASE + eax + APPDATA.pl0_stack] |
; lea esp, [eax + RING0_STACK_SIZE] ; configure ESP |
; mov eax, [ss:sysenter_stack - 4] ; eax - original eax, from app |
mov esp, [ss:CURRENT_RING0_ESP] |
mov esp, [ss:tss._esp0] |
sti |
;------------------ |
push ds es |
pushad |
cld |
mov ax, word os_data |
mov ds, ax |
mov es, ax |
mov eax, ebx |
mov ebx, ecx |
mov ecx, edx |
92,7 → 84,6 |
pop eax |
popad |
pop es ds |
;------------------ |
mov edx, [SYSENTER_VAR] ; eip |
mov ecx, [SYSENTER_VAR + 4] ; esp |
105,12 → 96,11 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
align 32 |
syscall_entry: |
; cli syscall clear IF |
xchg esp, [ss:CURRENT_RING0_ESP] |
xchg esp, [ss:tss._esp0] |
push ecx |
lea ecx, [esp+4] |
xchg ecx, [ss:CURRENT_RING0_ESP] |
xchg ecx, [ss:tss._esp0] |
sti |
push ecx |
mov ecx, [ecx] |
123,13 → 113,12 |
; mov eax, [ss:sysenter_stack - 4] ; eax - original eax, from app |
;------------------ |
push ds es |
pushad |
cld |
mov ax, word os_data |
mov ds, ax |
mov es, ax |
; mov ax, word app_data |
; mov ds, ax |
; mov es, ax |
mov eax, ebx |
mov ebx, ecx |
144,13 → 133,11 |
pop eax |
popad |
pop es ds |
;------------------ |
mov ecx, [ss:esp+4] |
pop esp |
sysret |
iglobal |
;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
;; SYSTEM FUNCTIONS TABLE ;; |
/kernel/trunk/core/taskman.inc |
---|
28,41 → 28,7 |
.i_icon dd ? ;+32 |
} |
struc TSS |
{ |
._back rw 2 |
._esp0 rd 1 |
._ss0 rw 2 |
._esp1 rd 1 |
._ss1 rw 2 |
._esp2 rd 1 |
._ss2 rw 2 |
._cr3 rd 1 |
._eip rd 1 |
._eflags rd 1 |
._eax rd 1 |
._ecx rd 1 |
._edx rd 1 |
._ebx rd 1 |
._esp rd 1 |
._ebp rd 1 |
._esi rd 1 |
._edi rd 1 |
._es rw 2 |
._cs rw 2 |
._ss rw 2 |
._ds rw 2 |
._fs rw 2 |
._gs rw 2 |
._ldt rw 2 |
._trap rw 1 |
._io rw 1 |
} |
virtual at 0 |
TSS TSS |
end virtual |
struc APP_PARAMS |
{ .app_cmdline ;0x00 |
.app_path ;0x04 |
154,9 → 120,6 |
cmp eax, 0 |
jne .wait_lock |
; pushfd |
; cli |
call set_application_table_status |
call get_new_process_place |
216,7 → 179,7 |
jna @F |
xor eax, eax |
add edi, new_app_base |
; add edi, new_app_base |
cld |
rep stosb |
@@: |
395,21 → 358,21 |
mov [dir_addr], eax |
stdcall map_page,[tmp_task_pdir],eax,dword PG_SW |
mov esi, sys_pgdir |
mov edi, [tmp_task_pdir] |
mov ecx, (page_tabs shr 20)/4 |
mov ecx, (OS_BASE shr 20)/4 |
xor eax, eax |
cld |
rep stosd |
mov ecx, (OS_BASE shr 20)/4 |
mov esi, sys_pgdir+(OS_BASE shr 20) |
rep movsd |
mov eax, [dir_addr] |
or eax, PG_SW |
stosd ; [(page_tabs shr 20)]= eax |
mov [edi-4096+(page_tabs shr 20)], eax |
mov ecx, 0x800/4 |
xor eax, eax |
rep stosd |
mov eax, [dir_addr] |
and eax, -4096 |
call set_cr3 |
mov edx, [app_tabs] |
494,13 → 457,9 |
align 4 |
set_cr3: |
mov esi, [CURRENT_TASK] |
mov ebx, esi |
shl esi,8 |
mov [SLOT_BASE+esi+0xB8],eax |
imul ebx,tss_step |
add ebx,tss_data |
mov [ebx+28], eax |
mov ebx, [current_slot] |
mov [ebx+APPDATA.dir_table], eax |
mov cr3, eax |
ret |
558,8 → 517,7 |
and eax, not 0xFFF |
stdcall map_page,[tmp_task_pdir],eax,dword PG_SW |
mov esi, [tmp_task_pdir] |
add esi, 0x800 |
mov edi, 0x800/4 |
mov edi, (OS_BASE shr 20)/4 |
.destroy: |
mov eax, [esi] |
test eax, 1 |
744,7 → 702,7 |
mov eax, [slot] |
shl eax,8 |
mov ebx, [offset] |
add ebx, new_app_base |
; add ebx, new_app_base |
push ecx |
stdcall map_memEx, [proc_mem_map],\ |
[SLOT_BASE+eax+0xB8],\ |
810,7 → 768,7 |
mov eax, [slot] |
shl eax,8 |
mov ebx, [offset] |
add ebx, new_app_base |
; add ebx, new_app_base |
push ecx |
stdcall map_memEx, [proc_mem_map],\ |
[SLOT_BASE+eax+0xB8],\ |
875,9 → 833,7 |
mov [slot], eax |
mov esi,[CURRENT_TASK] |
shl esi,8 |
add esi,SLOT_BASE |
mov esi,[current_slot] |
mov ebx,esi ;ebx=esi - pointer to extended information about current thread |
mov edi, eax |
942,6 → 898,12 |
pop eax |
ret |
EFL_IF equ 0x0200 |
EFL_IOPL1 equ 0x1000 |
EFL_IOPL2 equ 0x2000 |
EFL_IOPL3 equ 0x3000 |
align 4 |
proc set_app_params stdcall,slot:dword, params:dword,\ |
cmd_line:dword, app_path:dword, flags:dword |
963,9 → 925,14 |
mov [eax+SLOT_BASE+APPDATA.fpu_handler], 0 |
mov [eax+SLOT_BASE+APPDATA.sse_handler], 0 |
;set default io permission map |
mov [eax+SLOT_BASE+APPDATA.io_map],\ |
(tss._io_map_0-OS_BASE+PG_MAP) |
mov [eax+SLOT_BASE+APPDATA.io_map+4],\ |
(tss._io_map_1-OS_BASE+PG_MAP) |
mov esi, fpu_data |
mov ecx, 512/4 |
cld |
rep movsd |
cmp ebx,[TASK_COUNT] |
1003,7 → 970,6 |
cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
ja @f |
add edx, new_app_base |
stdcall k_strncpy, edx, [cmd_line], 256 |
@@: |
mov edx,[params] |
1015,12 → 981,13 |
jc @f |
cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
ja @f |
add edx, new_app_base |
stdcall k_strncpy, edx, [app_path], 1024 |
@@: |
mov ebx,[slot] |
mov eax,ebx |
shl ebx,5 |
lea ecx,[draw_data+ebx] ;ecx - pointer to draw data |
; set window state to 'normal' (non-minimized/maximized/rolled-up) state |
mov [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL |
mov [ebx+window_data+WDATA.fl_redraw], 1 |
1033,8 → 1000,6 |
mov eax,[process_number] |
mov [ebx+4],eax ;set PID |
mov ecx,ebx |
add ecx,(draw_data-CURRENT_TASK) ;ecx - pointer to draw data |
;set draw data to full screen |
mov [ecx+0],dword 0 |
1044,54 → 1009,34 |
mov eax,[ScreenHeight] |
mov [ecx+12],eax |
mov edi,[slot] |
imul edi,tss_step |
add edi,tss_data |
mov ecx,128/4 |
mov ebx, [pl0_stack] |
mov esi,[params] |
lea ecx, [ebx+REG_EIP] |
xor eax, eax |
cld |
rep stosd |
;Add IO access table - bit array of permitted ports |
not eax |
mov ecx,2048 |
rep stosd ; access to 4096*8=65536 ports |
sub edi, tss_step |
;set cr3 register in TSS of application |
mov ecx, [slot] |
shl ecx, 8 |
mov eax,[SLOT_BASE+ecx+APPDATA.dir_table] |
mov [edi+TSS._cr3],eax |
mov [ebx+REG_RET], dword irq0.return |
mov [ebx+REG_EDI], eax |
mov [ebx+REG_ESI], eax |
mov [ebx+REG_EBP], eax |
mov [ebx+REG_ESP], ecx ;ebx+REG_EIP |
mov [ebx+REG_EBX], eax |
mov [ebx+REG_EDX], eax |
mov [ebx+REG_ECX], eax |
mov [ebx+REG_EAX], eax |
mov esi,[params] |
mov eax, [esi+0x08] ;app_eip |
mov [edi+TSS._eip],eax ;set eip in TSS |
mov [ebx+REG_EIP], eax ;app_entry |
mov [ebx+REG_CS], dword app_code |
mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF |
mov eax, [esi+0x0C] ;app_esp |
mov [edi+TSS._esp],eax ;set stack in TSS |
mov [edi+TSS._eflags],dword 0x1202 |
mov [ebx+REG_APP_ESP], eax ;app_stack |
mov [ebx+REG_SS], dword app_data |
mov [edi+TSS._cs],app_code ;selector of code segment |
mov [edi+TSS._ss],app_data |
mov [edi+TSS._ds],app_data |
mov [edi+TSS._es],app_data |
mov [edi+TSS._fs],app_data |
mov [edi+TSS._gs],graph_data ;selector of graphic segment |
mov [edi+TSS._io],word 128 |
mov [edi+TSS._ss0], os_data |
mov ebx, [pl0_stack] |
add ebx, RING0_STACK_SIZE |
mov [edi+TSS._esp0],ebx |
mov ecx, edi ;ecx - address of application TSS |
lea ecx, [ebx+REG_RET] |
mov ebx,[slot] |
shl ebx,3 |
;set TSS descriptor |
mov [ebx+gdts+tss0+0],word tss_step ;limit (size) |
mov [ebx+gdts+tss0+2],cx ;part of offset |
shr ecx,16 |
mov [ebx+gdts+tss0+4],cl ;part of offset |
mov [ebx+gdts+tss0+7],ch ;part of offset |
mov [ebx+gdts+tss0+5],word 01010000b*256+11101001b ;system flags |
shl ebx, 8 |
mov [ebx+SLOT_BASE+APPDATA.saved_esp], ecx |
;flush keyboard and buttons queue |
mov [KEY_COUNT],byte 0 |
1121,13 → 1066,5 |
ret |
endp |
include "debug.inc" |
iglobal |
new_process_loading db 'K : New Process - loading',13,10,0 |
new_process_running db 'K : New Process - done',13,10,0 |
start_not_enough_memory db 'K : New Process - not enough memory',13,10,0 |
endg |