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 
27 class DebuggerIO;
28 
30 {
31 }
32 
34 {
35 }
36 
38  const HugeStaticString &input, HugeStaticString &output)
39 {
40 }
41 
43  const HugeStaticString &input, HugeStaticString &output,
44  InterruptState &state, DebuggerIO *pScreen)
45 {
46  // If we see just "mapping", no parameters were matched.
47  uintptr_t address = 0;
48  if (!(input == "mapping"))
49  {
50  // Is it an address?
51  address = input.intValue();
52 
53  if (address == 0)
54  {
55  // No, try a symbol name.
56  // TODO.
57  output = "Not a valid address: `";
58  output += input;
59  output += "'.\n";
60  return true;
61  }
62  }
63  else
64  {
65  output = "Usage: mapping <effective address>";
66  return true;
67  }
68 
69  VirtualAddressSpace &thisVa =
70  Processor::information().getVirtualAddressSpace();
71  VirtualAddressSpace &kernelVa =
73 
74  address &= ~(PhysicalMemoryManager::getPageSize() - 1);
75 
76  void *vAddr = reinterpret_cast<void *>(address);
77 
78  output = "0x";
79  output.append(address, 16);
80  output += ":\n";
81 
82  if (thisVa.isMapped(vAddr))
83  {
84  size_t flags, phys;
85  thisVa.getMapping(vAddr, phys, flags);
86  output += " Mapped to ";
87  output.append(phys, 16);
88  output += " (flags ";
89  output.append(flags, 16);
90  output += ") in this address space.\n";
91  }
92  else
93  output += " Not mapped in this address space.\n";
94 
95 #ifdef KERNEL_NEEDS_ADDRESS_SPACE_SWITCH
97 #endif
98 
99  if (kernelVa.isMapped(vAddr))
100  {
101  size_t flags, phys;
102  kernelVa.getMapping(vAddr, phys, flags);
103  output += " Mapped to ";
104  output.append(phys, 16);
105  output += " (flags ";
106  output.append(flags, 16);
107  output += ") in the kernel address space.\n";
108  }
109  else
110  output += " Not mapped in the kernel address space.\n";
111 
112 #ifdef KERNEL_NEEDS_ADDRESS_SPACE_SWITCH
114 #endif
115 
116  return true;
117 }
bool execute(const HugeStaticString &input, HugeStaticString &output, InterruptState &state, DebuggerIO *screen)
virtual void getMapping(void *virtualAddress, physical_uintptr_t &physicalAddress, size_t &flags)=0
virtual bool isMapped(void *virtualAddress)=0
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()
static ProcessorInformation & information()
Definition: Processor.cc:45
static void switchAddressSpace(VirtualAddressSpace &AddressSpace)
void autocomplete(const HugeStaticString &input, HugeStaticString &output)