qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: blauwirbel@gmail.com, anthony@codemonkey.ws, avi@redhat.com,
	gleb@redhat.com
Subject: [Qemu-devel] [PATCH 2/2] pc: Fix RTC CMOS info on RAM for ram_size < 1MiB
Date: Tue, 14 Aug 2012 13:58:55 +0200	[thread overview]
Message-ID: <1344945535-2774-3-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1344945535-2774-1-git-send-email-armbru@redhat.com>

pc_cmos_init() always claims 640KiB base memory, and ram_size - 1MiB
extended memory.  The latter can underflow to "lots of extended
memory".  Fix both, and clean up some.

Note: SeaBIOS currently requires 1MiB of RAM, and doesn't check
whether it got enough.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/pc.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index e8bcfc0..1597fe6 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -337,32 +337,35 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
     /* various important CMOS locations needed by PC/Bochs bios */
 
     /* memory size */
-    val = 640; /* base memory in K */
+    /* base memory (first MiB) */
+    val = MIN(ram_size / 1024, 640);
     rtc_set_memory(s, 0x15, val);
     rtc_set_memory(s, 0x16, val >> 8);
-
-    val = (ram_size / 1024) - 1024;
+    /* extended memory (next 64MiB) */
+    if (ram_size > 1024 * 1024)
+        val = (ram_size - 1024 * 1024) / 1024;
+    else
+        val = 0;
     if (val > 65535)
         val = 65535;
     rtc_set_memory(s, 0x17, val);
     rtc_set_memory(s, 0x18, val >> 8);
     rtc_set_memory(s, 0x30, val);
     rtc_set_memory(s, 0x31, val >> 8);
-
-    if (above_4g_mem_size) {
-        rtc_set_memory(s, 0x5b, (unsigned int)above_4g_mem_size >> 16);
-        rtc_set_memory(s, 0x5c, (unsigned int)above_4g_mem_size >> 24);
-        rtc_set_memory(s, 0x5d, (uint64_t)above_4g_mem_size >> 32);
-    }
-
-    if (ram_size > (16 * 1024 * 1024))
-        val = (ram_size / 65536) - ((16 * 1024 * 1024) / 65536);
+    /* memory between 16MiB and 4GiB */
+    if (ram_size > 16 * 1024 * 1024)
+        val = (ram_size - 16 * 1024 * 1024) / 65536;
     else
         val = 0;
     if (val > 65535)
         val = 65535;
     rtc_set_memory(s, 0x34, val);
     rtc_set_memory(s, 0x35, val >> 8);
+    /* memory above 4GiB */
+    val = above_4g_mem_size / 65536;
+    rtc_set_memory(s, 0x5b, val);
+    rtc_set_memory(s, 0x5c, val >> 8);
+    rtc_set_memory(s, 0x5d, val >> 16);
 
     /* set the number of CPU */
     rtc_set_memory(s, 0x5f, smp_cpus - 1);
-- 
1.7.11.2

  parent reply	other threads:[~2012-08-14 11:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-14 11:58 [Qemu-devel] [PATCH 0/2] Fix two bugs related to ram_size Markus Armbruster
2012-08-14 11:58 ` [Qemu-devel] [PATCH 1/2] vl: Round argument of -m up to multiple of 8KiB Markus Armbruster
2012-08-14 12:42   ` Avi Kivity
2012-08-14 12:55     ` Markus Armbruster
2012-08-14 11:58 ` Markus Armbruster [this message]
2012-08-14 18:31   ` [Qemu-devel] [PATCH 2/2] pc: Fix RTC CMOS info on RAM for ram_size < 1MiB Blue Swirl
2012-08-15  8:23     ` Markus Armbruster

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=1344945535-2774-3-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=avi@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=gleb@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).