t=UTF-8 Content-Disposition: inline; filename="bf281b3cad1d05c6ef863fa179d3d6ab442a163c..56bd36c5ef3960874628bc08cbfcedf4c6057a19.patch" Last-Modified: Mon, 05 May 2025 10:03:50 GMT Expires: Thu, 03 May 2035 10:03:50 GMT From 56bd36c5ef3960874628bc08cbfcedf4c6057a19 Mon Sep 17 00:00:00 2001 From: "therealmogminer@gmail.com" Date: Wed, 8 Jun 2016 08:10:55 +1000 Subject: Major refactoring of debugger core [Ryan Holtz] * Eliminate globals/file statics * Remove lots of stuff from global scope * Use std::function for custom command registration * Eliminate some trampolines * Build fixes from Vas Crabb and balr0g --- src/mame/machine/xbox.cpp | 380 ++++++++++++++++++++++++---------------------- 1 file changed, 196 insertions(+), 184 deletions(-) (limited to 'src/mame/machine/xbox.cpp') diff --git a/src/mame/machine/xbox.cpp b/src/mame/machine/xbox.cpp index 99993ec79c5..7479aec05a2 100644 --- a/src/mame/machine/xbox.cpp +++ b/src/mame/machine/xbox.cpp @@ -1,6 +1,8 @@ // license:BSD-3-Clause // copyright-holders:Samuele Zannoli +#include + #include "emu.h" #include "cpu/i386/i386.h" #include "machine/lpci.h" @@ -9,6 +11,7 @@ #include "machine/idectrl.h" #include "video/poly.h" #include "bitmap.h" +#include "debugger.h" #include "debug/debugcon.h" #include "debug/debugcmd.h" #include "debug/debugcpu.h" @@ -20,109 +23,113 @@ //#define LOG_OHCI #define USB_HACK_ENABLED -static void dump_string_command(running_machine &machine, int ref, int params, const char **param) +void xbox_base_state::dump_string_command(int ref, int params, const char **param) { - xbox_base_state *state = machine.driver_data(); - address_space &space = state->m_maincpu->space(); - UINT64 addr; - offs_t address; - UINT32 length, maximumlength; - offs_t buffer; + address_space &space = m_maincpu->space(); if (params < 1) return; - if (!debug_command_parameter_number(machine, param[0], &addr)) + + UINT64 addr; + if (!machine().debugger().commands().validate_number_parameter(param[0], &addr)) return; - address = (offs_t)addr; - if (!debug_cpu_translate(space, TRANSLATE_READ_DEBUG, &address)) + + offs_t address = (offs_t)addr; + if (!machine().debugger().cpu().translate(space, TRANSLATE_READ_DEBUG, &address)) { - debug_console_printf(machine, "Address is unmapped.\n"); + machine().debugger().console().printf("Address is unmapped.\n"); return; } - length = space.read_word_unaligned(address); - maximumlength = space.read_word_unaligned(address + 2); - buffer = space.read_dword_unaligned(address + 4); - debug_console_printf(machine, "Length %d word\n", length); - debug_console_printf(machine, "MaximumLength %d word\n", maximumlength); - debug_console_printf(machine, "Buffer %08X byte* ", buffer); - if (!debug_cpu_translate(space, TRANSLATE_READ_DEBUG, &buffer)) + + UINT32 length = space.read_word_unaligned(address); + UINT32 maximumlength = space.read_word_unaligned(address + 2); + offs_t buffer = space.read_dword_unaligned(address + 4); + machine().debugger().console().printf("Length %d word\n", length); + machine().debugger().console().printf("MaximumLength %d word\n", maximumlength); + machine().debugger().console().printf("Buffer %08X byte* ", buffer); + if (!machine().debugger().cpu().translate(space, TRANSLATE_READ_DEBUG, &buffer)) { - debug_console_printf(machine, "\nBuffer is unmapped.\n"); + machine().debugger().console().printf("\nBuffer is unmapped.\n"); return; } + if (length > 256) length = 256; + for (int a = 0; a < length; a++) { UINT8 c = space.read_byte(buffer + a); - debug_console_printf(machine, "%c", c); + machine().debugger().console().printf("%c", c); } - debug_console_printf(machine, "\n"); + machine().debugger().console().printf("\n"); } -static void dump_process_command(running_machine &machine, int ref, int params, const char **param) +void xbox_base_state::dump_process_command(int ref, int params, const char **param) { - xbox_base_state *state = machine.driver_data(); - address_space &space = state->m_maincpu->space(); - UINT64 addr; - offs_t address; + address_space &space = m_maincpu->space(); if (params < 1) return; - if (!debug_command_parameter_number(machine, param[0], &addr)) + + UINT64 addr; + if (!machine().debugger().commands().validate_number_parameter(param[0], &addr)) return; - address = (offs_t)addr; - if (!debug_cpu_translate(space, TRANSLATE_READ_DEBUG, &address)) + + offs_t address = (offs_t)addr; + if (!machine().debugger().cpu().translate(space, TRANSLATE_READ_DEBUG, &address)) { - debug_console_printf(machine, "Address is unmapped.\n"); + machine().debugger().console().printf("Address is unmapped.\n"); return; } - debug_console_printf(machine, "ReadyListHead {%08X,%08X} _LIST_ENTRY\n", space.read_dword_unaligned(address), space.read_dword_unaligned(address + 4)); - debug_console_printf(machine, "ThreadListHead {%08X,%08X} _LIST_ENTRY\n", space.read_dword_unaligned(address + 8), space.read_dword_unaligned(address + 12)); - debug_console_printf(machine, "StackCount %d dword\n", space.read_dword_unaligned(address + 16)); - debug_console_printf(machine, "ThreadQuantum %d dword\n", space.read_dword_unaligned(address + 20)); - debug_console_printf(machine, "BasePriority %d byte\n", space.read_byte(address + 24)); - debug_console_printf(machine, "DisableBoost %d byte\n", space.read_byte(address + 25)); - debug_console_printf(machine, "DisableQuantum %d byte\n", space.read_byte(address + 26)); - debug_console_printf(machine, "_padding %d byte\n", space.read_byte(address + 27)); + machine().debugger().console().printf("ReadyListHead {%08X,%08X} _LIST_ENTRY\n", space.read_dword_unaligned(address), space.read_dword_unaligned(address + 4)); + machine().debugger().console().printf("ThreadListHead {%08X,%08X} _LIST_ENTRY\n", space.read_dword_unaligned(address + 8), space.read_dword_unaligned(address + 12)); + machine().debugger().console().printf("StackCount %d dword\n", space.read_dword_unaligned(address + 16)); + machine().debugger().console().printf("ThreadQuantum %d dword\n", space.read_dword_unaligned(address + 20)); + machine().debugger().console().printf("BasePriority %d byte\n", space.read_byte(address + 24)); + machine().debugger().console().printf("DisableBoost %d byte\n", space.read_byte(address + 25)); + machine().debugger().console().printf("DisableQuantum %d byte\n", space.read_byte(address + 26)); + machine().debugger().console().printf("_padding %d byte\n", space.read_byte(address + 27)); } -static void dump_list_command(running_machine &machine, int ref, int params, const char **param) +void xbox_base_state::dump_list_command(int ref, int params, const char **param) { - xbox_base_state *state = machine.driver_data(); - address_space &space = state->m_maincpu->space(); - UINT64 addr, offs, start, old; - offs_t address, offset; + address_space &space = m_maincpu->space(); if (params < 1) return; - if (!debug_command_parameter_number(machine, param[0], &addr)) + + UINT64 addr; + if (!machine().debugger().commands().validate_number_parameter(param[0], &addr)) return; - offs = 0; - offset = 0; + + UINT64 offs = 0; + offs_t offset = 0; if (params >= 2) { - if (!debug_command_parameter_number(machine, param[1], &offs)) + if (!machine().debugger().commands().validate_number_parameter(param[1], &offs)) return; offset = (offs_t)offs; } - start = addr; - address = (offs_t)addr; - if (!debug_cpu_translate(space, TRANSLATE_READ_DEBUG, &address)) + + UINT64 start = addr; + offs_t address = (offs_t)addr; + if (!machine().debugger().cpu().translate(space, TRANSLATE_READ_DEBUG, &address)) { - debug_console_printf(machine, "Address is unmapped.\n"); + machine().debugger().console().printf("Address is unmapped.\n"); return; } if (params >= 2) - debug_console_printf(machine, "Entry Object\n"); + machine().debugger().console().printf("Entry Object\n"); else - debug_console_printf(machine, "Entry\n"); + machine().debugger().console().printf("Entry\n"); + + UINT64 old; for (int num = 0; num < 32; num++) { if (params >= 2) - debug_console_printf(machine, "%08X %08X\n", (UINT32)addr, (offs_t)addr - offset); + machine().debugger().console().printf("%08X %08X\n", (UINT32)addr, (offs_t)addr - offset); else - debug_console_printf(machine, "%08X\n", (UINT32)addr); + machine().debugger().console().printf("%08X\n", (UINT32)addr); old = addr; addr = space.read_dword_unaligned(address); if (addr == start) @@ -130,159 +137,151 @@ static void dump_list_command(running_machine &machine, int ref, int params, con if (addr == old) break; address = (offs_t)addr; - if (!debug_cpu_translate(space, TRANSLATE_READ_DEBUG, &address)) + if (!machine().debugger().cpu().translate(space, TRANSLATE_READ_DEBUG, &address)) break; } } -static void dump_dpc_command(running_machine &machine, int ref, int params, const char **param) +void xbox_base_state::dump_dpc_command(int ref, int params, const char **param) { - xbox_base_state *state = machine.driver_data(); - address_space &space = state->m_maincpu->space(); - UINT64 addr; - offs_t address; + address_space &space = m_maincpu->space(); if (params < 1) return; - if (!debug_command_parameter_number(machine, param[0], &addr)) + + UINT64 addr; + if (!machine().debugger().commands().validate_number_parameter(param[0], &addr)) return; - address = (offs_t)addr; - if (!debug_cpu_translate(space, TRANSLATE_READ_DEBUG, &address)) + + offs_t address = (offs_t)addr; + if (!machine().debugger().cpu().translate(space, TRANSLATE_READ_DEBUG, &address)) { - debug_console_printf(machine, "Address is unmapped.\n"); + machine().debugger().console().printf("Address is unmapped.\n"); return; } - debug_console_printf(machine, "Type %d word\n", space.read_word_unaligned(address)); - debug_console_printf(machine, "Inserted %d byte\n", space.read_byte(address + 2)); - debug_console_printf(machine, "Padding %d byte\n", space.read_byte(address + 3)); - debug_console_printf(machine, "DpcListEntry {%08X,%08X} _LIST_ENTRY\n", space.read_dword_unaligned(address + 4), space.read_dword_unaligned(address + 8)); - debug_console_printf(machine, "DeferredRoutine %08X dword\n", space.read_dword_unaligned(address + 12)); - debug_console_printf(machine, "DeferredContext %08X dword\n", space.read_dword_unaligned(address + 16)); - debug_console_printf(machine, "SystemArgument1 %08X dword\n", space.read_dword_unaligned(address + 20)); - debug_console_printf(machine, "SystemArgument2 %08X dword\n", space.read_dword_unaligned(address + 24)); + machine().debugger().console().printf("Type %d word\n", space.read_word_unaligned(address)); + machine().debugger().console().printf("Inserted %d byte\n", space.read_byte(address + 2)); + machine().debugger().console().printf("Padding %d byte\n", space.read_byte(address + 3)); + machine().debugger().console().printf("DpcListEntry {%08X,%08X} _LIST_ENTRY\n", space.read_dword_unaligned(address + 4), space.read_dword_unaligned(address + 8)); + machine().debugger().console().printf("DeferredRoutine %08X dword\n", space.read_dword_unaligned(address + 12)); + machine().debugger().console().printf("DeferredContext %08X dword\n", space.read_dword_unaligned(address + 16)); + machine().debugger().console().printf("SystemArgument1 %08X dword\n", space.read_dword_unaligned(address + 20)); + machine().debugger().console().printf("SystemArgument2 %08X dword\n", space.read_dword_unaligned(address + 24)); } -static void dump_timer_command(running_machine &machine, int ref, int params, const char **param) +void xbox_base_state::dump_timer_command(int ref, int params
//
// transmit_file.cpp
// ~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#include <ctime>
#include <functional>
#include <iostream>
#include <memory>
#include <string>
#include "asio.hpp"

#if defined(ASIO_HAS_WINDOWS_OVERLAPPED_PTR)

using asio::ip::tcp;
using asio::windows::overlapped_ptr;
using asio::windows::random_access_handle;

typedef asio::basic_stream_socket<tcp,
    asio::io_context::executor_type> tcp_socket;

typedef asio::basic_socket_acceptor<tcp,
    asio::io_context::executor_type> tcp_acceptor;

// A wrapper for the TransmitFile overlapped I/O operation.
template <typename Handler>
void transmit_file(tcp_socket& socket,
    random_access_handle& file, Handler handler)
{
  // Construct an OVERLAPPED-derived object to contain the handler.
  overlapped_ptr overlapped(socket.get_executor().context(), handler);

  // Initiate the TransmitFile operation.
  BOOL ok = ::TransmitFile(socket.native_handle(),
      file.native_handle(), 0, 0, overlapped.get(), 0, 0);
  DWORD last_error = ::GetLastError();

  // Check if the operation completed immediately.
  if (!ok && last_error != ERROR_IO_PENDING)
  {
    // The operation completed immediately, so a completion notification needs
    // to be posted. When complete() is called, ownership of the OVERLAPPED-
    // derived object passes to the io_context.
    std::error_code ec(last_error,
        asio::error::get_system_category());
    overlapped.complete(ec, 0);
  }
  else
  {
    // The operation was successfully initiated, so ownership of the
    // OVERLAPPED-derived object has passed to the io_context.
    overlapped.release();
  }
}

class connection
  : public std::enable_shared_from_this<connection>
{
public:
  typedef std::shared_ptr<connection> pointer;

  static pointer create(asio::io_context& io_context,
      const std::string& filename)
  {
    return pointer(new connection(io_context, filename));
  }

  tcp_socket& socket()
  {
    return socket_;
  }

  void start()
  {
    std::error_code ec;
    file_.assign(::CreateFile(filename_.c_str(), GENERIC_READ, 0, 0,
          OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 0), ec);
    if (file_.is_open())
    {
      transmit_file(socket_, file_,
          std::bind(&connection::handle_write, shared_from_this(),
            asio::placeholders::error,
            asio::placeholders::bytes_transferred));
    }
  }

private:
  connection(asio::io_context& io_context, const std::string& filename)
    : socket_(io_context),
      filename_(filename),
      file_(io_context)
  {
  }

  void handle_write(const std::error_code& /*error*/,
      size_t /*bytes_transferred*/)
  {
    std::error_code ignored_ec;
    socket_.shutdown(tcp_socket::shutdown_both, ignored_ec);
  }

  tcp_socket socket_;
  std::string filename_;
  random_access_handle file_;
};

class server
{
public:
  server(asio::io_context& io_context,
      unsigned short port, const std::string& filename)
    : acceptor_(io_context, tcp::endpoint(tcp::v4(), port)),
      filename_(filename)
  {
    start_accept();
  }

private:
  void start_accept()
  {
    connection::pointer new_connection =
      connection::create(acceptor_.get_executor().context(), filename_);

    acceptor_.async_accept(new_connection->socket(),
        std::bind(&server::handle_accept, this, new_connection,
          asio::placeholders::error));
  }

  void handle_accept(connection::pointer new_connection,
      const std::error_code& error)
  {
    if (!error)
    {
      new_connection->start();
    }

    start_accept();
  }

  tcp_acceptor acceptor_;
  std::string filename_;
};

int main(int argc, char* argv[])
{
  try
  {
    if (argc != 3)
    {
      std::cerr << "Usage: transmit_file <port> <filename>\n";
      return 1;
    }

    asio::io_context io_context;

    using namespace std; // For atoi.
    server s(io_context, atoi(argv[1]), argv[2]);

    io_context.run();
  }
  catch (std::exception& e)
  {
    std::cerr << e.what() << std::endl;
  }

  return 0;
}

#else // defined(ASIO_HAS_WINDOWS_OVERLAPPED_PTR)
# error Overlapped I/O not available on this platform
#endif // defined(ASIO_HAS_WINDOWS_OVERLAPPED_PTR)