Rev 1760 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1760 | Rev 1780 | ||
---|---|---|---|
Line 40... | Line 40... | ||
40 | #define VALUE0 0x01234567 |
40 | #define VALUE0 0x01234567 |
41 | #define VALUE1 0x89abcdef |
41 | #define VALUE1 0x89abcdef |
42 | 42 | ||
43 | void test(void) |
43 | void test(void) |
44 | { |
44 | { |
45 | __address frame0, frame1; |
45 | uintptr_t frame0, frame1; |
46 | __u32 v0, v1; |
46 | uint32_t v0, v1; |
47 | 47 | ||
48 | printf("Memory management test mapping #1\n"); |
48 | printf("Memory management test mapping #1\n"); |
49 | 49 | ||
50 | frame0 = frame_alloc(ONE_FRAME, FRAME_KA); |
50 | frame0 = frame_alloc(ONE_FRAME, FRAME_KA); |
51 | frame1 = frame_alloc(ONE_FRAME, FRAME_KA); |
51 | frame1 = frame_alloc(ONE_FRAME, FRAME_KA); |
52 | 52 | ||
53 | printf("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0)); |
53 | printf("Writing %#x to physical address %p.\n", VALUE0, KA2PA(frame0)); |
54 | *((__u32 *) frame0) = VALUE0; |
54 | *((uint32_t *) frame0) = VALUE0; |
55 | printf("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1)); |
55 | printf("Writing %#x to physical address %p.\n", VALUE1, KA2PA(frame1)); |
56 | *((__u32 *) frame1) = VALUE1; |
56 | *((uint32_t *) frame1) = VALUE1; |
57 | 57 | ||
58 | printf("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0)); |
58 | printf("Mapping virtual address %p to physical address %p.\n", PAGE0, KA2PA(frame0)); |
59 | page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE); |
59 | page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE); |
60 | printf("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1)); |
60 | printf("Mapping virtual address %p to physical address %p.\n", PAGE1, KA2PA(frame1)); |
61 | page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE); |
61 | page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE); |
62 | 62 | ||
63 | printf("Value at virtual address %p is %#x.\n", PAGE0, v0 = *((__u32 *) PAGE0)); |
63 | printf("Value at virtual address %p is %#x.\n", PAGE0, v0 = *((uint32_t *) PAGE0)); |
64 | printf("Value at virtual address %p is %#x.\n", PAGE1, v1 = *((__u32 *) PAGE1)); |
64 | printf("Value at virtual address %p is %#x.\n", PAGE1, v1 = *((uint32_t *) PAGE1)); |
65 | 65 | ||
66 | ASSERT(v0 == VALUE0); |
66 | ASSERT(v0 == VALUE0); |
67 | ASSERT(v1 == VALUE1); |
67 | ASSERT(v1 == VALUE1); |
68 | 68 | ||
69 | printf("Writing %#x to virtual address %p.\n", 0, PAGE0); |
69 | printf("Writing %#x to virtual address %p.\n", 0, PAGE0); |
70 | *((__u32 *) PAGE0) = 0; |
70 | *((uint32_t *) PAGE0) = 0; |
71 | printf("Writing %#x to virtual address %p.\n", 0, PAGE1); |
71 | printf("Writing %#x to virtual address %p.\n", 0, PAGE1); |
72 | *((__u32 *) PAGE1) = 0; |
72 | *((uint32_t *) PAGE1) = 0; |
73 | 73 | ||
74 | v0 = *((__u32 *) PAGE0); |
74 | v0 = *((uint32_t *) PAGE0); |
75 | v1 = *((__u32 *) PAGE1); |
75 | v1 = *((uint32_t *) PAGE1); |
76 | 76 | ||
77 | printf("Value at virtual address %p is %#x.\n", PAGE0, *((__u32 *) PAGE0)); |
77 | printf("Value at virtual address %p is %#x.\n", PAGE0, *((uint32_t *) PAGE0)); |
78 | printf("Value at virtual address %p is %#x.\n", PAGE1, *((__u32 *) PAGE1)); |
78 | printf("Value at virtual address %p is %#x.\n", PAGE1, *((uint32_t *) PAGE1)); |
79 | 79 | ||
80 | ASSERT(v0 == 0); |
80 | ASSERT(v0 == 0); |
81 | ASSERT(v1 == 0); |
81 | ASSERT(v1 == 0); |
82 | 82 | ||
83 | printf("Test passed.\n"); |
83 | printf("Test passed.\n"); |