Merge relocators into mips

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2009-11-26 23:00:02 +01:00
commit a44c7e23d8
3 changed files with 44 additions and 23 deletions

View file

@ -27,13 +27,11 @@
#ifdef __x86_64__ #ifdef __x86_64__
#define RAX %rax #define RAX %rax
#define RCX %rcx #define RCX %rcx
#define RDX %rdx
#define RDI %rdi #define RDI %rdi
#define RSI %rdi #define RSI %rdi
#else #else
#define RAX %eax #define RAX %eax
#define RCX %ecx #define RCX %ecx
#define RDX %edx
#define RDI %edi #define RDI %edi
#define RSI %esi #define RSI %esi
#endif #endif
@ -97,7 +95,7 @@ RELOCATOR_VARIABLE(size)
#ifdef BACKWARD #ifdef BACKWARD
add RCX, RSI add RCX, RSI
add RDX, RDI add RCX, RDI
#endif #endif
#ifndef BACKWARD #ifndef BACKWARD

View file

@ -30,16 +30,28 @@ copycont1:
addiu $8, $8, 0x1 addiu $8, $8, 0x1
addiu $9, $9, 0x1 addiu $9, $9, 0x1
addiu $10, $10, 0xffff addiu $10, $10, 0xffff
subu $11,$10,$0 bne $10, $0, copycont1
bne $11, $0, copycont1
cachecont1: move $9, $12
move $10, $13
cachecont1a:
cache 1,0($12) 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) cache 0,0($12)
addiu $12, $12, 0x1 addiu $12, $12, 0x1
addiu $13, $13, 0xffff addiu $13, $13, 0xffff
subu $11,$13,$0 bne $13, $0, cachecont1b
bne $11, $0, cachecont1
sync
VARIABLE (grub_relocator32_forward_end) VARIABLE (grub_relocator32_forward_end)
VARIABLE (grub_relocator32_backward_start) VARIABLE (grub_relocator32_backward_start)
@ -54,18 +66,28 @@ VARIABLE (grub_relocator32_backward_start)
copycont2: copycont2:
lb $11,0($8) lb $11,0($8)
sb $11,0($9) sb $11,0($9)
cache 1, 0($9)
cache 0, 0($9)
addiu $8, $8, 0xffff addiu $8, $8, 0xffff
addiu $9, $9, 0xffff addiu $9, $9, 0xffff
addiu $10, 0xffff addiu $10, 0xffff
subu $11,$10,$0 bne $10, $0, copycont2
bne $11, $0, copycont2
cachecont2: move $9, $12
move $10, $13
cachecont2a:
cache 1,0($12) 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) cache 0,0($12)
addiu $12, $12, 0x1 addiu $12, $12, 0x1
addiu $13, $13, 0xffff addiu $13, $13, 0xffff
subu $11,$13,$0 bne $13, $0, cachecont2b
bne $11, $0, cachecont2
sync
VARIABLE (grub_relocator32_backward_end) VARIABLE (grub_relocator32_backward_end)

View file

@ -20,6 +20,7 @@
+ (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN) \ + (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN) \
+ (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN) \ + (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN) \
+ (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN)) + (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN))
#define PRE_REGION_SIZE (RELOCATOR_SIZEOF (backward) + RELOCATOR_ALIGN)
void * void *
PREFIX (alloc) (grub_size_t size) PREFIX (alloc) (grub_size_t size)
@ -32,7 +33,7 @@ PREFIX (alloc) (grub_size_t size)
*(grub_size_t *) playground = size; *(grub_size_t *) playground = size;
return playground + RELOCATOR_SIZEOF (forward); return playground + PRE_REGION_SIZE;
} }
void * void *
@ -40,7 +41,7 @@ PREFIX (realloc) (void *relocator, grub_size_t size)
{ {
char *playground; char *playground;
playground = (char *) relocator - RELOCATOR_SIZEOF (forward); playground = (char *) relocator - PRE_REGION_SIZE;
playground = grub_realloc (playground, size + MAX_OVERHEAD); playground = grub_realloc (playground, size + MAX_OVERHEAD);
if (!playground) if (!playground)
@ -48,14 +49,14 @@ PREFIX (realloc) (void *relocator, grub_size_t size)
*(grub_size_t *) playground = size; *(grub_size_t *) playground = size;
return playground + RELOCATOR_SIZEOF (forward); return playground + PRE_REGION_SIZE;
} }
void void
PREFIX(free) (void *relocator) PREFIX(free) (void *relocator)
{ {
if (relocator) if (relocator)
grub_free ((char *) relocator - RELOCATOR_SIZEOF (forward)); grub_free ((char *) relocator - PRE_REGION_SIZE);
} }
grub_err_t grub_err_t
@ -65,7 +66,7 @@ PREFIX (boot) (void *relocator, grub_uint32_t dest,
grub_size_t size; grub_size_t size;
char *playground; char *playground;
playground = (char *) relocator - RELOCATOR_SIZEOF (forward); playground = (char *) relocator - PRE_REGION_SIZE;
size = *(grub_size_t *) playground; size = *(grub_size_t *) playground;
grub_dprintf ("relocator", grub_dprintf ("relocator",
@ -75,9 +76,9 @@ PREFIX (boot) (void *relocator, grub_uint32_t dest,
/* Very unlikely condition: Relocator may risk overwrite itself. /* Very unlikely condition: Relocator may risk overwrite itself.
Just move it a bit up. */ Just move it a bit up. */
if ((grub_uint8_t *) UINT_TO_PTR (dest) - (grub_uint8_t *) relocator 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 && (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) void *relocator_new = ((grub_uint8_t *) relocator)
+ (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN) + (RELOCATOR_SIZEOF (forward) + RELOCATOR_ALIGN)
@ -94,7 +95,7 @@ PREFIX (boot) (void *relocator, grub_uint32_t dest,
if (UINT_TO_PTR (dest) >= relocator) if (UINT_TO_PTR (dest) >= relocator)
{ {
int overhead; int overhead;
overhead = overhead = dest -
ALIGN_UP (dest - RELOCATOR_SIZEOF (backward) - RELOCATOR_ALIGN, ALIGN_UP (dest - RELOCATOR_SIZEOF (backward) - RELOCATOR_ALIGN,
RELOCATOR_ALIGN); RELOCATOR_ALIGN);
grub_dprintf ("relocator", grub_dprintf ("relocator",