Give x86 unit tests access to environment variables. The environment variables are passed to the unit test with '-initrd env-file'. Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx> --- x86/run | 4 +++- lib/x86/setup.c | 16 ++++++++++++++++ x86/cstart.S | 2 ++ x86/cstart64.S | 2 ++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/x86/run b/x86/run index 10a6e6d3421c..867a1cccd3ba 100755 --- a/x86/run +++ b/x86/run @@ -42,7 +42,9 @@ else pc_testdev="-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out" fi -command="${qemu} -nodefaults -enable-kvm $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev -kernel" +command="${qemu} -nodefaults -enable-kvm $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev" +[ -f "$ENV" ] && command+=" -initrd $ENV" +command+=" -kernel" command="$(timeout_cmd) $command" echo ${command} "$@" diff --git a/lib/x86/setup.c b/lib/x86/setup.c index e5df6ce95b64..804ba3a1b86e 100644 --- a/lib/x86/setup.c +++ b/lib/x86/setup.c @@ -12,9 +12,15 @@ #define MB_MOD_START 0 #define MB_MOD_END 4 +#define ENV_SIZE 16384 + +extern void setup_env(char *env, int size); + char *initrd; u32 initrd_size; +static char env[ENV_SIZE]; + void setup_get_initrd(u8 *bootinfo) { u32 *mods_addr, *mod_start, *mod_end; @@ -29,3 +35,13 @@ void setup_get_initrd(u8 *bootinfo) initrd = (char *)(ulong)*mod_start; initrd_size = *mod_end - *mod_start; } + +void setup_environ(void) +{ + if (initrd) { + /* environ is currently the only file in the initrd */ + u32 size = MIN(initrd_size, ENV_SIZE); + memcpy(env, initrd, size); + setup_env(env, size); + } +} diff --git a/x86/cstart.S b/x86/cstart.S index 7ab99cd20b7f..69b5c332cbcc 100644 --- a/x86/cstart.S +++ b/x86/cstart.S @@ -96,6 +96,7 @@ MSR_GS_BASE = 0xc0000101 start: push %ebx call setup_get_initrd + call setup_environ mov mb_cmdline(%ebx), %eax mov %eax, __args call __setup_args @@ -149,6 +150,7 @@ start32: call enable_apic call smp_init call enable_x2apic + push $__environ push $__argv push __argc call main diff --git a/x86/cstart64.S b/x86/cstart64.S index 1c5182043703..004c014b5ba2 100644 --- a/x86/cstart64.S +++ b/x86/cstart64.S @@ -200,11 +200,13 @@ start64: mov mb_boot_info(%rip), %rbx mov %rbx, %rdi call setup_get_initrd + call setup_environ mov mb_cmdline(%rbx), %eax mov %rax, __args(%rip) call __setup_args mov __argc(%rip), %edi lea __argv(%rip), %rsi + lea __environ(%rip), %rdx call main mov %eax, %edi call exit -- 2.9.3 -- 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