Fix build of sparc64 port & implement setjmp/longjmp
PATCH 1/1 Fix build of sparc64 port & implement setjmp/longjmp
Hi.
Here is a (mostly) maintainance patch for sparc64 port.
It only fixes the build and implements setjmp/longjmp so that one can jump to rescue mode.
It also builds the linux loader module, but the boot is known to fail on my box (some disk access error at OF level when reading the linux kernel image).
I prefer to post the patch for validation before commiting, it's been too long I haven't post to go on my own :) . (changelog is in the diff :p ).
Signature · 1 line
Vincent Pelletier
? include/grub/sparc64/ieee1275/loader.h
Index: ChangeLog
===================================================================
RCS file: /sources/grub/grub2/ChangeLog,v
retrieving revision 1.341
ChangeLog +67 -0
@@ -1,3 +1,70 @@ +2007-03-01 Vincent Pelletier <[email protected]> + + * THANKS: Update my mail address. + * conf/sparc64-ieee1275.rmk: Include conf/common.mk. + (COMMON_ASFLAGS): Build sparc64 binary. + (COMMON_LDFLAGS): Updated to gcc-style flags. + (grub_mkimage_SOURCES): Commented out. + (pkgdata_MODULES): Removed fat.mod, ufs.mod, ext2.mod, minix.mod, + hfs.mod, jfs.mod, hello.mod, font.mod, ls.mod, boot.mod, cmp.mod, + cat.mod, terminal.mod, fshelp.mod, amiga.mod, apple.mod, pc.mod, + loopback.mod, help.mod, sun.mod, configfile.mod, search.mod, + gzio.mod, xfs.mod, affs.mod, sfs.mod, acorn.mod. Added _linux.mod + and linux.mod. + (kernel_elf_LDFLAGS): Prepend common flags. Updated to gcc-style + flags. + (_linux_mod_SOURCES, _linux_mod_CFLAGS, _linux_mod_LDFLAGS) + (linux_mod_SOURCES, linux_mod_CFLAGS, linux_mod_LDFLAGS): Uncomment. + (grub_script.tab.c, grub_script.tab.h, grub_modules_init.lst) + (fshelp_mod_SOURCES, fshelp_mod_CFLAGS, fshelp_mod_LDFLAGS) + (fat_mod_SOURCES, fat_mod_CFLAGS, fat_mod_LDFLAGS) + (ext2_mod_SOURCES, ext2_mod_CFLAGS, ext2_mod_LDFLAGS) + (ufs_mod_SOURCES, ufs_mod_CFLAGS, ufs_mod_LDFLAGS) + (minix_mod_SOURCES, minix_mod_CFLAGS, minix_mod_LDFLAGS) + (hfs_mod_SOURCES, hfs_mod_CFLAGS, hfs_mod_LDFLAGS, jfs_mod_SOURCES) + (jfs_mod_CFLAGS, jfs_mod_LDFLAGS, iso9660_mod_SOURCES) + (iso9660_mod_CFLAGS, iso9660_mod_LDFLAGS, xfs_mod_SOURCES) + (xfs_mod_CFLAGS, xfs_mod_LDFLAGS, affs_mod_SOURCES) + (affs_mod_CFLAGS, affs_mod_LDFLAGS, sfs_mod_SOURCES) + (sfs_mod_CFLAGS, sfs_mod_LDFLAGS, hello_mod_SOURCES) + (hello_mod_CFLAGS, hello_mod_LDFLAGS, boot_mod_SOURCES) + (boot_mod_CFLAGS, boot_mod_LDFLAGS, terminal_mod_SOURCES) + (terminal_mod_CFLAGS, terminal_mod_LDFLAGS, ls_mod_SOURCES) + (ls_mod_CFLAGS, ls_mod_LDFLAGS, cmp_mod_SOURCES, cmp_mod_CFLAGS) + (cmp_mod_LDFLAGS, cat_mod_SOURCES, cat_mod_CFLAGS, cat_mod_LDFLAGS) + (help_mod_SOURCES, help_mod_CFLAGS, help_mod_LDFLAGS) + (font_mod_SOURCES, font_mod_CFLAGS, font_mod_LDFLAGS) + (terminfo_mod_SOURCES, terminfo_mod_CFLAGS, terminfo_mod_LDFLAGS) + (amiga_mod_SOURCES, amiga_mod_CFLAGS, amiga_mod_LDFLAGS) + (apple_mod_SOURCES, apple_mod_CFLAGS, apple_mod_LDFLAG) + (pc_mod_SOURCES, pc_mod_CFLAGS, pc_mod_LDFLAGS, sun_mod_SOURCES) + (sun_mod_CFLAGS, sun_mod_LDFLAGS, acorn_mod_SOURCES, acorn_mod_CFLAGS) + (loopback_mod_SOURCES, loopback_mod_CFLAGS, loopback_mod_LDFLAGS) + (default_mod_SOURCES, default_mod_CFLAGS, default_mod_LDFLAGS) + (timeout_mod_SOURCES, timeout_mod_CFLAGS, timeout_mod_LDFLAGS) + (configfile_mod_SOURCES, configfile_mod_CFLAGS) + (configfile_mod_LDFLAGS, search_mod_SOURCES, search_mod_CFLAGS) + (search_mod_LDFLAGS, gzio_mod_SOURCES, gzio_mod_CFLAGS) + (gzio_mod_LDFLAGS, test_mod_SOURCES, test_mod_CFLAGS) + (test_mod_LDFLAGS): Removed. + * conf/sparc64-ieee1275.mk: Regenerate. + * include/grub/elf.h (ELF64_R_TYPE_DATA, ELF64_R_TYPE_ID) + (ELF64_R_TYPE_INFO): New macros. + * include/grub/sparc64/setjmp.h: Include grub/types.h. + (grub_jmp_buf): Update definition. + * kern/sparc64/dl.c (grub_arch_dl_relocate_symbols): Use + ELF64_R_TYPE_ID macro. Explicited bitmasks and casts. Fixed + R_SPARC_WDISP30 relocation checks and updated its error message. + Added support for R_SPARC_13 and R_SPARC_OLO10 relocations. + * kern/sparc64/ieee1275/init.c (grub_claim_heap): New function. + (grub_machine_fini): Call `grub_ieee1275_exit'. + * kern/sparc64/ieee1275/openfw.c (grub_devalias_iterate): Update call + to `grub_ieee1275_next_property'. Remove uneeded variable. + (grub_available_iterate): New function. + * normal/main.c: Explicit grub_exit_env alignment. + * normal/sparc64/setjmp.S (grub_setjmp, grub_longjmp): Implement. + * include/grub/sparc64/ieee1275/loader.h: New file. + 2007-02-21 Hollis Blanchard <[email protected]> * kern/powerpc/ieee1275/init.c (HEAP_SIZE): Removed.
Index: THANKS
===================================================================
RCS file: /sources/grub/grub2/THANKS,v
retrieving revision 1.18
THANKS +1 -1
@@ -26,7 +26,7 @@ Tristan Gingold <[email protected] Tsuneyoshi Yasuo <[email protected]> Vesa Jaaskelainen <[email protected]> Vincent Guffens <[email protected]> -Vincent Pelletier <[email protected]> +Vincent Pelletier <[email protected]> Vladimir Serbinenko <[email protected]> Also, we thank the projects GNU Automake and LZO. Some code
Index: conf/sparc64-ieee1275.rmk
===================================================================
RCS file: /sources/grub/grub2/conf/sparc64-ieee1275.rmk,v retrieving revision 1.16
sparc64-ieee1275.rmk +18 -175
233 lines not on this page · raw message
Index: include/grub/elf.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/elf.h,v retrieving revision 1.3
grub/elf.h +4 -0
@@ -514,6 +514,10 @@ typedef struct#define ELF64_R_SYM (i) ((i) >> 32)#define ELF64_R_TYPE (i) ((i) & 0xffffffff)#define ELF64_R_INFO (sym,type) ((((Elf64_Xword) (sym)) << 32) + (type)) +#define ELF64_R_TYPE_DATA (info) (((Elf64_Xword)(info) << 32) >> 40) +#define ELF64_R_TYPE_ID (info) (((Elf64_Xword)(info) << 56) >> 56) +#define ELF64_R_TYPE_INFO (data, type) (((Elf64_Xword)(sym) << 8) + \ + (Elf64_Xword)(type))/* Program segment header. */
Index: include/grub/sparc64/setjmp.h
===================================================================
RCS file: /sources/grub/grub2/include/grub/sparc64/setjmp.h,v retrieving revision 1.2
grub/sparc64/setjmp.h +3 -2
@@ -20,8 +20,9 @@#ifndef GRUB_SETJMP_CPU_HEADER #define GRUB_SETJMP_CPU_HEADER 1 -/* FIXME (sparc64). */ -typedef unsigned long grub_jmp_buf [20 ]; +#include <grub/types.h> + +typedef grub_uint64_t grub_jmp_buf [10 ];int grub_setjmp (grub_jmp_buf env);void grub_longjmp (grub_jmp_buf env,int val) __attribute__ ((noreturn));
Index: kern/sparc64/dl.c
===================================================================
RCS file: /sources/grub/grub2/kern/sparc64/dl.c,v
retrieving revision 1.2
sparc64/dl.c +27 -10
@@ -96,40 +96,57 @@ grub_arch_dl_relocate_symbols (grub_dl_t + entsize * ELF64_R_SYM (rel->r_info)); value = sym->st_value + rel->r_addend; -switch (ELF64_R_TYPE (rel->r_info)) +switch (ELF64_R_TYPE_ID (ELF64_R_TYPE (rel->r_info))) {case R_SPARC_32 :/* 3 V-word32 */ if (value &0xFFFFFFFF00000000 )return grub_error (GRUB_ERR_BAD_MODULE ,"Address out of 32 bits range" ); - *addr = value; + *addr = (grub_uint32_t) (value &0xFFFFFFFF );break ;case R_SPARC_WDISP30 :/* 7 V-disp30 */ -if (((value - (Elf64_Addr ) addr) &0xFFFFFFFF00000000 ) && - ((value - (Elf64_Addr ) addr) &0xFFFFFFFF00000000 - !=0xFFFFFFFF00000000 )) +if ((value - (Elf64_Addr ) addr) &0x3 )return grub_error (GRUB_ERR_BAD_MODULE , -"Displacement out of 30 bits range" ); +"30 bits displacement is not 4-bytes alligned" ); *addr = (*addr &0xC0000000 ) | (((grub_int32_t) ((value - (Elf64_Addr ) addr) >>2 )) &0x3FFFFFFF );break ;case R_SPARC_HI22 :/* 9 V-imm22 */ -if (((grub_int32_t ) value) &0xFF00000000 ) +if (value &0xFFFFFFFF00000000 )return grub_error (GRUB_ERR_BAD_MODULE ,"High address out of 22 bits range" ); - *addr = (*addr &0xFFC00000 ) | ((value >>10 ) &0x3FFFFF ); + *addr = ((*addr) &0xFFC00000 ) | + ((((grub_uint32_t ) value) >>10 ) &0x3FFFFF ); +break ; +case R_SPARC_13 :/* 11 V-simm13 */ +if (value &0xFFFFFFFFFFFFE000 ) +return grub_error (GRUB_ERR_BAD_MODULE , +"Address out of 13 bits range" ); + *addr = ((*addr) &0xFFFFE000 ) | + (((grub_uint32_t ) value) &0x1FFF );break ;case R_SPARC_LO10 :/* 12 T-simm13 */ - *addr = (*addr &0xFFFFFC00 ) | (value &0x3FF ); + *addr = ((*addr) &0xFFFFFC00 ) | + (((grub_uint32_t ) value) &0x3FF );break ;case R_SPARC_64 :/* 32 V-xwords64 */ *(Elf64_Xword *) addr = value;break ; +case R_SPARC_OLO10 :/* 33 V-simm13 */ + { +grub_uint32_t delta = ((grub_uint32_t ) value &0x3FF ) + +ELF64_R_TYPE_DATA (ELF64_R_TYPE (rel->r_info)); +if (delta &0xFFFFE000 ) +return grub_error (GRUB_ERR_BAD_MODULE , +"Address out of 13 bits range" ); + *addr = ((*addr) &0xFFFFFE000 ) | delta; +break ; + }default :return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET ,"This relocation (%d) is not implemented yet" , -ELF64_R_TYPE (rel->r_info)); +ELF64_R_TYPE_ID (ELF64_R_TYPE (rel->r_info))); } } }
Index: kern/sparc64/ieee1275/init.c
===================================================================
RCS file: /sources/grub/grub2/kern/sparc64/ieee1275/init.c,v retrieving revision 1.2
sparc64/ieee1275/init.c +29 -1
@@ -140,6 +140,34 @@ grub_machine_set_prefix (void)grub_free (prefix); } +/* Claim some available memory in the first /memory node. */ +static void grub_claim_heap (unsigned long heaplimit) +{ + autoint heap_init (grub_uint64_t addr,grub_uint64_t len); +int heap_init (grub_uint64_t addr,grub_uint64_t len) + { + len -=1 ;/* Required for some firmware. */ + +/* Don't claim anything above `heaplimit'. */ +if (addr + len > heaplimit) + len = heaplimit - addr; + +if (len) + { +/* Claim and use it. */ +if (grub_claimmap (addr, len) <0 ) +return grub_error (GRUB_ERR_OUT_OF_MEMORY , +"Failed to claim heap at 0x%llx, len 0x%llx\n" , + addr, len); +grub_mm_init_region ((void *) (grub_addr_t ) addr, len); + } + +return 0 ; + } + +grub_available_iterate (heap_init); +} +void grub_machine_init (void ) {
@@ -208,7 +236,7 @@ grub_machine_fini (void)void grub_exit (void ) { -grub_ieee1275_enter (); +grub_ieee1275_exit (); } grub_uint32_t
Index: kern/sparc64/ieee1275/openfw.c
===================================================================
RCS file: /sources/grub/grub2/kern/sparc64/ieee1275/openfw.c,v retrieving revision 1.1
sparc64/ieee1275/openfw.c +48 -3
69 lines not on this page · raw message
Index: normal/main.c
===================================================================
RCS file: /sources/grub/grub2/normal/main.c,v
retrieving revision 1.19
main.c +1 -1
@@ -30,7 +30,7 @@#include <grub/parser.h> #include <grub/script.h> -grub_jmp_buf grub_exit_env; +grub_jmp_buf grub_exit_env __attribute__ ((__aligned__(8)));static grub_fs_module_list_t fs_module_list =0 ;
Index: normal/sparc64/setjmp.S
===================================================================
RCS file: /sources/grub/grub2/normal/sparc64/setjmp.S,v retrieving revision 1.1
sparc64/setjmp.S +47 -4
60 lines not on this page · raw message
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2004 Free Software Foundation, Inc. *
* This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef GRUB_LOADER_MACHINE_HEADER
#define GRUB_LOADER_MACHINE_HEADER 1
/* The symbol shared between the normal mode and rescue mode
loader. */
void grub_rescue_cmd_linux (int argc, char *argv[]); void grub_rescue_cmd_initrd (int argc, char *argv[]);
void grub_linux_init (void);
void grub_linux_fini (void);
void grub_linux_normal_init (void);
void grub_linux_normal_fini (void);
#endif /* ! GRUB_LOADER_MACHINE_HEADER */
Quoted 5 lines · Vincent Pelletier
Hi.
Here is a (mostly) maintainance patch for sparc64 port.
It only fixes the build and implements setjmp/longjmp so that one can jump to rescue mode.
It looks like you also introduce new ELF relocations, I guess because you've stumbled across modload errors?
Quoted 2 lines
I prefer to post the patch for validation before commiting, it's been too long I haven't post to go on my own :) . (changelog is in the diff :p ).
Could you remove the commented-out code in setjmp.S please?
Also, it doesn't look like you're actually calling grub_claim_heap(). In that case, why add it to kern/sparc64/ieee1275/init.c ?
Quoted 1 line
+typedef
grub_uint64_tgrub_jmp_buf[10];
...
main.c line 33
Quoted 2 lines
main.c +1
-1-grub_jmp_buf grub_exit_env; +grub_jmp_buf grub_exit_env __attribute__ ((__aligned__(8)));
grub_jmp_buf should already be 8-byte aligned (because grub_uint64_t is, right?), so you should leave grub_exit_env alone.
-Hollis