do I need to know assembler?
|Deletions are marked like this.||Additions are marked like this.|
|Line 20:||Line 20:|
|No. God no. Please see the ["http://kernel.org/pub/linux/docs/lkml/#s15-3" LKML FAQ"] on that.||No. God no. Please see the [http://kernel.org/pub/linux/docs/lkml/#s15-3 LKML FAQ] on that.|
Do I need to know assembler to hack the kernel?
In fact, even if you do know assembler it is better if you stick to C in most of the kernel, so your code is more portable, is more easily read and maintained and can be optimized by the compiler, which gets confused a lot less than humans do.
The kernel uses assembler code only where it is really needed:
- very early boot code
- system call and exception entry points
- poking I/O ports
- locking and barriers
- switching between kernel and user space
Note that many of the things above need to be done from C code, for example device drivers need to poke at I/O ports. This is done through architecture defined C macros like inb, inw, inl, outb, outw and outl. These macros will automatically do the right thing by including the bits of inline assembler that are needed to make your driver work on the architecture on which it is compiled.
This means that the same device driver, written in C, can work on i386, x86-64, MIPS, PPC and other architectures. If the driver is written carefully, taking little/big endianness and 32 vs 64 bitness into account, no changes will be needed to run the driver on multiple architectures.
What about C++?
No. God no. Please see the [http://kernel.org/pub/linux/docs/lkml/#s15-3 LKML FAQ] on that.