Annotation of nono/m680x0/m68030core.h, revision 1.1.1.2

1.1       root        1: //
                      2: // nono
1.1.1.2 ! root        3: // Copyright (C) 2020 nono project
        !             4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
                      7: #pragma once
                      8: 
                      9: #include "m68030.h"
                     10: #include "m68030excep.h"
                     11: #include "mpu.h"
                     12: 
                     13: // XXX ?
                     14: #define CCR                            (cpu->reg.ccr)
                     15: 
                     16: #define RegIsS                 (cpu->reg.s)
                     17: 
                     18: extern void m68030_restore_reg_pi(m68kcpu *);
                     19: extern void m68030_restore_reg_pd(m68kcpu *);
                     20: extern void m68030_set_sr(m68kcpu *, uint16);
                     21: extern void m68030_exception(m68kcpu *, int);
                     22: extern void m68030_exception_reset(m68kcpu *);
1.1.1.2 ! root       23: extern void m68030_exception_buserr(m68kcpu *, int);
1.1       root       24: extern void m68030_exception_interrupt(m68kcpu *, int, int);
                     25: extern void m68030_rte(m68kcpu *);
                     26: extern const char *m68030_get_exception_name(int);
                     27: 
                     28: static inline void cpulog(int lv, const char *fmt, ...) __printflike(2, 3);
                     29: static inline void
                     30: cpulog(int lv, const char *fmt, ...)
                     31: {
                     32:        if (__predict_false(gMPU->loglevel >= lv)) {
                     33:                va_list ap;
                     34:                va_start(ap, fmt);
                     35:                gMPU->vputlog(fmt, ap);
                     36:                va_end(ap);
                     37:        }
                     38: }
                     39: 
                     40: // ops 用のマクロとか
                     41: 
                     42: static inline void
                     43: m68k_add_cycle(m68kcpu *cpu, int cc)
                     44: {
                     45:        cpu->cycle_cache += cc;
                     46: }
                     47: 
                     48: static inline void
                     49: m68k_add_cycle_nc(m68kcpu *cpu, int cc, int ncc)
                     50: {
                     51:        cpu->cycle_cache += cc;
                     52:        cpu->cycle_nocache += ncc - cc;
                     53: }
                     54: 
                     55: // サイクルを加算する。
                     56: // キャッシュケース、ノーキャッシュケースで同じ場合用。
                     57: #define CYCLE(cc)              m68k_add_cycle(cpu, (cc))
                     58: 
                     59: // サイクルを加算する。
                     60: // cc はキャッシュケース、ncc はノーキャッシュケースのサイクル。
                     61: // ncc は cc からの差分ではなく、ノーキャッシュケースの時のサイクル数
                     62: // そのものを指定する。(内部で差分をとっている)
1.1.1.2 ! root       63: #define CYCLE2(cc, ncc)        m68k_add_cycle_nc(cpu, (cc), (ncc))
1.1       root       64: 
                     65: // PC を addr に変更する。
                     66: // addr がメモリからの入力の場合アドレスエラーのチェックが必要なため。
                     67: static inline void
                     68: m68030_jump(m68kcpu *cpu, uint32 addr)
                     69: {
                     70:        // アドレスエラーチェック
                     71:        if (__predict_false((addr & 1) != 0)) {
                     72:                m68030_exception(cpu, M68K_EXCEP_ADDRERR);
                     73:                return;
                     74:        }
                     75: 
                     76:        // ブランチ履歴
1.1.1.2 ! root       77:        cpu->brhist.AddEntry(RegPPC, addr);
        !            78: 
        !            79:        RegPC = addr;
1.1       root       80: }
                     81: 
                     82: // -(An) 実行前にレジスタを保存する。
                     83: // バスエラーからの復帰用。
                     84: static inline void
                     85: m68030_save_reg_pd(m68kcpu *cpu, int n)
                     86: {
                     87:        // 該当ビットのフラグを立てる
                     88:        cpu->flag_pd |= (1 << n);
                     89: 
                     90:        // 保存
                     91:        cpu->save_pd[n] = RegA(n);
                     92: }
                     93: 
                     94: // (An)+ 実行前にレジスタを保存する。
                     95: // バスエラーからの復帰用。
                     96: static inline void
                     97: m68030_save_reg_pi(m68kcpu *cpu, int n)
                     98: {
                     99:        // 該当ビットのフラグを立てる
                    100:        cpu->flag_pi |= (1 << n);
                    101: 
                    102:        // 保存
                    103:        cpu->save_pi[n] = RegA(n);
                    104: }
                    105: 
                    106: // cond で示される条件が成立すれば true を返す。
                    107: static inline bool
                    108: cond_func(m68kcpu *cpu, int cond)
                    109: {
                    110:        switch (cond) {
                    111:         case 0:        // T
                    112:                return RegCondT;
                    113:         case 1:        // F
                    114:                return RegCondF;
                    115:         case 2:
                    116:                return RegCondHI;
                    117:         case 3:
                    118:                return RegCondLS;
                    119:         case 4:
                    120:                return RegCondCC;
                    121:         case 5:
                    122:                return RegCondCS;
                    123:         case 6:
                    124:                return RegCondNE;
                    125:         case 7:
                    126:                return RegCondEQ;
                    127:         case 8:
                    128:                return RegCondVC;
                    129:         case 9:
                    130:                return RegCondVS;
                    131:         case 10:
                    132:                return RegCondPL;
                    133:         case 11:
                    134:                return RegCondMI;
                    135:         case 12:
                    136:                return RegCondGE;
                    137:         case 13:
                    138:                return RegCondLT;
                    139:         case 14:
                    140:                return RegCondGT;
                    141:         case 15:
                    142:                return RegCondLE;
                    143:        }
                    144:        __unreachable();
                    145: }
                    146: 
                    147: 
                    148: // 副作用のあるマクロ
                    149: // 特権違反例外のスタックに積む PC は違反を起こした命令先頭。
1.1.1.2 ! root      150: #define SUPERVISOR_OP  do { \
1.1       root      151:        if (!RegIsS) {  \
                    152:                CYCLE2(18, 20); \
                    153:                m68030_exception(cpu, M68K_EXCEP_PRIV); \
                    154:                return; \
1.1.1.2 ! root      155:        }       \
        !           156: } while (0)

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.