gem5  v20.1.0.0
atag.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __ARCH_ARM_LINUX_ATAG_HH__
39 #define __ARCH_ARM_LINUX_ATAG_HH__
40 
41 #include <cstring>
42 #include <string>
43 
44 #include "base/types.hh"
45 
46 enum {
47  CoreTag = 0x54410001,
48  MemTag = 0x54410002,
49  RevTag = 0x54410007,
50  SerialTag = 0x54410006,
51  CmdTag = 0x54410009,
52  NoneTag = 0x00000000
53 };
54 
56 {
57  protected:
58  uint32_t *storage;
59  uint32_t _size;
60 
61  public:
63  virtual uint32_t tag() = 0;
65  virtual bool null() { return false; }
66 
67  uint32_t size() const { return _size; }
68 
69  AtagHeader(uint32_t s)
70  : _size(s)
71  {
72  storage = new uint32_t[size()];
73  }
74 
75  virtual ~AtagHeader()
76  {
77  delete[] storage;
78  }
79 
80  uint32_t copyOut(uint8_t *p)
81  {
82  storage[0] = null() ? 0 : size();
83  storage[1] = tag();
84  memcpy(p, storage, size() << 2);
85  return size() << 2;
86  }
87 };
88 
89 class AtagCore : public AtagHeader
90 {
91  public:
92  static const uint32_t Size = 5;
93  uint32_t tag() { return CoreTag; }
94 
95  void flags(uint32_t i) { storage[2] = i; }
96  void pagesize(uint32_t i) { storage[3] = i; }
97  void rootdev(uint32_t i) { storage[4] = i; }
99  : AtagHeader(Size)
100  {}
101 };
102 
103 class AtagMem : public AtagHeader
104 {
105  public:
106  static const uint32_t Size = 4;
107  uint32_t tag() { return MemTag; }
108 
109  void memSize(uint32_t i) { storage[2] = i; }
110  void memStart(uint32_t i) { storage[3] = i; }
112  : AtagHeader(Size)
113  {}
114 };
115 
116 class AtagRev : public AtagHeader
117 {
118  public:
119  static const uint32_t Size = 3;
120  uint32_t tag() { return RevTag; }
121 
122  void rev(uint32_t i) { storage[2] = i; }
124  : AtagHeader(Size)
125  {}
126 };
127 
128 
129 class AtagSerial : public AtagHeader
130 {
131  public:
132  static const uint32_t Size = 4;
133  uint32_t tag() { return SerialTag; }
134 
135  void sn(uint64_t i) { storage[2] = (uint32_t)i; storage[3] = i >> 32; }
137  : AtagHeader(Size)
138  {}
139 };
140 
141 class AtagCmdline : public AtagHeader
142 {
143  public:
144  static const uint32_t Size = 3;
145  uint32_t tag() { return CmdTag; }
146 
147  void cmdline(const std::string &s)
148  {
149  // Add one for null terminator
150  int len = s.length() + 1;
151 
152  // 2 + ceiling(len/4)
153  _size = 2 + ((len + 3) >> 2);
154 
155  delete[] storage;
156  storage = new uint32_t[size()];
157  // Initialize the last byte of memory here beacuse it might be slightly
158  // longer than needed and mis-speculation of the NULL in the O3 CPU can
159  // change stats ever so slightly when that happens.
160  storage[size() - 1] = 0;
161  strcpy((char*)&storage[2] , s.c_str());
162  }
164  : AtagHeader(Size)
165  {}
166 };
167 
168 class AtagNone : public AtagHeader
169 {
170  public:
171  static const uint32_t Size = 2;
172  virtual bool null() { return true; }
173  uint32_t tag() { return NoneTag; }
175  : AtagHeader(Size)
176  {}
177 };
178 /*
179 //
180 // example ARM Linux bootloader code
181 // this example is distributed under the BSD licence
182 // Code taken from http://www.simtec.co.uk/products/SWLINUX/files/booting_article.html
184 
185 // list of possible tags
186 #define ATAG_NONE 0x00000000
187 #define ATAG_CORE 0x54410001
188 #define ATAG_MEM 0x54410002
189 #define ATAG_VIDEOTEXT 0x54410003
190 #define ATAG_RAMDISK 0x54410004
191 #define ATAG_INITRD2 0x54420005
192 #define ATAG_SERIAL 0x54410006
193 #define ATAG_REVISION 0x54410007
194 #define ATAG_VIDEOLFB 0x54410008
195 #define ATAG_CMDLINE 0x54410009
196 
197 // structures for each atag
198 struct atag_header {
199  u32 size; // length of tag in words including this header
200  u32 tag; // tag type
201 };
202 
203 struct atag_core {
204  u32 flags;
205  u32 pagesize;
206  u32 rootdev;
207 };
208 
209 struct atag_mem {
210  u32 size;
211  u32 start;
212 };
213 
214 struct atag_videotext {
215  u8 x;
216  u8 y;
217  u16 video_page;
218  u8 video_mode;
219  u8 video_cols;
220  u16 video_ega_bx;
221  u8 video_lines;
222  u8 video_isvga;
223  u16 video_points;
224 };
225 
226 struct atag_ramdisk {
227  u32 flags;
228  u32 size;
229  u32 start;
230 };
231 
232 struct atag_initrd2 {
233  u32 start;
234  u32 size;
235 };
236 
237 struct atag_serialnr {
238  u32 low;
239  u32 high;
240 };
241 
242 struct atag_revision {
243  u32 rev;
244 };
245 
246 struct atag_videolfb {
247  u16 lfb_width;
248  u16 lfb_height;
249  u16 lfb_depth;
250  u16 lfb_linelength;
251  u32 lfb_base;
252  u32 lfb_size;
253  u8 red_size;
254  u8 red_pos;
255  u8 green_size;
256  u8 green_pos;
257  u8 blue_size;
258  u8 blue_pos;
259  u8 rsvd_size;
260  u8 rsvd_pos;
261 };
262 
263 struct atag_cmdline {
264  char cmdline[1];
265 };
266 
267 struct atag {
268  struct atag_header hdr;
269  union {
270  struct atag_core core;
271  struct atag_mem mem;
272  struct atag_videotext videotext;
273  struct atag_ramdisk ramdisk;
274  struct atag_initrd2 initrd2;
275  struct atag_serialnr serialnr;
276  struct atag_revision revision;
277  struct atag_videolfb videolfb;
278  struct atag_cmdline cmdline;
279  } u;
280 };
281 */
282 
283 
284 #endif // __ARCH_ARM_LINUX_ATAG_HH__
SerialTag
@ SerialTag
Definition: atag.hh:50
AtagSerial::Size
static const uint32_t Size
Definition: atag.hh:132
AtagHeader::tag
virtual uint32_t tag()=0
Tag (normally starts with 'T''A' and 16 bits of number.
AtagCore::AtagCore
AtagCore()
Definition: atag.hh:98
AtagHeader::copyOut
uint32_t copyOut(uint8_t *p)
Definition: atag.hh:80
AtagHeader::_size
uint32_t _size
Definition: atag.hh:59
AtagSerial::sn
void sn(uint64_t i)
Definition: atag.hh:135
AtagCore::flags
void flags(uint32_t i)
Definition: atag.hh:95
AtagNone::Size
static const uint32_t Size
Definition: atag.hh:171
CoreTag
@ CoreTag
Definition: atag.hh:47
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
AtagHeader::~AtagHeader
virtual ~AtagHeader()
Definition: atag.hh:75
RevTag
@ RevTag
Definition: atag.hh:49
AtagMem::Size
static const uint32_t Size
Definition: atag.hh:106
AtagHeader::AtagHeader
AtagHeader(uint32_t s)
Definition: atag.hh:69
AtagSerial::AtagSerial
AtagSerial()
Definition: atag.hh:136
AtagMem
Definition: atag.hh:103
AtagRev
Definition: atag.hh:116
AtagCore::pagesize
void pagesize(uint32_t i)
Definition: atag.hh:96
AtagSerial::tag
uint32_t tag()
Tag (normally starts with 'T''A' and 16 bits of number.
Definition: atag.hh:133
AtagNone
Definition: atag.hh:168
AtagCmdline::tag
uint32_t tag()
Tag (normally starts with 'T''A' and 16 bits of number.
Definition: atag.hh:145
AtagNone::tag
uint32_t tag()
Tag (normally starts with 'T''A' and 16 bits of number.
Definition: atag.hh:173
AtagCmdline
Definition: atag.hh:141
AtagMem::memStart
void memStart(uint32_t i)
Definition: atag.hh:110
AtagHeader::storage
uint32_t * storage
Definition: atag.hh:58
AtagMem::AtagMem
AtagMem()
Definition: atag.hh:111
AtagRev::Size
static const uint32_t Size
Definition: atag.hh:119
AtagRev::AtagRev
AtagRev()
Definition: atag.hh:123
AtagHeader
Definition: atag.hh:55
AtagMem::memSize
void memSize(uint32_t i)
Definition: atag.hh:109
AtagCmdline::AtagCmdline
AtagCmdline()
Definition: atag.hh:163
AtagNone::AtagNone
AtagNone()
Definition: atag.hh:174
AtagCmdline::cmdline
void cmdline(const std::string &s)
Definition: atag.hh:147
AtagCmdline::Size
static const uint32_t Size
Definition: atag.hh:144
AtagCore::Size
static const uint32_t Size
Definition: atag.hh:92
types.hh
AtagCore
Definition: atag.hh:89
CmdTag
@ CmdTag
Definition: atag.hh:51
ArmISA::len
Bitfield< 18, 16 > len
Definition: miscregs_types.hh:439
AtagSerial
Definition: atag.hh:129
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
AtagRev::tag
uint32_t tag()
Tag (normally starts with 'T''A' and 16 bits of number.
Definition: atag.hh:120
MemTag
@ MemTag
Definition: atag.hh:48
AtagCore::rootdev
void rootdev(uint32_t i)
Definition: atag.hh:97
NoneTag
@ NoneTag
Definition: atag.hh:52
AtagCore::tag
uint32_t tag()
Tag (normally starts with 'T''A' and 16 bits of number.
Definition: atag.hh:93
AtagHeader::size
uint32_t size() const
Definition: atag.hh:67
AtagMem::tag
uint32_t tag()
Tag (normally starts with 'T''A' and 16 bits of number.
Definition: atag.hh:107
AtagRev::rev
void rev(uint32_t i)
Definition: atag.hh:122

Generated on Wed Sep 30 2020 14:02:00 for gem5 by doxygen 1.8.17