The Pedigree Project  0.1
ppc32/StackFrame.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/processor/StackFrame.h"
21 #include "pedigree/kernel/Log.h"
22 
23 #if defined(DEBUGGER)
24 
25 uintptr_t PPC32StackFrame::getParameter(size_t n)
26 {
27  if (n == 0)
28  return m_State.m_R3;
29  if (n == 1)
30  return m_State.m_R4;
31  if (n == 2)
32  return m_State.m_R5;
33  if (n == 3)
34  return m_State.m_R6;
35  if (n == 4)
36  return m_State.m_R7;
37  if (n == 5)
38  return m_State.m_R8;
39  if (n == 6)
40  return m_State.m_R9;
41  if (n == 7)
42  return m_State.m_R10;
43 
44  // Slightly difficult - have to follow the back chain pointer then
45  // go up 2 words to skip the next back chain and the saved LR.
46  WARNING("PPC32StackFrame: More than 8 parameters not implemented yet.");
47  // uint64_t *pPtr = reinterpret_cast<uint64_t*>(m_State.m_R1 + (n - 8) *
48  // sizeof(uint64_t)); return *pPtr;
49  return 0;
50 }
51 
52 #endif
53 
54 void PPC32StackFrame::construct(
55  ProcessorState &state, uintptr_t returnAddress, unsigned int nParams, ...)
56 {
57  state.m_Lr = returnAddress;
58 
59  va_list list;
60  va_start(list, nParams);
61 
62  for (unsigned int i = 0; i < nParams; i++)
63  {
64  uintptr_t arg = va_arg(list, uintptr_t);
65  NOTICE("Setting " << Hex << i << ", " << arg);
66  switch (i)
67  {
68  case 0:
69  state.m_R3 = arg;
70  break;
71  case 1:
72  state.m_R4 = arg;
73  break;
74  case 2:
75  state.m_R5 = arg;
76  break;
77  case 3:
78  state.m_R6 = arg;
79  break;
80  case 4:
81  state.m_R7 = arg;
82  break;
83  case 5:
84  state.m_R8 = arg;
85  break;
86  default:
87  ERROR("StackFrame: Too many parameters");
88  }
89  }
90 
91  va_end(list);
92 }
virtual uintptr_t getParameter(size_t n)
const ProcessorState & m_State
#define WARNING(text)
Definition: Log.h:78
#define NOTICE(text)
Definition: Log.h:74
Definition: Log.h:136
#define ERROR(text)
Definition: Log.h:82