Paging

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
chrisa128

Re:Paging

Post 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 
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Paging

Post 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)
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
chrisa128

Re:Paging

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Paging

Post 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

Code: Select all

push ebp
mov ebp,esp
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 :)
chrisa128

Re:Paging

Post 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!!!
Post Reply