Why assembly needed to kick-start any OS kernel

前端 未结 3 480
生来不讨喜
生来不讨喜 2021-01-16 20:16

I was reading How to write a simple operating system, which says:

For your very first OS, you\'re better off sticking with assembly language, as used

3条回答
  •  抹茶落季
    2021-01-16 20:51

    C code requires for example a stack to be setup, so if nothing else you need to set the stack pointer before you enter the first level of code. And from C (not counting inline asm which in this case would be assembly not C) you cant set the stack pointer. So you have that chicken and egg problem. Next is bss and data segments, although you can certainly write clean C code that does not rely on bss nor data being setup, but to meet the C standards you need them setup. So you will find some code that zeros bss and if need be copies .data into place from nv storage.

    In general assembly can do anything the processor can do C cannot nativly do anything the processor do. In particular you cant generally bootstrap C with C, you need asm...

提交回复
热议问题