2 * Copyright 2007, Travis Geiselbrecht. All rights reserved.
3 * Distributed under the terms of the MIT License.
10 #include <KernelExport.h>
14 #include <vm/vm_types.h>
17 static area_id sCommPageArea
;
18 static addr_t
* sCommPageAddress
;
19 static void* sFreeCommPageSpace
;
20 static image_id sCommPageImage
;
23 #define ALIGN_ENTRY(pointer) (void*)ROUNDUP((addr_t)(pointer), 8)
27 allocate_commpage_entry(int entry
, size_t size
)
29 void* space
= sFreeCommPageSpace
;
30 sFreeCommPageSpace
= ALIGN_ENTRY((addr_t
)sFreeCommPageSpace
+ size
);
31 sCommPageAddress
[entry
] = (addr_t
)space
- (addr_t
)sCommPageAddress
;
32 dprintf("allocate_commpage_entry(%d, %lu) -> %p\n", entry
, size
,
33 (void*)sCommPageAddress
[entry
]);
39 fill_commpage_entry(int entry
, const void* copyFrom
, size_t size
)
41 void* space
= allocate_commpage_entry(entry
, size
);
42 memcpy(space
, copyFrom
, size
);
43 return (addr_t
)space
- (addr_t
)sCommPageAddress
;
50 return sCommPageImage
;
55 clone_commpage_area(team_id team
, void** address
)
57 *address
= (void*)KERNEL_USER_DATA_BASE
;
58 return vm_clone_area(team
, "commpage", address
,
59 B_RANDOMIZED_BASE_ADDRESS
, B_READ_AREA
| B_EXECUTE_AREA
| B_KERNEL_AREA
,
60 REGION_PRIVATE_MAP
, sCommPageArea
, true);
67 // create a read/write kernel area
68 sCommPageArea
= create_area("kernel_commpage", (void **)&sCommPageAddress
,
69 B_ANY_ADDRESS
, COMMPAGE_SIZE
, B_FULL_LOCK
,
70 B_KERNEL_WRITE_AREA
| B_KERNEL_READ_AREA
);
73 memset(sCommPageAddress
, 0, COMMPAGE_SIZE
);
75 // fill in some of the table
76 sCommPageAddress
[0] = COMMPAGE_SIGNATURE
;
77 sCommPageAddress
[1] = COMMPAGE_VERSION
;
79 // the next slot to allocate space is after the table
80 sFreeCommPageSpace
= ALIGN_ENTRY(&sCommPageAddress
[COMMPAGE_TABLE_ENTRIES
]);
82 // create the image for the commpage
83 sCommPageImage
= elf_create_memory_image("commpage", 0, COMMPAGE_SIZE
, 0,
85 elf_add_memory_image_symbol(sCommPageImage
, "commpage_table",
86 0, COMMPAGE_TABLE_ENTRIES
* sizeof(addr_t
),
96 commpage_init_post_cpus(void)
98 return arch_commpage_init_post_cpus();