URL
https://opencores.org/ocsvn/eco32/eco32/trunk
Subversion Repositories eco32
[/] [eco32/] [trunk/] [stdalone/] [memsize/] [main.c] - Rev 139
Go to most recent revision | Compare with Previous | Blame | View Log
/* * main.c -- start the ball rolling */ #include "stdarg.h" #include "start.h" /**************************************************************/ void putchar(char c) { unsigned int *base; if (c == '\n') { putchar('\r'); } base = (unsigned int *) 0xF0300000; while ((*(base + 2) & 1) == 0) ; *(base + 3) = c; } void puts(char *s) { char c; while ((c = *s++) != '\0') { putchar(c); } } void printn(int n) { int a; if (n < 0) { putchar('-'); n = -n; } a = n / 10; if (a != 0) { printn(a); } putchar(n % 10 + '0'); } void printu(unsigned int n, unsigned int b) { unsigned int a; a = n / b; if (a != 0) { printu(a, b); } putchar("0123456789ABCDEF"[n % b]); } void printf(char *fmt, ...) { va_list ap; char c; int n; unsigned int u; char *s; va_start(ap, fmt); while (1) { while ((c = *fmt++) != '%') { if (c == '\0') { va_end(ap); return; } putchar(c); } c = *fmt++; if (c == 'd') { n = va_arg(ap, int); printn(n); } else if (c == 'u' || c == 'o' || c == 'x') { u = va_arg(ap, int); printu(u, c == 'o' ? 8 : (c == 'x' ? 16 : 10)); } else if (c == 's') { s = va_arg(ap, char *); puts(s); } else { putchar(c); } } } /**************************************************************/ static char *exceptionCause[32] = { /* 00 */ "terminal 0 transmitter interrupt", /* 01 */ "terminal 0 receiver interrupt", /* 02 */ "terminal 1 transmitter interrupt", /* 03 */ "terminal 1 receiver interrupt", /* 04 */ "keyboard interrupt", /* 05 */ "unknown interrupt", /* 06 */ "unknown interrupt", /* 07 */ "unknown interrupt", /* 08 */ "disk interrupt", /* 09 */ "unknown interrupt", /* 10 */ "unknown interrupt", /* 11 */ "unknown interrupt", /* 12 */ "unknown interrupt", /* 13 */ "unknown interrupt", /* 14 */ "timer 0 interrupt", /* 15 */ "timer 1 interrupt", /* 16 */ "bus timeout exception", /* 17 */ "illegal instruction exception", /* 18 */ "privileged instruction exception", /* 19 */ "divide instruction exception", /* 20 */ "trap instruction exception", /* 21 */ "TLB miss exception", /* 22 */ "TLB write exception", /* 23 */ "TLB invalid exception", /* 24 */ "illegal address exception", /* 25 */ "privileged address exception", /* 26 */ "unknown exception", /* 27 */ "unknown exception", /* 28 */ "unknown exception", /* 29 */ "unknown exception", /* 30 */ "unknown exception", /* 31 */ "unknown exception" }; int defaultISR(int irq) { printf("\n%s\n", exceptionCause[irq]); return 0; /* do not skip any instruction */ } void initInterrupts(void) { int i; for (i = 0; i < 32; i++) { setISR(i, defaultISR); } } /**************************************************************/ static int busTimeoutSeen; int busTimeoutISR(int irq) { busTimeoutSeen = 1; return 1; /* skip offending instruction */ } int memsize(void) { unsigned char *ptr; unsigned char b; ISR oldService; busTimeoutSeen = 0; oldService = getISR(16); setISR(16, busTimeoutISR); ptr = (unsigned char *) 0xC0000000; while (1) { b = *ptr; if (busTimeoutSeen) { break; } ptr += (1 << 12); } setISR(16, oldService); return (ptr - (unsigned char *) 0xC0000000) >> 12; } /**************************************************************/ void main(void) { int numberPages; initInterrupts(); printf("\n"); printf("Probing memory...\n"); numberPages = memsize(); printf("Memory size = %d pages * 4 Kbytes\n", numberPages); printf("Halting...\n"); }
Go to most recent revision | Compare with Previous | Blame | View Log