#ifndef _KERNEL_ARCH_M68K_030_MMU_H
#define _KERNEL_ARCH_M68K_030_MMU_H
#include <SupportDefs.h>
#include <string.h>
#include <arch_mmu.h>
struct short_page_directory_entry {
uint32 addr : 28;
uint32 accessed : 1;
uint32 write_protect : 1;
uint32 type : 2;
};
struct long_page_directory_entry {
uint32 low_up : 1;
uint32 limit : 15;
uint32 _ones : 6;
uint32 _zero2 : 1;
uint32 supervisor : 1;
uint32 _zero1 : 4;
uint32 accessed : 1;
uint32 write_protect : 1;
uint32 type : 2;
uint32 addr : 28;
uint32 unused : 4;
};
struct short_page_table_entry {
uint32 addr : 24;
uint32 _zero2 : 1;
uint32 cache_disabled : 1;
uint32 _zero1 : 1;
uint32 dirty : 1;
uint32 accessed : 1;
uint32 write_protect : 1;
uint32 type : 2;
};
struct long_page_table_entry {
uint32 low_up : 1;
uint32 limit : 15;
uint32 _ones : 6;
uint32 _zero3 : 1;
uint32 supervisor : 1;
uint32 _zero2 : 1;
uint32 cache_disabled : 1;
uint32 _zero1 : 1;
uint32 dirty : 1;
uint32 accessed : 1;
uint32 write_protect : 1;
uint32 type : 2;
uint32 addr : 24;
uint32 unused : 8;
};
struct short_indirect_entry {
uint32 addr : 30;
uint32 type : 2;
};
struct long_indirect_entry {
uint32 unused1 : 30;
uint32 type : 2;
uint32 addr : 30;
uint32 unused2 : 2;
};
typedef struct short_page_directory_entry page_root_entry;
typedef struct short_page_directory_entry page_directory_entry;
typedef struct long_page_table_entry page_table_entry;
typedef struct long_indirect_entry page_indirect_entry;
typedef uint32 page_root_entry_scalar;
typedef uint32 page_directory_entry_scalar;
typedef uint64 page_table_entry_scalar;
typedef uint64 page_indirect_entry_scalar;
#define DT_ROOT DT_VALID_4
#define DT_DIR DT_VALID_8
#define DT_INDIRECT DT_VALID_8
#define DFL_ROOTENT_VAL 0x00000000
#define DFL_DIRENT_VAL 0x00000000
#define DFL_PAGEENT_VAL 0x7FFFFC0000000000LL
#define NUM_ROOTENT_PER_TBL 128
#define NUM_DIRENT_PER_TBL 128
#define NUM_PAGEENT_PER_TBL 64
#define SIZ_ROOTTBL (NUM_ROOTENT_PER_TBL * sizeof(page_root_entry))
#define SIZ_DIRTBL (NUM_DIRENT_PER_TBL * sizeof(page_directory_entry))
#define SIZ_PAGETBL (NUM_PAGEENT_PER_TBL * sizeof(page_table_entry))
#define NUM_DIRTBL_PER_PAGE (B_PAGE_SIZE / SIZ_DIRTBL)
#define NUM_PAGETBL_PER_PAGE (B_PAGE_SIZE / SIZ_PAGETBL)
#if 0
#define PREA_TO_TA(a) ((a) << 4)
#define PREA_TO_PN(a) ((a) >> (12-4))
#define PREA_TO_PA(a) ((a) << 4)
#define TA_TO_PREA(a) ((a) >> 4)
#endif
#define PRE_TO_TA(a) ((*(uint32 *)(&(a))) & ~((1<<4)-1))
#define PRE_TO_PN(e) ((*(uint32 *)(&(e))) >> 12)
#define PRE_TO_PA(e) ((*(uint32 *)(&(e))) & ~((1<<12)-1))
#define TA_TO_PREA(a) ((a) >> 4)
#define PDE_TO_TA(a) ((*(uint32 *)(&(a))) & ~((1<<4)-1))
#define PDE_TO_PN(e) ((*(uint32 *)(&(e))) >> 12)
#define PDE_TO_PA(e) ((*(uint32 *)(&(e))) & ~((1<<12)-1))
#define TA_TO_PDEA(a) ((a) >> 4)
#define PTE_TO_TA(a) ((((uint32 *)(&(a)))[1]) & ~((1<<8)-1))
#define PTE_TO_PN(e) ((((uint32 *)(&(e)))[1]) >> 12)
#define PTE_TO_PA(e) ((((uint32 *)(&(e)))[1]) & ~((1<<12)-1))
#define TA_TO_PTEA(a) ((a) >> 8)
#define PIE_TO_TA(a) ((((uint32 *)(&(a)))[1]) & ~((1<<2)-1))
#define PIE_TO_PN(e) ((((uint32 *)(&(e)))[1]) >> 12)
#define PIE_TO_PA(e) ((((uint32 *)(&(e)))[1]) & ~((1<<12)-1))
#define PIE_TO_PO(e) ((((uint32 *)(&(e)))[1]) & ((1<<12)-(1<<2)))
#define TA_TO_PIEA(a) ((a) >> 2)
#define VADDR_TO_PRENT(va) (((va) / B_PAGE_SIZE) / (64*128))
#define VADDR_TO_PDENT(va) ((((va) / B_PAGE_SIZE) / 64) % 128)
#define VADDR_TO_PTENT(va) (((va) / B_PAGE_SIZE) % 64)
#endif