4 .equ FLAT_CODE_SEG,_pmcs-_gdt
5 .equ FLAT_DATA_SEG,_pmds-_gdt
6 .equ MSR_K6_EFER, 0xC0000080
7 .equ EFER_LME, 0x00000100
8 .equ X86_CR4_PAE, 0x00000020
9 .equ CR0_PG, 0x80000000
11 .section ".prefix", "ax", @progbits
13 #define LOAD_ADDR 0x10000
18 e_ident: .byte 0x7f, 'E', 'L', 'F', 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
20 e_machine: .short EM_X86_64
22 e_entry: .long LOAD_ADDR + elf_start - elf_header
23 e_phoff: .long elf_program_header - elf_header
26 e_ehsize: .short elf_header_end - elf_header
27 e_phentsize: .short ELF32_PHDR_SIZE
28 e_phnum: .short (elf_program_header_end - elf_program_header)/ELF32_PHDR_SIZE
35 phdr1_p_type: .long PT_NOTE
36 phdr1_p_offset: .long elf_note - elf_header
37 phdr1_p_vaddr: .long elf_note
38 phdr1_p_paddr: .long elf_note
39 phdr1_p_filesz: .long elf_note_end - elf_note
40 phdr1_p_memsz: .long elf_note_end - elf_note
41 phdr1_p_flags: .long PF_R | PF_W | PF_X
42 phdr1_p_align: .long 0
44 /* The decompressor */
45 phdr2_p_type: .long PT_LOAD
46 phdr2_p_offset: .long 0
47 phdr2_p_vaddr: .long elf_header
48 phdr2_p_paddr: .long LOAD_ADDR
49 phdr2_p_filesz: .long _verbatim_size
50 phdr2_p_memsz: .long _image_size
51 phdr2_p_flags: .long PF_R | PF_W | PF_X
52 phdr2_p_align: .long 16
54 elf_program_header_end:
73 .int EIN_PROGRAM_VERSION
85 .int EIN_PROGRAM_CHECKSUM
98 /* Reload the gdt to something I know */
100 movq %rax, 0x02 + gdtptr(%rip)
103 /* Enter 32bit compatibility mode */
104 leaq elf_start32(%rip), %rax
105 movl %eax, 0x00 + elf_start32_addr(%rip)
106 ljmp *elf_start32_addr(%rip)
110 /* Reload the data segments */
111 movl $FLAT_DATA_SEG, %eax
121 /* Disable long mode */
122 movl $MSR_K6_EFER, %ecx
124 andl $~EFER_LME, %eax
129 andl $~X86_CR4_PAE, %eax
132 /* Save the first argument */
137 .word _gdt_end - _gdt -1
145 /* 32 bit protected mode code segment, base 0 */
150 /* 32 bit protected mode data segment, base 0 */
156 /* Dummy routines to satisfy the build */
157 .section ".text16", "ax", @progbits