Simtec BAST system emulation
PATCH 1/1 Simtec BAST system emulation
Hi,
I have spent a while now sorting out the Simtec BAST patch which I originally subbed at the start of this month.
Paul: I believe I have addressed all the points you raised when you previously reviewed the patch
andrzej: We eventually chose to continue with our emulation because yours is too hw-faithful to be fast. Hopefully we can work together in the future when you have some more bandwidth to integrate your work into ours and thus get a best-of-both-worlds solution into mainline.
Everyone else:
Have a play. I believe the patch is clean and it does fix a bug in the IDE emulation and adds support to the ARM boot stuff for ARM systems which do not place their SDRAM at phys_addr 0x00
Thanks,
Daniel.
Signature · 2 lines
Daniel Silverstone http://www.digital-scurf.org/ PGP mail accepted and encouraged. Key Id: 2BC8 4016 2068 7895
=== added file 'hw/dm9000.c'
dm9000.c +623 -0
@@ -0,0 +1,623 @@ +/* hw/dm9000.c +* +* DM9000 Ethernet interface +* +* Copyright Daniel Silverstone and Vincent Sanders +* +* This file is under the terms of the GNU General Public +* License Version 2 +*/ + +#include <string.h> +#include "vl.h" +#include "hw/irq.h" + +/* Comment this out if you don't want register debug on stderr */ +//#define DM9000_DEBUG + +/* Comment this out if you don't want a packet dump */ +//#define DM9000_DUMP_FILENAME "/tmp/dm9k_dump" + +#ifdef DM9000_DEBUG +#define DM9000_DBF(X...) fprintf(stderr, X) +#else +#define DM9000_DBF(X...) if(0) fprintf(stderr, X) +#endif + +#define DM9000_REG_NCR 0x00 +#define DM9000_REG_NSR 0x01 +#define DM9000_REG_TCR 0x02 +#define DM9000_REG_TSR1 0x03 +#define DM9000_REG_TSR2 0x04 +#define DM9000_REG_RCR 0x05 +#define DM9000_REG_RSR 0x06 +#define DM9000_REG_ROCR 0x07 +#define DM9000_REG_BPTR 0x08 +#define DM9000_REG_FCTR 0x09 +#define DM9000_REG_FCR 0x0A +#define DM9000_REG_EPCR 0x0B +#define DM9000_REG_EPAR 0x0C +#define DM9000_REG_EPDRL 0x0D +#define DM9000_REG_EPDRH 0x0E +#define DM9000_REG_WCR 0x0F +#define DM9000_REG_PAR0 0x10 +#define DM9000_REG_PAR1 0x11 +#define DM9000_REG_PAR2 0x12 +#define DM9000_REG_PAR3 0x13 +#define DM9000_REG_PAR4 0x14 +#define DM9000_REG_PAR5 0x15 +#define DM9000_REG_MAR0 0x16 +#define DM9000_REG_MAR1 0x17 +#define DM9000_REG_MAR2 0x18 +#define DM9000_REG_MAR3 0x19 +#define DM9000_REG_MAR4 0x1A +#define DM9000_REG_MAR5 0x1B +#define DM9000_REG_MAR6 0x1C +#define DM9000_REG_MAR7 0x1D +#define DM9000_REG_GPCR 0x1E +#define DM9000_REG_GPR 0x1F +#define DM9000_REG_TRPAL 0x22 +#define DM9000_REG_TRPAH 0x23 +#define DM9000_REG_RWPAL 0x24 +#define DM9000_REG_RWPAH 0x25 +#define DM9000_REG_VIDL 0x28 +#define DM9000_REG_VIDH 0x29 +#define DM9000_REG_PIDL 0x2A +#define DM9000_REG_PIDH 0x2B +#define DM9000_REG_CHIPR 0x2C +#define DM9000_REG_SMCR 0x2F +#define DM9000_REG_MRCMDX 0xF0 +#define DM9000_REG_MRCMD 0xF2 +#define DM9000_REG_MRRL 0xF4 +#define DM9000_REG_MRRH 0xF5 +#define DM9000_REG_MWCMDX 0xF6 +#define DM9000_REG_MWCMD 0xF8 +#define DM9000_REG_MWRL 0xFA +#define DM9000_REG_MWRH 0xFB +#define DM9000_REG_TXPLL 0xFC +#define DM9000_REG_TXPLH 0xFD +#define DM9000_REG_ISR 0xFE +#define DM9000_REG_IMR 0xFF + +#define DM9000_NCR_RESET 0x01 +#define DM9000_NSR_TX1END 0x04 +#define DM9000_NSR_TX2END 0x08 +#define DM9000_TCR_TXREQ 0x01 + +#define DM9000_IMR_AUTOWRAP 0x80 + +#define DM9000_MII_READ 0x0C +#define DM9000_MII_WRITE 0x0A + +#define DM9000_MII_REG_BMCR 0x00 +#define DM9000_MII_REG_STATUS 0x01 +#define DM9000_MII_REG_PHYID1 0x02 +#define DM9000_MII_REG_PHYID2 0x03 +#define DM9000_MII_REG_ANAR 0x04 +#define DM9000_MII_REG_ANLPAR 0x05 +#define DM9000_MII_REG_ANER 0x06 +#define DM9000_MII_REG_DSCR 0x10 +#define DM9000_MII_REG_DSCSR 0x11 +#define DM9000_MII_REG_10BTCSR 0x12 + + +typedef struct { +uint32_t addr;/* address port */ +uint32_t data;/* data port */ +VLANClientState *vc; +qemu_irq irq; +uint8_t macaddr[6 ]; +uint8_t address;/* The internal magial address */ +uint8_t packet_buffer[16 *1024 ]; +uint16_t dm9k_mrr, dm9k_mwr;/* Read and write address registers */ +uint16_t dm9k_txpl;/* TX packet length */ +uint16_t dm9k_trpa, dm9k_rwpa;/* TX Read ptr address, RX write ptr address */ +uint8_t dm9k_imr, dm9k_isr;/* Interrupt mask register and status register*/ +uint8_t dm9k_ncr, dm9k_nsr;/* Network control register, network status register */ +uint8_t dm9k_wcr;/* Wakeup control */ +uint8_t dm9k_tcr;/* Transmission control register */ +uint8_t packet_copy_buffer[3 *1024 ];/* packet copy buffer */ +unsigned int packet_index:1 ;/* 0 == packet I, 1 == packet II */ + +/* Internal MII PHY state */ +uint8_t dm9k_epcr;/* EEPROM/PHY control register */ +uint8_t dm9k_epar;/* EEPROM/PHY address register */ +uint16_t dm9k_epdr;/* EEPROM/PHY data register */ +/* MII Regs */ +uint16_t dm9k_mii_bmcr; +uint16_t dm9k_mii_anar; +uint16_t dm9k_mii_dscr; + +}dm9000_state ; + + +#ifdef DM9000_DUMP_FILENAME +#include <arpa/inet.h> +static uint8_t pcap_header[24 ] = { +0xA1 ,0xB2 ,0xC3 ,0xD4 ,/* TCPDUMP Magic */ +0x00 ,0x02 ,0x00 ,0x04 ,/* Major 2, Minor 4 */ +0x00 ,0x00 ,0x00 ,0x00 ,/* Timezone offset */ +0x00 ,0x00 ,0x00 ,0x01 ,/* Accuracy of timestamps */ +0x00 ,0x00 ,0x0C ,0x00 ,/* Snaplen 3KiB */ +0x00 ,0x00 ,0x00 ,0x01 ,/* Ethernet frames */ +}; +static uint8_t nulls[8 ] = {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 }; +static void dm9k_dump_packet (uint8_t *buf,uint32_t size) +{ +FILE * dm9k_fileh =fopen (DM9000_DUMP_FILENAME ,"ab+" ); +unsigned long bsize =htonl (size); +DM9000_DBF ("Dumping packet at %08x (%d bytes)\n" , buf, size); +fseek (dm9k_fileh,0 ,SEEK_END ); +if (ftell (dm9k_fileh)==0 )fwrite (pcap_header,1 ,24 , dm9k_fileh); +fwrite (nulls,1 ,8 , dm9k_fileh); +fwrite (&bsize,1 ,4 , dm9k_fileh); +fwrite (&bsize,1 ,4 , dm9k_fileh); +fwrite (buf,1 , size, dm9k_fileh); +fclose (dm9k_fileh); +} +#else +#define dm9k_dump_packet(X...) do { } while(0) +#endif + +static void dm9000_raise_irq (dm9000_state *state) +{ +int level = ((state->dm9k_isr & state->dm9k_imr) &0x03 ) !=0 ; +DM9000_DBF ("DM9000: Set IRQ level %d\n" , level); +qemu_set_irq (state->irq, level); +} + +static void dm9000_soft_reset_mii (dm9000_state *state) +{ + state->dm9k_mii_bmcr =0x3100 ;/* 100Mbps, AUTONEG, FULL DUPLEX */ + state->dm9k_mii_anar =0x01E1 ; + state->dm9k_mii_dscr =0x0410 ; +} + +static void dm9000_soft_reset (dm9000_state *state) +{ +DM9000_DBF ("DM9000: Soft Reset\n" ); + state->dm9k_mrr = state->dm9k_mwr = state->dm9k_txpl = state->dm9k_trpa =0x0000 ; + state->dm9k_rwpa =0x0C04 ; + state->dm9k_imr =0 ; + state->dm9k_isr =0 ;/* 16 bit mode, no interrupts asserted */ + state->dm9k_tcr =0 ; + state->packet_index =0 ; +memset (state->packet_buffer,0 ,16 *1024 ); +memset (state->packet_copy_buffer,0 ,3 *1024 ); +/* These registers have some bits "unaffected by software reset" */ +/* Clear the reset bits */ + state->dm9k_ncr &=0xA0 ; + state->dm9k_nsr &=0xD0 ; +/* Claim full duplex */ + state->dm9k_ncr |=1 <<3 ; +/* Set link status to 1 */ + state->dm9k_nsr |=1 <<6 ; +/* dm9k_wcr is unaffected or reserved, never reset */ +/* MII control regs */ + state->dm9k_epcr =0x00 ; + state->dm9k_epar =0x40 ; +/* reset the MII */ +dm9000_soft_reset_mii (state); +dm9000_raise_irq (state);/* Clear any potentially pending IRQ */ +} + +static void dm9000_hard_reset (dm9000_state *state) +{ + state->dm9k_ncr =0x00 ; + state->dm9k_nsr =0x00 ; + state->dm9k_wcr =0x00 ; +dm9000_soft_reset (state); +} + +static void dm9000_do_transmit (dm9000_state *state) +{ +uint16_t idx, cnt, tptr; + idx = state->dm9k_trpa; + cnt = state->dm9k_txpl; + tptr =0 ; +if ( cnt >3 *1024 ) cnt =3 *1024 ;/* HARD CAP AT 3KiB */ +DM9000_DBF ("TX_Packet: %d bytes from %04x\n" , cnt, idx); +while (cnt--) { + state->packet_copy_buffer[tptr++] = state->packet_buffer[idx++]; +if ( idx ==0x0C00 ) idx =0 ; + } +/* DM9KNOTE: Assumes 16bit wiring */ + idx = (idx+1 ) & ~1 ;/* Round up to nearest 16bit boundary */ +if ( idx ==0x0C00 ) idx =0 ; + state->dm9k_trpa = idx; +dm9k_dump_packet (state->packet_copy_buffer, state->dm9k_txpl); +/* We have the copy buffer, now we do the transmit */ +qemu_send_packet (state->vc, state->packet_copy_buffer, state->dm9k_txpl); +/* Clear the "please xmit" bit */ + state->dm9k_tcr &= ~DM9000_TCR_TXREQ ; +/* Set the TXEND bit */ + state->dm9k_nsr |=1 <<(2 +state->packet_index); +DM9000_DBF ("TX: NSR=%02x PI=%d\n" , state->dm9k_nsr, state->packet_index); +/* Claim a TX complete IRQ */ + state->dm9k_isr |=0x02 ;/* Packet transmitted latch */ +/* And flip the next-packet bit */ + state->packet_index = !state->packet_index; +dm9000_raise_irq (state); +} + +static void dm9000_mii_read (dm9000_state *state) +{ +int mii_reg = (state->dm9k_epar) &0x3f ; +uint16_t ret =0 ; +switch (mii_reg) { +case DM9000_MII_REG_BMCR : + ret = state->dm9k_mii_bmcr; +break ; +case DM9000_MII_REG_STATUS : + ret =0x782D ;/* No 100/T4, Can 100/FD, Can 100/HD, Can 10/FD, Can 10/HD, +* No Preamble suppression, Autoneg complete, No remote fault, +* Can autoneg, link up, no jabber, extended capability */ +break ; +case DM9000_MII_REG_PHYID1 : + ret =0x0181 ; +break ; +case DM9000_MII_REG_PHYID2 : + ret =0xB8C0 ; +break ; +case DM9000_MII_REG_ANAR : + ret = state->dm9k_mii_anar; +break ; +case DM9000_MII_REG_ANLPAR : + ret =0x0400 ; +break ; +case DM9000_MII_REG_ANER : + ret =0x0001 ; +break ; +case DM9000_MII_REG_DSCR : + ret = state->dm9k_mii_dscr; +break ; +case DM9000_MII_REG_DSCSR : + ret =0xF008 ; +break ; +case DM9000_MII_REG_10BTCSR : + ret =0x7800 ; + } + state->dm9k_epdr = ret; +DM9000_DBF ("DM9000:MIIPHY: Read of MII reg %d gives %04x\n" , mii_reg, state->dm9k_epdr); +} + +static void dm9000_mii_write (dm9000_state *state) +{ +int mii_reg = (state->dm9k_epar) &0x3f ; +DM9000_DBF ("DM9000:MIIPHY: Write of MII reg %d value %04x\n" , mii_reg, state->dm9k_epdr); +switch (mii_reg) { +case DM9000_MII_REG_BMCR : + state->dm9k_mii_bmcr = (state->dm9k_epdr &~0x8000 ); +if ( state->dm9k_epdr &0x8000 )dm9000_soft_reset_mii (state); +break ; +case DM9000_MII_REG_ANAR : + state->dm9k_mii_anar = state->dm9k_epdr; +break ; +case DM9000_MII_REG_DSCR : + state->dm9k_mii_dscr = state->dm9k_epdr & ~0x0008 ; +break ; + } +} + +static void dm9000_write (void *opaque,target_phys_addr_t address, +uint32_t value) +{ +dm9000_state *state = (dm9000_state *)opaque; +#ifdef DM9000_DEBUG +int suppress_debug =0 ; +#endif + +if (address == state->addr) { +if ( (value !=DM9000_REG_MRCMD ) && + (value !=DM9000_REG_MWCMD ) ) +DM9000_DBF ("DM9000: Address set to 0x%02x\n" , value); + state->address = value; +return ; + } + +switch (state->address) { +case DM9000_REG_NCR : + state->dm9k_ncr = value &0xDF ; +if (state->dm9k_ncr &DM9000_NCR_RESET ) +dm9000_soft_reset (state); +break ; +case DM9000_REG_NSR : + state->dm9k_nsr &= ~(value &0x2C ); +break ; +case DM9000_REG_TCR : + state->dm9k_tcr = value &0xFF ; +if ( value &DM9000_TCR_TXREQ )dm9000_do_transmit (state); +break ; +case DM9000_REG_EPCR : + state->dm9k_epcr = value &0xFF ; +if ( value &DM9000_MII_READ ) +dm9000_mii_read (state); +else if ( value &DM9000_MII_WRITE ) +dm9000_mii_write (state); +break ; +case DM9000_REG_EPAR : + state->dm9k_epar = value &0xFF ; +break ; +case DM9000_REG_EPDRL : + state->dm9k_epdr &=0xFF00 ; + state->dm9k_epdr |= value &0xFF ; +break ; +case DM9000_REG_EPDRH : + state->dm9k_epdr &=0xFF ; + state->dm9k_epdr |= (value &0xFF ) <<8 ; +break ; +case DM9000_REG_PAR0 : +case DM9000_REG_PAR1 : +case DM9000_REG_PAR2 : +case DM9000_REG_PAR3 : +case DM9000_REG_PAR4 : +case DM9000_REG_PAR5 : + state->macaddr[state->address -DM9000_REG_PAR0 ] = value &0xFF ; +break ; +case DM9000_REG_MRRL : + state->dm9k_mrr &=0xFF00 ; + state->dm9k_mrr |= value &0xFF ; +break ; +case DM9000_REG_MRRH : + state->dm9k_mrr &=0xFF ; + state->dm9k_mrr |= (value &0xFF ) <<8 ; +break ; +case DM9000_REG_MWCMDX : +case DM9000_REG_MWCMD : +/* DM9KNOTE: This assumes a 16bit wide wiring */ + state->packet_buffer[state->dm9k_mwr] = value &0xFF ; + state->packet_buffer[state->dm9k_mwr+1 ] = (value >>8 ) &0xFF ; +if ( state->address ==DM9000_REG_MWCMD ) { + state->dm9k_mwr +=2 ; +if ( state->dm9k_imr &DM9000_IMR_AUTOWRAP ) +if ( state->dm9k_mwr >=0x0C00 ) + state->dm9k_mwr -=0x0C00 ; + } +#ifdef DM9000_DEBUG + suppress_debug =1 ; +#endif +break ; +case DM9000_REG_MWRL : + state->dm9k_mwr &=0xFF00 ; + state->dm9k_mwr |= value &0xFF ; +break ; +case DM9000_REG_MWRH : + state->dm9k_mwr &=0xFF ; + state->dm9k_mwr |= (value &0xFF ) <<8 ; +break ; +case DM9000_REG_TXPLL : + state->dm9k_txpl &=0xFF00 ; + state->dm9k_txpl |= value &0xFF ; +break ; +case DM9000_REG_TXPLH : + state->dm9k_txpl &=0xFF ; + state->dm9k_txpl |= (value &0xFF ) <<8 ; +break ; +case DM9000_REG_ISR : + state->dm9k_isr &= ~(value &0x0F ); +dm9000_raise_irq (state); +break ; +case DM9000_REG_IMR : +if ( !(state->dm9k_imr &DM9000_IMR_AUTOWRAP ) && + (value &DM9000_IMR_AUTOWRAP ) ) + state->dm9k_mrr =0x0C00 | (state->dm9k_mrr &0xFF ); + state->dm9k_imr = value &0xFF ; +dm9000_raise_irq (state); +break ; + } +#ifdef DM9000_DEBUG +if (!suppress_debug)DM9000_DBF ("DM9000: Write value %04x\n" , value); +#endif +} + +static uint32_t dm9000_read (void *opaque,target_phys_addr_t address) +{ +dm9000_state *state = (dm9000_state *)opaque; +uint32_t ret =0 ; +#ifdef DM9000_DEBUG +int suppress_debug =0 ; +#endif + +if (address == state->addr) +return state->address; +switch (state->address) { +case DM9000_REG_NCR : + ret = state->dm9k_ncr; +break ; +case DM9000_REG_NSR : + ret = state->dm9k_nsr; +/* Note, TX1END and TX2END are *CLEAR ON READ* */ + state->dm9k_nsr &= ~(DM9000_NSR_TX1END |DM9000_NSR_TX2END ); +break ; +case DM9000_REG_TCR : + ret = state->dm9k_tcr; +break ; +case DM9000_REG_TSR1 : +case DM9000_REG_TSR2 : + ret =0x00 ;/* No error, yay! */ +break ; +case DM9000_REG_EPCR : + ret = state->dm9k_epcr; +break ; +case DM9000_REG_EPAR : + ret = state->dm9k_epar; +break ; +case DM9000_REG_EPDRL : + ret = state->dm9k_epdr &0xFF ; +break ; +case DM9000_REG_EPDRH : + ret = (state->dm9k_epdr >>8 ) &0xFF ; +break ; +case DM9000_REG_PAR0 : +case DM9000_REG_PAR1 : +case DM9000_REG_PAR2 : +case DM9000_REG_PAR3 : +case DM9000_REG_PAR4 : +case DM9000_REG_PAR5 : + ret = state->macaddr[state->address -DM9000_REG_PAR0 ]; +break ; +case DM9000_REG_TRPAL : + ret = state->dm9k_trpa &0xFF ; +break ; +case DM9000_REG_TRPAH : + ret = state->dm9k_trpa >>8 ; +break ; +case DM9000_REG_RWPAL : + ret = state->dm9k_rwpa &0xFF ; +break ; +case DM9000_REG_RWPAH : + ret = state->dm9k_rwpa >>8 ; +break ; +case DM9000_REG_VIDL : + ret =0x46 ; +break ; +case DM9000_REG_VIDH : + ret =0x0A ; +break ; +case DM9000_REG_PIDL : + ret =0x00 ; +break ; +case DM9000_REG_PIDH : + ret =0x90 ; +break ; +case DM9000_REG_CHIPR : + ret =0x00 ; +break ; +case DM9000_REG_MRCMDX : +case DM9000_REG_MRCMD : +/* DM9KNOTE: This assumes a 16bit wide wiring */ + ret = state->packet_buffer[state->dm9k_mrr]; + ret |= state->packet_buffer[state->dm9k_mrr+1 ] <<8 ; +if ( state->address ==DM9000_REG_MRCMD ) { + state->dm9k_mrr +=2 ; +if ( state->dm9k_mrr >= (16 *1024 ) ) state->dm9k_mrr -= (16 *1024 ); +if ( state->dm9k_imr &DM9000_IMR_AUTOWRAP ) +if ( state->dm9k_mrr <0x0C00 ) + state->dm9k_mrr +=0x0C00 ; + } +#ifdef DM9000_DEBUG +if (state->address==DM9000_REG_MRCMD ) + suppress_debug =1 ; +#endif +break ; +case DM9000_REG_MRRL : + ret = state->dm9k_mrr &0xFF ; +break ; +case DM9000_REG_MRRH : + ret = state->dm9k_mrr >>8 ; +break ; +case DM9000_REG_MWRL : + ret = state->dm9k_mwr &0xFF ; +break ; +case DM9000_REG_MWRH : + ret = state->dm9k_mwr >>8 ; +break ; +case DM9000_REG_TXPLL : + ret = state->dm9k_txpl &0xFF ; +break ; +case DM9000_REG_TXPLH : + ret = state->dm9k_txpl >>8 ; +break ; +case DM9000_REG_ISR : + ret = state->dm9k_isr; +break ; +case DM9000_REG_IMR : + ret = state->dm9k_imr; +break ; +default : + ret =0 ; + } + +#ifdef DM9000_DEBUG +if (!suppress_debug)DM9000_DBF ("DM9000: Read gives: %04x\n" , ret); +#endif +return ret; +} + + + +static int dm9000_can_receive (void *opaque) +{ +dm9000_state *state = (dm9000_state *)opaque; +uint16_t rx_space; +if ( state->dm9k_rwpa < state->dm9k_mrr ) + rx_space = state->dm9k_mrr - state->dm9k_rwpa; +else + rx_space = (13 *1024 ) - (state->dm9k_rwpa - state->dm9k_mrr); +DM9000_DBF ("DM9000:RX_Packet: Asked about RX, rwpa=%d mrr=%d => space is %d bytes\n" , + state->dm9k_rwpa, state->dm9k_mrr, rx_space); +if (rx_space >2048 )return 1 ; +return 0 ; +} + +static void dm9000_receive (void *opaque,const uint8_t *buf,int size) +{ +dm9000_state *state = (dm9000_state *)opaque; +uint16_t rxptr = state->dm9k_rwpa; +uint8_t magic_padding =4 ; +if ( size >2048 )return ;/* La La La, I can't hear you */ +/* Fill out the magical header structure */ +DM9000_DBF ("DM9000:RX_Packet: %d bytes into buffer at %04x\n" , size, rxptr); +dm9k_dump_packet (buf, size); +if ( size <64 ) magic_padding += (64 - size); +DM9000_DBF ("DM9000:RX_Packet: Magical padding is %d bytes\n" , magic_padding); + size += magic_padding;/* The magical CRC bollocks */ + state->packet_buffer[state->dm9k_rwpa-4 ] =0x01 ;/* Packet read */ + state->packet_buffer[state->dm9k_rwpa-3 ] =0x00 ;/* Status OK */ + state->packet_buffer[state->dm9k_rwpa-2 ] = size &0xFF ;/* Size LOW */ + state->packet_buffer[state->dm9k_rwpa-1 ] = (size &0xFF00 )>>8 ;/* Size HIGH */ + size +=4 ;/* The magical next header (which we zero for fun) */ +while (size--) { +if ( size > (magic_padding +3 ) ) + state->packet_buffer[rxptr++] = *buf++; +else + state->packet_buffer[rxptr++] =0x00 ;/* Clear to the next header */ +/* DM9KNOTE: Assumes 16 bit wired config */ +if (size ==4 ) rxptr = (rxptr+1 ) & ~1 ;/* At end of packet, realign */ +if ( rxptr >= (16 *1024 ) ) rxptr -= (16 *1024 ); +if ( rxptr <0x0C00 ) rxptr +=0x0C00 ; + } + state->dm9k_rwpa = rxptr; + state->dm9k_isr |=0x01 ;/* RX interrupt, yay */ +dm9000_raise_irq (state); +} + + +static CPUReadMemoryFunc *dm9000_readfn[] = { + dm9000_read, + dm9000_read, + dm9000_read +}; + +static CPUWriteMemoryFunc *dm9000_writefn[] = { + dm9000_write, + dm9000_write, + dm9000_write +}; + +/* initialises a dm9000 ethernet controller +* The dm9k has a single 16bit wide address and data port through which all +* operations are multiplexed, there is a single IRQ +*/ +void dm9000_init (NICInfo *nd,target_phys_addr_t base_addr, +uint32_t addr_offset,uint32_t data_offset, +qemu_irq irq) +{ +dm9000_state *state; +int iomemtype; + + state = (dm9000_state *)qemu_mallocz (sizeof (dm9000_state)); + iomemtype =cpu_register_io_memory (0 , dm9000_readfn, + dm9000_writefn, state); +cpu_register_physical_memory (base_addr,MAX (addr_offset, data_offset) +4 , iomemtype); + state->addr = base_addr + addr_offset; + state->data = base_addr + data_offset; + state->irq = irq; +memcpy (state->macaddr, nd->macaddr,6 ); + +dm9000_hard_reset (state); + + state->vc =qemu_new_vlan_client (nd->vlan, dm9000_receive, + dm9000_can_receive, state); + +}
=== added file 'hw/s3c2410x.c'
s3c2410x.c +73 -0
73 lines not on this page · raw message
=== added file 'hw/s3c2410x.h'
s3c2410x.h +395 -0
395 lines not on this page · raw message
=== added file 'hw/s3c2410x_clkcon.c'
s3c2410x_clkcon.c +79 -0
79 lines not on this page · raw message
=== added file 'hw/s3c2410x_gpio.c'
s3c2410x_gpio.c +160 -0
160 lines not on this page · raw message
=== added file 'hw/s3c2410x_iic.c'
s3c2410x_iic.c +145 -0
145 lines not on this page · raw message
=== added file 'hw/s3c2410x_irq.c'
s3c2410x_irq.c +182 -0
182 lines not on this page · raw message
=== added file 'hw/s3c2410x_memc.c'
s3c2410x_memc.c +60 -0
60 lines not on this page · raw message
=== added file 'hw/s3c2410x_rtc.c'
s3c2410x_rtc.c +85 -0
85 lines not on this page · raw message
=== added file 'hw/s3c2410x_serial.c'
s3c2410x_serial.c +219 -0
219 lines not on this page · raw message
=== added file 'hw/s3c2410x_timers.c'
s3c2410x_timers.c +114 -0
114 lines not on this page · raw message
=== added directory 'hw/s3c24xx'
=== added file 'hw/s3c24xx/regs-iic.h'
s3c24xx/regs-iic.h +56 -0
56 lines not on this page · raw message
=== added file 'hw/simtecbast.c'
simtecbast.c +117 -0
117 lines not on this page · raw message
=== modified file 'Makefile.target'
Makefile.target +2 -0
@@ -447,6 +447,8 @@ ifeq ($(TARGET_BASE_ARCH), arm) VL_OBJS+= integratorcp.o versatilepb.o ps2.o smc91c111.o arm_pic.o arm_timer.o VL_OBJS+= arm_boot.o pl011.o pl050.o pl080.o pl110.o pl181.o pl190.o +VL_OBJS+= simtecbast.o s3c2410x.o s3c2410x_serial.o s3c2410x_memc.o s3c2410x_gpio.o s3c2410x_iic.o dm9000.o +VL_OBJS+= s3c2410x_irq.o s3c2410x_timers.o ide.o s3c2410x_clkcon.o s3c2410x_rtc.o VL_OBJS+= versatile_pci.o sd.o VL_OBJS+= arm_gic.o realview.o arm_sysctl.o VL_OBJS+= arm-semi.o
=== modified file 'hw/arm_boot.c'
arm_boot.c +8 -6
@@ -32,11 +32,12 @@if (env->kernel_filename)arm_load_kernel (env, env->ram_size, env->kernel_filename, env->kernel_cmdline, env->initrd_filename, - env->board_id); + env->board_id, env->emulated_sdram_base); }static void set_kernel_args (uint32_t ram_size,int initrd_size, -const char *kernel_cmdline) +const char *kernel_cmdline, +target_phys_addr_t emulated_sdram_base) {uint32_t *p;
@@ -51,12 +52,12 @@stl_raw (p++,4 );stl_raw (p++,0x54410002 );stl_raw (p++, ram_size); -stl_raw (p++,0 ); +stl_raw (p++, emulated_sdram_base);if (initrd_size) {/* ATAG_INITRD2 */ stl_raw (p++,4 );stl_raw (p++,0x54420005 ); -stl_raw (p++,INITRD_LOAD_ADDR ); +stl_raw (p++,INITRD_LOAD_ADDR + emulated_sdram_base);stl_raw (p++, initrd_size); }if (kernel_cmdline && *kernel_cmdline) {
@@ -77,7 +78,7 @@void arm_load_kernel (CPUState *env,int ram_size,const char *kernel_filename,const char *kernel_cmdline,const char *initrd_filename, -int board_id) +int board_id,target_phys_addr_t emulated_sdram_base) {int kernel_size;int initrd_size;
@@ -98,6 +99,7 @@ env->kernel_cmdline = kernel_cmdline; env->initrd_filename = initrd_filename; env->board_id = board_id; + env->emulated_sdram_base = emulated_sdram_base;qemu_register_reset (main_cpu_reset, env); }/* Assume that raw images are linux kernels, and ELF images are not. */
@@ -138,7 +140,7 @@ bootloader[6 ] = entry;for (n =0 ; n <sizeof (bootloader) /4 ; n++)stl_raw (phys_ram_base + (n *4 ), bootloader[n]); -set_kernel_args (ram_size, initrd_size, kernel_cmdline); +set_kernel_args (ram_size, initrd_size, kernel_cmdline, emulated_sdram_base); } }
=== modified file 'hw/ide.c'
ide.c +84 -1
100 lines not on this page · raw message
=== modified file 'hw/integratorcp.c'
integratorcp.c +1 -1
@@ -508,7 +508,7 @@pl110_init (ds,0xc0000000 , pic[22 ],0 );arm_load_kernel (env, ram_size, kernel_filename, kernel_cmdline, - initrd_filename,0x113 ); + initrd_filename,0x113 ,0 ); }QEMUMachine integratorcp_machine = {
=== modified file 'hw/irq.h'
irq.h +3 -0
@@ -1,3 +1,5 @@ +#ifndef QEMU_HW_IRQ_H +#define QEMU_HW_IRQ_H /* Generic IRQ/GPIO pin infrastructure. */ typedef void (*qemu_irq_handler )(void *opaque,int n,int level);
@@ -19,3 +21,4 @@/* Returns an array of N IRQs. */ qemu_irq *qemu_allocate_irqs (qemu_irq_handler handler,void *opaque,int n); +#endif
=== modified file 'hw/realview.c'
realview.c +1 -1
@@ -131,7 +131,7 @@/* 0x6c000000 PCI mem 2. */ arm_load_kernel (env, ram_size, kernel_filename, kernel_cmdline, - initrd_filename,0x33b ); + initrd_filename,0x33b ,0x0 ); }QEMUMachine realview_machine = {
=== modified file 'hw/versatilepb.c'
versatilepb.c +1 -1
@@ -260,7 +260,7 @@/* 0x101f4000 SSPI. */ arm_load_kernel (env, ram_size, kernel_filename, kernel_cmdline, - initrd_filename, board_id); + initrd_filename, board_id,0 ); } static void vpb_init(int ram_size, int vga_ram_size, int boot_device,
=== modified file 'target-arm/cpu.h'
cpu.h +2 -0
@@ -127,6 +127,7 @@const char *kernel_filename;const char *kernel_cmdline;const char *initrd_filename; +target_phys_addr_t emulated_sdram_base;int board_id; } CPUARMState;
@@ -220,6 +221,7 @@#define ARM_CPUID_ARM1026 0x4106a262#define ARM_CPUID_ARM926 0x41069265 +#define ARM_CPUID_ARM920T 0x41129200#if defined(CONFIG_USER_ONLY )#define TARGET_PAGE_BITS 12
=== modified file 'target-arm/helper.c'
helper.c +3 -0
@@ -14,6 +14,8 @@ { env->cp15.c0_cpuid = id;switch (id) { +case ARM_CPUID_ARM920T : +break ;case ARM_CPUID_ARM926 :set_feature (env,ARM_FEATURE_VFP ); env->vfp.xregs[ARM_VFP_FPSID ] =0x41011090 ;
@@ -68,6 +70,7 @@static const struct arm_cpu_t arm_cpu_names[] = { {ARM_CPUID_ARM926 ,"arm926" }, {ARM_CPUID_ARM1026 ,"arm1026" }, + {ARM_CPUID_ARM920T ,"arm920t" }, {0 ,NULL } };
=== modified file 'target-arm/translate.c'
translate.c +18 -0
@@ -525,6 +525,19 @@return 0 ; } +static int disas_cp14_insn (DisasContext *s,uint32_t insn) +{ +uint32_t rd = (insn >>12 ) &0xf ; +if (insn & (1 <<20 )) { +gen_op_movl_T0_im (0 ); + gen_op_movl_reg_TN[0 ][rd](); + }else { +/* Nothing to do on writes to cp14 */ + } +gen_lookup_tb (s); +return 0 ; +} +/* Disassemble a VFP instruction. Returns nonzero if an error occured (ie. an undefined instruction). */ static int disas_vfp_insn (CPUState * env,DisasContext *s,uint32_t insn)
@@ -1818,6 +1831,11 @@if (disas_vfp_insn (env, s, insn)) goto illegal_op;break ; +case 14 : +/* ice */ +if (disas_cp14_insn (s, insn)) + goto illegal_op; +break ;case 15 :if (disas_cp15_insn (s, insn)) goto illegal_op;
=== modified file 'vl.c'
vl.c +1 -0
@@ -6728,6 +6728,7 @@qemu_register_machine (&versatilepb_machine);qemu_register_machine (&versatileab_machine);qemu_register_machine (&realview_machine); +qemu_register_machine (&simtecbast_machine);#elif defined(TARGET_SH4 )qemu_register_machine (&shix_machine);#elif defined(TARGET_ALPHA )
=== modified file 'vl.h'
vl.h +15 -1
@@ -173,6 +173,11 @@#define BIOS_SIZE ((512 + 32) * 1024)#elif defined(TARGET_MIPS )#define BIOS_SIZE (4 * 1024 * 1024) +#elif defined(TARGET_ARM ) +/* ARM boards often have bootloaders in NOR which ends up +* memory mapped. 8 Megabytes seems enough for this +*/ +#define BIOS_SIZE (8 * 1024 * 1024)#endif /* keyboard/mouse support */
@@ -964,6 +969,7 @@void pci_piix3_ide_init (PCIBus *bus,BlockDriverState **hd_table,int devfn,qemu_irq *pic);int pmac_ide_init (BlockDriverState **hd_table,qemu_irq irq); +int stcb_ide_init (BlockDriverState **hd_table,qemu_irq irq);/* cdrom.c */ int cdrom_read_toc (int nb_sectors,uint8_t *buf,int msf,int start_track);
@@ -1376,6 +1382,9 @@extern QEMUMachine versatilepb_machine;extern QEMUMachine versatileab_machine; +/* simtecbast.c */ +extern QEMUMachine simtecbast_machine; +/* realview.c */ extern QEMUMachine realview_machine;
@@ -1392,6 +1401,11 @@/* smc91c111.c */ void smc91c111_init (NICInfo *,uint32_t ,qemu_irq ); +/* dm9000.c */ + +void dm9000_init (NICInfo *nd,target_phys_addr_t base_addr,uint32_t addr_offset, +uint32_t data_offset,qemu_irq irq); +/* pl110.c */ void *pl110_init (DisplayState *ds,uint32_t base,qemu_irq irq,int );
@@ -1425,7 +1439,7 @@void arm_load_kernel (CPUState *env,int ram_size,const char *kernel_filename,const char *kernel_cmdline,const char *initrd_filename, -int board_id); +int board_id,target_phys_addr_t emulated_sdram_base);/* sh7750.c */ struct SH7750State ;
On Thu, 2007-04-19 at 14:06 +0100, Daniel Silverstone wrote:
[snip]
I missed a tiny bit out of the patch, an oversight if you will related to the loading of ARM kernels on systems whose RAM does not start at emulated phys_addr zero.
Here's the extra bit of patch to apply after the patch attached to my previous mail.
petitemort% bzr diff -r-3..-2 ~/dev-simtec/qemu-trunk-simtecbast
=== modified file 'hw/arm_boot.c'
arm_boot.c 2007-04-24 08:35:00 +0000 renamed from arm_boot.c 2007-04-16 21:52:59 +0000 +1 -1
@@ -137,7 +137,7 @@ bootloader[1] |= board_id & 0xff; bootloader[2] |= (board_id >> 8) & 0xff; bootloader[5] = KERNEL_ARGS_ADDR; - bootloader[6] = entry; + bootloader[6] = entry + emulated_sdram_base; for (n = 0; n < sizeof(bootloader) / 4; n++) stl_raw(phys_ram_base + (n * 4), bootloader[n]); set_kernel_args(ram_size, initrd_size, kernel_cmdline, emulated_sdram_base);
zsh: exit 1 bzr diff -r-3..-2
petitemort% ~/dev-simtec/qemu-trunk-simtecbast
Signature · 2 lines
Daniel Silverstone http://www.digital-scurf.org/ PGP mail accepted and encouraged. Key Id: 2BC8 4016 2068 7895