4 ms·
>"1) Privileged instructions, like IN/OUT, WAIT, or SGDT. These instructions aren't even usable outside the kernel, and there's no way to represent their effect
by bogomipz 4y ago
>"1) Privileged instructions, like IN/OUT, WAIT, or SGDT. These instructions aren't even usable outside the kernel, and there's no way to represent their effects in pure C anyway."
Could you elaborate on this? I understand you need to be in ring 0 for these instructions but you still need be able to compile the kernel. Or I am completely misunderstanding something obvious or missing your point completely?
- duskwuff 4y agoThere isn't any pure C code you can write which would be expressed with those instructions, in the sort of way that MUL would be an expression of "a * b" (for example). The C virtual machine doesn't have the concept of an I/O port or a global descriptor table; the only way of interacting with these features from C is to either use a CPU-specific intrinsic (not available for these instructions) or inline assembly.
- bogomipz 4y agoAh right these would all be inline assembly in the kernel code and so the assembler would handle these. Thanks.
- deckard1 4y agoThe kernel either uses a separate file written in assembly (.S file) or inline assembly that GCC understands. https://github.com/torvalds/linux/blob/ce990f1de0bc6ff3de43d385e0985efa980fba24/arch/x86/boot/compressed/efi_thunk_64.S#L55 https://github.com/torvalds/linux/blob/ce990f1de0bc6ff3de43d... https://github.com/torvalds/linux/blob/35e43538af8fd2cb39d58caca1134a87db173f75/arch/x86/include/asm/desc.h#L220 https://github.com/torvalds/linux/blob/35e43538af8fd2cb39d58...
- p_l 4y agoKernels can't really be built with standard-compliant C, and use noticeable amount of assembly and intrinsics (which are essentially inlined asm functions or generators for those) to drive such details.