summaryrefslogtreecommitdiffstats
path: root/zpu/sw/simulator/com/zylin/zpu/simulator/Abel.java
blob: 8d8667cde26a329762879dcffd9ab690df756092 (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

package com.zylin.zpu.simulator;

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

public class Abel extends Simulator
{

    protected int getIO()
    {
        return 0x8000;
    }



    protected int ioRead(int addr) throws CPUException
    {
        switch (addr)
        {
            case 0xc000:
                return syscall.readUART();
                
                /* FIFO empty? bit 0, FIFO full bit 1(never the case) */
            case 0xc004:
                return syscall.readFIFO();
                
            case 0x9000:
            case 0x9004:
            case 0x9008:
            case 0x900c:
                
            case 0x9010:
            case 0x9014:
            case 0x9018:
            case 0x901c:
            return readSampledTimer(addr, 0x9000);
            
            case 0x8800:
                return readMHz();
                
        	default:
        		throw new MemoryAccessException();
        }
    }

    /*
    ; Read/write are on different addresses
    ; The registers are 8 bits and mapped to bit[7:0]
    ; 
    ; 0xC000 Write: Writes to UART TX FIFO (4 byte FIFO) 
    ;        Read : Reads from UART RX FIFO (4 byte FIFO)
    ; 0xC004 Read : UART status register
    ;                       Bit 0 = RX FIFO empty
    ;                       Bit 1 = TX FIFO full
    ; 0xA000 Write: 8 LED's 
    */
    
    /*
    0x9000 Write: bit 0: 1= reset counter
                   0= counter running
              bit 1: 1= sample counter (when set to 1)
                   0=not used
         Read : counter bit[7:0]
    0x9004 Read: counter bit [15:8]
    0x9008 Read: counter bit [23:16]
    0x900C Read: counter bit [31:24]
    0x9010 Read: counter bit [39:32]
    0x9014 Read: counter bit [47:40]
    0x9018 Read: counter bit [55:48]
    0x901C Read: counter bit [63:56]

    0x8800 Read: unsigned 8-bit integer with FPGA frequency (in MHz)
    */

    protected void ioWrite(int addr, int val) throws MemoryAccessException
    {
        switch (addr)
        {
            case 0x9000:
                writeTimerSampleReg(val);
            case 0xc000:
                syscall.writeUART(val);
                break;
        	default:
                throw new MemoryAccessException();
        }
    }

    Abel() throws CPUException
    {
    }

    protected boolean emulateConfig()
    {
        return true;
    }

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

    protected int getRAMSIZE()
    {
        return 32768;
    }

}
OpenPOWER on IntegriCloud