qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vince Weaver <vince@csl.cornell.edu>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] linux-user exception handling
Date: Wed, 27 Aug 2008 12:58:07 -0400 (EDT)	[thread overview]
Message-ID: <20080827125223.H53558@stanley.csl.cornell.edu> (raw)
In-Reply-To: <f43fc5580808251334u2127c88fv18465b4d0ba263be@mail.gmail.com>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1386 bytes --]

On Mon, 25 Aug 2008, Blue Swirl wrote:
>
> No, register window handling and other exceptions are handled in
> linux-user/main.c.

You are right.  It can be frustrating tracing through the code trying to 
find out what is being called when.

In any case, I think I've found a bug with register-window handling.
When using sparc32plus, the "wim" value isn't being updated on a 
save_window() call.  Thus when later a "ta 3" (flush register windows) 
call happens, the wrong windows get written out to memory.

I've attached some sample code that shows this problem.

The patch below fixes this for me, but it should be looked over carefully 
because the register window code in qemu is deep magic.

This fix allows the spec2k gcc.scilab and fma3d benchmarks to progress 
further.

Vince

--- linux-user/main.c.orig	2008-08-27 12:48:52.000000000 -0400
+++ linux-user/main.c	2008-08-27 12:49:41.000000000 -0400
@@ -793,14 +793,12 @@

  static void save_window(CPUSPARCState *env)
  {
-#ifndef TARGET_SPARC64
      unsigned int new_wim;
      new_wim = ((env->wim >> 1) | (env->wim << (env->nwindows - 1))) &
          ((1LL << env->nwindows) - 1);
      save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
      env->wim = new_wim;
-#else
-    save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
+#if defined(TARGET_SPARC64)
      env->cansave++;
      env->canrestore--;
  #endif

[-- Attachment #2: Type: TEXT/PLAIN, Size: 3581 bytes --]

!     + Syscalls have number in %g1, options in %o0,%o1,...
!	Result returned in %o0
!	Linux syscall is called by "ta 0x10"

.equ SYSCALL_EXIT,1	
.equ SYSCALL_WRITE,4

.equ STDOUT,1

	.globl _start
_start:
	nop
	
label:
	set	0x41410a00,%l0
	set	out_string,%o1
	st	%l0,[%o1]
	call	write_stdout		! AA
	nop
	
	save	%sp,-96,%sp

	set	0x42420a00,%l0
	set	out_string,%o1
	st	%l0,[%o1]
	call	write_stdout		! BB
	nop

	save	%sp,-96,%sp

	set	0x43430a00,%l0
	set	out_string,%o1
	st	%l0,[%o1]
	call	write_stdout		! CC
	nop
	
	save	%sp,-96,%sp

	set	0x44440a00,%l0
	set	out_string,%o1
	st	%l0,[%o1]
	call	write_stdout		! DD
	nop

	save	%sp,-96,%sp

	set	0x45450a00,%l0
	set	out_string,%o1
	st	%l0,[%o1]
	call	write_stdout		! EE
	nop
	
	save	%sp,-96,%sp

	set	0x46460a00,%l0
	set	out_string,%o1
	st	%l0,[%o1]
	call	write_stdout		! FF
	nop
	
	save	%sp,-96,%sp

	set	0x47470a00,%l0
	set	out_string,%o1
	st	%l0,[%o1]
	call	write_stdout		! GG
	nop
	
	save	%sp,-96,%sp

	set	0x48480a00,%l0
	set	out_string,%o1
	st	%l0,[%o1]
	call	write_stdout		! HH
	nop
	
	save	%sp,-96,%sp

	set	0x49490a00,%l0
	set	out_string,%o1
	st	%l0,[%o1]
	call	write_stdout		! II
	nop
	
	save	%sp,-96,%sp

	set	0x4a4a0a00,%l0
	set	out_string,%o1
	st	%l0,[%o1]
	call	write_stdout		! JJ
	nop

	save	%sp,-96,%sp

	set	0x4b4b0a00,%l0
	set	out_string,%o1
	st	%l0,[%o1]
	call	write_stdout		! KK
	nop

	save	%sp,-96,%sp

	set	0x4c4c0a00,%l0
	set	out_string,%o1
	st	%l0,[%o1]
	call	write_stdout		! LL
	nop

	save	%sp,-96,%sp

	set	0x4d4d0a00,%l0
	set	out_string,%o1
	st	%l0,[%o1]
	call	write_stdout		! MM
	nop	
	
!	flushw sparc9 only

	

	restore

	set	out_string,%o1	
	st	%l0,[%o1]
	call	write_stdout		! LL
	nop

	restore

	set	out_string,%o1	
	st	%l0,[%o1]
	call	write_stdout		! KK
	nop

	restore

	set	out_string,%o1	
	st	%l0,[%o1]
	call	write_stdout		! JJ
	nop

	restore

	set	out_string,%o1	
	st	%l0,[%o1]
	call	write_stdout		! II
	nop
	
	ta 3
	
	restore

	set	out_string,%o1		
	st	%l0,[%o1]
	call	write_stdout
	nop	
	
	restore
	
	set	out_string,%o1	
	st	%l0,[%o1]
	call	write_stdout
	nop	

	restore

	set	out_string,%o1		
	st	%l0,[%o1]	
	call	write_stdout
	nop	
	
	restore

	set	out_string,%o1		
	st	%l0,[%o1]
	call	write_stdout
	nop	
	
	restore

	set	out_string,%o1		
	st	%l0,[%o1]
	call	write_stdout
	nop	

	restore

	set	out_string,%o1		
	st	%l0,[%o1]
	call	write_stdout
	nop	

	restore

	set	out_string,%o1		
	st	%l0,[%o1]
	call	write_stdout
	nop	
	
	restore

	set	out_string,%o1		
	st	%l0,[%o1]
	call	write_stdout
	nop		

	nop
	nop
	nop
	
exit:		
        mov	0,%o0			! exit value
        mov	SYSCALL_EXIT,%g1        ! put the exit syscall number in g1
        ta      0x10			! and exit
	
	#================================
	# WRITE_STDOUT
	#================================
	# %o1 has string

write_stdout:

	set	SYSCALL_WRITE,%g1	! Write syscall in %g1
	set	STDOUT,%o0		! 1 in %o0 (stdout)
	set	0,%o2			! 0 (count) in %o2

str_loop1:
	ldub	[%o1+%o2],%l1		! load byte
	cmp	%l1,%g0			! compare against zero
	bnz	str_loop1		! if not nul, repeat
	# BRANCH DELAY SLOT
	inc	%o2			! increment count

	dec	%o2			! correct count	
	ta	0x10			! run the syscall

	retl
	nop




!===========================================================================
.data
!===========================================================================

data_region:		.int -1,-1
out_string:		.int 0

[-- Attachment #3: Type: APPLICATION/octet-stream, Size: 1563 bytes --]

  reply	other threads:[~2008-08-27 16:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-25 20:26 [Qemu-devel] linux-user exception handling Vince Weaver
2008-08-25 20:34 ` Blue Swirl
2008-08-27 16:58   ` Vince Weaver [this message]
2008-08-27 17:14     ` Blue Swirl
2008-08-27 17:30       ` Vince Weaver
2008-08-27 18:19         ` Blue Swirl
2008-08-27 19:02           ` Vince Weaver
2008-08-27 19:26             ` Blue Swirl

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=20080827125223.H53558@stanley.csl.cornell.edu \
    --to=vince@csl.cornell.edu \
    --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).