From d4e56ea7877ef15eac42f174d49fddbc4117e462 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 26 Nov 2009 22:19:37 +0100 Subject: [PATCH 1/3] Fix warning on some build systems --- lib/relocator.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/relocator.c b/lib/relocator.c index 68260b197..31695ff62 100644 --- a/lib/relocator.c +++ b/lib/relocator.c @@ -75,9 +75,9 @@ PREFIX (boot) (void *relocator, grub_uint32_t dest, /* Very unlikely condition: Relocator may risk overwrite itself. Just move it a bit up. */ if ((grub_uint8_t *) UINT_TO_PTR (dest) - (grub_uint8_t *) relocator - < RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN + < (signed) (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN) && (grub_uint8_t *) UINT_TO_PTR (dest) - (grub_uint8_t *) relocator - > -(RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN)) + > - (signed) (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN)) { void *relocator_new = ((grub_uint8_t *) relocator) + (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN) From f93415cfee91ca1e7a68409092653a95c05b2b48 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 26 Nov 2009 22:20:06 +0100 Subject: [PATCH 2/3] Improved cache handling in mips --- lib/mips/relocator_asm.S | 46 +++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/lib/mips/relocator_asm.S b/lib/mips/relocator_asm.S index f9cdf1470..9daf0d32f 100644 --- a/lib/mips/relocator_asm.S +++ b/lib/mips/relocator_asm.S @@ -30,16 +30,28 @@ copycont1: addiu $8, $8, 0x1 addiu $9, $9, 0x1 addiu $10, $10, 0xffff - subu $11,$10,$0 - bne $11, $0, copycont1 + bne $10, $0, copycont1 -cachecont1: + move $9, $12 + move $10, $13 +cachecont1a: cache 1,0($12) + addiu $12, $12, 0x1 + addiu $13, $13, 0xffff + bne $13, $0, cachecont1a + + sync + + move $12, $9 + move $13, $10 +cachecont1b: cache 0,0($12) addiu $12, $12, 0x1 addiu $13, $13, 0xffff - subu $11,$13,$0 - bne $11, $0, cachecont1 + bne $13, $0, cachecont1b + + sync + VARIABLE (grub_relocator32_forward_end) VARIABLE (grub_relocator32_backward_start) @@ -54,18 +66,28 @@ VARIABLE (grub_relocator32_backward_start) copycont2: lb $11,0($8) sb $11,0($9) - cache 1, 0($9) - cache 0, 0($9) addiu $8, $8, 0xffff addiu $9, $9, 0xffff addiu $10, 0xffff - subu $11,$10,$0 - bne $11, $0, copycont2 -cachecont2: + bne $10, $0, copycont2 + + move $9, $12 + move $10, $13 +cachecont2a: cache 1,0($12) + addiu $12, $12, 0x1 + addiu $13, $13, 0xffff + bne $13, $0, cachecont2a + + sync + + move $12, $9 + move $13, $10 +cachecont2b: cache 0,0($12) addiu $12, $12, 0x1 addiu $13, $13, 0xffff - subu $11,$13,$0 - bne $11, $0, cachecont2 + bne $13, $0, cachecont2b + + sync VARIABLE (grub_relocator32_backward_end) From bbd46b09667317cab3393c07c2fac5b6c86f296b Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 26 Nov 2009 22:51:00 +0100 Subject: [PATCH 3/3] Fixes for backwards relocator --- lib/i386/relocator_asm.S | 4 +--- lib/relocator.c | 13 +++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/i386/relocator_asm.S b/lib/i386/relocator_asm.S index bd25143e8..c1be85c2b 100644 --- a/lib/i386/relocator_asm.S +++ b/lib/i386/relocator_asm.S @@ -27,13 +27,11 @@ #ifdef __x86_64__ #define RAX %rax #define RCX %rcx -#define RDX %rdx #define RDI %rdi #define RSI %rdi #else #define RAX %eax #define RCX %ecx -#define RDX %edx #define RDI %edi #define RSI %esi #endif @@ -97,7 +95,7 @@ RELOCATOR_VARIABLE(size) #ifdef BACKWARD add RCX, RSI - add RDX, RDI + add RCX, RDI #endif #ifndef BACKWARD diff --git a/lib/relocator.c b/lib/relocator.c index 31695ff62..176379eb7 100644 --- a/lib/relocator.c +++ b/lib/relocator.c @@ -20,6 +20,7 @@ + (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN) \ + (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN) \ + (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN)) +#define PRE_REGION_SIZE (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN) void * PREFIX (alloc) (grub_size_t size) @@ -32,7 +33,7 @@ PREFIX (alloc) (grub_size_t size) *(grub_size_t *) playground = size; - return playground + RELOCATOR_SIZEOF (forward); + return playground + PRE_REGION_SIZE; } void * @@ -40,7 +41,7 @@ PREFIX (realloc) (void *relocator, grub_size_t size) { char *playground; - playground = (char *) relocator - RELOCATOR_SIZEOF (forward); + playground = (char *) relocator - PRE_REGION_SIZE; playground = grub_realloc (playground, size + MAX_OVERHEAD); if (!playground) @@ -48,14 +49,14 @@ PREFIX (realloc) (void *relocator, grub_size_t size) *(grub_size_t *) playground = size; - return playground + RELOCATOR_SIZEOF (forward); + return playground + PRE_REGION_SIZE; } void PREFIX(free) (void *relocator) { if (relocator) - grub_free ((char *) relocator - RELOCATOR_SIZEOF (forward)); + grub_free ((char *) relocator - PRE_REGION_SIZE); } grub_err_t @@ -65,7 +66,7 @@ PREFIX (boot) (void *relocator, grub_uint32_t dest, grub_size_t size; char *playground; - playground = (char *) relocator - RELOCATOR_SIZEOF (forward); + playground = (char *) relocator - PRE_REGION_SIZE; size = *(grub_size_t *) playground; grub_dprintf ("relocator", @@ -94,7 +95,7 @@ PREFIX (boot) (void *relocator, grub_uint32_t dest, if (UINT_TO_PTR (dest) >= relocator) { int overhead; - overhead = + overhead = dest - ALIGN_UP (dest - RELOCATOR_SIZEOF (backward) - RELOCATOR_ALIGN, RELOCATOR_ALIGN); grub_dprintf ("relocator",