From 83088afbba0c142fda5313866abd1e679d0f9e78 Mon Sep 17 00:00:00 2001 From: Graeme Russ Date: Tue, 8 Nov 2011 02:33:15 +0000 Subject: cosmetic: checkpatch cleanup of arch/x86/lib/*.c Signed-off-by: Graeme Russ --- arch/x86/lib/realmode.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'arch/x86/lib/realmode.c') diff --git a/arch/x86/lib/realmode.c b/arch/x86/lib/realmode.c index 6aa0f23a1..5a525ee79 100644 --- a/arch/x86/lib/realmode.c +++ b/arch/x86/lib/realmode.c @@ -26,11 +26,7 @@ #include #include -#define REALMODE_MAILBOX ((char*)0xe00) - -extern ulong __realmode_start; -extern ulong __realmode_size; -extern char realmode_enter; +#define REALMODE_MAILBOX ((char *)0xe00) int realmode_setup(void) { @@ -63,15 +59,14 @@ int enter_realmode(u16 seg, u16 off, struct pt_regs *in, struct pt_regs *out) in->eip = off; in->xcs = seg; - if (3>(in->esp & 0xffff)) { + if ((in->esp & 0xffff) < 4) printf("Warning: entering realmode with sp < 4 will fail\n"); - } memcpy(REALMODE_MAILBOX, in, sizeof(struct pt_regs)); asm("wbinvd\n"); __asm__ volatile ( - "lcall $0x20,%0\n" : : "i" (&realmode_enter) ); + "lcall $0x20,%0\n" : : "i" (&realmode_enter)); asm("wbinvd\n"); memcpy(out, REALMODE_MAILBOX, sizeof(struct pt_regs)); @@ -79,9 +74,10 @@ int enter_realmode(u16 seg, u16 off, struct pt_regs *in, struct pt_regs *out) return out->eax; } - -/* This code is supposed to access a realmode interrupt - * it does currently not work for me */ +/* + * This code is supposed to access a realmode interrupt + * it does currently not work for me + */ int enter_realmode_int(u8 lvl, struct pt_regs *in, struct pt_regs *out) { /* place two instructions at 0x700 */ @@ -92,5 +88,5 @@ int enter_realmode_int(u8 lvl, struct pt_regs *in, struct pt_regs *out) enter_realmode(0x00, 0x700, in, out); - return out->eflags&1; + return out->eflags & 0x00000001; } -- cgit v1.2.3-70-g09d2 From 03228b26d5d999b05ea6e5946ad0375715b9043c Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sat, 12 Nov 2011 16:31:18 +0000 Subject: x86: Fix how the location of the realmode and bios blobs are calculated There are two blobs embedded into the u-boot image which are linked to run at an address which is different from where they actually end up in the ROM, one called "realmode" and one called "bios". There are realmode_setup and bios_setup functions which prepare those blobs by copying them into the location they're supposed to run from, among other things. During u-boot relocation from ROM to RAM, the text and a few data segments are copied over. The realmode and bios sections are not copied, and so the only place they can be read from is their original location in the ROM. Looking specifically at the bios blob, there are symbols defined in the linker script called __bios_start and __bios_size which are defined to be the start and size of the blob in the ROM. In the bios_setup function, there seem to be two mistakes happening. First, the offset from ROM to RAM is being added to __bios_start which implies that this code expects to use the copy moved to RAM. No such copy is made, so that's wrong. More subtly, when u-boot relocates itself, it goes through all of the relocations stored in .rel.dyn and fixes them up. This has the effect of transforming the __bios_start reference in bios_setup so that it refers to the version in RAM (if one existed) instead of the one in ROM. To correct for that, the offset actually needs to be subtracted out again to translate the address back into the ROM. The net effect is that for both blobs, a + needs to be changed to a -. Signed-off-by: Gabe Black --- arch/x86/lib/bios_setup.c | 6 +++++- arch/x86/lib/realmode.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'arch/x86/lib/realmode.c') diff --git a/arch/x86/lib/bios_setup.c b/arch/x86/lib/bios_setup.c index 053280b95..0dfe4a103 100644 --- a/arch/x86/lib/bios_setup.c +++ b/arch/x86/lib/bios_setup.c @@ -78,7 +78,11 @@ static void setvector(int vector, u16 segment, void *handler) int bios_setup(void) { - ulong bios_start = (ulong)&__bios_start + gd->reloc_off; + /* + * The BIOS section is not relocated and still in the ROM. The + * __bios_start symbol was adjusted, though, so adjust it back. + */ + ulong bios_start = (ulong)&__bios_start - gd->reloc_off; ulong bios_size = (ulong)&__bios_size; static int done; diff --git a/arch/x86/lib/realmode.c b/arch/x86/lib/realmode.c index 5a525ee79..bf0d0aaa3 100644 --- a/arch/x86/lib/realmode.c +++ b/arch/x86/lib/realmode.c @@ -30,7 +30,11 @@ int realmode_setup(void) { - ulong realmode_start = (ulong)&__realmode_start + gd->reloc_off; + /* + * The realmode section is not relocated and still in the ROM. The + * __realmode_start symbol was adjusted, though, so adjust it back. + */ + ulong realmode_start = (ulong)&__realmode_start - gd->reloc_off; ulong realmode_size = (ulong)&__realmode_size; /* copy the realmode switch code */ -- cgit v1.2.3-70-g09d2 From 769db03a4a4ea1dc7e43c089c2227a0c8b4ffcbc Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sat, 12 Nov 2011 16:34:48 +0000 Subject: x86: Don't relocate symbols which point to things that aren't relocated This change adds an upper bound for symbols which are fixed up after u-boot is relocated into RAM. This way portions that are left at their original location can be referred to without having to manually fix up any pointers. Signed-off-by: Gabe Black --- arch/x86/lib/bios_setup.c | 7 ++----- arch/x86/lib/board.c | 5 ++++- arch/x86/lib/realmode.c | 7 ++----- 3 files changed, 8 insertions(+), 11 deletions(-) (limited to 'arch/x86/lib/realmode.c') diff --git a/arch/x86/lib/bios_setup.c b/arch/x86/lib/bios_setup.c index 0dfe4a103..265f7d671 100644 --- a/arch/x86/lib/bios_setup.c +++ b/arch/x86/lib/bios_setup.c @@ -78,11 +78,8 @@ static void setvector(int vector, u16 segment, void *handler) int bios_setup(void) { - /* - * The BIOS section is not relocated and still in the ROM. The - * __bios_start symbol was adjusted, though, so adjust it back. - */ - ulong bios_start = (ulong)&__bios_start - gd->reloc_off; + /* The BIOS section is not relocated and still in the ROM. */ + ulong bios_start = (ulong)&__bios_start; ulong bios_size = (ulong)&__bios_size; static int done; diff --git a/arch/x86/lib/board.c b/arch/x86/lib/board.c index 244a02163..18e0edee8 100644 --- a/arch/x86/lib/board.c +++ b/arch/x86/lib/board.c @@ -231,8 +231,11 @@ static int do_elf_reloc_fixups(void) offset_ptr_ram = offset_ptr_rom + gd->reloc_off; /* Check that the target points into .text */ - if (*offset_ptr_ram >= CONFIG_SYS_TEXT_BASE) + if (*offset_ptr_ram >= CONFIG_SYS_TEXT_BASE && + *offset_ptr_ram < + (CONFIG_SYS_TEXT_BASE + size)) { *offset_ptr_ram += gd->reloc_off; + } } } while (re_src++ < re_end); diff --git a/arch/x86/lib/realmode.c b/arch/x86/lib/realmode.c index bf0d0aaa3..75511b2bd 100644 --- a/arch/x86/lib/realmode.c +++ b/arch/x86/lib/realmode.c @@ -30,11 +30,8 @@ int realmode_setup(void) { - /* - * The realmode section is not relocated and still in the ROM. The - * __realmode_start symbol was adjusted, though, so adjust it back. - */ - ulong realmode_start = (ulong)&__realmode_start - gd->reloc_off; + /* The realmode section is not relocated and still in the ROM. */ + ulong realmode_start = (ulong)&__realmode_start; ulong realmode_size = (ulong)&__realmode_size; /* copy the realmode switch code */ -- cgit v1.2.3-70-g09d2