Added support for flags in mmap
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "addressspace.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
kernel::AddressSpace::AddressSpace(MemoryAllocator& malloc)
|
||||
: malloc(malloc)
|
||||
@@ -7,7 +8,7 @@ kernel::AddressSpace::AddressSpace(MemoryAllocator& malloc)
|
||||
this->pageDirectory = (PageTableEntry*) 0xFFFFF000;
|
||||
}
|
||||
|
||||
int kernel::AddressSpace::mmap(void* start, size_t length)
|
||||
int kernel::AddressSpace::mmap(void* start, size_t length, int flags)
|
||||
{
|
||||
size_t tableIndex = (size_t) start / 4096;
|
||||
for(int i = (int) length; i > 0; i -= 4096)
|
||||
@@ -27,9 +28,11 @@ int kernel::AddressSpace::mmap(void* start, size_t length)
|
||||
{
|
||||
physaddr_t page = malloc.allocate(4096);
|
||||
pageTables[tableIndex] = page;
|
||||
pageTables[tableIndex].setUsermode(false);
|
||||
pageTables[tableIndex].setRw(true);
|
||||
pageTables[tableIndex].setPresent(true);
|
||||
pageTables[tableIndex].setUsermode(false);
|
||||
if(flags & MMAP_RW)
|
||||
pageTables[tableIndex].setRw(true);
|
||||
|
||||
}
|
||||
tableIndex++;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
#include "x86/pagetableentry.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
#define MMAP_RW 0x01
|
||||
#define MMAP_EXEC 0x02
|
||||
#define MMAP_SHARED 0x04
|
||||
|
||||
namespace kernel {
|
||||
|
||||
class AddressSpace {
|
||||
@@ -14,7 +18,7 @@ public:
|
||||
|
||||
AddressSpace(MemoryAllocator& malloc);
|
||||
|
||||
int mmap(void* start, size_t length);
|
||||
int mmap(void* start, size_t length, int flags);
|
||||
|
||||
int munmap(void* start, size_t length);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ extern MemoryMap::Region memory_map;
|
||||
void main(char* cmdline)
|
||||
{
|
||||
TTY tty((char*) 0xC00B8000);
|
||||
tty << PACKAGE_STRING << '\n';
|
||||
tty << PACKAGE_STRING << "\n\n";
|
||||
tty << "Low memory: \t" << (int) system_info.getLowMemory() << " KiB\n";
|
||||
tty << "High memory:\t" << (int) system_info.getHighMemory() << " KiB\n";
|
||||
tty << "Type\t\tLocation\t\tSize\n";
|
||||
@@ -32,7 +32,7 @@ void main(char* cmdline)
|
||||
}
|
||||
BuddyAllocator alloc(memmap, (char*) 0xC0000000, system_info.getHighMemory() / 4 + 256, 6);
|
||||
AddressSpace vmem(alloc);
|
||||
vmem.mmap((void*) 0x80000000, 0x10000);
|
||||
vmem.mmap((void*) 0x80000000, 0x10000, MMAP_RW);
|
||||
outb(0xa1, 0xff);
|
||||
outb(0x21, 0xff);
|
||||
tty << "Nothing left to do. Hanging.\n";
|
||||
|
||||
Reference in New Issue
Block a user