[Qemu-devel] Classic Mac OS

2007-05-21 Thread Markus Hitter


Hello all

Somewhere in the FAQs, the state of Classic Mac OS ist mentioned as  
"it is being worked on". Is this still true, is it possible to join  
the effort?



Markus

- - - - - - - - - - - - - - - - - - -
Dipl. Ing. Markus Hitter
http://www.jump-ing.de/








[Qemu-devel] Re: [PATCH] floppy support for guest-OS OS9/x86 (aka OS9000)

2007-05-21 Thread W. Tasin

Hi,

after re-reading some of your cvs-logs and checking again the data 
sheet, here my second version of fdc1.diff.
This version is IMHO cleaner/saver, because it wouldn't break the hack 
(fdc.c; rev. 1.14) in the SENSE INTERRUPT STATUS and it is more data 
sheet conforming.


Sorry about the first fdc1.diff-"noise".
Ciao

Walter

W. Tasin schrieb:

Hello *,

I tried to make OS9/x86 runnable on qemu; with an existing hd image it 
already worked, but w/o floppy support. To make this also available 
I'd a look at the sources and (after some time ...) I was able to 
solve 3 little problems.

- boot from floppy didn't work
- floppy support inside os9/x86 didn't work
- a second ide reset sequence didn't work correctly

So here my patches (against snapshot 
http://qemu-forum.ipi.fi/qemu-snapshots/qemu-snapshot-2007-05-18_05.tar.bz2) 



You can find a more detailed explanation on 
http://pc01-lsw.ee.fhm.edu/wiki/QEmu/OS9Patch


HTH
Ciao

Walter

PS: Please CC me on questions, 'cause I'm not subscribed to the list.



--
Walter Tasin, M.Sc.
Fakultät für Elektrotechnik und Informationstechnik
Fachhochschule München, Munich University of Applied Sciences


--- hw/fdc.cMon May 21 10:38:54 2007
+++ hw/fdc.cMon May 21 10:39:20 2007
@@ -377,6 +377,7 @@
 uint8_t dma_en;
 uint8_t cur_drv;
 uint8_t bootsel;
+uint8_t first_sense;
 /* Command FIFO */
 uint8_t fifo[FD_SECTOR_LEN];
 uint32_t data_pos;
@@ -597,6 +598,7 @@
 fdctrl->irq = irq;
 fdctrl->dma_chann = dma_chann;
 fdctrl->io_base = io_base;
+fdctrl->first_sense=0;
 fdctrl->config = 0x60; /* Implicit seek, polling & FIFO enabled */
 if (fdctrl->dma_chann != -1) {
 fdctrl->dma_en = 1;
@@ -655,7 +657,7 @@
return;
 }
 #endif
-if (~(fdctrl->state & FD_CTRL_INTR)) {
+if (!(fdctrl->state & FD_CTRL_INTR)) {
 qemu_set_irq(fdctrl->irq, 1);
 fdctrl->state |= FD_CTRL_INTR;
 }
@@ -672,6 +674,7 @@
 fdctrl_reset_irq(fdctrl);
 /* Initialise controller */
 fdctrl->cur_drv = 0;
+fdctrl->first_sense = 4;
 /* FIFO state */
 fdctrl->data_pos = 0;
 fdctrl->data_len = 0;
@@ -1384,6 +1387,7 @@
 FLOPPY_DPRINTF("SPECIFY command\n");
 /* 1 parameter cmd */
 fdctrl->data_len = 3;
+fdctrl->first_sense=0;
 goto enqueue;
 case 0x04:
 /* SENSE_DRIVE_STATUS */
@@ -1401,21 +1405,29 @@
 /* SENSE_INTERRUPT_STATUS */
 FLOPPY_DPRINTF("SENSE_INTERRUPT_STATUS command (%02x)\n",
fdctrl->int_status);
+uint8_t act_drv = fdctrl->cur_drv;
 /* No parameters cmd: returns status if no interrupt */
+if (fdctrl->first_sense > 0)
+act_drv=4-fdctrl->first_sense--;
+
 #if 0
 fdctrl->fifo[0] =
-fdctrl->int_status | (cur_drv->head << 2) | fdctrl->cur_drv;
+(fdctrl->state & FD_CTRL_INTR) ? 
+(fdctrl->int_status | (cur_drv->head << 2) | act_drv) : 0x80;
 #else
 /* XXX: int_status handling is broken for read/write
commands, so we do this hack. It should be suppressed
ASAP */
 fdctrl->fifo[0] =
-0x20 | (cur_drv->head << 2) | fdctrl->cur_drv;
+(fdctrl->state & FD_CTRL_INTR) ? 
+(0x20 | (cur_drv->head << 2) | act_drv) : 0x80 ;
 #endif
+
 fdctrl->fifo[1] = cur_drv->track;
-fdctrl_set_fifo(fdctrl, 2, 0);
-   fdctrl_reset_irq(fdctrl);
-   fdctrl->int_status = 0xC0;
+fdctrl_set_fifo(fdctrl, (fdctrl->fifo[0] != 0x80) ? 2 : 1, 0);
+
+fdctrl_reset_irq(fdctrl);
+fdctrl->int_status = 0xC0;
 return;
 case 0x0E:
 /* DUMPREG */



Re: [Qemu-devel] [PATCH, MIPS64] 64-bit addressing fixes

2007-05-21 Thread Blue Swirl

On 5/21/07, Aurelien Jarno <[EMAIL PROTECTED]> wrote:

dyngen currently does not support passing 64-bit values to PARAM1 and
PARAM2, they are limited to 32-bit. This patch creates a new op_set64
function to set a register with a 64-bit value, by passing high and low
word in PARAM1 and PARAM2. The same thing is done for the
op_save_btarget and op_save_pc instructions. Unfortunately it is not
possible to pass the value via T0, T1 or T2, and then move it to btarget
or pc, because those functions are used in save_cpu_state where T0, T1
or T2 may already be used.


I don't know MIPS, but perhaps you could try this trick used in Sparc:
static inline void gen_jmp_im(target_ulong pc)
{
#ifdef TARGET_SPARC64
   if (pc == (uint32_t)pc) {
   gen_op_jmp_im(pc);
   } else {
   gen_op_jmp_im64(pc >> 32, pc);
   }
#else
   gen_op_jmp_im(pc);
#endif
}




[Qemu-devel] [PATCH] mips64 gdb_stub

2007-05-21 Thread Jason Wessel


This patch allows gdb to debug a 64 bit kernel running on the mips64 target.

signed-off-by: Jason Wessel <[EMAIL PROTECTED]>

Jason.
---
 gdbstub.c |   80 +++---
 1 file changed, 40 insertions(+), 40 deletions(-)

Index: qemu/gdbstub.c
===
--- qemu.orig/gdbstub.c
+++ qemu/gdbstub.c
@@ -549,41 +549,41 @@ static int cpu_gdb_read_registers(CPUSta
 ptr = mem_buf;
 for (i = 0; i < 32; i++)
   {
-*(uint32_t *)ptr = tswapl(env->gpr[i]);
-ptr += 4;
+*(target_ulong *)ptr = tswapl(env->gpr[i]);
+ptr += sizeof(target_ulong);
   }
 
-*(uint32_t *)ptr = tswapl(env->CP0_Status);
-ptr += 4;
+*(target_ulong *)ptr = tswapl(env->CP0_Status);
+ptr += sizeof(target_ulong);
 
-*(uint32_t *)ptr = tswapl(env->LO);
-ptr += 4;
+*(target_ulong *)ptr = tswapl(env->LO);
+ptr += sizeof(target_ulong);
 
-*(uint32_t *)ptr = tswapl(env->HI);
-ptr += 4;
+*(target_ulong *)ptr = tswapl(env->HI);
+ptr += sizeof(target_ulong);
 
-*(uint32_t *)ptr = tswapl(env->CP0_BadVAddr);
-ptr += 4;
+*(target_ulong *)ptr = tswapl(env->CP0_BadVAddr);
+ptr += sizeof(target_ulong);
 
-*(uint32_t *)ptr = tswapl(env->CP0_Cause);
-ptr += 4;
+*(target_ulong *)ptr = tswapl(env->CP0_Cause);
+ptr += sizeof(target_ulong);
 
-*(uint32_t *)ptr = tswapl(env->PC);
-ptr += 4;
+*(target_ulong *)ptr = tswapl(env->PC);
+ptr += sizeof(target_ulong);
 
 if (env->CP0_Config1 & (1 << CP0C1_FP))
   {
 for (i = 0; i < 32; i++)
   {
-*(uint32_t *)ptr = tswapl(env->fpr[i].fs[FP_ENDIAN_IDX]);
-ptr += 4;
+*(target_ulong *)ptr = tswapl(env->fpr[i].fs[FP_ENDIAN_IDX]);
+ptr += sizeof(target_ulong);
   }
 
-*(uint32_t *)ptr = tswapl(env->fcr31);
-ptr += 4;
+*(target_ulong *)ptr = tswapl(env->fcr31);
+ptr += sizeof(target_ulong);
 
-*(uint32_t *)ptr = tswapl(env->fcr0);
-ptr += 4;
+*(target_ulong *)ptr = tswapl(env->fcr0);
+ptr += sizeof(target_ulong);
   }
 
 /* 32 FP registers, fsr, fir, fp.  Not yet implemented.  */
@@ -611,41 +611,41 @@ static void cpu_gdb_write_registers(CPUS
 ptr = mem_buf;
 for (i = 0; i < 32; i++)
   {
-env->gpr[i] = tswapl(*(uint32_t *)ptr);
-ptr += 4;
+env->gpr[i] = tswapl(*(target_ulong *)ptr);
+ptr += sizeof(target_ulong);
   }
 
-env->CP0_Status = tswapl(*(uint32_t *)ptr);
-ptr += 4;
+env->CP0_Status = tswapl(*(target_ulong *)ptr);
+ptr += sizeof(target_ulong);
 
-env->LO = tswapl(*(uint32_t *)ptr);
-ptr += 4;
+env->LO = tswapl(*(target_ulong *)ptr);
+ptr += sizeof(target_ulong);
 
-env->HI = tswapl(*(uint32_t *)ptr);
-ptr += 4;
+env->HI = tswapl(*(target_ulong *)ptr);
+ptr += sizeof(target_ulong);
 
-env->CP0_BadVAddr = tswapl(*(uint32_t *)ptr);
-ptr += 4;
+env->CP0_BadVAddr = tswapl(*(target_ulong *)ptr);
+ptr += sizeof(target_ulong);
 
-env->CP0_Cause = tswapl(*(uint32_t *)ptr);
-ptr += 4;
+env->CP0_Cause = tswapl(*(target_ulong *)ptr);
+ptr += sizeof(target_ulong);
 
-env->PC = tswapl(*(uint32_t *)ptr);
-ptr += 4;
+env->PC = tswapl(*(target_ulong *)ptr);
+ptr += sizeof(target_ulong);
 
 if (env->CP0_Config1 & (1 << CP0C1_FP))
   {
 for (i = 0; i < 32; i++)
   {
-env->fpr[i].fs[FP_ENDIAN_IDX] = tswapl(*(uint32_t *)ptr);
-ptr += 4;
+env->fpr[i].fs[FP_ENDIAN_IDX] = tswapl(*(target_ulong *)ptr);
+ptr += sizeof(target_ulong);
   }
 
-env->fcr31 = tswapl(*(uint32_t *)ptr) & 0x0183;
-ptr += 4;
+env->fcr31 = tswapl(*(target_ulong *)ptr) & 0x0183;
+ptr += sizeof(target_ulong);
 
-env->fcr0 = tswapl(*(uint32_t *)ptr);
-ptr += 4;
+env->fcr0 = tswapl(*(target_ulong *)ptr);
+ptr += sizeof(target_ulong);
 
 /* set rounding mode */
 RESTORE_ROUNDING_MODE;


Re: [Qemu-devel] Classic Mac OS

2007-05-21 Thread Ed Swierk
On Monday 21 May 2007 03:40:12 Markus Hitter wrote:
> Somewhere in the FAQs, the state of Classic Mac OS ist mentioned as
> "it is being worked on". Is this still true, is it possible to join
> the effort?

I'm not aware of anyone currently working on classic Mac OS support. PowerPC 
system emulation has been broken for a while--at least I haven't had any luck 
booting a recent Linux distribution with a 2.6 kernel--so even with the 
proper firmware support, getting classic Mac OS to boot might be difficult 
until it's fixed.

--Ed




[Qemu-devel] Re: [kvm-devel] qemu/kvm seems to take ALSA all for itself?

2007-05-21 Thread Avi Kivity

David Abrahams wrote:
When I have windows XP running under kvm, I get 

  [EMAIL PROTECTED]:/tmp$ aplay /usr/share/sounds/gaim/receive.wav 
  ALSA lib pcm_dmix.c:864:(snd_pcm_dmix_open) unable to open slave

  aplay: main:550: audio open error: Device or resource busy

As soon as I shut down my VM, though, it works perfectly.  Is this
expected behavior?
  


I think you have to set up a mixer or something.  But I'd rather be deaf 
than have to wade through all the pseudo-documentation in order to find 
out how.


--
error compiling committee.c: too many arguments to function





[Qemu-devel] MIPS64 problem with ethernet

2007-05-21 Thread Jason Wessel


The ethernet device does not come up correctly on a 64 MIPS target with 
a 64 bit kernel.


I narrowed it down a bit, so I thought I might mention it.

If I add to the kernel the line:
   printk("\nTest ~0UL == %lx\n", (~0UL));

It will print correctly on the real HW:
Test ~0UL == 

In qemu-system-mips64 it will only print:
Test ~0UL ==

The ethernet fails due to the failure of the computing of the test 
kcalloc() found in slab.h.

if (n != 0 && size > ULONG_MAX / n)

Where n == 16,  size == 8, and ULONG_MAX == (~0UL).  I suspect some low 
level debugging of which op code translation is at fault would be next...


Jason.




Re: [Qemu-devel] MIPS64 problem with ethernet

2007-05-21 Thread Aurelien Jarno
Jason Wessel a écrit :
> The ethernet device does not come up correctly on a 64 MIPS target with 
> a 64 bit kernel.

Which Ethernet card are you using? The pcnet one is working correctly
here. I am using a 2.6.21.1 kernel.

-- 
  .''`.  Aurelien Jarno | GPG: 1024D/F1BCDB73
 : :' :  Debian developer   | Electrical Engineer
 `. `'   [EMAIL PROTECTED] | [EMAIL PROTECTED]
   `-people.debian.org/~aurel32 | www.aurel32.net




Re: [Qemu-devel] MIPS64 problem with ethernet

2007-05-21 Thread Jason Wessel

Aurelien Jarno wrote:

Jason Wessel a écrit :
  
The ethernet device does not come up correctly on a 64 MIPS target with 
a 64 bit kernel.



Which Ethernet card are you using? The pcnet one is working correctly
here. I am using a 2.6.21.1 kernel.

  
It works perfectly fine if I boot a 32bit kernel on the 64bit mips qemu 
with the pcnet32.  It is when I boot the 64bit kernel on the 64bit mips 
qemu that I see the issue.  The only difference I can see is the math 
operations in the kcalloc() inline because the sizes are different in 32 
vs 64 of course.  I too was using a 2.6.21.1 kernel with mips.org 
patches.  Likely that I am using a different compiler though.  Keeping 
in mind that the same kernel 32bit and 64bit kernels works fine on real 
hardware.


Jason.




[Qemu-devel] qemu/kvm seems to take ALSA all for itself?

2007-05-21 Thread David Abrahams

When I have windows XP running under kvm, I get 

  [EMAIL PROTECTED]:/tmp$ aplay /usr/share/sounds/gaim/receive.wav 
  ALSA lib pcm_dmix.c:864:(snd_pcm_dmix_open) unable to open slave
  aplay: main:550: audio open error: Device or resource busy

As soon as I shut down my VM, though, it works perfectly.  Is this
expected behavior?

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com





[Qemu-devel] qemu/target-arm op.c

2007-05-21 Thread Andrzej Zaborowski
CVSROOT:/sources/qemu
Module name:qemu
Changes by: Andrzej Zaborowski  07/05/21 17:48:02

Modified files:
target-arm : op.c 

Log message:
Don't touch carry flag in ASR  with zero , submitted by 
Aurelien Jarno.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemu/target-arm/op.c?cvsroot=qemu&r1=1.23&r2=1.24




[Qemu-devel] qemu/hw slavio_intctl.c

2007-05-21 Thread Blue Swirl
CVSROOT:/cvsroot/qemu
Module name:qemu
Changes by: Blue Swirl   07/05/21 18:08:36

Modified files:
hw : slavio_intctl.c 

Log message:
Fix interrupt controller address masking

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemu/hw/slavio_intctl.c?cvsroot=qemu&r1=1.12&r2=1.13




[Qemu-devel] PATCH, RFC: Sub-page I/O

2007-05-21 Thread Blue Swirl

Hi,

The attached patch (based on earlier work by J. Mayer) enables
assignment of multiple I/O devices and unassigned space in the same
page.

When devices register I/O locations, all accesses within the same page
are directed to the device, even outside the registered locations.
With the patch, the outside areas are unassigned space or whatever was
registered in the area.

The patch could be improved further to support multiple simultaneous
HW on same addresses or stacked registrations, but I leave that
exercise to the more interested reader.

Any comments? Would this break some architecture? Sparc32 tests work
as before, and I already found and fixed one bug.
Index: qemu/exec.c
===
--- qemu.orig/exec.c	2007-05-21 17:54:26.0 +
+++ qemu/exec.c	2007-05-21 18:11:35.0 +
@@ -48,6 +48,7 @@
 //#define DEBUG_TLB_CHECK 
 
 //#define DEBUG_IOPORT
+//#define DEBUG_SUBPAGE
 
 #if !defined(CONFIG_USER_ONLY)
 /* TB consistency checks only implemented for usermode emulation.  */
@@ -157,6 +158,14 @@
 static int tb_flush_count;
 static int tb_phys_invalidate_count;
 
+#define SUBPAGE_IDX(addr) ((addr) & ~TARGET_PAGE_MASK)
+typedef struct subpage_t {
+target_phys_addr_t base;
+CPUReadMemoryFunc **mem_read[TARGET_PAGE_SIZE];
+CPUWriteMemoryFunc **mem_write[TARGET_PAGE_SIZE];
+void *opaque[TARGET_PAGE_SIZE];
+} subpage_t;
+
 static void page_init(void)
 {
 /* NOTE: we can always suppose that qemu_host_page_size >=
@@ -1898,6 +1907,11 @@
 }
 #endif /* defined(CONFIG_USER_ONLY) */
 
+static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end,
+ int memory);
+static void *subpage_init (target_phys_addr_t base, uint32_t *phys,
+   int orig_memory);
+
 /* register physical memory. 'size' must be a multiple of the target
page size. If (phys_offset & ~TARGET_PAGE_MASK) != 0, then it is an
io memory page */
@@ -1908,15 +1922,81 @@
 target_phys_addr_t addr, end_addr;
 PhysPageDesc *p;
 CPUState *env;
+unsigned long orig_size = size;
+void *subpage;
 
 size = (size + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
 end_addr = start_addr + size;
 for(addr = start_addr; addr != end_addr; addr += TARGET_PAGE_SIZE) {
-p = phys_page_find_alloc(addr >> TARGET_PAGE_BITS, 1);
-p->phys_offset = phys_offset;
-if ((phys_offset & ~TARGET_PAGE_MASK) <= IO_MEM_ROM ||
-(phys_offset & IO_MEM_ROMD))
-phys_offset += TARGET_PAGE_SIZE;
+p = phys_page_find(addr >> TARGET_PAGE_BITS);
+if (p && p->phys_offset != IO_MEM_UNASSIGNED) {
+unsigned long orig_memory = p->phys_offset;
+target_phys_addr_t start_addr2, end_addr2;
+int need_subpage = 0;
+
+if (addr > start_addr)
+start_addr2 = 0;
+else {
+start_addr2 = start_addr & ~TARGET_PAGE_MASK;
+if (start_addr2 > 0)
+need_subpage = 1;
+}
+
+if (end_addr - addr > TARGET_PAGE_SIZE)
+end_addr2 = TARGET_PAGE_SIZE - 1;
+else {
+end_addr2 = start_addr + orig_size - addr;
+if (end_addr2 < TARGET_PAGE_SIZE - 1)
+need_subpage = 1;
+}
+
+if (need_subpage) {
+if (!(orig_memory & IO_MEM_SUBPAGE)) {
+subpage = subpage_init(addr, &p->phys_offset, orig_memory);
+} else {
+subpage = io_mem_opaque[(phys_offset & ~TARGET_PAGE_MASK) >> IO_MEM_SHIFT];
+}
+subpage_register(subpage, start_addr2, end_addr2, phys_offset);
+} else {
+p->phys_offset = phys_offset;
+if ((phys_offset & ~TARGET_PAGE_MASK) <= IO_MEM_ROM ||
+(phys_offset & IO_MEM_ROMD))
+phys_offset += TARGET_PAGE_SIZE;
+}
+} else {
+p = phys_page_find_alloc(addr >> TARGET_PAGE_BITS, 1);
+p->phys_offset = phys_offset;
+if ((phys_offset & ~TARGET_PAGE_MASK) <= IO_MEM_ROM ||
+(phys_offset & IO_MEM_ROMD))
+phys_offset += TARGET_PAGE_SIZE;
+else {
+target_phys_addr_t start_addr2, end_addr2;
+int need_subpage = 0;
+
+if (addr > start_addr)
+start_addr2 = 0;
+else {
+start_addr2 = start_addr & ~TARGET_PAGE_MASK;
+if (start_addr2 > 0)
+need_subpage = 1;
+}
+
+if (end_addr - addr > TARGET_PAGE_SIZE)
+end_addr2 = TARGET_PAGE_SIZE - 1;
+else {
+end_addr2 = start_addr + orig_size - addr;
+if (end_addr2 < TARGET_PAGE_SIZE - 1)
+

[Qemu-devel] Using native libraries

2007-05-21 Thread Luke -Jr
I'm sure someone's probably had a similar idea before, and it's probably not 
practical for some reason I'm overlooking-- but is there a reason Qemu can't 
dynamically translate library calls to use the native libraries instead of 
requiring emulated libraries as well?




Re: [Qemu-devel] Using native libraries

2007-05-21 Thread Carlos A. M. dos Santos

On 5/21/07, Luke -Jr <[EMAIL PROTECTED]> wrote:

I'm sure someone's probably had a similar idea before, and it's probably not
practical for some reason I'm overlooking-- but is there a reason Qemu can't
dynamically translate library calls to use the native libraries instead of
requiring emulated libraries as well?


That would be a totally different class of emulation, much more
similar to the FreeBSD "linuxulator" than to what QEMU is intended to
do.

--
Carlos A. M. dos Santos




Re: [Qemu-devel] Using native libraries

2007-05-21 Thread H. Peter Anvin
Luke -Jr wrote:
> I'm sure someone's probably had a similar idea before, and it's probably not 
> practical for some reason I'm overlooking-- but is there a reason Qemu can't 
> dynamically translate library calls to use the native libraries instead of 
> requiring emulated libraries as well?

The easiest way to do that is by having an "RPC stub library" in the
emulated environment which contains nothing but trap instructions --
like system calls -- that can be intercepted on the other side.  At that
point, one has to do translation of data types and pointers (called
"thunking") before invoking the native library.  Generating such
"thunks" is usually done automatically, but it is still a fairly major
effort.

This kind of stuff is what underlies things like running PowerMac
applications on IntelMacs (or 68kmac apps on PowerMac).

-hpa




Re: [Qemu-devel] Using native libraries

2007-05-21 Thread Luke -Jr
On Monday 21 May 2007 16:13, H. Peter Anvin wrote:
> The easiest way to do that is by having an "RPC stub library" in the
> emulated environment which contains nothing but trap instructions --
> like system calls -- that can be intercepted on the other side.  At that
> point, one has to do translation of data types and pointers (called
> "thunking") before invoking the native library.  Generating such
> "thunks" is usually done automatically, but it is still a fairly major
> effort.

But can it be done at the JIT stage?




Re: [Qemu-devel] Classic Mac OS

2007-05-21 Thread C . W . Betts
Please join.  As it is, it would be easier to try to get Mac OS 8.5 and 
higher running, mainly because they work with Macs that don't have the 
Mac OS Toolbox in their ROM (i.e. it would be easy to get it to emulate 
New World ROMs than Old World ROMs; the latter would be harder due to 
legal reasons).


And any help in the area of Classic Mac emulation, or PPC emulation in 
general, would be helpful.

On Monday, May 21, 2007, at 04:40  AM, Markus Hitter wrote:



Hello all

Somewhere in the FAQs, the state of Classic Mac OS ist mentioned as 
"it is being worked on". Is this still true, is it possible to join 
the effort?



Markus

- - - - - - - - - - - - - - - - - - -
Dipl. Ing. Markus Hitter
http://www.jump-ing.de/








PGP.sig
Description: This is a digitally signed message part


[Qemu-devel] [PATCH][UPDATED] Fix path mangling in linux-user/path.c

2007-05-21 Thread Lauri Leukkunen

Attached patch fixes the linux-user path mangling code for use with
real target root filesystems that have nasty symlinks and lots of
files. The old code is terribly slow and can easily end up going
through the entire host system /usr hierarchy in a recursive loop.

Compared to the previous version of this patch, fixes an issue with
attempting to free() a pointer returned by GNU basename().

/lauri
Index: linux-user/path.c
===
RCS file: /sources/qemu/qemu/linux-user/path.c,v
retrieving revision 1.2
diff -u -r1.2 path.c
--- linux-user/path.c	13 Sep 2004 21:39:32 -	1.2
+++ linux-user/path.c	21 May 2007 23:06:54 -
@@ -3,145 +3,201 @@
 
The assumption is that this area does not change.
 */
+
+#define _GNU_SOURCE
+
 #include 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
+#include 
 #include "qemu.h"
 
-struct pathelem
-{
-/* Name of this, eg. lib */
-char *name;
-/* Full path name, eg. /usr/gnemul/x86-linux/lib. */
-char *pathname;
-struct pathelem *parent;
-/* Children */
-unsigned int num_entries;
-struct pathelem *entries[0];
-};
-
-static struct pathelem *base;
-
-/* First N chars of S1 match S2, and S2 is N chars long. */
-static int strneq(const char *s1, unsigned int n, const char *s2)
-{
-unsigned int i;
-
-for (i = 0; i < n; i++)
-	if (s1[i] != s2[i])
-	return 0;
-return s2[i] == 0;
-}
+char *base = NULL;
 
-static struct pathelem *add_entry(struct pathelem *root, const char *name);
+struct path_entry {
+struct path_entry *prev;
+struct path_entry *next;
+char name[PATH_MAX];
+};
 
-static struct pathelem *new_entry(const char *root,
-  struct pathelem *parent,
-  const char *name)
+char *decolonize_path(const char *path)
 {
-struct pathelem *new = malloc(sizeof(*new));
-new->name = strdup(name);
-asprintf(&new->pathname, "%s/%s", root, name);
-new->num_entries = 0;
-return new;
-}
-
-#define streq(a,b) (strcmp((a), (b)) == 0)
+char *cpath, *index, *start;
+char cwd[PATH_MAX];
+struct path_entry list;
+struct path_entry *work;
+struct path_entry *new;
+char *buf = NULL;
 
-static struct pathelem *add_dir_maybe(struct pathelem *path)
-{
-DIR *dir;
+if (!path) {
+return NULL;
+}
 
-if ((dir = opendir(path->pathname)) != NULL) {
-	struct dirent *dirent;
+buf = malloc((PATH_MAX + 1) * sizeof(char));
+memset(buf, '\0', PATH_MAX + 1);
 
-	while ((dirent = readdir(dir)) != NULL) {
-	if (!streq(dirent->d_name,".") && !streq(dirent->d_name,"..")){
-		path = add_entry(path, dirent->d_name);
-	}
-	}
-closedir(dir);
+list.next = NULL;
+list.prev = NULL;
+work = &list;
+
+if (path[0] != '/') {
+/* not an absolute path */
+memset(cwd, '\0', PATH_MAX);
+if (getcwd(cwd, PATH_MAX) < 0) {
+perror("error getting current work dir\n");
+return NULL;
+}
+unsigned int l = (strlen(cwd) + 1 + strlen(path) + 1);
+cpath = malloc((strlen(cwd) + 1
++ strlen(path) + 1) * sizeof(char));
+memset(cpath, '\0', l);
+strcpy(cpath, cwd);
+strcat(cpath, "/");
+strcat(cpath, path);
+} else {
+cpath = strdup(path);
 }
-return path;
-}
 
-static struct pathelem *add_entry(struct pathelem *root, const char *name)
-{
-root->num_entries++;
-
-root = realloc(root, sizeof(*root)
-		   + sizeof(root->entries[0])*root->num_entries);
+start = cpath + 1;  /* ignore leading '/' */
+while (1) {
+index = strstr(start, "/");
+if (!index) {
+/* add the last item */
+new = malloc(sizeof(struct path_entry));
+memset(new->name, '\0', PATH_MAX);
+new->prev = work;
+work->next = new;
+new->next = NULL;
+strcpy(new->name, start);
+work = new;
+break;
+}
+*index = '\0';
+if (index == (start)) {
+goto proceed;   /* skip over empty strings 
+   resulting from // */
+}
+
+if (strcmp(start, "..") == 0) {
+/* travel up one */
+if (!work->prev)
+goto proceed;
+work = work->prev;
+free(work->next);
+work->next = NULL;
+} else if (strcmp(start, ".") == 0) {
+/* ignore */
+goto proceed;
+} else {
+/* add an entry to our path_entry list */
+new = malloc(sizeof(struct path_entry));
+memset(new->name, '\0', PATH_MAX);
+new->prev = work;
+work->next = new;
+new->next = NULL;
+strcpy(new->name, start);
+work = new;
+}
+
+  proceed:
+*index = '/';
+start = index + 1;
+}
 
-root->entries[ro

[Qemu-devel] [PATCH][UPDATED] Add support to linux-user for dropping LD_PRELOAD

2007-05-21 Thread Lauri Leukkunen

This patch adds an option "-drop-ld-preload" which results in the
target process not having LD_PRELOAD set in its environment. This is
useful when running inside environments like scratchbox.

This version of the patch doesn't unset("LD_PRELOAD") but modifies the
envp argument to loader_exec() instead.

/lauri




[Qemu-devel] Re: [PATCH][UPDATED] Add support to linux-user for dropping LD_PRELOAD

2007-05-21 Thread Lauri Leukkunen

And here is the actual patch itself.

On 5/22/07, Lauri Leukkunen <[EMAIL PROTECTED]> wrote:

This patch adds an option "-drop-ld-preload" which results in the
target process not having LD_PRELOAD set in its environment. This is
useful when running inside environments like scratchbox.

This version of the patch doesn't unset("LD_PRELOAD") but modifies the
envp argument to loader_exec() instead.

/lauri

Index: linux-user/main.c
===
RCS file: /sources/qemu/qemu/linux-user/main.c,v
retrieving revision 1.109
diff -u -r1.109 main.c
--- linux-user/main.c	13 May 2007 13:58:00 -	1.109
+++ linux-user/main.c	21 May 2007 22:33:55 -
@@ -1666,11 +1666,12 @@
"usage: qemu-" TARGET_ARCH " [-h] [-g] [-d opts] [-L path] [-s size] [-cpu model] program [arguments...]\n"
"Linux CPU emulator (compiled for %s emulation)\n"
"\n"
-   "-h   print this help\n"
-   "-g port  wait gdb connection to port\n"
-   "-L path  set the elf interpreter prefix (default=%s)\n"
-   "-s size  set the stack size in bytes (default=%ld)\n"
-   "-cpu model   select CPU (-cpu ? for list)\n"
+   "-hprint this help\n"
+   "-g port   wait gdb connection to port\n"
+   "-L path   set the elf interpreter prefix (default=%s)\n"
+   "-s size   set the stack size in bytes (default=%ld)\n"
+   "-cpu modelselect CPU (-cpu ? for list)\n"
+   "-drop-ld-preload  drop LD_PRELOAD for target process\n"
"\n"
"debug options:\n"
 #ifdef USE_CODE_COPY
@@ -1702,7 +1703,9 @@
 int optind;
 const char *r;
 int gdbstub_port = 0;
-
+int drop_ld_preload = 0, environ_count = 0;
+char **target_environ, **wrk, **dst;
+
 if (argc <= 1)
 usage();
 
@@ -1774,6 +1777,8 @@
 #endif
 _exit(1);
 }
+} else if (!strcmp(r, "drop-ld-preload")) {
+drop_ld_preload = 1;
 } else 
 #ifdef USE_CODE_COPY
 if (!strcmp(r, "no-code-copy")) {
@@ -1802,11 +1807,25 @@
 env = cpu_init();
 global_env = env;
 
-if (loader_exec(filename, argv+optind, environ, regs, info) != 0) {
-	printf("Error loading %s\n", filename);
-	_exit(1);
+wrk = environ;
+while (*(wrk++))
+environ_count++;
+
+target_environ = malloc((environ_count + 1) * sizeof(char *));
+for (wrk = environ, dst = target_environ; *wrk; wrk++) {
+if (drop_ld_preload && !strncmp(*wrk, "LD_PRELOAD=", 11))
+continue;
+*(dst++) = strdup(*wrk);
 }
-
+dst = NULL; /* NULL terminate target_environ */
+
+if (loader_exec(filename, argv+optind, target_environ, regs, info) != 0) {
+printf("Error loading %s\n", filename);
+_exit(1);
+}
+
+free(target_environ);
+
 if (loglevel) {
 page_dump(logfile);
 


[Qemu-devel] Re: [PATCH][UPDATED] Add support to linux-user for dropping LD_PRELOAD

2007-05-21 Thread Lauri Leukkunen

And while I'm at it here's the same with properly deallocated environ strings.

On 5/22/07, Lauri Leukkunen <[EMAIL PROTECTED]> wrote:

And here is the actual patch itself.

On 5/22/07, Lauri Leukkunen <[EMAIL PROTECTED]> wrote:
> This patch adds an option "-drop-ld-preload" which results in the
> target process not having LD_PRELOAD set in its environment. This is
> useful when running inside environments like scratchbox.
>
> This version of the patch doesn't unset("LD_PRELOAD") but modifies the
> envp argument to loader_exec() instead.
>
> /lauri
>


Index: linux-user/main.c
===
RCS file: /sources/qemu/qemu/linux-user/main.c,v
retrieving revision 1.109
diff -u -r1.109 main.c
--- linux-user/main.c	13 May 2007 13:58:00 -	1.109
+++ linux-user/main.c	21 May 2007 23:49:05 -
@@ -1666,11 +1666,12 @@
"usage: qemu-" TARGET_ARCH " [-h] [-g] [-d opts] [-L path] [-s size] [-cpu model] program [arguments...]\n"
"Linux CPU emulator (compiled for %s emulation)\n"
"\n"
-   "-h   print this help\n"
-   "-g port  wait gdb connection to port\n"
-   "-L path  set the elf interpreter prefix (default=%s)\n"
-   "-s size  set the stack size in bytes (default=%ld)\n"
-   "-cpu model   select CPU (-cpu ? for list)\n"
+   "-hprint this help\n"
+   "-g port   wait gdb connection to port\n"
+   "-L path   set the elf interpreter prefix (default=%s)\n"
+   "-s size   set the stack size in bytes (default=%ld)\n"
+   "-cpu modelselect CPU (-cpu ? for list)\n"
+   "-drop-ld-preload  drop LD_PRELOAD for target process\n"
"\n"
"debug options:\n"
 #ifdef USE_CODE_COPY
@@ -1702,7 +1703,9 @@
 int optind;
 const char *r;
 int gdbstub_port = 0;
-
+int drop_ld_preload = 0, environ_count = 0;
+char **target_environ, **wrk, **dst;
+
 if (argc <= 1)
 usage();
 
@@ -1774,6 +1777,8 @@
 #endif
 _exit(1);
 }
+} else if (!strcmp(r, "drop-ld-preload")) {
+drop_ld_preload = 1;
 } else 
 #ifdef USE_CODE_COPY
 if (!strcmp(r, "no-code-copy")) {
@@ -1802,11 +1807,29 @@
 env = cpu_init();
 global_env = env;
 
-if (loader_exec(filename, argv+optind, environ, regs, info) != 0) {
-	printf("Error loading %s\n", filename);
-	_exit(1);
+wrk = environ;
+while (*(wrk++))
+environ_count++;
+
+target_environ = malloc((environ_count + 1) * sizeof(char *));
+for (wrk = environ, dst = target_environ; *wrk; wrk++) {
+if (drop_ld_preload && !strncmp(*wrk, "LD_PRELOAD=", 11))
+continue;
+*(dst++) = strdup(*wrk);
+}
+dst = NULL; /* NULL terminate target_environ */
+
+if (loader_exec(filename, argv+optind, target_environ, regs, info) != 0) {
+printf("Error loading %s\n", filename);
+_exit(1);
+}
+
+for (wrk = target_environ; *wrk; wrk++) {
+free(*wrk);
 }
 
+free(target_environ);
+
 if (loglevel) {
 page_dump(logfile);
 


Re: [Qemu-devel] [PATCH][UPDATED] Fix path mangling in linux-user/path.c

2007-05-21 Thread Kirill A. Shutemov
On [Tue, 22.05.2007 02:22], Lauri Leukkunen wrote:
> Attached patch fixes the linux-user path mangling code for use with
> real target root filesystems that have nasty symlinks and lots of
> files. The old code is terribly slow and can easily end up going
> through the entire host system /usr hierarchy in a recursive loop.
> 
> Compared to the previous version of this patch, fixes an issue with
> attempting to free() a pointer returned by GNU basename().

My patch to solve same problems attached

-- 
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + Velesys LLC, http://www.velesys.com/
 + ALT Linux Team, http://www.altlinux.com/
--- qemu/linux-user/path.c
+++ qemu/linux-user/path.c
@@ -1,147 +1,81 @@
 /* Code to mangle pathnames into those matching a given prefix.
eg. open("/lib/foo.so") => open("/usr/gnemul/i386-linux/lib/foo.so");
-
-   The assumption is that this area does not change.
 */
 #include 
-#include 
+#include 
 #include 
-#include 
 #include 
-#include 
 #include 
 #include "qemu.h"
 
-struct pathelem
-{
-/* Name of this, eg. lib */
-char *name;
-/* Full path name, eg. /usr/gnemul/x86-linux/lib. */
-char *pathname;
-struct pathelem *parent;
-/* Children */
-unsigned int num_entries;
-struct pathelem *entries[0];
+struct path_list_head {
+   struct path_list_head *next;
+   char* path;
 };
 
-static struct pathelem *base;
-
-/* First N chars of S1 match S2, and S2 is N chars long. */
-static int strneq(const char *s1, unsigned int n, const char *s2)
-{
-unsigned int i;
-
-for (i = 0; i < n; i++)
-   if (s1[i] != s2[i])
-   return 0;
-return s2[i] == 0;
-}
-
-static struct pathelem *add_entry(struct pathelem *root, const char *name);
-
-static struct pathelem *new_entry(const char *root,
- struct pathelem *parent,
- const char *name)
-{
-struct pathelem *new = malloc(sizeof(*new));
-new->name = strdup(name);
-asprintf(&new->pathname, "%s/%s", root, name);
-new->num_entries = 0;
-return new;
-}
-
-#define streq(a,b) (strcmp((a), (b)) == 0)
-
-static struct pathelem *add_dir_maybe(struct pathelem *path)
-{
-DIR *dir;
-
-if ((dir = opendir(path->pathname)) != NULL) {
-   struct dirent *dirent;
-
-   while ((dirent = readdir(dir)) != NULL) {
-   if (!streq(dirent->d_name,".") && !streq(dirent->d_name,"..")){
-   path = add_entry(path, dirent->d_name);
-   }
-   }
-closedir(dir);
-}
-return path;
-}
-
-static struct pathelem *add_entry(struct pathelem *root, const char *name)
-{
-root->num_entries++;
-
-root = realloc(root, sizeof(*root)
-  + sizeof(root->entries[0])*root->num_entries);
-
-root->entries[root->num_entries-1] = new_entry(root->pathname, root, name);
-root->entries[root->num_entries-1]
-   = add_dir_maybe(root->entries[root->num_entries-1]);
-return root;
-}
-
-/* This needs to be done after tree is stabalized (ie. no more reallocs!). */
-static void set_parents(struct pathelem *child, struct pathelem *parent)
-{
-unsigned int i;
-
-child->parent = parent;
-for (i = 0; i < child->num_entries; i++)
-   set_parents(child->entries[i], child);
-}
+static struct path_list_head* list_head;
 
 void init_paths(const char *prefix)
 {
 if (prefix[0] != '/' ||
-prefix[0] == '\0' ||
-!strcmp(prefix, "/"))
+prefix[0] == '\0' ||
+!strcmp(prefix, "/"))
 return;
 
-base = new_entry("", NULL, prefix+1);
-base = add_dir_maybe(base);
-if (base->num_entries == 0) {
-free (base);
-base = NULL;
-} else {
-set_parents(base, base);
-}
-}
+   list_head = malloc(sizeof(struct path_list_head));
 
-/* FIXME: Doesn't handle DIR/.. where DIR is not in emulated dir. */
-static const char *
-follow_path(const struct pathelem *cursor, const char *name)
-{
-unsigned int i, namelen;
-
-name += strspn(name, "/");
-namelen = strcspn(name, "/");
-
-if (namelen == 0)
-   return cursor->pathname;
-
-if (strneq(name, namelen, ".."))
-   return follow_path(cursor->parent, name + namelen);
-
-if (strneq(name, namelen, "."))
-   return follow_path(cursor, name + namelen);
-
-for (i = 0; i < cursor->num_entries; i++)
-   if (strneq(name, namelen, cursor->entries[i]->name))
-   return follow_path(cursor->entries[i], name + namelen);
-
-/* Not found */
-return NULL;
+   /* first element of list is prefix */
+   list_head->path = strdup(prefix);
+   list_head->next = NULL;
 }
 
 /* Look for path in emulation dir, otherwise return name. */
 const char *path(const char *name)
 {
+   struct path_list_head *list = list_head;
+   int path_length = strlen(list_head->path) + strlen(name) + 1;
+   char *newname = malloc(path_length);
+   struct stat buf;
+   const char * re

Re: [Qemu-devel] Using native libraries

2007-05-21 Thread Gwenole Beauchesne

Hi,

I'm sure someone's probably had a similar idea before, and it's  
probably not
practical for some reason I'm overlooking-- but is there a reason  
Qemu can't
dynamically translate library calls to use the native libraries  
instead of

requiring emulated libraries as well?


It should be possible, and I have just released an old PoC. I might  
work again on that once I get more free time in 3 weeks. ;-)



I am copying the article hereunder for reference.

[...]

So, what’s the status on the QEMU project side? Well, here is a  
tarball and a patch provided as is for the QEMU PoC. It passes the  
QEMU testthread test and bridges enough of libpthread and librt for  
that purpose. That implementation is weak insofar as nativelib lookup  
is really sub-optimal. Other implementations are meant to run-time  
patch ld.so, this provides more flexibily and permits to selectively  
nativelib a few functions (e.g. memcpy et al.), not the whole library.


How to build?

Please bear in mind this is just a PoC and is very incomplete in  
function coverage. If you still want to have a look, grab qemu 0.9.0  
sources, preferably a 2007/02/14 snapshot, and apply both tarball and  
patch. Configure for a i386-linux-user target and make it. Then, in  
the i386-linux-user directory, delete the nativelib-*.so files and re- 
make them with CC=”gcc -m32”. This assumes your host was x86_64.  
Otherwise, simply go to an i386 system and manually build the  
nativelibs.


How does it work?

* Target libraries (here, linux/i386) are statically compiled with  
the functions reducing to a few assembly code: the nativelib cookie.  
The target libraries (e.g. nativelib-libpthread.so) are placed in a  
special directory so that the open() syscall can actually resolve to  
this directory when target system libraries are looked up for.


* The nativelib cookie is actually an illegal instruction (0x0f 0x3c)  
that is caught at code translation time. This illegal instruction is  
followed by two other instructions describing the native function to  
call (library code, function code). This could have been raw IDs but  
this makes debugging/disassembling trickier.


* The do_nativelib() hook is then called and the library and function  
IDs are decoded and dispatched.


Regards,
Gwenolé.