The Pedigree Project  0.1
InfoBlock.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/process/InfoBlock.h"
21 #include "pedigree/kernel/Log.h"
22 #include "pedigree/kernel/Version.h"
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/machine/Machine.h"
25 #include "pedigree/kernel/machine/Timer.h"
26 #include "pedigree/kernel/machine/TimerHandler.h"
27 #include "pedigree/kernel/processor/PhysicalMemoryManager.h"
28 #include "pedigree/kernel/processor/VirtualAddressSpace.h"
29 #include "pedigree/kernel/processor/state_forward.h"
30 #include "pedigree/kernel/processor/types.h"
31 #include "pedigree/kernel/time/Time.h"
32 #include "pedigree/kernel/utilities/utility.h"
33 
34 InfoBlockManager InfoBlockManager::m_Instance;
35 
36 InfoBlockManager::InfoBlockManager()
37  : TimerHandler(), m_bInitialised(false), m_pInfoBlock(0)
38 {
39 }
40 
41 InfoBlockManager::~InfoBlockManager()
42 {
43  Machine::instance().getTimer()->unregisterHandler(this);
44 }
45 
46 InfoBlockManager &InfoBlockManager::instance()
47 {
48  return m_Instance;
49 }
50 
51 bool InfoBlockManager::initialise()
52 {
53  // Prepare the mapping, if we can.
55  void *infoBlock = reinterpret_cast<void *>(va.getGlobalInfoBlock());
56  if (!infoBlock)
57  return false; // Nothing to do here.
58 
59  NOTICE(
60  "InfoBlockManager: Setting up global info block at " << Hex
61  << infoBlock);
62 
63  // Map for userspace.
64  physical_uintptr_t page = PhysicalMemoryManager::instance().allocatePage();
65  va.map(page, infoBlock, 0);
66 
67  // Map for the kernel - trick is, our version is a page ahead.
68  m_pInfoBlock =
69  reinterpret_cast<InfoBlock *>(adjust_pointer(infoBlock, 0x1000));
70  va.map(
71  page, m_pInfoBlock,
73 
74  // Set up basic defaults.
75  ByteSet(m_pInfoBlock, 0, sizeof(InfoBlock));
76  StringCopy(m_pInfoBlock->sysname, "Pedigree");
77  StringCopy(m_pInfoBlock->release, "Foster");
78  StringCopy(m_pInfoBlock->version, g_pBuildRevision);
80  StringCopy(m_pInfoBlock->machine, g_pBuildTarget);
81 
82  // Register ourselves with the main timer.
83  m_bInitialised = true;
84  return Machine::instance().getTimer()->registerHandler(this);
85 }
86 
87 void InfoBlockManager::timer(uint64_t, InterruptState &)
88 {
89  // Update the timestamp in the info block.
90  m_pInfoBlock->now = Time::getTimeNanoseconds();
91  m_pInfoBlock->now_s = Time::getTime();
92 }
93 
94 void InfoBlockManager::setPid(size_t value)
95 {
96  if (LIKELY(m_bInitialised))
97  m_pInfoBlock->pid = value;
98 }
static PhysicalMemoryManager & instance()
virtual Timer * getTimer()=0
virtual physical_uintptr_t allocatePage(size_t pageConstraints=0)=0
virtual bool map(physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags)=0
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()
#define NOTICE(text)
Definition: Log.h:74
Definition: Log.h:136