Why some kernel actions cannot be written in C

I apologize if this should sound trivial and unconvincing, but I could not understand the intuitive way to google it. Why are some kernel actions, such as saving the current state of registers and the stack (just a few words) in the Assembly? Why can't they be written in C, because in the end, apparently, when the compilation is complete, all we get is the object code? In addition, when you use ollydbg, you notice that before calling the function (in C), the current state of the register is pushed onto the stack

+4
source share
5 answers

When writing the OS, the main goal is to maintain the highest abstraction in order to make the code reusable for different architectures, but in the end there is inevitably architecture .

Each machine performs very low-level functions in such a specialized way so as not to support a common programming language.

Task switching, bus control, device interrupt handling, just to name a few, cannot be effectively encoded using a high-level language (consider command sequences, included registers and possible critical CPU timings and priority levels).

, , , , , .

, , . , , , .

.

+4

C , , .

C , , , , , , .

, set the X register with a given value move data from register X to register Y, , C.

+2

C - , . , , , C . MMU -, . , , C , . , , , .

, , , 32- , , , , asm.

+1

Context switching is critical and should be really very fast, which should not be written in a high-level language.

0
source

Source: https://habr.com/ru/post/1681672/


All Articles