qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin O'Connor <kevin@koconnor.net>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: seabios <seabios@seabios.org>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] Boot failure with MS-Dos 6.22 (due to bad BIOS build?)
Date: Mon, 19 Mar 2012 22:17:32 -0400	[thread overview]
Message-ID: <20120320021732.GA28726@morn.localdomain> (raw)
In-Reply-To: <4F6790FD.6030500@siemens.com>

On Mon, Mar 19, 2012 at 09:03:09PM +0100, Jan Kiszka wrote:
> On 2012-03-19 01:29, Kevin O'Connor wrote:
> > On Mon, Feb 27, 2012 at 04:25:09PM +0100, Jan Kiszka wrote:
> >>> EAX=ffffffff EBX=ffffffff ECX=0000c934 EDX=00000068
> >>> ESI=00006801 EDI=00000000 EBP=0000002b ESP=0000fff5
> > 
> > I traced this down, and it appears to be a stack size issue.  It looks
> > like MSDOS calls "int 0x13" with 229 bytes of stack space during its
> > boot.  On my build gcc generates the handle_13() function with a
> > maximum of 140 bytes of stack space utilized (according to
> > tools/checkstack.py).  On your build, gcc created it with a maximum of
> > 216 bytes.  The entry functions use 42 bytes of stack space.  Add it
> > up and you can see that the additional stack space that gcc used
> > caused %esp to wrap and the stack was corrupted.
> > 
> > I'm not sure how to best work around this.  One way is to sprinkle
> > "noinline" keywords through disk.c.  (It seems like gcc got in trouble
> > on your build by inlining many functions into disk_13().)  Another way
> > would be to jump into the extra stack (the disk code already uses its
> > own stack) earlier in the handle_13 code.
> > 
> > Also, can you see what happens if you change "--param
> > large-stack-frame=4" to "--param large-stack-frame=0" in the build?
> 
> This makes no difference here, still 216 bytes.

I've noticed that if one takes a pointer to a variable on the stack,
gcc seems to do a poor job managing stack space.  I'm guessing the
patch below would fix the issue.  It's a bit ugly though.

-Kevin


diff --git a/src/disk.c b/src/disk.c
index 7a58af4..706b9f4 100644
--- a/src/disk.c
+++ b/src/disk.c
@@ -76,7 +76,7 @@ fillLCHS(struct drive_s *drive_g, u16 *nlc, u16 *nlh, u16 *nlspt)
 }
 
 // Perform read/write/verify using old-style chs accesses
-static void
+static void noinline
 basic_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
 {
     struct disk_op_s dop;
@@ -119,7 +119,7 @@ basic_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
 }
 
 // Perform read/write/verify using new-style "int13ext" accesses.
-static void
+static void noinline
 extended_access(struct bregs *regs, struct drive_s *drive_g, u16 command)
 {
     struct disk_op_s dop;
@@ -201,7 +201,7 @@ disk_1304(struct bregs *regs, struct drive_s *drive_g)
 }
 
 // format disk track
-static void
+static void noinline
 disk_1305(struct bregs *regs, struct drive_s *drive_g)
 {
     debug_stub(regs);
@@ -228,7 +228,7 @@ disk_1305(struct bregs *regs, struct drive_s *drive_g)
 }
 
 // read disk drive parameters
-static void
+static void noinline
 disk_1308(struct bregs *regs, struct drive_s *drive_g)
 {
     u16 ebda_seg = get_ebda_seg();
@@ -329,7 +329,7 @@ disk_1314(struct bregs *regs, struct drive_s *drive_g)
 }
 
 // read disk drive size
-static void
+static void noinline
 disk_1315(struct bregs *regs, struct drive_s *drive_g)
 {
     disk_ret(regs, DISK_RET_SUCCESS);
@@ -463,7 +463,7 @@ disk_1345(struct bregs *regs, struct drive_s *drive_g)
 }
 
 // IBM/MS eject media
-static void
+static void noinline
 disk_1346(struct bregs *regs, struct drive_s *drive_g)
 {
     if (regs->dl < EXTSTART_CD) {

      reply	other threads:[~2012-03-20  2:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-27  9:51 [Qemu-devel] Boot failure with MS-Dos 6.22 (due to bad BIOS build?) Daniel P. Berrange
2012-02-27 15:25 ` Jan Kiszka
2012-02-27 16:00   ` [Qemu-devel] [SeaBIOS] " Peter Stuge
2012-02-27 16:10     ` Jan Kiszka
2012-02-27 16:20       ` Peter Stuge
2012-02-29  8:45   ` [Qemu-devel] " Kevin O'Connor
2012-02-29  9:19     ` Daniel P. Berrange
2012-02-29  9:51       ` [Qemu-devel] [SeaBIOS] " Fred .
2012-03-19  0:29   ` [Qemu-devel] " Kevin O'Connor
2012-03-19 20:03     ` Jan Kiszka
2012-03-20  2:17       ` Kevin O'Connor [this message]

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=20120320021732.GA28726@morn.localdomain \
    --to=kevin@koconnor.net \
    --cc=jan.kiszka@siemens.com \
    --cc=qemu-devel@nongnu.org \
    --cc=seabios@seabios.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).