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.
Poseidon
Post
by Poseidon » Thu Feb 24, 2005 10:31 am
i'm not too good at inline assembly.. is this code ok?
Code: Select all
#define read_cr0(void) ({ \
unsigned ret; \
__asm__ volatile ("movl %%cr0, %%edx": : "d" (ret)); \
ret; \
})
#define read_cr3(void) ({ \
unsigned ret; \
__asm__ volatile ("movl %%cr3, %%edx": : "d" (ret)); \
ret; \
})
#define write_cr0(value) ({ \
__asm__ volatile ("movl %%edx, %%cr0" :: "d" (value)); \
})
#define write_cr3(value) ({ \
__asm__ volatile ("movl %%edx, %%cr3" :: "d" (value)); \
})
thanx in advance
pini
Post
by pini » Thu Feb 24, 2005 11:01 am
Try this for reading :
Code: Select all
#define read_cr0(void) ({ \
unsigned ret; \
__asm__ volatile ("movl %%cr0, %%edx": "=d" (ret) : ); \
ret; \
})
#define read_cr3(void) ({ \
unsigned ret; \
__asm__ volatile ("movl %%cr3, %%edx": "=d" (ret) : ); \
ret; \
})
I'm not sure if gcc takes care of your use of edx, maybe you should replace "d" and "=d" by "g" and "=g" to let gcc choose itself which general register to use.
Pype.Clicker
Member
Posts: 5964 Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:
Post
by Pype.Clicker » Thu Feb 24, 2005 11:08 am
#defines do not need "(void)" but instead "()", iirc.
you may want to use static __inline__ readcr0(void) { ... } instead of a define, too ...