AMD64 Linux Kernel Conventions

The section is informative only.

Calling Conventions

The Linux AMD64 kernel uses internally the same calling conventions as user-level applications (see section [*] for details). User-level applications that like to call system calls should use the functions from the C library. The interface between the C library and the Linux kernel is the same as for the user-level applications with the following differences:

  1. User-level applications use as integer registers for passing the sequence %rdi, %rsi, %rdx, %rcx, %r8 and %r9. The kernel interface uses %rdi, %rsi, %rdx, %r10, %r8 and %r9.
  2. A system-call is done via the syscall instruction. The kernel destroys registers %rcx and %r11.
  3. The number of the syscall has to be passed in register %rax.
  4. System-calls are limited to six arguments, no argument is passed directly on the stack.
  5. Returning from the syscall, register %rax contains the result of the system-call. A value in the range between -4095 and -1 indicates an error, it is -errno.
  6. Only values of class INTEGER or class MEMORY are passed to the kernel.

Required Processor Features

Any program or kernel can expect that a AMD64 processor implements the features mentioned in table [*]. In general a program has to check itself whether those features are available but for AMD64 systems, these should always be available. Tablereffeatures uses the names for the processor features as documented in the processor manual.

Figure: Required Processor Features

Miscelleaneous Remarks

Linux Kernel code is not allowed to change the x87 and SSE units. If those are changed by kernel code, they have to be restored properly before sleeping or leaving the kernel. On preemptive kernels also more precautions may be needed.

Jan Hubicka 2003-05-04