My question is why nowadays some operating system event handling is still written in assembly language instead of a higher level language such as C, when the kernel itself is written mostly in C?
C is an abstraction from the machine code that runs on the machine (although much closer than most other languages).
For those things machine code statements that cannot be expressed in C, and maybe for the extra optimization not provided by the C compiler assembly is used, mostly in the form of inline assembler.
In the kernel source code tree this is stored under
<arch> is a specific architecture name. It is actually only a small part of the complete kernel source.
You cannot do this in C :)
lgdt[xxxx] mov eax, cr0 or al, 0x01 mov cr0, eax
Am trying to get into x86 protected mode. Obviously I can still do this in C by "emitting" raw machine codes, but still in case I require to access precise offets - i am out of luck mostly.
The second example is BootLoader. On x86 systems, it is required that the traditional boot code be exactly 512 bytes long and the last two bytes be 0xAA and 0x55 (or 55 AA exactly) respectively... Ensuring such a thing with C compilers are a nightmare and assembler does the job in a fantastic way.
There are many more such cases where Assembly is not just preferrable - but is the only means.