X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=x86_64%2Fsysdeps.h;h=338aa40bfbb6aa4ed28f2e543fe6ad0dfc52b559;hb=3384f0373c8758e5ddd08f489ad7110898dd5406;hp=af89cb186f8a74d080ad79fdd9759985fe6a381f;hpb=528b4479a96491431b243bf02da43c792962fb27;p=debian%2Felilo diff --git a/x86_64/sysdeps.h b/x86_64/sysdeps.h index af89cb1..338aa40 100644 --- a/x86_64/sysdeps.h +++ b/x86_64/sysdeps.h @@ -47,6 +47,10 @@ */ #define INITRD_START (50*1024*1024) +/* Default start address for kernel. */ +#define DEFAULT_KERNEL_START 0x100000 + + /* * This version must match the one in the kernel. * @@ -307,10 +311,16 @@ typedef union x86_64_boot_params { UINT8 *t = (UINT8 *)(to); \ UINT8 *f = (UINT8 *)(from); \ UINTN n = cnt; \ - if (t && f && n) { \ + if (t && f && n && (tf)) { \ + t += n; \ + f += n; \ + while (n--) { \ + *t-- = *f--; \ + } \ } \ } @@ -343,6 +353,7 @@ extern UINTN param_size; extern VOID *kernel_start; extern UINTN kernel_size; +extern VOID *kernel_load_address; extern VOID *initrd_start; extern UINTN initrd_size; @@ -370,8 +381,8 @@ start_kernel(VOID *kentry, boot_params_t *bp) UINT32 kernel_entry; UINT16 kernel_cs; } jumpvector; - UINTN njump; VOID *jump_start; + uint64_t temp; /* * Disable interrupts. @@ -379,11 +390,20 @@ start_kernel(VOID *kentry, boot_params_t *bp) asm volatile ( "cli" : : ); /* - * Relocate initrd, if present. + * Relocate kernel (if needed), and initrd (if present). + * Copy kernel first, in case kernel was loaded overlapping where we're + * planning to copy the initrd. This assumes that the initrd didn't + * get loaded overlapping where we're planning to copy the kernel, but + * that's pretty unlikely since we couldn't alloc that space for the + * kernel (or the kernel would already be there). */ + if (kernel_start != kernel_load_address) { + MEMCPY(kernel_start, kernel_load_address, kernel_size); + } if (bp->s.initrd_start) { - MEMCPY(INITRD_START, bp->s.initrd_start, bp->s.initrd_size); + temp = bp->s.initrd_start; + MEMCPY(INITRD_START, temp , bp->s.initrd_size); bp->s.initrd_start = INITRD_START; } /* @@ -434,14 +454,15 @@ start_kernel(VOID *kentry, boot_params_t *bp) /* * Jump to kernel entry point. + * + * Cast is to tell gcc that we know we're going from + * 64-bit ptr to 32-bit integer. */ - jumpvector.kernel_entry=kentry; + jumpvector.kernel_entry=(UINT32)((UINT64)kentry); jumpvector.kernel_cs=0x10; - njump = &jumpvector; jump_start = (VOID *)&jumpvector; //asm volatile ( "mov %0, %%rcx" : : "m" (&jumpvector) ); asm volatile ( "mov %0, %%rcx" : : "m" (jump_start) ); - //asm volatile ( "mov %0, %%rcx" : : "m" (njump) ); asm volatile ( "ljmp *(%%rcx)" : :); /* Never come back to here. */ }