From b1101aa86862cbd211dd35d7c2b8709916d7b200 Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Mon, 19 Mar 2007 06:28:05 +0000 Subject: [PATCH] software task switch (experimental, disabled IDE DMA, io permission map) git-svn-id: svn://kolibrios.org@420 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/flat_kernel/boot/bootcode.inc | 3 + kernel/branches/flat_kernel/const.inc | 21 +++-- kernel/branches/flat_kernel/core/debug.inc | 72 +++++++------- kernel/branches/flat_kernel/core/dll.inc | 2 +- kernel/branches/flat_kernel/core/fpu.inc | 14 +-- kernel/branches/flat_kernel/core/memory.inc | 6 +- kernel/branches/flat_kernel/core/sched.inc | 93 ++++++++++++------- kernel/branches/flat_kernel/core/sys32.inc | 28 +++--- kernel/branches/flat_kernel/core/syscall.inc | 43 ++++----- kernel/branches/flat_kernel/core/taskman.inc | 69 +++++++++++++- kernel/branches/flat_kernel/data32.inc | 3 +- kernel/branches/flat_kernel/kernel.asm | 48 ++++++---- kernel/branches/flat_kernel/kernel32.inc | 3 +- 13 files changed, 252 insertions(+), 153 deletions(-) diff --git a/kernel/branches/flat_kernel/boot/bootcode.inc b/kernel/branches/flat_kernel/boot/bootcode.inc index 7cde79a63c..23d915c3c9 100644 --- a/kernel/branches/flat_kernel/boot/bootcode.inc +++ b/kernel/branches/flat_kernel/boot/bootcode.inc @@ -209,6 +209,9 @@ sayerr: jmp $ cpugood: + push 0 + popf + sti ; set up esp movzx esp, sp diff --git a/kernel/branches/flat_kernel/const.inc b/kernel/branches/flat_kernel/const.inc index 3f09130c4f..c5b605bd81 100644 --- a/kernel/branches/flat_kernel/const.inc +++ b/kernel/branches/flat_kernel/const.inc @@ -279,19 +279,20 @@ std_application_base_address equ new_app_base RING0_STACK_SIZE equ (0x2000 - 512) ;512 байт для контекста FPU REG_SS equ (RING0_STACK_SIZE-4) -REG_ESP equ (RING0_STACK_SIZE-8) +REG_APP_ESP equ (RING0_STACK_SIZE-8) REG_EFLAGS equ (RING0_STACK_SIZE-12) REG_CS equ (RING0_STACK_SIZE-16) REG_EIP equ (RING0_STACK_SIZE-20) -REG_EAX equ (RING0_STACK_SIZE-24) -REG_ECX equ (RING0_STACK_SIZE-28) -REG_EDX equ (RING0_STACK_SIZE-32) -REG_EBX equ (RING0_STACK_SIZE-36) -REG_ESP equ (RING0_STACK_SIZE-40) ;RING0_STACK_SIZE-20 -REG_EBP equ (RING0_STACK_SIZE-44) -REG_ESI equ (RING0_STACK_SIZE-48) -REG_EDI equ (RING0_STACK_SIZE-52) -REG_RET equ (RING0_STACK_SIZE-56) ;irq0.return +REG_EFL_2 equ (RING0_STACK_SIZE-24) +REG_EAX equ (RING0_STACK_SIZE-28) +REG_ECX equ (RING0_STACK_SIZE-32) +REG_EDX equ (RING0_STACK_SIZE-36) +REG_EBX equ (RING0_STACK_SIZE-40) +REG_ESP equ (RING0_STACK_SIZE-44) ;RING0_STACK_SIZE-20 +REG_EBP equ (RING0_STACK_SIZE-48) +REG_ESI equ (RING0_STACK_SIZE-52) +REG_EDI equ (RING0_STACK_SIZE-56) +REG_RET equ (RING0_STACK_SIZE-60) ;irq0.return PG_UNMAP equ 0x000 PG_MAP equ 0x001 diff --git a/kernel/branches/flat_kernel/core/debug.inc b/kernel/branches/flat_kernel/core/debug.inc index 51fbefa0d4..39fc5e5191 100644 --- a/kernel/branches/flat_kernel/core/debug.inc +++ b/kernel/branches/flat_kernel/core/debug.inc @@ -135,32 +135,32 @@ debug_getcontext: 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 +; saves ring-3 context by 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 +; 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 +;;; add esi, 8 ;ds es + lodsd ;eip mov [edi], eax - lodsd - lodsd + lodsd ;cs + lodsd ;eflags mov [edi+4], eax - lodsd + lodsd ;esp mov [edi+18h], eax .ret: sti @@ -194,29 +194,29 @@ debug_setcontext: 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] ;ebx + stosd + mov eax, [esi+10h] ;edx + stosd + mov eax, [esi+0Ch] ;ecx + stosd + mov eax, [esi+8] ;eax + stosd +;;; add edi, 8 ;ds es + mov eax, [esi] ;eip stosd scasd - mov eax, [esi+14h] + mov eax, [esi+4] ;eflags stosd - mov eax, [esi+10h] - stosd - mov eax, [esi+0Ch] - stosd - mov eax, [esi+8] - stosd - add edi, 8 - mov eax, [esi] - stosd - scasd - mov eax, [esi+4] - stosd - mov eax, [esi+18h] + mov eax, [esi+18h] ;esp stosd .stiret: sti @@ -422,7 +422,7 @@ debug_exc: ; 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 @@ -460,7 +460,7 @@ debug_exc: 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] diff --git a/kernel/branches/flat_kernel/core/dll.inc b/kernel/branches/flat_kernel/core/dll.inc index 5b67d81649..bf5038c8da 100644 --- a/kernel/branches/flat_kernel/core/dll.inc +++ b/kernel/branches/flat_kernel/core/dll.inc @@ -125,7 +125,7 @@ align 4 align 16 .main: save_ring3_context - mov bx, os_data + mov bx, app_data ;os_data mov ds, bx mov es, bx diff --git a/kernel/branches/flat_kernel/core/fpu.inc b/kernel/branches/flat_kernel/core/fpu.inc index c82a742c6f..8674ce7d1f 100644 --- a/kernel/branches/flat_kernel/core/fpu.inc +++ b/kernel/branches/flat_kernel/core/fpu.inc @@ -130,7 +130,7 @@ align 4 e7: ;#NM exception handler save_ring3_context clts - mov ax, os_data + mov ax, app_data ; mov ds, ax mov es, ax @@ -183,17 +183,17 @@ except_16: ;fpu native exceptions handler 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 mov ecx, [reg_eip] mov edx, [reg_esp] sub edx, 4 - mov [ss:edx], ecx + mov [edx], ecx mov [reg_esp], edx mov dword [reg_eip], eax @@ -227,17 +227,17 @@ except_19: ;sse exceptions handler push ecx push edx - mov ebx, [ss:CURRENT_TASK] + mov ebx, [CURRENT_TASK] shl ebx, 8 - mov eax, [ss:ebx+SLOT_BASE+APPDATA.sse_handler] + mov eax, [ebx+SLOT_BASE+APPDATA.sse_handler] test eax, eax jz .default mov ecx, [reg_eip] mov edx, [reg_esp] sub edx, 4 - mov [ss:edx], ecx + mov [edx], ecx mov [reg_esp], edx mov dword [reg_eip], eax diff --git a/kernel/branches/flat_kernel/core/memory.inc b/kernel/branches/flat_kernel/core/memory.inc index e225da07a0..c8d2c95756 100644 --- a/kernel/branches/flat_kernel/core/memory.inc +++ b/kernel/branches/flat_kernel/core/memory.inc @@ -1339,9 +1339,9 @@ end if if 0 push eax push edx - mov edx, 0x400 ;bocsh - mov al,0xff ;bocsh - out dx, al ;bocsh + mov edx, 0x400 ;bochs + mov al,0xff ;bochs + out dx, al ;bochs pop edx pop eax end if diff --git a/kernel/branches/flat_kernel/core/sched.inc b/kernel/branches/flat_kernel/core/sched.inc index cae8711ea2..0c993324a6 100644 --- a/kernel/branches/flat_kernel/core/sched.inc +++ b/kernel/branches/flat_kernel/core/sched.inc @@ -5,10 +5,11 @@ align 32 irq0: - save_ring3_context - mov ax, os_data - mov ds, ax - mov es, ax + pushfd + pushad + mov ax, app_data ; + mov ds, ax + mov es, ax inc dword [timer_ticks] @@ -20,8 +21,7 @@ irq0: add eax,100 mov [next_usage_update],eax call updatecputimes - .nocounter: - +.nocounter: cmp [DONT_SWITCH], byte 1 jne .change_task @@ -31,10 +31,11 @@ irq0: mov [DONT_SWITCH], byte 0 - restore_ring3_context - iret + popad + popfd + iretd - .change_task: +.change_task: call update_counters call find_next_task @@ -49,9 +50,10 @@ irq0: call do_change_task - .return: - restore_ring3_context - iret +.return: + popad + popfd + iretd align 4 @@ -82,10 +84,9 @@ change_task: mov [DONT_SWITCH],byte 1 call do_change_task - .return: +.return: popad popfd - ret @@ -105,7 +106,7 @@ endg 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 @@ -123,10 +124,10 @@ find_next_task: mov edi, [TASK_BASE] mov [prev_slot], ebx - .waiting_for_termination: - .waiting_for_reuse: - .waiting_for_event: - .suspended: +.waiting_for_termination: +.waiting_for_reuse: +.waiting_for_event: +.suspended: cmp ebx, [TASK_COUNT] jb @f mov edi, CURRENT_TASK @@ -160,28 +161,58 @@ find_next_task: jz .waiting_for_event mov [event_sched], eax mov [edi+TASKDATA.state], byte 0 - .noevents: - .found: +.noevents: +.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] + + mov eax, [ebx+APPDATA.dir_table] + mov cr3, eax + + mov ebx, [ebx+APPDATA.pl0_stack] + add ebx, RING0_STACK_SIZE + mov [tss_data+TSS._esp0], ebx + mov ecx, cr0 + or ecx, CR0_TS ;set task switch flag + mov cr0, ecx inc [context_counter] ;noname & halyavin -ret + + ret + +; +; 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] +; inc [context_counter] ;noname & halyavin +;ret @@ -193,7 +224,7 @@ updatecputimes: mov [idleuse],dword 0 mov ecx, [TASK_COUNT] mov edi, TASK_DATA - .newupdate: +.newupdate: mov ebx,[edi+TASKDATA.counter_sum] mov [edi+TASKDATA.cpu_usage],ebx mov [edi+TASKDATA.counter_sum],dword 0 diff --git a/kernel/branches/flat_kernel/core/sys32.inc b/kernel/branches/flat_kernel/core/sys32.inc index 698baab590..2863767847 100644 --- a/kernel/branches/flat_kernel/core/sys32.inc +++ b/kernel/branches/flat_kernel/core/sys32.inc @@ -78,13 +78,11 @@ endg macro save_ring3_context { - push ds es pushad } macro restore_ring3_context { popad - pop es ds } ; simply return control to interrupted process @@ -114,9 +112,9 @@ exc_wo_code 0, 1, 2, 3, 4, 5, 6, 9, 15, 18 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 @@ -127,7 +125,7 @@ exc_c: 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 @@ -242,8 +240,8 @@ macro irqh [num] irqh 2,5,7,8,9,10,11 - irq_c: - mov ax, os_data +irq_c: + mov ax, app_data ;os_data mov ds, ax mov es, ax call irqhandler @@ -252,7 +250,7 @@ irqh 2,5,7,8,9,10,11 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 +260,7 @@ p_irq6: 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 +276,7 @@ p_irq3: 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 +292,7 @@ p_irq4: 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 +301,7 @@ p_irq12: 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 +310,7 @@ p_irq14: 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 +333,7 @@ ready_for_next_irq_1: irqD: save_ring3_context - mov ax, os_data + mov ax, app_data ;os_data mov ds, ax mov es, ax diff --git a/kernel/branches/flat_kernel/core/syscall.inc b/kernel/branches/flat_kernel/core/syscall.inc index 1708a3b9cf..57190b102b 100644 --- a/kernel/branches/flat_kernel/core/syscall.inc +++ b/kernel/branches/flat_kernel/core/syscall.inc @@ -4,15 +4,14 @@ ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -align 32 +align 16 i40: - 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 @@ -28,10 +27,8 @@ i40: and edi,0xff call dword [servetable+edi*4] pop eax -; cli popad - pop es ds iretd @@ -58,19 +55,18 @@ sysenter_entry: ; lea esp, [eax + RING0_STACK_SIZE] ; configure ESP ; mov eax, [ss:sysenter_stack - 4] ; eax - original eax, from app - mov esp, [ss:CURRENT_TASK] + mov esp, [CURRENT_TASK] shl esp, 8 - mov esp, [ss:SLOT_BASE + esp + APPDATA.pl0_stack] + mov esp, [SLOT_BASE + esp + APPDATA.pl0_stack] add esp, RING0_STACK_SIZE ; configure ESP sti - ;------------------ - 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 @@ -85,10 +81,9 @@ sysenter_entry: pop eax popad - pop es ds ;------------------ - mov edx, [SYSENTER_VAR] ; eip - mov ecx, [SYSENTER_VAR + 4] ; esp + mov edx, [SYSENTER_VAR] ; eip + mov ecx, [SYSENTER_VAR + 4] ; esp sysexit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -109,20 +104,20 @@ syscall_entry: ; lea esp, [eax + RING0_STACK_SIZE] ; configure ESP ; mov eax, [ss:sysenter_stack - 4] ; eax - original eax, from app - mov esp, [ss:CURRENT_TASK] + mov esp, [CURRENT_TASK] shl esp, 8 - mov esp, [ss:SLOT_BASE + esp + APPDATA.pl0_stack] + mov esp, [SLOT_BASE + esp + APPDATA.pl0_stack] add esp, RING0_STACK_SIZE ; configure ESP sti ;------------------ - push ds es +; 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 @@ -137,7 +132,7 @@ syscall_entry: pop eax popad - pop es ds + ; pop es ds ;------------------ cli diff --git a/kernel/branches/flat_kernel/core/taskman.inc b/kernel/branches/flat_kernel/core/taskman.inc index 40884991a3..a0ada62544 100644 --- a/kernel/branches/flat_kernel/core/taskman.inc +++ b/kernel/branches/flat_kernel/core/taskman.inc @@ -1011,6 +1011,8 @@ proc set_app_params stdcall,slot:dword, params:dword,\ 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 @@ -1023,8 +1025,6 @@ proc set_app_params stdcall,slot:dword, params:dword,\ 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 @@ -1058,7 +1058,7 @@ proc set_app_params stdcall,slot:dword, params:dword,\ mov [edi+TSS._eip],eax ;set eip in TSS mov eax, [esi+0x0C] ;app_esp mov [edi+TSS._esp],eax ;set stack in TSS - mov [edi+TSS._eflags],dword 0x3202 + mov [edi+TSS._eflags],dword 0x1202 mov [edi+TSS._cs],app_code ;selector of code segment mov [edi+TSS._ss],app_data @@ -1067,11 +1067,41 @@ proc set_app_params stdcall,slot:dword, params:dword,\ 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 [edi+TSS._ss0], os_stack mov ebx, [pl0_stack] add ebx, RING0_STACK_SIZE mov [edi+TSS._esp0],ebx + xor eax, eax + mov ebx, [pl0_stack] + lea ecx, [ebx+REG_EIP] + + 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 [ebx+REG_EFL_2], dword 0x1002 + + mov eax, [esi+0x08] ;app_eip + mov [ebx+REG_EIP], eax ;app_entry + mov [ebx+REG_CS], dword app_code + mov [ebx+REG_EFLAGS], dword 0x1202 + + mov eax, [esi+0x0C] ;app_esp + mov [ebx+REG_APP_ESP], eax ;app_stack + mov [ebx+REG_SS], dword app_data + + lea ecx, [ebx+REG_RET] + mov ebx, [slot] + shl ebx, 8 + mov [ebx+SLOT_BASE+APPDATA.saved_esp], ecx + mov ecx, edi ;ecx - address of application TSS mov ebx,[slot] shl ebx,3 @@ -1109,6 +1139,37 @@ proc set_app_params stdcall,slot:dword, params:dword,\ mov esi,new_process_running call sys_msg_board_str ;output information about succefull startup ret + +if 0 +; set stack frame + + xor eax, eax + lea ecx, [ebx+REG_EIP] + mov ebx, [pl0_stack] + mov esi,[params] + + 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 [ebx+REG_EFL_2], dword 0x1002 + + mov eax, [esi+0x08] ;app_eip + mov [ebx+REG_EIP], eax ;app_entry + mov [ebx+REG_CS], dword app_code + mov [ebx+REG_EFLAGS], dword 0x1202 + + mov eax, [esi+0x0C] ;app_esp + mov [ebx+REG_ESP], eax ;app_stack + mov [ebx+REG_SS], dword app_data +end if + endp include "debug.inc" diff --git a/kernel/branches/flat_kernel/data32.inc b/kernel/branches/flat_kernel/data32.inc index a12e1bb076..8fbe4c930c 100644 --- a/kernel/branches/flat_kernel/data32.inc +++ b/kernel/branches/flat_kernel/data32.inc @@ -245,7 +245,7 @@ event_start rd 1 event_end rd 1 event_uid rd 1 sys_page_map rd 1 -os_stack rd 1 +os_stack_seg rd 1 srv.fd rd 1 srv.bk rd 1 @@ -279,6 +279,7 @@ tmp_task_ptab rd 1 LFBSize rd 1 stall_mcs rd 1 +current_slot rd 1 ; status hd1_status rd 1 ; 0 - free : other - pid diff --git a/kernel/branches/flat_kernel/kernel.asm b/kernel/branches/flat_kernel/kernel.asm index ae3073df50..aa7301a7f0 100644 --- a/kernel/branches/flat_kernel/kernel.asm +++ b/kernel/branches/flat_kernel/kernel.asm @@ -19,7 +19,7 @@ max_processes equ 255 tss_step equ (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4 -os_data equ os_data_l-gdts ; GDTs +os_stack equ os_data_l-gdts ; GDTs os_code equ os_code_l-gdts graph_data equ 3+graph_data_l-gdts tss0 equ tss0_l-gdts @@ -151,7 +151,7 @@ org $+0x10000 align 4 B32: - mov ax,os_data ; Selector for os + mov ax,os_stack ; Selector for os mov ds,ax mov es,ax mov fs,ax @@ -214,14 +214,16 @@ org OS_BASE+$ align 4 high_code: - mov ax,os_data - mov ds,ax - mov es,ax - mov fs,ax - mov gs,ax + mov ax,os_stack + mov bx,app_data mov ss,ax add esp, OS_BASE + mov ds,bx + mov es,bx + mov fs,bx + mov gs,bx + mov dword [sys_pgdir], 0 mov dword [sys_pgdir+4], 0 mov dword [sys_pgdir+8], 0 @@ -369,7 +371,9 @@ high_code: call init_kernel_heap stdcall kernel_alloc, 0x2000 - mov [os_stack], eax + mov [os_stack_seg], eax + + lea esp, [eax+RING0_STACK_SIZE] mov [LFBSize], 0x800000 call init_mtrr @@ -552,7 +556,7 @@ include 'vmodeld.inc' mov dword [SLOT_BASE+256+APPDATA.app_name], dword 'OS/I' mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE ' - mov edi, [os_stack] + mov edi, [os_stack_seg] mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi add edi, 0x2000-512 mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi @@ -583,21 +587,21 @@ include 'vmodeld.inc' cld rep stosd - mov edi,tss_data+tss_step - mov [edi+TSS._ss0], os_data + mov edi,tss_data + mov [edi+TSS._ss0], os_stack mov eax,cr3 mov [edi+TSS._cr3],eax mov [edi+TSS._eip],osloop - mov [edi+TSS._eflags],dword 0x11202 ; sti and resume - mov eax, [os_stack] + mov [edi+TSS._eflags],dword 0x1202 ; sti and resume + mov eax, [os_stack_seg] add eax, 0x2000-512 mov [edi+TSS._esp], eax mov [edi+TSS._cs],os_code - mov [edi+TSS._ss],os_data - mov [edi+TSS._ds],os_data - mov [edi+TSS._es],os_data - mov [edi+TSS._fs],os_data - mov [edi+TSS._gs],os_data + mov [edi+TSS._ss],os_stack ;os_stack + mov [edi+TSS._ds],app_data ;os_data + mov [edi+TSS._es],app_data ;os_data + mov [edi+TSS._fs],app_data ;os_data + mov [edi+TSS._gs],app_data ;os_data mov ax,tss0 ltr ax @@ -717,7 +721,7 @@ first_app_found: mov esi,boot_tasking call boot_log - ; mov [ENABLE_TASKSWITCH],byte 1 ; multitasking enabled +; mov [ENABLE_TASKSWITCH],byte 1 ; multitasking enabled ; UNMASK ALL IRQ'S @@ -743,11 +747,15 @@ first_app_found: ; mov [dma_hdd],1 cmp [IDEContrRegsBaseAddr], 0 - setnz [dma_hdd] +; setnz [dma_hdd] stdcall init_uart_service, DRV_ENTRY sti + call change_task + + jmp osloop + jmp $ ; wait here for timer to take control ; Fly :) diff --git a/kernel/branches/flat_kernel/kernel32.inc b/kernel/branches/flat_kernel/kernel32.inc index bd1a48619d..55a2472eb5 100644 --- a/kernel/branches/flat_kernel/kernel32.inc +++ b/kernel/branches/flat_kernel/kernel32.inc @@ -184,8 +184,9 @@ struc APPDATA .bk_ev dd ? ;+52 .fd_obj dd ? ;+56 .bk_obj dd ? ;+60 + .saved_esp dd ? ;+64 - db 64 dup(?) ;+64 + db 60 dup(?) ;+68 .wnd_shape dd ? ;+128 .wnd_shape_scale dd ? ;+132