2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "kern/linux/printk.hh"
31 #include <sys/types.h>
37 #include "cpu/thread_context.hh"
38 #include "mem/port_proxy.hh"
44 printk(std::string
&str
, ThreadContext
*tc
, Addr format_ptr
,
48 std::ostringstream out
;
49 tc
->getVirtProxy().readString(format
, format_ptr
);
51 const char *p
= format
.c_str();
58 bool leftjustify
= false;
62 while (more
&& *++p
) {
81 if (*p
>= '1' && *p
<= '9')
82 width
= 10 * width
+ *p
- '0';
132 out
.setf(std::ios::showbase
);
150 if (leftjustify
&& !zero
)
151 out
.setf(std::ios::left
);
155 out
<< args
.get
<int64_t>();
157 out
<< args
.get
<int32_t>();
160 out
<< args
.get
<uint64_t>();
162 out
<< args
.get
<uint32_t>();
176 Addr s_ptr
= args
.get
<Addr
>();
179 tc
->getVirtProxy().readString(s
, s_ptr
);
186 out
.setf(std::ios::left
);
193 uint64_t mask
= (*p
== 'C') ? 0xffL
: 0x7fL
;
198 num
= args
.get
<uint64_t>();
199 cwidth
= sizeof(uint64_t);
201 num
= args
.get
<uint32_t>();
202 cwidth
= sizeof(uint32_t);
205 while (cwidth
-- > 0) {
206 char c
= (char)(num
& mask
);
214 uint64_t n
= args
.get
<uint64_t>();
215 Addr s_ptr
= args
.get
<Addr
>();
217 tc
->getVirtProxy().readString(s
, s_ptr
);
218 out
<< s
<< ": " << n
;
239 size_t len
= strcspn(p
, "%\n\r\0");