diff -Nru openbios-1.1+svn1340/arch/ppc/qemu/init.c openbios-1.1+svn1353/arch/ppc/qemu/init.c --- openbios-1.1+svn1340/arch/ppc/qemu/init.c 2015-09-12 12:35:39.000000000 +0000 +++ openbios-1.1+svn1353/arch/ppc/qemu/init.c 2016-01-07 17:22:23.000000000 +0000 @@ -302,6 +302,11 @@ fword("encode-string"); push_str("state"); fword("property"); + + PUSH(0x20); + fword("encode-int"); + push_str("reservation-granule-size"); + fword("property"); } static void @@ -680,6 +685,60 @@ } } +/* + * adler32 ( adler buf len -- checksum ) + * + * Adapted from Mark Adler's original implementation (zlib license) + * + * Both OS 9 and BootX require this word for payload validation. + */ + +#define DO1(buf,i) {s1 += buf[i]; s2 += s1;} +#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); +#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); +#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); +#define DO16(buf) DO8(buf,0); DO8(buf,8); + +static void adler32(void) +{ + uint32_t len = (uint32_t)POP(); + char *buf = (char *)POP(); + uint32_t adler = (uint32_t)POP(); + + if (buf == NULL) { + RET(-1); + } + + uint32_t base = 65521; + uint32_t nmax = 5552; + + uint32_t s1 = adler & 0xffff; + uint32_t s2 = (adler >> 16) & 0xffff; + + uint32_t k; + while (len > 0) { + k = (len < nmax ? len : nmax); + len -= k; + + while (k >= 16) { + DO16(buf); + buf += 16; + k -= 16; + } + if (k != 0) { + do { + s1 += *buf++; + s2 += s1; + } while (--k); + } + + s1 %= base; + s2 %= base; + } + + RET(s2 << 16 | s1); +} + void arch_of_init(void) { @@ -945,6 +1004,9 @@ /* Implementation of filll word (required by BootX) */ bind_func("filll", ffilll); + + /* Implementation of adler32 word (required by OS 9, BootX) */ + bind_func("(adler32)", adler32); bind_func("platform-boot", boot); bind_func("(go)", go); diff -Nru openbios-1.1+svn1340/arch/ppc/qemu/methods.c openbios-1.1+svn1353/arch/ppc/qemu/methods.c --- openbios-1.1+svn1340/arch/ppc/qemu/methods.c 2015-09-12 12:35:39.000000000 +0000 +++ openbios-1.1+svn1353/arch/ppc/qemu/methods.c 2016-01-07 17:22:23.000000000 +0000 @@ -114,6 +114,8 @@ ciface_quiesce( unsigned long args[], unsigned long ret[] ) { usb_exit(); + + ob_ide_quiesce(); #if 0 unsigned long msr; /* This seems to be the correct thing to do - but I'm not sure */ @@ -164,21 +166,21 @@ DECLARE_NODE( mmu_ciface, 0, 0, "+/openprom/client-services" ); -/* ( phys size align --- base ) */ +/* ( [phys] size align --- base ) */ static void mem_claim( void ) { ucell align = POP(); ucell size = POP(); - ucell phys = POP(); - ucell ret = ofmem_claim_phys( phys, size, align ); + phys_addr_t phys = -1; - if( ret == -1 ) { - printk("MEM: claim failure\n"); - throw( -13 ); - return; + if (!align) { + phys = POP(); } - PUSH( ret ); + + phys = ofmem_claim_phys(phys, size, align); + + PUSH(phys); } /* ( phys size --- ) */ @@ -188,24 +190,24 @@ POP(); POP(); } -/* ( phys size align --- base ) */ +/* ( [virt] size align --- base ) */ static void mmu_claim( void ) { ucell align = POP(); ucell size = POP(); - ucell phys = POP(); - ucell ret = ofmem_claim_virt( phys, size, align ); + ucell virt = -1; - if( ret == -1 ) { - printk("MMU: CLAIM failure\n"); - throw( -13 ); - return; + if (!align) { + virt = POP(); } - PUSH( ret ); + + virt = ofmem_claim_virt(virt, size, align); + + PUSH(virt); } -/* ( phys size --- ) */ +/* ( virt size --- ) */ static void mmu_release( void ) { diff -Nru openbios-1.1+svn1340/arch/ppc/qemu/qemu.fs openbios-1.1+svn1353/arch/ppc/qemu/qemu.fs --- openbios-1.1+svn1340/arch/ppc/qemu/qemu.fs 2015-09-12 12:35:39.000000000 +0000 +++ openbios-1.1+svn1353/arch/ppc/qemu/qemu.fs 2016-01-07 17:22:23.000000000 +0000 @@ -93,3 +93,31 @@ :noname set-defaults ; PREPOST-initializer + +\ ------------------------------------------------------------------------- +\ Adler-32 wrapper +\ ------------------------------------------------------------------------- + +: adler32 ( adler buf len -- checksum ) + \ Since Mac OS 9 is the only system using this word, we take this + \ opportunity to inject a copyright message that is necessary for the + \ system to boot. + " Copyright 1983-2001 Apple Computer, Inc. THIS MESSAGE FOR COMPATIBILITY ONLY" + encode-string " copyright" + " /" find-package if + " set-property" $find if + execute + else + 3drop drop + then + then + + ( adler buf len ) + + " (adler32)" $find if + execute + else + ." Can't find " ( adler32-name ) type cr + 3drop 0 + then +; diff -Nru openbios-1.1+svn1340/arch/ppc/qemu/tree.fs openbios-1.1+svn1353/arch/ppc/qemu/tree.fs --- openbios-1.1+svn1340/arch/ppc/qemu/tree.fs 2015-09-12 12:35:39.000000000 +0000 +++ openbios-1.1+svn1353/arch/ppc/qemu/tree.fs 2016-01-07 17:22:23.000000000 +0000 @@ -42,6 +42,14 @@ : close ; finish-device +new-device + " rom" device-name + h# ff800000 encode-int 0 encode-int encode+ " reg" property + 1 encode-int " #address-cells" property + h# ff800000 encode-int h# 800000 encode-int encode+ + h# ff800000 encode-int encode+ " ranges" property +finish-device + \ ------------------------------------------------------------- \ /packages \ ------------------------------------------------------------- diff -Nru openbios-1.1+svn1340/config/scripts/switch-arch openbios-1.1+svn1353/config/scripts/switch-arch --- openbios-1.1+svn1340/config/scripts/switch-arch 2015-09-12 12:36:21.000000000 +0000 +++ openbios-1.1+svn1353/config/scripts/switch-arch 2016-01-07 17:22:23.000000000 +0000 @@ -99,23 +99,25 @@ select_prefix() { - TARGETS="${1}-unknown-linux-gnu- ${1}-linux-gnu- ${1}-linux- ${1}-elf- ${1}-eabi-" + for target_arch ; do + TARGETS="${target_arch}-unknown-linux-gnu- ${target_arch}-linux-gnu- ${target_arch}-linux- ${target_arch}-elf- ${target_arch}-eabi-" - if [ x"$CROSS_COMPILE" != "x" ]; then - TARGETS=$CROSS_COMPILE - fi + if [ x"$CROSS_COMPILE" != "x" ]; then + TARGETS=$CROSS_COMPILE + fi - for TARGET in $TARGETS - do - if type ${TARGET}gcc > /dev/null 2>&1 - then + for TARGET in $TARGETS + do + if type ${TARGET}gcc > /dev/null 2>&1 + then + return + fi + done + if [ "$ARCH" = "$HOSTARCH" ]; then return fi done - if [ "$ARCH" = "$HOSTARCH" ]; then - return - fi - echo "ERROR: no ${1} cross-compiler found !" 1>&2 + echo "ERROR: no $* cross-compiler found !" 1>&2 exit 1 } @@ -251,7 +253,7 @@ ;; ppc) - select_prefix powerpc + select_prefix powerpc powerpc64 if [ "$unix" = "no" ]; then CFLAGS="-m32 -msoft-float -fno-builtin-bcopy -fno-builtin-log2" AS_FLAGS="-m32" diff -Nru openbios-1.1+svn1340/debian/changelog openbios-1.1+svn1353/debian/changelog --- openbios-1.1+svn1340/debian/changelog 2015-09-12 16:33:41.000000000 +0000 +++ openbios-1.1+svn1353/debian/changelog 2016-01-08 00:45:48.000000000 +0000 @@ -1,3 +1,12 @@ +openbios (1.1+svn1353-1) unstable; urgency=medium + + * New upstream snapshot, compatible with qemu 2.5.x. + * debian/cross-toolchain.mk: allow top level directory in source + tarballs to not use the same version as the corresponding package. + * Switch to gcc-5 from gcc-4.9. + + -- Aurelien Jarno Fri, 08 Jan 2016 00:45:47 +0000 + openbios (1.1+svn1340-1) unstable; urgency=medium * New upstream snapshot, compatible with qemu 2.4.x. diff -Nru openbios-1.1+svn1340/debian/control openbios-1.1+svn1353/debian/control --- openbios-1.1+svn1340/debian/control 2015-09-12 12:39:09.000000000 +0000 +++ openbios-1.1+svn1353/debian/control 2016-01-08 00:32:13.000000000 +0000 @@ -3,7 +3,7 @@ Uploaders: Aurelien Jarno Section: misc Priority: extra -Build-Depends: debhelper (>= 9), fcode-utils, xsltproc, binutils-source, bison, flex, gcc-4.9-source, libmpc-dev +Build-Depends: debhelper (>= 9), fcode-utils, xsltproc, binutils-source, bison, flex, gcc-5-source, libmpc-dev Standards-Version: 3.9.6 Homepage: http://www.openbios.org/ Vcs-Browser: http://git.debian.org/?p=pkg-qemu/openbios.git diff -Nru openbios-1.1+svn1340/debian/cross-toolchain.mk openbios-1.1+svn1353/debian/cross-toolchain.mk --- openbios-1.1+svn1340/debian/cross-toolchain.mk 2015-09-12 12:39:09.000000000 +0000 +++ openbios-1.1+svn1353/debian/cross-toolchain.mk 2016-01-08 00:32:13.000000000 +0000 @@ -9,9 +9,7 @@ njobs = -j $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS))) endif -gcc_major_version = 4.9 -binutils_version = $(shell dpkg-query -W -f="\$${Version}\n" binutils-source | cut -d- -f1) -gcc_version = $(shell dpkg-query -W -f="\$${Version}\n" gcc-$(gcc_major_version)-source | cut -d- -f1) +gcc_major_version = 5 # GCC does not build with some hardening options and anyway we do not # ship the resulting binaries in the package @@ -21,10 +19,10 @@ toolchain_dir = $(CURDIR)/cross-toolchain stamp = $(toolchain_dir)/stamp- binutils_src_dir = /usr/src/binutils -binutils_unpack_dir = $(toolchain_dir)/binutils-$(binutils_version) +binutils_unpack_dir = $(toolchain_dir)/binutils-source binutils_build_dir = $(toolchain_dir)/binutils-$(target) gcc_src_dir = /usr/src/gcc-$(gcc_major_version) -gcc_unpack_dir = $(toolchain_dir)/gcc-$(gcc_version) +gcc_unpack_dir = $(toolchain_dir)/gcc-source gcc_build_dir = $(toolchain_dir)/gcc-$(target) # We can not apply all the patches provided by GCC as they are architecture @@ -33,8 +31,9 @@ gcc_patches = svn-updates.diff gcc-gfdl-build.diff $(stamp)binutils_unpack: - mkdir -p $(toolchain_dir) - tar -C $(toolchain_dir) -xf $(binutils_src_dir)/binutils-*.tar.* + mkdir -p $(binutils_unpack_dir) + cd $(binutils_unpack_dir) && \ + tar --strip-components=1 -xf $(binutils_src_dir)/binutils-*.tar.* touch $@ $(stamp)binutils_%: $(stamp)binutils_unpack @@ -53,9 +52,9 @@ touch $@ $(stamp)gcc_unpack: - mkdir -p $(toolchain_dir) - tar -C $(toolchain_dir) -xf $(gcc_src_dir)/gcc-*.tar.* + mkdir -p $(gcc_unpack_dir) cd $(gcc_unpack_dir) && \ + tar --strip-components=1 -xf $(gcc_src_dir)/gcc-*.tar.* ; \ for p in $(gcc_patches) ; do \ cat $(gcc_src_dir)/patches/$$p | patch -p2 ; \ done diff -Nru openbios-1.1+svn1340/drivers/cuda.c openbios-1.1+svn1353/drivers/cuda.c --- openbios-1.1+svn1340/drivers/cuda.c 2015-09-12 09:36:30.000000000 +0000 +++ openbios-1.1+svn1353/drivers/cuda.c 2016-01-07 17:22:23.000000000 +0000 @@ -144,8 +144,22 @@ // CUDA_DPRINTF("len: %d %02x\n", len, snd_buf[0]); len = cuda_request(host, ADB_PACKET, snd_buf, len, buffer); if (len > 1 && buffer[0] == ADB_PACKET) { - pos = buffer + 2; - len -= 2; + /* We handle 2 types of ADB packet here: + Normal: ... + Error : ( ...) + Ideally we should use buffer[1] (status) to determine whether this + is a normal or error packet but this requires a corresponding fix + in QEMU <= 2.4. Hence we temporarily handle it this way to ease + the transition. */ + if (len > 2 && buffer[2] == snd_buf[0]) { + /* Error */ + pos = buffer + 3; + len -= 3; + } else { + /* Normal */ + pos = buffer + 2; + len -= 2; + } } else { pos = buffer + 1; len = -1; @@ -380,7 +394,8 @@ ph = find_dev(buf); set_property(ph, "device_type", "power-mgt", 10); - set_property(ph, "compatible", "power-mgt", 10); + set_property(ph, "mgt-kind", "min-consumption-pwm-led", strlen("min-consumption-pwm-led") + 1); + set_property(ph, "compatible", "cuda", strlen("cuda") + 1); } cuda_t *cuda_init (const char *path, phys_addr_t base) diff -Nru openbios-1.1+svn1340/drivers/escc.c openbios-1.1+svn1353/drivers/escc.c --- openbios-1.1+svn1340/drivers/escc.c 2015-09-12 09:36:30.000000000 +0000 +++ openbios-1.1+svn1353/drivers/escc.c 2016-01-07 17:22:23.000000000 +0000 @@ -380,12 +380,22 @@ static void escc_add_channel(const char *path, const char *node, phys_addr_t addr, - uint32_t offset) + int esnum) { char buf[64], tty[32]; phandle_t dnode, aliases; - int len; - cell props[2]; + + cell props[10]; + int offset; + int legacy; + + switch (esnum) { + case 2: offset = 1; legacy = 0; break; + case 3: offset = 0; legacy = 0; break; + case 4: offset = 1; legacy = 1; break; + case 5: offset = 0; legacy = 1; break; + default: return; + } /* add device */ @@ -411,16 +421,28 @@ set_property(dnode, "device_type", "serial", strlen("serial") + 1); - snprintf(buf, sizeof(buf), "ch-%s", node); - len = strlen(buf) + 1; - snprintf(buf + len, sizeof(buf) - len, "CHRP,es2"); - set_property(dnode, "compatible", buf, len + 9); - - props[0] = IO_ESCC_OFFSET + offset * 0x20; - props[1] = 0x00000020; - set_property(dnode, "reg", (char *)&props, 2 * sizeof(cell)); + snprintf(buf, sizeof(buf), "chrp,es%d", esnum); + set_property(dnode, "compatible", buf, 9); - props[0] = addr + IO_ESCC_OFFSET + offset * 0x20; + if (legacy) { + props[0] = IO_ESCC_LEGACY_OFFSET + offset * 0x4; + props[1] = 0x00000001; + props[2] = IO_ESCC_LEGACY_OFFSET + offset * 0x4 + 2; + props[3] = 0x00000001; + props[4] = IO_ESCC_LEGACY_OFFSET + offset * 0x4 + 6; + props[5] = 0x00000001; + set_property(dnode, "reg", (char *)&props, 6 * sizeof(cell)); + } else { + props[0] = IO_ESCC_OFFSET + offset * 0x20; + props[1] = 0x00000020; + set_property(dnode, "reg", (char *)&props, 2 * sizeof(cell)); + } + + if (legacy) { + props[0] = addr + IO_ESCC_LEGACY_OFFSET + offset * 0x4; + } else { + props[0] = addr + IO_ESCC_OFFSET + offset * 0x20; + } OLDWORLD(set_property(dnode, "AAPL,address", (char *)&props, 1 * sizeof(cell))); @@ -430,13 +452,21 @@ props[0] = (0x24) + offset; props[1] = 0; + props[2] = 0; NEWWORLD(set_property(dnode, "interrupts", - (char *)&props, 2 * sizeof(cell))); + (char *)&props, 3 * sizeof(cell))); device_end(); - uart_init_line((unsigned char*)addr + IO_ESCC_OFFSET + offset * 0x20, - CONFIG_SERIAL_SPEED); + if (legacy) { + uart_init_line( + (unsigned char*)addr + IO_ESCC_LEGACY_OFFSET + offset * 0x4, + CONFIG_SERIAL_SPEED); + } else { + uart_init_line( + (unsigned char*)addr + IO_ESCC_OFFSET + offset * 0x20, + CONFIG_SERIAL_SPEED); + } } void @@ -467,10 +497,34 @@ fword("finish-device"); - escc_add_channel(buf, "a", addr, 1); - escc_add_channel(buf, "b", addr, 0); + escc_add_channel(buf, "a", addr, 2); + escc_add_channel(buf, "b", addr, 3); escc_serial_dev = (unsigned char *)addr + IO_ESCC_OFFSET + (CONFIG_SERIAL_PORT ? 0 : 0x20); + + push_str(path); + fword("find-device"); + fword("new-device"); + + push_str("escc-legacy"); + fword("device-name"); + + snprintf(buf, sizeof(buf), "%s/escc-legacy", path); + + dnode = find_dev(buf); + + set_int_property(dnode, "#address-cells", 1); + props[0] = __cpu_to_be32(IO_ESCC_LEGACY_OFFSET); + props[1] = __cpu_to_be32(IO_ESCC_LEGACY_SIZE); + set_property(dnode, "reg", (char *)&props, sizeof(props)); + set_property(dnode, "device_type", "escc-legacy", + strlen("escc-legacy") + 1); + set_property(dnode, "compatible", "chrp,es1", 9); + + fword("finish-device"); + + escc_add_channel(buf, "a", addr, 4); + escc_add_channel(buf, "b", addr, 5); } #endif diff -Nru openbios-1.1+svn1340/drivers/escc.h openbios-1.1+svn1353/drivers/escc.h --- openbios-1.1+svn1340/drivers/escc.h 2015-09-12 09:36:30.000000000 +0000 +++ openbios-1.1+svn1353/drivers/escc.h 2016-01-07 17:22:23.000000000 +0000 @@ -1,6 +1,8 @@ #define IO_ESCC_SIZE 0x00001000 #define IO_ESCC_OFFSET 0x00013000 +#define IO_ESCC_LEGACY_SIZE 0x00001000 +#define IO_ESCC_LEGACY_OFFSET 0x00012000 #define ZS_REGS 8 diff -Nru openbios-1.1+svn1340/drivers/ide.c openbios-1.1+svn1353/drivers/ide.c --- openbios-1.1+svn1340/drivers/ide.c 2015-09-12 09:36:30.000000000 +0000 +++ openbios-1.1+svn1353/drivers/ide.c 2016-01-07 17:22:23.000000000 +0000 @@ -1488,6 +1488,28 @@ return 0; } +void ob_ide_quiesce(void) +{ + struct ide_channel *channel; + int i; + + channel = channels; + while (channel) { + for (i = 0; i < 2; i++) { + struct ide_drive *drive = &channel->drives[i]; + + if (!drive->present) + continue; + + ob_ide_select_drive(drive); + ob_ide_software_reset(drive); + ob_ide_device_type_check(drive); + } + + channel = channel->next; + } +} + #if defined(CONFIG_DRIVER_MACIO) static unsigned char macio_ide_inb(struct ide_channel *chan, unsigned int port) @@ -1581,6 +1603,12 @@ set_property(dnode, "compatible", (is_oldworld() ? "heathrow-ata" : "keylargo-ata"), 13); + set_property(dnode, "model", ((current_channel == 3) ? + "ata-3" : "ata-4"), strlen("ata-*") + 1); + + set_property(dnode, "AAPL,connector", "ata", + strlen("ata") + 1); + props[0] = 0x00000526; props[1] = 0x00000085; props[2] = 0x00000025; @@ -1589,8 +1617,8 @@ props[5] = 0x00000000; props[6] = 0x00000000; props[7] = 0x00000000; - OLDWORLD(set_property(dnode, "AAPL,pio-timing", - (char *)&props, 8*sizeof(props[0]))); + set_property(dnode, "AAPL,pio-timing", + (char *)&props, 8*sizeof(props[0])); /* The first interrupt entry is the ide interrupt, the second the dbdma interrupt */ @@ -1634,8 +1662,8 @@ (char *)&props, 2*sizeof(props[0]))); props[0] = 0; - OLDWORLD(set_property(dnode, "AAPL,bus-id", (char*)props, - 1 * sizeof(props[0]))); + set_property(dnode, "AAPL,bus-id", (char*)props, + 1 * sizeof(props[0])); IDE_DPRINTF(DEV_NAME": [io ports 0x%lx]\n", current_channel, chan->mmio); diff -Nru openbios-1.1+svn1340/drivers/pci.c openbios-1.1+svn1353/drivers/pci.c --- openbios-1.1+svn1340/drivers/pci.c 2015-09-12 09:36:30.000000000 +0000 +++ openbios-1.1+svn1353/drivers/pci.c 2016-01-07 17:22:23.000000000 +0000 @@ -824,7 +824,7 @@ ncells += pci_encode_phys_addr(props + ncells, flags, space_code, config->dev, PCI_BASE_ADDR_0 + (i * sizeof(uint32_t)), - 0); + config->assigned[i] & ~mask); props[ncells++] = config->sizes[i]; } @@ -1420,6 +1420,12 @@ target_node = find_dev("/pci/mac-io/escc/ch-b"); set_int_property(target_node, "interrupt-parent", dnode); + target_node = find_dev("/pci/mac-io/escc-legacy/ch-a"); + set_int_property(target_node, "interrupt-parent", dnode); + + target_node = find_dev("/pci/mac-io/escc-legacy/ch-b"); + set_int_property(target_node, "interrupt-parent", dnode); + /* QEMU only emulates 2 of the 3 ata buses currently */ /* On a new world Mac these are not numbered but named by the * ATA version they support. Thus we have: ata-3, ata-3, ata-4 diff -Nru openbios-1.1+svn1340/include/drivers/drivers.h openbios-1.1+svn1353/include/drivers/drivers.h --- openbios-1.1+svn1340/include/drivers/drivers.h 2015-09-12 09:36:30.000000000 +0000 +++ openbios-1.1+svn1353/include/drivers/drivers.h 2016-01-07 17:22:23.000000000 +0000 @@ -52,6 +52,7 @@ /* drivers/ide.c */ int ob_ide_init(const char *path, uint32_t io_port0, uint32_t ctl_port0, uint32_t io_port1, uint32_t ctl_port1); +void ob_ide_quiesce(void); int macio_ide_init(const char *path, uint32_t addr, int nb_channels); #endif #ifdef CONFIG_DRIVER_ESP diff -Nru openbios-1.1+svn1340/libopenbios/bootinfo_load.c openbios-1.1+svn1353/libopenbios/bootinfo_load.c --- openbios-1.1+svn1340/libopenbios/bootinfo_load.c 2015-09-12 12:35:39.000000000 +0000 +++ openbios-1.1+svn1353/libopenbios/bootinfo_load.c 2016-01-07 17:22:23.000000000 +0000 @@ -161,6 +161,12 @@ feval("load-size"); size = POP(); + /* Some bootinfo scripts contain a binary payload after the + NULL-terminated Forth string such as OS 9. Restrict our + size to just the Forth section, otherwise we end up trying + to allocate memory for the entire binary which might fail. */ + size = strnlen(base, size); + bootscript = malloc(size); if (bootscript == NULL) { DPRINTF("Can't malloc %d bytes\n", size);