浏览代码

[relocate] Preserve page alignment during relocation

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 年前
父节点
当前提交
bfe6e3e90e
共有 1 个文件被更改,包括 10 次插入12 次删除
  1. 10
    12
      src/arch/x86/core/relocate.c

+ 10
- 12
src/arch/x86/core/relocate.c 查看文件

10
 
10
 
11
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
12
 
12
 
13
-/*
14
- * The linker passes in the symbol _max_align, which is the alignment
15
- * that we must preserve, in bytes.
16
- *
17
- */
18
-extern char _max_align[];
19
-#define max_align ( ( size_t ) _max_align )
20
-
21
 /* Linker symbols */
13
 /* Linker symbols */
22
 extern char _textdata[];
14
 extern char _textdata[];
23
 extern char _etextdata[];
15
 extern char _etextdata[];
30
  */
22
  */
31
 #define MAX_ADDR (0xfff00000UL)
23
 #define MAX_ADDR (0xfff00000UL)
32
 
24
 
25
+/* Preserve alignment to a 4kB page
26
+ *
27
+ * Required for x86_64, and doesn't hurt for i386.
28
+ */
29
+#define ALIGN 4096
30
+
33
 /**
31
 /**
34
  * Relocate iPXE
32
  * Relocate iPXE
35
  *
33
  *
53
 	start = virt_to_phys ( _textdata );
51
 	start = virt_to_phys ( _textdata );
54
 	end = virt_to_phys ( _etextdata );
52
 	end = virt_to_phys ( _etextdata );
55
 	size = ( end - start );
53
 	size = ( end - start );
56
-	padded_size = ( size + max_align - 1 );
54
+	padded_size = ( size + ALIGN - 1 );
57
 
55
 
58
 	DBG ( "Relocate: currently at [%x,%x)\n"
56
 	DBG ( "Relocate: currently at [%x,%x)\n"
59
-	      "...need %x bytes for %zd-byte alignment\n",
60
-	      start, end, padded_size, max_align );
57
+	      "...need %x bytes for %d-byte alignment\n",
58
+	      start, end, padded_size, ALIGN );
61
 
59
 
62
 	/* Determine maximum usable address */
60
 	/* Determine maximum usable address */
63
 	max = MAX_ADDR;
61
 	max = MAX_ADDR;
125
 	 * required alignemnt.
123
 	 * required alignemnt.
126
 	 */
124
 	 */
127
 	new_start = new_end - padded_size;
125
 	new_start = new_end - padded_size;
128
-	new_start += ( start - new_start ) & ( max_align - 1 );
126
+	new_start += ( ( start - new_start ) & ( ALIGN - 1 ) );
129
 	new_end = new_start + size;
127
 	new_end = new_start + size;
130
 
128
 
131
 	DBG ( "Relocating from [%x,%x) to [%x,%x)\n",
129
 	DBG ( "Relocating from [%x,%x) to [%x,%x)\n",

正在加载...
取消
保存