Introduction
The LoongArch Image is the uncompressed Linux kernel for LoongArch (vmlinux.efi in the kernel build). Every such image is an
EFI application: its first 64 bytes are at the same time a DOS header (MZ) and the Linux boot header, and the PE header follows
at offset 64. The fields are from the kernel documents Documentation/arch/loongarch/booting.rst and arch/loongarch/include/asm/image.h
and from arch/loongarch/kernel/head.S, which writes the header (all read as raw text from the kernel tree; the descriptions are in our own words).
A distribution’s vmlinuz for LoongArch is usually an EFI zboot image instead, with this image
compressed inside it.
Header
All numbers are little-endian. The booting document draws the first two fields as u32 MZ_MAGIC and u32 res0; the kernel’s header struct
has the two letters, then three 16-bit padding words, which is the same 8 bytes.
| Offset | Size | Field | What it holds |
|---|---|---|---|
0x00 | 2 | MZ | The MS-DOS signature MZ of a PE file. |
0x02 | 6 | res0 | Reserved, zero. |
0x08 | 8 | kernel_entry | The kernel entry point, a physical address. The booting document says the kernel is passed, on kernel_entry, a0 = efi_boot (a flag: whether the environment is fully UEFI-compliant), a1 = the command line, a2 = the EFI system table; all pointers are physical. |
0x10 | 8 | kernel_asize | _end - _text: the effective size of the kernel image in memory. |
0x18 | 8 | load_offset | The load offset from the start of RAM (the struct calls it text_offset; head.S stores PHYS_LINK_KADDR). |
0x20 | 8 | res1 | Reserved, zero. |
0x28 | 8 | res2 | Reserved, zero. |
0x30 | 8 | res3 | Reserved, zero. |
0x38 | 4 | magic | LINUX_PE_MAGIC = 0x818223CD. include/linux/pe.h puts it at offset 0x38 of the DOS header of every EFI-bootable Linux kernel of an architecture; the PE machine type says which. |
0x3C | 4 | pe_header | The offset of the PE header from the start of the image (64 in the kernel). |
The header struct in image.h names the field at 0x18 text_offset and the one at 0x10
kernel_asize; the booting document calls them load_offset and “Kernel image effective size”. They are the same fields.
The PE header
At the offset in pe_header is PE\0\0, the COFF file header (machine 0x6264 for LoongArch 64-bit, 0x6232 for the
32-bit one, from include/linux/pe.h), the PE32+ optional header and a section table. The file is the EFI application efi_pe_entry
of the kernel’s EFI stub. The format is described on the EXE pages; the viewer reads only the machine, subsystem, entry point,
size of headers and the section table (the kernel’s image has two sections, .text and .data).
A real image
The Alpine Linux linux-lts package for LoongArch (7.3.5, edge) holds boot/vmlinuz-lts, an EFI zboot image whose gzip payload is a LoongArch Image
of 27,852,800 bytes. Its header: kernel_entry 0x0000000000EE6000, kernel_asize 0x0000000001A90000 (equal to the
file size), load_offset 0x200000, pe_header 0x40; PE machine 0x6264, subsystem EFI application,
entry point 0xD4DF3C, 64 KiB of headers and two sections (.text, .data). llvm-readobj reads the same PE values.
What the viewer shows
The header field by field, the entry point, the size and the load offset, the PE header’s machine, subsystem, entry point and section table. It reports
non-zero reserved fields, a kernel_asize that is zero or smaller than the file, a PE header that is not where pe_header says and a PE
machine that is not LoongArch. The file is recognised by MZ, the Linux magic at offset 56 and a PE header with a LoongArch machine type; with no extension
the explorer asks that test. Nothing is disassembled: the explorer has no LoongArch decoder.
Not described
Known, not yet covered
- Viewer: the code: there is no LoongArch decoder in the explorer, so the kernel’s entry code is not disassembled and no function is named.
- Reference: the PE data directories of the EFI stub (the EXE pages describe the format) and how the EFI stub itself boots the kernel.
- Reference: what
kernel_entryexpects of a boot loader beyond the three argument registers (the booting document lists no more). - Viewer: one real image, from one distribution; no 32-bit image (machine
0x6232) was available.
Unknown
- Reference: nothing is known to be undocumented in the header: every field is in the booting document or the struct.
Links
Reference
- Booting Linux/LoongArch – the header and the kernel arguments
- arch/loongarch/include/asm/image.h – the header struct
- arch/loongarch/kernel/head.S – where the header is written
- include/linux/pe.h –
LINUX_PE_MAGICand the machine types