-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-x86_64.S
120 lines (100 loc) · 3.16 KB
/
start-x86_64.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
*
* This file is part of UEFI fdisk.
*
* UEFI fdisk is a port of util-linux fdisk to UEFI/BIOS.
* UEFI fdisk est un portage de util-linux fdisk vers UEFI/BIOS.
* Ce fichier a été initié par Bernard Burette en janvier 2014.
*
* Original work is copyleft Bernard Burette.
* Modifications are copyleft Joseph Zeller.
*
* This program is distributed under the terms of the GNU General Public
* License version 2 or more.
* La diffusion de ce code est faite selon les termes de la licence publique
* générale GNU version 2 ou plus.
*
*/
/** @file
*
* start-x86_64.S - UEFI startup code for x86_64 architecture.
*
* This module contains the exported _start symbol, the entry
* point of the UEFI image (program).
*
* This module also provides a fake .reloc section, because
* some UEFI loaders need that to successfully detect a program.
*
*/
//
// Startup code.
// Entry point of program given to "ld" is "_start" in Makefile.
// It first processes the ELF relocation information (because the UEFI loader
// will not have loaded this program at the VMA specified in the file (use
// "objdump -h" to see those VMAs) and we do not use the .reloc PE section
// because it is defined in µ$ crap and we would have to build it manually.
// It then calls the efi_main() function using x86_64 ABI (arguments in %rdi
// and %rsi registers.
// Also note that since UEFI uses µ$ 64 bits ABI to call this entry point
// the two arguments from the UEFI loader are received here in %rcx and %rdx
// registers.
// This file also uses external symbol _DYNAMIC automatically defined by the
// linker.
//
.section .text.startup, "ax"
.global _start
_start:
// make room in the stack
subq $8 , %rsp
// 1st arg (MS ABI %rcx) is ImageHandle
pushq %rcx
// 2nd arg (MS ABI %rdx) is SystemTable
pushq %rdx
// address of variable UEFI_ImageHandle
lea UEFI_ImageHandle(%rip) , %rdi
// save value of 1st arg in this location
mov %rcx , (%rdi)
// address of variable ST - from GNU EFI library
lea ST(%rip) , %rdi
// save value of 2nd arg in this location
mov %rdx , (%rdi)
// initialze FPU (will be needed later)
fninit
// VMA=0 adjusted with %rip to real loaded address
lea ImageBase(%rip) , %rdi
// VMA of .dynamic section adjusted with %rip to real loaded address
lea _DYNAMIC(%rip) , %rsi
// call with 3 args (x86_64 ABI %rdi, %rsi, %rdx)
call _relocate@PLT
// call with no args
call _call_init@PLT
// get SystemTable (pushed to stack by code above)
popq %rsi
// get ImageHandle (pushed to stack by code above)
popq %rdi
// call with 2 args (x86_64 ABI %rdi, %rsi)
call efi_main@PLT
// use return value for first arg (exit status)
mov %rax , %rdi
// call exit() function with 1 arg (x86_64 ABI %rdi)
// instead of returning
call exit@PLT
// if we ever return from exit()
addq $8 , %rsp
ret
//
// Une entrée .reloc bidon pour faire plaisir au loader EFI
//
.section .reloc, "al"
.long 0/*VirtualAddress*/
.long 10/*SymbolTableIndex*/
.word ( 0/*do nothing*/ << 12 ) + 0/*fixup*/
//
// Les variables UEFI_ImageHandle et ST
//
.bss
.global UEFI_ImageHandle
.comm UEFI_ImageHandle,8,8
.global ST
.comm ST,8,8
.section .note.GNU-stack,"",%progbits