test map/unmap
This commit is contained in:
@@ -14,7 +14,6 @@ void *operator new(size_t, void *);
|
|||||||
|
|
||||||
uint8_t mapNumber = 0;
|
uint8_t mapNumber = 0;
|
||||||
|
|
||||||
uint32_t next_start_v = 0x4000;
|
|
||||||
|
|
||||||
namespace Syscall {
|
namespace Syscall {
|
||||||
namespace Skeleton {
|
namespace Skeleton {
|
||||||
@@ -163,6 +162,7 @@ namespace Syscall {
|
|||||||
void* getFreeVirtSpace(four_lvl_paging_t* search_table, uint8_t num_pages){
|
void* getFreeVirtSpace(four_lvl_paging_t* search_table, uint8_t num_pages){
|
||||||
uint32_t start_v = 0x4000;
|
uint32_t start_v = 0x4000;
|
||||||
uint32_t stop_v = 0x6000;
|
uint32_t stop_v = 0x6000;
|
||||||
|
static uint32_t next_start_v = 0x4000;
|
||||||
//static uint32_t next_start_v = start_v;
|
//static uint32_t next_start_v = start_v;
|
||||||
|
|
||||||
//start from last found address
|
//start from last found address
|
||||||
@@ -174,7 +174,7 @@ namespace Syscall {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(space_is_free){
|
if(space_is_free){
|
||||||
next_start_v = v+num_pages;
|
//next_start_v = v+num_pages;
|
||||||
return (void*) ((uintptr_t) (v <<12));
|
return (void*) ((uintptr_t) (v <<12));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,6 +202,7 @@ namespace Syscall {
|
|||||||
|
|
||||||
if(!(flpt->l4->entries[l4Index].present)){
|
if(!(flpt->l4->entries[l4Index].present)){
|
||||||
pagetable_t* newl3 = (pagetable_t*)PageFrameAllocator::alloc(true);
|
pagetable_t* newl3 = (pagetable_t*)PageFrameAllocator::alloc(true);
|
||||||
|
memset(newl3, 0, 4096);
|
||||||
flpt->l4->entries[l4Index] = {
|
flpt->l4->entries[l4Index] = {
|
||||||
.present = 1,
|
.present = 1,
|
||||||
.write = 1,
|
.write = 1,
|
||||||
@@ -213,6 +214,7 @@ namespace Syscall {
|
|||||||
pagetable_t* lvl3 = (pagetable_t*)(flpt->l4->entries[l4Index].address<<12);
|
pagetable_t* lvl3 = (pagetable_t*)(flpt->l4->entries[l4Index].address<<12);
|
||||||
if(!(lvl3->entries[l3Index].present)){
|
if(!(lvl3->entries[l3Index].present)){
|
||||||
pagetable_t* newl2 = (pagetable_t*)PageFrameAllocator::alloc(true);
|
pagetable_t* newl2 = (pagetable_t*)PageFrameAllocator::alloc(true);
|
||||||
|
memset(newl2, 0, 4096);
|
||||||
lvl3->entries[l3Index] = {
|
lvl3->entries[l3Index] = {
|
||||||
.present = 1,
|
.present = 1,
|
||||||
.write = 1,
|
.write = 1,
|
||||||
@@ -224,6 +226,7 @@ namespace Syscall {
|
|||||||
pagetable_t* lvl2 = (pagetable_t*)(lvl3->entries[l3Index].address<<12);
|
pagetable_t* lvl2 = (pagetable_t*)(lvl3->entries[l3Index].address<<12);
|
||||||
if(!(lvl2->entries[l2Index].present)){
|
if(!(lvl2->entries[l2Index].present)){
|
||||||
pagetable_t* newl1 = (pagetable_t*)PageFrameAllocator::alloc(true);
|
pagetable_t* newl1 = (pagetable_t*)PageFrameAllocator::alloc(true);
|
||||||
|
memset(newl1, 0, 4096);
|
||||||
lvl2->entries[l2Index] = {
|
lvl2->entries[l2Index] = {
|
||||||
.present = 1,
|
.present = 1,
|
||||||
.write = 1,
|
.write = 1,
|
||||||
@@ -233,15 +236,16 @@ namespace Syscall {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pagetable_t* lvl1 = (pagetable_t*)(lvl2->entries[l2Index].address<<12);
|
pagetable_t* lvl1 = (pagetable_t*)(lvl2->entries[l2Index].address<<12);
|
||||||
assert(!(lvl1->entries[l1Index].present)); // should not be present, bc its a new mapping
|
|
||||||
|
|
||||||
if(frame)
|
if(frame){
|
||||||
|
assert(!(lvl1->entries[l1Index].present)); // should not be present, bc its a new mapping
|
||||||
lvl1->entries[l1Index] = {
|
lvl1->entries[l1Index] = {
|
||||||
.present = 1,
|
.present = 1,
|
||||||
.write = 1,
|
.write = 1,
|
||||||
.user = 1,
|
.user = 1,
|
||||||
.address = (uintptr_t)frame >> 12
|
.address = (uintptr_t)frame >> 12
|
||||||
};
|
};
|
||||||
|
}
|
||||||
else //unmap if nullptr
|
else //unmap if nullptr
|
||||||
lvl1->entries[l1Index].present = 0;
|
lvl1->entries[l1Index].present = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,14 @@ Thread::Thread (bool kernel, void * startframe, int num_pages): queue_link(null
|
|||||||
StackPointer.user = (void*)(0x61FF000+STACK_SIZE);
|
StackPointer.user = (void*)(0x61FF000+STACK_SIZE);
|
||||||
|
|
||||||
paging_tree = (four_lvl_paging_t*)PageFrameAllocator::alloc(true);
|
paging_tree = (four_lvl_paging_t*)PageFrameAllocator::alloc(true);
|
||||||
|
memset(paging_tree, 0, 4096);
|
||||||
create_basic_page_table(paging_tree, &identity_table);
|
create_basic_page_table(paging_tree, &identity_table);
|
||||||
|
|
||||||
appcode_table = (pagetable_t*) PageFrameAllocator::alloc(true);
|
appcode_table = (pagetable_t*) PageFrameAllocator::alloc(true);
|
||||||
|
memset(appcode_table, 0, 4096);
|
||||||
|
|
||||||
|
appstack_table = (pagetable_t*) PageFrameAllocator::alloc(true);
|
||||||
|
memset(appstack_table, 0, 4096);
|
||||||
|
|
||||||
assert(num_pages < 512); //limit for application code size is 2M
|
assert(num_pages < 512); //limit for application code size is 2M
|
||||||
for(uint8_t i=0; i<num_pages; i++){
|
for(uint8_t i=0; i<num_pages; i++){
|
||||||
|
|||||||
@@ -1,6 +1,44 @@
|
|||||||
// vim: set noet ts=4 sw=4:
|
// vim: set noet ts=4 sw=4:
|
||||||
|
|
||||||
#include "../libsys/stub.h"
|
#include "../libsys/stub.h"
|
||||||
|
#include "../libsys/string.h"
|
||||||
|
|
||||||
|
char* itoh(unsigned int value, char* buffer) {
|
||||||
|
char* ptr = &buffer[11];
|
||||||
|
*ptr = '\0'; // Nullterminator am Ende setzen
|
||||||
|
|
||||||
|
if (value == 0) {
|
||||||
|
*--ptr = '0';
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
ptr--;
|
||||||
|
*ptr = '0' + (value % 16);
|
||||||
|
if(*ptr >= 0x3A)
|
||||||
|
*ptr+=7;
|
||||||
|
value /= 16;
|
||||||
|
} while (value != 0);
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
char* itoa(unsigned int value, char* buffer) {
|
||||||
|
char* ptr = &buffer[11];
|
||||||
|
*ptr = '\0'; // Nullterminator am Ende setzen
|
||||||
|
|
||||||
|
if (value == 0) {
|
||||||
|
*--ptr = '0';
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
ptr--;
|
||||||
|
*ptr = '0' + (value % 10);
|
||||||
|
value /= 10;
|
||||||
|
} while (value != 0);
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" void main() {
|
extern "C" void main() {
|
||||||
// Thread 1 may be an auxiliary thread
|
// Thread 1 may be an auxiliary thread
|
||||||
@@ -10,31 +48,29 @@ extern "C" void main() {
|
|||||||
unsigned id = sys_getpid();
|
unsigned id = sys_getpid();
|
||||||
char text[] = "appX";
|
char text[] = "appX";
|
||||||
text[3] = 0x30+id;
|
text[3] = 0x30+id;
|
||||||
char buf = 32;
|
|
||||||
|
|
||||||
write(1, text, sizeof(text), 0, (int)id);
|
write(1, text, sizeof(text), 0, (int)id);
|
||||||
|
|
||||||
uint8_t cnt = 0;
|
uint8_t cnt = 0;
|
||||||
for (unsigned i = 1;; ++i) {
|
for (unsigned i = 1;; ++i) {
|
||||||
char msg[5];
|
|
||||||
msg[0] = 0x30+cnt;
|
|
||||||
msg[1] = 0;
|
|
||||||
cnt=(cnt+1)%10;
|
|
||||||
write(1, msg, 1, 6, (int)id);
|
|
||||||
void* ptr= map(512);
|
|
||||||
|
|
||||||
//sprintf(&buf, "ptr address: %x \n" , ptr);
|
//counter to see app running
|
||||||
//unmap(ptr, 512);
|
cnt=(cnt+1)%100;
|
||||||
|
char buf[12];
|
||||||
|
char* msg = itoa(cnt,buf);
|
||||||
|
write(1, msg, strlen(msg), 6, (int)id);
|
||||||
|
|
||||||
|
// test map/unmap and print ptr
|
||||||
|
void* ptr= map(4096);
|
||||||
|
uint16_t* val = ((uint16_t*)ptr);
|
||||||
|
*val = 0x1337;
|
||||||
|
|
||||||
//if(i==id){
|
msg = itoh((uintptr_t)ptr,buf);
|
||||||
// //write(2, "kill", 4);
|
write(1, msg, strlen(msg), 12, (int)id);
|
||||||
// //write(2, &text[4], 1);
|
unmap(ptr, 4096);
|
||||||
// //write(2, " ", 1);
|
|
||||||
// sys_exit();
|
sleep(100);
|
||||||
//}
|
if(id == 4)
|
||||||
sleep(1000);
|
|
||||||
if(id == 2)
|
|
||||||
*reinterpret_cast<uint8_t*>(0xdeadbeaf) = 1;
|
*reinterpret_cast<uint8_t*>(0xdeadbeaf) = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user