All of lore.kernel.org
 help / color / mirror / Atom feed
From: Danny Milosavljevic <danny.milo@datacom.wien>
To: qemu-devel@nongnu.org, rminnich@google.com
Cc: Danny Milosavljevic <danny.milo@datacom.wien>
Subject: [PATCH 1/1] i386: Add support for AMD new-style boot mechanism.
Date: Mon,  1 Mar 2021 17:14:32 +0100	[thread overview]
Message-ID: <20210301161432.22554-2-danny.milo@datacom.wien> (raw)
In-Reply-To: <20210301161432.22554-1-danny.milo@datacom.wien>

This introduces a new generic-loader setting "csbaseaddr" that
allows you to set the segment base address of CS.

Signed-off-by: Danny Milosavljevic <danny.milo@datacom.wien>
---
 hw/core/generic-loader.c         |  5 ++++-
 include/hw/core/cpu.h            |  1 +
 include/hw/core/generic-loader.h |  1 +
 target/i386/cpu.c                | 11 +++++++++++
 4 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
index 2b2a7b5e9a..a151dcdd89 100644
--- a/hw/core/generic-loader.c
+++ b/hw/core/generic-loader.c
@@ -53,6 +53,8 @@ static void generic_loader_reset(void *opaque)
         cpu_reset(s->cpu);
         if (cc) {
             cc->set_pc(s->cpu, s->addr);
+            if (cc->set_csbase)
+                cc->set_csbase(s->cpu, s->csbaseaddr);
         }
     }
 
@@ -103,7 +105,7 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
         if (s->cpu_num != CPU_NONE) {
             s->set_pc = true;
         }
-    } else if (s->addr) {
+    } else if (s->addr || s->csbaseaddr) {
         /* User is setting the PC */
         if (s->data || s->data_len || s->data_be) {
             error_setg(errp, "data can not be specified when setting a "
@@ -180,6 +182,7 @@ static void generic_loader_unrealize(DeviceState *dev)
 }
 
 static Property generic_loader_props[] = {
+    DEFINE_PROP_UINT64("csbaseaddr", GenericLoaderState, csbaseaddr, 0xffff0000),
     DEFINE_PROP_UINT64("addr", GenericLoaderState, addr, 0),
     DEFINE_PROP_UINT64("data", GenericLoaderState, data, 0),
     DEFINE_PROP_UINT8("data-len", GenericLoaderState, data_len, 0),
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index c005d3dc2d..9998b6b986 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -161,6 +161,7 @@ struct CPUClass {
     void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
                                Error **errp);
     void (*set_pc)(CPUState *cpu, vaddr value);
+    void (*set_csbase)(CPUState *cpu, vaddr value);
     hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
     hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr,
                                         MemTxAttrs *attrs);
diff --git a/include/hw/core/generic-loader.h b/include/hw/core/generic-loader.h
index 19d87b39c8..b407d8e8e9 100644
--- a/include/hw/core/generic-loader.h
+++ b/include/hw/core/generic-loader.h
@@ -29,6 +29,7 @@ struct GenericLoaderState {
     /* <public> */
     CPUState *cpu;
 
+    uint64_t csbaseaddr;
     uint64_t addr;
     uint64_t data;
     uint8_t data_len;
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 6a53446e6a..7cb4634e18 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -7171,6 +7171,16 @@ static void x86_cpu_set_pc(CPUState *cs, vaddr value)
     cpu->env.eip = value;
 }
 
+static void x86_cpu_set_csbase(CPUState *cs, vaddr value)
+{
+    X86CPU *cpu = X86_CPU(cs);
+    CPUX86State *env = &cpu->env;
+
+    cpu_x86_load_seg_cache(env, R_CS, 0xf000, value, 0xffff,
+                            DESC_P_MASK | DESC_S_MASK | DESC_CS_MASK |
+                            DESC_R_MASK | DESC_A_MASK);
+}
+
 int x86_cpu_pending_interrupt(CPUState *cs, int interrupt_request)
 {
     X86CPU *cpu = X86_CPU(cs);
@@ -7412,6 +7422,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
 
     cc->dump_state = x86_cpu_dump_state;
     cc->set_pc = x86_cpu_set_pc;
+    cc->set_csbase = x86_cpu_set_csbase;
     cc->gdb_read_register = x86_cpu_gdb_read_register;
     cc->gdb_write_register = x86_cpu_gdb_write_register;
     cc->get_arch_id = x86_cpu_get_arch_id;
-- 
2.29.2



  reply	other threads:[~2021-03-01 17:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-01 16:14 [PATCH 0/1] Add support for AMD new-style boot mechanism Danny Milosavljevic
2021-03-01 16:14 ` Danny Milosavljevic [this message]
2021-03-01 17:12 ` no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210301161432.22554-2-danny.milo@datacom.wien \
    --to=danny.milo@datacom.wien \
    --cc=qemu-devel@nongnu.org \
    --cc=rminnich@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.