<commit_before>package net.katsuster.ememu.riscv;

import net.katsuster.ememu.generic.*;

/**
 * DDR Controller
 *
 * 参考: SiFive FU540-C000 Manual: v1p0
 */
public class DDRController implements ParentCore {
    private DDRControllerSlave slave;

    public static final int REG_CTRL000 = 0x0000;
    public static final int REG_CTRL264 = 0x0420;

    public static final int REG_PHY0000 = 0x2000;
    public static final int REG_PHY1214 = 0x32f8;

    //8bytes registers
    public static final int REG_BUSBLOCKER_L = 0x8000;
    public static final int REG_BUSBLOCKER_H = 0x8004;

    public DDRController() {
        slave = new DDRControllerSlave();
    }

    @Override
    public SlaveCore64 getSlaveCore() {
        return slave;
    }

    class DDRControllerSlave extends Controller32 {
        public DDRControllerSlave() {
            for (int i = 0; i <= 264; i++) {
                addReg(REG_CTRL000 + i * 4, "CTRL" + i, 0x00000000);
            }
            for (int i = 0; i <= 1214; i++) {
                addReg(REG_PHY0000 + i * 4, "PHY" + i, 0x00000000);
            }

            addReg(REG_BUSBLOCKER_L, "BUSBLOCKER_L", 0x80000000);
            addReg(REG_BUSBLOCKER_H, "BUSBLOCKER_H", 0x80000000);
        }

        @Override
        public int readWord(BusMaster64 m, long addr) {
            int regaddr;
            int result;

            regaddr = (int) (addr & BitOp.getAddressMask(LEN_WORD_BITS));

            switch (regaddr) {
            case 0x210:
                result = super.readWord(m, regaddr);
                result |= 0x100;
                break;
            default:
                result = super.readWord(m, regaddr);
                break;
            }

            return result;
        }

        @Override
        public void writeWord(BusMaster64 m, long addr, int data) {
            int regaddr;

            regaddr = (int) (addr & BitOp.getAddressMask(LEN_WORD_BITS));

            if (REG_CTRL000 <= regaddr && regaddr <= REG_CTRL264) {
                int i = (regaddr - REG_CTRL000) >> 2;
                System.out.printf("DDRC: wr CTRL%d 0x%x\n", i, data);
                return;
            }

            if (REG_PHY0000 <= regaddr && regaddr <= REG_PHY1214) {
                int i = (regaddr - REG_PHY0000) >> 2;
                System.out.printf("DDRC: wr PHY%d 0x%x\n", i, data);
                return;
            }

            switch (regaddr) {
            default:
                super.writeWord(m, regaddr, data);<commit_msg>riscv: reduce DDR core log<commit_after>package net.katsuster.ememu.riscv;

import net.katsuster.ememu.generic.*;

/**
 * DDR Controller
 *
 * 参考: SiFive FU540-C000 Manual: v1p0
 */
public class DDRController implements ParentCore {
    private DDRControllerSlave slave;

    public static final int REG_CTRL000 = 0x0000;
    public static final int REG_CTRL264 = 0x0420;

    public static final int REG_PHY0000 = 0x2000;
    public static final int REG_PHY1214 = 0x32f8;

    //8bytes registers
    public static final int REG_BUSBLOCKER_L = 0x8000;
    public static final int REG_BUSBLOCKER_H = 0x8004;

    public DDRController() {
        slave = new DDRControllerSlave();
    }

    @Override
    public SlaveCore64 getSlaveCore() {
        return slave;
    }

    class DDRControllerSlave extends Controller32 {
        public DDRControllerSlave() {
            for (int i = 0; i <= 264; i++) {
                addReg(REG_CTRL000 + i * 4, "CTRL" + i, 0x00000000);
            }
            for (int i = 0; i <= 1214; i++) {
                addReg(REG_PHY0000 + i * 4, "PHY" + i, 0x00000000);
            }

            addReg(REG_BUSBLOCKER_L, "BUSBLOCKER_L", 0x80000000);
            addReg(REG_BUSBLOCKER_H, "BUSBLOCKER_H", 0x80000000);
        }

        @Override
        public int readWord(BusMaster64 m, long addr) {
            int regaddr;
            int result;

            regaddr = (int) (addr & BitOp.getAddressMask(LEN_WORD_BITS));

            if (REG_CTRL000 <= regaddr && regaddr <= REG_CTRL264) {
                int i = (regaddr - REG_CTRL000) >> 2;

                switch (i) {
                case 0:
                case 19:
                case 21:
                case 120:
                    result = super.readWord(m, regaddr);
                    break;
                case 132:
                    result = super.readWord(m, regaddr);
                    //int_status[8]: Initialization has been completed
                    result |= 0x100;
                    break;
                case 136:
                    result = super.readWord(m, regaddr);
                    break;
                default:
                    result = super.readWord(m, regaddr);
                    break;
                }

                return result;
            }

            switch (regaddr) {
            default:
                result = super.readWord(m, regaddr);
                break;
            }

            return result;
        }

        @Override
        public void writeWord(BusMaster64 m, long addr, int data) {
            int regaddr;

            regaddr = (int) (addr & BitOp.getAddressMask(LEN_WORD_BITS));

            if (REG_CTRL000 <= regaddr && regaddr <= REG_CTRL264) {
                int i = (regaddr - REG_CTRL000) >> 2;

                switch (i) {
                case 0:
                case 19:
                case 21:
                case 120:
                case 132:
                case 136:
                    System.out.printf("DDRC: wr CTRL%d 0x%x\n", i, data);
                    break;
                }

                return;
            }

            if (REG_PHY0000 <= regaddr && regaddr <= REG_PHY1214) {
                int i = (regaddr - REG_PHY0000) >> 2;
                //System.out.printf("DDRC: wr PHY%d 0x%x\n", i, data);
                return;
            }

            switch (regaddr) {
            default:
                super.writeWord(m, regaddr, data);
{'fraction_non_alphanumeric': 0.09380234505862646, 'fraction_numerical': 0.05510887772194305, 'mean_word_length': 1.4693961952026469, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6883729', 'n_tokens_mistral': 2062, 'n_tokens_neox': 1707, 'n_words': 446}