1/*
2 * Copyright (C) 2013 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. 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 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27
28#if ENABLE(ASSEMBLER) && (CPU(X86) || CPU(X86_64))
29#include "MacroAssemblerX86Common.h"
30
31namespace JSC {
32
33#if USE(MASM_PROBE)
34
35void MacroAssemblerX86Common::ProbeContext::dumpCPURegisters(const char* indentation)
36{
37#if CPU(X86)
38    #define DUMP_GPREGISTER(_type, _regName) { \
39        int32_t value = reinterpret_cast<int32_t>(cpu._regName); \
40        dataLogF("%s    %6s: 0x%08x   %d\n", indentation, #_regName, value, value) ; \
41    }
42#elif CPU(X86_64)
43    #define DUMP_GPREGISTER(_type, _regName) { \
44        int64_t value = reinterpret_cast<int64_t>(cpu._regName); \
45        dataLogF("%s    %6s: 0x%016llx   %lld\n", indentation, #_regName, value, value) ; \
46    }
47#endif
48    FOR_EACH_CPU_GPREGISTER(DUMP_GPREGISTER)
49    FOR_EACH_CPU_SPECIAL_REGISTER(DUMP_GPREGISTER)
50    #undef DUMP_GPREGISTER
51
52    #define DUMP_FPREGISTER(_type, _regName) { \
53        uint32_t* u = reinterpret_cast<uint32_t*>(&cpu._regName); \
54        double* d = reinterpret_cast<double*>(&cpu._regName); \
55        dataLogF("%s    %6s: 0x%08x%08x 0x%08x%08x   %12g %12g\n", \
56            indentation, #_regName, u[3], u[2], u[1], u[0], d[1], d[0]); \
57    }
58    FOR_EACH_CPU_FPREGISTER(DUMP_FPREGISTER)
59    #undef DUMP_FPREGISTER
60}
61
62void MacroAssemblerX86Common::ProbeContext::dump(const char* indentation)
63{
64    if (!indentation)
65        indentation = "";
66
67    dataLogF("%sProbeContext %p {\n", indentation, this);
68    dataLogF("%s  probeFunction: %p\n", indentation, probeFunction);
69    dataLogF("%s  arg1: %p %llu\n", indentation, arg1, reinterpret_cast<int64_t>(arg1));
70    dataLogF("%s  arg2: %p %llu\n", indentation, arg2, reinterpret_cast<int64_t>(arg2));
71    dataLogF("%s  cpu: {\n", indentation);
72
73    dumpCPURegisters(indentation);
74
75    dataLogF("%s  }\n", indentation);
76    dataLogF("%s}\n", indentation);
77}
78
79#endif // USE(MASM_PROBE)
80
81} // namespace JSC
82
83#endif // ENABLE(ASSEMBLER) && (CPU(X86) || CPU(X86_64))
84