Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1062 → Rev 1063

/kernel/trunk/arch/amd64/include/mm/page.h
26,6 → 26,18
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** Paging on AMD64
*
* The space is divided in positive numbers - userspace and
* negative numbers - kernel space. The 'negative' space starting
* with 0xffff800000000000 and ending with 0xffffffff80000000
* (-2GB) is identically mapped physical memory. The area
* (0xffffffff80000000 ... 0xffffffffffffffff is again identically
* mapped first 2GB.
*
* ATTENTION - PA2KA(KA2PA(x)) != x if 'x' is in kernel
*/
 
#ifndef __amd64_PAGE_H__
#define __amd64_PAGE_H__
 
42,11 → 54,32
#endif
 
#ifndef __ASM__
# define KA2PA(x) (((__address) (x)) - 0xffffffff80000000)
# define PA2KA(x) (((__address) (x)) + 0xffffffff80000000)
static inline __address ka2pa(__address x)
{
if (x > 0xffffffff80000000)
return x - 0xffffffff80000000;
else
return x - 0xffff800000000000;
}
/* Linker symbol */
extern int ktext_start;
extern int kdata_end;
static inline __address pa2ka(__address x)
{
if (x >= ka2pa((__address)(&kdata_end)) || \
x <= ka2pa((__address)&ktext_start))
return x + 0xffff800000000000;
else
return x + 0xffffffff80000000;
}
# define KA2PA(x) ka2pa((__address)x)
# define PA2KA(x) pa2ka((__address)x)
# define PA2KA_IDENT(x) (((__address) (x)) + 0xffff800000000000)
# define PA2KA_CODE(x) (((__address) (x)) + 0xffffffff80000000)
#else
# define KA2PA(x) ((x) - 0xffffffff80000000)
# define PA2KA(x) ((x) + 0xffffffff80000000)
# define PA2KA_DATA(x) ((x) + 0xffff800000000000)
#endif
 
#define PTL0_ENTRIES_ARCH 512
/kernel/trunk/arch/amd64/include/mm/as.h
31,7 → 31,7
 
#include <arch/types.h>
 
#define KERNEL_ADDRESS_SPACE_START_ARCH (__address) 0xffffffff80000000
#define KERNEL_ADDRESS_SPACE_START_ARCH (__address) 0xffff800000000000
#define KERNEL_ADDRESS_SPACE_END_ARCH (__address) 0xffffffffffffffff
#define USER_ADDRESS_SPACE_START_ARCH (__address) 0x0000000000000000
#define USER_ADDRESS_SPACE_END_ARCH (__address) 0x00007fffffffffff
/kernel/trunk/arch/amd64/src/boot/boot.S
174,7 → 174,8
xorq %rdx, %rdx
movl 0(%esi), %edx # mods->mod_start
addq $0xffffffff80000000, %rdx
movq $0xffff800000000000, %r10
addq %r10, %rdx
movq %rdx, 8(%rdi)
xorq %rdx, %rdx
303,8 → 304,10
.global ptl_0
ptl_0:
.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
.fill 510,8,0
.fill 255,8,0
.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
.fill 254,8,0
.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
 
.global bootstrap_gdtr
bootstrap_gdtr:
/kernel/trunk/arch/amd64/src/mm/page.c
39,6 → 39,7
#include <interrupt.h>
#include <print.h>
#include <panic.h>
#include <align.h>
 
/* Definitions for identity page mapper */
pte_t helper_ptl1[512] __attribute__((aligned (PAGE_SIZE)));
70,11 → 71,11
SET_FRAME_ADDRESS_ARCH(ptl3, PTL3_INDEX_ARCH(page), (__address)KA2PA(tgt)); \
SET_FRAME_FLAGS_ARCH(ptl3, PTL3_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
}
 
void page_arch_init(void)
{
__address cur;
int flags;
int i;
int identity_flags = PAGE_CACHEABLE | PAGE_EXEC | PAGE_GLOBAL;
 
if (config.cpu_active == 1) {
page_mapping_operations = &pt_mapping_operations;
83,11 → 84,22
* PA2KA(identity) mapping for all frames.
*/
for (cur = 0; cur < last_frame; cur += FRAME_SIZE) {
flags = PAGE_CACHEABLE | PAGE_EXEC;
if ((PA2KA(cur) >= config.base) && (PA2KA(cur) < config.base + config.kernel_size))
flags |= PAGE_GLOBAL;
page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, flags);
/* Standard identity mapping */
page_mapping_insert(AS_KERNEL, PA2KA_IDENT(cur), cur, identity_flags);
}
/* Upper kernel mapping
* - from zero to top of kernel (include bottom addresses
* because some are needed for init )
*/
for (cur = PA2KA_CODE(0); cur < config.base+config.kernel_size; cur += FRAME_SIZE) {
page_mapping_insert(AS_KERNEL, cur, KA2PA(cur), identity_flags);
}
for (i=0; i < init.cnt; i++) {
for (cur=init.tasks[i].addr;cur < init.tasks[i].size; cur += FRAME_SIZE) {
page_mapping_insert(AS_KERNEL, PA2KA_CODE(KA2PA(cur)), KA2PA(cur), identity_flags);
}
}
 
exc_register(14, "page_fault", (iroutine)page_fault);
write_cr3((__address) AS_KERNEL->page_table);
}