summaryrefslogtreecommitdiffstats
path: root/zpu/sw/simulator/com/zylin/zpu/simulator/Phi.java
blob: 663e68f4e0524b55288d542cc60cd382cedf2b3a (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

package com.zylin.zpu.simulator;

import com.zylin.zpu.simulator.exceptions.CPUException;
import com.zylin.zpu.simulator.exceptions.MemoryAccessException;

public class Phi extends Simulator
{
	@Override
	protected long getSampleOffset()
	{
		 
		return super.getSampleOffset()-(0x5e7b2-0x0005E7C0);
	}


	public static void main(String[] args)
	{
        new SimApp(new SimFactory()
        {
        	public Simulator create()
        	{
        		return new Phi();
        	}
        }).run(args);
	}
    

    protected int getIO()
    {
        return 0x08000000;
    }



    protected int ioRead(int addr) throws CPUException
    {
        switch (addr)
        {
        
        case 0x080a0020:
        	return interrupt?0:1; // interrupt mask

        	
        
            /* FIFO empty? bit 0, FIFO full bit 1(never the case) */
            case 0x080a000c:
            	return 0x100; // buffer ready. 
                
            case 0x080a0014:
            case 0x080a0018:
            return readSampledTimer(addr, 0x080a0014);

            case 0x080a0030:
            	return timerPending?1:0;
            case 0x080a0038:
            	return (int)(timerInterval-1-((cycles-lastTimer)%timerInterval));

            
        	default:
        		throw new MemoryAccessException();
        }
    }



    protected void ioWrite(int addr, int val) throws MemoryAccessException
    {
        switch (addr)
        {
        case 0x080a0020:
        	interrupt=(val&1)==0;
        	return;
        case 0x080a002c:
        	timer=(val&0x1)!=0;
        	break;
        case 0x080a0030:
        	if ((val&0x1)!=0)
        	{
        		timerPending=false;
        	}
        	if ((val&0x2)!=0)
        	{
        		lastTimer=cycles;
        	}
        	break;
        case 0x080a0034:
        	timerInterval=val;
        	return;
        	
            case 0x080a0014:
                writeTimerSampleReg(val);
            case 0x080a000c:
                syscall.writeUART(val);
                break;
        	default:
                throw new MemoryAccessException();
        }
    }

    public Phi() throws CPUException
    {
    }

    protected boolean emulateConfig()
    {
        return true;
    }

    protected int getStartStack()
    {
        return getRAMSIZE()-8;
    }

    protected int getRAMSIZE()
    {
        return 2*1024*1024;
    }


	protected int getIOSIZE()
	{
		return 0x100000;
	}

}
OpenPOWER on IntegriCloud