Could someone look at these peaces of assembly?

Programming, for all ages and all languages.
Post Reply
LaurensR1983
Posts: 24
Joined: Wed Jun 27, 2007 10:34 am

Could someone look at these peaces of assembly?

Post 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
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Post by Kevin McGuire »

They look correct to me, maybe it is crashing because you are enabling paging?
LaurensR1983
Posts: 24
Joined: Wed Jun 27, 2007 10:34 am

Post 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.
jinglexy
Posts: 15
Joined: Sat Mar 10, 2007 1:05 am

Re: Could someone look at these peaces of assembly?

Post by jinglexy »

i have also crash at first, the address for cr3 not aligned 4k,
maybe the problem in
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

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