Added support for flags in mmap

This commit is contained in:
2020-07-18 13:16:10 -05:00
parent 74fb6834f6
commit 048211a876
3 changed files with 13 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
#include "addressspace.hpp" #include "addressspace.hpp"
#include "util.hpp"
kernel::AddressSpace::AddressSpace(MemoryAllocator& malloc) kernel::AddressSpace::AddressSpace(MemoryAllocator& malloc)
: malloc(malloc) : malloc(malloc)
@@ -7,7 +8,7 @@ kernel::AddressSpace::AddressSpace(MemoryAllocator& malloc)
this->pageDirectory = (PageTableEntry*) 0xFFFFF000; 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; size_t tableIndex = (size_t) start / 4096;
for(int i = (int) length; i > 0; i -= 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); physaddr_t page = malloc.allocate(4096);
pageTables[tableIndex] = page; pageTables[tableIndex] = page;
pageTables[tableIndex].setUsermode(false);
pageTables[tableIndex].setRw(true);
pageTables[tableIndex].setPresent(true); pageTables[tableIndex].setPresent(true);
pageTables[tableIndex].setUsermode(false);
if(flags & MMAP_RW)
pageTables[tableIndex].setRw(true);
} }
tableIndex++; tableIndex++;
} }

View File

@@ -7,6 +7,10 @@
#include "x86/pagetableentry.hpp" #include "x86/pagetableentry.hpp"
#include "types.hpp" #include "types.hpp"
#define MMAP_RW 0x01
#define MMAP_EXEC 0x02
#define MMAP_SHARED 0x04
namespace kernel { namespace kernel {
class AddressSpace { class AddressSpace {
@@ -14,7 +18,7 @@ public:
AddressSpace(MemoryAllocator& malloc); 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); int munmap(void* start, size_t length);

View File

@@ -19,7 +19,7 @@ extern MemoryMap::Region memory_map;
void main(char* cmdline) void main(char* cmdline)
{ {
TTY tty((char*) 0xC00B8000); TTY tty((char*) 0xC00B8000);
tty << PACKAGE_STRING << '\n'; tty << PACKAGE_STRING << "\n\n";
tty << "Low memory: \t" << (int) system_info.getLowMemory() << " KiB\n"; tty << "Low memory: \t" << (int) system_info.getLowMemory() << " KiB\n";
tty << "High memory:\t" << (int) system_info.getHighMemory() << " KiB\n"; tty << "High memory:\t" << (int) system_info.getHighMemory() << " KiB\n";
tty << "Type\t\tLocation\t\tSize\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); BuddyAllocator alloc(memmap, (char*) 0xC0000000, system_info.getHighMemory() / 4 + 256, 6);
AddressSpace vmem(alloc); AddressSpace vmem(alloc);
vmem.mmap((void*) 0x80000000, 0x10000); vmem.mmap((void*) 0x80000000, 0x10000, MMAP_RW);
outb(0xa1, 0xff); outb(0xa1, 0xff);
outb(0x21, 0xff); outb(0x21, 0xff);
tty << "Nothing left to do. Hanging.\n"; tty << "Nothing left to do. Hanging.\n";