#pypp 0 // Iris: micro-kernel for a capability-based operating system. // mips/arch.hhp: mips-specific declarations and type definitions. // Copyright 2009 Bas Wijnen // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #ifndef _ARCH_HH #define _ARCH_HH #ifdef ARCH #ifndef ASM #include "board.hh" #endif #define reg_hack(x...) #x #define cp0_get(reg, target) do { __asm__ volatile ("mfc0 %0, $" reg_hack(reg) : "=r" (target)); } while (0) #define cp0_set(reg, value) do { __asm__ volatile ("mtc0 %0, $" reg_hack(reg) :: "r" (value)); } while (0) #define cp0_set0(reg) do { __asm__ volatile ("mtc0 $zero, $" reg_hack(reg)); } while (0) // cp0 registers. #define CP0_INDEX 0 #define CP0_RANDOM 1 #define CP0_ENTRY_LO0 2 #define CP0_ENTRY_LO1 3 #define CP0_CONTEXT 4 #define CP0_PAGE_MASK 5 #define CP0_WIRED 6 #define CP0_BAD_V_ADDR 8 #define CP0_COUNT 9 #define CP0_ENTRY_HI 10 #define CP0_COMPARE 11 #define CP0_STATUS 12 #define CP0_INT_CTL 12, 1 #define CP0_CAUSE 13 #define CP0_EPC 14 #define CP0_P_R_ID 15 #define CP0_EBASE 15, 1 #define CP0_CONFIG 16 #define CP0_CONFIG1 16, 1 #define CP0_CONFIG2 16, 2 #define CP0_CONFIG3 16, 3 #define CP0_L_L_ADDR 17 #define CP0_WATCH_LO 18 #define CP0_WATCH_HI 19 #define CP0_DEBUG 23 #define CP0_DEPC 24 #define CP0_PERF_CNT 25 #define CP0_ERR_CTL 26 #define CP0_CACHE_ERR 27 #define CP0_TAG_LO 28, 0 #define CP0_DATA_LO 28, 1 #define CP0_TAG_HI 29, 0 #define CP0_DATA_HI 29, 1 #define CP0_ERROR_EPC 30 #define CP0_DESAVE 31 #endif #ifdef __KERNEL__ // register save positions in kThread #define SAVE_PC (6 * 4) #define SAVE_SP (SAVE_PC + 4) #define SAVE_AT (SAVE_SP + 4) #define SAVE_V (SAVE_AT + 4) #define SAVE_A (SAVE_V + 2 * 4) #define SAVE_T (SAVE_A + 4 * 4) #define SAVE_S (SAVE_T + 10 * 4) #define SAVE_GP (SAVE_S + 8 * 4) #define SAVE_FP (SAVE_GP + 4) #define SAVE_RA (SAVE_FP + 4) #define SAVE_HI (SAVE_RA + 4) #define SAVE_LO (SAVE_HI + 4) #define SAVE_K (SAVE_LO + 4) #ifndef ASM void flush_tlb (unsigned asid) void arch_flush_cache () struct kThread_arch: unsigned at, v[2], a[4], t[10], s[8], gp, fp, ra, hi, lo, k[2] // The following is used for page mapping. // Each Memory has a directory with 0x400 page tables. // Page tables are pages which contain 0x200 EntryLo. values and 0x200 // kPage pointers. // For a virtual address, bits 0-11 are in the physical address, bits 12-20 are // an index in the page table, bits 21-30 are an index in the page directory // and bit 31 is always 0. struct kPage_arch: kPageP prev_mapped, next_mapped struct Table: unsigned entrylo[0x200] kPage *page[0x200] struct kMemory_arch: unsigned asid Table **directory kPageP *shadow unsigned first_table // Pointers to kMemory when asid is taken, index of next free, or 0, if free. // asid[0] is used as index to first free asid. // asid value 0 is only used by the idle task. EXTERN unsigned asids[64] EXTERN kReceiverP arch_interrupt_receiver[32] // Functions which can be called from assembly must not be mangled. extern "C": // Kernel entry points, called from entry.S. kThread *interrupt () kThread *cache_error () kThread *exception () kThread *tlb_refill () #ifdef INIT // Initialize most things (the rest is done in boot.S) void init (unsigned mem) void board_init () // Start running the idle task for the first time. void run_idle (kThread *self) #endif // These are "extern", not "EXTERN", because they really are defined elsewhere. #ifdef INIT extern unsigned thread_start[NUM_THREADS + 1] #endif // Fast pointer to page directory, for tlb miss events extern Table **directory #endif // not defined ASM #endif // defined __KERNEL__ #endif