Subject: Re: cpu_switch() bug?
To: None <>
From: Wolfgang Solfrank <>
List: port-powerpc
Date: 02/20/2001 14:44:34

> I am also trying to figure out why it was written in assembly
> rather than C, and I (as yet) don't have a really good answer.  I
> think the C compiler will output practically the same code, except
> for the ``cntlzw'' instruction which is easy enough to either inline
> asm (yuck), or make a two line function in locore.S

No, the cntlzw isn't the reason for writing the switch routine in assembly
(note that you can get a cntlzw instruction into your code even without
assembly by using the ffs() builtin function, albeit the code would lack
a bit, because ffs counts bits from the other end).

The reason for writing the cpu_switch code in assembly is that it has to
switch the stack, and while doing so, it has to save and restore the
registers to/from known locations on the old/new stack so they can be
manipulated by other parts of the kernel (like when doing a fork or exec).

ws@TooLs.DE     Wolfgang Solfrank, TooLs GmbH 	+49-228-985800