Page 2 of 2
Re:Paging
Posted: Mon Feb 24, 2003 2:00 pm
by chrisa128
It is 0 in the GDT for the data selector. and it still triple faults on me. The ASM functions are as follow...
Code: Select all
[GLOBAL _get_page_bit]
_get_page_bit
mov eax,cr0
retn
[GLOBAL _set_page_bit]
_set_page_bit
push eax
mov eax,[esp + 8]
mov cr0,eax
pop eax
jmp check1
check1:
retn
[GLOBAL _get_page_dir]
_get_page_dir
mov eax,cr3
retn
[GLOBAL _set_page_dir]
_set_page_dir
pusha
push eax
mov eax,[esp + 4]
mov cr3,eax
jmp check2
check2:
pop eax
popa
retn
Re:Paging
Posted: Mon Feb 24, 2003 2:52 pm
by distantvoices
Try this nasm-code. After all, it worked fine for me, is simple and straight forward:
[global activate_paging]
;void activate_paging(ulong_t *page_directory)->c prototype
cli
push ebp
mov ebp,esp
mov eax,[ebp+8]
mov cr3,eax
mov eax,cr0
or eax,0x80000000
mov cr0,eax
jmp s1
s1:
pop ebp
sti
ret
this you call it in c:
activate_paging(pgdir)
Re:Paging
Posted: Mon Feb 24, 2003 3:08 pm
by chrisa128
It works or if doesn't I am blind!!!
My Thanks to...
beyond infinity
aafuss
pype.clicker
and anyone else who helped as I am doing this from memory
Re:Paging
Posted: Tue Feb 25, 2003 2:17 am
by Pype.Clicker
afai can see, your problem (as you probably figured out now ;p ) was in the ASM-C parameters passing.
It might be impressive to see code where arguments are addressed with [esp+xxx], but in fact it isn't. It's just more complicated to handle.
A C-function always starts with
This rule allows implementing a stack-tracing algorithm very simply. It also means that the arguments of the function will always be at the same location (arg1 = [ebp+8], arg2=[ebp+12], arg3=[ebp+16] -- [ebp+4] is the return location)
if you want to push/pop other registers, do it *after* you set ebp=esp.
you can also quickly restore the stack to a clean value (even if you had some misbehaved push/pop) with mov esp,ebp ; pop ebp.
May the Stack be with You
Re:Paging
Posted: Tue Feb 25, 2003 3:48 am
by chrisa128
Thanks pype, I will remeber this in future but during the course of getting paging going I have learnt plenty.
Now on to getting malloc and free written!!!