[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
vaddr.h
Go to the documentation of this file.
1#ifndef THREADS_VADDR_H
2#define THREADS_VADDR_H
3
4#include <debug.h>
5#include <stdint.h>
6#include <stdbool.h>
7
8#include "threads/loader.h"
9
10/* Functions and macros for working with virtual addresses.
11 *
12 * See pte.h for functions and macros specifically for x86
13 * hardware page tables. */
14
15#define BITMASK(SHIFT, CNT) (((1ul << (CNT)) - 1) << (SHIFT))
16
17/* Page offset (bits 0:12). */
18#define PGSHIFT 0 /* Index of first offset bit. */
19#define PGBITS 12 /* Number of offset bits. */
20#define PGSIZE (1 << PGBITS) /* Bytes in a page. */
21#define PGMASK BITMASK(PGSHIFT, PGBITS) /* Page offset bits (0:12). */
22
23/* Offset within a page. */
24#define pg_ofs(va) ((uint64_t) (va) & PGMASK)
25
26#define pg_no(va) ((uint64_t) (va) >> PGBITS)
27
28/* Round up to nearest page boundary. */
29#define pg_round_up(va) ((void *) (((uint64_t) (va) + PGSIZE - 1) & ~PGMASK))
30
31/* Round down to nearest page boundary. */
32#define pg_round_down(va) (void *) ((uint64_t) (va) & ~PGMASK)
33
34/* Kernel virtual address start */
35#define KERN_BASE LOADER_KERN_BASE
36
37/* User stack start */
38#define USER_STACK 0x47480000
39
40/* Returns true if VADDR is a user virtual address. */
41#define is_user_vaddr(vaddr) (!is_kernel_vaddr((vaddr)))
42
43/* Returns true if VADDR is a kernel virtual address. */
44#define is_kernel_vaddr(vaddr) ((uint64_t)(vaddr) >= KERN_BASE)
45
46// FIXME: add checking
47/* Returns kernel virtual address at which physical address PADDR
48 * is mapped. */
49#define ptov(paddr) ((void *) (((uint64_t) paddr) + KERN_BASE))
50
51/* Returns physical address at which kernel virtual address VADDR
52 * is mapped. */
53#define vtop(vaddr) \
54({ \
55 ASSERT(is_kernel_vaddr(vaddr)); \
56 ((uint64_t) (vaddr) - (uint64_t) KERN_BASE);\
57})
58
59#endif /* threads/vaddr.h */