mirror of
https://github.com/KolibriOS/kolibrios.git
synced 2024-12-26 00:26:52 +03:00
redesigned memory layout
git-svn-id: svn://kolibrios.org@839 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
1146b67279
commit
0490e63747
@ -184,6 +184,20 @@ end virtual
|
||||
|
||||
TSS_SIZE equ (128+8192)
|
||||
|
||||
HEAP_BASE equ 0x80000000
|
||||
|
||||
HEAP_MIN_SIZE equ 0x01000000
|
||||
|
||||
LFB_BASE equ 0xDF000000
|
||||
|
||||
page_tabs equ 0xDF800000
|
||||
app_page_tabs equ 0xDF800000
|
||||
|
||||
OS_TEMP equ 0xDFC00000
|
||||
|
||||
kernel_tabs equ (page_tabs+ (OS_BASE shr 10)) ;0xFDE00000
|
||||
master_tab equ (page_tabs+ (page_tabs shr 10)) ;0xFDFF70000
|
||||
|
||||
OS_BASE equ 0xE0000000
|
||||
|
||||
window_data equ OS_BASE
|
||||
@ -318,16 +332,6 @@ end virtual
|
||||
|
||||
sys_pgmap equ (OS_BASE+0x047F000)
|
||||
|
||||
HEAP_BASE equ (OS_BASE+0x0800000)
|
||||
HEAP_MIN_SIZE equ 0x01000000
|
||||
|
||||
page_tabs equ 0xFDC00000
|
||||
app_page_tabs equ 0xFDC00000
|
||||
kernel_tabs equ (page_tabs+ (OS_BASE shr 10)) ;0xFDE00000
|
||||
master_tab equ (page_tabs+ (page_tabs shr 10)) ;0xFDFF70000
|
||||
|
||||
LFB_BASE equ 0xFE000000
|
||||
|
||||
|
||||
new_app_base equ 0;
|
||||
|
||||
|
@ -89,7 +89,7 @@ macro remove_from_used op
|
||||
}
|
||||
|
||||
align 4
|
||||
proc init_kernel_heap
|
||||
init_kernel_heap:
|
||||
|
||||
mov ecx, 64/4
|
||||
mov edi, mem_block_list
|
||||
@ -102,59 +102,39 @@ proc init_kernel_heap
|
||||
not eax
|
||||
rep stosd
|
||||
|
||||
stdcall alloc_pages, dword 32
|
||||
add eax, OS_BASE
|
||||
|
||||
mov [mem_block_start], mem_block_map
|
||||
mov [mem_block_end], mem_block_map+512
|
||||
mov [mem_block_arr], HEAP_BASE
|
||||
mov [mem_block_arr], eax
|
||||
|
||||
mov eax, mem_used.fd-MEM_LIST_OFFSET
|
||||
mov [mem_used.fd], eax
|
||||
mov [mem_used.bk], eax
|
||||
mov ebx, mem_used.fd-MEM_LIST_OFFSET
|
||||
mov [mem_used.fd], ebx
|
||||
mov [mem_used.bk], ebx
|
||||
|
||||
stdcall alloc_pages, dword 32
|
||||
mov ecx, 32
|
||||
mov edx, eax
|
||||
mov edi, HEAP_BASE
|
||||
.l1:
|
||||
stdcall map_page,edi,edx,PG_SW
|
||||
add edi, 0x1000
|
||||
add edx, 0x1000
|
||||
dec ecx
|
||||
jnz .l1
|
||||
xor edx, edx
|
||||
|
||||
mov edi, HEAP_BASE
|
||||
mov ebx, HEAP_BASE+MEM_BLOCK_SIZE
|
||||
xor eax, eax
|
||||
mov [edi+block_next], ebx
|
||||
mov [edi+block_prev], eax
|
||||
mov [edi+list_fd], eax
|
||||
mov [edi+list_bk], eax
|
||||
mov [edi+block_base], HEAP_BASE
|
||||
mov [edi+block_size], 4096*MEM_BLOCK_SIZE
|
||||
mov [edi+block_flags], USED_BLOCK
|
||||
mov [eax+block_next], edx
|
||||
mov [eax+block_prev], edx
|
||||
mov [eax+list_fd], edx
|
||||
mov [eax+list_bk], edx
|
||||
mov [eax+block_base], HEAP_BASE
|
||||
mov [eax+block_size], page_tabs-HEAP_BASE
|
||||
mov [eax+block_flags], FREE_BLOCK
|
||||
|
||||
mov [ebx+block_next], eax
|
||||
mov [ebx+block_prev], eax
|
||||
mov [ebx+list_fd], eax
|
||||
mov [ebx+list_bk], eax
|
||||
mov [ebx+block_base], HEAP_BASE+4096*MEM_BLOCK_SIZE
|
||||
mov [heap_size], page_tabs-HEAP_BASE
|
||||
mov [heap_free], page_tabs-HEAP_BASE
|
||||
|
||||
mov ecx, [MEM_AMOUNT]
|
||||
sub ecx, (HEAP_BASE - OS_BASE + 4096*MEM_BLOCK_SIZE)
|
||||
mov [heap_size], ecx
|
||||
mov [heap_free], ecx
|
||||
mov [ebx+block_size], ecx
|
||||
mov [ebx+block_flags], FREE_BLOCK
|
||||
|
||||
mov [mem_block_mask], eax
|
||||
mov [mem_block_mask], edx
|
||||
mov [mem_block_mask+4],0x80000000
|
||||
|
||||
mov [mem_block_list+63*4], ebx
|
||||
mov byte [mem_block_map], 0xFC
|
||||
mov [mem_block_list+63*4], eax
|
||||
mov byte [mem_block_map], 0xFE
|
||||
and [heap_mutex], 0
|
||||
mov [heap_blocks], 4095
|
||||
mov [free_blocks], 4095
|
||||
mov [heap_blocks], 4096
|
||||
mov [free_blocks], 4096
|
||||
ret
|
||||
endp
|
||||
|
||||
; param
|
||||
; eax= required size
|
||||
@ -329,7 +309,7 @@ proc alloc_kernel_space stdcall, size:dword
|
||||
je .m_eq_size
|
||||
|
||||
call alloc_mem_block
|
||||
and eax, eax
|
||||
test eax, eax
|
||||
jz .error
|
||||
|
||||
mov esi, eax ;esi - splitted block
|
||||
@ -340,7 +320,7 @@ proc alloc_kernel_space stdcall, size:dword
|
||||
mov [edi+block_prev], esi
|
||||
mov [esi+list_fd], 0
|
||||
mov [esi+list_bk], 0
|
||||
and eax, eax
|
||||
test eax, eax
|
||||
jz @f
|
||||
mov [eax+block_next], esi
|
||||
@@:
|
||||
|
@ -321,7 +321,8 @@ proc init_LFB
|
||||
cmp dword [LFBAddress], -1
|
||||
jne @f
|
||||
mov [BOOT_VAR+0x901c],byte 2
|
||||
stdcall kernel_alloc, 0x280000
|
||||
stdcall alloc_pages, 0x280000 shr 12
|
||||
add eax, OS_BASE
|
||||
mov [LFBAddress], eax
|
||||
ret
|
||||
@@:
|
||||
@ -332,55 +333,20 @@ proc init_LFB
|
||||
@@:
|
||||
call init_mtrr
|
||||
|
||||
mov edx, LFB_BASE
|
||||
mov esi, [LFBAddress]
|
||||
mov edi, 0x00800000
|
||||
mov dword [exp_lfb+4], edx
|
||||
xchg bx, bx
|
||||
|
||||
shr edi, 12
|
||||
mov [pg_count], edi
|
||||
shr edi, 10
|
||||
mov eax, [LFBAddress]
|
||||
or eax, PG_LARGE+PG_UW
|
||||
mov [sys_pgdir+(LFB_BASE shr 20)], eax
|
||||
add eax, 0x00400000
|
||||
mov [sys_pgdir+4+(LFB_BASE shr 20)], eax
|
||||
|
||||
bt [cpu_caps], CAPS_PSE
|
||||
jnc .map_page_tables
|
||||
or esi, PG_LARGE+PG_UW
|
||||
mov edx, sys_pgdir+(LFB_BASE shr 20)
|
||||
@@:
|
||||
mov [edx], esi
|
||||
add edx, 4
|
||||
add esi, 0x00400000
|
||||
dec edi
|
||||
jnz @B
|
||||
mov dword [exp_lfb+4], LFB_BASE
|
||||
|
||||
bt [cpu_caps], CAPS_PGE
|
||||
jnc @F
|
||||
or dword [sys_pgdir+(LFB_BASE shr 20)], PG_GLOBAL
|
||||
@@:
|
||||
mov dword [LFBAddress], LFB_BASE
|
||||
mov eax, cr3 ;flush TLB
|
||||
mov cr3, eax
|
||||
ret
|
||||
|
||||
.map_page_tables:
|
||||
|
||||
@@:
|
||||
call alloc_page
|
||||
stdcall map_page_table, edx, eax
|
||||
add edx, 0x00400000
|
||||
dec edi
|
||||
jnz @B
|
||||
|
||||
mov eax, [LFBAddress]
|
||||
mov edi, page_tabs + (LFB_BASE shr 10)
|
||||
or eax, PG_UW
|
||||
mov ecx, [pg_count]
|
||||
cld
|
||||
@@:
|
||||
stosd
|
||||
add eax, 0x1000
|
||||
dec ecx
|
||||
jnz @B
|
||||
|
||||
mov dword [LFBAddress], LFB_BASE
|
||||
mov eax, cr3 ;flush TLB
|
||||
mov cr3, eax
|
||||
@ -563,29 +529,71 @@ proc page_fault_handler
|
||||
|
||||
inc [pg_data.pages_faults]
|
||||
|
||||
; xchg bx,bx
|
||||
; jmp .exit
|
||||
|
||||
mov ebx, [.err_addr]
|
||||
mov eax, [.err_code]
|
||||
|
||||
cmp ebx, OS_BASE
|
||||
; xchg bx, bx
|
||||
|
||||
cmp ebx, HEAP_BASE
|
||||
jb .user_space ;страница в памяти приложения ;
|
||||
|
||||
cmp ebx, page_tabs
|
||||
jb .kernel_space ;ñòğàíèöà â ïàìÿòè ÿäğà
|
||||
cmp ebx, LFB_BASE
|
||||
jb .kernel_heap
|
||||
|
||||
cmp ebx, kernel_tabs
|
||||
jb .alloc;.app_tabs ;òàáëèöû ñòğàíèö ïğèëîæåíèÿ ;
|
||||
cmp ebx, page_tabs
|
||||
jb .lfb
|
||||
|
||||
cmp ebx, OS_BASE
|
||||
jb .core_tabs
|
||||
|
||||
jmp .core_tabs
|
||||
|
||||
; cmp ebx, kernel_tabs
|
||||
; jb .alloc;.app_tabs ;òàáëèöû ñòðàíèö ïðèëîæåíèÿ ;
|
||||
;просто создадим одну
|
||||
|
||||
cmp ebx, LFB_BASE
|
||||
jb .core_tabs ;òàáëèöû ñòğàíèö ÿäğà
|
||||
;Îøèáêà
|
||||
.lfb:
|
||||
;îáëàñòü LFB
|
||||
;Îøèáêà
|
||||
jmp .fail
|
||||
shr ebx, 22
|
||||
mov edx, [sys_pgdir + ebx*4]
|
||||
mov [master_tab + ebx*4], edx
|
||||
jmp .exit
|
||||
|
||||
.core_tabs:
|
||||
|
||||
shr ebx, 12
|
||||
and ebx, 0x3FF
|
||||
mov edx, [master_tab + ebx*4]
|
||||
test edx, PG_MAP
|
||||
jz .check_ptab ;òàáëèöà ñòðàíèö íå ñîçäàíà
|
||||
|
||||
align 4
|
||||
.kernel_heap:
|
||||
|
||||
shr ebx, 22
|
||||
mov edx, [master_tab + ebx*4]
|
||||
test edx, PG_MAP
|
||||
jz .check_ptab ;òàáëèöà ñòðàíèö íå ñîçäàíà
|
||||
|
||||
.check_ptab:
|
||||
mov edx, [sys_pgdir + ebx*4]
|
||||
test edx, PG_MAP
|
||||
jnz @F
|
||||
|
||||
call alloc_page
|
||||
test eax, eax
|
||||
jz .fail
|
||||
|
||||
lea edx, [eax + PG_UW]
|
||||
lea edi, [eax + OS_BASE]
|
||||
mov ecx, 1024
|
||||
xor eax, eax
|
||||
cld
|
||||
rep stosd
|
||||
|
||||
mov [sys_pgdir + ebx*4], edx
|
||||
@@:
|
||||
mov [master_tab + ebx*4], edx
|
||||
jmp .exit
|
||||
|
||||
align 4
|
||||
.user_space:
|
||||
@ -596,7 +604,7 @@ align 4
|
||||
shr ebx, 12
|
||||
mov ecx, ebx
|
||||
shr ecx, 10
|
||||
mov edx, [master_tab+ecx*4]
|
||||
mov edx, [master_tab + ecx*4]
|
||||
test edx, PG_MAP
|
||||
jz .fail ;таблица страниц не создана
|
||||
;неверный адрес в программе
|
||||
@ -676,7 +684,6 @@ align 4
|
||||
|
||||
;не обрабатываем. Ошибка
|
||||
|
||||
.core_tabs:
|
||||
.fail:
|
||||
mov esp, ebp
|
||||
popad
|
||||
|
@ -578,21 +578,18 @@ term9:
|
||||
.nodebug:
|
||||
popad
|
||||
|
||||
mov ebx, [.slot]
|
||||
shl ebx, 8
|
||||
push ebx
|
||||
mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack]
|
||||
|
||||
stdcall kernel_free, ebx
|
||||
|
||||
pop ebx
|
||||
mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir]
|
||||
stdcall kernel_free, ebx
|
||||
|
||||
mov edi, [.slot]
|
||||
shl edi,8
|
||||
mov edi, [.slot]
|
||||
shl edi, 8
|
||||
add edi,SLOT_BASE
|
||||
|
||||
mov eax,[edi+APPDATA.pl0_stack]
|
||||
sub eax, OS_BASE
|
||||
call free_page
|
||||
|
||||
mov eax,[edi+APPDATA.cur_dir]
|
||||
sub eax, OS_BASE
|
||||
call free_page
|
||||
|
||||
mov eax, [edi+APPDATA.io_map]
|
||||
cmp eax, (tss._io_map_0-OS_BASE+PG_MAP)
|
||||
je @F
|
||||
|
@ -138,8 +138,6 @@ proc fs_execute
|
||||
test eax, eax
|
||||
jz .err_hdr
|
||||
|
||||
;mov esi, new_process_loading
|
||||
;call sys_msg_board_str ; write message to message board
|
||||
DEBUGF 1,"%s",new_process_loading
|
||||
|
||||
.wait_lock:
|
||||
@ -189,6 +187,7 @@ proc fs_execute
|
||||
loop .copy_process_name_loop
|
||||
.copy_process_name_done:
|
||||
|
||||
|
||||
mov ebx, cr3
|
||||
mov [save_cr3], ebx
|
||||
|
||||
@ -388,10 +387,9 @@ proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword
|
||||
test eax, eax
|
||||
jz .fail
|
||||
mov [dir_addr], eax
|
||||
stdcall map_page,[tmp_task_pdir],eax,dword PG_SW
|
||||
|
||||
mov edi, [tmp_task_pdir]
|
||||
mov ecx, (OS_BASE shr 20)/4
|
||||
lea edi, [eax + OS_BASE]
|
||||
mov ecx, (OS_BASE shr 20)/4
|
||||
xor eax, eax
|
||||
cld
|
||||
rep stosd
|
||||
@ -400,15 +398,15 @@ proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword
|
||||
mov esi, sys_pgdir+(OS_BASE shr 20)
|
||||
rep movsd
|
||||
|
||||
mov eax, [dir_addr]
|
||||
or eax, PG_SW
|
||||
mov [edi-4096+(page_tabs shr 20)], eax
|
||||
mov edi, [dir_addr]
|
||||
lea eax, [edi+PG_SW]
|
||||
mov [edi+OS_BASE+(page_tabs shr 20)], eax
|
||||
|
||||
and eax, -4096
|
||||
and eax, -4096
|
||||
call set_cr3
|
||||
|
||||
mov edx, [app_tabs]
|
||||
mov edi, new_app_base
|
||||
xor edi, edi
|
||||
@@:
|
||||
call alloc_page
|
||||
test eax, eax
|
||||
@ -419,9 +417,7 @@ proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword
|
||||
dec edx
|
||||
jnz @B
|
||||
|
||||
mov edi, new_app_base
|
||||
shr edi, 10
|
||||
add edi, page_tabs
|
||||
mov edi, page_tabs
|
||||
|
||||
mov ecx, [app_tabs]
|
||||
shl ecx, 10
|
||||
@ -430,13 +426,11 @@ proc create_app_space stdcall, app_size:dword,img_base:dword,img_size:dword
|
||||
|
||||
mov ecx, [img_pages]
|
||||
mov ebx, PG_UW
|
||||
mov edx, new_app_base
|
||||
mov esi, [img_base]
|
||||
mov edi, new_app_base
|
||||
mov esi, [img_base]
|
||||
shr esi, 10
|
||||
shr edi, 10
|
||||
add esi, page_tabs
|
||||
add edi, page_tabs
|
||||
xor edx, edx
|
||||
mov edi, page_tabs
|
||||
.remap:
|
||||
lodsd
|
||||
or eax, ebx ; force user level r/w access
|
||||
@ -467,9 +461,7 @@ else
|
||||
end if
|
||||
|
||||
.done:
|
||||
stdcall map_page,[tmp_task_pdir],dword 0,dword PG_UNMAP
|
||||
|
||||
dec [pg_data.pg_mutex]
|
||||
dec [pg_data.pg_mutex]
|
||||
mov eax, [dir_addr]
|
||||
ret
|
||||
.fail:
|
||||
@ -543,18 +535,21 @@ proc destroy_app_space stdcall, pg_dir:dword
|
||||
;if there isn't threads then clear memory.
|
||||
|
||||
mov eax, [pg_dir]
|
||||
and eax, not 0xFFF
|
||||
stdcall map_page,[tmp_task_pdir],eax,dword PG_SW
|
||||
mov esi, [tmp_task_pdir]
|
||||
mov edi, (OS_BASE shr 20)/4
|
||||
and eax, -4096
|
||||
add eax, OS_BASE
|
||||
mov [tmp_task_pdir], eax
|
||||
mov esi, eax
|
||||
mov edi, (HEAP_BASE shr 20)/4
|
||||
.destroy:
|
||||
mov eax, [esi]
|
||||
test eax, 1
|
||||
jz .next
|
||||
and eax, not 0xFFF
|
||||
stdcall map_page,[tmp_task_ptab],eax,dword PG_SW
|
||||
stdcall destroy_page_table, [tmp_task_ptab]
|
||||
mov eax, [esi]
|
||||
add eax, OS_BASE
|
||||
|
||||
stdcall destroy_page_table, eax
|
||||
|
||||
mov eax, [esi]
|
||||
call free_page
|
||||
.next:
|
||||
add esi, 4
|
||||
@ -564,8 +559,6 @@ proc destroy_app_space stdcall, pg_dir:dword
|
||||
mov eax, [pg_dir]
|
||||
call free_page
|
||||
.exit:
|
||||
stdcall map_page,[tmp_task_ptab],dword 0,dword PG_UNMAP
|
||||
stdcall map_page,[tmp_task_pdir],dword 0,dword PG_UNMAP
|
||||
dec [pg_data.pg_mutex]
|
||||
ret
|
||||
endp
|
||||
@ -951,7 +944,8 @@ proc set_app_params stdcall,slot:dword, params:dword,\
|
||||
pl0_stack dd ?
|
||||
endl
|
||||
|
||||
stdcall kernel_alloc, RING0_STACK_SIZE+512
|
||||
stdcall alloc_pages, (RING0_STACK_SIZE+512) shr 12
|
||||
add eax, OS_BASE
|
||||
mov [pl0_stack], eax
|
||||
|
||||
lea edi, [eax+RING0_STACK_SIZE]
|
||||
@ -994,9 +988,8 @@ proc set_app_params stdcall,slot:dword, params:dword,\
|
||||
add eax, RING0_STACK_SIZE
|
||||
mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax
|
||||
|
||||
push ebx
|
||||
stdcall kernel_alloc, 0x1000
|
||||
pop ebx
|
||||
call alloc_page
|
||||
add eax, OS_BASE
|
||||
mov esi,[current_slot]
|
||||
mov esi,[esi+APPDATA.cur_dir]
|
||||
mov ecx,0x1000/4
|
||||
|
@ -8,159 +8,8 @@
|
||||
$Revision$
|
||||
|
||||
|
||||
MEM_WB equ 6 ;write-back memory
|
||||
MEM_WC equ 1 ;write combined memory
|
||||
MEM_UC equ 0 ;uncached memory
|
||||
|
||||
|
||||
align 4
|
||||
proc init_mem
|
||||
|
||||
mov ecx, [0x2F0000 + 0x9100]
|
||||
mov esi, 0x2F0000 + 0x9104
|
||||
xor eax, eax
|
||||
@@:
|
||||
cmp dword [esi+16], 1
|
||||
jne .next
|
||||
mov edx, [esi+8]
|
||||
cmp eax, [esi+8]
|
||||
ja .next
|
||||
|
||||
mov eax, [esi+8]
|
||||
.next:
|
||||
add esi, 20
|
||||
loop @B
|
||||
|
||||
and eax, -4096
|
||||
|
||||
mov [MEM_AMOUNT-OS_BASE], eax
|
||||
mov [pg_data.mem_amount-OS_BASE], eax
|
||||
|
||||
shr eax, 12
|
||||
mov edx, eax
|
||||
mov [pg_data.pages_count-OS_BASE], eax
|
||||
shr eax, 3
|
||||
mov [pg_data.pagemap_size-OS_BASE], eax
|
||||
|
||||
add eax, (sys_pgmap-OS_BASE)+4095
|
||||
and eax, not 4095
|
||||
mov [tmp_page_tabs], eax
|
||||
|
||||
cmp edx, (OS_BASE/4096)
|
||||
jbe @F
|
||||
mov edx, (OS_BASE/4096)
|
||||
jmp .set
|
||||
@@:
|
||||
cmp edx, (HEAP_MIN_SIZE/4096)
|
||||
jae .set
|
||||
mov edx, (HEAP_MIN_SIZE/4096)
|
||||
.set:
|
||||
mov [pg_data.kernel_pages-OS_BASE], edx
|
||||
shr edx, 10
|
||||
mov [pg_data.kernel_tables-OS_BASE], edx
|
||||
|
||||
xor eax, eax
|
||||
mov edi, sys_pgdir-OS_BASE
|
||||
mov ecx, 4096/4
|
||||
cld
|
||||
rep stosd
|
||||
|
||||
mov edx, (sys_pgdir-OS_BASE)+ (OS_BASE shr 20)
|
||||
bt [cpu_caps-OS_BASE], CAPS_PSE
|
||||
jnc .no_PSE
|
||||
|
||||
mov ebx, cr4
|
||||
or ebx, CR4_PSE
|
||||
mov eax, PG_LARGE+PG_SW
|
||||
mov cr4, ebx
|
||||
dec [pg_data.kernel_tables-OS_BASE]
|
||||
|
||||
mov [edx], eax
|
||||
add eax, 0x00400000
|
||||
add edx, 4
|
||||
|
||||
mov eax, 0x400000+PG_SW
|
||||
mov ecx, [tmp_page_tabs]
|
||||
sub ecx, 0x400000
|
||||
shr ecx, 12 ;ecx/=4096
|
||||
jmp .map_low
|
||||
.no_PSE:
|
||||
mov eax, PG_SW
|
||||
mov ecx, [tmp_page_tabs]
|
||||
shr ecx, 12
|
||||
.map_low:
|
||||
mov edi, [tmp_page_tabs]
|
||||
@@: ;
|
||||
stosd
|
||||
add eax, 0x1000
|
||||
dec ecx
|
||||
jnz @B
|
||||
|
||||
mov ecx, [pg_data.kernel_tables-OS_BASE]
|
||||
shl ecx, 10
|
||||
xor eax, eax
|
||||
rep stosd
|
||||
|
||||
mov ecx, [pg_data.kernel_tables-OS_BASE]
|
||||
mov eax, [tmp_page_tabs]
|
||||
or eax, PG_SW
|
||||
mov edi, edx
|
||||
|
||||
.map_kernel_tabs:
|
||||
|
||||
stosd
|
||||
add eax, 0x1000
|
||||
dec ecx
|
||||
jnz .map_kernel_tabs
|
||||
|
||||
mov dword [sys_pgdir-OS_BASE+(page_tabs shr 20)], sys_pgdir+PG_SW-OS_BASE
|
||||
|
||||
mov edi, (sys_pgdir-OS_BASE)
|
||||
lea esi, [edi+(OS_BASE shr 20)]
|
||||
movsd
|
||||
movsd
|
||||
ret
|
||||
endp
|
||||
|
||||
align 4
|
||||
proc init_page_map
|
||||
|
||||
mov edi, sys_pgmap-OS_BASE
|
||||
mov ecx, [pg_data.pagemap_size-OS_BASE]
|
||||
shr ecx, 2
|
||||
or eax, -1
|
||||
cld
|
||||
rep stosd
|
||||
|
||||
mov ecx, [tmp_page_tabs]
|
||||
mov edx, [pg_data.pages_count-OS_BASE]
|
||||
shr ecx, 12
|
||||
add ecx, [pg_data.kernel_tables-OS_BASE]
|
||||
sub edx, ecx
|
||||
mov [pg_data.pages_free-OS_BASE], edx
|
||||
|
||||
mov edi, sys_pgmap-OS_BASE
|
||||
mov ebx, ecx
|
||||
shr ecx, 5
|
||||
xor eax, eax
|
||||
rep stosd
|
||||
|
||||
not eax
|
||||
mov ecx, ebx
|
||||
and ecx, 31
|
||||
shl eax, cl
|
||||
mov [edi], eax
|
||||
add edi, OS_BASE
|
||||
mov [page_start-OS_BASE], edi;
|
||||
|
||||
mov ebx, sys_pgmap
|
||||
add ebx, [pg_data.pagemap_size-OS_BASE]
|
||||
mov [page_end-OS_BASE], ebx
|
||||
|
||||
mov [pg_data.pg_mutex-OS_BASE], 0
|
||||
ret
|
||||
endp
|
||||
|
||||
align 4
|
||||
|
||||
init_BIOS32:
|
||||
|
@ -215,7 +215,7 @@ B32:
|
||||
|
||||
xor eax,eax
|
||||
mov edi,0x280000
|
||||
mov ecx,(HEAP_BASE-OS_BASE-0x280000) / 4
|
||||
mov ecx,(0x800000-0x280000) / 4
|
||||
cld
|
||||
rep stosd
|
||||
|
||||
@ -242,20 +242,31 @@ B32:
|
||||
bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc
|
||||
|
||||
call init_BIOS32
|
||||
; MEMORY MODEL
|
||||
|
||||
call init_mem
|
||||
mov dword [sys_pgdir-OS_BASE], PG_LARGE+PG_SW
|
||||
mov dword [sys_pgdir-OS_BASE+4], PG_LARGE+PG_SW+4*1024*1024
|
||||
|
||||
call init_page_map
|
||||
mov ecx, 32
|
||||
lea edi, [sys_pgdir-OS_BASE+0xE00]
|
||||
mov eax, PG_LARGE+PG_SW
|
||||
@@:
|
||||
stosd
|
||||
add eax, 4*1024*1024
|
||||
loop @B
|
||||
|
||||
mov ebx, cr4
|
||||
or ebx, CR4_PSE
|
||||
and ebx, not CR4_PAE
|
||||
mov cr4, ebx
|
||||
|
||||
; ENABLE PAGING
|
||||
|
||||
mov eax, sys_pgdir-OS_BASE
|
||||
mov cr3, eax
|
||||
mov ebx, cr0
|
||||
or ebx,CR0_PG+CR0_WP
|
||||
|
||||
mov eax,cr0
|
||||
or eax,CR0_PG+CR0_WP
|
||||
mov cr0,eax
|
||||
mov cr3, eax
|
||||
mov cr0, ebx
|
||||
|
||||
lgdt [gdts]
|
||||
jmp pword os_code:high_code
|
||||
@ -276,6 +287,79 @@ include 'init.inc'
|
||||
|
||||
org OS_BASE+$
|
||||
|
||||
MEM_WB equ 6 ;write-back memory
|
||||
MEM_WC equ 1 ;write combined memory
|
||||
MEM_UC equ 0 ;uncached memory
|
||||
|
||||
align 4
|
||||
init_mem:
|
||||
|
||||
mov ecx, [BOOT_VAR + 0x9100]
|
||||
mov esi, BOOT_VAR + 0x9104
|
||||
xor eax, eax
|
||||
@@:
|
||||
cmp dword [esi+16], 1
|
||||
jne .next
|
||||
mov edx, [esi+8]
|
||||
cmp eax, [esi+8]
|
||||
ja .next
|
||||
|
||||
mov eax, [esi+8]
|
||||
.next:
|
||||
add esi, 20
|
||||
loop @B
|
||||
|
||||
and eax, -4096
|
||||
|
||||
mov [MEM_AMOUNT], eax
|
||||
mov [pg_data.mem_amount], eax
|
||||
|
||||
shr eax, 12
|
||||
mov edx, eax
|
||||
mov [pg_data.pages_count], eax
|
||||
shr eax, 3
|
||||
and eax, -4
|
||||
mov [pg_data.pagemap_size], eax
|
||||
|
||||
ret
|
||||
|
||||
align 4
|
||||
init_page_map:
|
||||
|
||||
mov edi, sys_pgmap
|
||||
mov ecx, [pg_data.pagemap_size]
|
||||
shr ecx, 2
|
||||
or eax, -1
|
||||
cld
|
||||
rep stosd
|
||||
|
||||
mov ecx, 0x800000 ;reserve 8 Mb
|
||||
mov edx, [pg_data.pages_count]
|
||||
shr ecx, 12
|
||||
sub edx, ecx
|
||||
mov [pg_data.pages_free], edx
|
||||
|
||||
mov edi, sys_pgmap
|
||||
mov ebx, ecx
|
||||
shr ecx, 5
|
||||
xor eax, eax
|
||||
rep stosd
|
||||
|
||||
not eax
|
||||
mov ecx, ebx
|
||||
and ecx, 31
|
||||
shl eax, cl
|
||||
mov [edi], eax
|
||||
mov [page_start], edi;
|
||||
|
||||
mov ebx, sys_pgmap
|
||||
add ebx, [pg_data.pagemap_size]
|
||||
mov [page_end], ebx
|
||||
|
||||
mov [pg_data.pg_mutex], 0
|
||||
ret
|
||||
|
||||
|
||||
align 4
|
||||
high_code:
|
||||
mov ax,os_stack
|
||||
@ -288,10 +372,12 @@ high_code:
|
||||
mov fs,bx
|
||||
mov gs,bx
|
||||
|
||||
mov dword [sys_pgdir-OS_BASE+(page_tabs shr 20)], sys_pgdir+PG_SW-OS_BASE
|
||||
|
||||
bt [cpu_caps], CAPS_PGE
|
||||
jnc @F
|
||||
|
||||
or dword [sys_pgdir+(OS_BASE shr 20)], PG_GLOBAL
|
||||
or dword [sys_pgdir-OS_BASE+(OS_BASE shr 20)], PG_GLOBAL
|
||||
|
||||
mov ebx, cr4
|
||||
or ebx, CR4_PGE
|
||||
@ -304,6 +390,14 @@ high_code:
|
||||
mov eax, cr3
|
||||
mov cr3, eax ; flush TLB
|
||||
|
||||
|
||||
; MEMORY MODEL
|
||||
|
||||
call init_mem
|
||||
|
||||
call init_page_map
|
||||
|
||||
|
||||
; SAVE REAL MODE VARIABLES
|
||||
mov ax, [BOOT_VAR + 0x9031]
|
||||
mov [IDEContrRegsBaseAddr], ax
|
||||
@ -455,7 +549,9 @@ high_code:
|
||||
lidt [idtreg]
|
||||
|
||||
call init_kernel_heap
|
||||
stdcall kernel_alloc, RING0_STACK_SIZE+512
|
||||
|
||||
stdcall alloc_pages, (RING0_STACK_SIZE+512) shr 12
|
||||
add eax, OS_BASE
|
||||
mov [os_stack_seg], eax
|
||||
|
||||
lea esp, [eax+RING0_STACK_SIZE]
|
||||
@ -715,7 +811,7 @@ no_lib_load:
|
||||
mov [SLOT_BASE+APPDATA.cursor],eax
|
||||
mov [SLOT_BASE+APPDATA.cursor+256],eax
|
||||
|
||||
stdcall load_pe_driver, szAtiHW
|
||||
; stdcall load_pe_driver, szAtiHW
|
||||
|
||||
; READ TSC / SECOND
|
||||
|
||||
@ -743,7 +839,7 @@ no_lib_load:
|
||||
|
||||
;call detect_devices
|
||||
stdcall load_driver, szPS2MDriver
|
||||
stdcall load_driver, szCOM_MDriver
|
||||
; stdcall load_driver, szCOM_MDriver
|
||||
|
||||
mov esi,boot_setmouse
|
||||
call boot_log
|
||||
@ -752,7 +848,7 @@ no_lib_load:
|
||||
|
||||
; STACK AND FDC
|
||||
|
||||
call stack_init
|
||||
call stack_init
|
||||
call fdc_init
|
||||
|
||||
; PALETTE FOR 320x200 and 640x480 16 col
|
||||
@ -811,8 +907,6 @@ no_load_vrr_m:
|
||||
mov ebp, firstapp
|
||||
call fs_execute_from_sysdir
|
||||
|
||||
|
||||
|
||||
cmp eax,2 ; continue if a process has been loaded
|
||||
je first_app_found
|
||||
|
||||
@ -943,7 +1037,7 @@ osloop:
|
||||
; call check_window_move_request
|
||||
call checkmisc
|
||||
call checkVga_N13
|
||||
call stack_handler
|
||||
call stack_handler
|
||||
call checkidle
|
||||
call check_fdd_motor_status
|
||||
call check_ATAPI_device_event
|
||||
|
Loading…
Reference in New Issue
Block a user