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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [orpmon/] [common/] [support.c] - Rev 833

Go to most recent revision | Compare with Previous | Blame | View Log

/* Support */
 
#include <sys/time.h>
#include "spr_defs.h"
#include "support.h"
#include "common.h"
#include "int.h"
 
volatile unsigned long timestamp = 0;
 
void int_main(void);
 
/* return value by making a syscall */
void exit (int i)
{
  asm("l.add r3,r0,%0": : "r" (i));
  asm("l.nop %0": :"K" (NOP_EXIT));
  while (1);
}
 
/* activate printf support in simulator */
void __printf(const char *fmt, ...)
{
 
  va_list args;
  va_start(args, fmt);
  __asm__ __volatile__ ("  l.addi\tr3,%1,0\n \
                           l.addi\tr4,%2,0\n \
                           l.nop %0": :"K" (NOP_PRINTF), "r" (fmt), "r"  (args) : "r3", "r4");
}
 
/* print long */
void report(unsigned long value)
{
  asm("l.addi\tr3,%0,0": :"r" (value));
  asm("l.nop %0": :"K" (NOP_REPORT));
}
 
/* just to satisfy linker */
void __main(void)
{
}
 
/* For writing into SPR. */
void mtspr(unsigned long spr, unsigned long value)
{	
  asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
}
 
/* For reading SPR. */
unsigned long mfspr(unsigned long spr)
{	
  unsigned long value;
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
  return value;
}
 
void *memcpy (void *dstv, const void *srcv, unsigned long length)
{
  char *dst = dstv;
  const char *src = (const char *) srcv;
 
  while (length--)
    *dst++ = *src++;
  return dst;
}
 
void *memmove (void *dstv, const void *srcv, unsigned long length)
{
  char *dst = dstv;
  const char *src = srcv;
 
  /* Copy backwards? */
  if (src < dst && dst < src + length) {
    src += length;
    dst += length;
    while (length--) *--dst = *--src;
    return dstv;
	} else return memcpy (dstv, srcv, length);
}
 
int memcmp (void *dstv, const void *srcv, unsigned long length)
{
  char *dst = dstv;
  const char *src = (const char *) srcv;
 
  while (length--)
    if(*dst++ != *src++) {
      if(*(--dst) > *(--src))
        return 1;
      else 
        return -1;
    }
  return 1;
}
 
void *memchr (void *dstvoid, const char data, unsigned long length)
{
  char *dst = dstvoid;
  while (length--) *dst++ = data;
  return dst;
}
 
int strlen (const char *src)
{
  int len = 0;
  while (*src++) len++;
  return len;
}
 
int strcmp (const char *s1, const char *s2)
{
  while (*s1 != '\0' && *s1 == *s2) {
    s1++;
    s2++;
  }
  return (*(unsigned char *) s1) - (*(unsigned char *) s2);                      
}
 
char *strcpy (char *dst0, char *src0)
{
  char *s = dst0;
  while ((*dst0++ = *src0++));
  return s;	
}
 
void reset_timer (void)
{
  timestamp = 0;
}
 
/* Parses hex or decimal number */
unsigned long strtoul (const char *str, char **endptr, int base)
{
  unsigned long number = 0;
  char *pos = (char *) str;
  char *fail_char = (char *) str;
 
  while (isspace(*pos)) pos++;	/* skip leading whitespace */
 
  if ((base == 16) && (*pos == '0')) { /* handle option prefix */
    ++pos;
    fail_char = pos;
    if ((*pos == 'x') || (*pos == 'X')) ++pos;
  }
 
  if (base == 0) {		/* dynamic base */
    base = 10;		/* default is 10 */
    if (*pos == '0') {
      ++pos;
      base -= 2;		/* now base is 8 (or 16) */
      fail_char = pos;
      if ((*pos == 'x') || (*pos == 'X')) {
        base += 8;	/* base is 16 */
        ++pos;
      }
    }
  }
 
  if ((base < 2) || (base > 36)) goto done; /* illegal base */
 
  while (1) {
    int digit = 40;
    if ((*pos >= '0') && (*pos <= '9')) {
        digit = (*pos - '0');
    } else if (*pos >= 'a') {
        digit = (*pos - 'a' + 10);
    } else if (*pos >= 'A') {
        digit = (*pos - 'A' + 10);
    } else break;
 
    if (digit >= base) break;
 
    fail_char = ++pos;
    number = number * base + digit;
  }
 
done:
  if (endptr) *endptr = fail_char;
  return number;
}
 
unsigned long get_timer (unsigned long base)
{
__printf("%s - %s: %d\n", __FILE__, __FUNCTION__, __LINE__);
__printf("   timestamp = %.8lx base = %.8lx\n", timestamp, base);
  return (timestamp - base);
}
 
void set_timer (unsigned long t)
{
  timestamp = t;
}
 
 

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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