X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=x86_64%2Fsysdeps.h;h=ff99eef220cd8709da84fdd9de5e9410f67e4f12;hb=4d5dcc08ba40d496e8253cd32fd8b15fac984c74;hp=df86f443a1fa4460bd594b410c4058804314b3d7;hpb=d38858b0a1d960e82104939c810e6d4f30cbe6b0;p=debian%2Felilo diff --git a/x86_64/sysdeps.h b/x86_64/sysdeps.h index df86f44..ff99eef 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. * @@ -103,12 +107,12 @@ typedef union x86_64_boot_params { /* 0x06 */ UINT8 orig_video_mode; /* LDR */ /* 0x07 */ UINT8 orig_video_cols; /* LDR */ -/* 0x08 */ UINT16 unused_1; /* unused */ +/* 0x08 */ UINT16 pad_1; /* unused */ /* %%TBD */ /* 0x0A */ UINT16 orig_ega_bx; /* LDR */ -/* 0x0C */ UINT16 unused_2; /* unused */ +/* 0x0C */ UINT16 pad_2; /* unused */ /* Screen height before passing control to kernel. */ /* 0x0E */ UINT8 orig_video_rows; /* LDR */ @@ -170,7 +174,7 @@ typedef union x86_64_boot_params { /* 0x4E */ UINT32 bios_code_len; /* LDR */ /* 0x52 */ UINT16 bios_data_len; /* LDR */ -/* 0x54 */ UINT8 unused_3[0x2C]; /* unused */ +/* 0x54 */ UINT8 pad_3[0x2C]; /* unused */ /* %%TBD */ /* 0x80 */ UINT8 hd0_info[0x10]; /* LDR */ @@ -180,35 +184,34 @@ typedef union x86_64_boot_params { /* 0xA0 */ UINT16 mca_info_len; /* LDR */ /* 0xA2 */ UINT8 mca_info_buf[0x10]; /* LDR */ -/* 0xB2 */ UINT8 unused_4[0x106]; /* unused */ - -/* Address of the EFI system table. */ -/* 0x1B8 */ UINT64 efi_sys_tbl; /* LDR */ +/* 0xB2 */ UINT8 pad_4[0x10E]; /* unused */ /* EFI boot loader signature. */ /* 0x1C0 */ UINT8 efi_loader_sig[4]; /* LDR */ -#define EFI_LOADER_SIG "EFIL" +#define EFI_LOADER_SIG_X64 "EL64" + +/* Address of the EFI system table. */ +/* 0x1C4 */ UINT32 efi_sys_tbl; /* LDR */ /* EFI memory descriptor size. */ -/* 0x1C4 */ UINT32 efi_mem_desc_size; /* LDR */ +/* 0x1C8 */ UINT32 efi_mem_desc_size; /* LDR */ /* EFI memory descriptor version. */ -/* 0x1C8 */ UINT32 efi_mem_desc_ver; /* LDR */ +/* 0x1CC */ UINT32 efi_mem_desc_ver; /* LDR */ /* Address & size of EFI memory map. */ -/* 0x1CC */ UINT32 efi_mem_map_size; /* LDR */ -/* 0x1D0 */ UINT64 efi_mem_map; /* LDR */ +/* 0x1D0 */ UINT32 efi_mem_map; /* LDR */ +/* 0x1D4 */ UINT32 efi_mem_map_size; /* LDR */ -/* Address & size of loader. */ -/* 0x1D8 */ UINT32 loader_start; /* LDR */ -/* 0x1DC */ UINT32 loader_size; /* LDR */ +/* 0x1D8 */ UINT32 efi_sys_tbl_hi; /* LDR */ +/* 0x1DC */ UINT32 efi_mem_map_hi; /* LDR */ /* Available contiguous extended memory in KB. */ /* 0x1E0 */ UINT32 alt_mem_k; /* LDR */ -/* 0x1E4 */ UINT32 unused_51; /* unused */ +/* 0x1E4 */ UINT32 pad_51; /* unused */ /* 0x1E8 */ UINT8 e820_nrmap; -/* 0x1E9 */ UINT32 unused_52[2]; /* unused */ +/* 0x1E9 */ UINT32 pad_52[2]; /* unused */ /* Size of setup code in sectors (1 sector == 512 bytes). */ /* 0x1F1 */ UINT8 setup_sectors; /* BLD */ @@ -217,15 +220,10 @@ typedef union x86_64_boot_params { /* 0x1F2 */ UINT16 mount_root_rdonly; /* BLD */ /* %%TBD */ -/* 0x1F4 */ UINT16 sys_size; /* BLD */ - -/* %%TBD */ -/* 0x1F6 */ UINT16 swap_dev; /* BLD */ +/* 0x1F4 */ UINT32 sys_size; /* BLD */ /* %%TBD */ -/* 0x1F8 */ UINT16 ramdisk_flags; /* BLD */ -#define RAMDISK_PROMPT 0x8000 -#define RAMDISK_LOAD 0x4000 +/* 0x1F8 */ UINT16 ram_size_DNU; /* BLD */ /* %%TBD */ /* 0x1FA */ UINT16 video_mode_flag; /* BLD */ @@ -233,12 +231,8 @@ typedef union x86_64_boot_params { /* %%TBD */ /* 0x1FC */ UINT16 orig_root_dev; /* BLD */ -/* 0x1FE */ UINT8 unused_6; /* unused */ - /* %%TBD */ -/* 0x1FF */ UINT8 aux_dev_info; /* LDR */ -#define NO_MOUSE 0x00 -#define FOUND_MOUSE 0xAA +/* 0x1FE */ UINT16 boot_flag; /* ? */ /* Jump past setup data (not used in EFI). */ /* 0x200 */ UINT16 jump; /* BLD */ @@ -280,16 +274,21 @@ typedef union x86_64_boot_params { /* 0x21C */ UINT32 initrd_size; /* LDR */ /* %%TBD */ -/* 0x220 */ UINT32 bootsect_helper; /* BLD */ +/* 0x220 */ UINT32 bootsect_helper_DNU; /* BLD */ /* %%TBD */ /* 0x224 */ UINT16 heap_end_ptr; /* LDR */ /* %%TBD */ -/* 0x226 */ UINT16 unused_7; /* LDR */ +/* 0x226 */ UINT8 ext_loader_ver; /* LDR */ +/* 0x227 */ UINT8 ext_loader_type; /* LDR */ /* 0x228 */ UINT32 cmdline_addr; /* LDR */ -/* 0x22C */ UINT32 unused_8[41]; +/* 0x22C */ UINT32 initrd_addr_max; /* BLD */ +/* 0x230 */ UINT32 kernel_alignment; /* BLD */ +/* 0x234 */ UINT8 relocatable_kernel; /* BLD */ +/* 0x235 */ UINT8 pad_8[3]; +/* 0x238 */ UINT32 pad_9[38]; /* 0x2D0 */ UINT8 e820_map[2560]; } s; } boot_params_t; @@ -308,10 +307,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--; \ + } \ } \ } @@ -344,6 +349,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; @@ -358,6 +364,7 @@ extern UINT8 rmswitch_image[]; extern UINTN rmswitch_size; extern INTN x86_64_use_legacy_free_boot(); +extern INTN x86_64_text_mode(); /* * How to jump to kernel code @@ -371,7 +378,6 @@ start_kernel(VOID *kentry, boot_params_t *bp) UINT32 kernel_entry; UINT16 kernel_cs; } jumpvector; - UINTN njump; VOID *jump_start; /* @@ -380,13 +386,16 @@ start_kernel(VOID *kentry, boot_params_t *bp) asm volatile ( "cli" : : ); /* - * Relocate initrd, if present. + * Relocate kernel (if needed). + * 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 (bp->s.initrd_start) { - MEMCPY(INITRD_START, bp->s.initrd_start, bp->s.initrd_size); - bp->s.initrd_start = INITRD_START; + if (kernel_start != kernel_load_address) { + MEMCPY(kernel_start, kernel_load_address, kernel_size); } + /* * Copy boot sector, setup data and command line * to final resting place. We need to copy @@ -395,6 +404,9 @@ start_kernel(VOID *kentry, boot_params_t *bp) MEMCPY(high_base_mem, bp, 0x4000); + bp = (boot_params_t *)high_base_mem; + bp->s.cmdline_addr = high_base_mem + bp->s.cmdline_offset; + /* * Initialize Linux GDT. */ @@ -432,20 +444,22 @@ 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. */ } typedef struct sys_img_options { - UINT8 nothing_yet; + UINT8 dummy; /* forces non-zero offset for first field */ + UINT8 text_mode; /* do not try to initialize Graphics Output Protocol */ } sys_img_options_t; #endif /* __ELILO_SYSDEPS_X86_64_H__ */