--- trunk/src/machine.c 2007/10/08 16:17:48 2 +++ trunk/src/machine.c 2007/10/08 16:18:38 12 @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: machine.c,v 1.406 2005/04/06 23:13:37 debug Exp $ + * $Id: machine.c,v 1.515 2005/08/16 09:16:26 debug Exp $ * * Emulation of specific machines. * @@ -53,7 +53,6 @@ #include "arcbios.h" #include "bus_pci.h" #include "cpu.h" -#include "cpu_mips.h" #include "device.h" #include "devices.h" #include "diskimage.h" @@ -65,11 +64,16 @@ #include "net.h" #include "symbol.h" +/* For Alpha emulation: */ +#include "alpha_rpb.h" + /* For SGI and ARC emulation: */ #include "sgi_arcbios.h" -#include "arcbios_other.h" #include "crimereg.h" +/* For evbmips emulation: */ +#include "maltareg.h" + /* For DECstation emulation: */ #include "dec_prom.h" #include "dec_bootinfo.h" @@ -84,6 +88,9 @@ #include "hpc_bootinfo.h" #include "vripreg.h" +#define BOOTSTR_BUFLEN 1000 +#define BOOTARG_BUFLEN 2000 +#define ETHERNET_STRING_MAXLEN 40 struct machine_entry_subtype { int machine_subtype;/* Old-style subtype */ @@ -107,6 +114,11 @@ struct machine_entry_subtype **subtype; }; + +/* See main.c: */ +extern int quiet_mode; + + /* This is initialized by machine_init(): */ static struct machine_entry *first_machine_entry = NULL; @@ -133,10 +145,16 @@ m->name = strdup(name); /* Sane default values: */ - m->serial_nr = 0; + m->serial_nr = 1; m->machine_type = MACHINE_NONE; m->machine_subtype = MACHINE_NONE; +#ifdef BINTRANS m->bintrans_enable = 1; + m->old_bintrans_enable = 1; +#endif + m->arch_pagesize = 4096; /* Should be overriden in + emul.c for other pagesizes. */ + m->dyntrans_alignment_check = 1; m->prom_emulation = 1; m->speed_tricks = 1; m->byte_order_override = NO_BYTE_ORDER_OVERRIDE; @@ -167,11 +185,12 @@ int *type, int *subtype, int *arch) { struct machine_entry *me; - int i, j, k; + int i, j, k, nmatches = 0; *type = MACHINE_NONE; *subtype = 0; + /* Check stype, and optionally ssubtype: */ me = first_machine_entry; while (me != NULL) { for (i=0; in_aliases; i++) @@ -195,22 +214,59 @@ return 1; } - fatal("unknown subtype '%s' for emulation" + fatal("Unknown subtype '%s' for emulation" " '%s'\n", ssubtype, stype); + if (!ssubtype[0]) + fatal("(Maybe you forgot the -e" + " command line option?)\n"); exit(1); } me = me->next; } - fatal("machine_name_to_type(): unknown emulation type '%s' (", stype); - if (ssubtype == NULL) - fatal("no subtype)\n"); - else - fatal("subtype '%s')\n", ssubtype); + /* Not found? Then just check ssubtype: */ + me = first_machine_entry; + while (me != NULL) { + if (me->n_subtypes == 0) { + me = me->next; + continue; + } + + /* Check for subtype: */ + for (j=0; jn_subtypes; j++) + for (k=0; ksubtype[j]->n_aliases; k++) + if (strcasecmp(ssubtype, me->subtype[j]-> + aliases[k]) == 0) { + *type = me->machine_type; + *arch = me->arch; + *subtype = me->subtype[j]-> + machine_subtype; + nmatches ++; + } + + me = me->next; + } + + switch (nmatches) { + case 0: fatal("\nSorry, emulation \"%s\"", stype); + if (ssubtype != NULL && ssubtype[0] != '\0') + fatal(" (subtype \"%s\")", ssubtype); + fatal(" is unknown.\n"); + break; + case 1: return 1; + default:fatal("\nSorry, multiple matches for \"%s\"", stype); + if (ssubtype != NULL && ssubtype[0] != '\0') + fatal(" (subtype \"%s\")", ssubtype); + fatal(".\n"); + } + + *type = MACHINE_NONE; + *subtype = 0; + + fatal("Use the -H command line option to get a list of " + "available types and subtypes.\n\n"); - fatal("Use the -H command line option to get a list of available" - " types and subtypes.\n"); return 0; } @@ -332,6 +388,35 @@ /* + * add_environment_string_dual(): + * + * Add "dual" environment strings, one for the variable name and one for the + * value, and update pointers afterwards. + */ +void add_environment_string_dual(struct cpu *cpu, + uint64_t *ptrp, uint64_t *addrp, char *s1, char *s2) +{ + uint64_t ptr = *ptrp, addr = *addrp; + + store_32bit_word(cpu, ptr, addr); + ptr += sizeof(uint32_t); + if (addr != 0) { + store_string(cpu, addr, s1); + addr += strlen(s1) + 1; + } + store_32bit_word(cpu, ptr, addr); + ptr += sizeof(uint32_t); + if (addr != 0) { + store_string(cpu, addr, s2); + addr += strlen(s2) + 1; + } + + *ptrp = ptr; + *addrp = addr; +} + + +/* * store_64bit_word(): * * Stores a 64-bit word in emulated RAM. Byte order is taken into account. @@ -415,26 +500,23 @@ */ void store_buf(struct cpu *cpu, uint64_t addr, char *s, size_t len) { + int psize = 1024; /* 1024 256 64 16 4 1 */ + if ((addr >> 32) == 0) addr = (int64_t)(int32_t)addr; - if ((addr & 7) == 0 && (((size_t)s) & 7) == 0) { - while (len >= 8) { - cpu->memory_rw(cpu, cpu->mem, addr, (unsigned char *)s, - 8, MEM_WRITE, CACHE_DATA); - addr += 8; - s += 8; - len -= 8; - } - } - if ((addr & 3) == 0 && (((size_t)s) & 3) == 0) { - while (len >= 4) { - cpu->memory_rw(cpu, cpu->mem, addr, (unsigned char *)s, - 4, MEM_WRITE, CACHE_DATA); - addr += 4; - s += 4; - len -= 4; + while (len != 0) { + if ((addr & (psize-1)) == 0) { + while (len >= psize) { + cpu->memory_rw(cpu, cpu->mem, addr, + (unsigned char *)s, psize, MEM_WRITE, + CACHE_DATA); + addr += psize; + s += psize; + len -= psize; + } } + psize >>= 2; } while (len-- != 0) @@ -488,6 +570,29 @@ /* + * load_16bit_word(): + * + * Helper function. Prints a warning and returns 0, if the read failed. + * Emulated byte order is taken into account. + */ +uint16_t load_16bit_word(struct cpu *cpu, uint64_t addr) +{ + unsigned char data[2]; + + if ((addr >> 32) == 0) + addr = (int64_t)(int32_t)addr; + cpu->memory_rw(cpu, cpu->mem, + addr, data, sizeof(data), MEM_READ, CACHE_DATA); + + if (cpu->byte_order == EMUL_LITTLE_ENDIAN) { + int tmp = data[0]; data[0] = data[1]; data[1] = tmp; + } + + return (data[0] << 8) + data[1]; +} + + +/* * store_64bit_word_in_host(): * * Stores a 64-bit word in the _host's_ RAM. Emulated byte order is taken @@ -571,13 +676,13 @@ if (assrt) { /* OR in the irq_nr into the CSR: */ - m->kn02_csr->csr[0] |= irq_nr; + m->md_int.kn02_csr->csr[0] |= irq_nr; } else { /* AND out the irq_nr from the CSR: */ - m->kn02_csr->csr[0] &= ~irq_nr; + m->md_int.kn02_csr->csr[0] &= ~irq_nr; } - current = m->kn02_csr->csr[0] & m->kn02_csr->csr[2]; + current = m->md_int.kn02_csr->csr[0] & m->md_int.kn02_csr->csr[2]; if (current == 0) cpu_interrupt_ack(cpu, 2); else @@ -596,12 +701,12 @@ /* debug("kmin_interrupt(): irq_nr=%i assrt=%i\n", irq_nr, assrt); */ if (assrt) - m->dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] |= irq_nr; + m->md_int.dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] |= irq_nr; else - m->dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] &= ~irq_nr; + m->md_int.dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] &= ~irq_nr; - if (m->dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] - & m->dec_ioasic_data->reg[(IOASIC_IMSK - IOASIC_SLOT_1_START) / 0x10]) + if (m->md_int.dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] + & m->md_int.dec_ioasic_data->reg[(IOASIC_IMSK - IOASIC_SLOT_1_START) / 0x10]) cpu_interrupt(cpu, KMIN_INT_TC3); else cpu_interrupt_ack(cpu, KMIN_INT_TC3); @@ -617,12 +722,12 @@ /* debug("kn03_interrupt(): irq_nr=0x%x assrt=%i\n", irq_nr, assrt); */ if (assrt) - m->dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] |= irq_nr; + m->md_int.dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] |= irq_nr; else - m->dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] &= ~irq_nr; + m->md_int.dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] &= ~irq_nr; - if (m->dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] - & m->dec_ioasic_data->reg[(IOASIC_IMSK - IOASIC_SLOT_1_START) / 0x10]) + if (m->md_int.dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] + & m->md_int.dec_ioasic_data->reg[(IOASIC_IMSK - IOASIC_SLOT_1_START) / 0x10]) cpu_interrupt(cpu, KN03_INT_ASIC); else cpu_interrupt_ack(cpu, KN03_INT_ASIC); @@ -639,14 +744,14 @@ debug("maxine_interrupt(): irq_nr=0x%x assrt=%i\n", irq_nr, assrt); if (assrt) - m->dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) + m->md_int.dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] |= irq_nr; else - m->dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) + m->md_int.dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] &= ~irq_nr; - if (m->dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] - & m->dec_ioasic_data->reg[(IOASIC_IMSK - IOASIC_SLOT_1_START) + if (m->md_int.dec_ioasic_data->reg[(IOASIC_INTR - IOASIC_SLOT_1_START) / 0x10] + & m->md_int.dec_ioasic_data->reg[(IOASIC_IMSK - IOASIC_SLOT_1_START) / 0x10]) cpu_interrupt(cpu, XINE_INT_TC3); else @@ -661,7 +766,7 @@ { int r2 = 0; - m->kn230_csr->csr |= irq_nr; + m->md_int.kn230_csr->csr |= irq_nr; switch (irq_nr) { case KN230_CSR_INTR_SII: @@ -679,24 +784,24 @@ if (assrt) { /* OR in the irq_nr mask into the CSR: */ - m->kn230_csr->csr |= irq_nr; + m->md_int.kn230_csr->csr |= irq_nr; /* Assert MIPS interrupt 2 or 3: */ cpu_interrupt(cpu, r2); } else { /* AND out the irq_nr mask from the CSR: */ - m->kn230_csr->csr &= ~irq_nr; + m->md_int.kn230_csr->csr &= ~irq_nr; /* If the CSR interrupt bits are all zero, clear the bit in the cause register as well. */ if (r2 == 2) { /* irq 2: */ - if ((m->kn230_csr->csr & (KN230_CSR_INTR_DZ0 + if ((m->md_int.kn230_csr->csr & (KN230_CSR_INTR_DZ0 | KN230_CSR_INTR_OPT0 | KN230_CSR_INTR_OPT1)) == 0) cpu_interrupt_ack(cpu, r2); } else { /* irq 3: */ - if ((m->kn230_csr->csr & (KN230_CSR_INTR_SII | + if ((m->md_int.kn230_csr->csr & (KN230_CSR_INTR_SII | KN230_CSR_INTR_LANCE)) == 0) cpu_interrupt_ack(cpu, r2); } @@ -730,34 +835,35 @@ if (isa) { if (assrt) - m->jazz_data->isa_int_asserted |= irq; + m->md_int.jazz_data->isa_int_asserted |= irq; else - m->jazz_data->isa_int_asserted &= ~irq; + m->md_int.jazz_data->isa_int_asserted &= ~irq; } else { if (assrt) - m->jazz_data->int_asserted |= irq; + m->md_int.jazz_data->int_asserted |= irq; else - m->jazz_data->int_asserted &= ~irq; + m->md_int.jazz_data->int_asserted &= ~irq; } - /* debug(" %08x %08x\n", m->jazz_data->int_asserted, - m->jazz_data->int_enable_mask); */ - /* debug(" %08x %08x\n", m->jazz_data->isa_int_asserted, - m->jazz_data->isa_int_enable_mask); */ + /* debug(" %08x %08x\n", m->md_int.jazz_data->int_asserted, + m->md_int.jazz_data->int_enable_mask); */ + /* debug(" %08x %08x\n", m->md_int.jazz_data->isa_int_asserted, + m->md_int.jazz_data->isa_int_enable_mask); */ - if (m->jazz_data->int_asserted /* & m->jazz_data->int_enable_mask */ - & ~0x8000 ) + if (m->md_int.jazz_data->int_asserted + /* & m->md_int.jazz_data->int_enable_mask */ & ~0x8000 ) cpu_interrupt(cpu, 3); else cpu_interrupt_ack(cpu, 3); - if (m->jazz_data->isa_int_asserted & m->jazz_data->isa_int_enable_mask) + if (m->md_int.jazz_data->isa_int_asserted & + m->md_int.jazz_data->isa_int_enable_mask) cpu_interrupt(cpu, 4); else cpu_interrupt_ack(cpu, 4); /* TODO: this "15" (0x8000) is the timer... fix this? */ - if (m->jazz_data->int_asserted & 0x8000) + if (m->md_int.jazz_data->int_asserted & 0x8000) cpu_interrupt(cpu, 6); else cpu_interrupt_ack(cpu, 6); @@ -782,9 +888,9 @@ giu_irq = irq_nr - 32; if (assrt) - m->vr41xx_data->giuint |= (1 << giu_irq); + m->md_int.vr41xx_data->giuint |= (1 << giu_irq); else - m->vr41xx_data->giuint &= ~(1 << giu_irq); + m->md_int.vr41xx_data->giuint &= ~(1 << giu_irq); } /* TODO: This is wrong. What about GIU bit 8? */ @@ -792,7 +898,8 @@ if (irq_nr != 8) { /* If any GIU bit is asserted, then assert the main GIU interrupt: */ - if (m->vr41xx_data->giuint & m->vr41xx_data->giumask) + if (m->md_int.vr41xx_data->giuint & + m->md_int.vr41xx_data->giumask) vr41xx_interrupt(m, cpu, 8 + 8, 1); else vr41xx_interrupt(m, cpu, 8 + 8, 0); @@ -803,25 +910,25 @@ if (irq_nr < 16) { if (assrt) - m->vr41xx_data->sysint1 |= (1 << irq_nr); + m->md_int.vr41xx_data->sysint1 |= (1 << irq_nr); else - m->vr41xx_data->sysint1 &= ~(1 << irq_nr); + m->md_int.vr41xx_data->sysint1 &= ~(1 << irq_nr); } else if (irq_nr < 32) { irq_nr -= 16; if (assrt) - m->vr41xx_data->sysint2 |= (1 << irq_nr); + m->md_int.vr41xx_data->sysint2 |= (1 << irq_nr); else - m->vr41xx_data->sysint2 &= ~(1 << irq_nr); + m->md_int.vr41xx_data->sysint2 &= ~(1 << irq_nr); } /* TODO: Which hardware interrupt pin? */ /* debug(" sysint1=%04x mask=%04x, sysint2=%04x mask=%04x\n", - m->vr41xx_data->sysint1, m->vr41xx_data->msysint1, - m->vr41xx_data->sysint2, m->vr41xx_data->msysint2); */ + m->md_int.vr41xx_data->sysint1, m->md_int.vr41xx_data->msysint1, + m->md_int.vr41xx_data->sysint2, m->md_int.vr41xx_data->msysint2); */ - if ((m->vr41xx_data->sysint1 & m->vr41xx_data->msysint1) | - (m->vr41xx_data->sysint2 & m->vr41xx_data->msysint2)) + if ((m->md_int.vr41xx_data->sysint1 & m->md_int.vr41xx_data->msysint1) | + (m->md_int.vr41xx_data->sysint2 & m->md_int.vr41xx_data->msysint2)) cpu_interrupt(cpu, 2); else cpu_interrupt_ack(cpu, 2); @@ -830,37 +937,69 @@ /* * Playstation 2 interrupt routine: + * + * irq_nr = 8 + x normal irq x + * 8 + 16 + y dma irq y + * 8 + 32 + 0 sbus irq 0 (pcmcia) + * 8 + 32 + 1 sbus irq 1 (usb) */ void ps2_interrupt(struct machine *m, struct cpu *cpu, int irq_nr, int assrt) { irq_nr -= 8; debug("ps2_interrupt(): irq_nr=0x%x assrt=%i\n", irq_nr, assrt); - if (assrt) { - /* OR into the INTR: */ - if (irq_nr < 0x10000) - m->ps2_data->intr |= irq_nr; + if (irq_nr >= 32) { + int msk = 0; + switch (irq_nr - 32) { + case 0: /* PCMCIA: */ + msk = 0x100; + break; + case 1: /* USB: */ + msk = 0x400; + break; + default: + fatal("ps2_interrupt(): bad irq_nr %i\n", irq_nr); + } + + if (assrt) + m->md_int.ps2_data->sbus_smflg |= msk; else - m->ps2_data->dmac_reg[0x601] |= (irq_nr >> 16); + m->md_int.ps2_data->sbus_smflg &= ~msk; - /* Assert interrupt: TODO: masks */ - if (irq_nr >= 0x10000) - cpu_interrupt(cpu, 3); + if (m->md_int.ps2_data->sbus_smflg != 0) + cpu_interrupt(cpu, 8 + 1); else - cpu_interrupt(cpu, 2); + cpu_interrupt_ack(cpu, 8 + 1); + return; + } + + if (assrt) { + /* OR into the INTR: */ + if (irq_nr < 16) + m->md_int.ps2_data->intr |= (1 << irq_nr); + else + m->md_int.ps2_data->dmac_reg[0x601] |= + (1 << (irq_nr-16)); } else { /* AND out of the INTR: */ - if (irq_nr < 0x10000) - m->ps2_data->intr &= ~irq_nr; + if (irq_nr < 16) + m->md_int.ps2_data->intr &= ~(1 << irq_nr); else - m->ps2_data->dmac_reg[0x601] &= ~(irq_nr >> 16); - - /* TODO: masks */ - if ((m->ps2_data->intr & 0xffff) == 0) - cpu_interrupt_ack(cpu, 2); - if ((m->ps2_data->dmac_reg[0x601] & 0xffff) == 0) - cpu_interrupt_ack(cpu, 3); + m->md_int.ps2_data->dmac_reg[0x601] &= + ~(1 << (irq_nr-16)); } + + /* TODO: Hm? How about the mask? */ + if (m->md_int.ps2_data->intr /* & m->md_int.ps2_data->imask */ ) + cpu_interrupt(cpu, 2); + else + cpu_interrupt_ack(cpu, 2); + + /* TODO: mask? */ + if (m->md_int.ps2_data->dmac_reg[0x601] & 0xffff) + cpu_interrupt(cpu, 3); + else + cpu_interrupt_ack(cpu, 3); } @@ -889,36 +1028,36 @@ int ms = irq_nr / 64; uint32_t new = 1 << ms; if (assrt) - m->sgi_ip22_data->reg[4] |= new; + m->md_int.sgi_ip22_data->reg[4] |= new; else - m->sgi_ip22_data->reg[4] &= ~new; + m->md_int.sgi_ip22_data->reg[4] &= ~new; /* TODO: is this enough? */ irq_nr &= 63; } if (irq_nr < 32) { if (assrt) - m->sgi_ip22_data->reg[0] |= newmask; + m->md_int.sgi_ip22_data->reg[0] |= newmask; else - m->sgi_ip22_data->reg[0] &= ~newmask; + m->md_int.sgi_ip22_data->reg[0] &= ~newmask; } else { if (assrt) - m->sgi_ip22_data->reg[2] |= newmask; + m->md_int.sgi_ip22_data->reg[2] |= newmask; else - m->sgi_ip22_data->reg[2] &= ~newmask; + m->md_int.sgi_ip22_data->reg[2] &= ~newmask; } /* Read stat and mask for local0: */ - stat = m->sgi_ip22_data->reg[0]; - mask = m->sgi_ip22_data->reg[1]; + stat = m->md_int.sgi_ip22_data->reg[0]; + mask = m->md_int.sgi_ip22_data->reg[1]; if ((stat & mask) == 0) cpu_interrupt_ack(cpu, 2); else cpu_interrupt(cpu, 2); /* Read stat and mask for local1: */ - stat = m->sgi_ip22_data->reg[2]; - mask = m->sgi_ip22_data->reg[3]; + stat = m->md_int.sgi_ip22_data->reg[2]; + mask = m->md_int.sgi_ip22_data->reg[3]; if ((stat & mask) == 0) cpu_interrupt_ack(cpu, 3); else @@ -950,9 +1089,9 @@ newmask = (int64_t)1 << irq_nr; if (assrt) - m->sgi_ip30_data->isr |= newmask; + m->md_int.sgi_ip30_data->isr |= newmask; else - m->sgi_ip30_data->isr &= ~newmask; + m->md_int.sgi_ip30_data->isr &= ~newmask; just_assert_and_such: @@ -962,8 +1101,8 @@ cpu_interrupt_ack(cpu, 5); cpu_interrupt_ack(cpu, 6); - stat = m->sgi_ip30_data->isr; - mask = m->sgi_ip30_data->imask0; + stat = m->md_int.sgi_ip30_data->isr; + mask = m->md_int.sgi_ip30_data->imask0; if ((stat & mask) & 0x000000000000ffffULL) cpu_interrupt(cpu, 2); @@ -994,16 +1133,33 @@ * interrupt 2 should be asserted. * * TODO: how should all this be done nicely? - * - * TODO: mace interrupt mask */ uint64_t crime_addr = CRIME_INTSTAT; - uint64_t mace_addr = 0x14; - uint64_t crime_interrupts, crime_interrupts_mask, mace_interrupts; + uint64_t mace_addr = 0x10; + uint64_t crime_interrupts, crime_interrupts_mask; + uint64_t mace_interrupts, mace_interrupt_mask; unsigned int i; unsigned char x[8]; + /* Read current MACE interrupt assertions: */ + memcpy(x, m->md_int.ip32.mace_data->reg + mace_addr, + sizeof(uint64_t)); + mace_interrupts = 0; + for (i=0; imd_int.ip32.mace_data->reg + mace_addr + 8, + sizeof(uint64_t)); + mace_interrupt_mask = 0; + for (i=0; imace_data->reg + mace_addr, sizeof(uint32_t)); - mace_interrupts = 0; - for (i=0; i> (i*8); - memcpy(m->mace_data->reg + mace_addr, x, sizeof(uint32_t)); - irq_nr = MACE_PERIPH_SERIAL; - if (mace_interrupts == 0) + if ((mace_interrupts & mace_interrupt_mask) == 0) assrt = 0; else assrt = 1; @@ -1043,37 +1185,28 @@ /* Hopefully _MISC and _SERIAL will not be both on at the same time. */ if (irq_nr & MACE_PERIPH_MISC) { - /* Read current MACE interrupt bits: */ - memcpy(x, m->mace_data->reg + mace_addr, sizeof(uint32_t)); - mace_interrupts = 0; - for (i=0; i> (i*8); - memcpy(m->mace_data->reg + mace_addr, x, sizeof(uint32_t)); - irq_nr = MACE_PERIPH_MISC; - if (mace_interrupts == 0) + if ((mace_interrupts & mace_interrupt_mask) == 0) assrt = 0; else assrt = 1; } + /* Write back MACE interrupt assertions: */ + for (i=0; i> (i*8); + memcpy(m->md_int.ip32.mace_data->reg + mace_addr, x, sizeof(uint64_t)); + /* Read CRIME_INTSTAT: */ - memcpy(x, m->crime_data->reg + crime_addr, sizeof(uint64_t)); + memcpy(x, m->md_int.ip32.crime_data->reg + crime_addr, + sizeof(uint64_t)); crime_interrupts = 0; - for (i=0; i<8; i++) { - /* SGI is big-endian... */ + for (i=0; i> (i*8); - memcpy(m->crime_data->reg + crime_addr, x, sizeof(uint64_t)); + memcpy(m->md_int.ip32.crime_data->reg + crime_addr, x, + sizeof(uint64_t)); /* Read CRIME_INTMASK: */ - memcpy(x, m->crime_data->reg + CRIME_INTMASK, sizeof(uint64_t)); + memcpy(x, m->md_int.ip32.crime_data->reg + CRIME_INTMASK, + sizeof(uint64_t)); crime_interrupts_mask = 0; - for (i=0; i<8; i++) { + for (i=0; iau1x00_ic_data->request0_int |= ms; + m->md_int.au1x00_ic_data->request0_int |= ms; else - m->au1x00_ic_data->request0_int &= ~ms; + m->md_int.au1x00_ic_data->request0_int &= ~ms; /* TODO: Controller 1 */ } - if ((m->au1x00_ic_data->request0_int & - m->au1x00_ic_data->mask) != 0) + if ((m->md_int.au1x00_ic_data->request0_int & + m->md_int.au1x00_ic_data->mask) != 0) cpu_interrupt(cpu, 2); else cpu_interrupt_ack(cpu, 2); @@ -1153,6 +1289,145 @@ } +/* + * Malta (evbmips) interrupts: + * + * ISA interrupts. + * (irq_nr = 16+8 can be used to just reassert/deassert interrupts.) + */ +void malta_interrupt(struct machine *m, struct cpu *cpu, int irq_nr, + int assrt) +{ + int mask; + + irq_nr -= 8; + mask = 1 << (irq_nr & 7); + + if (irq_nr < 8) { + if (assrt) + m->md_int.isa_pic_data.pic1->irr |= mask; + else + m->md_int.isa_pic_data.pic1->irr &= ~mask; + } else if (irq_nr < 16) { + if (assrt) + m->md_int.isa_pic_data.pic2->irr |= mask; + else + m->md_int.isa_pic_data.pic2->irr &= ~mask; + } + + /* Any interrupt assertions on PIC2 go to irq 2 on PIC1 */ + /* (TODO: don't hardcode this here) */ + if (m->md_int.isa_pic_data.pic2->irr & + ~m->md_int.isa_pic_data.pic2->ier) + m->md_int.isa_pic_data.pic1->irr |= 0x04; + else + m->md_int.isa_pic_data.pic1->irr &= ~0x04; + + /* Now, PIC1: */ + if (m->md_int.isa_pic_data.pic1->irr & + ~m->md_int.isa_pic_data.pic1->ier) + cpu_interrupt(cpu, 2); + else + cpu_interrupt_ack(cpu, 2); + + /* printf("MALTA: pic1.irr=0x%02x ier=0x%02x pic2.irr=0x%02x " + "ier=0x%02x\n", m->md_int.isa_pic_data.pic1->irr, + m->md_int.isa_pic_data.pic1->ier, + m->md_int.isa_pic_data.pic2->irr, + m->md_int.isa_pic_data.pic2->ier); */ +} + + +/* + * Cobalt interrupts: + * + * (irq_nr = 8 + 16 can be used to just reassert/deassert interrupts.) + */ +void cobalt_interrupt(struct machine *m, struct cpu *cpu, int irq_nr, int assrt) +{ + int mask; + + irq_nr -= 8; + mask = 1 << (irq_nr & 7); + + if (irq_nr < 8) { + if (assrt) + m->md_int.isa_pic_data.pic1->irr |= mask; + else + m->md_int.isa_pic_data.pic1->irr &= ~mask; + } else if (irq_nr < 16) { + if (assrt) + m->md_int.isa_pic_data.pic2->irr |= mask; + else + m->md_int.isa_pic_data.pic2->irr &= ~mask; + } + + /* Any interrupt assertions on PIC2 go to irq 2 on PIC1 */ + /* (TODO: don't hardcode this here) */ + if (m->md_int.isa_pic_data.pic2->irr & + ~m->md_int.isa_pic_data.pic2->ier) + m->md_int.isa_pic_data.pic1->irr |= 0x04; + else + m->md_int.isa_pic_data.pic1->irr &= ~0x04; + + /* Now, PIC1: */ + if (m->md_int.isa_pic_data.pic1->irr & + ~m->md_int.isa_pic_data.pic1->ier) + cpu_interrupt(cpu, 6); + else + cpu_interrupt_ack(cpu, 6); + + /* printf("COBALT: pic1.irr=0x%02x ier=0x%02x pic2.irr=0x%02x " + "ier=0x%02x\n", m->md_int.isa_pic_data.pic1->irr, + m->md_int.isa_pic_data.pic1->ier, + m->md_int.isa_pic_data.pic2->irr, + m->md_int.isa_pic_data.pic2->ier); */ +} + + +/* + * x86 (PC) interrupts: + * + * (irq_nr = 16 can be used to just reassert/deassert interrupts.) + */ +void x86_pc_interrupt(struct machine *m, struct cpu *cpu, int irq_nr, int assrt) +{ + int mask = 1 << (irq_nr & 7); + + if (irq_nr < 8) { + if (assrt) + m->md.pc.pic1->irr |= mask; + else + m->md.pc.pic1->irr &= ~mask; + } else if (irq_nr < 16) { + if (m->md.pc.pic2 == NULL) { + fatal("x86_pc_interrupt(): pic2 used (irq_nr = %i), " + "but we are emulating an XT?\n", irq_nr); + return; + } + if (assrt) + m->md.pc.pic2->irr |= mask; + else + m->md.pc.pic2->irr &= ~mask; + } + + if (m->md.pc.pic2 != NULL) { + /* Any interrupt assertions on PIC2 go to irq 2 on PIC1 */ + /* (TODO: don't hardcode this here) */ + if (m->md.pc.pic2->irr & ~m->md.pc.pic2->ier) + m->md.pc.pic1->irr |= 0x04; + else + m->md.pc.pic1->irr &= ~0x04; + } + + /* Now, PIC1: */ + if (m->md.pc.pic1->irr & ~m->md.pc.pic1->ier) + cpu->cd.x86.interrupt_asserted = 1; + else + cpu->cd.x86.interrupt_asserted = 0; +} + + /**************************************************************************** * * * Machine dependant Initialization routines * @@ -1172,6 +1447,7 @@ int i, j; struct memory *mem; char tmpstr[1000]; + struct cons_data *cons_data; /* DECstation: */ char *framebuffer_console_name, *serial_console_name; @@ -1195,21 +1471,14 @@ int hpcmips_fb_ysize_mem = 0; /* ARCBIOS stuff: */ - struct arcbios_spb arcbios_spb; - struct arcbios_spb_64 arcbios_spb_64; - struct arcbios_sysid arcbios_sysid; - struct arcbios_dsp_stat arcbios_dsp_stat; - uint64_t mem_base, mem_count; - uint64_t system = 0; uint64_t sgi_ram_offset = 0; - uint64_t arc_reserved; int arc_wordlen = sizeof(uint32_t); - char *short_machine_name = NULL; char *eaddr_string = "eaddr=10:20:30:40:50:60"; /* nonsense */ unsigned char macaddr[6]; /* Generic bootstring stuff: */ - int bootdev_id = diskimage_bootdev(machine); + int bootdev_type = 0; + int bootdev_id; char *bootstr = NULL; char *bootarg = NULL; char *init_bootpath; @@ -1224,6 +1493,8 @@ struct cpu *cpu = machine->cpus[machine->bootstrap_cpu]; + bootdev_id = diskimage_bootdev(machine, &bootdev_type); + mem = cpu->mem; machine->machine_name = NULL; @@ -1249,6 +1520,7 @@ printf("\nNo emulation type specified.\n"); exit(1); +#ifdef ENABLE_MIPS case MACHINE_BAREMIPS: /* * A "bare" MIPS test machine. @@ -1261,21 +1533,40 @@ case MACHINE_TESTMIPS: /* - * A MIPS test machine (which happens to work with my - * thesis work). + * A MIPS test machine (which happens to work with the + * code in my master's thesis). :-) + * + * IRQ map: + * 7 CPU counter + * 6 SMP IPIs + * 5 not used yet + * 4 not used yet + * 3 ethernet + * 2 serial console */ cpu->byte_order = EMUL_BIG_ENDIAN; machine->machine_name = "MIPS test machine"; - machine->main_console_handle = dev_cons_init( - machine, mem, DEV_CONS_ADDRESS, "console", 2); + snprintf(tmpstr, sizeof(tmpstr), "cons addr=0x%llx irq=2", + (long long)DEV_CONS_ADDRESS); + cons_data = device_add(machine, tmpstr); + machine->main_console_handle = cons_data->console_handle; - snprintf(tmpstr, sizeof(tmpstr) - 1, "mp addr=0x%llx", + snprintf(tmpstr, sizeof(tmpstr), "mp addr=0x%llx", (long long)DEV_MP_ADDRESS); device_add(machine, tmpstr); - fb = dev_fb_init(machine, mem, 0x12000000, VFB_GENERIC, - 640,480, 640,480, 24, "generic", 1); + fb = dev_fb_init(machine, mem, DEV_FB_ADDRESS, VFB_GENERIC, + 640,480, 640,480, 24, "testmips generic"); + + snprintf(tmpstr, sizeof(tmpstr), "disk addr=0x%llx", + (long long)DEV_DISK_ADDRESS); + device_add(machine, tmpstr); + + snprintf(tmpstr, sizeof(tmpstr), "ether addr=0x%llx irq=3", + (long long)DEV_ETHER_ADDRESS); + device_add(machine, tmpstr); + break; case MACHINE_DEC: @@ -1317,7 +1608,7 @@ */ fb = dev_fb_init(machine, mem, KN01_PHYS_FBUF_START, color_fb_flag? VFB_DEC_VFB02 : VFB_DEC_VFB01, - 0,0,0,0,0, color_fb_flag? "VFB02":"VFB01", 1); + 0,0,0,0,0, color_fb_flag? "VFB02":"VFB01"); dev_colorplanemask_init(mem, KN01_PHYS_COLMASK_START, &fb->color_plane_mask); dev_vdac_init(mem, KN01_SYS_VDAC, fb->rgb_palette, color_fb_flag); dev_le_init(machine, mem, KN01_SYS_LANCE, KN01_SYS_LANCE_B_START, KN01_SYS_LANCE_B_END, KN01_INT_LANCE, 4*1048576); @@ -1407,7 +1698,7 @@ dev_mc146818_init(machine, mem, KN02_SYS_CLOCK, KN02_INT_CLOCK, MC146818_DEC, 1); - machine->kn02_csr = + machine->md_int.kn02_csr = dev_kn02_init(cpu, mem, KN02_SYS_CSR); framebuffer_console_name = "osconsole=0,7"; @@ -1441,7 +1732,7 @@ * asc0 at ioasic0 offset 0x300000: NCR53C94, 25MHz, SCSI ID 7 (0x1c300000) slot 12 * dma for asc0 (0x1c380000) slot 14 */ - machine->dec_ioasic_data = dev_dec_ioasic_init(cpu, mem, 0x1c000000, 0); + machine->md_int.dec_ioasic_data = dev_dec_ioasic_init(cpu, mem, 0x1c000000, 0); dev_le_init(machine, mem, 0x1c0c0000, 0, 0, KMIN_INTR_LANCE +8, 4*65536); dev_scc_init(machine, mem, 0x1c100000, KMIN_INTR_SCC_0 +8, machine->use_x11, 0, 1); dev_scc_init(machine, mem, 0x1c180000, KMIN_INTR_SCC_1 +8, machine->use_x11, 1, 1); @@ -1507,14 +1798,14 @@ * mcclock0 at ioasic0 offset 0x200000: mc146818 or compatible (0x1fa00000) * asc0 at ioasic0 offset 0x300000: NCR53C94, 25MHz, SCSI ID 7 (0x1fb00000) */ - machine->dec_ioasic_data = dev_dec_ioasic_init(cpu, mem, 0x1f800000, 0); + machine->md_int.dec_ioasic_data = dev_dec_ioasic_init(cpu, mem, 0x1f800000, 0); dev_le_init(machine, mem, KN03_SYS_LANCE, 0, 0, KN03_INTR_LANCE +8, 4*65536); - machine->dec_ioasic_data->dma_func[3] = dev_scc_dma_func; - machine->dec_ioasic_data->dma_func_extra[2] = dev_scc_init(machine, mem, KN03_SYS_SCC_0, KN03_INTR_SCC_0 +8, machine->use_x11, 0, 1); - machine->dec_ioasic_data->dma_func[2] = dev_scc_dma_func; - machine->dec_ioasic_data->dma_func_extra[3] = dev_scc_init(machine, mem, KN03_SYS_SCC_1, KN03_INTR_SCC_1 +8, machine->use_x11, 1, 1); + machine->md_int.dec_ioasic_data->dma_func[3] = dev_scc_dma_func; + machine->md_int.dec_ioasic_data->dma_func_extra[2] = dev_scc_init(machine, mem, KN03_SYS_SCC_0, KN03_INTR_SCC_0 +8, machine->use_x11, 0, 1); + machine->md_int.dec_ioasic_data->dma_func[2] = dev_scc_dma_func; + machine->md_int.dec_ioasic_data->dma_func_extra[3] = dev_scc_init(machine, mem, KN03_SYS_SCC_1, KN03_INTR_SCC_1 +8, machine->use_x11, 1, 1); dev_mc146818_init(machine, mem, KN03_SYS_CLOCK, KN03_INT_RTC, MC146818_DEC, 1); dev_asc_init(machine, mem, KN03_SYS_SCSI, @@ -1573,9 +1864,9 @@ * Clock uses interrupt 3 (shared with XMI?). */ - machine->dec5800_csr = dev_dec5800_init(machine, mem, 0x10000000); + machine->md_int.dec5800_csr = dev_dec5800_init(machine, mem, 0x10000000); dev_decbi_init(mem, 0x10000000); - dev_ssc_init(machine, mem, 0x10140000, 2, machine->use_x11, &machine->dec5800_csr->csr); + dev_ssc_init(machine, mem, 0x10140000, 2, machine->use_x11, &machine->md_int.dec5800_csr->csr); dev_decxmi_init(mem, 0x11800000); dev_deccca_init(mem, DEC_DECCCA_BASEADDR); @@ -1644,7 +1935,7 @@ * asc0 at ioasic0 offset 0x300000: NCR53C94, 25MHz, SCSI ID 7 (0x1c300000) * xcfb0 at tc0 slot 2 offset 0x0: 1024x768x8 built-in framebuffer (0xa000000) */ - machine->dec_ioasic_data = dev_dec_ioasic_init(cpu, mem, 0x1c000000, 0); + machine->md_int.dec_ioasic_data = dev_dec_ioasic_init(cpu, mem, 0x1c000000, 0); /* TURBOchannel slots (0 and 1): */ dev_turbochannel_init(machine, mem, 0, @@ -1749,9 +2040,9 @@ dev_le_init(machine, mem, KN230_SYS_LANCE, KN230_SYS_LANCE_B_START, KN230_SYS_LANCE_B_END, KN230_CSR_INTR_LANCE, 4*1048576); dev_sii_init(machine, mem, KN230_SYS_SII, KN230_SYS_SII_B_START, KN230_SYS_SII_B_END, KN230_CSR_INTR_SII); - snprintf(tmpstr, sizeof(tmpstr) - 1, + snprintf(tmpstr, sizeof(tmpstr), "kn230 addr=0x%llx", (long long)KN230_SYS_ICSR); - machine->kn230_csr = device_add(machine, tmpstr); + machine->md_int.kn230_csr = device_add(machine, tmpstr); serial_console_name = "osconsole=0"; break; @@ -1830,19 +2121,20 @@ #if 0 if (machine->machine_subtype == MACHINE_DEC_PMAX_3100) - strcpy(bootpath, "rz(0,0,0)"); + strlcpy(bootpath, "rz(0,0,0)", sizeof(bootpath)); else #endif - strcpy(bootpath, "5/rz1/"); + strlcpy(bootpath, "5/rz1/", sizeof(bootpath)); if (bootdev_id < 0 || machine->force_netboot) { /* tftp boot: */ - strcpy(bootpath, "5/tftp/"); + strlcpy(bootpath, "5/tftp/", sizeof(bootpath)); bootpath[0] = '0' + boot_net_boardnumber; } else { /* disk boot: */ bootpath[0] = '0' + boot_scsi_boardnumber; - if (diskimage_is_a_tape(machine, bootdev_id)) + if (diskimage_is_a_tape(machine, bootdev_id, + bootdev_type)) bootpath[2] = 't'; bootpath[4] = '0' + bootdev_id; } @@ -1850,11 +2142,17 @@ init_bootpath = bootpath; } - bootarg = malloc(strlen(init_bootpath) + - strlen(machine->boot_kernel_filename) + 1 + - strlen(machine->boot_string_argument) + 1); - strcpy(bootarg, init_bootpath); - strcat(bootarg, machine->boot_kernel_filename); + bootarg = malloc(BOOTARG_BUFLEN); + if (bootarg == NULL) { + fprintf(stderr, "out of memory\n"); + exit(1); + } + strlcpy(bootarg, init_bootpath, BOOTARG_BUFLEN); + if (strlcat(bootarg, machine->boot_kernel_filename, + BOOTARG_BUFLEN) > BOOTARG_BUFLEN) { + fprintf(stderr, "bootarg truncated?\n"); + exit(1); + } bootstr = "boot"; @@ -1869,8 +2167,12 @@ cpu->cd.mips.gpr[MIPS_GPR_A0] --; if (machine->boot_string_argument[0] != '\0') { - strcat(bootarg, " "); - strcat(bootarg, machine->boot_string_argument); + strlcat(bootarg, " ", BOOTARG_BUFLEN); + if (strlcat(bootarg, machine->boot_string_argument, + BOOTARG_BUFLEN) >= BOOTARG_BUFLEN) { + fprintf(stderr, "bootstr truncated?\n"); + exit(1); + } } xx.a.common.next = (char *)&xx.b - (char *)&xx; @@ -1879,7 +2181,7 @@ xx.b.common.next = (char *)&xx.c - (char *)&xx.b; xx.b.common.type = BTINFO_BOOTPATH; - strcpy(xx.b.bootpath, bootstr); + strlcpy(xx.b.bootpath, bootstr, sizeof(xx.b.bootpath)); xx.c.common.next = 0; xx.c.common.type = BTINFO_SYMTAB; @@ -1920,25 +2222,28 @@ */ { char tmps[300]; - sprintf(tmps, "cca=%x", + snprintf(tmps, sizeof(tmps), "cca=%x", (int)(DEC_DECCCA_BASEADDR + 0xa0000000ULL)); add_environment_string(cpu, tmps, &addr); } /* These are needed for Sprite to boot: */ { - char tmps[300]; + char tmps[500]; - sprintf(tmps, "boot=%s", bootarg); + snprintf(tmps, sizeof(tmps), "boot=%s", bootarg); + tmps[sizeof(tmps)-1] = '\0'; add_environment_string(cpu, tmps, &addr); - sprintf(tmps, "bitmap=0x%x", (uint32_t)(( + snprintf(tmps, sizeof(tmps), "bitmap=0x%x", (uint32_t)(( DEC_MEMMAP_ADDR + sizeof(memmap.pagesize)) & 0xffffffffULL)); + tmps[sizeof(tmps)-1] = '\0'; add_environment_string(cpu, tmps, &addr); - sprintf(tmps, "bitmaplen=0x%x", + snprintf(tmps, sizeof(tmps), "bitmaplen=0x%x", machine->physical_ram_in_mb * 1048576 / 4096 / 8); + tmps[sizeof(tmps)-1] = '\0'; add_environment_string(cpu, tmps, &addr); } @@ -1974,12 +2279,25 @@ * 4 Tulip 1 * 5 16550 UART (serial console) * 6 VIA southbridge PIC - * 7 PCI + * 7 PCI (Note: Not used. The PCI controller + * interrupts at ISA interrupt 9.) */ -/* dev_XXX_init(cpu, mem, 0x10000000, machine->emulated_hz); */ + + /* ISA interrupt controllers: */ + snprintf(tmpstr, sizeof(tmpstr), "8259 irq=24 addr=0x10000020"); + machine->md_int.isa_pic_data.pic1 = device_add(machine, tmpstr); + snprintf(tmpstr, sizeof(tmpstr), "8259 irq=24 addr=0x100000a0"); + machine->md_int.isa_pic_data.pic2 = device_add(machine, tmpstr); + machine->md_interrupt = cobalt_interrupt; + dev_mc146818_init(machine, mem, 0x10000070, 0, MC146818_PC_CMOS, 4); - machine->main_console_handle = dev_ns16550_init(machine, mem, - 0x1c800000, 5, 1, 1, "serial console"); + + machine->main_console_handle = (size_t) + device_add(machine, "ns16550 irq=5 addr=0x1c800000 name2=tty0 in_use=1"); + +#if 0 + device_add(machine, "ns16550 irq=0 addr=0x1f000010 name2=tty1 in_use=0"); +#endif /* * According to NetBSD/cobalt: @@ -1990,8 +2308,10 @@ * pcib0 at pci0 dev 9 function 0, VIA Technologies VT82C586 (Apollo VP) PCI-ISA Bridge, rev 37 * pciide0 at pci0 dev 9 function 1: VIA Technologies VT82C586 (Apollo VP) ATA33 cr * tlp1 at pci0 dev 12 function 0: DECchip 21143 Ethernet, pass 4.1 + * + * The PCI controller interrupts at ISA interrupt 9. */ - pci_data = dev_gt_init(machine, mem, 0x14000000, 2, 6); /* 7 for PCI, not 6? */ + pci_data = dev_gt_init(machine, mem, 0x14000000, 2, 8 + 9, 11); /* bus_pci_add(machine, pci_data, mem, 0, 7, 0, pci_dec21143_init, pci_dec21143_rr); */ bus_pci_add(machine, pci_data, mem, 0, 8, 0, NULL, NULL); /* PCI_VENDOR_SYMBIOS, PCI_PRODUCT_SYMBIOS_860 */ bus_pci_add(machine, pci_data, mem, 0, 9, 0, pci_vt82c586_isa_init, pci_vt82c586_isa_rr); @@ -2002,14 +2322,15 @@ * NetBSD/cobalt expects memsize in a0, but it seems that what * it really wants is the end of memory + 0x80000000. * - * The bootstring should be stored starting 512 bytes before end - * of physical ram. + * The bootstring is stored 512 bytes before the end of + * physical ram. */ - cpu->cd.mips.gpr[MIPS_GPR_A0] = machine->physical_ram_in_mb * 1048576 + 0x80000000; + cpu->cd.mips.gpr[MIPS_GPR_A0] = + machine->physical_ram_in_mb * 1048576 + 0xffffffff80000000ULL; bootstr = "root=/dev/hda1 ro"; /* bootstr = "nfsroot=/usr/cobalt/"; */ - store_string(cpu, 0xffffffff80000000ULL + - machine->physical_ram_in_mb * 1048576 - 512, bootstr); + /* TODO: bootarg, and/or automagic boot device detection */ + store_string(cpu, cpu->cd.mips.gpr[MIPS_GPR_A0] - 512, bootstr); break; case MACHINE_HPCMIPS: @@ -2046,10 +2367,11 @@ hpcmips_fb_bits = 15; hpcmips_fb_encoding = BIFB_D16_0000; - machine->main_console_handle = dev_ns16550_init( - machine, mem, 0xa008680, 0, 4, - machine->use_x11? 0 : 1, "serial console"); /* TODO: irq? */ - machine->vr41xx_data = dev_vr41xx_init(machine, mem, 4131); + /* TODO: irq? */ + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=0 addr=0x0a008680 addr_mult=4 in_use=%i", machine->use_x11? 0 : 1); + machine->main_console_handle = (size_t)device_add(machine, tmpstr); + + machine->md_int.vr41xx_data = dev_vr41xx_init(machine, mem, 4131); machine->md_interrupt = vr41xx_interrupt; store_32bit_word_in_host(cpu, (unsigned char *)&hpc_bootinfo.platid_cpu, @@ -2077,10 +2399,11 @@ hpcmips_fb_bits = 16; hpcmips_fb_encoding = BIFB_D16_0000; - machine->main_console_handle = dev_ns16550_init( - machine, mem, 0xa008680, 0, 4, - machine->use_x11? 0 : 1, "serial console"); /* TODO: irq? */ - machine->vr41xx_data = dev_vr41xx_init(machine, mem, 4121); + /* TODO: irq? */ + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=0 addr=0x0a008680 addr_mult=4 in_use=%i", machine->use_x11? 0 : 1); + machine->main_console_handle = (size_t)device_add(machine, tmpstr); + + machine->md_int.vr41xx_data = dev_vr41xx_init(machine, mem, 4121); machine->md_interrupt = vr41xx_interrupt; store_32bit_word_in_host(cpu, (unsigned char *)&hpc_bootinfo.platid_cpu, @@ -2108,7 +2431,7 @@ hpcmips_fb_bits = 16; hpcmips_fb_encoding = BIFB_D16_0000; - machine->vr41xx_data = dev_vr41xx_init(machine, mem, 4121); + machine->md_int.vr41xx_data = dev_vr41xx_init(machine, mem, 4121); machine->md_interrupt = vr41xx_interrupt; store_32bit_word_in_host(cpu, (unsigned char *)&hpc_bootinfo.platid_cpu, @@ -2136,7 +2459,7 @@ hpcmips_fb_bits = 16; hpcmips_fb_encoding = BIFB_D16_0000; - machine->vr41xx_data = dev_vr41xx_init(machine, mem, 4121); + machine->md_int.vr41xx_data = dev_vr41xx_init(machine, mem, 4121); machine->md_interrupt = vr41xx_interrupt; store_32bit_word_in_host(cpu, (unsigned char *)&hpc_bootinfo.platid_cpu, @@ -2164,7 +2487,7 @@ hpcmips_fb_bits = 16; hpcmips_fb_encoding = BIFB_D16_0000; - machine->vr41xx_data = dev_vr41xx_init(machine, mem, 4121); + machine->md_int.vr41xx_data = dev_vr41xx_init(machine, mem, 4121); machine->md_interrupt = vr41xx_interrupt; store_32bit_word_in_host(cpu, (unsigned char *)&hpc_bootinfo.platid_cpu, @@ -2192,7 +2515,7 @@ hpcmips_fb_bits = 16; hpcmips_fb_encoding = BIFB_D16_0000; - machine->vr41xx_data = dev_vr41xx_init(machine, mem, 4121); + machine->md_int.vr41xx_data = dev_vr41xx_init(machine, mem, 4121); machine->md_interrupt = vr41xx_interrupt; store_32bit_word_in_host(cpu, (unsigned char *)&hpc_bootinfo.platid_cpu, @@ -2220,15 +2543,15 @@ hpcmips_fb_bits = 4; hpcmips_fb_encoding = BIFB_D4_M2L_F; - machine->vr41xx_data = dev_vr41xx_init(machine, mem, 4181); + machine->md_int.vr41xx_data = dev_vr41xx_init(machine, mem, 4181); machine->md_interrupt = vr41xx_interrupt; /* TODO: Hm... irq 17 according to linux, but VRIP_INTR_SIU (=9) here? */ { int x; - x = dev_ns16550_init(machine, mem, 0x0c000010, - 8 + VRIP_INTR_SIU, 1, 1, "serial 0"); + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=%i addr=0x0c000010", 8 + VRIP_INTR_SIU); + x = (size_t)device_add(machine, tmpstr); if (!machine->use_x11) machine->main_console_handle = x; @@ -2251,7 +2574,7 @@ break; case MACHINE_HPCMIPS_IBM_WORKPAD_Z50: /* 131 MHz VR4121 */ - machine->machine_name = "Agenda VR3"; + machine->machine_name = "IBM Workpad Z50"; /* TODO: */ hpcmips_fb_addr = 0xa000000; hpcmips_fb_xsize = 640; @@ -2261,7 +2584,7 @@ hpcmips_fb_bits = 16; hpcmips_fb_encoding = BIFB_D16_0000; - machine->vr41xx_data = dev_vr41xx_init(machine, mem, 4121); + machine->md_int.vr41xx_data = dev_vr41xx_init(machine, mem, 4121); machine->md_interrupt = vr41xx_interrupt; store_32bit_word_in_host(cpu, (unsigned char *)&hpc_bootinfo.platid_cpu, @@ -2284,7 +2607,7 @@ if (machine->use_x11) machine->main_console_handle = - machine->vr41xx_data->kiu_console_handle; + machine->md_int.vr41xx_data->kiu_console_handle; /* NetBSD/hpcmips and possibly others expects the following: */ @@ -2354,7 +2677,7 @@ dev_fb_init(machine, mem, hpcmips_fb_addr, VFB_HPCMIPS, hpcmips_fb_xsize, hpcmips_fb_ysize, hpcmips_fb_xsize_mem, hpcmips_fb_ysize_mem, - hpcmips_fb_bits, "HPCmips", 0); + hpcmips_fb_bits, "HPCmips"); /* NetBSD/hpcmips uses framebuffer at physical address 0x8.......: */ @@ -2384,27 +2707,47 @@ * ohci0: OHCI version 1.0 */ + machine->md_int.ps2_data = dev_ps2_stuff_init(machine, mem, 0x10000000); device_add(machine, "ps2_gs addr=0x12000000"); - machine->ps2_data = dev_ps2_stuff_init(machine, mem, 0x10000000); - dev_ps2_ohci_init(cpu, mem, 0x1f801600); + device_add(machine, "ps2_ether addr=0x14001000"); dev_ram_init(mem, 0x1c000000, 4 * 1048576, DEV_RAM_RAM, 0); /* TODO: how much? */ + /* irq = 8 + 32 + 1 (SBUS/USB) */ + device_add(machine, "ohci addr=0x1f801600 irq=41"); machine->md_interrupt = ps2_interrupt; add_symbol_name(&machine->symbol_context, - PLAYSTATION2_SIFBIOS, 0x10000, "[SIFBIOS entry]", 0); + PLAYSTATION2_SIFBIOS, 0x10000, "[SIFBIOS entry]", 0, 0); store_32bit_word(cpu, PLAYSTATION2_BDA + 0, PLAYSTATION2_SIFBIOS); store_buf(cpu, PLAYSTATION2_BDA + 4, "PS2b", 4); -#if 0 - /* Harddisk controller present flag: */ - store_32bit_word(cpu, 0xa0000000 + machine->physical_ram_in_mb*1048576 - 0x1000 + 0x0, 0x100); - dev_ps2_spd_init(machine, mem, 0x14000000); -#endif + /* Set the Harddisk controller present flag, if either + disk 0 or 1 is present: */ + if (diskimage_exist(machine, 0, DISKIMAGE_IDE) || + diskimage_exist(machine, 1, DISKIMAGE_IDE)) { + store_32bit_word(cpu, 0xa0000000 + machine->physical_ram_in_mb*1048576 - 0x1000 + 0x0, 0x100); + dev_ps2_spd_init(machine, mem, 0x14000000); + } store_32bit_word(cpu, 0xa0000000 + machine->physical_ram_in_mb*1048576 - 0x1000 + 0x4, PLAYSTATION2_OPTARGS); - bootstr = "root=/dev/hda1 crtmode=vesa0,60"; - store_string(cpu, PLAYSTATION2_OPTARGS, bootstr); + { + int tmplen = 1000; + char *tmp = malloc(tmplen); + if (tmp == NULL) { + fprintf(stderr, "out of memory\n"); + exit(1); + } + + strlcpy(tmp, "root=/dev/hda1 crtmode=vesa0,60", tmplen); + + if (machine->boot_string_argument[0]) + snprintf(tmp+strlen(tmp), tmplen-strlen(tmp), + " %s", machine->boot_string_argument); + tmp[tmplen-1] = '\0'; + + bootstr = tmp; + store_string(cpu, PLAYSTATION2_OPTARGS, bootstr); + } /* TODO: netbsd's bootinfo.h, for symbolic names */ { @@ -2424,10 +2767,7 @@ } /* "BOOTINFO_PCMCIA_TYPE" in NetBSD's bootinfo.h. This contains the sbus controller type. */ - store_32bit_word(cpu, 0xa0000000 + machine->physical_ram_in_mb*1048576 - 0x1000 + 0x1c, 3); - - /* TODO: Is this necessary? */ - cpu->cd.mips.gpr[MIPS_GPR_SP] = 0x80007f00; + store_32bit_word(cpu, 0xa0000000 + machine->physical_ram_in_mb*1048576 - 0x1000 + 0x1c, 2); break; @@ -2441,25 +2781,16 @@ * detailed list of IP ("Inhouse Processor") model numbers. * (Or http://hardware.majix.org/computers/sgi/iptable.shtml) */ - machine->machine_name = malloc(500); + machine->machine_name = malloc(MACHINE_NAME_MAXBUF); if (machine->machine_name == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } - short_machine_name = malloc(500); - if (short_machine_name == NULL) { - fprintf(stderr, "out of memory\n"); - exit(1); - } if (machine->machine_type == MACHINE_SGI) { cpu->byte_order = EMUL_BIG_ENDIAN; - sprintf(short_machine_name, "SGI-IP%i", machine->machine_subtype); - sprintf(machine->machine_name, "SGI-IP%i", machine->machine_subtype); - - /* Super-special case for IP24: */ - if (machine->machine_subtype == 24) - sprintf(short_machine_name, "SGI-IP22"); + snprintf(machine->machine_name, MACHINE_NAME_MAXBUF, + "SGI-IP%i", machine->machine_subtype); sgi_ram_offset = 1048576 * machine->memory_offset_in_mb; @@ -2477,15 +2808,16 @@ } } else { cpu->byte_order = EMUL_LITTLE_ENDIAN; - sprintf(short_machine_name, "ARC"); - sprintf(machine->machine_name, "ARC"); + snprintf(machine->machine_name, + MACHINE_NAME_MAXBUF, "ARC"); } if (machine->machine_type == MACHINE_SGI) { /* TODO: Other SGI machine types? */ switch (machine->machine_subtype) { case 12: - strcat(machine->machine_name, " (Iris Indigo IP12)"); + strlcat(machine->machine_name, + " (Iris Indigo IP12)", MACHINE_NAME_MAXBUF); /* TODO */ /* 33 MHz R3000, according to http://www.irisindigo.com/ */ @@ -2493,7 +2825,8 @@ break; case 19: - strcat(machine->machine_name, " (Everest IP19)"); + strlcat(machine->machine_name, + " (Everest IP19)", MACHINE_NAME_MAXBUF); machine->main_console_handle = dev_zs_init(machine, mem, 0x1fbd9830, 0, 1, "serial zs"); /* serial? netbsd? */ dev_scc_init(machine, mem, 0x10086000, 0, machine->use_x11, 0, 8); /* serial? irix? */ @@ -2513,7 +2846,8 @@ break; case 20: - strcat(machine->machine_name, " (Indigo)"); + strlcat(machine->machine_name, + " (Indigo)", MACHINE_NAME_MAXBUF); /* * Guesses based on NetBSD 2.0 beta, 20040606. @@ -2533,7 +2867,7 @@ */ /* int0 at mainbus0 addr 0x1fb801c0 */ - machine->sgi_ip20_data = dev_sgi_ip20_init(cpu, mem, DEV_SGI_IP20_BASE); + machine->md_int.sgi_ip20_data = dev_sgi_ip20_init(cpu, mem, DEV_SGI_IP20_BASE); /* imc0 at mainbus0 addr 0x1fa00000: revision 0: TODO (or in dev_sgi_ip20?) */ @@ -2558,7 +2892,8 @@ break; case 21: - strcat(machine->machine_name, " (uknown SGI-IP21 ?)"); /* TODO */ + strlcat(machine->machine_name, /* TODO */ + " (uknown SGI-IP21 ?)", MACHINE_NAME_MAXBUF); /* NOTE: Special case for arc_wordlen: */ arc_wordlen = sizeof(uint64_t); @@ -2568,11 +2903,15 @@ case 22: case 24: if (machine->machine_subtype == 22) { - strcat(machine->machine_name, " (Indy, Indigo2, Challenge S; Full-house)"); - machine->sgi_ip22_data = dev_sgi_ip22_init(machine, mem, 0x1fbd9000, 0); + strlcat(machine->machine_name, + " (Indy, Indigo2, Challenge S; Full-house)", + MACHINE_NAME_MAXBUF); + machine->md_int.sgi_ip22_data = dev_sgi_ip22_init(machine, mem, 0x1fbd9000, 0); } else { - strcat(machine->machine_name, " (Indy, Indigo2, Challenge S; Guiness)"); - machine->sgi_ip22_data = dev_sgi_ip22_init(machine, mem, 0x1fbd9880, 1); + strlcat(machine->machine_name, + " (Indy, Indigo2, Challenge S; Guiness)", + MACHINE_NAME_MAXBUF); + machine->md_int.sgi_ip22_data = dev_sgi_ip22_init(machine, mem, 0x1fbd9880, 1); } /* @@ -2615,7 +2954,7 @@ /* Not supported by NetBSD 1.6.2, but by 2.0_BETA: */ j = dev_pckbc_init(machine, mem, 0x1fbd9840, PCKBC_8242, - 0, 0, machine->use_x11); /* TODO: irq numbers */ + 0, 0, machine->use_x11, 0); /* TODO: irq numbers */ if (machine->use_x11) machine->main_console_handle = j; @@ -2644,7 +2983,8 @@ case 25: /* NOTE: Special case for arc_wordlen: */ arc_wordlen = sizeof(uint64_t); - strcat(machine->machine_name, " (Everest IP25)"); + strlcat(machine->machine_name, + " (Everest IP25)", MACHINE_NAME_MAXBUF); /* serial? irix? */ dev_scc_init(machine, mem, @@ -2665,15 +3005,17 @@ case 26: /* NOTE: Special case for arc_wordlen: */ arc_wordlen = sizeof(uint64_t); - strcat(machine->machine_name, - " (uknown SGI-IP26 ?)"); /* TODO */ + strlcat(machine->machine_name, + " (uknown SGI-IP26 ?)", + MACHINE_NAME_MAXBUF); /* TODO */ machine->main_console_handle = dev_zs_init(machine, mem, 0x1fbd9830, 0, 1, "zs console"); break; case 27: - strcat(machine->machine_name, - " (Origin 200/2000, Onyx2)"); + strlcat(machine->machine_name, + " (Origin 200/2000, Onyx2)", + MACHINE_NAME_MAXBUF); arc_wordlen = sizeof(uint64_t); /* 2 cpus per node */ @@ -2684,7 +3026,8 @@ case 28: /* NOTE: Special case for arc_wordlen: */ arc_wordlen = sizeof(uint64_t); - strcat(machine->machine_name, " (Impact Indigo2 ?)"); + strlcat(machine->machine_name, + " (Impact Indigo2 ?)", MACHINE_NAME_MAXBUF); device_add(machine, "random addr=0x1fbe0000, len=1"); @@ -2694,9 +3037,10 @@ case 30: /* NOTE: Special case for arc_wordlen: */ arc_wordlen = sizeof(uint64_t); - strcat(machine->machine_name, " (Octane)"); + strlcat(machine->machine_name, + " (Octane)", MACHINE_NAME_MAXBUF); - machine->sgi_ip30_data = dev_sgi_ip30_init(machine, mem, 0x0ff00000); + machine->md_int.sgi_ip30_data = dev_sgi_ip30_init(machine, mem, 0x0ff00000); machine->md_interrupt = sgi_ip30_interrupt; dev_ram_init(mem, 0xa0000000ULL, @@ -2718,17 +3062,20 @@ * program dumps something there, but it doesn't look like * readable text. (TODO) */ - machine->main_console_handle = dev_ns16550_init(machine, mem, 0x1f620170, 0, 1, - machine->use_x11? 0 : 1, "serial 0"); /* TODO: irq? */ - dev_ns16550_init(machine, mem, 0x1f620178, 0, 1, - 0, "serial 1"); /* TODO: irq? */ + + /* TODO: irq! */ + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=0 addr=0x1f620170 name2=tty0 in_use=%i", machine->use_x11? 0 : 1); + machine->main_console_handle = (size_t)device_add(machine, tmpstr); + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=0 addr=0x1f620178 name2=tty1 in_use=0"); + device_add(machine, tmpstr); /* MardiGras graphics: */ device_add(machine, "sgi_mardigras addr=0x1c000000"); break; case 32: - strcat(machine->machine_name, " (O2)"); + strlcat(machine->machine_name, + " (O2)", MACHINE_NAME_MAXBUF); /* TODO: Find out where the physical ram is actually located. */ dev_ram_init(mem, 0x07ffff00ULL, 256, DEV_RAM_MIRROR, 0x03ffff00); @@ -2739,7 +3086,7 @@ dev_ram_init(mem, 0x20000000ULL, 128 * 1048576, DEV_RAM_MIRROR, 0x00000000); dev_ram_init(mem, 0x40000000ULL, 128 * 1048576, DEV_RAM_MIRROR, 0x10000000); - machine->crime_data = dev_crime_init(machine, mem, 0x14000000, 2, machine->use_x11); /* crime0 */ + machine->md_int.ip32.crime_data = dev_crime_init(machine, mem, 0x14000000, 2, machine->use_x11); /* crime0 */ dev_sgi_mte_init(mem, 0x15000000); /* mte ??? memory thing */ dev_sgi_gbe_init(machine, mem, 0x16000000); /* gbe? framebuffer? */ @@ -2766,7 +3113,7 @@ * 1f3a0000 mcclock0 */ - machine->mace_data = dev_mace_init(mem, 0x1f310000, 2); + machine->md_int.ip32.mace_data = dev_mace_init(mem, 0x1f310000, 2); machine->md_interrupt = sgi_ip32_interrupt; /* @@ -2783,35 +3130,39 @@ * intr 7 = MACE_PCI_BRIDGE */ +#if 0 i = dev_pckbc_init(machine, mem, 0x1f320000, PCKBC_8242, 0x200 + MACE_PERIPH_MISC, - 0x800 + MACE_PERIPH_MISC, machine->use_x11); + 0x800 + MACE_PERIPH_MISC, machine->use_x11, 0); /* keyb+mouse (mace irq numbers) */ +#endif net_generate_unique_mac(machine, macaddr); - eaddr_string = malloc(30); + eaddr_string = malloc(ETHERNET_STRING_MAXLEN); if (eaddr_string == NULL) { fprintf(stderr, "out of memory\n"); exit(1); } - sprintf(eaddr_string, "eaddr=%02x:%02x:" - "%02x:%02x:%02x:%02x", + snprintf(eaddr_string, ETHERNET_STRING_MAXLEN, + "eaddr=%02x:%02x:%02x:%02x:%02x:%02x", macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]); - dev_sgi_mec_init(machine, mem, 0x1f280000, MACE_ETHERNET, macaddr); + dev_sgi_mec_init(machine, mem, 0x1f280000, + MACE_ETHERNET, macaddr); dev_sgi_ust_init(mem, 0x1f340000); /* ust? */ - j = dev_ns16550_init(machine, mem, 0x1f390000, - (1<<20) + MACE_PERIPH_SERIAL, 0x100, - machine->use_x11? 0 : 1, "serial 0"); /* com0 */ - dev_ns16550_init(machine, mem, 0x1f398000, - (1<<26) + MACE_PERIPH_SERIAL, 0x100, - 0, "serial 1"); /* com1 */ - + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=%i addr=0x1f390000 addr_mult=0x100 in_use=%i name2=tty0", + (1<<20) + MACE_PERIPH_SERIAL, machine->use_x11? 0 : 1); + j = (size_t)device_add(machine, tmpstr); + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=%i addr=0x1f398000 addr_mult=0x100 in_use=%i name2=tty1", + (1<<26) + MACE_PERIPH_SERIAL, 0); + device_add(machine, tmpstr); +#if 0 if (machine->use_x11) machine->main_console_handle = i; else +#endif machine->main_console_handle = j; dev_mc146818_init(machine, mem, 0x1f3a0000, (1<<8) + MACE_PERIPH_MISC, MC146818_SGI, 0x40); /* mcclock0 */ @@ -2827,14 +3178,25 @@ pci_data = dev_macepci_init(mem, 0x1f080000, MACE_PCI_BRIDGE); /* macepci0 */ /* bus_pci_add(machine, pci_data, mem, 0, 0, 0, pci_ne2000_init, pci_ne2000_rr); TODO */ -#if 1 - bus_pci_add(machine, pci_data, mem, 0, 1, 0, pci_ahc_init, pci_ahc_rr); -#endif + + /* TODO: make this nicer */ + if (diskimage_exist(machine, 0, DISKIMAGE_SCSI) || + diskimage_exist(machine, 1, DISKIMAGE_SCSI) || + diskimage_exist(machine, 2, DISKIMAGE_SCSI) || + diskimage_exist(machine, 3, DISKIMAGE_SCSI) || + diskimage_exist(machine, 4, DISKIMAGE_SCSI) || + diskimage_exist(machine, 5, DISKIMAGE_SCSI) || + diskimage_exist(machine, 6, DISKIMAGE_SCSI) || + diskimage_exist(machine, 7, DISKIMAGE_SCSI)) + bus_pci_add(machine, pci_data, mem, 0, 1, 0, pci_ahc_init, pci_ahc_rr); + + /* TODO: second ahc */ /* bus_pci_add(machine, pci_data, mem, 0, 2, 0, pci_ahc_init, pci_ahc_rr); */ break; case 35: - strcat(machine->machine_name, " (Origin 3000)"); + strlcat(machine->machine_name, + " (Origin 3000)", MACHINE_NAME_MAXBUF); /* 4 cpus per node */ machine->main_console_handle = @@ -2842,7 +3204,8 @@ 0, 1, "zs console"); break; case 53: - strcat(machine->machine_name, " (Origin 350)"); + strlcat(machine->machine_name, + " (Origin 350)", MACHINE_NAME_MAXBUF); /* * According to http://kumba.drachentekh.net/xml/myguide.html * Origin 350, Tezro IP53 R16000 @@ -2869,13 +3232,17 @@ switch (machine->machine_subtype) { case MACHINE_ARC_NEC_RD94: - strcat(machine->machine_name, " (NEC-RD94, NEC RISCstation 2250)"); + strlcat(machine->machine_name, + " (NEC-RD94, NEC RISCstation 2250)", + MACHINE_NAME_MAXBUF); break; case MACHINE_ARC_NEC_R94: - strcat(machine->machine_name, " (NEC-R94; NEC RISCstation 2200)"); + strlcat(machine->machine_name, " (NEC-R94; NEC RISCstation 2200)", + MACHINE_NAME_MAXBUF); break; case MACHINE_ARC_NEC_R96: - strcat(machine->machine_name, " (NEC-R96; NEC Express RISCserver)"); + strlcat(machine->machine_name, " (NEC-R96; NEC Express RISCserver)", + MACHINE_NAME_MAXBUF); break; } @@ -2886,11 +3253,12 @@ device_add(machine, "sn addr=0x80001000 irq=0"); dev_mc146818_init(machine, mem, 0x80004000ULL, 0, MC146818_ARC_NEC, 1); - i = dev_pckbc_init(machine, mem, 0x80005000ULL, PCKBC_8042, 0, 0, machine->use_x11); - j = dev_ns16550_init(machine, mem, 0x80006000ULL, - 3, 1, machine->use_x11? 0 : 1, "serial 0"); /* com0 */ - dev_ns16550_init(machine, mem, 0x80007000ULL, - 0, 1, 0, "serial 1"); /* com1 */ + i = dev_pckbc_init(machine, mem, 0x80005000ULL, PCKBC_8042, 0, 0, machine->use_x11, 0); + + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=3 addr=0x80006000 in_use=%i name2=tty0", machine->use_x11? 0 : 1); + j = (size_t)device_add(machine, tmpstr); + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=0 addr=0x80007000 in_use=%i name2=tty1", 0); + device_add(machine, tmpstr); if (machine->use_x11) machine->main_console_handle = i; @@ -2910,7 +3278,7 @@ case MACHINE_ARC_NEC_R96: dev_fb_init(machine, mem, 0x100e00000ULL, VFB_GENERIC, 640,480, 1024,480, - 8, "necvdfrb", 1); + 8, "necvdfrb"); break; } break; @@ -2929,7 +3297,9 @@ * Parallel at "start: 0x 0 18c10278, length: 0x1000, level: 5, vector: 5" */ - strcat(machine->machine_name, " (NEC-R98; NEC RISCserver 4200)"); + strlcat(machine->machine_name, + " (NEC-R98; NEC RISCserver 4200)", + MACHINE_NAME_MAXBUF); /* * Windows NT access stuff at these addresses: @@ -2985,28 +3355,44 @@ switch (machine->machine_subtype) { case MACHINE_ARC_JAZZ_PICA: - strcat(machine->machine_name, " (Microsoft Jazz, Acer PICA-61)"); + strlcat(machine->machine_name, " (Microsoft Jazz, Acer PICA-61)", + MACHINE_NAME_MAXBUF); break; case MACHINE_ARC_JAZZ_MAGNUM: - strcat(machine->machine_name, " (Microsoft Jazz, MIPS Magnum)"); + strlcat(machine->machine_name, " (Microsoft Jazz, MIPS Magnum)", + MACHINE_NAME_MAXBUF); break; default: fatal("error in machine.c. jazz\n"); exit(1); } - machine->jazz_data = device_add(machine, + machine->md_int.jazz_data = device_add(machine, "jazz addr=0x80000000"); machine->md_interrupt = jazz_interrupt; + i = dev_pckbc_init(machine, mem, 0x80005000ULL, + PCKBC_JAZZ, 8 + 6, 8 + 7, machine->use_x11, 0); + + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=16 addr=0x80006000 in_use=%i name2=tty0", machine->use_x11? 0 : 1); + j = (size_t)device_add(machine, tmpstr); + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=17 addr=0x80007000 in_use=%i name2=tty1", 0); + device_add(machine, tmpstr); + + if (machine->use_x11) + machine->main_console_handle = i; + else + machine->main_console_handle = j; + switch (machine->machine_subtype) { case MACHINE_ARC_JAZZ_PICA: - dev_vga_init(machine, mem, - 0x400b8000ULL, 0x600003c0ULL, - ARC_CONSOLE_MAX_X, ARC_CONSOLE_MAX_Y, machine->machine_name); - arcbios_console_init(cpu, 0x400b8000ULL, - 0x600003c0ULL, ARC_CONSOLE_MAX_X, - ARC_CONSOLE_MAX_Y); + if (machine->use_x11) { + dev_vga_init(machine, mem, + 0x400a0000ULL, 0x600003c0ULL, + machine->machine_name); + arcbios_console_init(machine, + 0x400b8000ULL, 0x600003c0ULL); + } break; case MACHINE_ARC_JAZZ_MAGNUM: /* PROM mirror? */ @@ -3017,7 +3403,7 @@ /* control at 0x60100000? */ dev_fb_init(machine, mem, 0x60200000ULL, VFB_GENERIC, 1024,768, 1024,768, - 8, "VXL", 1); + 8, "VXL"); break; } @@ -3026,27 +3412,14 @@ dev_asc_init(machine, mem, 0x80002000ULL, 8 + 5, NULL, DEV_ASC_PICA, - dev_jazz_dma_controller, machine->jazz_data); + dev_jazz_dma_controller, + machine->md_int.jazz_data); device_add(machine, "fdc addr=0x80003000, irq=0"); dev_mc146818_init(machine, mem, 0x80004000ULL, 2, MC146818_ARC_JAZZ, 1); - i = dev_pckbc_init(machine, mem, 0x80005000ULL, - PCKBC_JAZZ, 8 + 6, 8 + 7, machine->use_x11); - - j = dev_ns16550_init(machine, mem, - 0x80006000ULL, 8 + 8, 1, - machine->use_x11? 0 : 1, "serial 0"); - dev_ns16550_init(machine, mem, - 0x80007000ULL, 8 + 9, 1, 0, "serial 1"); - - if (machine->use_x11) - machine->main_console_handle = i; - else - machine->main_console_handle = j; - #if 0 Not yet. dev_wdc_init(machine, mem, 0x900001f0ULL, 8+16 + 14, 0); @@ -3064,9 +3437,10 @@ * See http://mail-index.netbsd.org/port-arc/2000/10/18/0001.html. */ - strcat(machine->machine_name, " (Microsoft Jazz, Olivetti M700)"); + strlcat(machine->machine_name, " (Microsoft Jazz, Olivetti M700)", + MACHINE_NAME_MAXBUF); - machine->jazz_data = device_add(machine, + machine->md_int.jazz_data = device_add(machine, "jazz addr=0x80000000"); machine->md_interrupt = jazz_interrupt; @@ -3076,13 +3450,13 @@ i = 0; /* TODO: Yuck! */ #if 0 i = dev_pckbc_init(machine, mem, 0x80005000ULL, - PCKBC_JAZZ, 8 + 6, 8 + 7, machine->use_x11); + PCKBC_JAZZ, 8 + 6, 8 + 7, machine->use_x11, 0); #endif - j = dev_ns16550_init(machine, mem, - 0x80006000ULL, 8 + 8, 1, - machine->use_x11? 0 : 1, "serial 0"); - dev_ns16550_init(machine, mem, - 0x80007000ULL, 8 + 9, 1, 0, "serial 1"); + + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=16 addr=0x80006000 in_use=%i name2=tty0", machine->use_x11? 0 : 1); + j = (size_t)device_add(machine, tmpstr); + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=17 addr=0x80007000 in_use=%i name2=tty1", 0); + device_add(machine, tmpstr); if (machine->use_x11) machine->main_console_handle = i; @@ -3102,19 +3476,14 @@ * http://mail-index.netbsd.org/port-arc/2000/10/14/0000.html */ - strcat(machine->machine_name, " (Deskstation Tyne)"); - - dev_vga_init(machine, mem, 0x1000b8000ULL, 0x9000003c0ULL, - ARC_CONSOLE_MAX_X, ARC_CONSOLE_MAX_Y, machine->machine_name); + strlcat(machine->machine_name, " (Deskstation Tyne)", + MACHINE_NAME_MAXBUF); - arcbios_console_init(cpu, 0x1000b8000ULL, - 0x9000003c0ULL, ARC_CONSOLE_MAX_X, - ARC_CONSOLE_MAX_Y); - - i = dev_ns16550_init(machine, mem, 0x9000003f8ULL, 0, 1, machine->use_x11? 0 : 1, "serial 0"); - dev_ns16550_init(machine, mem, 0x9000002f8ULL, 0, 1, 0, "serial 1"); - dev_ns16550_init(machine, mem, 0x9000003e8ULL, 0, 1, 0, "serial 2"); - dev_ns16550_init(machine, mem, 0x9000002e8ULL, 0, 1, 0, "serial 3"); + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=0 addr=0x9000003f8 in_use=%i name2=tty0", machine->use_x11? 0 : 1); + i = (size_t)device_add(machine, tmpstr); + device_add(machine, "ns16550 irq=0 addr=0x9000002f8 in_use=0 name2=tty1"); + device_add(machine, "ns16550 irq=0 addr=0x9000003e8 in_use=0 name2=tty2"); + device_add(machine, "ns16550 irq=0 addr=0x9000002e8 in_use=0 name2=tty3"); dev_mc146818_init(machine, mem, 0x900000070ULL, 2, MC146818_PC_CMOS, 1); @@ -3125,13 +3494,20 @@ #endif /* PC kbd */ j = dev_pckbc_init(machine, mem, 0x900000060ULL, - PCKBC_8042, 0, 0, machine->use_x11); + PCKBC_8042, 0, 0, machine->use_x11, 0); if (machine->use_x11) machine->main_console_handle = j; else machine->main_console_handle = i; + if (machine->use_x11) { + dev_vga_init(machine, mem, 0x1000a0000ULL, + 0x9000003c0ULL, machine->machine_name); + + arcbios_console_init(machine, + 0x1000b8000ULL, 0x9000003c0ULL); + } break; default: @@ -3141,732 +3517,24 @@ } } - - if (!machine->prom_emulation) - goto no_arc_prom_emulation; /* TODO: ugly */ - - /* * This is important: :-) * - * TODO: There should not be any use of - * ARCBIOS before this statement. - */ - if (arc_wordlen == sizeof(uint64_t)) - arcbios_set_64bit_mode(1); - - if (machine->physical_ram_in_mb < 16) - fprintf(stderr, "WARNING! The ARC platform specification doesn't allow less than 16 MB of RAM. Continuing anyway.\n"); - - arcbios_set_default_exception_handler(cpu); - - memset(&arcbios_sysid, 0, sizeof(arcbios_sysid)); - if (machine->machine_type == MACHINE_SGI) { - /* Vendor ID, max 8 chars: */ - strncpy(arcbios_sysid.VendorId, "SGI", 3); - switch (machine->machine_subtype) { - case 22: - strncpy(arcbios_sysid.ProductId, - "87654321", 8); /* some kind of ID? */ - break; - case 32: - strncpy(arcbios_sysid.ProductId, "8", 1); - /* 6 or 8 (?) */ - break; - default: - snprintf(arcbios_sysid.ProductId, 8, "IP%i", - machine->machine_subtype); - } - } else { - switch (machine->machine_subtype) { - case MACHINE_ARC_NEC_RD94: - strncpy(arcbios_sysid.VendorId, "NEC W&S", 8); /* NOTE: max 8 chars */ - strncpy(arcbios_sysid.ProductId, "RD94", 4); /* NOTE: max 8 chars */ - break; - case MACHINE_ARC_NEC_R94: - strncpy(arcbios_sysid.VendorId, "NEC W&S", 8); /* NOTE: max 8 chars */ - strncpy(arcbios_sysid.ProductId, "ijkl", 4); /* NOTE: max 8 chars */ - break; - case MACHINE_ARC_NEC_R96: - strncpy(arcbios_sysid.VendorId, "MIPS DUO", 8); /* NOTE: max 8 chars */ - strncpy(arcbios_sysid.ProductId, "blahblah", 8); /* NOTE: max 8 chars */ - break; - case MACHINE_ARC_NEC_R98: - strncpy(arcbios_sysid.VendorId, "NEC W&S", 8); /* NOTE: max 8 chars */ - strncpy(arcbios_sysid.ProductId, "R98", 4); /* NOTE: max 8 chars */ - break; - case MACHINE_ARC_JAZZ_PICA: - strncpy(arcbios_sysid.VendorId, "MIPS MAG", 8);/* NOTE: max 8 chars */ - strncpy(arcbios_sysid.ProductId, "ijkl", 4); /* NOTE: max 8 chars */ - break; - case MACHINE_ARC_JAZZ_MAGNUM: - strncpy(arcbios_sysid.VendorId, "MIPS MAG", 8);/* NOTE: max 8 chars */ - strncpy(arcbios_sysid.ProductId, "ijkl", 4); /* NOTE: max 8 chars */ - break; - case MACHINE_ARC_JAZZ_M700: - strncpy(arcbios_sysid.VendorId, "OLI00000", 8);/* NOTE: max 8 chars */ - strncpy(arcbios_sysid.ProductId, "ijkl", 4); /* NOTE: max 8 chars */ - break; - case MACHINE_ARC_DESKTECH_TYNE: - strncpy(arcbios_sysid.VendorId, "DESKTECH", 8);/* NOTE: max 8 chars */ - strncpy(arcbios_sysid.ProductId, "ijkl", 4); /* NOTE: max 8 chars */ - break; - default: - fatal("error in machine.c sysid\n"); - exit(1); - } - } - store_buf(cpu, SGI_SYSID_ADDR, (char *)&arcbios_sysid, sizeof(arcbios_sysid)); - - arcbios_get_dsp_stat(cpu, &arcbios_dsp_stat); - store_buf(cpu, ARC_DSPSTAT_ADDR, (char *)&arcbios_dsp_stat, sizeof(arcbios_dsp_stat)); - - /* - * The first 12 MBs of RAM are simply reserved... this simplifies things a lot. - * If there's more than 512MB of RAM, it has to be split in two, according to - * the ARC spec. This code creates a number of chunks of at most 512MB each. - * - * NOTE: The region of physical address space between 0x10000000 and 0x1fffffff - * (256 - 512 MB) is usually occupied by memory mapped devices, so that portion is "lost". - */ - - arc_reserved = 0x2000; - if (machine->machine_type == MACHINE_SGI) - arc_reserved = 0x4000; - - arcbios_add_memory_descriptor(cpu, 0, arc_reserved, ARCBIOS_MEM_FirmwarePermanent); - arcbios_add_memory_descriptor(cpu, sgi_ram_offset + arc_reserved, 0x60000-arc_reserved, ARCBIOS_MEM_FirmwareTemporary); - - mem_base = 12; - mem_base += sgi_ram_offset / 1048576; - - while (mem_base < machine->physical_ram_in_mb + sgi_ram_offset/1048576) { - mem_count = machine->physical_ram_in_mb + sgi_ram_offset/1048576 - - mem_base; - - /* Skip the 256-512MB region (for devices) */ - if (mem_base < 256 && mem_base + mem_count > 256) { - mem_count = 256-mem_base; - } - - /* At most 512MB per descriptor (at least the first 512MB - must be separated this way, according to the ARC spec) */ - if (mem_count > 512) - mem_count = 512; - - arcbios_add_memory_descriptor(cpu, mem_base * 1048576, - mem_count * 1048576, ARCBIOS_MEM_FreeMemory); - - mem_base += mem_count; - - /* Skip the devices: */ - if (mem_base == 256) - mem_base = 512; - } - - - /* - * Components: (this is an example of what a system could look like) - * - * [System] - * [CPU] (one for each cpu) - * [FPU] (one for each cpu) - * [CPU Caches] - * [Memory] - * [Ethernet] - * [Serial] - * [SCSI] - * [Disk] - * - * Here's a good list of what hardware is in different IP-models: - * http://www.linux-mips.org/archives/linux-mips/2001-03/msg00101.html - */ - - if (machine->machine_name == NULL) - fatal("ERROR: machine_name == NULL\n"); - if (short_machine_name == NULL) - fatal("ERROR: short_machine_name == NULL\n"); - - switch (machine->machine_type) { - case MACHINE_SGI: - system = arcbios_addchild_manual(cpu, COMPONENT_CLASS_SystemClass, COMPONENT_TYPE_ARC, - 0, 1, 2, 0, 0xffffffff, short_machine_name, 0 /* ROOT */ , NULL, 0); - break; - default: - /* ARC: */ - switch (machine->machine_subtype) { - case MACHINE_ARC_NEC_RD94: - system = arcbios_addchild_manual(cpu, COMPONENT_CLASS_SystemClass, COMPONENT_TYPE_ARC, - 0, 1, 2, 0, 0xffffffff, "NEC-RD94", 0 /* ROOT */ , NULL, 0); - break; - case MACHINE_ARC_NEC_R94: - system = arcbios_addchild_manual(cpu, COMPONENT_CLASS_SystemClass, COMPONENT_TYPE_ARC, - 0, 1, 2, 0, 0xffffffff, "NEC-R94", 0 /* ROOT */ , NULL, 0); - break; - case MACHINE_ARC_NEC_R96: - system = arcbios_addchild_manual(cpu, COMPONENT_CLASS_SystemClass, COMPONENT_TYPE_ARC, - 0, 1, 2, 0, 0xffffffff, "NEC-R96", 0 /* ROOT */ , NULL, 0); - break; - case MACHINE_ARC_NEC_R98: - system = arcbios_addchild_manual(cpu, COMPONENT_CLASS_SystemClass, COMPONENT_TYPE_ARC, - 0, 1, 2, 0, 0xffffffff, "NEC-R98", 0 /* ROOT */ , NULL, 0); - break; - case MACHINE_ARC_JAZZ_PICA: - system = arcbios_addchild_manual(cpu, COMPONENT_CLASS_SystemClass, COMPONENT_TYPE_ARC, - 0, 1, 2, 0, 0xffffffff, "PICA-61", 0 /* ROOT */ , NULL, 0); - break; - case MACHINE_ARC_JAZZ_MAGNUM: - system = arcbios_addchild_manual(cpu, COMPONENT_CLASS_SystemClass, COMPONENT_TYPE_ARC, - 0, 1, 2, 0, 0xffffffff, "Microsoft-Jazz", 0 /* ROOT */ , NULL, 0); - break; - case MACHINE_ARC_JAZZ_M700: - system = arcbios_addchild_manual(cpu, COMPONENT_CLASS_SystemClass, COMPONENT_TYPE_ARC, - 0, 1, 2, 0, 0xffffffff, "Microsoft-Jazz", 0 /* ROOT */ , NULL, 0); - break; - case MACHINE_ARC_DESKTECH_TYNE: - system = arcbios_addchild_manual(cpu, COMPONENT_CLASS_SystemClass, COMPONENT_TYPE_ARC, - 0, 1, 2, 0, 0xffffffff, "DESKTECH-TYNE", 0 /* ROOT */ , NULL, 0); - break; - default: - fatal("Unimplemented ARC machine type %i\n", - machine->machine_subtype); - exit(1); - } - } - - - /* - * Common stuff for both SGI and ARC: + * TODO: There should not be any use of ARCBIOS before this + * point. */ - debug("ARC system @ 0x%llx\n", (long long)system); - - for (i=0; incpus; i++) { - uint64_t cpuaddr, fpu=0, picache, pdcache, sdcache=0; - int cache_size, cache_line_size; - unsigned int jj; - char arc_cpu_name[100]; - char arc_fpc_name[105]; - - snprintf(arc_cpu_name, sizeof(arc_cpu_name), - "MIPS-%s", machine->cpu_name); - - if (machine->machine_type == MACHINE_ARC && - machine->machine_subtype == MACHINE_ARC_NEC_R96) - snprintf(arc_cpu_name, sizeof(arc_cpu_name), - "MIPS-%s - Pr 4/5.0, Fp 5/0", - machine->cpu_name); - - arc_cpu_name[sizeof(arc_cpu_name)-1] = 0; - for (jj=0; jj= 'a' && arc_cpu_name[jj] <= 'z') - arc_cpu_name[jj] += ('A' - 'a'); - - strcpy(arc_fpc_name, arc_cpu_name); - strcat(arc_fpc_name, "FPC"); - - cpuaddr = arcbios_addchild_manual(cpu, COMPONENT_CLASS_ProcessorClass, COMPONENT_TYPE_CPU, - 0, 1, 2, i, 0xffffffff, arc_cpu_name, system, NULL, 0); - - /* - * TODO: This was in the ARC specs, but it isn't - * really used by ARC implementations? - * At least SGI-IP32 uses it. - */ - if (machine->machine_type == MACHINE_SGI) - fpu = arcbios_addchild_manual(cpu, COMPONENT_CLASS_ProcessorClass, COMPONENT_TYPE_FPU, - 0, 1, 2, 0, 0xffffffff, arc_fpc_name, cpuaddr, NULL, 0); - - cache_size = DEFAULT_PCACHE_SIZE - 12; - if (machine->cache_picache) - cache_size = machine->cache_picache - 12; - if (cache_size < 0) - cache_size = 0; - - cache_line_size = DEFAULT_PCACHE_LINESIZE; - if (machine->cache_picache_linesize) - cache_line_size = machine->cache_picache_linesize; - if (cache_line_size < 0) - cache_line_size = 0; - - picache = arcbios_addchild_manual(cpu, COMPONENT_CLASS_CacheClass, - COMPONENT_TYPE_PrimaryICache, 0, 1, 2, - /* - * Key bits: 0xXXYYZZZZ - * XX is refill-size. - * Cache line size is 1 << YY, - * Cache size is 4KB << ZZZZ. - */ - 0x01000000 + (cache_line_size << 16) + cache_size, - /* 32 bytes per line, default = 32 KB total */ - 0xffffffff, NULL, cpuaddr, NULL, 0); - - cache_size = DEFAULT_PCACHE_SIZE - 12; - if (machine->cache_pdcache) - cache_size = machine->cache_pdcache - 12; - if (cache_size < 0) - cache_size = 0; - - cache_line_size = DEFAULT_PCACHE_LINESIZE; - if (machine->cache_pdcache_linesize) - cache_line_size = machine->cache_pdcache_linesize; - if (cache_line_size < 0) - cache_line_size = 0; - - pdcache = arcbios_addchild_manual(cpu, COMPONENT_CLASS_CacheClass, - COMPONENT_TYPE_PrimaryDCache, 0, 1, 2, - /* - * Key bits: 0xYYZZZZ - * Cache line size is 1 << YY, - * Cache size is 4KB << ZZZZ. - */ - 0x01000000 + (cache_line_size << 16) + cache_size, - /* 32 bytes per line, default = 32 KB total */ - 0xffffffff, NULL, cpuaddr, NULL, 0); - - if (machine->cache_secondary >= 12) { - cache_size = machine->cache_secondary - 12; - - cache_line_size = 6; /* 64 bytes default */ - if (machine->cache_secondary_linesize) - cache_line_size = machine->cache_secondary_linesize; - if (cache_line_size < 0) - cache_line_size = 0; - - sdcache = arcbios_addchild_manual(cpu, COMPONENT_CLASS_CacheClass, - COMPONENT_TYPE_SecondaryDCache, 0, 1, 2, - /* - * Key bits: 0xYYZZZZ - * Cache line size is 1 << YY, - * Cache size is 4KB << ZZZZ. - */ - 0x01000000 + (cache_line_size << 16) + cache_size, - /* 64 bytes per line, default = 1 MB total */ - 0xffffffff, NULL, cpuaddr, NULL, 0); - } - - debug("ARC cpu%i @ 0x%llx", i, (long long)cpuaddr); - - if (fpu != 0) - debug(" (fpu @ 0x%llx)\n", (long long)fpu); - else - debug("\n"); - - debug(" picache @ 0x%llx, pdcache @ 0x%llx\n", - (long long)picache, (long long)pdcache); - - if (machine->cache_secondary >= 12) - debug(" sdcache @ 0x%llx\n", - (long long)sdcache); - - if (machine->machine_type == MACHINE_SGI) { - /* TODO: Memory amount (and base address?)! */ - uint64_t memory = arcbios_addchild_manual(cpu, COMPONENT_CLASS_MemoryClass, - COMPONENT_TYPE_MemoryUnit, - 0, 1, 2, 0, 0xffffffff, "memory", cpuaddr, NULL, 0); - debug(" memory @ 0x%llx\n", (long long)memory); - } - } + if (machine->prom_emulation) + arcbios_init(machine, arc_wordlen == sizeof(uint64_t), + sgi_ram_offset); + else + goto no_arc_prom_emulation; /* TODO: ugly */ /* - * Other components, and default TLB entries: - * * TODO: How to build the component tree intermixed with * the rest of device initialization? */ - if (machine->machine_type == MACHINE_SGI) { - /* TODO: On which models is this required? */ - mips_coproc_tlb_set_entry(cpu, 0, 1048576*16, - 0xc000000000000000ULL, - 0x0, 1048576*16, - 1, 1, 1, 1, 1, 0, 2, 2); - } - - if (machine->machine_type == MACHINE_ARC && - ( machine->machine_subtype == MACHINE_ARC_NEC_RD94 || - machine->machine_subtype == MACHINE_ARC_NEC_R94 || - machine->machine_subtype == MACHINE_ARC_NEC_R96 )) { - uint64_t jazzbus, eisa, other; - - jazzbus = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_AdapterClass, - COMPONENT_TYPE_MultiFunctionAdapter, - 0, 1, 2, 0, 0xffffffff, "Jazz-Internal Bus", - system, NULL, 0); - - switch (machine->machine_subtype) { - case MACHINE_ARC_NEC_RD94: - case MACHINE_ARC_NEC_R94: - if (machine->use_x11) - arcbios_addchild_manual(cpu, - COMPONENT_CLASS_ControllerClass, - COMPONENT_TYPE_DisplayController, - 0, 1, 2, 0, 0x0, "10110004", - system, NULL, 0); - break; - case MACHINE_ARC_NEC_R96: - if (machine->use_x11) { - uint64_t x; - x = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_ControllerClass, - COMPONENT_TYPE_DisplayController, - COMPONENT_FLAG_ConsoleOut | - COMPONENT_FLAG_Output, - 1, 2, 0, 0x0, "necvdfrb", - jazzbus, NULL, 0); - arcbios_addchild_manual(cpu, - COMPONENT_CLASS_PeripheralClass, - COMPONENT_TYPE_MonitorPeripheral, - COMPONENT_FLAG_ConsoleOut | - COMPONENT_FLAG_Output, - 1, 2, 0, 0xffffffff, "640x480", - x, NULL, 0); - } - - /* TODO: R[D]94 too? */ - eisa = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_AdapterClass, - COMPONENT_TYPE_EISAAdapter, - 0, 1, 2, 0, 0xffffffff, "EISA", - system, NULL, 0); - - other = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_ControllerClass, - COMPONENT_TYPE_OtherController, - 0, 1, 2, 0, 0xffffffff, "NEC1C01", - eisa, NULL, 0); - - break; - } - } - - if (machine->machine_type == MACHINE_ARC && - (machine->machine_subtype == MACHINE_ARC_JAZZ_PICA - || machine->machine_subtype == MACHINE_ARC_JAZZ_MAGNUM)) { - uint64_t jazzbus, ali_s3, vxl; - uint64_t diskcontroller, floppy, kbdctl, kbd; - uint64_t ptrctl, ptr, paral, audio; - uint64_t eisa, scsi; - /* uint64_t serial1, serial2; */ - - jazzbus = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_AdapterClass, - COMPONENT_TYPE_MultiFunctionAdapter, - 0, 1, 2, 0, 0xffffffff, "Jazz-Internal Bus", - system, NULL, 0); - - /* - * DisplayController, needed by NetBSD: - * TODO: NetBSD still doesn't use it :( - */ - switch (machine->machine_subtype) { - case MACHINE_ARC_JAZZ_PICA: - /* Default TLB entries on PICA-61: */ - - /* 7: 256K, asid: 0x0, v: 0xe1000000, - p0: 0xfff00000(2.VG), p1: 0x0(0..G) */ - mips_coproc_tlb_set_entry(cpu, 7, 262144, - 0xffffffffe1000000ULL, - 0x0fff00000ULL, 0, - 1, 0, 0, 0, 1, 0, 2, 0); - - /* 8: 64K, asid: 0x0, v: 0xe0000000, - p0: 0x80000000(2DVG), p1: 0x0(0..G) */ - mips_coproc_tlb_set_entry(cpu, 8, 65536, - 0xffffffffe0000000ULL, - 0x080000000ULL, 0, - 1, 0, 1, 0, 1, 0, 2, 0); - - /* 9: 64K, asid: 0x0, v: 0xe00e0000, - p0: 0x800e0000(2DVG), p1: 0x800f0000(2DVG) */ - mips_coproc_tlb_set_entry(cpu, 9, 65536, - (uint64_t)0xffffffffe00e0000ULL, - (uint64_t)0x0800e0000ULL, - (uint64_t)0x0800f0000ULL, - 1, 1, 1, 1, 1, 0, 2, 2); - - /* 10: 4K, asid: 0x0, v: 0xe0100000, - p0: 0xf0000000(2DVG), p1: 0x0(0..G) */ - mips_coproc_tlb_set_entry(cpu, 10, 4096, - (uint64_t)0xffffffffe0100000ULL, - (uint64_t)0x0f0000000ULL, 0, - 1, 0, 1, 0, 1, 0, 2, 0); - - /* 11: 1M, asid: 0x0, v: 0xe0200000, - p0: 0x60000000(2DVG), p1: 0x60100000(2DVG) */ - mips_coproc_tlb_set_entry(cpu, 11, 1048576, - 0xffffffffe0200000ULL, - 0x060000000ULL, 0x060100000ULL, - 1, 1, 1, 1, 1, 0, 2, 2); - - /* 12: 1M, asid: 0x0, v: 0xe0400000, - p0: 0x60200000(2DVG), p1: 0x60300000(2DVG) */ - mips_coproc_tlb_set_entry(cpu, 12, 1048576, - 0xffffffffe0400000ULL, - 0x060200000ULL, 0x060300000ULL, - 1, 1, 1, 1, 1, 0, 2, 2); - - /* 13: 4M, asid: 0x0, v: 0xe0800000, - p0: 0x40000000(2DVG), p1: 0x40400000(2DVG) */ - mips_coproc_tlb_set_entry(cpu, 13, 1048576*4, - 0xffffffffe0800000ULL, - 0x040000000ULL, 0x040400000ULL, - 1, 1, 1, 1, 1, 0, 2, 2); - - /* 14: 16M, asid: 0x0, v: 0xe2000000, - p0: 0x90000000(2DVG), p1: 0x91000000(2DVG) */ - mips_coproc_tlb_set_entry(cpu, 14, 1048576*16, - 0xffffffffe2000000ULL, - 0x090000000ULL, 0x091000000ULL, - 1, 1, 1, 1, 1, 0, 2, 2); - - if (machine->use_x11) { - ali_s3 = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_ControllerClass, - COMPONENT_TYPE_DisplayController, - COMPONENT_FLAG_ConsoleOut | - COMPONENT_FLAG_Output, - 1, 2, 0, 0xffffffff, "ALI_S3", - jazzbus, NULL, 0); - - arcbios_addchild_manual(cpu, - COMPONENT_CLASS_PeripheralClass, - COMPONENT_TYPE_MonitorPeripheral, - COMPONENT_FLAG_ConsoleOut | - COMPONENT_FLAG_Output, - 1, 2, 0, 0xffffffff, "1024x768", - ali_s3, NULL, 0); - } - break; - case MACHINE_ARC_JAZZ_MAGNUM: - if (machine->use_x11) { - vxl = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_ControllerClass, - COMPONENT_TYPE_DisplayController, - COMPONENT_FLAG_ConsoleOut | - COMPONENT_FLAG_Output, - 1, 2, 0, 0xffffffff, "VXL", - jazzbus, NULL, 0); - - arcbios_addchild_manual(cpu, - COMPONENT_CLASS_PeripheralClass, - COMPONENT_TYPE_MonitorPeripheral, - COMPONENT_FLAG_ConsoleOut | - COMPONENT_FLAG_Output, - 1, 2, 0, 0xffffffff, "1024x768", - vxl, NULL, 0); - } - break; - } - - diskcontroller = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_ControllerClass, - COMPONENT_TYPE_DiskController, - COMPONENT_FLAG_Input | - COMPONENT_FLAG_Output, - 1, 2, 0, 0xffffffff, "I82077", - jazzbus, NULL, 0); - - floppy = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_PeripheralClass, - COMPONENT_TYPE_FloppyDiskPeripheral, - COMPONENT_FLAG_Removable | - COMPONENT_FLAG_Input | - COMPONENT_FLAG_Output, - 1, 2, 0, 0xffffffff, NULL, - diskcontroller, NULL, 0); - - kbdctl = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_ControllerClass, - COMPONENT_TYPE_KeyboardController, - COMPONENT_FLAG_ConsoleIn | - COMPONENT_FLAG_Input, - 1, 2, 0, 0xffffffff, "I8742", - jazzbus, NULL, 0); - - kbd = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_PeripheralClass, - COMPONENT_TYPE_KeyboardPeripheral, - COMPONENT_FLAG_ConsoleIn | - COMPONENT_FLAG_Input, - 1, 2, 0, 0xffffffff, "PCAT_ENHANCED", - kbdctl, NULL, 0); - - ptrctl = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_ControllerClass, - COMPONENT_TYPE_PointerController, - COMPONENT_FLAG_Input, - 1, 2, 0, 0xffffffff, "I8742", - jazzbus, NULL, 0); - - ptr = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_PeripheralClass, - COMPONENT_TYPE_PointerPeripheral, - COMPONENT_FLAG_Input, - 1, 2, 0, 0xffffffff, "PS2 MOUSE", - ptrctl, NULL, 0); - -/* These cause Windows NT to bug out. */ -#if 0 - serial1 = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_ControllerClass, - COMPONENT_TYPE_SerialController, - COMPONENT_FLAG_Input | - COMPONENT_FLAG_Output, - 1, 2, 0, 0xffffffff, "COM1", - jazzbus, NULL, 0); - - serial2 = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_ControllerClass, - COMPONENT_TYPE_SerialController, - COMPONENT_FLAG_Input | - COMPONENT_FLAG_Output, - 1, 2, 0, 0xffffffff, "COM1", - jazzbus, NULL, 0); -#endif - - paral = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_ControllerClass, - COMPONENT_TYPE_ParallelController, - COMPONENT_FLAG_Input | - COMPONENT_FLAG_Output, - 1, 2, 0, 0xffffffff, "LPT1", - jazzbus, NULL, 0); - - audio = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_ControllerClass, - COMPONENT_TYPE_AudioController, - COMPONENT_FLAG_Input | - COMPONENT_FLAG_Output, - 1, 2, 0, 0xffffffff, "MAGNUM", - jazzbus, NULL, 0); - - eisa = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_AdapterClass, - COMPONENT_TYPE_EISAAdapter, - 0, 1, 2, 0, 0xffffffff, "EISA", - system, NULL, 0); - -{ -unsigned char config[78]; -memset(config, 0, sizeof(config)); - -/* config data version: 1, revision: 2, count: 4 */ -config[0] = 0x01; config[1] = 0x00; -config[2] = 0x02; config[3] = 0x00; -config[4] = 0x04; config[5] = 0x00; config[6] = 0x00; config[7] = 0x00; - -/* - type: Interrupt - share_disposition: DeviceExclusive, flags: LevelSensitive - level: 4, vector: 22, reserved1: 0 -*/ -config[8] = arc_CmResourceTypeInterrupt; -config[9] = arc_CmResourceShareDeviceExclusive; -config[10] = arc_CmResourceInterruptLevelSensitive; -config[12] = 4; -config[16] = 22; -config[20] = 0; - -/* - type: Memory - share_disposition: DeviceExclusive, flags: ReadWrite - start: 0x 0 80002000, length: 0x1000 -*/ -config[24] = arc_CmResourceTypeMemory; -config[25] = arc_CmResourceShareDeviceExclusive; -config[26] = arc_CmResourceMemoryReadWrite; -config[28] = 0x00; config[29] = 0x20; config[30] = 0x00; config[31] = 0x80; - config[32] = 0x00; config[33] = 0x00; config[34] = 0x00; config[35] = 0x00; -config[36] = 0x00; config[37] = 0x10; config[38] = 0x00; config[39] = 0x00; - -/* - type: DMA - share_disposition: DeviceExclusive, flags: 0x0 - channel: 0, port: 0, reserved1: 0 -*/ -config[40] = arc_CmResourceTypeDMA; -config[41] = arc_CmResourceShareDeviceExclusive; -/* 42..43 = flags, 44,45,46,47 = channel, 48,49,50,51 = port, 52,53,54,55 = reserved */ - -/* type: DeviceSpecific - share_disposition: DeviceExclusive, flags: 0x0 - datasize: 6, reserved1: 0, reserved2: 0 - data: [0x1:0x0:0x2:0x0:0x7:0x30] -*/ -config[56] = arc_CmResourceTypeDeviceSpecific; -config[57] = arc_CmResourceShareDeviceExclusive; -/* 58,59 = flags 60,61,62,63 = data size, 64..71 = reserved */ -config[60] = 6; -/* 72..77 = the data */ -config[72] = 0x01; -config[73] = 0x00; -config[74] = 0x02; -config[75] = 0x00; -config[76] = 0x07; -config[77] = 0x30; - scsi = arcbios_addchild_manual(cpu, - COMPONENT_CLASS_AdapterClass, - COMPONENT_TYPE_SCSIAdapter, - 0, 1, 2, 0, 0xffffffff, "ESP216", - system, config, sizeof(config)); - - arcbios_register_scsicontroller(scsi); -} - - } - - - add_symbol_name(&machine->symbol_context, - ARC_FIRMWARE_ENTRIES, 0x10000, "[ARCBIOS entry]", 0); - - switch (arc_wordlen) { - case sizeof(uint64_t): - for (i=0; i<100; i++) - store_64bit_word(cpu, ARC_FIRMWARE_VECTORS + i*8, - ARC_FIRMWARE_ENTRIES + i*8); - for (i=0; i<100; i++) - store_64bit_word(cpu, ARC_PRIVATE_VECTORS + i*8, - ARC_PRIVATE_ENTRIES + i*8); - break; - default: - for (i=0; i<100; i++) - store_32bit_word(cpu, ARC_FIRMWARE_VECTORS + i*4, - ARC_FIRMWARE_ENTRIES + i*4); - for (i=0; i<100; i++) - store_32bit_word(cpu, ARC_PRIVATE_VECTORS + i*4, - ARC_PRIVATE_ENTRIES + i*4); - } - - switch (arc_wordlen) { - case sizeof(uint64_t): - /* - * ARCS64 SPD (TODO: This is just a guess) - */ - memset(&arcbios_spb_64, 0, sizeof(arcbios_spb_64)); - store_64bit_word_in_host(cpu, (unsigned char *)&arcbios_spb_64.SPBSignature, ARCBIOS_SPB_SIGNATURE); - store_16bit_word_in_host(cpu, (unsigned char *)&arcbios_spb_64.Version, 64); - store_16bit_word_in_host(cpu, (unsigned char *)&arcbios_spb_64.Revision, 0); - store_64bit_word_in_host(cpu, (unsigned char *)&arcbios_spb_64.FirmwareVector, ARC_FIRMWARE_VECTORS); - store_buf(cpu, SGI_SPB_ADDR, (char *)&arcbios_spb_64, sizeof(arcbios_spb_64)); - break; - default: /* 32-bit */ - /* - * ARCBIOS SPB: (For ARC and 32-bit SGI modes) - */ - memset(&arcbios_spb, 0, sizeof(arcbios_spb)); - store_32bit_word_in_host(cpu, (unsigned char *)&arcbios_spb.SPBSignature, ARCBIOS_SPB_SIGNATURE); - store_32bit_word_in_host(cpu, (unsigned char *)&arcbios_spb.SPBLength, sizeof(arcbios_spb)); - store_16bit_word_in_host(cpu, (unsigned char *)&arcbios_spb.Version, 1); - store_16bit_word_in_host(cpu, (unsigned char *)&arcbios_spb.Revision, machine->machine_type == MACHINE_SGI? 10 : 2); - store_32bit_word_in_host(cpu, (unsigned char *)&arcbios_spb.FirmwareVector, ARC_FIRMWARE_VECTORS); - store_32bit_word_in_host(cpu, (unsigned char *)&arcbios_spb.FirmwareVectorLength, 100 * 4); /* ? */ - store_32bit_word_in_host(cpu, (unsigned char *)&arcbios_spb.PrivateVector, ARC_PRIVATE_VECTORS); - store_32bit_word_in_host(cpu, (unsigned char *)&arcbios_spb.PrivateVectorLength, 100 * 4); /* ? */ - store_buf(cpu, SGI_SPB_ADDR, (char *)&arcbios_spb, sizeof(arcbios_spb)); - } - /* * Boot string in ARC format: * @@ -3886,26 +3554,37 @@ /* TODO: Make this nicer. */ if (machine->machine_type == MACHINE_SGI) { if (machine->machine_subtype == 30) - strcat(init_bootpath, "xio(0)pci(15)"); + strlcat(init_bootpath, "xio(0)pci(15)", + MACHINE_NAME_MAXBUF); if (machine->machine_subtype == 32) - strcat(init_bootpath, "pci(0)"); + strlcat(init_bootpath, "pci(0)", + MACHINE_NAME_MAXBUF); } - if (diskimage_is_a_cdrom(machine, bootdev_id)) - snprintf(init_bootpath + strlen(init_bootpath), 400, - "scsi(0)cdrom(%i)fdisk(0)", bootdev_id); + if (diskimage_is_a_cdrom(machine, bootdev_id, + bootdev_type)) + snprintf(init_bootpath + strlen(init_bootpath), + 400,"scsi(0)cdrom(%i)fdisk(0)", bootdev_id); else - snprintf(init_bootpath + strlen(init_bootpath), 400, - "scsi(0)disk(%i)rdisk(0)partition(1)", bootdev_id); + snprintf(init_bootpath + strlen(init_bootpath), + 400,"scsi(0)disk(%i)rdisk(0)partition(1)", + bootdev_id); } if (machine->machine_type == MACHINE_ARC) - strcat(init_bootpath, "\\"); + strlcat(init_bootpath, "\\", MACHINE_NAME_MAXBUF); - bootstr = malloc(strlen(init_bootpath) + - strlen(machine->boot_kernel_filename) + 1); - strcpy(bootstr, init_bootpath); - strcat(bootstr, machine->boot_kernel_filename); + bootstr = malloc(BOOTSTR_BUFLEN); + if (bootstr == NULL) { + fprintf(stderr, "out of memory\n"); + exit(1); + } + strlcpy(bootstr, init_bootpath, BOOTSTR_BUFLEN); + if (strlcat(bootstr, machine->boot_kernel_filename, + BOOTSTR_BUFLEN) >= BOOTSTR_BUFLEN) { + fprintf(stderr, "boot string too long?\n"); + exit(1); + } /* Boot args., eg "-a" */ bootarg = machine->boot_string_argument; @@ -3914,7 +3593,8 @@ cpu->cd.mips.gpr[MIPS_GPR_A0] = 0; /* note: argc is increased later */ /* TODO: not needed? */ - cpu->cd.mips.gpr[MIPS_GPR_SP] = machine->physical_ram_in_mb * 1048576 + 0x80000000 - 0x2080; + cpu->cd.mips.gpr[MIPS_GPR_SP] = (int64_t)(int32_t) + (machine->physical_ram_in_mb * 1048576 + 0x80000000 - 0x2080); /* Set up argc/argv: */ addr = ARC_ENV_STRINGS; @@ -4032,8 +3712,9 @@ add_environment_string(cpu, "kernname=unix", &addr); } else { char *tmp; - tmp = malloc(strlen(bootarg) + strlen("OSLOADOPTIONS=") + 2); - sprintf(tmp, "OSLOADOPTIONS=%s", bootarg); + size_t mlen = strlen(bootarg) + strlen("OSLOADOPTIONS=") + 2; + tmp = malloc(mlen); + snprintf(tmp, mlen, "OSLOADOPTIONS=%s", bootarg); store_pointer_and_advance(cpu, &addr2, addr, arc_wordlen==sizeof(uint64_t)); add_environment_string(cpu, tmp, &addr); @@ -4067,7 +3748,7 @@ /* First of all, the MeshCube has an Au1500 in it: */ machine->md_interrupt = au1x00_interrupt; - machine->au1x00_ic_data = dev_au1x00_init(machine, mem); + machine->md_int.au1x00_ic_data = dev_au1x00_init(machine, mem); /* * TODO: Which non-Au1500 devices, and at what addresses? @@ -4115,46 +3796,6 @@ device_add(machine, "8250 addr=0x18000800 addr_mult=4 irq=0"); break; - case MACHINE_WRT54G: - machine->machine_name = "Linksys WRT54G"; - - if (machine->use_x11) - fprintf(stderr, "WARNING! Linksys WRT54G with -X is meaningless. Continuing anyway.\n"); - - /* 200 MHz default */ - if (machine->emulated_hz == 0) - machine->emulated_hz = 200000000; - - /* - * Linux should be loaded at 0x80001000. - * RAM: 16 or 32 MB, Flash RAM: 4 or 8 MB. - * http://www.bumpclub.ee/~jaanus/wrt54g/vana/minicom.cap: - * - * Starting program at 0x80001000 - * CPU revision is: 00029007 - * Primary instruction cache 8kb, linesize 16 bytes (2 ways) - * Primary data cache 4kb, linesize 16 bytes (2 ways) - * memory: 01000000 @ 00000000 (usable) - * Kernel command line: root=/dev/mtdblock2 rootfstype=squashfs init=/etc/preinit noinitrd console=ttyS0,115200 - * CPU: BCM4712 rev 1 at 200 MHz - * Calibrating delay loop... 199.47 BogoMIPS - * ttyS00 at 0xb8000300 (irq = 3) is a 16550A - * ttyS01 at 0xb8000400 (irq = 0) is a 16550A - * Flash device: 0x400000 at 0x1c000000 - * .. - */ - - /* TODO: What should the initial register contents be? */ -#if 1 -{ -int i; -for (i=0; i<32; i++) - cpu->cd.mips.gpr[i] = 0x01230000 + (i << 8) + 0x55; -} -#endif - - break; - case MACHINE_SONYNEWS: /* * There are several models, according to @@ -4192,6 +3833,168 @@ break; + case MACHINE_EVBMIPS: + /* http://www.netbsd.org/Ports/evbmips/ */ + cpu->byte_order = EMUL_LITTLE_ENDIAN; + + switch (machine->machine_subtype) { + case MACHINE_EVBMIPS_MALTA: + case MACHINE_EVBMIPS_MALTA_BE: + machine->machine_name = "MALTA (evbmips, little endian)"; + cpu->byte_order = EMUL_LITTLE_ENDIAN; + + if (machine->machine_subtype == MACHINE_EVBMIPS_MALTA_BE) { + machine->machine_name = "MALTA (evbmips, big endian)"; + cpu->byte_order = EMUL_BIG_ENDIAN; + } + + /* ISA interrupt controllers: */ + snprintf(tmpstr, sizeof(tmpstr), "8259 irq=24 addr=0x18000020"); + machine->md_int.isa_pic_data.pic1 = device_add(machine, tmpstr); + snprintf(tmpstr, sizeof(tmpstr), "8259 irq=24 addr=0x180000a0"); + machine->md_int.isa_pic_data.pic2 = device_add(machine, tmpstr); + machine->md_interrupt = malta_interrupt; + + dev_mc146818_init(machine, mem, 0x18000070, 8 + 8, MC146818_PC_CMOS, 1); + + machine->main_console_handle = (size_t) + device_add(machine, "ns16550 irq=12 addr=0x180003f8 name2=tty0"); + device_add(machine, "ns16550 irq=11 addr=0x180002f8 name2=tty1"); + + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=4 addr=0x%x name2=tty2", MALTA_CBUSUART); + device_add(machine, tmpstr); + /* TODO: Irqs */ + pci_data = dev_gt_init(machine, mem, 0x1be00000, 8+9, 8+9, 120); + + /* TODO: Haha, this is bogus. Just a cut&paste + from the Cobalt emulation above. */ + bus_pci_add(machine, pci_data, mem, 0, 9, 0, pci_vt82c586_isa_init, pci_vt82c586_isa_rr); + bus_pci_add(machine, pci_data, mem, 0, 9, 1, pci_vt82c586_ide_init, pci_vt82c586_ide_rr); + + device_add(machine, "malta_lcd addr=0x1f000400"); + break; + case MACHINE_EVBMIPS_PB1000: + machine->machine_name = "PB1000 (evbmips)"; + cpu->byte_order = EMUL_BIG_ENDIAN; + + machine->md_interrupt = au1x00_interrupt; + machine->md_int.au1x00_ic_data = dev_au1x00_init(machine, mem); + /* TODO */ + break; + default: + fatal("Unimplemented EVBMIPS model.\n"); + exit(1); + } + + if (machine->prom_emulation) { + /* This is just a test. TODO */ + for (i=0; i<32; i++) + cpu->cd.mips.gpr[i] = + 0x01230000 + (i << 8) + 0x55; + + /* NetBSD/evbmips wants these: (at least for Malta) */ + + /* a0 = argc */ + cpu->cd.mips.gpr[MIPS_GPR_A0] = 2; + + /* a1 = argv */ + cpu->cd.mips.gpr[MIPS_GPR_A1] = (int32_t)0x9fc01000; + store_32bit_word(cpu, (int32_t)0x9fc01000, 0x9fc01040); + store_32bit_word(cpu, (int32_t)0x9fc01004, 0x9fc01200); + store_32bit_word(cpu, (int32_t)0x9fc01008, 0); + + bootstr = strdup(machine->boot_kernel_filename); + bootarg = strdup(machine->boot_string_argument); + store_string(cpu, (int32_t)0x9fc01040, bootstr); + store_string(cpu, (int32_t)0x9fc01200, bootarg); + + /* a2 = (yamon_env_var *)envp */ + cpu->cd.mips.gpr[MIPS_GPR_A2] = (int32_t)0x9fc01800; + { + uint64_t env = cpu->cd.mips.gpr[MIPS_GPR_A2]; + uint64_t tmpptr = 0xffffffff9fc01c00ULL; + char tmps[50]; + + snprintf(tmps, sizeof(tmps), "0x%08x", + machine->physical_ram_in_mb * 1048576); + add_environment_string_dual(cpu, + &env, &tmpptr, "memsize", tmps); + + add_environment_string_dual(cpu, + &env, &tmpptr, "yamonrev", "02.06"); + + /* End of env: */ + tmpptr = 0; + add_environment_string_dual(cpu, + &env, &tmpptr, NULL, NULL); + } + + /* a3 = memsize */ + cpu->cd.mips.gpr[MIPS_GPR_A3] = + machine->physical_ram_in_mb * 1048576; + /* Hm. Linux ignores a3. */ + + /* + * TODO: + * Core ID numbers. + * How much of this is not valid for PBxxxx? + * + * See maltareg.h for more info. + */ + store_32bit_word(cpu, (int32_t)(0x80000000 + MALTA_REVISION), (1 << 10) + 0x26); + + /* Call vectors at 0x9fc005xx: */ + for (i=0; i<0x100; i+=4) + store_32bit_word(cpu, (int64_t)(int32_t)0x9fc00500 + i, + (int64_t)(int32_t)0x9fc00800 + i); + } + break; + + case MACHINE_PSP: + /* + * The Playstation Portable seems to be a strange beast. + * + * http://yun.cup.com/psppg004.html (in Japanese) seems to + * suggest that virtual addresses are not displaced by + * 0x80000000 as on normal CPUs, but by 0x40000000? + */ + machine->machine_name = "Playstation Portable"; + cpu->byte_order = EMUL_LITTLE_ENDIAN; + + if (!machine->use_x11 && !quiet_mode) + fprintf(stderr, "-------------------------------------" + "------------------------------------------\n" + "\n WARNING! You are emulating a PSP without -X. " + "You will miss graphical output!\n\n" + "-------------------------------------" + "------------------------------------------\n"); + + /* 480 x 272 pixels framebuffer (512 bytes per line) */ + fb = dev_fb_init(machine, mem, 0x04000000, VFB_HPCMIPS, + 480,272, 512,1088, -15, "Playstation Portable"); + + /* + * TODO/NOTE: This is ugly, but necessary since GXemul doesn't + * emulate any MIPS CPU without MMU right now. + */ + mips_coproc_tlb_set_entry(cpu, 0, 1048576*16, + 0x44000000 /*vaddr*/, 0x4000000, 0x4000000 + 1048576*16, + 1,1,1,1,1, 0, 2, 2); + mips_coproc_tlb_set_entry(cpu, 1, 1048576*16, + 0x8000000 /*vaddr*/, 0x0, 0x0 + 1048576*16, + 1,1,1,1,1, 0, 2, 2); + mips_coproc_tlb_set_entry(cpu, 2, 1048576*16, + 0x9000000 /*vaddr*/, 0x01000000, 0x01000000 + 1048576*16, + 1,1,1,1,1, 0, 2, 2); + mips_coproc_tlb_set_entry(cpu, 3, 1048576*16, + 0x0 /*vaddr*/, 0, 0 + 1048576*16, 1,1,1,1,1, 0, 2, 2); + + cpu->cd.mips.gpr[MIPS_GPR_SP] = 0xfff0; + + break; +#endif /* ENABLE_MIPS */ + +#ifdef ENABLE_PPC case MACHINE_BAREPPC: /* * A "bare" PPC machine. @@ -4208,15 +4011,26 @@ machine->machine_name = "PPC test machine"; /* TODO: interrupt for PPC? */ - machine->main_console_handle = dev_cons_init( - machine, mem, DEV_CONS_ADDRESS, "console", 0); + snprintf(tmpstr, sizeof(tmpstr), "cons addr=0x%llx irq=0", + (long long)DEV_CONS_ADDRESS); + cons_data = device_add(machine, tmpstr); + machine->main_console_handle = cons_data->console_handle; - snprintf(tmpstr, sizeof(tmpstr) - 1, "mp addr=0x%llx", + snprintf(tmpstr, sizeof(tmpstr), "mp addr=0x%llx", (long long)DEV_MP_ADDRESS); device_add(machine, tmpstr); - fb = dev_fb_init(machine, mem, 0x12000000, VFB_GENERIC, - 640,480, 640,480, 24, "generic", 1); + fb = dev_fb_init(machine, mem, DEV_FB_ADDRESS, VFB_GENERIC, + 640,480, 640,480, 24, "testppc generic"); + + snprintf(tmpstr, sizeof(tmpstr), "disk addr=0x%llx", + (long long)DEV_DISK_ADDRESS); + device_add(machine, tmpstr); + + snprintf(tmpstr, sizeof(tmpstr), "ether addr=0x%llx irq=0", + (long long)DEV_ETHER_ADDRESS); + device_add(machine, tmpstr); + break; case MACHINE_WALNUT: @@ -4236,10 +4050,9 @@ dev_pmppc_init(mem); /* com0 = 0xff600300, com1 = 0xff600400 */ - machine->main_console_handle = dev_ns16550_init(machine, mem, - 0xff600300, 0, 1, 1, "serial 0"); - dev_ns16550_init(machine, mem, - 0xff600400, 0, 1, 0, "serial 1"); + + machine->main_console_handle = (size_t)device_add(machine, "ns16550 irq=0 addr=0xff600300 name2=tty0"); + device_add(machine, "ns16550 irq=0 addr=0xff600400 in_use=0 name2=tty1"); break; @@ -4266,16 +4079,13 @@ device_add(machine, "bebox"); - /* Serial, used by NetBSD: */ - machine->main_console_handle = dev_ns16550_init(machine, mem, - 0x800003f8, 0, 1, 1, "serial 0"); - - /* Serial, used by Linux: */ - dev_ns16550_init(machine, mem, 0x800002f8, 0, 1, 0, "serial 1"); - - /* This is used by Linux too: */ - dev_vga_init(machine, mem, 0xc00b8000ULL, 0x800003c0ULL, 80, 25, - machine->machine_name); + machine->main_console_handle = (size_t) + device_add(machine, "ns16550 irq=0 addr=0x800003f8 name2=tty0"); + device_add(machine, "ns16550 irq=0 addr=0x800002f8 name2=tty1 in_use=0"); + + if (machine->use_x11) + dev_vga_init(machine, mem, 0xc00a0000ULL, 0x800003c0ULL, + machine->machine_name); store_32bit_word(cpu, 0x3010, machine->physical_ram_in_mb * 1048576); @@ -4302,7 +4112,8 @@ store_32bit_word(cpu, cpu->cd.ppc.gpr[6] + 12, 20); /* next */ store_32bit_word(cpu, cpu->cd.ppc.gpr[6] + 16, 1); /* console */ - store_buf(cpu, cpu->cd.ppc.gpr[6] + 20, "com", 4); + store_buf(cpu, cpu->cd.ppc.gpr[6] + 20, + machine->use_x11? "vga" : "com", 4); store_32bit_word(cpu, cpu->cd.ppc.gpr[6] + 24, 0x3f8);/* addr */ store_32bit_word(cpu, cpu->cd.ppc.gpr[6] + 28, 9600);/* speed */ @@ -4351,8 +4162,7 @@ /* For playing with PMON2000 for PPC: */ machine->machine_name = "DB64360"; - machine->main_console_handle = dev_ns16550_init(machine, mem, - 0x1d000020, 0, 4, 1, "serial console"); + machine->main_console_handle = (size_t)device_add(machine, "ns16550 irq=0 addr=0x1d000020"); { int i; @@ -4362,12 +4172,39 @@ } break; +#endif /* ENABLE_PPC */ +#ifdef ENABLE_SPARC case MACHINE_BARESPARC: /* A bare SPARC machine, with no devices. */ machine->machine_name = "\"Bare\" SPARC machine"; break; + case MACHINE_TESTSPARC: + machine->machine_name = "SPARC test machine"; + + snprintf(tmpstr, sizeof(tmpstr), "cons addr=0x%llx irq=0", + (long long)DEV_CONS_ADDRESS); + cons_data = device_add(machine, tmpstr); + machine->main_console_handle = cons_data->console_handle; + + snprintf(tmpstr, sizeof(tmpstr), "mp addr=0x%llx", + (long long)DEV_MP_ADDRESS); + device_add(machine, tmpstr); + + fb = dev_fb_init(machine, mem, DEV_FB_ADDRESS, VFB_GENERIC, + 640,480, 640,480, 24, "testsparc generic"); + + snprintf(tmpstr, sizeof(tmpstr), "disk addr=0x%llx", + (long long)DEV_DISK_ADDRESS); + device_add(machine, tmpstr); + + snprintf(tmpstr, sizeof(tmpstr), "ether addr=0x%llx irq=0", + (long long)DEV_ETHER_ADDRESS); + device_add(machine, tmpstr); + + break; + case MACHINE_ULTRA1: /* * NetBSD/sparc64 (http://www.netbsd.org/Ports/sparc64/) @@ -4375,42 +4212,290 @@ */ machine->machine_name = "Sun Ultra1"; break; +#endif /* ENABLE_SPARC */ - case MACHINE_BAREURISC: - machine->machine_name = "\"Bare\" URISC machine"; +#ifdef ENABLE_ALPHA + case MACHINE_BAREALPHA: + machine->machine_name = "\"Bare\" Alpha machine"; break; - case MACHINE_TESTURISC: - machine->machine_name = "URISC test machine"; + case MACHINE_TESTALPHA: + machine->machine_name = "Alpha test machine"; + + snprintf(tmpstr, sizeof(tmpstr), "cons addr=0x%llx irq=0", + (long long)DEV_CONS_ADDRESS); + cons_data = device_add(machine, tmpstr); + machine->main_console_handle = cons_data->console_handle; + + snprintf(tmpstr, sizeof(tmpstr), "mp addr=0x%llx", + (long long)DEV_MP_ADDRESS); + device_add(machine, tmpstr); - /* TODO */ - /* A special "device" for accessing normal devices - using urisc accesses? */ + fb = dev_fb_init(machine, mem, DEV_FB_ADDRESS, VFB_GENERIC, + 640,480, 640,480, 24, "testalpha generic"); - device_add(machine, "urisc addr=0x12341234"); + snprintf(tmpstr, sizeof(tmpstr), "disk addr=0x%llx", + (long long)DEV_DISK_ADDRESS); + device_add(machine, tmpstr); + + snprintf(tmpstr, sizeof(tmpstr), "ether addr=0x%llx irq=0", + (long long)DEV_ETHER_ADDRESS); + device_add(machine, tmpstr); + + break; + + case MACHINE_ALPHA: + /* TODO: Most of these... They are used by NetBSD/alpha: */ + /* a0 = First free Page Frame Number */ + /* a1 = PFN of current Level 1 page table */ + /* a2 = Bootinfo magic */ + /* a3 = Bootinfo pointer */ + /* a4 = Bootinfo version */ + cpu->cd.alpha.r[ALPHA_A0] = 16*1024*1024 / 8192; + cpu->cd.alpha.r[ALPHA_A1] = 0; + cpu->cd.alpha.r[ALPHA_A2] = 0; + cpu->cd.alpha.r[ALPHA_A3] = 0; + cpu->cd.alpha.r[ALPHA_A4] = 0; + + if (machine->prom_emulation) { + struct rpb rpb; + struct crb crb; + struct ctb ctb; + + /* HWRPB: Hardware Restart Parameter Block */ + memset(&rpb, 0, sizeof(struct rpb)); + store_64bit_word_in_host(cpu, (unsigned char *) + &(rpb.rpb_phys), HWRPB_ADDR); + strlcpy((char *)&(rpb.rpb_magic), "HWRPB", 8); + store_64bit_word_in_host(cpu, (unsigned char *) + &(rpb.rpb_size), sizeof(struct rpb)); + store_64bit_word_in_host(cpu, (unsigned char *) + &(rpb.rpb_page_size), 8192); + store_64bit_word_in_host(cpu, (unsigned char *) + &(rpb.rpb_type), machine->machine_subtype); + store_64bit_word_in_host(cpu, (unsigned char *) + &(rpb.rpb_cc_freq), 100000000); + store_64bit_word_in_host(cpu, (unsigned char *) + &(rpb.rpb_ctb_off), CTB_ADDR - HWRPB_ADDR); + store_64bit_word_in_host(cpu, (unsigned char *) + &(rpb.rpb_crb_off), CRB_ADDR - HWRPB_ADDR); + + /* CTB: Console Terminal Block */ + memset(&ctb, 0, sizeof(struct ctb)); + store_64bit_word_in_host(cpu, (unsigned char *) + &(ctb.ctb_term_type), machine->use_x11? + CTB_GRAPHICS : CTB_PRINTERPORT); + + /* CRB: Console Routine Block */ + memset(&crb, 0, sizeof(struct crb)); + store_64bit_word_in_host(cpu, (unsigned char *) + &(crb.crb_v_dispatch), CRB_ADDR - 0x100); + store_64bit_word(cpu, CRB_ADDR - 0x100 + 8, 0x10000); + + /* + * Place a special "hack" palcode call at 0x10000: + * (Hopefully nothing else will be there.) + */ + store_32bit_word(cpu, 0x10000, 0x3fffffe); + + store_buf(cpu, HWRPB_ADDR, (char *)&rpb, sizeof(struct rpb)); + store_buf(cpu, CTB_ADDR, (char *)&ctb, sizeof(struct ctb)); + store_buf(cpu, CRB_ADDR, (char *)&crb, sizeof(struct crb)); + } + + switch (machine->machine_subtype) { + case ST_DEC_3000_300: + machine->machine_name = "DEC 3000/300"; + break; + default:fatal("Unimplemented Alpha machine type %i\n", + machine->machine_subtype); + exit(1); + } break; +#endif /* ENABLE_ALPHA */ - case MACHINE_BAREHPPA: - machine->machine_name = "\"Bare\" HPPA machine"; +#ifdef ENABLE_ARM + case MACHINE_BAREARM: + machine->machine_name = "\"Bare\" ARM machine"; break; - case MACHINE_TESTHPPA: - machine->machine_name = "HPPA test machine"; + case MACHINE_TESTARM: + machine->machine_name = "ARM test machine"; + + snprintf(tmpstr, sizeof(tmpstr), "cons addr=0x%llx irq=0", + (long long)DEV_CONS_ADDRESS); + cons_data = device_add(machine, tmpstr); + machine->main_console_handle = cons_data->console_handle; + + snprintf(tmpstr, sizeof(tmpstr), "mp addr=0x%llx", + (long long)DEV_MP_ADDRESS); + device_add(machine, tmpstr); + + fb = dev_fb_init(machine, mem, DEV_FB_ADDRESS, VFB_GENERIC, + 640,480, 640,480, 24, "testarm generic"); + + snprintf(tmpstr, sizeof(tmpstr), "disk addr=0x%llx", + (long long)DEV_DISK_ADDRESS); + device_add(machine, tmpstr); + + snprintf(tmpstr, sizeof(tmpstr), "ether addr=0x%llx irq=0", + (long long)DEV_ETHER_ADDRESS); + device_add(machine, tmpstr); + + /* Place a tiny stub at end of memory, and set the link + register to point to it. This stub halts the machine. */ + cpu->cd.arm.r[ARM_SP] = + machine->physical_ram_in_mb * 1048576 - 4096; + cpu->cd.arm.r[ARM_LR] = cpu->cd.arm.r[ARM_SP] + 32; + store_32bit_word(cpu, cpu->cd.arm.r[ARM_LR] + 0, 0xe3a00201); + store_32bit_word(cpu, cpu->cd.arm.r[ARM_LR] + 4, 0xe5c00010); + store_32bit_word(cpu, cpu->cd.arm.r[ARM_LR] + 8, + 0xeafffffe); + break; +#endif /* ENABLE_ARM */ + +#ifdef ENABLE_IA64 + case MACHINE_BAREIA64: + machine->machine_name = "\"Bare\" IA64 machine"; + break; + + case MACHINE_TESTIA64: + machine->machine_name = "IA64 test machine"; + + snprintf(tmpstr, sizeof(tmpstr), "cons addr=0x%llx irq=0", + (long long)DEV_CONS_ADDRESS); + cons_data = device_add(machine, tmpstr); + machine->main_console_handle = cons_data->console_handle; + + snprintf(tmpstr, sizeof(tmpstr), "mp addr=0x%llx", + (long long)DEV_MP_ADDRESS); + device_add(machine, tmpstr); + + fb = dev_fb_init(machine, mem, DEV_FB_ADDRESS, VFB_GENERIC, + 640,480, 640,480, 24, "testia64 generic"); + + snprintf(tmpstr, sizeof(tmpstr), "disk addr=0x%llx", + (long long)DEV_DISK_ADDRESS); + device_add(machine, tmpstr); + + snprintf(tmpstr, sizeof(tmpstr), "ether addr=0x%llx irq=0", + (long long)DEV_ETHER_ADDRESS); + device_add(machine, tmpstr); - /* TODO */ break; +#endif /* ENABLE_IA64 */ - case MACHINE_BAREALPHA: - machine->machine_name = "\"Bare\" Alpha machine"; +#ifdef ENABLE_M68K + case MACHINE_BAREM68K: + machine->machine_name = "\"Bare\" M68K machine"; break; - case MACHINE_TESTALPHA: - machine->machine_name = "Alpha test machine"; + case MACHINE_TESTM68K: + machine->machine_name = "M68K test machine"; + + snprintf(tmpstr, sizeof(tmpstr), "cons addr=0x%llx irq=0", + (long long)DEV_CONS_ADDRESS); + cons_data = device_add(machine, tmpstr); + machine->main_console_handle = cons_data->console_handle; - /* TODO */ + snprintf(tmpstr, sizeof(tmpstr), "mp addr=0x%llx", + (long long)DEV_MP_ADDRESS); + device_add(machine, tmpstr); + + fb = dev_fb_init(machine, mem, DEV_FB_ADDRESS, VFB_GENERIC, + 640,480, 640,480, 24, "testm68k generic"); + + snprintf(tmpstr, sizeof(tmpstr), "disk addr=0x%llx", + (long long)DEV_DISK_ADDRESS); + device_add(machine, tmpstr); + + snprintf(tmpstr, sizeof(tmpstr), "ether addr=0x%llx irq=0", + (long long)DEV_ETHER_ADDRESS); + device_add(machine, tmpstr); + + break; +#endif /* ENABLE_M68K */ + +#ifdef ENABLE_X86 + case MACHINE_BAREX86: + machine->machine_name = "\"Bare\" x86 machine"; break; + case MACHINE_X86: + if (machine->machine_subtype == MACHINE_X86_XT) + machine->machine_name = "PC XT"; + else + machine->machine_name = "Generic x86 PC"; + + /* Interrupt controllers: */ + snprintf(tmpstr, sizeof(tmpstr), "8259 irq=16 addr=0x%llx", + (long long)(X86_IO_BASE + 0x20)); + machine->md.pc.pic1 = device_add(machine, tmpstr); + if (machine->machine_subtype != MACHINE_X86_XT) { + snprintf(tmpstr, sizeof(tmpstr), "8259 irq=16 addr=0x%llx irq=2", + (long long)(X86_IO_BASE + 0xa0)); + machine->md.pc.pic2 = device_add(machine, tmpstr); + } + + machine->md_interrupt = x86_pc_interrupt; + + /* Timer: */ + snprintf(tmpstr, sizeof(tmpstr), "8253 addr=0x%llx irq=0", + (long long)(X86_IO_BASE + 0x40)); + device_add(machine, tmpstr); + + snprintf(tmpstr, sizeof(tmpstr), "pccmos addr=0x%llx", + (long long)(X86_IO_BASE + 0x70)); + device_add(machine, tmpstr); + + /* TODO: IRQ when emulating a PC XT? */ + + /* IDE controllers: */ + if (diskimage_exist(machine, 0, DISKIMAGE_IDE) || + diskimage_exist(machine, 1, DISKIMAGE_IDE)) + dev_wdc_init(machine, mem, X86_IO_BASE + 0x1f0, 14, 0); + if (diskimage_exist(machine, 2, DISKIMAGE_IDE) || + diskimage_exist(machine, 3, DISKIMAGE_IDE)) + dev_wdc_init(machine, mem, X86_IO_BASE + 0x170, 15, 2); + + /* Floppy controller at irq 6 */ + snprintf(tmpstr, sizeof(tmpstr), "fdc addr=0x%llx irq=6", + (long long)(X86_IO_BASE + 0x3f0)); + device_add(machine, tmpstr); + + /* TODO: sound blaster (eventually) at irq 7? */ + + /* TODO: parallel port */ + + /* Serial ports: (TODO: 8250 for PC XT?) */ + + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=4 addr=0x%llx name2=com1 in_use=0", + (long long)X86_IO_BASE + 0x3f8); + device_add(machine, tmpstr); + snprintf(tmpstr, sizeof(tmpstr), "ns16550 irq=3 addr=0x%llx name2=com2 in_use=0", + (long long)X86_IO_BASE + 0x2f8); + device_add(machine, tmpstr); + + /* VGA + keyboard: */ + dev_vga_init(machine, mem, 0xa0000ULL, X86_IO_BASE + 0x3c0, + "Generic x86 PC"); + machine->main_console_handle = dev_pckbc_init(machine, + mem, X86_IO_BASE + 0x60, PCKBC_8042, 1, 12, 1, 1); + + if (machine->prom_emulation) + pc_bios_init(cpu); + + if (!machine->use_x11 && !quiet_mode) + fprintf(stderr, "-------------------------------------" + "------------------------------------------\n" + "\n WARNING! You are emulating a PC without -X. " + "You will miss graphical output!\n\n" + "-------------------------------------" + "------------------------------------------\n"); + break; +#endif /* ENABLE_X86 */ + default: fatal("Unknown emulation type %i\n", machine->machine_type); exit(1); @@ -4478,8 +4563,17 @@ case MACHINE_NETGEAR: m->physical_ram_in_mb = 16; break; - case MACHINE_WRT54G: - m->physical_ram_in_mb = 32; + case MACHINE_EVBMIPS: + m->physical_ram_in_mb = 64; + break; + case MACHINE_PSP: + /* + * According to + * http://wiki.ps2dev.org/psp:memory_map: + * 0×08000000 = 8 MB kernel memory + * 0×08800000 = 24 MB user memory + */ + m->physical_ram_in_mb = 8 + 24; break; case MACHINE_ARC: switch (m->machine_subtype) { @@ -4502,19 +4596,21 @@ m->physical_ram_in_mb = 32; } break; + case MACHINE_ALPHA: + m->physical_ram_in_mb = 64; + break; case MACHINE_BEBOX: m->physical_ram_in_mb = 64; break; - case MACHINE_BAREURISC: - case MACHINE_TESTURISC: - m->physical_ram_in_mb = 2; + case MACHINE_X86: + if (m->machine_subtype == MACHINE_X86_XT) + m->physical_ram_in_mb = 1; break; } } - /* Special hack for WRT54G and hpcmips machines: */ - if (m->machine_type == MACHINE_WRT54G || - m->machine_type == MACHINE_HPCMIPS) { + /* Special hack for hpcmips machines: */ + if (m->machine_type == MACHINE_HPCMIPS) { m->dbe_on_nonexistant_memaccess = 0; } @@ -4610,9 +4706,6 @@ case MACHINE_NETGEAR: m->cpu_name = strdup("RC32334"); break; - case MACHINE_WRT54G: - m->cpu_name = strdup("BCM4712"); - break; case MACHINE_ARC: switch (m->machine_subtype) { case MACHINE_ARC_JAZZ_PICA: @@ -4644,6 +4737,22 @@ if (m->cpu_name == NULL) m->cpu_name = strdup("R4400"); break; + case MACHINE_EVBMIPS: + switch (m->machine_subtype) { + case MACHINE_EVBMIPS_MALTA: + case MACHINE_EVBMIPS_MALTA_BE: + m->cpu_name = strdup("5Kc"); + break; + case MACHINE_EVBMIPS_PB1000: + m->cpu_name = strdup("AU1000"); + break; + default:fatal("Unimpl. evbmips.\n"); + exit(1); + } + break; + case MACHINE_PSP: + m->cpu_name = strdup("Allegrex"); + break; /* PowerPC: */ case MACHINE_BAREPPC: @@ -4691,28 +4800,43 @@ /* SPARC: */ case MACHINE_BARESPARC: - m->cpu_name = strdup("SPARCV9"); - break; + case MACHINE_TESTSPARC: case MACHINE_ULTRA1: - m->cpu_name = strdup("SPARCV9"); + m->cpu_name = strdup("SPARCv9"); break; - /* URISC: */ - case MACHINE_BAREURISC: - case MACHINE_TESTURISC: - m->cpu_name = strdup("URISC"); + /* Alpha: */ + case MACHINE_BAREALPHA: + case MACHINE_TESTALPHA: + case MACHINE_ALPHA: + m->cpu_name = strdup("Alpha"); break; - /* HPPA: */ - case MACHINE_BAREHPPA: - case MACHINE_TESTHPPA: - m->cpu_name = strdup("HPPA2.0"); + /* ARM: */ + case MACHINE_BAREARM: + case MACHINE_TESTARM: + m->cpu_name = strdup("ARM"); break; - /* Alpha: */ - case MACHINE_BAREALPHA: - case MACHINE_TESTALPHA: - m->cpu_name = strdup("EV4"); + /* IA64: */ + case MACHINE_BAREIA64: + case MACHINE_TESTIA64: + m->cpu_name = strdup("IA64"); + break; + + /* M68K: */ + case MACHINE_BAREM68K: + case MACHINE_TESTM68K: + m->cpu_name = strdup("68020"); + break; + + /* x86: */ + case MACHINE_BAREX86: + case MACHINE_X86: + if (m->machine_subtype == MACHINE_X86_XT) + m->cpu_name = strdup("8086"); + else + m->cpu_name = strdup("AMD64"); break; } @@ -4752,12 +4876,14 @@ if (m->single_step_on_bad_addr) debug("single-step on bad addresses\n"); - if (m->bintrans_enable) - debug("bintrans enabled (%i MB cache)\n", - (int) (m->bintrans_size / 1048576)); - else - debug("bintrans disabled, other speedtricks %s\n", - m->speed_tricks? "enabled" : "disabled"); + if (m->arch == ARCH_MIPS) { + if (m->bintrans_enable) + debug("bintrans enabled (%i MB cache)\n", + (int) (m->bintrans_size / 1048576)); + else + debug("bintrans disabled, other speedtricks %s\n", + m->speed_tricks? "enabled" : "disabled"); + } debug("clock: "); if (m->automatic_clock_adjustment) @@ -4944,6 +5070,8 @@ debug("\n"); useremul_list_emuls(); + debug("Userland emulation works for programs with the complexity" + " of Hello World,\nbut not much more.\n"); } @@ -4962,6 +5090,20 @@ * entries will appear in normal order when listed. :-) */ + /* X86 machine: */ + me = machine_entry_new("x86-based PC", ARCH_X86, + MACHINE_X86, 2, 2); + me->aliases[0] = "pc"; + me->aliases[1] = "x86"; + me->subtype[0] = machine_entry_subtype_new("Generic PC", + MACHINE_X86_GENERIC, 1); + me->subtype[0]->aliases[0] = "generic"; + me->subtype[1] = machine_entry_subtype_new("PC XT", MACHINE_X86_XT, 1); + me->subtype[1]->aliases[0] = "xt"; + if (cpu_family_ptr_by_number(ARCH_X86) != NULL) { + me->next = first_machine_entry; first_machine_entry = me; + } + /* Walnut: (NetBSD/evbppc) */ me = machine_entry_new("Walnut evaluation board", ARCH_PPC, MACHINE_WALNUT, 2, 0); @@ -4971,11 +5113,11 @@ me->next = first_machine_entry; first_machine_entry = me; } - /* Test-machine for URISC: */ - me = machine_entry_new("Test-machine for URISC", ARCH_URISC, - MACHINE_TESTURISC, 1, 0); - me->aliases[0] = "testurisc"; - if (cpu_family_ptr_by_number(ARCH_URISC) != NULL) { + /* Test-machine for SPARC: */ + me = machine_entry_new("Test-machine for SPARC", ARCH_SPARC, + MACHINE_TESTSPARC, 1, 0); + me->aliases[0] = "testsparc"; + if (cpu_family_ptr_by_number(ARCH_SPARC) != NULL) { me->next = first_machine_entry; first_machine_entry = me; } @@ -4995,11 +5137,27 @@ me->next = first_machine_entry; first_machine_entry = me; } - /* Test-machine for HPPA: */ - me = machine_entry_new("Test-machine for HPPA", ARCH_HPPA, - MACHINE_TESTHPPA, 1, 0); - me->aliases[0] = "testhppa"; - if (cpu_family_ptr_by_number(ARCH_HPPA) != NULL) { + /* Test-machine for M68K: */ + me = machine_entry_new("Test-machine for M68K", ARCH_M68K, + MACHINE_TESTM68K, 1, 0); + me->aliases[0] = "testm68k"; + if (cpu_family_ptr_by_number(ARCH_M68K) != NULL) { + me->next = first_machine_entry; first_machine_entry = me; + } + + /* Test-machine for IA64: */ + me = machine_entry_new("Test-machine for IA64", ARCH_IA64, + MACHINE_TESTIA64, 1, 0); + me->aliases[0] = "testia64"; + if (cpu_family_ptr_by_number(ARCH_IA64) != NULL) { + me->next = first_machine_entry; first_machine_entry = me; + } + + /* Test-machine for ARM: */ + me = machine_entry_new("Test-machine for ARM", ARCH_ARM, + MACHINE_TESTARM, 1, 0); + me->aliases[0] = "testarm"; + if (cpu_family_ptr_by_number(ARCH_ARM) != NULL) { me->next = first_machine_entry; first_machine_entry = me; } @@ -5037,32 +5195,34 @@ } /* SGI: */ - me = machine_entry_new("SGI", ARCH_MIPS, MACHINE_SGI, 2, 9); + me = machine_entry_new("SGI", ARCH_MIPS, MACHINE_SGI, 2, 10); me->aliases[0] = "silicon graphics"; me->aliases[1] = "sgi"; - me->subtype[0] = machine_entry_subtype_new("IP19", 19, 1); - me->subtype[0]->aliases[0] = "ip19"; - me->subtype[1] = machine_entry_subtype_new("IP20", 20, 1); - me->subtype[1]->aliases[0] = "ip20"; - me->subtype[2] = machine_entry_subtype_new("IP22", 22, 2); - me->subtype[2]->aliases[0] = "ip22"; - me->subtype[2]->aliases[1] = "indy"; - me->subtype[3] = machine_entry_subtype_new("IP24", 24, 1); - me->subtype[3]->aliases[0] = "ip24"; - me->subtype[4] = machine_entry_subtype_new("IP27", 27, 3); - me->subtype[4]->aliases[0] = "ip27"; - me->subtype[4]->aliases[1] = "origin 200"; - me->subtype[4]->aliases[2] = "origin 2000"; - me->subtype[5] = machine_entry_subtype_new("IP28", 28, 1); - me->subtype[5]->aliases[0] = "ip28"; - me->subtype[6] = machine_entry_subtype_new("IP30", 30, 2); - me->subtype[6]->aliases[0] = "ip30"; - me->subtype[6]->aliases[1] = "octane"; - me->subtype[7] = machine_entry_subtype_new("IP32", 32, 2); - me->subtype[7]->aliases[0] = "ip32"; - me->subtype[7]->aliases[1] = "o2"; - me->subtype[8] = machine_entry_subtype_new("IP35", 35, 1); - me->subtype[8]->aliases[0] = "ip35"; + me->subtype[0] = machine_entry_subtype_new("IP12", 12, 1); + me->subtype[0]->aliases[0] = "ip12"; + me->subtype[1] = machine_entry_subtype_new("IP19", 19, 1); + me->subtype[1]->aliases[0] = "ip19"; + me->subtype[2] = machine_entry_subtype_new("IP20", 20, 1); + me->subtype[2]->aliases[0] = "ip20"; + me->subtype[3] = machine_entry_subtype_new("IP22", 22, 2); + me->subtype[3]->aliases[0] = "ip22"; + me->subtype[3]->aliases[1] = "indy"; + me->subtype[4] = machine_entry_subtype_new("IP24", 24, 1); + me->subtype[4]->aliases[0] = "ip24"; + me->subtype[5] = machine_entry_subtype_new("IP27", 27, 3); + me->subtype[5]->aliases[0] = "ip27"; + me->subtype[5]->aliases[1] = "origin 200"; + me->subtype[5]->aliases[2] = "origin 2000"; + me->subtype[6] = machine_entry_subtype_new("IP28", 28, 1); + me->subtype[6]->aliases[0] = "ip28"; + me->subtype[7] = machine_entry_subtype_new("IP30", 30, 2); + me->subtype[7]->aliases[0] = "ip30"; + me->subtype[7]->aliases[1] = "octane"; + me->subtype[8] = machine_entry_subtype_new("IP32", 32, 2); + me->subtype[8]->aliases[0] = "ip32"; + me->subtype[8]->aliases[1] = "o2"; + me->subtype[9] = machine_entry_subtype_new("IP35", 35, 1); + me->subtype[9]->aliases[0] = "ip35"; if (cpu_family_ptr_by_number(ARCH_MIPS) != NULL) { me->next = first_machine_entry; first_machine_entry = me; } @@ -5075,6 +5235,14 @@ me->next = first_machine_entry; first_machine_entry = me; } + /* Playstation Portable: */ + me = machine_entry_new("Playstation Portable", ARCH_MIPS, + MACHINE_PSP, 1, 0); + me->aliases[0] = "psp"; + if (cpu_family_ptr_by_number(ARCH_MIPS) != NULL) { + me->next = first_machine_entry; first_machine_entry = me; + } + /* NetGear: */ me = machine_entry_new("NetGear WG602", ARCH_MIPS, MACHINE_NETGEAR, 2, 0); @@ -5113,20 +5281,10 @@ me->next = first_machine_entry; first_machine_entry = me; } - /* Linksys: */ - me = machine_entry_new("Linksys WRT54G", ARCH_MIPS, - MACHINE_WRT54G, 2, 0); - me->aliases[0] = "linksys"; - me->aliases[1] = "wrt54g"; - if (cpu_family_ptr_by_number(ARCH_MIPS) != NULL) { - me->next = first_machine_entry; first_machine_entry = me; - } - /* HPCmips: */ - me = machine_entry_new("Handheld MIPS (HPC)", - ARCH_MIPS, MACHINE_HPCMIPS, 2, 8); + me = machine_entry_new("Handheld MIPS (HPCmips)", + ARCH_MIPS, MACHINE_HPCMIPS, 1, 8); me->aliases[0] = "hpcmips"; - me->aliases[1] = "hpc"; me->subtype[0] = machine_entry_subtype_new( "Casio Cassiopeia BE-300", MACHINE_HPCMIPS_CASIO_BE300, 2); me->subtype[0]->aliases[0] = "be-300"; @@ -5159,11 +5317,11 @@ me->next = first_machine_entry; first_machine_entry = me; } - /* Generic "bare" URISC machine: */ - me = machine_entry_new("Generic \"bare\" URISC machine", ARCH_URISC, - MACHINE_BAREURISC, 1, 0); - me->aliases[0] = "bareurisc"; - if (cpu_family_ptr_by_number(ARCH_URISC) != NULL) { + /* Generic "bare" X86 machine: */ + me = machine_entry_new("Generic \"bare\" X86 machine", ARCH_X86, + MACHINE_BAREX86, 1, 0); + me->aliases[0] = "barex86"; + if (cpu_family_ptr_by_number(ARCH_X86) != NULL) { me->next = first_machine_entry; first_machine_entry = me; } @@ -5191,11 +5349,27 @@ me->next = first_machine_entry; first_machine_entry = me; } - /* Generic "bare" HPPA machine: */ - me = machine_entry_new("Generic \"bare\" HPPA machine", ARCH_HPPA, - MACHINE_BAREHPPA, 1, 0); - me->aliases[0] = "barehppa"; - if (cpu_family_ptr_by_number(ARCH_HPPA) != NULL) { + /* Generic "bare" M68K machine: */ + me = machine_entry_new("Generic \"bare\" M68K machine", ARCH_M68K, + MACHINE_BAREM68K, 1, 0); + me->aliases[0] = "barem68k"; + if (cpu_family_ptr_by_number(ARCH_M68K) != NULL) { + me->next = first_machine_entry; first_machine_entry = me; + } + + /* Generic "bare" IA64 machine: */ + me = machine_entry_new("Generic \"bare\" IA64 machine", ARCH_IA64, + MACHINE_BAREIA64, 1, 0); + me->aliases[0] = "bareia64"; + if (cpu_family_ptr_by_number(ARCH_IA64) != NULL) { + me->next = first_machine_entry; first_machine_entry = me; + } + + /* Generic "bare" ARM machine: */ + me = machine_entry_new("Generic \"bare\" ARM machine", ARCH_ARM, + MACHINE_BAREARM, 1, 0); + me->aliases[0] = "barearm"; + if (cpu_family_ptr_by_number(ARCH_ARM) != NULL) { me->next = first_machine_entry; first_machine_entry = me; } @@ -5207,6 +5381,23 @@ me->next = first_machine_entry; first_machine_entry = me; } + /* Evaluation Boards (MALTA etc): */ + me = machine_entry_new("Evaluation boards (evbmips)", ARCH_MIPS, + MACHINE_EVBMIPS, 1, 3); + me->aliases[0] = "evbmips"; + me->subtype[0] = machine_entry_subtype_new("Malta", + MACHINE_EVBMIPS_MALTA, 1); + me->subtype[0]->aliases[0] = "malta"; + me->subtype[1] = machine_entry_subtype_new("Malta (Big-Endian)", + MACHINE_EVBMIPS_MALTA_BE, 1); + me->subtype[1]->aliases[0] = "maltabe"; + me->subtype[2] = machine_entry_subtype_new("PB1000", + MACHINE_EVBMIPS_PB1000, 1); + me->subtype[2]->aliases[0] = "pb1000"; + if (cpu_family_ptr_by_number(ARCH_MIPS) != NULL) { + me->next = first_machine_entry; first_machine_entry = me; + } + /* DECstation: */ me = machine_entry_new("DECstation/DECsystem", ARCH_MIPS, MACHINE_DEC, 3, 9); @@ -5338,5 +5529,15 @@ if (cpu_family_ptr_by_number(ARCH_MIPS) != NULL) { me->next = first_machine_entry; first_machine_entry = me; } + + /* Alpha: */ + me = machine_entry_new("Alpha", ARCH_ALPHA, MACHINE_ALPHA, 1, 1); + me->aliases[0] = "alpha"; + me->subtype[0] = machine_entry_subtype_new( + "DEC 3000/300", ST_DEC_3000_300, 1); + me->subtype[0]->aliases[0] = "3000/300"; + if (cpu_family_ptr_by_number(ARCH_ALPHA) != NULL) { + me->next = first_machine_entry; first_machine_entry = me; + } }