On 11/07/2016 15:50, Andrew Jones wrote: > On Mon, Jul 11, 2016 at 03:05:38PM +0200, Paolo Bonzini wrote: >> What about this slightly simpler Makefilery? I'll test ARM shortly, help >> with PPC will be gladly accepted. :) > > If it works, it works for me :-) > > I guess we don't need the x86/Makefile.common hunk though, as seabios > gets you argv[0]=prognam already. Right, I left that in only for testing. :) x86 is the reason why I'm making the symbol common in auxinfo.h. Paolo > nit: I'ed like to either add an 'e' to .prognam or remove the 'E' from > PROGNAME. > > Thanks, > drew > >> >> Paolo >> >> diff --git a/arm/Makefile.common b/arm/Makefile.common >> index a786fcf..be99a4a 100644 >> --- a/arm/Makefile.common >> +++ b/arm/Makefile.common >> @@ -54,7 +54,7 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi) >> %.elf: %.o $(FLATLIBS) arm/flat.lds $(cstart.o) >> $(CC) $(LDFLAGS) -o $@ \ >> -Wl,-T,arm/flat.lds,--build-id=none,-Ttext=$(start_addr) \ >> - $(filter %.o, $^) $(FLATLIBS) >> + $(filter %.o, $^) $(FLATLIBS) lib/auxinfo.c -DPROGNAME=\"$(*F)\" >> >> %.flat: %.elf >> $(OBJCOPY) -O binary $^ $@ >> diff --git a/lib/argv.c b/lib/argv.c >> index 4f6b4f0..f61992c 100644 >> --- a/lib/argv.c >> +++ b/lib/argv.c >> @@ -1,10 +1,13 @@ >> #include "libcflat.h" >> +#include "auxinfo.h" >> >> int __argc; >> char *__argv[100]; >> char *__args; >> char __args_copy[1000]; >> >> +static char *copy_ptr = __args_copy; >> + >> static bool isblank(char p) >> { >> return p == ' ' || p == '\t'; >> @@ -21,13 +24,12 @@ void __setup_args(void) >> { >> char *args = __args; >> char **argv = __argv; >> - char *p = __args_copy; >> >> while (*(args = skip_blanks(args)) != '\0') { >> - *argv++ = p; >> + *argv++ = copy_ptr; >> while (*args != '\0' && !isblank(*args)) >> - *p++ = *args++; >> - *p++ = '\0'; >> + *copy_ptr++ = *args++; >> + *copy_ptr++ = '\0'; >> } >> __argc = argv - __argv; >> } >> @@ -52,6 +54,8 @@ void setup_args_prognam(char *args) >> for (i = __argc; i > 0; --i) >> __argv[i] = __argv[i-1]; >> } >> - __argv[0] = NULL; // just reserve for now >> + __argv[0] = copy_ptr; >> + strcpy(__argv[0], auxinfo.prognam); >> + copy_ptr += strlen(auxinfo.prognam) + 1; >> ++__argc; >> } >> diff --git a/lib/auxinfo.c b/lib/auxinfo.c >> new file mode 100644 >> index 0000000..bffeac2 >> --- /dev/null >> +++ b/lib/auxinfo.c >> @@ -0,0 +1,2 @@ >> +#include "auxinfo.h" >> +struct auxinfo auxinfo = { PROGNAME }; >> diff --git a/lib/auxinfo.h b/lib/auxinfo.h >> new file mode 100644 >> index 0000000..18510ba >> --- /dev/null >> +++ b/lib/auxinfo.h >> @@ -0,0 +1,9 @@ >> +#ifndef _AUXINFO_H_ >> +#define _AUXINFO_H_ >> +struct auxinfo { >> + const char *prognam; >> +}; >> + >> +/* No extern! Define a common symbol. */ >> +struct auxinfo auxinfo; >> +#endif >> diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common >> index 4ff1dc8..bbad9c7 100644 >> --- a/powerpc/Makefile.common >> +++ b/powerpc/Makefile.common >> @@ -41,9 +41,10 @@ FLATLIBS = $(libcflat) $(LIBFDT_archive) >> %.elf: CFLAGS += $(arch_CFLAGS) >> %.elf: LDFLAGS = $(arch_LDFLAGS) -nostdlib -pie >> %.elf: %.o $(FLATLIBS) powerpc/flat.lds $(cstart.o) $(reloc.o) >> - $(LD) $(LDFLAGS) -o $@ \ >> - -T powerpc/flat.lds --build-id=none \ >> - $(filter %.o, $^) $(FLATLIBS) >> + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ \ >> + -Wl,-T,powerpc/flat.lds -Wl,--build-id=none \ >> + $(filter %.o, $^) $(FLATLIBS) \ >> + lib/auxinfo.c -DPROGNAME=\"$*\" >> @echo -n Checking $@ for unsupported reloc types... >> @if $(OBJDUMP) -R $@ | grep R_ | grep -v R_PPC64_RELATIVE; then \ >> false; \ >> diff --git a/x86/Makefile.common b/x86/Makefile.common >> index 356d879..67fb65b 100644 >> --- a/x86/Makefile.common >> +++ b/x86/Makefile.common >> @@ -31,7 +31,7 @@ libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name) >> FLATLIBS = lib/libcflat.a $(libgcc) >> %.elf: %.o $(FLATLIBS) x86/flat.lds $(cstart.o) >> $(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,x86/flat.lds \ >> - $(filter %.o, $^) $(FLATLIBS) >> + $(filter %.o, $^) $(FLATLIBS) lib/auxinfo.c -DPROGNAME=\"$(*F)\" >> >> %.flat: %.elf >> $(OBJCOPY) -O elf32-i386 $^ $@ >> -- >> To unsubscribe from this list: send the line "unsubscribe kvm" in >> the body of a message to majordomo@xxxxxxxxxxxxxxx >> More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html