1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/include/kernel/stacksegment.H $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
/* COPYRIGHT International Business Machines Corp. 2011,2014 */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
/* You may obtain a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
/* implied. See the License for the specific language governing */
/* permissions and limitations under the License. */
/* */
/* IBM_PROLOG_END_TAG */
/** @file stacksegment.H
* @brief Defines the stack segment (1TB) class.
*/
#ifndef __KERNEL_STACKSEGMENT_H
#define __KERNEL_STACKSEGMENT_H
#include <kernel/types.h>
#include <kernel/segment.H>
#include <kernel/spinlock.H>
#include <util/locked/list.H>
#include <usr/vmmconst.h>
// Forward declaration.
class Block;
/** @struct StackBlockNode
* @brief Node structure for storing blocks onto a Util::Locked::List.
*/
struct StackBlockNode
{
/** Next pointer for list. */
StackBlockNode* next;
/** Previous pointer for list. */
StackBlockNode* prev;
/** Key value (8mb adjusted address for stack). */
uint64_t key;
/** Pointer to block representing the stack. */
Block* block;
};
/** @class StackSegment
* @brief Class to manage the stack segment at 1 TB.
*
* Contains a list of blocks, one for each task, associated with the segment
* representing the stacks.
*/
class StackSegment : public Segment
{
protected:
/**
* @brief Constructor.
* Initialize attributes and set base addresss of segment to 1 TB.
*/
StackSegment() : Segment(VMM_VADDR_STACK_SEGMENT) {};
/**
* @brief Destructor
* Delete any blocks owned by this segment.
*/
~StackSegment();
public:
/**
* @brief Initialize the segment by adding to the segment manager.
*/
static void init();
/**
* @brief Implementation of the pure-virtual function from Segment.
*
* Calls block chain to deal with page fault.
*/
bool handlePageFault(task_t* i_task, uint64_t i_addr, bool i_store);
/**
* @brief Locate the physical address of the given virtual address
* @param[in] i_vaddr virtual address
* @return the physical address bound to the virtual address, or
* -EFAULT if i_vaddr not found. @see errno.h
*/
uint64_t findPhysicalAddress(uint64_t i_vaddr) const;
/**
* @brief Create a new stack for a task.
*
* @param i_task - Task ID of task to own the stack.
*
* @return Upper address of the newly created stack.
*/
static void* createStack(tid_t i_task);
/**
* @brief Delete previously created stack for a task.
*
* @param i_task - Task ID of task owning the stack.
*
* @note This function obtains the VMM-subsystem spinlock.
*/
static void deleteStack(tid_t i_task);
private:
/** @brief Mapping of virtual address ranges to blocks representing
* stacks.
*
* The blocks are created such that the 1TB range of this segment is
* divided into 8MB chunks, such that (tid*8MB + 1TB) = bottom of
* the stack address range. The stack is then arranged somewhere
* within that range to provide protection above and below the stack
* and to efficiently utilize the hashed page table.
*
* This list is therefore indexed by the low address of the
* range (tid*8MB + 1TB).
*/
Util::Locked::List<StackBlockNode, uint64_t,
true, Spinlock> iv_blockList;
/** Internal implementation of init function. */
void _init();
/** Internal implementation of createStack function. */
void* _createStack(tid_t i_task);
/** Internal implementation of deleteStack function. */
void _deleteStack(tid_t i_task);
StackSegment(const StackSegment&); // prohibit copy.
StackSegment& operator=(const StackSegment&); // prohibit assignment.
};
#endif
|