Cutting a lot of lines, this is what I thing is relevant(I had to rewrite it at hand, because the develop PC have not Internet):
Code: Select all
;.....
;Reading the e820 output, I run out of available registers and use BP, after that not restore it, I need to do it?
;.....
;My stack is set up next to entering protect mode:
protect_code:
mov AX, Data_Selector
mov DS, AX
mov SS, AX
mov ESP, 090h ;I put here random number, it seems to works whatever put here, I don't understand the stack very fine :oops:
;.......
cli
;........
;Here I modify some registers in order to activate SSE
mov EAX, CR4
or EAX, 600h
mov CR4, EAX
mov EAX, CR0
and EAX, 0FFFFFFFBh
or EAX, 2
mov CR0, EAX
;......
mov EAX, 2000h ;base address for PML4
mov ECX, EAX
add ECX, 4096
mov EDX, ECX
shl EDX, 12 ;Here I ignore upper bits of dirrection, because tables is below 1MB
or EDX, 1
or EDX, 2
mov [DS:EAX], EDX ;DS:EAX == 0+EAX
add EAX, 4
mov EDX, 0
mov [DS:EAX], EDX
add EAX, 4
fill_PML4:
mov dword [DS:EAX], 0
add EAX, 4
mov dword [DS:EAX], 0
add EAX, 4
cmp EAX, ECX
jne fill_PML4 ;Here EAX keep the base for the next table
mov EDX, EAX
add EAX, 4096
mov ESI, EAX
mov ECX, EAX
shl ECX, 12
or ECX, 1
or ECX, 2
mov [DS:EDX], ECX
add EDX, 4
mov ECX, 0
mov [DS:EDX], ECX
add EDX, 4
fill_PDPT:
mov dword [DS:EDX], 0
add EDX, 4
mov dword [DS:EDX], 0
add EDX, 4
cmp EDX, ESI
jne fill_PDPT
mov dword [DS:EDX], 83h
add EDX, 4
mov dword [DS:EDX], 0
add EDX, 4
mov EDI, 511
fill_PD:
mov dword [DS:EDX], 0
mov EDX, 4
mov dword [DS:EDX], 0
add EDX, 4
dec EDI
cmp EDI, 0
jne fill_PD
mov EAX, 2000h
shl EAX, 12
mov CR3, EAX
mov EAX, CR4
or EAX, 32
mov CR4, EAX
mov ECX, 0C0000080h
rdmsr
or EAX, 100h
wrmsr
;At this point work
mov EAX, CR0
or EAX, 80000000h
mov CR0, EAX ;Here restart
I don't know if can simplify more the code, still don't work and still don't see an error