11 #define MASK(SHIFT, CNT) (((1ul << (CNT)) - 1) << (SHIFT))
13 /* Page offset (bits 0:11). */
14 #define PGSHIFT 0 /* First offset bit. */
15 #define PGBITS 12 /* Number of offset bits. */
16 #define PGMASK MASK(PGSHIFT, PGBITS)
17 #define PGSIZE (1 << PGBITS)
19 /* Page table (bits 12:21). */
20 #define PTSHIFT PGBITS /* First page table bit. */
21 #define PTBITS 10 /* Number of page table bits. */
22 #define PTMASK MASK(PTSHIFT, PTBITS)
24 /* Page directory (bits 22:31). */
25 #define PDSHIFT (PTSHIFT + PTBITS) /* First page dir bit. */
26 #define PDBITS 10 /* Number of page dir bits. */
27 #define PDMASK MASK(PDSHIFT, PDBITS)
30 /* Offset within a page. */
31 static inline unsigned pg_ofs (void *va) { return (uintptr_t) va & PGMASK; }
34 static inline uintptr_t pg_no (void *va) { return (uintptr_t) va >> PTSHIFT; }
36 /* Page table number. */
37 static inline unsigned pt_no (void *va) {
38 return ((uintptr_t) va & PTMASK) >> PTSHIFT;
41 /* Page directory number. */
42 static inline uintptr_t pd_no (void *va) { return (uintptr_t) va >> PDSHIFT; }
44 /* Round up to nearest page boundary. */
45 static inline void *pg_round_up (void *va) {
46 return (void *) (((uintptr_t) va + PGSIZE - 1) & ~PGMASK);
49 /* Round down to nearest page boundary. */
50 static inline void *pg_round_down (void *va) {
51 return (void *) ((uintptr_t) va & ~PGMASK);
54 #define PHYS_BASE ((void *) LOADER_PHYS_BASE)
56 /* Returns kernel virtual address at which physical address PADDR
59 ptov (uintptr_t paddr)
61 ASSERT ((void *) paddr < PHYS_BASE);
63 return (void *) (paddr + PHYS_BASE);
66 /* Returns physical address at which kernel virtual address VADDR
68 static inline uintptr_t
71 ASSERT (vaddr >= PHYS_BASE);
73 return (uintptr_t) vaddr - (uintptr_t) PHYS_BASE;
77 /* Page Directory Entry (PDE) and Page Table Entry (PTE) flags. */
78 #define PG_P 0x1 /* 1=present, 0=not present. */
79 #define PG_W 0x2 /* 1=read/write, 0=read-only. */
80 #define PG_U 0x4 /* 1=user/kernel, 0=kernel only. */
81 #define PG_A 0x20 /* 1=accessed, 0=not acccessed. */
82 #define PG_D 0x40 /* 1=dirty, 0=not dirty. */
84 /* EFLAGS Register. */
85 #define FLAG_MBS 0x00000002 /* Must be set. */
86 #define FLAG_IF 0x00000200 /* Interrupt Flag. */