summaryrefslogtreecommitdiff
path: root/src/device/oprom
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2013-02-08 16:56:51 -0600
committerStefan Reinauer <stefan.reinauer@coreboot.org>2013-03-21 18:01:38 +0100
commita146d58ca0375a12f23dc5a4bd25adfa3423114f (patch)
tree874776d78835bf56ba66eba54e2558edd97645de /src/device/oprom
parente8c866ad45d80de768c9422474449e171d133575 (diff)
downloadcoreboot-a146d58ca0375a12f23dc5a4bd25adfa3423114f.tar.xz
ramstage: prepare for relocation
The current ramstage code contains uses of symbols that cause issues when the ramstage is relocatable. There are 2 scenarios resolved by this patch: 1. Absolute symbols that are actually sizes/limits. The symbols are problematic when relocating a program because there is no way to distinguish a symbol that shouldn't be relocated and one that can. The only way to handle these symbols is to write a program to post process the relocations and keep a whitelist of ones that shouldn't be relocated. I don't believe that is a route that should be taken so fix the users of these sizes/limits encoded as absolute symbols to calculate the size at runtime or dereference a variable in memory containing the size/limit. 2. Absoulte symbols that were relocated to a fixed address. These absolute symbols are generated by assembly files to be placed at a fixed location. Again, these symbols are problematic because one can't distinguish a symbol that can't be relocated. The symbols are again resolved at runtime to allow for proper relocation. For the symbols defining a size either use 2 symbols and calculate the difference or provide a variable in memory containing the size. Change-Id: I1ef2bfe6fd531308218bcaac5dcccabf8edf932c Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: http://review.coreboot.org/2789 Tested-by: build bot (Jenkins) Reviewed-by: Marc Jones <marc.jones@se-eng.com>
Diffstat (limited to 'src/device/oprom')
-rw-r--r--src/device/oprom/realmode/x86.c45
-rw-r--r--src/device/oprom/realmode/x86.h8
-rw-r--r--src/device/oprom/realmode/x86_asm.S15
3 files changed, 44 insertions, 24 deletions
diff --git a/src/device/oprom/realmode/x86.c b/src/device/oprom/realmode/x86.c
index 5fd11b59a5..94b65e1abc 100644
--- a/src/device/oprom/realmode/x86.c
+++ b/src/device/oprom/realmode/x86.c
@@ -36,16 +36,37 @@
#include <boot/coreboot_tables.h>
#include <device/pci_ids.h>
+/* The following symbols cannot be used directly. They need to be fixed up
+ * to point to the correct address location after the code has been copied
+ * to REALMODE_BASE. Absolute symbols are not used because those symbols are
+ * relocated when a relocatable ramstage is enabled.
+ */
+extern unsigned char __realmode_call, __realmode_interrupt;
+extern unsigned char __realmode_buffer;
+
+#define PTR_TO_REAL_MODE(sym)\
+ (void *)(REALMODE_BASE + ((char *)&(sym) - (char *)&__realmode_code))
+
/* to have a common register file for interrupt handlers */
X86EMU_sysEnv _X86EMU_env;
void (*realmode_call)(u32 addr, u32 eax, u32 ebx, u32 ecx, u32 edx,
- u32 esi, u32 edi) asmlinkage =
- (void *)&__realmode_call;
+ u32 esi, u32 edi) asmlinkage;
void (*realmode_interrupt)(u32 intno, u32 eax, u32 ebx, u32 ecx, u32 edx,
- u32 esi, u32 edi) asmlinkage =
- (void *)&__realmode_interrupt;
+ u32 esi, u32 edi) asmlinkage;
+
+static void setup_realmode_code(void)
+{
+ memcpy(REALMODE_BASE, &__realmode_code, __realmode_code_size);
+
+ /* Ensure the global pointers are relocated properly. */
+ realmode_call = PTR_TO_REAL_MODE(__realmode_call);
+ realmode_interrupt = PTR_TO_REAL_MODE(__realmode_interrupt);
+
+ printk(BIOS_SPEW, "Real mode stub @%p: %d bytes\n", REALMODE_BASE,
+ __realmode_code_size);
+}
static void setup_rombios(void)
{
@@ -149,7 +170,7 @@ static void write_idt_stub(void *target, u8 intnum)
{
unsigned char *codeptr;
codeptr = (unsigned char *) target;
- memcpy(codeptr, &__idt_handler, (size_t)&__idt_handler_size);
+ memcpy(codeptr, &__idt_handler, __idt_handler_size);
codeptr[3] = intnum; /* modify int# in the code stub. */
}
@@ -163,7 +184,7 @@ static void setup_realmode_idt(void)
*/
for (i = 0; i < 256; i++) {
idts[i].cs = 0;
- idts[i].offset = 0x1000 + (i * (u32)&__idt_handler_size);
+ idts[i].offset = 0x1000 + (i * __idt_handler_size);
write_idt_stub((void *)((u32 )idts[i].offset), i);
}
@@ -204,7 +225,7 @@ static u8 vbe_get_mode_info(vbe_mode_info_t * mi)
{
printk(BIOS_DEBUG, "VBE: Getting information about VESA mode %04x\n",
mi->video_mode);
- char *buffer = (char *)&__buffer;
+ char *buffer = PTR_TO_REAL_MODE(__realmode_buffer);
u16 buffer_seg = (((unsigned long)buffer) >> 4) & 0xff00;
u16 buffer_adr = ((unsigned long)buffer) & 0xffff;
realmode_interrupt(0x10, VESA_GET_MODE_INFO, 0x0000,
@@ -312,9 +333,8 @@ void run_bios(struct device *dev, unsigned long addr)
/* Set up real-mode IDT */
setup_realmode_idt();
- memcpy(REALMODE_BASE, &__realmode_code, (size_t)&__realmode_code_size);
- printk(BIOS_SPEW, "Real mode stub @%p: %d bytes\n", REALMODE_BASE,
- (u32)&__realmode_code_size);
+ /* Make sure the code is placed. */
+ setup_realmode_code();
printk(BIOS_DEBUG, "Calling Option ROM...\n");
/* TODO ES:DI Pointer to System BIOS PnP Installation Check Structure */
@@ -366,9 +386,8 @@ void do_vsmbios(void)
/* Setting up realmode IDT */
setup_realmode_idt();
- memcpy(REALMODE_BASE, &__realmode_code, (size_t)&__realmode_code_size);
- printk(BIOS_SPEW, "VSA: Real mode stub @%p: %d bytes\n", REALMODE_BASE,
- (u32)&__realmode_code_size);
+ /* Make sure the code is placed. */
+ setup_realmode_code();
if ((unsigned int)cbfs_load_stage(CBFS_DEFAULT_MEDIA, "vsa") !=
VSA2_ENTRY_POINT) {
diff --git a/src/device/oprom/realmode/x86.h b/src/device/oprom/realmode/x86.h
index 76d3e4643c..a811a5621e 100644
--- a/src/device/oprom/realmode/x86.h
+++ b/src/device/oprom/realmode/x86.h
@@ -32,10 +32,10 @@ struct realmode_idt {
void x86_exception(struct eregs *info);
/* From x86_asm.S */
-extern unsigned char __idt_handler, __idt_handler_size;
-extern unsigned char __realmode_code, __realmode_code_size;
-extern unsigned char __realmode_call, __realmode_interrupt;
-extern unsigned char __buffer;
+extern unsigned char __idt_handler;
+extern unsigned int __idt_handler_size;
+extern unsigned char __realmode_code;
+extern unsigned int __realmode_code_size;
extern void (*realmode_call)(u32 addr, u32 eax, u32 ebx, u32 ecx, u32 edx,
u32 esi, u32 edi) asmlinkage;
diff --git a/src/device/oprom/realmode/x86_asm.S b/src/device/oprom/realmode/x86_asm.S
index 56ebb3a885..54cf374025 100644
--- a/src/device/oprom/realmode/x86_asm.S
+++ b/src/device/oprom/realmode/x86_asm.S
@@ -36,7 +36,8 @@ __idt_handler:
movb $0, %al /* This instruction gets modified */
ljmp $0, $__interrupt_handler_16bit
.globl __idt_handler_size
-__idt_handler_size = ( . - __idt_handler)
+__idt_handler_size:
+ .long . - __idt_handler
/* In order to be independent of coreboot's position in RAM
@@ -47,7 +48,6 @@ __idt_handler_size = ( . - __idt_handler)
__realmode_code:
/* Realmode IDT pointer structure. */
- .globl __realmode_idt
__realmode_idt = RELOCATED(.)
.word 1023 /* 16 bit limit */
.long 0 /* 24 bit base */
@@ -67,13 +67,13 @@ __registers = RELOCATED(.)
.long 0 /* 20 - EDI */
/* 256 byte buffer, used by int10 */
- .globl __buffer
-__buffer = RELOCATED(.)
+ .globl __realmode_buffer
+__realmode_buffer:
.skip 256
.code32
.globl __realmode_call
-__realmode_call = RELOCATED(.)
+__realmode_call:
/* save all registers to the stack */
pusha
pushf
@@ -204,7 +204,7 @@ __lcall_instr = RELOCATED(.)
ret
.globl __realmode_interrupt
-__realmode_interrupt = RELOCATED(.)
+__realmode_interrupt:
/* save all registers to the stack */
pusha
pushf
@@ -408,6 +408,7 @@ __interrupt_handler_16bit = RELOCATED(.)
iret
.globl __realmode_code_size
-__realmode_code_size = (. - __realmode_code)
+__realmode_code_size:
+ .long . - __realmode_code
.code32