14120Sgblack@eecs.umich.edu/*
211274Sshingarov@labware.com * Copyright 2015 LabWare
310600Sgabeblack@google.com * Copyright 2014 Google, Inc.
44120Sgblack@eecs.umich.edu * Copyright (c) 2007 The Hewlett-Packard Development Company
54120Sgblack@eecs.umich.edu * All rights reserved.
64120Sgblack@eecs.umich.edu *
77087Snate@binkert.org * The license below extends only to copyright in the software and shall
87087Snate@binkert.org * not be construed as granting a license to any other intellectual
97087Snate@binkert.org * property including but not limited to intellectual property relating
107087Snate@binkert.org * to a hardware implementation of the functionality of the software
117087Snate@binkert.org * licensed hereunder.  You may use the software subject to the license
127087Snate@binkert.org * terms below provided that you ensure that this notice is replicated
137087Snate@binkert.org * unmodified and in its entirety in all distributions of the software,
147087Snate@binkert.org * modified or unmodified, in source code or in binary form.
154120Sgblack@eecs.umich.edu *
167087Snate@binkert.org * Redistribution and use in source and binary forms, with or without
177087Snate@binkert.org * modification, are permitted provided that the following conditions are
187087Snate@binkert.org * met: redistributions of source code must retain the above copyright
197087Snate@binkert.org * notice, this list of conditions and the following disclaimer;
207087Snate@binkert.org * redistributions in binary form must reproduce the above copyright
217087Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
227087Snate@binkert.org * documentation and/or other materials provided with the distribution;
237087Snate@binkert.org * neither the name of the copyright holders nor the names of its
244120Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
257087Snate@binkert.org * this software without specific prior written permission.
264120Sgblack@eecs.umich.edu *
274120Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
284120Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
294120Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
304120Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
314120Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
324120Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
334120Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
344120Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
354120Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
364120Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
374120Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
384120Sgblack@eecs.umich.edu *
394120Sgblack@eecs.umich.edu * Authors: Gabe Black
4011274Sshingarov@labware.com *          Boris Shingarov
414120Sgblack@eecs.umich.edu */
424120Sgblack@eecs.umich.edu
434120Sgblack@eecs.umich.edu#ifndef __ARCH_X86_REMOTEGDB_HH__
444120Sgblack@eecs.umich.edu#define __ARCH_X86_REMOTEGDB_HH__
454120Sgblack@eecs.umich.edu
4610600Sgabeblack@google.com#include <algorithm>
4710600Sgabeblack@google.com
484144Sgblack@eecs.umich.edu#include "arch/x86/types.hh"
494144Sgblack@eecs.umich.edu#include "base/remote_gdb.hh"
504144Sgblack@eecs.umich.edu
514144Sgblack@eecs.umich.educlass System;
524144Sgblack@eecs.umich.educlass ThreadContext;
534120Sgblack@eecs.umich.edu
544120Sgblack@eecs.umich.edunamespace X86ISA
554120Sgblack@eecs.umich.edu{
5610600Sgabeblack@google.comclass RemoteGDB : public BaseRemoteGDB
5710600Sgabeblack@google.com{
5811274Sshingarov@labware.com  protected:
5911274Sshingarov@labware.com    bool acc(Addr addr, size_t len);
6011274Sshingarov@labware.com    bool checkBpLen(size_t len) { return len == 1; }
6111274Sshingarov@labware.com    class X86GdbRegCache : public BaseGdbRegCache
6210600Sgabeblack@google.com    {
6311274Sshingarov@labware.com      using BaseGdbRegCache::BaseGdbRegCache;
6411274Sshingarov@labware.com      private:
6511274Sshingarov@labware.com        struct {
6611274Sshingarov@labware.com          uint32_t eax;
6711274Sshingarov@labware.com          uint32_t ecx;
6811274Sshingarov@labware.com          uint32_t edx;
6911274Sshingarov@labware.com          uint32_t ebx;
7011274Sshingarov@labware.com          uint32_t esp;
7111274Sshingarov@labware.com          uint32_t ebp;
7211274Sshingarov@labware.com          uint32_t esi;
7311274Sshingarov@labware.com          uint32_t edi;
7411274Sshingarov@labware.com          uint32_t eip;
7511274Sshingarov@labware.com          uint32_t eflags;
7611274Sshingarov@labware.com          uint32_t cs;
7711274Sshingarov@labware.com          uint32_t ss;
7811274Sshingarov@labware.com          uint32_t ds;
7911274Sshingarov@labware.com          uint32_t es;
8011274Sshingarov@labware.com          uint32_t fs;
8111274Sshingarov@labware.com          uint32_t gs;
8211274Sshingarov@labware.com        } r;
8311274Sshingarov@labware.com      public:
8411274Sshingarov@labware.com        char *data() const { return (char *)&r; }
8511274Sshingarov@labware.com        size_t size() const { return sizeof(r); }
8611274Sshingarov@labware.com        void getRegs(ThreadContext*);
8711274Sshingarov@labware.com        void setRegs(ThreadContext*) const;
8812031Sgabeblack@google.com        const std::string
8912031Sgabeblack@google.com        name() const
9012031Sgabeblack@google.com        {
9112031Sgabeblack@google.com            return gdb->name() + ".X86GdbRegCache";
9212031Sgabeblack@google.com        }
9310600Sgabeblack@google.com    };
9410600Sgabeblack@google.com
9511274Sshingarov@labware.com    class AMD64GdbRegCache : public BaseGdbRegCache
9610600Sgabeblack@google.com    {
9711274Sshingarov@labware.com      using BaseGdbRegCache::BaseGdbRegCache;
9811274Sshingarov@labware.com      private:
9912073Smatthiashille8@gmail.com        struct M5_ATTR_PACKED {
10011274Sshingarov@labware.com          uint64_t rax;
10111274Sshingarov@labware.com          uint64_t rbx;
10211274Sshingarov@labware.com          uint64_t rcx;
10311274Sshingarov@labware.com          uint64_t rdx;
10411274Sshingarov@labware.com          uint64_t rsi;
10511274Sshingarov@labware.com          uint64_t rdi;
10611274Sshingarov@labware.com          uint64_t rbp;
10711274Sshingarov@labware.com          uint64_t rsp;
10811274Sshingarov@labware.com          uint64_t r8;
10911274Sshingarov@labware.com          uint64_t r9;
11011274Sshingarov@labware.com          uint64_t r10;
11111274Sshingarov@labware.com          uint64_t r11;
11211274Sshingarov@labware.com          uint64_t r12;
11311274Sshingarov@labware.com          uint64_t r13;
11411274Sshingarov@labware.com          uint64_t r14;
11511274Sshingarov@labware.com          uint64_t r15;
11611274Sshingarov@labware.com          uint64_t rip;
11711274Sshingarov@labware.com          uint32_t eflags;
11811274Sshingarov@labware.com          uint32_t cs;
11911274Sshingarov@labware.com          uint32_t ss;
12011274Sshingarov@labware.com          uint32_t ds;
12111274Sshingarov@labware.com          uint32_t es;
12211274Sshingarov@labware.com          uint32_t fs;
12311274Sshingarov@labware.com          uint32_t gs;
12411274Sshingarov@labware.com          /*
12511274Sshingarov@labware.com           * We do not model st[], FPU status regs, xmm[] etc.
12611274Sshingarov@labware.com           * While it's not ok to have G-packets larger than what gdb
12711274Sshingarov@labware.com           * knows about, it is ok to have smaller ones.
12811274Sshingarov@labware.com           */
12911274Sshingarov@labware.com        } r;
13011274Sshingarov@labware.com      public:
13111274Sshingarov@labware.com        char *data() const { return (char *)&r; }
13211274Sshingarov@labware.com        size_t size() const { return sizeof(r); }
13311274Sshingarov@labware.com        void getRegs(ThreadContext*);
13411274Sshingarov@labware.com        void setRegs(ThreadContext*) const;
13512031Sgabeblack@google.com        const std::string
13612031Sgabeblack@google.com        name() const
13712031Sgabeblack@google.com        {
13812031Sgabeblack@google.com            return gdb->name() + ".AMD64GdbRegCache";
13912031Sgabeblack@google.com        }
14010600Sgabeblack@google.com    };
14110600Sgabeblack@google.com
14212031Sgabeblack@google.com    X86GdbRegCache regCache32;
14312031Sgabeblack@google.com    AMD64GdbRegCache regCache64;
14412031Sgabeblack@google.com
14511274Sshingarov@labware.com  public:
14612449Sgabeblack@google.com    RemoteGDB(System *system, ThreadContext *context, int _port);
14711274Sshingarov@labware.com    BaseGdbRegCache *gdbRegs();
14810600Sgabeblack@google.com};
14911274Sshingarov@labware.com} // namespace X86ISA
1504120Sgblack@eecs.umich.edu
1514120Sgblack@eecs.umich.edu#endif // __ARCH_X86_REMOTEGDB_HH__
152