Re: [Qemu-devel] [RFC][PATCH] Preliminary BeBox support

2011-03-02 Thread François Revol

Le 2 mars 2011 à 22:59, Andreas Färber a écrit :

> Hello François,
> 
> Am 01.03.2011 um 01:15 schrieb François Revol:
> 
>> Since Natalia raised the subject I though I'd post my current patch for the 
>> BeBox support.
>> I think the loader stuff can probably be committed already with some cleanup.
>> The rest is mostly a copy of the prep file with tweaks and needs more work.
>> The boot nub images can be extracted with this script:
>> http://revolf.free.fr/beos/extract_bebox_images.sh
>> Running -M bebox -bios bootnub.image makes it try to probe the PCI bridge 
>> for now.
>> Comments ?
> 
> How does this relate to the BeBox emulation I started? I assume not at all?
> I tried to do the PEF parsing and nub extraction inside QEMU.
> http://repo.or.cz/w/qemu/afaerber.git/shortlog/refs/heads/bebox

Eh, not at all, I didn't notice this one.
Hopefully I won't be dupping work anymore :p

> I'd prefer the BeBox machine to go into ppc_prep.c and to benefit from the 
> PReP cleanup that I started.

Yeah it needs some.

> I'll have a closer look the weekend, please cc me on future patches.

Ok.

François.


Re: [Qemu-devel] [RFC][PATCH] Preliminary BeBox support

2011-03-02 Thread Andreas Färber

Hello François,

Am 01.03.2011 um 01:15 schrieb François Revol:

Since Natalia raised the subject I though I'd post my current patch  
for the BeBox support.
I think the loader stuff can probably be committed already with some  
cleanup.
The rest is mostly a copy of the prep file with tweaks and needs  
more work.

The boot nub images can be extracted with this script:
http://revolf.free.fr/beos/extract_bebox_images.sh
Running -M bebox -bios bootnub.image makes it try to probe the PCI  
bridge for now.

Comments ?


How does this relate to the BeBox emulation I started? I assume not at  
all?

I tried to do the PEF parsing and nub extraction inside QEMU.
http://repo.or.cz/w/qemu/afaerber.git/shortlog/refs/heads/bebox

I'd prefer the BeBox machine to go into ppc_prep.c and to benefit from  
the PReP cleanup that I started.

I'll have a closer look the weekend, please cc me on future patches.

Thanks,

Andreas


[Qemu-devel] [RFC][PATCH] Preliminary BeBox support

2011-02-28 Thread François Revol
Since Natalia raised the subject I though I'd post my current patch for the 
BeBox support.
I think the loader stuff can probably be committed already with some cleanup.
The rest is mostly a copy of the prep file with tweaks and needs more work.
The boot nub images can be extracted with this script:
http://revolf.free.fr/beos/extract_bebox_images.sh
Running -M bebox -bios bootnub.image makes it try to probe the PCI bridge for 
now.
Comments ?

François.

diff --git a/Makefile.target b/Makefile.target
index 220589e..a41f792 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -227,6 +227,7 @@ obj-ppc-y += vga.o
 # PREP target
 obj-ppc-y += i8259.o mc146818rtc.o
 obj-ppc-y += ppc_prep.o
+obj-ppc-y += ppc_bebox.o
 # OldWorld PowerMac
 obj-ppc-y += ppc_oldworld.o
 # NewWorld PowerMac
diff --git a/hw/loader.c b/hw/loader.c
index 35d792e..7dc759a 100644
--- a/hw/loader.c
+++ b/hw/loader.c
@@ -515,6 +515,142 @@ out:
 return ret;
 }
 
+/* BeBox ROM image loader */
+
+struct bebox_image_header {
+   uint32_t entry;
+   uint32_t TOC;
+   uint32_t serial_num[2];
+   uint32_t checksum;
+   uint32_t addr;
+   uint32_t size;
+   uint32_t segtable;
+   char date[32];
+};
+
+struct bebox_image_section {
+   uint32_t size;
+   uint32_t offset;
+   uint32_t addr;
+   uint32_t zsize;
+};
+
+static void bswap_bebox_header(struct bebox_image_header *hdr)
+{
+#ifndef HOST_WORDS_BIGENDIAN
+bswap32s(&hdr->entry);
+bswap32s(&hdr->TOC);
+bswap32s(&hdr->serial_num[0]);
+bswap32s(&hdr->serial_num[1]);
+bswap32s(&hdr->checksum);
+bswap32s(&hdr->addr);
+bswap32s(&hdr->size);
+bswap32s(&hdr->segtable);
+#endif
+}
+
+static void bswap_bebox_section(struct bebox_image_section *sec)
+{
+#ifndef HOST_WORDS_BIGENDIAN
+bswap32s(&sec->size);
+bswap32s(&sec->addr);
+bswap32s(&sec->offset);
+bswap32s(&sec->zsize);
+#endif
+}
+
+/* Load a BeBox nub image. */
+int load_bebox(const char *filename, target_phys_addr_t *ep,
+   target_phys_addr_t *ds, target_phys_addr_t *loadaddr)
+{
+int fd;
+int size;
+   int i;
+struct bebox_image_header h;
+struct bebox_image_header *hdr = &h;
+struct bebox_image_section s;
+struct bebox_image_section *sec = &s;
+uint8_t *data = NULL;
+int ret = -1;
+fprintf(stderr, "%s(%s)\n", __FUNCTION__, filename);
+fd = open(filename, O_RDONLY | O_BINARY);
+if (fd < 0)
+return -1;
+
+size = read(fd, hdr, sizeof(uboot_image_header_t));
+if (size < sizeof(uboot_image_header_t))
+goto out;
+
+fprintf(stderr, "%s: %d read\n", __FUNCTION__, size);
+bswap_bebox_header(hdr);
+
+fprintf(stderr, "%s: entry %08x addr %08x\n", __FUNCTION__, hdr->entry, 
hdr->addr);
+   /* XXX: all known images load there, but... */
+if (hdr->entry != 0xfff00100)
+goto out;
+if (hdr->addr != 0xfff0)
+goto out;
+   /* date field seems be ASCII, ends with \n and \0 padded */
+   for (i = 0; i < 32; i++) {
+   if (!qemu_isprint(hdr->date[i]))
+   break;
+   }
+   if (i >= 32 || hdr->date[i] != '\n')
+   goto out;
+   i++;
+   for (; i < 32; i++) {
+   if (hdr->date[i] != '\0')
+   goto out;
+   }
+
+   /* TODO: check sum */
+
+fprintf(stderr, "%s: hdr ok\n", __FUNCTION__);
+/* it seems the image is supposed to be loaded at hdr->addr,
+* then the primary boot nub relocates the sections itself, copying 
some in RAM.
+ * But we don't have the image for the primary boot nub, so we do it on 
our own. */
+
+*ep = hdr->entry;
+*ds = hdr->TOC;
+data = qemu_malloc(hdr->size);
+
+   /* we also include the header when flashing */
+   lseek(fd, 0, SEEK_SET);
+
+if (read(fd, data, hdr->size) != hdr->size) {
+fprintf(stderr, "Error reading file\n");
+goto out;
+}
+
+rom_add_blob_fixed(filename, data, hdr->size, hdr->addr);
+
+if (loadaddr)
+*loadaddr = hdr->addr;
+
+fprintf(stderr, "%s: loaded @ %08x\n", __FUNCTION__, *loadaddr);
+
+   /* relocate sections */
+   for (i = 0; ; i++) {
+   memcpy(sec, data + hdr->segtable + i * sizeof(*sec), 
sizeof(*sec));
+   bswap_bebox_section(sec);
+fprintf(stderr, "%s: section: offset %08x addr %08x size %d zsize %d \n", 
__FUNCTION__, sec->offset, sec->addr, sec->size, sec->zsize);
+   if (sec->size == 0 && sec->zsize == 0)
+   break;
+   /* already there */
+   if (sec->addr == -1 || sec->addr == (hdr->addr + sec->offset))
+   continue;
+   rom_add_blob_z(filename, data + sec->offset, sec->size, 
sec->addr, sec->zsize);
+   }
+
+ret = hdr->size;
+
+out:
+if (data)
+qemu_free(data);
+close(fd);
+return ret;
+}
+
 /*
  * Functions for reboot-persistent memory regions.
  *  - used for vga bios an