The arm architecture is going to allow the user to specify the size and address of various memory regions. Let's make the function to parse size@addr options globally visible, because we will be using it. Signed-off-by: Alexandru Elisei <alexandru.elisei@xxxxxxx> --- builtin-run.c | 29 ++++++++++++++++++----------- include/kvm/kvm.h | 2 ++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/builtin-run.c b/builtin-run.c index 757ede4ac0d1..70ece3754644 100644 --- a/builtin-run.c +++ b/builtin-run.c @@ -131,37 +131,44 @@ static u64 parse_addr(char **next) return ((u64)1) << shift; } -static int mem_parser(const struct option *opt, const char *arg, int unset) +void kvm__parse_size_addr_option(const char *p, u64 *size, u64 *addr) { - struct kvm_config *cfg = opt->value; - const char *p = arg; char *next; - u64 size, addr = INVALID_MEM_ADDR; + + *addr = INVALID_MEM_ADDR; /* Parse memory size. */ - size = strtoll(p, &next, 0); + *size = strtoll(p, &next, 0); if (next == p) die("Invalid memory size"); - size *= parse_size(&next); + *size *= parse_size(&next); if (*next == '\0') - goto out; + return; else p = next + 1; - addr = strtoll(p, &next, 0); + *addr = strtoll(p, &next, 0); if (next == p) die("Invalid memory address"); + *addr *= parse_addr(&next); +} + +static int mem_parser(const struct option *opt, const char *arg, int unset) +{ + struct kvm_config *cfg = opt->value; + const char *p = arg; + u64 size, addr; + + kvm__parse_size_addr_option(p, &size, &addr); + #ifndef ARCH_SUPPORT_CFG_RAM_BASE if (addr != INVALID_MEM_ADDR) die("Specifying the memory address not supported by the architecture"); #endif - addr *= parse_addr(&next); - -out: cfg->ram_base = addr; cfg->ram_size = size; diff --git a/include/kvm/kvm.h b/include/kvm/kvm.h index 8787a92b4dbb..a93e30d1a320 100644 --- a/include/kvm/kvm.h +++ b/include/kvm/kvm.h @@ -192,4 +192,6 @@ static inline void kvm__set_thread_name(const char *name) prctl(PR_SET_NAME, name); } +void kvm__parse_size_addr_option(const char *p, u64 *size, u64 *addr); + #endif /* KVM__KVM_H */ -- 2.7.4