2009-05-18 10:30:27 +03:00
|
|
|
#pypp 0
|
2009-06-01 15:26:42 +03:00
|
|
|
// Iris: micro-kernel for a capability-based operating system.
|
|
|
|
// mips/arch.hhp: mips-specific declarations and type definitions.
|
|
|
|
// Copyright 2009 Bas Wijnen <wijnen@debian.org>
|
|
|
|
//
|
|
|
|
// 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
2009-05-18 10:30:27 +03:00
|
|
|
#ifndef _ARCH_HH
|
|
|
|
#define _ARCH_HH
|
|
|
|
|
2009-05-22 23:48:49 +03:00
|
|
|
#ifdef ARCH
|
2009-06-22 18:48:05 +03:00
|
|
|
|
|
|
|
#ifndef ASM
|
2009-09-27 11:23:33 +03:00
|
|
|
#include "board.hh"
|
2009-06-22 18:48:05 +03:00
|
|
|
#endif
|
|
|
|
|
2009-05-22 23:48:49 +03:00
|
|
|
#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
|
2009-09-30 00:48:33 +03:00
|
|
|
#define CP0_INT_CTL 12, 1
|
2009-05-22 23:48:49 +03:00
|
|
|
#define CP0_CAUSE 13
|
|
|
|
#define CP0_EPC 14
|
|
|
|
#define CP0_P_R_ID 15
|
2009-09-30 00:48:33 +03:00
|
|
|
#define CP0_EBASE 15, 1
|
2009-05-22 23:48:49 +03:00
|
|
|
#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
|
2009-06-22 18:48:05 +03:00
|
|
|
|
2009-05-22 23:48:49 +03:00
|
|
|
#endif
|
|
|
|
|
2009-10-31 10:32:23 +02:00
|
|
|
#ifdef __KERNEL__
|
2009-08-18 00:11:15 +03:00
|
|
|
// register save positions in kThread
|
2009-08-05 11:16:24 +03:00
|
|
|
#define SAVE_PC (6 * 4)
|
2009-05-25 01:31:35 +03:00
|
|
|
#define SAVE_SP (SAVE_PC + 4)
|
|
|
|
#define SAVE_AT (SAVE_SP + 4)
|
2009-08-24 22:02:35 +03:00
|
|
|
#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)
|
2009-05-25 01:31:35 +03:00
|
|
|
#define SAVE_FP (SAVE_GP + 4)
|
|
|
|
#define SAVE_RA (SAVE_FP + 4)
|
|
|
|
#define SAVE_HI (SAVE_RA + 4)
|
|
|
|
#define SAVE_LO (SAVE_HI + 4)
|
2009-08-24 22:02:35 +03:00
|
|
|
#define SAVE_K (SAVE_LO + 4)
|
2009-05-25 01:31:35 +03:00
|
|
|
|
|
|
|
#ifndef ASM
|
|
|
|
|
2009-06-26 00:09:42 +03:00
|
|
|
void flush_tlb (unsigned asid)
|
2010-08-22 23:03:06 +03:00
|
|
|
void arch_flush_cache ()
|
2009-06-26 00:09:42 +03:00
|
|
|
|
2009-08-18 00:11:15 +03:00
|
|
|
struct kThread_arch:
|
2009-08-24 22:02:35 +03:00
|
|
|
unsigned at, v[2], a[4], t[10], s[8], gp, fp, ra, hi, lo, k[2]
|
2009-05-18 10:30:27 +03:00
|
|
|
|
2009-05-26 01:42:47 +03:00
|
|
|
// The following is used for page mapping.
|
2010-01-17 11:01:42 +02:00
|
|
|
// 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.
|
2009-05-26 01:42:47 +03:00
|
|
|
|
2009-08-18 00:11:15 +03:00
|
|
|
struct kPage_arch:
|
2010-01-17 11:01:42 +02:00
|
|
|
kPageP prev_mapped, next_mapped
|
|
|
|
|
|
|
|
struct Table:
|
|
|
|
unsigned entrylo[0x200]
|
|
|
|
kPage *page[0x200]
|
2009-05-26 01:42:47 +03:00
|
|
|
|
2009-08-18 00:11:15 +03:00
|
|
|
struct kMemory_arch:
|
2009-05-18 10:30:27 +03:00
|
|
|
unsigned asid
|
2010-01-17 11:01:42 +02:00
|
|
|
Table **directory
|
|
|
|
kPageP *shadow
|
|
|
|
unsigned first_table
|
2009-05-19 00:18:23 +03:00
|
|
|
|
2009-08-18 00:11:15 +03:00
|
|
|
// Pointers to kMemory when asid is taken, index of next free, or 0, if free.
|
2009-05-24 13:22:22 +03:00
|
|
|
// asid[0] is used as index to first free asid.
|
2010-01-17 11:01:42 +02:00
|
|
|
// asid value 0 is only used by the idle task.
|
2009-05-24 13:22:22 +03:00
|
|
|
EXTERN unsigned asids[64]
|
2009-08-18 00:11:15 +03:00
|
|
|
EXTERN kReceiverP arch_interrupt_receiver[32]
|
2009-05-18 10:30:27 +03:00
|
|
|
|
|
|
|
// Functions which can be called from assembly must not be mangled.
|
|
|
|
extern "C":
|
|
|
|
// Kernel entry points, called from entry.S.
|
2009-08-18 00:11:15 +03:00
|
|
|
kThread *interrupt ()
|
|
|
|
kThread *cache_error ()
|
|
|
|
kThread *exception ()
|
|
|
|
kThread *tlb_refill ()
|
2009-05-18 10:30:27 +03:00
|
|
|
|
|
|
|
#ifdef INIT
|
|
|
|
// Initialize most things (the rest is done in boot.S)
|
2009-07-16 10:15:15 +03:00
|
|
|
void init (unsigned mem)
|
2009-09-27 11:23:33 +03:00
|
|
|
void board_init ()
|
2009-05-18 10:30:27 +03:00
|
|
|
// Start running the idle task for the first time.
|
2009-08-18 00:11:15 +03:00
|
|
|
void run_idle (kThread *self)
|
2009-05-18 10:30:27 +03:00
|
|
|
#endif
|
|
|
|
|
2009-05-26 01:42:47 +03:00
|
|
|
// These are "extern", not "EXTERN", because they really are defined elsewhere.
|
2009-05-22 23:48:49 +03:00
|
|
|
#ifdef INIT
|
2012-09-26 23:20:38 +03:00
|
|
|
extern unsigned thread_start[]
|
2009-05-22 23:48:49 +03:00
|
|
|
#endif
|
2009-05-26 01:42:47 +03:00
|
|
|
// Fast pointer to page directory, for tlb miss events
|
2010-01-17 11:01:42 +02:00
|
|
|
extern Table **directory
|
2009-05-22 23:48:49 +03:00
|
|
|
|
2009-06-22 18:48:05 +03:00
|
|
|
#endif // not defined ASM
|
|
|
|
|
2009-10-31 10:32:23 +02:00
|
|
|
#endif // defined __KERNEL__
|
2009-05-25 01:31:35 +03:00
|
|
|
|
2009-05-20 23:07:56 +03:00
|
|
|
#endif
|