-
+ F82EA8FEBCEB149C589262C1387C2A99D641219DAC217DE1BA1E3E99ED8B815B5FE4F6B68128CB55FEFED5BD41B4D764C802B6EBCE34BD4580769027CA001CD7
m/mips.asm
(0 . 0)(1 . 117)
1792 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1793 ;; ;;
1794 ;; This file is part of 'M', a MIPS system emulator. ;;
1795 ;; ;;
1796 ;; (C) 2019 Stanislav Datskovskiy ( www.loper-os.org ) ;;
1797 ;; http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html ;;
1798 ;; ;;
1799 ;; You do not have, nor can you ever acquire the right to use, copy or ;;
1800 ;; distribute this software ; Should you use this software for any purpose, ;;
1801 ;; or copy and distribute it to anyone or in any manner, you are breaking ;;
1802 ;; the laws of whatever soi-disant jurisdiction, and you promise to ;;
1803 ;; continue doing so for the indefinite future. In any case, please ;;
1804 ;; always : read and understand any software ; verify any PGP signatures ;;
1805 ;; that you use - for any purpose. ;;
1806 ;; ;;
1807 ;; See also http://trilema.com/2015/a-new-software-licensing-paradigm . ;;
1808 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1809
1810 ;-----------------------------------------------------------------------------
1811 ; Value of Program Counter (PC) on Warmup
1812 ;-----------------------------------------------------------------------------
1813 %define INIT_PC 0xBFC00000 ; Per traditional MIPS standard.
1814 ;-----------------------------------------------------------------------------
1815
1816 ;-----------------------------------------------------------------------------
1817 ; # of TLB entries. Could have more; but would have to change not only here.
1818 ;-----------------------------------------------------------------------------
1819 %define TLB_ENTRIES_COUNT 16 ; in principle could have more.
1820 ;-----------------------------------------------------------------------------
1821
1822 ;-----------------------------------------------------------------------------
1823 ; MIPS Exceptions Codes (See CP0_Cause Flags re: where they sit)
1824 ;-----------------------------------------------------------------------------
1825 %define EXC_Int 0 ; Interrupt
1826 %define EXC_Mod 1 ; TLB modification exception
1827 %define EXC_TLBL 2 ; TLB exception (load or instruction fetch)
1828 %define EXC_TLBS 3 ; TLB exception (store)
1829 %define EXC_AdEL 4 ; Address error exception (load or instruction fetch)
1830 %define EXC_AdES 5 ; Address error exception (store)
1831 %define EXC_IBE 6 ; Bus error exception (instruction fetch)
1832 %define EXC_DBE 7 ; Bus error exception (data reference: load or store)
1833 %define EXC_SYS 8 ; Syscall exception
1834 %define EXC_BP 9 ; Breakpoint exception
1835 %define EXC_RI 10 ; Reserved instruction exception
1836 %define EXC_CpU 11 ; Coprocessor Unusable exception
1837 %define EXC_Ov 12 ; Arithmetic Overflow exception
1838 %define EXC_Tr 13 ; Trap exception
1839 %define EXC_Watch 23 ; Reference to WatchHi/WatchLo address
1840 %define EXC_MCheck 24 ; Machine check
1841 ;-----------------------------------------------------------------------------
1842
1843 ;-----------------------------------------------------------------------------
1844 ; MIPS CP0_Cause Register
1845 ;-----------------------------------------------------------------------------
1846 ; 11111111111111110000000000000000 EEEEE - Exception Code; IIIIIIII - IRQ;
1847 ; FEDCBA9876543210FEDCBA9876543210 IV - Indicates whether an interrupt
1848 ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ exception uses the general exception
1849 ; B0CC0000IW000000IIIIIIII0EEEEE00 vector or a special interrupt vector:
1850 ; D EE VP 76543210 0: General exception vector (0x180)
1851 ; 1: Special interrupt vector (0x200)
1852 ; BD - Indicates whether last exception taken occurred in a branch delay slot.
1853 ; 0: Not in delay slot; 1: In delay slot.
1854 ; BD bit is not updated on a new exception if the EXL bit is set.
1855 ; IRQ0, IRQ1 -- 'software IRQ'; IRQ2..IRQ7 -- iron IRQ.
1856 ; MIPS Timer (powered by CP0_Count and CP0_Compare) is perma-soldered to IRQ7.
1857 ;-----------------------------------------------------------------------------
1858 %define CP0Cau_IRQ_Bottom 8 ; Index of bit in CP0_Cause where IRQ # lives
1859 %define CP0Cau_IV 23 ; Whether exception uses general or special vect
1860 %define CP0Cau_BD 31 ; Whether exception occurred in branch delay slt
1861 ;-----------------------------------------------------------------------------
1862
1863 ;-----------------------------------------------------------------------------
1864 ; MIPS CP0_Status Register
1865 ;-----------------------------------------------------------------------------
1866 %define CP0St_CU3 31 ; Coprocessor Access CU3 (unused)
1867 %define CP0St_CU2 30 ; Coprocessor Access CU2 (unused)
1868 %define CP0St_CU1 29 ; Coprocessor Access CU1 (unused)
1869 %define CP0St_CU0 28 ; Coprocessor Access CU0 (unused)
1870 %define CP0St_RP 27 ; Reduced Power Mode (unused)
1871 %define CP0St_FR 26 ; Floating Point Reg Mode -- Unused on 32-bit MIPS
1872 %define CP0St_RE 25 ; Reverse-Endianism (0: user, 1: flipped) - unused
1873 %define CP0St_MX 24 ; Unused on 32-bit MIPS
1874 %define CP0St_PX 23 ; Unused on 32-bit MIPS
1875 %define CP0St_BEV 22 ; BEV (0: Normal Exception Vector, 1: Bootstrap)
1876 %define CP0St_TS 21 ; TLB 'multi-match' shutdown (unused)
1877 %define CP0St_SR 20 ; Soft Reset (0: not soft, 1: soft)
1878 %define CP0St_NMI 19 ; NMI (unused)
1879 %define CP0St_IM 8 ; Start of Interrupt Mask (0: IRQ OFF, 1: IRQ ON)
1880 %define CP0St_KX 7 ; Unused on 32-bit MIPS
1881 %define CP0St_SX 6 ; Unused on 32-bit MIPS
1882 %define CP0St_UX 5 ; Unused on 32-bit MIPS
1883 %define CP0St_UM 4 ; User Mode (0: Kernel Mode, 1: User Mode)
1884 %define CP0St_KSU 3 ; Unused
1885 %define CP0St_ERL 2 ; Error Level (0: Normal, 1: Error)
1886 %define CP0St_EXL 1 ; Exception Level (0: Normal, 1: Kernel)
1887 %define CP0St_IE 0 ; Interrupt Enable
1888 ;-----------------------------------------------------------------------------
1889
1890 ;-----------------------------------------------------------------------------
1891 ; MIPS TLB Entry.
1892 ; We don't use C0 and C1 anywhere! and so we can put all of it in 32bits:
1893 ;-----------------------------------------------------------------------------
1894 ; 11111111111111110000000000000000
1895 ; FEDCBA9876543210FEDCBA9876543210
1896 ; --------------------------------
1897 ; GVVDDAAAAAAAAVVVVVVVVVVVVVVVVVVV
1898 ; |1010| ASID || VPN2 |
1899 ;-----------------------------------------------------------------------------
1900 %define TLB_VPN2_Mask 0x7FFFF ; 19 bits
1901 %define TLB_ASID_Mask 0xFF ; 8 bits
1902 %define TLB_ASID_Shift 19 ; sits after VPN2 Mask
1903 %define TLB_D0 27 ; 27th bit
1904 %define TLB_D1 28 ; 28th bit
1905 %define TLB_V0 29 ; 29th bit
1906 %define TLB_V1 30 ; 30th bit
1907 %define TLB_G 31 ; 31st bit (last)
1908 ;-----------------------------------------------------------------------------