The Pedigree Project 0.1
MappingCommand.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "pedigree/kernel/debugger/commands/MappingCommand.h"
21#include "pedigree/kernel/processor/PhysicalMemoryManager.h"
22#include "pedigree/kernel/processor/Processor.h"
23#include "pedigree/kernel/processor/ProcessorInformation.h"
24#include "pedigree/kernel/processor/VirtualAddressSpace.h"
25#include "pedigree/kernel/processor/types.h"
26
27class DebuggerIO;
28
30
32
34
36 InterruptState& state, DebuggerIO* pScreen) {
37 // If we see just "mapping", no parameters were matched.
38 uintptr_t address = 0;
39 if (!(input == "mapping"))
40 {
41 // Is it an address?
42 address = input.intValue();
43
44 if (address == 0) {
45 // No, try a symbol name.
46 // TODO.
47 output = "Not a valid address: `";
48 output += input;
49 output += "'.\n";
50 return true;
51 }
52 } else {
53 output = "Usage: mapping <effective address>";
54 return true;
55 }
56
57 VirtualAddressSpace& thisVa = Processor::information().getVirtualAddressSpace();
59
60 address &= ~(PhysicalMemoryManager::getPageSize() - 1);
61
62 void* vAddr = reinterpret_cast<void*>(address);
63
64 output = "0x";
65 output.append(address, 16);
66 output += ":\n";
67
68 if (thisVa.isMapped(vAddr)) {
69 size_t flags;
70 physical_uintptr_t phys;
71 thisVa.getMapping(vAddr, phys, flags);
72 output += " Mapped to ";
73 output.append(phys, 16);
74 output += " (flags ";
75 output.append(flags, 16);
76 output += ") in this address space.\n";
77 } else
78 output += " Not mapped in this address space.\n";
79
80 if (kernelVa.isMapped(vAddr)) {
81 size_t flags;
82 physical_uintptr_t phys;
83 kernelVa.getMapping(vAddr, phys, flags);
84 output += " Mapped to ";
85 output.append(phys, 16);
86 output += " (flags ";
87 output.append(flags, 16);
88 output += ") in the kernel address space.\n";
89 } else
90 output += " Not mapped in the kernel address space.\n";
91
92 return true;
93}
bool execute(const HugeStaticString &input, HugeStaticString &output, InterruptState &state, DebuggerIO *screen)
void autocomplete(const HugeStaticString &input, HugeStaticString &output)
static ProcessorInformation & information()
virtual bool isMapped(void *virtualAddress)=0
virtual bool getMapping(void *virtualAddress, physical_uintptr_t &physicalAddress, size_t &flags)=0
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()