What are .S files?
.S
files are source code files written in assembly. Assembly is an extremely low-level form of programming. The files contain assembly instructions to the processor in sequential order and are typically compiled based on a selected architecture. Examples of such files are often seen in the linux kernel for specific architectures, e.g. x86, sparc, ARM, etc.
For more information about assembly language:
- X86 Assembly/GAS syntax
- x86 Instruction list
- TLDP Linux Assembly Howto
- Example in the Linux kernel: arch/x86/net/bpf_jit.S
.S
files are usually assembly language.
Something nobody mentioned is, why capital S
?
.S
(capital S) stands for assembly code that must still pass through a pre-processor. That means it can have#include
and#define
among other macros. It may also be written as.sx
..s
(lowercase s) is pure assembly code that can be compiled into an object.
Why not use .c
? Well, being an operating system, it is impossible to write everything in C. Actually, that would be ideal, and C language itself has a background history linked to help creating operating systems and diminish the amount of assembly needed to code it. But many low-level operations are too dependant of the machine.
Here a nice example of a memory copy routine for the Linux boot that uses #include <linux/linkage.h>
.
.S
files are assembly files.
Why
.S
& why not.c
files?
Its because machine dependent stuff and early initialization such as setting up cache and memory can only be done with assembly level instructions such as I/O instructions.
The kernel doesn't have the luxury of the libc
library to take care of the initial set up of various resources.
And hardware resources at any point even during application execution in turn call system calls which call I/O routines coded in assembly language.