1#include <stdlib.h> 2#include <stdbool.h> 3#include <stdio.h> 4#include <string.h> 5#include <barrelfish/barrelfish.h> 6#include <barrelfish/types.h> 7#include <barrelfish/cap_predicates.h> 8#include <mdb/mdb.h> 9#include <mdb/mdb_tree.h> 10 11bool debug_all_the_things = false; 12 13#define DEBUG_ALL_THE_THINGS(...) \ 14 do { \ 15 if (debug_all_the_things) \ 16 printf(__VA_ARGS__); \ 17 } while(0) 18 19 20#define CAP_COUNT 8 21#define BASE_BITS 12 22struct cte caps[CAP_COUNT]; 23static inline void setup(void) { 24 memset(caps, 0, CAP_COUNT*sizeof(struct cte)); 25 for (size_t i = 0; i < CAP_COUNT; i++) { 26 struct capability *cap = &caps[i].cap; 27 cap->type = ObjType_PhysAddr; 28 cap->rights = CAPRIGHTS_ALLRIGHTS; 29 cap->u.ram.base = 0x0; 30 cap->u.ram.bytes = 1UL << (BASE_BITS + i); 31 mdb_insert(&caps[i]); 32 } 33} 34 35int main(int argc, char *argv[]) 36{ 37 setup(); 38 39 struct cte devframe; 40 struct capability *cap = &devframe.cap; 41 cap->type = ObjType_DevFrame; 42 cap->rights = CAPRIGHTS_ALLRIGHTS; 43 cap->u.devframe.base = 0x0; 44 cap->u.devframe.bytes = 1UL << BASE_BITS; 45 mdb_insert(&devframe); 46 47 struct cte *retcte; 48 mdb_find_cap_for_address(0x0, &retcte); 49 50 if (retcte != &devframe) { 51 printf("devframe@%p\n", &devframe); 52 printf(" retcap@%p\n", retcte); 53 if (retcte) { 54 printf("retcap: (%d) 0x%lx %zd\n", retcte->cap.type, get_address(&retcte->cap), get_size(&retcte->cap)); 55 } 56 printf("devframe: (%d) 0x%lx %zd\n", devframe.cap.type, get_address(&devframe.cap), get_size(&devframe.cap)); 57 mdb_dump_all_the_things(); 58 } 59 60 return 0; 61} 62