More work on Kernel class, syscalls

This commit is contained in:
Nathan Giddings
2020-12-11 09:19:29 -06:00
parent e8c3de4a63
commit 69c3c8a847
34 changed files with 390 additions and 121 deletions

View File

@@ -1,17 +1,24 @@
#ifndef KERNEL_H
#define KERNEL_H
#include "pageallocator.hpp"
#include "memorymanager.hpp"
#include "memoryblock.hpp"
#include "process.hpp"
#include "systypes.hpp"
using namespace kernelns;
class Kernel
{
public:
Kernel();
/**
* Maps a region of pages starting at the virtual address 'page', allocating
* each mapped frame and any necessary page tables.
* @brief Maps a region of pages starting at virtual address 'page' with
* length 'length'. Allocates each mapped frame and any necessary page
* tables. This method does not perform any checks before overwriting page
* tables; it is the responsibility of the caller to ensure that the
* operation is safe to perform.
*
* @param page The virtual address of the first page to map
* @param length The size in bytes of the region to map
@@ -22,9 +29,21 @@ public:
int allocateRegion(void* page, size_t length, int flags);
/**
* Maps a contiguous region of pages to a configuous region of frames,
* allocating new page tables as needed. All pages will share the same
* flags.
* @brief Unmaps and frees a region of mapped pages starting at virtual
* address 'page' with length 'length'. Does not free any page tables
* that are made redundant by this operation. It is the responsibility
* of the caller to ensure that all pages in the specified region are
* mapped and should be returned to the page allocator.
*
* @param page The virtual address of the first page to free
* @param length The size in bytes of the region to free
*/
void freeRegion(void* page, size_t length);
/**
* @brief Maps a contiguous region of pages to a contiguous region of
* frames. Allocates new page tables as needed. All pages will share
* the same flags.
*
* @param page The virtual address of the first page to map
* @param frame The physical address of the first frame to map to
@@ -36,33 +55,32 @@ public:
int mapRegion(void* page, physaddr_t frame, size_t length, int flags);
/**
* Maps a single page to a single frame. Allocates a new page table if one
* does not exist for that frame.
* @brief Unmaps a region of pages; does not return them to the page
* allocator.
*
* @param page the virtual address of the page to map
* @param frame the physical address of the frame to map to
* @param flags flags to apply to the entry
*
* @returns zero upon success, nonzero on failure
* @param page The virtual address of the first page to unmap
* @param length The size in bytes of the region to unmap
*/
int mapPage(void* page, physaddr_t frame, int flags);
void unmapRegion(void* page, size_t length);
/**
* Reserve a single page frame.
*
* @returns the physical address of the reserved frame.
*/
physaddr_t reserveFrame();
unsigned int createSharedBlock(size_t length, int flags);
/**
* Frees a single page frame.
*/
void freeFrame(physaddr_t frame);
void deleteSharedBlock(unsigned int id);
const MemoryBlock& getSharedBlock(unsigned int id);
const Process& getActiveProcess();
const Process& switchProcess();
private:
PageAllocator& pageAllocator;
MemoryManager& mmgr;
};
extern Kernel kernel;
#endif