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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [stdalone/] [memsize/] [main.c] - Blame information for rev 105

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

Line No. Rev Author Line
1 18 hellwig
/*
2
 * main.c -- start the ball rolling
3
 */
4
 
5
 
6
#include "stdarg.h"
7
#include "start.h"
8
 
9
 
10
/**************************************************************/
11
 
12
 
13
void putchar(char c) {
14
  unsigned int *base;
15
 
16
  if (c == '\n') {
17
    putchar('\r');
18
  }
19
  base = (unsigned int *) 0xF0300000;
20
  while ((*(base + 2) & 1) == 0) ;
21
  *(base + 3) = c;
22
}
23
 
24
 
25
void puts(char *s) {
26
  char c;
27
 
28
  while ((c = *s++) != '\0') {
29
    putchar(c);
30
  }
31
}
32
 
33
 
34
void printn(int n) {
35
  int a;
36
 
37
  if (n < 0) {
38
    putchar('-');
39
    n = -n;
40
  }
41
  a = n / 10;
42
  if (a != 0) {
43
    printn(a);
44
  }
45
  putchar(n % 10 + '0');
46
}
47
 
48
 
49
void printu(unsigned int n, unsigned int b) {
50
  unsigned int a;
51
 
52
  a = n / b;
53
  if (a != 0) {
54
    printu(a, b);
55
  }
56
  putchar("0123456789ABCDEF"[n % b]);
57
}
58
 
59
 
60
void printf(char *fmt, ...) {
61
  va_list ap;
62
  char c;
63
  int n;
64
  unsigned int u;
65
  char *s;
66
 
67
  va_start(ap, fmt);
68
  while (1) {
69
    while ((c = *fmt++) != '%') {
70
      if (c == '\0') {
71
        va_end(ap);
72
        return;
73
      }
74
      putchar(c);
75
    }
76
    c = *fmt++;
77
    if (c == 'd') {
78
      n = va_arg(ap, int);
79
      printn(n);
80
    } else
81
    if (c == 'u' || c == 'o' || c == 'x') {
82
      u = va_arg(ap, int);
83
      printu(u, c == 'o' ? 8 : (c == 'x' ? 16 : 10));
84
    } else
85
    if (c == 's') {
86
      s = va_arg(ap, char *);
87
      puts(s);
88
    } else {
89
      putchar(c);
90
    }
91
  }
92
}
93
 
94
 
95
/**************************************************************/
96
 
97
 
98
static char *exceptionCause[32] = {
99
  /* 00 */  "terminal 0 transmitter interrupt",
100
  /* 01 */  "terminal 0 receiver interrupt",
101
  /* 02 */  "terminal 1 transmitter interrupt",
102
  /* 03 */  "terminal 1 receiver interrupt",
103
  /* 04 */  "keyboard interrupt",
104
  /* 05 */  "unknown interrupt",
105
  /* 06 */  "unknown interrupt",
106
  /* 07 */  "unknown interrupt",
107
  /* 08 */  "disk interrupt",
108
  /* 09 */  "unknown interrupt",
109
  /* 10 */  "unknown interrupt",
110
  /* 11 */  "unknown interrupt",
111
  /* 12 */  "unknown interrupt",
112
  /* 13 */  "unknown interrupt",
113 38 hellwig
  /* 14 */  "timer 0 interrupt",
114
  /* 15 */  "timer 1 interrupt",
115 18 hellwig
  /* 16 */  "bus timeout exception",
116
  /* 17 */  "illegal instruction exception",
117
  /* 18 */  "privileged instruction exception",
118
  /* 19 */  "divide instruction exception",
119
  /* 20 */  "trap instruction exception",
120
  /* 21 */  "TLB miss exception",
121
  /* 22 */  "TLB write exception",
122
  /* 23 */  "TLB invalid exception",
123
  /* 24 */  "illegal address exception",
124
  /* 25 */  "privileged address exception",
125
  /* 26 */  "unknown exception",
126
  /* 27 */  "unknown exception",
127
  /* 28 */  "unknown exception",
128
  /* 29 */  "unknown exception",
129
  /* 30 */  "unknown exception",
130
  /* 31 */  "unknown exception"
131
};
132
 
133
 
134
int defaultISR(int irq) {
135
  printf("\n%s\n", exceptionCause[irq]);
136
  return 0;  /* do not skip any instruction */
137
}
138
 
139
 
140
void initInterrupts(void) {
141
  int i;
142
 
143
  for (i = 0; i < 32; i++) {
144
    setISR(i, defaultISR);
145
  }
146
}
147
 
148
 
149
/**************************************************************/
150
 
151
 
152
static int busTimeoutSeen;
153
 
154
 
155
int busTimeoutISR(int irq) {
156
  busTimeoutSeen = 1;
157
  return 1;  /* skip offending instruction */
158
}
159
 
160
 
161
int memsize(void) {
162
  unsigned char *ptr;
163
  unsigned char b;
164
  ISR oldService;
165
 
166
  busTimeoutSeen = 0;
167
  oldService = getISR(16);
168
  setISR(16, busTimeoutISR);
169
  ptr = (unsigned char *) 0xC0000000;
170
  while (1) {
171
    b = *ptr;
172
    if (busTimeoutSeen) {
173
      break;
174
    }
175
    ptr += (1 << 12);
176
  }
177
  setISR(16, oldService);
178
  return (ptr - (unsigned char *) 0xC0000000) >> 12;
179
}
180
 
181
 
182
/**************************************************************/
183
 
184
 
185
void main(void) {
186
  int numberPages;
187
 
188
  initInterrupts();
189
  printf("\n");
190
  printf("Probing memory...\n");
191
  numberPages = memsize();
192
  printf("Memory size = %d pages * 4 Kbytes\n", numberPages);
193
  printf("Halting...\n");
194
}

powered by: WebSVN 2.1.0

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