Page 1 of 1

Could someone look at these peaces of assembly?

Posted: Sun Jul 01, 2007 9:41 am
by LaurensR1983
Hi,

I'm creating my paging system atm. To enable paging, I need to call some of these assembly routines (below) halfway during the code. To be honoust; I'm really bad at assembly. The page that provided these function, didn't include the C declarations for these function.

Like I tried to create some myself... but my OS kept crashing.. so I want to exclude the possibility that my declarations are wrong.

Code: Select all

unsigned long read_cr0();
extern void write_cr3(unsigned long*); 
extern void write_cr0(unsigned long); 
So my question is can someone look at these, and give me the declaration in C? (as in 'extern void.... ();' etc) Or does someone have a more C friendly alternative to these assembly routines?

Code: Select all

global _read_cr0
_read_cr0:
	mov eax, cr0
	retn

global _write_cr0
_write_cr0:
	push ebp
	mov ebp, esp
	mov eax, [ebp+8]
	mov cr0,  eax
	pop ebp
	retn

global _read_cr3
_read_cr3:
	mov eax, cr3
	retn

global _write_cr3
_write_cr3:
	push ebp
	mov ebp, esp
	mov eax, [ebp+8]
	mov cr3, eax
	pop ebp
	retn

Posted: Sun Jul 01, 2007 10:11 am
by Kevin McGuire
They look correct to me, maybe it is crashing because you are enabling paging?

Posted: Sun Jul 01, 2007 11:42 am
by LaurensR1983
Yea... i think that's the case too, but I just wanted to make sure that the C declarations are OK, so I can rule them out.

Re: Could someone look at these peaces of assembly?

Posted: Mon Jul 02, 2007 3:09 am
by jinglexy
i have also crash at first, the address for cr3 not aligned 4k,
maybe the problem in

Posted: Mon Jul 02, 2007 3:57 am
by mathematician
I'm not sure about that asterisk in the second declaration. It looks to me as if the value is being taken off the stack, not a pointer.