summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/include/kernel/basesegment.H12
-rw-r--r--src/include/kernel/syscalls.H9
-rw-r--r--src/include/kernel/vmmmgr.H12
-rw-r--r--src/include/sys/mm.h27
-rw-r--r--src/kernel/basesegment.C8
-rw-r--r--src/kernel/syscall.C30
-rw-r--r--src/kernel/vmmmgr.C5
-rw-r--r--src/lib/makefile2
-rw-r--r--src/lib/syscall_mm.C12
-rw-r--r--src/makefile2
-rw-r--r--src/usr/testcore/kernel/slbtest.H15
11 files changed, 121 insertions, 13 deletions
diff --git a/src/include/kernel/basesegment.H b/src/include/kernel/basesegment.H
index 7f1c78dfa..8086c08b5 100644
--- a/src/include/kernel/basesegment.H
+++ b/src/include/kernel/basesegment.H
@@ -6,6 +6,8 @@
#include <kernel/segment.H>
+// Forward declaration.
+class MessageQueue;
class Block;
/** @class BaseSegment
@@ -41,6 +43,16 @@ class BaseSegment : public Segment
*/
bool handlePageFault(task_t* i_task, uint64_t i_addr);
+ /**
+ * @brief Allocates a block of virtual memory of the given size
+ * @param i_mq[in] - Message queue to be associated with the block
+ * @param i_va[in] - Base virtual address of the block to be allocated
+ * @param i_size[in] - Requested virtual memory size of the block
+ * @return int - 0 for successful block allocation, non-zero otherwise
+ */
+ static int mmAllocBlock(MessageQueue* i_mq,void* i_va,
+ uint64_t i_size);
+
private:
/**
* @brief Internal implementation of init function.
diff --git a/src/include/kernel/syscalls.H b/src/include/kernel/syscalls.H
index a76bb82a9..dad90056c 100644
--- a/src/include/kernel/syscalls.H
+++ b/src/include/kernel/syscalls.H
@@ -56,17 +56,18 @@ namespace Systemcalls
/** futex_wait() */
FUTEX_WAIT,
-
/** futex_wake() */
FUTEX_WAKE,
/** shutdown() */
MISC_SHUTDOWN,
-
/** cpu_core_type() */
- MISC_CPUCORETYPE,
+ MISC_CPUCORETYPE,
/** cpu_dd_level() */
- MISC_CPUDDLEVEL,
+ MISC_CPUDDLEVEL,
+
+ /** mm_alloc_block() */
+ MM_ALLOC_BLOCK,
SYSCALL_MAX
};
diff --git a/src/include/kernel/vmmmgr.H b/src/include/kernel/vmmmgr.H
index feee7a731..7c8c63c22 100644
--- a/src/include/kernel/vmmmgr.H
+++ b/src/include/kernel/vmmmgr.H
@@ -6,6 +6,8 @@
#include <kernel/types.h>
#include <kernel/spinlock.H>
+class MessageQueue;
+
class VmmManager
{
public:
@@ -68,6 +70,16 @@ class VmmManager
*/
static int devUnmap(void* ea);
+ /**
+ * @brief Allocates a block of virtual memory of the given size
+ * @param i_mq[in] - Message queue to be associated with the block
+ * @param i_va[in] - Base virtual address of the block to be allocated
+ * @param i_size[in] - Requested virtual memory size of the block
+ * @return int - 0 for successful block allocation, non-zero otherwise
+ */
+ static int mmAllocBlock(MessageQueue* i_mq,void* i_va,uint64_t i_size);
+
+
protected:
VmmManager();
~VmmManager() {};
diff --git a/src/include/sys/mm.h b/src/include/sys/mm.h
new file mode 100644
index 000000000..4719ff7df
--- /dev/null
+++ b/src/include/sys/mm.h
@@ -0,0 +1,27 @@
+#ifndef __SYS_MM_H
+#define __SYS_MM_H
+
+#include <stdint.h>
+#include <sys/msg.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/** @fn mm_alloc_block()
+ * @brief System call to allocate virtual memory block in the base segment
+ *
+ * @param[in] mq - Message queue to be associated with the block
+ * @param[in] va - Base virtual address of the block to be allocated
+ * @param[in] size - Requested virtual memory size of the block
+ *
+ * @return int - 0 for successful block allocation, non-zero otherwise
+ */
+int mm_alloc_block(msg_q_t mq,void* va,uint64_t size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/kernel/basesegment.C b/src/kernel/basesegment.C
index 4a94b86f5..d9f5a12e8 100644
--- a/src/kernel/basesegment.C
+++ b/src/kernel/basesegment.C
@@ -70,3 +70,11 @@ bool BaseSegment::handlePageFault(task_t* i_task, uint64_t i_addr)
// Tail recursion to block chain.
return iv_block->handlePageFault(i_task, i_addr);
}
+
+/**
+ * Allocates a block of virtual memory of the given size
+ */
+int BaseSegment::mmAllocBlock(MessageQueue* i_mq,void* i_va,uint64_t i_size)
+{
+ return 0;
+}
diff --git a/src/kernel/syscall.C b/src/kernel/syscall.C
index 639845224..51009195d 100644
--- a/src/kernel/syscall.C
+++ b/src/kernel/syscall.C
@@ -54,6 +54,7 @@ namespace Systemcalls
void Shutdown(task_t *t);
void CpuCoreType(task_t *t);
void CpuDDLevel(task_t *t);
+ void MmAllocBlock(task_t *t);
syscall syscalls[] =
{
@@ -73,18 +74,20 @@ namespace Systemcalls
&MmioMap, // MMIO_MAP
&MmioUnmap, // MMIO_UNMAP
- &DevMap,
- &DevUnmap,
+ &DevMap, // DEV_MAP
+ &DevUnmap, // DEV_UNMAP
&TimeNanosleep, // TIME_NANOSLEEP
- &FutexWait, // FUTEX_WAIT
- &FutexWake, // FUTEX_WAKE
+ &FutexWait, // FUTEX_WAIT
+ &FutexWake, // FUTEX_WAKE
- &Shutdown, // MISC_SHUTDOWN
+ &Shutdown, // MISC_SHUTDOWN
- &CpuCoreType, // MISC_CPUCORETYPE
- &CpuDDLevel, // MISC_CPUDDLEVEL
+ &CpuCoreType, // MISC_CPUCORETYPE
+ &CpuDDLevel, // MISC_CPUDDLEVEL
+
+ &MmAllocBlock, // MM_ALLOC_BLOCK
};
};
@@ -398,4 +401,17 @@ namespace Systemcalls
TASK_SETRTN(t, CpuID::getCpuDD());
}
+ /**
+ * Allocate a block of virtual memory within the base segment
+ * @param[in] t: The task used to allocate a block in the base segment
+ */
+ void MmAllocBlock(task_t* t)
+ {
+ MessageQueue* mq = (MessageQueue*)TASK_GETARG0(t);
+ void* va = (void*)TASK_GETARG1(t);
+ uint64_t size = (uint64_t)TASK_GETARG2(t);
+
+ TASK_SETRTN(t, VmmManager::mmAllocBlock(mq,va,size));
+ }
+
};
diff --git a/src/kernel/vmmmgr.C b/src/kernel/vmmmgr.C
index bf6ff10d4..46fca9fef 100644
--- a/src/kernel/vmmmgr.C
+++ b/src/kernel/vmmmgr.C
@@ -106,3 +106,8 @@ bool VmmManager::_pteMiss(task_t* t, uint64_t effAddr)
return rc;
}
+int VmmManager::mmAllocBlock(MessageQueue* i_mq,void* i_va,uint64_t i_size)
+{
+ return BaseSegment::mmAllocBlock(i_mq,i_va,i_size);
+}
+
diff --git a/src/lib/makefile b/src/lib/makefile
index 67b412a3d..b1660d469 100644
--- a/src/lib/makefile
+++ b/src/lib/makefile
@@ -20,6 +20,6 @@ ROOTPATH = ../..
OBJS = string.o stdlib.o assert.o stdio.o
OBJS += syscall_stub.o syscall_task.o syscall_msg.o
OBJS += syscall_mmio.o syscall_time.o sync.o syscall_misc.o
-OBJS += cxxtest_data.o
+OBJS += syscall_mm.o cxxtest_data.o
include ${ROOTPATH}/config.mk
diff --git a/src/lib/syscall_mm.C b/src/lib/syscall_mm.C
new file mode 100644
index 000000000..187cdced2
--- /dev/null
+++ b/src/lib/syscall_mm.C
@@ -0,0 +1,12 @@
+#include <sys/syscall.h>
+#include <sys/mm.h>
+
+using namespace Systemcalls;
+
+/**
+ * System call to allocate a block of virtual memory within the base segment
+ */
+int mm_alloc_block(msg_q_t mq,void* va,uint64_t size)
+{
+ return (int64_t)_syscall3(MM_ALLOC_BLOCK, mq, va, (void*)size);
+}
diff --git a/src/makefile b/src/makefile
index 3a5489cb9..f21afaf9b 100644
--- a/src/makefile
+++ b/src/makefile
@@ -28,7 +28,7 @@ DIRECT_BOOT_OBJECTS = start.o kernel.o taskmgr.o cpumgr.o syscall.o \
scheduler.o exception.o vmmmgr.o timemgr.o \
syscall_stub.o syscall_task.o syscall_misc.o \
syscall_msg.o syscall_mmio.o syscall_time.o \
- init_main.o vfs_main.o sync.o futexmgr.o \
+ syscall_mm.o init_main.o vfs_main.o sync.o futexmgr.o \
ptmgr.o segmentmgr.o basesegment.o devicesegment.o \
block.o cxxtest_data.o cpuid.o misc.o
diff --git a/src/usr/testcore/kernel/slbtest.H b/src/usr/testcore/kernel/slbtest.H
index 65fe3bd08..0572ca068 100644
--- a/src/usr/testcore/kernel/slbtest.H
+++ b/src/usr/testcore/kernel/slbtest.H
@@ -10,6 +10,7 @@
#include <sys/time.h>
#include <sys/task.h>
#include <sys/mmio.h>
+#include <sys/mm.h>
class slbtest: public CxxTest::TestSuite
{
@@ -63,6 +64,20 @@ class slbtest: public CxxTest::TestSuite
}
}
+ void testSegBlock()
+ {
+ int rc = -1;
+ msg_q_t mq = msg_q_create(); //Create empty message queue
+ uint64_t va = 0xC800000000; //800GB
+ uint64_t size = 0x40000000; //1GB
+ printk("Allocate 1GB block with empty msgq @ vaddr = 800GB within base segment\n");
+ rc = mm_alloc_block(mq,reinterpret_cast<void*>(va),size);
+ if (rc != 0)
+ {
+ TS_FAIL("Failed to create BaseSegment block\n");
+ }
+ }
+
private:
static void writeEA1TB(void *i_p)
OpenPOWER on IntegriCloud