OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [libgloss/] [sparc/] [salib-701.c] - Diff between revs 158 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 158 Rev 816
/* Stand-alone library for Sparclet 701 board
/* Stand-alone library for Sparclet 701 board
 *
 *
 * Copyright (c) 1996 Cygnus Support
 * Copyright (c) 1996 Cygnus Support
 *
 *
 * The authors hereby grant permission to use, copy, modify, distribute,
 * The authors hereby grant permission to use, copy, modify, distribute,
 * and license this software and its documentation for any purpose, provided
 * and license this software and its documentation for any purpose, provided
 * that existing copyright notices are retained in all copies and that this
 * that existing copyright notices are retained in all copies and that this
 * notice is included verbatim in any distributions. No written agreement,
 * notice is included verbatim in any distributions. No written agreement,
 * license, or royalty fee is required for any of the authorized uses.
 * license, or royalty fee is required for any of the authorized uses.
 * Modifications to this software may be copyrighted by their authors
 * Modifications to this software may be copyrighted by their authors
 * and need not follow the licensing terms described here, provided that
 * and need not follow the licensing terms described here, provided that
 * the new terms are clearly indicated on the first page of each file where
 * the new terms are clearly indicated on the first page of each file where
 * they apply.
 * they apply.
 */
 */
 
 
#define RAM_BASE                ((unsigned char *)0x12000000) /* Start of cacheable dram */
#define RAM_BASE                ((unsigned char *)0x12000000) /* Start of cacheable dram */
#define DCACHE_LINES            128        /* Number of lines in data cache */
#define DCACHE_LINES            128        /* Number of lines in data cache */
#define DCACHE_LINE_SIZE        16         /* Bytes per data cache line */
#define DCACHE_LINE_SIZE        16         /* Bytes per data cache line */
#define DCACHE_BANKS            4          /* 4-way associative */
#define DCACHE_BANKS            4          /* 4-way associative */
#define CACHE_INST_TAG_ADDR     ((unsigned char *)0xc0020000) /* I-Cache tag base address */
#define CACHE_INST_TAG_ADDR     ((unsigned char *)0xc0020000) /* I-Cache tag base address */
#define ALL_BANKS               0x0000f000 /* Selects all 4 cache banks */
#define ALL_BANKS               0x0000f000 /* Selects all 4 cache banks */
#define ICACHE_LINES            128        /* Number of lines in inst cache */
#define ICACHE_LINES            128        /* Number of lines in inst cache */
#define ICACHE_LINE_SIZE        32         /* Bytes per inst cache line */
#define ICACHE_LINE_SIZE        32         /* Bytes per inst cache line */
 
 
/* I/O Base addresses */
/* I/O Base addresses */
#define CACHE_INST_BASE_ADD     0xc0000000
#define CACHE_INST_BASE_ADD     0xc0000000
#define CACHE_DATA_BASE_ADD     0xc8000000
#define CACHE_DATA_BASE_ADD     0xc8000000
#define _InstrCacheCtlBase      0xc0000000
#define _InstrCacheCtlBase      0xc0000000
#define _DataCacheCtlBase       0xc8000000
#define _DataCacheCtlBase       0xc8000000
 
 
#define USART_BASE_ADD          0x92000000
#define USART_BASE_ADD          0x92000000
#define USART_BASE_ADRS(n)      (USART_BASE_ADD + ((n)<<21))    /*0..3*/
#define USART_BASE_ADRS(n)      (USART_BASE_ADD + ((n)<<21))    /*0..3*/
 
 
/* Serial receiver definitions */
/* Serial receiver definitions */
#define USART_RX_CHAR(n) (*(unsigned char *) (USART_BASE_ADRS(n)  +(2<<19)))
#define USART_RX_CHAR(n) (*(unsigned char *) (USART_BASE_ADRS(n)  +(2<<19)))
#define USART_RX_CTRL_BASE_ADRS(n)       (USART_BASE_ADRS(n)+(3<<19))
#define USART_RX_CTRL_BASE_ADRS(n)       (USART_BASE_ADRS(n)+(3<<19))
#define URSTR(n)        (*(unsigned int *) (USART_RX_CTRL_BASE_ADRS(n)+(2<<15)))
#define URSTR(n)        (*(unsigned int *) (USART_RX_CTRL_BASE_ADRS(n)+(2<<15)))
#define URSTR_CHAR_NUM                  0x1f00  /* Bits 8-12 */
#define URSTR_CHAR_NUM                  0x1f00  /* Bits 8-12 */
 
 
/* Serial receiver definitions */
/* Serial receiver definitions */
#define USART_TX_CHAR(n)        (*(unsigned char *) (USART_BASE_ADRS(n)+3))
#define USART_TX_CHAR(n)        (*(unsigned char *) (USART_BASE_ADRS(n)+3))
#define USART_TX_CTRL_BASE_ADRS(n)       (USART_BASE_ADRS(n)+(1<<19))
#define USART_TX_CTRL_BASE_ADRS(n)       (USART_BASE_ADRS(n)+(1<<19))
#define UTSTR(n)        (*(unsigned int *) (USART_TX_CTRL_BASE_ADRS(n)+(2<<15)))
#define UTSTR(n)        (*(unsigned int *) (USART_TX_CTRL_BASE_ADRS(n)+(2<<15)))
#define UTSTR_CHAR_FREE                 0x1f0   /* Bits 4-8 */
#define UTSTR_CHAR_FREE                 0x1f0   /* Bits 4-8 */
 
 
/* Cache definitions */
/* Cache definitions */
#define DCCA_NB_LINES       128         /* Nb of lines of the cache */
#define DCCA_NB_LINES       128         /* Nb of lines of the cache */
/* Bank number, used for Cache Memory and Cache Tag */
/* Bank number, used for Cache Memory and Cache Tag */
#define ICCA_B3         0x000008000     /* Bit 15 - 1:Bank3 selected       */
#define ICCA_B3         0x000008000     /* Bit 15 - 1:Bank3 selected       */
#define ICCA_B2         0x000004000     /* Bit 14 - 1:Bank2 selected       */
#define ICCA_B2         0x000004000     /* Bit 14 - 1:Bank2 selected       */
#define ICCA_B1         0x000002000     /* Bit 13 - 1:Bank1 selected       */
#define ICCA_B1         0x000002000     /* Bit 13 - 1:Bank1 selected       */
#define ICCA_B0         0x000001000     /* Bit 12 - 1:Bank0 selected       */
#define ICCA_B0         0x000001000     /* Bit 12 - 1:Bank0 selected       */
/* Register address, show which register is to be checked/updated */
/* Register address, show which register is to be checked/updated */
#define ICCACR          0x00000000      /* Bits 17 - 16 - Control register */
#define ICCACR          0x00000000      /* Bits 17 - 16 - Control register */
#define ICCAMEM         0x00010000      /* Bits 17 - 16 - Cache memory     */
#define ICCAMEM         0x00010000      /* Bits 17 - 16 - Cache memory     */
#define DCCACR          0x00000000      /* Bits 16 - 15 - Control register */
#define DCCACR          0x00000000      /* Bits 16 - 15 - Control register */
/* Instruction Cache Controller Register */
/* Instruction Cache Controller Register */
#define ICCR_DISABLE  0xfffffffe        /* Reset enable bit                 */
#define ICCR_DISABLE  0xfffffffe        /* Reset enable bit                 */
 
 
/* Serial I/O routines */
/* Serial I/O routines */
 
 
#define STUB_PORT 1             /* 0 = serial port A;  1 = serial port B */
#define STUB_PORT 1             /* 0 = serial port A;  1 = serial port B */
 
 
static volatile unsigned char *rx_fifo = &USART_RX_CHAR(STUB_PORT);
static volatile unsigned char *rx_fifo = &USART_RX_CHAR(STUB_PORT);
static volatile unsigned int *rx_status = &URSTR(STUB_PORT);
static volatile unsigned int *rx_status = &URSTR(STUB_PORT);
 
 
static volatile unsigned char *tx_fifo = &USART_TX_CHAR(STUB_PORT);
static volatile unsigned char *tx_fifo = &USART_TX_CHAR(STUB_PORT);
static volatile unsigned int *tx_status = &UTSTR(STUB_PORT);
static volatile unsigned int *tx_status = &UTSTR(STUB_PORT);
 
 
/* library-free debug reoutines */
/* library-free debug reoutines */
#ifdef XDEBUG
#ifdef XDEBUG
#define XDBG_MSG(x) pmsg(x)
#define XDBG_MSG(x) pmsg(x)
#define XDBG_HEX(x) phex(x)
#define XDBG_HEX(x) phex(x)
#else
#else
#define XDBG_MSG(x) 
#define XDBG_MSG(x) 
#define XDBG_HEX(x) 
#define XDBG_HEX(x) 
#endif
#endif
 
 
static int
static int
rx_rdy()
rx_rdy()
{
{
  return (*rx_status & URSTR_CHAR_NUM);
  return (*rx_status & URSTR_CHAR_NUM);
}
}
 
 
static unsigned char
static unsigned char
rx_char()
rx_char()
{
{
  return *rx_fifo;
  return *rx_fifo;
}
}
 
 
void
void
tx_char(char c)
tx_char(char c)
{
{
  *tx_fifo = c;
  *tx_fifo = c;
}
}
 
 
static int
static int
tx_rdy()
tx_rdy()
{
{
  return (*tx_status & UTSTR_CHAR_FREE);
  return (*tx_status & UTSTR_CHAR_FREE);
}
}
 
 
int
int
getDebugChar()
getDebugChar()
{
{
  while (!rx_rdy())
  while (!rx_rdy())
    ;
    ;
  return rx_char();
  return rx_char();
}
}
 
 
void
void
putDebugChar(int c)
putDebugChar(int c)
{
{
  while (!tx_rdy())
  while (!tx_rdy())
    ;
    ;
  tx_char(c);
  tx_char(c);
}
}
 
 
#ifdef XDEBUG
#ifdef XDEBUG
/* library-free debug reoutines */
/* library-free debug reoutines */
/* print a string */
/* print a string */
void pmsg(char *p)
void pmsg(char *p)
{
{
    while (*p)
    while (*p)
    {
    {
        if (*p == '\n')
        if (*p == '\n')
            putDebugChar('\r');
            putDebugChar('\r');
        putDebugChar(*p++);
        putDebugChar(*p++);
    }
    }
}
}
 
 
/* print a hex number */
/* print a hex number */
void phex(long x)
void phex(long x)
{
{
    char buf[9];
    char buf[9];
    int i;
    int i;
 
 
    buf[8] = '\0';
    buf[8] = '\0';
    for (i = 7; i >= 0; i--)
    for (i = 7; i >= 0; i--)
    {
    {
        char c = x & 0x0f;
        char c = x & 0x0f;
        buf[i] = c < 10 ? c + '0' : c - 10 + 'A';
        buf[i] = c < 10 ? c + '0' : c - 10 + 'A';
        x >>= 4;
        x >>= 4;
    }
    }
    pmsg(buf);
    pmsg(buf);
}
}
#endif
#endif
 
 
/* rdtbr() - read the trap base register */
/* rdtbr() - read the trap base register */
 
 
unsigned long rdtbr();
unsigned long rdtbr();
 
 
asm("
asm("
        .text
        .text
        .align 4
        .align 4
        .globl _rdtbr
        .globl _rdtbr
_rdtbr:
_rdtbr:
        retl
        retl
        mov     %tbr, %o0
        mov     %tbr, %o0
");
");
 
 
/* wrtbr() - write the trap base register */
/* wrtbr() - write the trap base register */
 
 
void wrtbr(unsigned long);
void wrtbr(unsigned long);
 
 
asm("
asm("
        .text
        .text
        .align 4
        .align 4
        .globl _wrtbr
        .globl _wrtbr
_wrtbr:
_wrtbr:
        retl
        retl
        mov     %o0, %tbr
        mov     %o0, %tbr
");
");
 
 
/* Each entry in the trap vector occupies four words. */
/* Each entry in the trap vector occupies four words. */
 
 
struct trap_entry
struct trap_entry
{
{
  unsigned sethi_filler:10;
  unsigned sethi_filler:10;
  unsigned sethi_imm22:22;
  unsigned sethi_imm22:22;
  unsigned jmpl_filler:19;
  unsigned jmpl_filler:19;
  unsigned jmpl_simm13:13;
  unsigned jmpl_simm13:13;
  unsigned long filler[2];
  unsigned long filler[2];
};
};
 
 
extern struct trap_entry fltr_proto;
extern struct trap_entry fltr_proto;
asm ("
asm ("
        .data
        .data
        .globl _fltr_proto
        .globl _fltr_proto
        .align 4
        .align 4
_fltr_proto:                    ! First level trap routine prototype
_fltr_proto:                    ! First level trap routine prototype
        sethi 0, %l0
        sethi 0, %l0
        jmpl 0+%l0, %g0
        jmpl 0+%l0, %g0
        nop
        nop
        nop
        nop
 
 
        .text
        .text
        .align 4
        .align 4
");
");
 
 
/* copy_vectors - Copy the trap vectors from ROM to RAM, set the TBR register
/* copy_vectors - Copy the trap vectors from ROM to RAM, set the TBR register
   to point to the RAM vectors, and return the address of the RAM vectors.  */
   to point to the RAM vectors, and return the address of the RAM vectors.  */
 
 
extern struct trap_entry __trap_vectors[256];   /* defined in matra.ld */
extern struct trap_entry __trap_vectors[256];   /* defined in matra.ld */
 
 
struct trap_entry *copy_vectors()
struct trap_entry *copy_vectors()
{
{
  int i;
  int i;
  struct trap_entry *old = (struct trap_entry *) (rdtbr() & ~0xfff);
  struct trap_entry *old = (struct trap_entry *) (rdtbr() & ~0xfff);
 
 
  XDBG_MSG("Copying vectors...\n");
  XDBG_MSG("Copying vectors...\n");
  for (i = 0; i < 256; i++)
  for (i = 0; i < 256; i++)
    __trap_vectors[i] = old[i];
    __trap_vectors[i] = old[i];
  wrtbr ((unsigned long)__trap_vectors);
  wrtbr ((unsigned long)__trap_vectors);
  XDBG_MSG("Done\n");
  XDBG_MSG("Done\n");
  return __trap_vectors;
  return __trap_vectors;
}
}
 
 
 
 
void
void
disable_cache()
disable_cache()
{
{
  unsigned long *ptr;
  unsigned long *ptr;
  static unsigned long CACHE_shadow_iccr = 0;   /* Because CR cannot be read */
  static unsigned long CACHE_shadow_iccr = 0;   /* Because CR cannot be read */
  static unsigned long CACHE_shadow_dccr = 0;   /* Because CR cannot be read */
  static unsigned long CACHE_shadow_dccr = 0;   /* Because CR cannot be read */
 
 
  XDBG_MSG("Disabling cache...\n");
  XDBG_MSG("Disabling cache...\n");
  ptr = (unsigned long*)(CACHE_INST_BASE_ADD | ICCACR);
  ptr = (unsigned long*)(CACHE_INST_BASE_ADD | ICCACR);
  CACHE_shadow_iccr = CACHE_shadow_iccr & ICCR_DISABLE;
  CACHE_shadow_iccr = CACHE_shadow_iccr & ICCR_DISABLE;
  *ptr = CACHE_shadow_iccr;
  *ptr = CACHE_shadow_iccr;
 
 
  ptr = (unsigned long*)(CACHE_DATA_BASE_ADD | DCCACR);
  ptr = (unsigned long*)(CACHE_DATA_BASE_ADD | DCCACR);
  CACHE_shadow_dccr = CACHE_shadow_dccr & ICCR_DISABLE;
  CACHE_shadow_dccr = CACHE_shadow_dccr & ICCR_DISABLE;
  *ptr = CACHE_shadow_dccr;
  *ptr = CACHE_shadow_dccr;
  XDBG_MSG("Done\n");
  XDBG_MSG("Done\n");
}
}
 
 
/* Flush the instruction cache.  We need to do this for the debugger stub so
/* Flush the instruction cache.  We need to do this for the debugger stub so
   that breakpoints, et. al. become visible to the instruction stream after
   that breakpoints, et. al. become visible to the instruction stream after
   storing them in memory.  FIXME!!
   storing them in memory.  FIXME!!
 */
 */
 
 
void
void
flush_i_cache ()
flush_i_cache ()
{
{
  volatile unsigned char *addr;
  volatile unsigned char *addr;
 
 
  /* First, force all dirty items in the data cache to be moved out to real
  /* First, force all dirty items in the data cache to be moved out to real
     memory.  This is done by making read refs to alternate addresses that will
     memory.  This is done by making read refs to alternate addresses that will
     fill up all four banks for each line.  Note that we actually have to
     fill up all four banks for each line.  Note that we actually have to
     reference 8 locs per line just in case the region of memory we use is one
     reference 8 locs per line just in case the region of memory we use is one
     of the areas that needs to be flushed.  */
     of the areas that needs to be flushed.  */
 
 
  for (addr = RAM_BASE;
  for (addr = RAM_BASE;
       addr < RAM_BASE + (DCACHE_LINES * DCACHE_LINE_SIZE * DCACHE_BANKS) * 2;
       addr < RAM_BASE + (DCACHE_LINES * DCACHE_LINE_SIZE * DCACHE_BANKS) * 2;
       addr += DCACHE_LINE_SIZE)
       addr += DCACHE_LINE_SIZE)
    *addr;                      /* Read the loc */
    *addr;                      /* Read the loc */
 
 
  /* Now, flush the instruction cache.  */
  /* Now, flush the instruction cache.  */
 
 
  for (addr = CACHE_INST_TAG_ADDR + ALL_BANKS;
  for (addr = CACHE_INST_TAG_ADDR + ALL_BANKS;
       addr <= CACHE_INST_TAG_ADDR + ALL_BANKS + ICACHE_LINES * ICACHE_LINE_SIZE;
       addr <= CACHE_INST_TAG_ADDR + ALL_BANKS + ICACHE_LINES * ICACHE_LINE_SIZE;
       addr += ICACHE_LINE_SIZE)
       addr += ICACHE_LINE_SIZE)
    *(unsigned long *)addr = 0; /* Clr tag entry for all banks on this line */
    *(unsigned long *)addr = 0; /* Clr tag entry for all banks on this line */
}
}
 
 
/* Setup trap TT to go to ROUTINE. */
/* Setup trap TT to go to ROUTINE. */
 
 
void
void
exceptionHandler (int tt, unsigned long routine)
exceptionHandler (int tt, unsigned long routine)
{
{
  static struct trap_entry *tb;         /* Trap vector base address */
  static struct trap_entry *tb;         /* Trap vector base address */
 
 
  if (!tb)
  if (!tb)
    {
    {
      tb = copy_vectors();              /* Copy trap vectors to RAM */
      tb = copy_vectors();              /* Copy trap vectors to RAM */
      disable_cache();                  /* Disable cache  FIXME!! */
      disable_cache();                  /* Disable cache  FIXME!! */
    }
    }
 
 
  XDBG_MSG("Setting exception handler for trap...\n");
  XDBG_MSG("Setting exception handler for trap...\n");
 
 
  tb[tt] = fltr_proto;
  tb[tt] = fltr_proto;
 
 
  tb[tt].sethi_imm22 = routine >> 10;
  tb[tt].sethi_imm22 = routine >> 10;
  tb[tt].jmpl_simm13 = routine & 0x3ff;
  tb[tt].jmpl_simm13 = routine & 0x3ff;
 
 
  XDBG_MSG("Done\n");
  XDBG_MSG("Done\n");
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.