kvm: user: ppc: implement PowerPC 44x libcflat
[kvm-userspace.git] / user / test / lib / powerpc / 44x / map.c
blob113434d2f1b4d009fa78e7a1bf5d0751d698a740
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2, as
4 * published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 * Copyright IBM Corp. 2008
17 * Authors: Hollis Blanchard <hollisb@us.ibm.com>
20 #include "libcflat.h"
22 #define TLB_SIZE 64
24 extern void tlbwe(unsigned int index,
25 unsigned char tid,
26 unsigned int word0,
27 unsigned int word1,
28 unsigned int word2);
30 unsigned int next_free_index;
32 #define PAGE_SHIFT 12
33 #define PAGE_MASK (~((1<<PAGE_SHIFT)-1))
35 #define V (1<<9)
37 void map(unsigned long vaddr, unsigned long paddr)
39 unsigned int w0, w1, w2;
41 /* We don't install exception handlers, so we can't handle TLB misses,
42 * so we can't loop around and overwrite entry 0. */
43 if (next_free_index++ >= TLB_SIZE)
44 panic("TLB overflow");
46 w0 = (vaddr & PAGE_MASK) | V;
47 w1 = paddr & PAGE_MASK;
48 w2 = 0x3;
50 tlbwe(next_free_index, 0, w0, w1, w2);