summaryrefslogtreecommitdiffstats
path: root/zpu/sw/startup/crt_io.c
blob: 966ae3384455a5c3c5dab6b8dd03e88433393f08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <syscall.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>

extern int _hardware;
/* _cpu_config==0 => Abel
 * _cpu_config==1 => Zeta
 * _cpu_config==2 => Phi
 */
extern int _cpu_config;
static volatile int *UART;
static volatile int *TIMER;
volatile int *MHZ;



/*
 * Wait indefinitely for input byte
 */


int __attribute__ ((weak)) inbyte()  
{
	int val;
	for (;;)
	{
		val=UART[1];
		if ((val&0x100)!=0)
		{
			return val&0xff;
		}
	}
}



/* 
 * Output one character to the serial port 
 * 
 * 
 */
void __attribute__ ((weak)) outbyte(int c)  
{
	/* Wait for space in FIFO */
	while ((UART[0]&0x100)==0);
	UART[0]=c;
}

static const int mhz=64;

void __attribute__ ((weak)) _initIO(void)  
{
	if (_hardware)
	{
		if (_cpu_config==2)
		{
			/* Phi board addresses */
			UART=(volatile int *)0x080a000c;
			TIMER=(volatile int *)0x080a0014; 
			MHZ=(volatile int *)&mhz; 
		} else 
		{
			/* Abel board */
			UART=(volatile int *)0xc000;
			TIMER=(volatile int *)0x9000;
			MHZ=(volatile int *)0x8800;
		}
	} else
	{
		UART=(volatile int *)0x80000024;
		TIMER=(volatile int *)0x80000100;
		MHZ=(volatile int *)0x80000200;
	}
}



long long __attribute__ ((weak)) _readCycles()  
{
	long long clock;
	unsigned int i;
	
	TIMER[0]=0x2; /* sample timer */
	clock=0;
	for (i=0; i<2; i++)
	{
		clock|=((long long )(TIMER[i]))<<(i*32);
	}
	return clock;
}
OpenPOWER on IntegriCloud