[prefix] Remove unsupported .com prefix
[gpxe.git] / src / arch / i386 / prefix / lmelf_dprefix.S
blob93534df5f52a7b8669a1dfdd6cff2f7d9e9f7a43
1 #include "elf.h"
2         .arch sledgehammer
3         .code32
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
14                 
15         /* ELF Header */
16         .globl elf_header
17 elf_header:     
18 e_ident:        .byte   0x7f, 'E', 'L', 'F', 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
19 e_type:         .short  ET_DYN
20 e_machine:      .short  EM_X86_64
21 e_version:      .long   1
22 e_entry:        .long   LOAD_ADDR + elf_start - elf_header
23 e_phoff:        .long   elf_program_header - elf_header
24 e_shoff:        .long   0
25 e_flags:        .long   0
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
29 e_shentsize:    .short  0
30 e_shnum:        .short  0
31 e_shstrndx:     .short  0
32 elf_header_end:
33         
34 elf_program_header:
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:
56         .globl elf_note
57 elf_note:
58         .balign 4
59         .int 2f - 1f
60         .int 4f - 3f
61         .int EIN_PROGRAM_NAME
62 1:      .asciz "ELFBoot"
64         .balign 4
65 3:      
66         .asciz "Etherboot"
70         .balign 4
71         .int 2f - 1f
72         .int 4f - 3f
73         .int EIN_PROGRAM_VERSION
74 1:      .asciz "ELFBoot"
76         .balign 4
77 3:      
78         .asciz VERSION
81 #if 0
82         .balign 4
83         .int 2f - 1f
84         .int 4f - 3f
85         .int EIN_PROGRAM_CHECKSUM
86 1:      .asciz "ELFBoot"
88         .balign 4
89 3:      
90         .word 0
92 #endif
93         .balign 4
94 elf_note_end:
96 elf_start:
97         .code64
98         /* Reload the gdt to something I know */
99         leaq    _gdt(%rip), %rax
100         movq    %rax, 0x02 + gdtptr(%rip)
101         lgdt    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)
108 elf_start32:    
109         .code32
110         /* Reload the data segments */
111         movl    $FLAT_DATA_SEG, %eax
112         movl    %eax, %ds
113         movl    %eax, %es
114         movl    %eax, %ss
115         
116         /* Disable paging */
117         movl    %cr0, %eax
118         andl    $~CR0_PG, %eax
119         movl    %eax, %cr0
121         /* Disable long mode */
122         movl    $MSR_K6_EFER, %ecx
123         rdmsr
124         andl    $~EFER_LME, %eax
125         wrmsr
127         /* Disable PAE */
128         movl    %cr4, %eax
129         andl    $~X86_CR4_PAE, %eax
130         movl    %eax, %cr4
132         /* Save the first argument */
133         pushl   %ebx
134         jmp     _start
136 gdtptr: 
137         .word   _gdt_end - _gdt -1
138         .long   _gdt
139         .long   0
140 _gdt:
141 elf_start32_addr:
142         .long   elf_start32
143         .long   FLAT_CODE_SEG
144 _pmcs:
145         /* 32 bit protected mode code segment, base 0 */
146         .word   0xffff,0
147         .byte   0,0x9f,0xcf,0
149 _pmds:
150         /* 32 bit protected mode data segment, base 0 */
151         .word   0xffff,0
152         .byte   0,0x93,0xcf,0
153 _gdt_end:       
156         /* Dummy routines to satisfy the build */
157         .section ".text16", "ax", @progbits
158 prefix_exit:
160 prefix_exit_end:
161         .previous