Subversion Repositories HelenOS-historic

Compare Revisions

No changes between revisions

Ignore whitespace Rev 755 → Rev 756

/kernel/trunk/test/mm/mapping1/test.c
56,9 → 56,9
*((__u32 *) frame1) = VALUE1;
printf("Mapping virtual address %P to physical address %P.\n", PAGE0, KA2PA(frame0));
page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE, 0);
page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE);
printf("Mapping virtual address %P to physical address %P.\n", PAGE1, KA2PA(frame1));
page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE, 0);
page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE);
printf("Value at virtual address %P is %L.\n", PAGE0, v0 = *((__u32 *) PAGE0));
printf("Value at virtual address %P is %L.\n", PAGE1, v1 = *((__u32 *) PAGE1));
/kernel/trunk/genarch/include/mm/as_ht.h
0,0 → 1,36
/*
* Copyright (C) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __AS_HT_H__
#define __AS_HT_H__
 
#include <mm/as.h>
 
extern as_operations_t as_ht_operations;
 
#endif
/kernel/trunk/genarch/include/mm/page_pt.h
87,7 → 87,7
 
extern page_operations_t page_pt_operations;
 
extern void page_mapping_insert_pt(as_t *as, __address page, __address frame, int flags, __address root);
extern pte_t *page_mapping_find_pt(as_t *as, __address page, __address root);
extern void page_mapping_insert_pt(as_t *as, __address page, __address frame, int flags);
extern pte_t *page_mapping_find_pt(as_t *as, __address page);
 
#endif
/kernel/trunk/genarch/include/mm/as_pt.h
0,0 → 1,36
/*
* Copyright (C) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __AS_PT_H__
#define __AS_PT_H__
 
#include <mm/as.h>
 
extern as_operations_t as_pt_operations;
 
#endif
/kernel/trunk/genarch/include/mm/page_ht.h
38,8 → 38,10
#include <mm/page.h>
#include <typedefs.h>
 
/** Number of slots in page hash table. */
#define HT_ENTRIES HT_ENTRIES_ARCH
/** Page hash table size. */
#define HT_WIDTH HT_WIDTH_ARCH
#define HT_SIZE (1<<HT_WIDTH)
#define HT_ENTRIES (HT_SIZE/sizeof(pte_t))
 
/** Hash function.
*
99,7 → 101,6
*/
#define HT_SET_RECORD(t, page, asid, frame, flags) HT_SET_RECORD_ARCH(t, page, asid, frame, flags)
 
 
extern page_operations_t page_ht_operations;
extern spinlock_t page_ht_lock;
 
/kernel/trunk/genarch/Makefile.inc
39,11 → 39,13
endif
ifeq ($(CONFIG_PAGE_PT),y)
GENARCH_SOURCES += \
genarch/src/mm/page_pt.c
genarch/src/mm/page_pt.c \
genarch/src/mm/as_pt.c
endif
ifeq ($(CONFIG_PAGE_HT),y)
GENARCH_SOURCES += \
genarch/src/mm/page_ht.c
genarch/src/mm/page_ht.c \
genarch/src/mm/as_ht.c
endif
ifeq ($(CONFIG_ASID),y)
GENARCH_SOURCES += \
/kernel/trunk/genarch/src/mm/as_ht.c
0,0 → 1,60
/*
* Copyright (C) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <genarch/mm/as_ht.h>
#include <genarch/mm/page_ht.h>
#include <mm/as.h>
#include <mm/frame.h>
#include <arch/types.h>
#include <typedefs.h>
#include <memstr.h>
 
static pte_t *ht_create(int flags);
 
as_operations_t as_ht_operations = {
.page_table_create = ht_create
};
 
 
/** Page hash table create.
*
* The page hash table will be created only once
* and will be shared by all address spaces.
*
* @param flags Ignored.
*
* @return Address of global page hash table.
*/
pte_t *ht_create(int flags)
{
if (!page_ht) {
page_ht = (pte_t *) frame_alloc(FRAME_KA | FRAME_PANIC, HT_WIDTH - FRAME_WIDTH, NULL);
memsetb((__address) page_ht, HT_SIZE, 0);
}
return page_ht;
}
/kernel/trunk/genarch/src/mm/page_pt.c
29,6 → 29,7
#include <genarch/mm/page_pt.h>
#include <mm/page.h>
#include <mm/frame.h>
#include <mm/as.h>
#include <arch/mm/page.h>
#include <arch/mm/as.h>
#include <arch/types.h>
36,8 → 37,8
#include <arch/asm.h>
#include <memstr.h>
 
static void pt_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root);
static pte_t *pt_mapping_find(as_t *as, __address page, __address root);
static void pt_mapping_insert(as_t *as, __address page, __address frame, int flags);
static pte_t *pt_mapping_find(as_t *as, __address page);
 
page_operations_t page_pt_operations = {
.mapping_insert = pt_mapping_insert,
49,18 → 50,19
* Map virtual address 'page' to physical address 'frame'
* using 'flags'.
*
* @param as Ignored.
* The address space must be locked and interrupts must be disabled.
*
* @param as Address space to wich page belongs.
* @param page Virtual address of the page to be mapped.
* @param frame Physical address of memory frame to which the mapping is done.
* @param flags Flags to be used for mapping.
* @param root Explicit PTL0 address.
*/
void pt_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root)
void pt_mapping_insert(as_t *as, __address page, __address frame, int flags)
{
pte_t *ptl0, *ptl1, *ptl2, *ptl3;
__address newpt;
 
ptl0 = (pte_t *) PA2KA(root ? root : (__address) GET_PTL0_ADDRESS());
ptl0 = (pte_t *) PA2KA((__address) as->page_table);
 
if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) {
newpt = frame_alloc(FRAME_KA, ONE_FRAME, NULL);
97,17 → 99,18
*
* Find mapping for virtual page.
*
* @param as Ignored.
* The address space must be locked and interrupts must be disabled.
*
* @param as Address space to which page belongs.
* @param page Virtual page.
* @param root PTL0 address if non-zero.
*
* @return NULL if there is no such mapping; entry from PTL3 describing the mapping otherwise.
*/
pte_t *pt_mapping_find(as_t *as, __address page, __address root)
pte_t *pt_mapping_find(as_t *as, __address page)
{
pte_t *ptl0, *ptl1, *ptl2, *ptl3;
 
ptl0 = (pte_t *) PA2KA(root ? root : (__address) GET_PTL0_ADDRESS());
ptl0 = (pte_t *) PA2KA((__address) as->page_table);
 
if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT)
return NULL;
/kernel/trunk/genarch/src/mm/as_pt.c
0,0 → 1,78
/*
* Copyright (C) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <genarch/mm/page_pt.h>
#include <mm/page.h>
#include <mm/frame.h>
#include <mm/as.h>
#include <arch/mm/page.h>
#include <arch/mm/as.h>
#include <arch/types.h>
#include <typedefs.h>
#include <memstr.h>
#include <arch.h>
 
static pte_t *ptl0_create(int flags);
 
as_operations_t as_pt_operations = {
.page_table_create = ptl0_create
};
 
/** Create PTL0.
*
* PTL0 of 4-level page table will be created for each address space.
*
* @param flags Flags can specify whether ptl0 is for the kernel address space.
*
* @return New PTL0.
*/
pte_t *ptl0_create(int flags)
{
pte_t *src_ptl0, *dst_ptl0;
ipl_t ipl;
 
dst_ptl0 = (pte_t *) frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME, NULL);
 
if (flags & FLAG_AS_KERNEL) {
memsetb((__address) dst_ptl0, PAGE_SIZE, 0);
} else {
/*
* Copy the kernel address space portion to new PTL0.
* TODO: copy only kernel address space.
*/
ipl = interrupts_disable();
spinlock_lock(&AS_KERNEL->lock);
src_ptl0 = (pte_t *) PA2KA((__address) AS_KERNEL->page_table);
memcpy((void *) dst_ptl0,(void *) src_ptl0, PAGE_SIZE);
spinlock_unlock(&AS_KERNEL->lock);
interrupts_restore(ipl);
}
 
return (pte_t *) KA2PA((__address) dst_ptl0);
}
/kernel/trunk/genarch/src/mm/page_ht.c
38,12 → 38,10
#include <synch/spinlock.h>
#include <arch.h>
#include <debug.h>
#include <memstr.h>
 
/**
* This lock protects the page hash table. Note that software must
* be still careful about ordering of writes to ensure consistent
* view of the page hash table for hardware helpers such as VHPT
* walker on ia64.
* This lock protects the page hash table.
*/
SPINLOCK_INITIALIZE(page_ht_lock);
 
53,28 → 51,27
*/
pte_t *page_ht = NULL;
 
static void ht_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root);
static pte_t *ht_mapping_find(as_t *as, __address page, __address root);
static void ht_mapping_insert(as_t *as, __address page, __address frame, int flags);
static pte_t *ht_mapping_find(as_t *as, __address page);
 
page_operations_t page_ht_operations = {
.mapping_insert = ht_mapping_insert,
.mapping_find = ht_mapping_find
.mapping_find = ht_mapping_find,
};
 
/** Map page to frame using page hash table.
*
* Map virtual address 'page' to physical address 'frame'
* using 'flags'. In order not to disturb hardware searching,
* new mappings are appended to the end of the collision
* chain.
* using 'flags'.
*
* @param as Address space to which page belongs. Must be locked prior the call.
* The address space must be locked and interruptsmust be disabled.
*
* @param as Address space to which page belongs.
* @param page Virtual address of the page to be mapped.
* @param frame Physical address of memory frame to which the mapping is done.
* @param flags Flags to be used for mapping.
* @param root Ignored.
*/
void ht_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root)
void ht_mapping_insert(as_t *as, __address page, __address frame, int flags)
{
pte_t *t, *u;
ipl_t ipl;
121,15 → 118,14
*
* Find mapping for virtual page.
*
* Interrupts must be disabled.
* The address space must be locked and interrupts must be disabled.
*
* @param as Address space to wich page belongs. Must be locked prior the call.
* @param as Address space to wich page belongs.
* @param page Virtual page.
* @param root Ignored.
*
* @return NULL if there is no such mapping; requested mapping otherwise.
*/
pte_t *ht_mapping_find(as_t *as, __address page, __address root)
pte_t *ht_mapping_find(as_t *as, __address page)
{
pte_t *t;
/kernel/trunk/genarch/src/acpi/acpi.c
79,7 → 79,7
 
static void map_sdt(struct acpi_sdt_header *sdt)
{
page_mapping_insert(AS_KERNEL, (__address) sdt, (__address) sdt, PAGE_NOT_CACHEABLE, 0);
page_mapping_insert(AS_KERNEL, (__address) sdt, (__address) sdt, PAGE_NOT_CACHEABLE);
map_structure((__address) sdt, sdt->length);
}
 
/kernel/trunk/generic/include/mm/page.h
61,8 → 61,8
 
/** Operations to manipulate page mappings. */
struct page_operations {
void (* mapping_insert)(as_t *as, __address page, __address frame, int flags, __address root);
pte_t *(* mapping_find)(as_t *as, __address page, __address root);
void (* mapping_insert)(as_t *as, __address page, __address frame, int flags);
pte_t *(* mapping_find)(as_t *as, __address page);
};
typedef struct page_operations page_operations_t;
 
69,8 → 69,9
extern page_operations_t *page_operations;
 
extern void page_init(void);
extern void page_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root);
extern pte_t *page_mapping_find(as_t *as, __address page, __address root);
extern void page_mapping_insert(as_t *as, __address page, __address frame, int flags);
extern pte_t *page_mapping_find(as_t *as, __address page);
extern pte_t *page_table_create(int flags);
extern void map_structure(__address s, size_t size);
 
#endif
/kernel/trunk/generic/include/mm/as.h
80,13 → 80,24
 
SPINLOCK_DECLARE(lock);
link_t as_area_head;
pte_t *ptl0;
asid_t asid; /**< Address space identifier. */
 
/** Page table pointer. Constant on architectures that use global page hash table. */
pte_t *page_table;
 
/** Address space identifier. Constant on architectures that do not support ASIDs.*/
asid_t asid;
};
 
struct as_operations {
pte_t *(* page_table_create)(int flags);
};
typedef struct as_operations as_operations_t;
 
extern as_t *AS_KERNEL;
extern as_operations_t *as_operations;
 
extern as_t *as_create(pte_t *ptl0, int flags);
extern void as_init(void);
extern as_t *as_create(int flags);
extern as_area_t *as_area_create(as_t *as, as_area_type_t type, size_t size, __address base);
extern void as_set_mapping(as_t *as, __address page, __address frame);
extern int as_page_fault(__address page);
/kernel/trunk/generic/include/mm/buddy.h
57,5 → 57,4
extern void buddy_system_free(buddy_system_t *b, link_t *block);
extern void buddy_system_structure_print(buddy_system_t *b, size_t elem_size);
 
 
#endif
/kernel/trunk/generic/src/main/kinit.c
147,7 → 147,7
if (KA2PA(config.init_addr) % FRAME_SIZE)
panic("config.init_addr is not frame aligned");
as = as_create(NULL, 0);
as = as_create(0);
if (!as)
panic("as_create\n");
u = task_create(as);
158,7 → 158,7
panic("thread_create\n");
/*
* Create the text as_area and copy the userspace code there.
* Create the text as_area and initialize its mapping.
*/
frame = KA2PA(config.init_addr);
169,7 → 169,10
a = as_area_create(as, AS_AREA_TEXT, frames, UTEXT_ADDRESS);
if (!a)
panic("as_area_create: text\n");
 
for (i = 0; i < frames; i++)
as_set_mapping(as, UTEXT_ADDRESS + i * PAGE_SIZE, frame + i * FRAME_SIZE);
 
/*
* Create the data as_area.
*/
177,13 → 180,6
if (!a)
panic("as_area_create: stack\n");
 
/*
* Initialize text area mapping.
*/
for (i = 0; i < frames; i++)
as_set_mapping(as, UTEXT_ADDRESS + i * PAGE_SIZE, frame + i * FRAME_SIZE);
 
thread_ready(t);
}
 
/kernel/trunk/generic/src/main/main.c
138,7 → 138,6
*/
void main_bsp_separated_stack(void)
{
as_t *as;
task_t *k;
thread_t *t;
151,7 → 150,8
*/
kconsole_init();
 
/* Exception handler initialization, before architecture
/*
* Exception handler initialization, before architecture
* starts adding its own handlers
*/
exc_init();
162,6 → 162,7
arch_pre_mm_init();
early_heap_init(config.heap_addr, config.heap_size + config.heap_delta);
frame_init();
as_init();
page_init();
tlb_init();
arch_post_mm_init();
189,16 → 190,9
printf("config.init_addr=%X, config.init_size=%d\n", config.init_addr, config.init_size);
 
/*
* Create kernel address space.
*/
as = as_create(GET_PTL0_ADDRESS(), FLAG_AS_KERNEL);
if (!as)
panic("can't create kernel address space\n");
 
/*
* Create kernel task.
*/
k = task_create(as);
k = task_create(AS_KERNEL);
if (!k)
panic("can't create kernel task\n");
/kernel/trunk/generic/src/mm/as.c
33,7 → 33,7
*/
 
#include <mm/as.h>
#include <mm/asid.h>
#include <arch/mm/as.h>
#include <mm/page.h>
#include <mm/frame.h>
#include <mm/tlb.h>
42,7 → 42,6
#include <genarch/mm/page_pt.h>
#include <mm/asid.h>
#include <arch/mm/asid.h>
#include <arch/mm/as.h>
#include <arch/types.h>
#include <typedefs.h>
#include <synch/spinlock.h>
55,18 → 54,21
#include <arch.h>
#include <print.h>
 
#define KAS_START_INDEX PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)
#define KAS_END_INDEX PTL0_INDEX(KERNEL_ADDRESS_SPACE_END)
#define KAS_INDICES (1+(KAS_END_INDEX-KAS_START_INDEX))
as_operations_t *as_operations = NULL;
 
static int get_area_flags(as_area_t *a);
 
/** Initialize address space subsystem. */
void as_init(void)
{
as_arch_init();
AS_KERNEL = as_create(FLAG_AS_KERNEL);
if (!AS_KERNEL)
panic("can't create kernel address space\n");
}
 
/** Create address space. */
/*
* FIXME: this interface must be meaningful for all possible VAT
* (Virtual Address Translation) mechanisms.
*/
as_t *as_create(pte_t *ptl0, int flags)
as_t *as_create(int flags)
{
as_t *as;
 
81,20 → 83,7
else
as->asid = ASID_INVALID;
 
as->ptl0 = ptl0;
if (!as->ptl0) {
pte_t *src_ptl0, *dst_ptl0;
src_ptl0 = (pte_t *) PA2KA((__address) GET_PTL0_ADDRESS());
dst_ptl0 = (pte_t *) frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME, NULL);
 
// memsetb((__address) dst_ptl0, PAGE_SIZE, 0);
// memcpy((void *) &dst_ptl0[KAS_START_INDEX], (void *) &src_ptl0[KAS_START_INDEX], KAS_INDICES);
memcpy((void *) dst_ptl0,(void *) src_ptl0, PAGE_SIZE);
 
as->ptl0 = (pte_t *) KA2PA((__address) dst_ptl0);
}
as->page_table = page_table_create(flags);
}
 
return as;
186,7 → 175,7
* Note: area->lock is held.
*/
page_mapping_insert(as, page, frame, get_area_flags(area), (__address) as->ptl0);
page_mapping_insert(as, page, frame, get_area_flags(area));
spinlock_unlock(&area->lock);
spinlock_unlock(&as->lock);
266,7 → 255,7
* Note that TLB shootdown is not attempted as only new information is being
* inserted into page tables.
*/
page_mapping_insert(AS, page, frame, get_area_flags(area), (__address) AS->ptl0);
page_mapping_insert(AS, page, frame, get_area_flags(area));
spinlock_unlock(&area->lock);
spinlock_unlock(&AS->lock);
286,8 → 275,8
ipl = interrupts_disable();
spinlock_lock(&as->lock);
ASSERT(as->ptl0);
SET_PTL0_ADDRESS(as->ptl0);
ASSERT(as->page_table);
SET_PTL0_ADDRESS(as->page_table);
spinlock_unlock(&as->lock);
interrupts_restore(ipl);
 
327,3 → 316,20
return flags;
}
 
/** Create page table.
*
* Depending on architecture, create either address space
* private or global page table.
*
* @param flags Flags saying whether the page table is for kernel address space.
*
* @return First entry of the page table.
*/
pte_t *page_table_create(int flags)
{
ASSERT(as_operations);
ASSERT(as_operations->page_table_create);
 
return as_operations->page_table_create(flags);
}
/kernel/trunk/generic/src/mm/page.c
48,7 → 48,6
void page_init(void)
{
page_arch_init();
page_mapping_insert(AS_KERNEL, 0x0, 0x0, PAGE_NOT_PRESENT, 0);
}
 
/** Map memory structure
68,7 → 67,7
cnt = length/PAGE_SIZE + (length%PAGE_SIZE>0);
 
for (i = 0; i < cnt; i++)
page_mapping_insert(AS_KERNEL, s + i*PAGE_SIZE, s + i*PAGE_SIZE, PAGE_NOT_CACHEABLE, 0);
page_mapping_insert(AS_KERNEL, s + i*PAGE_SIZE, s + i*PAGE_SIZE, PAGE_NOT_CACHEABLE);
 
}
 
77,18 → 76,19
* Map virtual address 'page' to physical address 'frame'
* using 'flags'. Allocate and setup any missing page tables.
*
* @param as Address space to wich page belongs. Must be locked prior the call.
* The address space must be locked and interrupts must be disabled.
*
* @param as Address space to wich page belongs..
* @param page Virtual address of the page to be mapped.
* @param frame Physical address of memory frame to which the mapping is done.
* @param flags Flags to be used for mapping.
* @param root Explicit PTL0 address.
*/
void page_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root)
void page_mapping_insert(as_t *as, __address page, __address frame, int flags)
{
ASSERT(page_operations);
ASSERT(page_operations->mapping_insert);
page_operations->mapping_insert(as, page, frame, flags, root);
page_operations->mapping_insert(as, page, frame, flags);
}
 
/** Find mapping for virtual page
95,16 → 95,17
*
* Find mapping for virtual page.
*
* @param as Address space to wich page belongs must be locked prior the call.
* The address space must be locked and interrupts must be disabled.
*
* @param as Address space to wich page belongs.
* @param page Virtual page.
* @param root PTL0 address if non-zero.
*
* @return NULL if there is no such mapping; requested mapping otherwise.
*/
pte_t *page_mapping_find(as_t *as, __address page, __address root)
pte_t *page_mapping_find(as_t *as, __address page)
{
ASSERT(page_operations);
ASSERT(page_operations->mapping_find);
 
return page_operations->mapping_find(as, page, root);
return page_operations->mapping_find(as, page);
}
/kernel/trunk/arch/sparc64/include/mm/frame.h
31,7 → 31,8
 
#include <arch/types.h>
 
#define FRAME_SIZE 8192
#define FRAME_WIDTH 13
#define FRAME_SIZE (1<<FRAME_WIDTH)
 
union frame_address {
__address address;
/kernel/trunk/arch/sparc64/include/mm/page.h
38,11 → 38,10
#define KA2PA(x) ((__address) (x))
#define PA2KA(x) ((__address) (x))
 
#define GET_PTL0_ADDRESS_ARCH() 0
#define SET_PTL0_ADDRESS_ARCH(ptl0)
#define SET_PTL0_ADDRESS_ARCH(x) /**< To be removed as situation permits. */
 
/** Implementation of page hash table interface. */
#define HT_ENTRIES_ARCH 0
#define HT_WIDTH_ARCH 20 /* 1M */
#define HT_HASH_ARCH(page, asid) 0
#define HT_COMPARE_ARCH(page, asid, t) 0
#define HT_SLOT_EMPTY_ARCH(t) 1
/kernel/trunk/arch/sparc64/include/mm/as.h
42,4 → 42,6
 
#define as_install_arch(as)
 
extern void as_arch_init(void);
 
#endif
/kernel/trunk/arch/sparc64/Makefile.inc
64,6 → 64,7
arch/$(ARCH)/src/console.c \
arch/$(ARCH)/src/context.S \
arch/$(ARCH)/src/dummy.s \
arch/$(ARCH)/src/mm/as.c \
arch/$(ARCH)/src/mm/frame.c \
arch/$(ARCH)/src/mm/page.c \
arch/$(ARCH)/src/mm/tlb.c \
/kernel/trunk/arch/sparc64/src/mm/as.c
0,0 → 1,36
/*
* Copyright (C) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <arch/mm/as.h>
#include <genarch/mm/as_ht.h>
 
/** Architecture dependent address space init. */
void as_arch_init(void)
{
as_operations = &as_ht_operations;
}
/kernel/trunk/arch/ia64/include/mm/page.h
43,11 → 43,10
#define KA2PA(x) ((__address) (x))
#define PA2KA(x) ((__address) (x))
 
#define GET_PTL0_ADDRESS_ARCH() ((pte_t *) 0)
#define SET_PTL0_ADDRESS_ARCH(ptl0)
#define SET_PTL0_ADDRESS_ARCH(x) /**< To be removed as situation permits. */
 
/** Implementation of page hash table interface. */
#define HT_ENTRIES_ARCH (VHPT_SIZE/sizeof(pte_t))
#define HT_WIDTH_ARCH 20 /* 1M */
#define HT_HASH_ARCH(page, asid) vhpt_hash((page), (asid))
#define HT_COMPARE_ARCH(page, asid, t) vhpt_compare((page), (asid), (t))
#define HT_SLOT_EMPTY_ARCH(t) ((t)->present.tag.tag_info.ti)
/kernel/trunk/arch/ia64/include/mm/as.h
42,4 → 42,6
 
#define as_install_arch(as)
 
extern void as_arch_init(void);
 
#endif
/kernel/trunk/arch/ia64/Makefile.inc
64,6 → 64,7
arch/$(ARCH)/src/cpu/cpu.c \
arch/$(ARCH)/src/ivt.S \
arch/$(ARCH)/src/interrupt.c \
arch/$(ARCH)/src/mm/as.c \
arch/$(ARCH)/src/mm/frame.c \
arch/$(ARCH)/src/mm/page.c \
arch/$(ARCH)/src/mm/tlb.c \
/kernel/trunk/arch/ia64/src/mm/tlb.c
33,11 → 33,7
#include <mm/tlb.h>
#include <arch/mm/asid.h>
 
/** Invalidate all TLB entries.
*
* Because of ASID management, region registers must be reset
* with new RIDs derived from the potentionally new ASID.
*/
/** Invalidate all TLB entries. */
void tlb_invalidate_all(void)
{
/* TODO */
/kernel/trunk/arch/ia64/src/mm/as.c
0,0 → 1,36
/*
* Copyright (C) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <arch/mm/as.h>
#include <genarch/mm/as_ht.h>
 
/** Architecture dependent address space init. */
void as_arch_init(void)
{
as_operations = &as_ht_operations;
}
/kernel/trunk/arch/ppc32/include/mm/as.h
42,4 → 42,6
 
#define as_install_arch(as)
 
extern void as_arch_init(void);
 
#endif
/kernel/trunk/arch/ppc32/Makefile.inc
60,6 → 60,7
arch/$(ARCH)/src/start.S \
arch/$(ARCH)/src/asm.S \
arch/$(ARCH)/src/cpu/cpu.c \
arch/$(ARCH)/src/mm/as.c \
arch/$(ARCH)/src/mm/frame.c \
arch/$(ARCH)/src/mm/memory_init.c \
arch/$(ARCH)/src/mm/page.c
/kernel/trunk/arch/ppc32/src/mm/as.c
0,0 → 1,36
/*
* Copyright (C) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <arch/mm/as.h>
#include <genarch/mm/as_pt.h>
 
/** Architecture dependent address space init. */
void as_arch_init(void)
{
as_operations = &as_pt_operations;
}
/kernel/trunk/arch/amd64/include/mm/as.h
42,4 → 42,6
 
#define as_install_arch(as)
 
extern void as_arch_init(void);
 
#endif
/kernel/trunk/arch/amd64/Makefile.inc
87,6 → 87,7
arch/$(ARCH)/src/amd64.c \
arch/$(ARCH)/src/bios/bios.c \
arch/$(ARCH)/src/interrupt.c \
arch/$(ARCH)/src/mm/as.c \
arch/$(ARCH)/src/mm/frame.c \
arch/$(ARCH)/src/mm/page.c \
arch/$(ARCH)/src/mm/tlb.c \
/kernel/trunk/arch/amd64/src/mm/as.c
0,0 → 1,0
link ../../../ia32/src/mm/as.c
Property changes:
Added: svn:special
+*
\ No newline at end of property
/kernel/trunk/arch/amd64/src/mm/page.c
38,32 → 38,24
#include <memstr.h>
#include <interrupt.h>
 
static __address bootstrap_dba;
 
void page_arch_init(void)
{
__address dba;
__address cur;
 
if (config.cpu_active == 1) {
page_operations = &page_pt_operations;
dba = frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME, NULL);
memsetb(dba, PAGE_SIZE, 0);
 
bootstrap_dba = dba;
 
/*
* PA2KA(identity) mapping for all frames.
*/
for (cur = 0; cur < last_frame; cur += FRAME_SIZE) {
page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, PAGE_CACHEABLE | PAGE_EXEC, KA2PA(dba));
page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, PAGE_CACHEABLE | PAGE_EXEC);
}
 
exc_register(14, "page_fault", page_fault);
write_cr3(KA2PA(dba));
write_cr3((__address) AS_KERNEL->page_table);
}
else {
write_cr3(KA2PA(bootstrap_dba));
write_cr3((__address) AS_KERNEL->page_table);
}
}
/kernel/trunk/arch/mips32/include/mm/as.h
41,4 → 41,6
#define USTACK_ADDRESS_ARCH (0x80000000-PAGE_SIZE)
#define UDATA_ADDRESS_ARCH 0x01001000
 
extern void as_arch_init(void);
 
#endif
/kernel/trunk/arch/mips32/src/mm/tlb.c
339,7 → 339,7
/*
* Check if the mapping exists in page tables.
*/
pte = page_mapping_find(AS, badvaddr, 0);
pte = page_mapping_find(AS, badvaddr);
if (pte && pte->lo.v) {
/*
* Mapping found in page tables.
356,7 → 356,7
* The higher-level page fault handler succeeded,
* The mapping ought to be in place.
*/
pte = page_mapping_find(AS, badvaddr, 0);
pte = page_mapping_find(AS, badvaddr);
ASSERT(pte && pte->lo.v);
return pte;
}
/kernel/trunk/arch/mips32/src/mm/as.c
27,6 → 27,7
*/
 
#include <arch/mm/as.h>
#include <genarch/mm/as_pt.h>
#include <arch/mm/tlb.h>
#include <mm/tlb.h>
#include <mm/as.h>
33,6 → 34,12
#include <arch/cp0.h>
#include <arch.h>
 
/** Architecture dependent address space init. */
void as_arch_init(void)
{
as_operations = &as_pt_operations;
}
 
/** Install address space.
*
* Install ASID.
56,3 → 63,4
spinlock_unlock(&as->lock);
interrupts_restore(ipl);
}
 
/kernel/trunk/arch/ia32/include/mm/as.h
42,4 → 42,6
 
#define as_install_arch(as)
 
extern void as_arch_init(void);
 
#endif
/kernel/trunk/arch/ia32/Makefile.inc
110,6 → 110,7
arch/$(ARCH)/src/pm.c \
arch/$(ARCH)/src/userspace.c \
arch/$(ARCH)/src/cpu/cpu.c \
arch/$(ARCH)/src/mm/as.c \
arch/$(ARCH)/src/mm/frame.c \
arch/$(ARCH)/src/mm/memory_init.c \
arch/$(ARCH)/src/mm/page.c \
/kernel/trunk/arch/ia32/src/smp/smp.c
66,9 → 66,9
 
if (config.cpu_count > 1) {
page_mapping_insert(AS_KERNEL, (__address) l_apic, (__address) l_apic,
PAGE_NOT_CACHEABLE, 0);
PAGE_NOT_CACHEABLE);
page_mapping_insert(AS_KERNEL, (__address) io_apic, (__address) io_apic,
PAGE_NOT_CACHEABLE, 0);
PAGE_NOT_CACHEABLE);
}
 
/*
/kernel/trunk/arch/ia32/src/mm/as.c
0,0 → 1,36
/*
* Copyright (C) 2006 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <arch/mm/as.h>
#include <genarch/mm/as_pt.h>
 
/** Architecture dependent address space init. */
void as_arch_init(void)
{
as_operations = &as_pt_operations;
}
/kernel/trunk/arch/ia32/src/mm/page.c
42,32 → 42,24
#include <print.h>
#include <interrupt.h>
 
static __address bootstrap_dba;
 
void page_arch_init(void)
{
__address dba;
__address cur;
 
if (config.cpu_active == 1) {
page_operations = &page_pt_operations;
dba = frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME, NULL);
memsetb(dba, PAGE_SIZE, 0);
 
bootstrap_dba = dba;
/*
* PA2KA(identity) mapping for all frames until last_frame.
*/
for (cur = 0; cur < last_frame; cur += FRAME_SIZE)
page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, PAGE_CACHEABLE, KA2PA(dba));
page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, PAGE_CACHEABLE);
 
exc_register(14, "page_fault", page_fault);
write_cr3(KA2PA(dba));
write_cr3((__address) AS_KERNEL->page_table);
}
else {
write_cr3(KA2PA(bootstrap_dba));
write_cr3((__address) AS_KERNEL->page_table);
}
 
paging_on();
/kernel/trunk/arch/ia32/src/drivers/ega.c
59,7 → 59,7
{
__u8 hi, lo;
 
page_mapping_insert(AS_KERNEL, PA2KA(VIDEORAM), VIDEORAM, PAGE_NOT_CACHEABLE, 0);
page_mapping_insert(AS_KERNEL, PA2KA(VIDEORAM), VIDEORAM, PAGE_NOT_CACHEABLE);
outb(0x3d4,0xe);
hi = inb(0x3d5);
outb(0x3d4,0xf);