Some questions

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

Some questions

Post by BAlroj »

Hi,

I'd like to know how can i know at run time my kernel's size.

If i want want to use asm with intel sintaxi in gcc, what should i do?

thanks for all.
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:Some questions

Post by Pype.Clicker »

BAlroj wrote: I'd like to know how can i know at run time my kernel's size.
The easiest solution is to insert symbols like _start_kernel (before anything else) and _end_kernel in your linker script (just after everything else) and then use _end_kernel - _start_kernel to know the kernel size at runtime ;)

If i want want to use asm with intel sintaxi in gcc, what should i do?
http://sources.redhat.com/ml/binutils/2 ... 00268.html should interrest you ...
balroj

Re:Some questions

Post by balroj »

Hi pype,

thanks for the answer.

this is my funtion now:

unsigned int ReadCr0()
{
   unsigned int cere=0;
   
   asm( ".intel_syntax noprefix\n" );
   asm( "\tmov cere, cr0\n");
   
   return cere;
}

Gcc tells me that there's not an movl instruction. is still searching at$t syntax. I'm triying to use intel asm syntax in my c code. i know i could do it with nasm and link them after.. but i'm interested on that way.

Thanks for all.
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:Some questions

Post by Pype.Clicker »

there's a trick here: the control registers (CR0, CR1, CR2 and CR3) may not be moved to something else than a generic register (eax, ebx, ecx, edx, ebp, esp, esi or edi). Thus if you want to get the content of the CR0 register in a C variable, you'll need to use

Code: Select all

int cere;
asm volatile("mov eax,CR0":"=a"(cere));
Note that i'm unsure GCC could have generated the proper code for "mov cere,eax", as "cere" is not really a label (until defined static): it's a location on the stack (something like [ebp-4]) ... Never really tried it, though, so it might work anyway.
Balroj

Re:Some questions

Post by Balroj »

Thanks again pype for answering.

I'll try it this night, now i'm at work ;)

One last question, in this line:
asm volatile("mov eax,CR0":"=a"(cere));
what is =a(cere) for? ( well, i undertand what is for, but don't know why to put an =a, will be the same =b? or there is a reason?)

thanks for all.
pini

Re:Some questions

Post by pini »

For use of intel's asm syntax in GCC inline assembly, check if your gcc supports the -masm option
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:Some questions

Post by Pype.Clicker »

Balroj wrote: One last question, in this line:
asm volatile("mov eax,CR0":"=a"(cere));
what is =a(cere) for?
the full answer is in "info gcc" -> "extended inline assembly" documentation. briefly, the full asm command looks like
asm(<asm text>:[output specifiers][:[input specifiers][:<clobber specifiers>]]);
thus here, we have <asm text> :: "mov eax,CR0" and <output specifiers> :: "=a"(cere).

The '=' sign is mandatory for output specifiers and the letter after it defines a constraint on the operand that can be used to hold the result. the 'a' letter means i want the compiler to assume the value of eAx should be stored in cere after the asm commands completes. if i had used "=b", the content of ebx would have been used, but this would have been plain silly as there's nothing interresting in ebx so far ...

in order to have easier optimizable code (for the compiler), i could have used "=g" to let it select the register, but this then means the asm command must be parametric:

Code: Select all

asm volatile("mov %0,CR0":"=g"(cere));
Post Reply