<commit_before>/////////////////////////////////////////////////////////////////////////
// $Id$
/////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2001  MandrakeSoft S.A.
//
//    MandrakeSoft S.A.
//    43, rue d'Aboukir
//    75002 Paris - France
//    http://www.linux-mandrake.com/
//    http://www.mandrakesoft.com/
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA


#define NEED_CPU_REG_SHORTCUTS 1
#include "bochs.h"
#define LOG_THIS BX_CPU_THIS_PTR


/* the device id and stepping id are loaded into DH & DL upon processor
   startup.  for device id: 3 = 80386, 4 = 80486.  just make up a
   number for the stepping (revision) id. */
#define BX_DEVICE_ID     3
#define BX_STEPPING_ID   0

BX_CPU_C::BX_CPU_C()
#if BX_SUPPORT_APIC
   : local_apic (this)
#endif
{
  // in case of SMF, you cannot reference any member data
  // in the constructor because the only access to it is via
  // global variables which aren't initialized quite yet.
  put("CPU");
  settype (CPU0LOG);
}


#if BX_WITH_WX

#define CASE_SEG_REG_GET(x) \
  case BXP_CPU_SEG_##x: \
    return BX_CPU_THIS_PTR sregs[BX_SEG_REG_##x].selector.value;
#define CASE_SEG_REG_SET(reg, val) \
  case BXP_CPU_SEG_##reg: \
    BX_CPU_THIS_PTR load_seg_reg (&BX_CPU_THIS_PTR sregs[BX_SEG_REG_##reg],val); \
    break;
#define CASE_LAZY_EFLAG_GET(flag) \
    case BXP_CPU_EFLAGS_##flag: \
      return BX_CPU_THIS_PTR get_##flag ();
#define CASE_LAZY_EFLAG_SET(flag, val) \
    case BXP_CPU_EFLAGS_##flag: \
      BX_CPU_THIS_PTR set_##flag(val); \
      break;
#define CASE_EFLAG_GET(flag) \
    case BXP_CPU_EFLAGS_##flag: \
      return BX_CPU_THIS_PTR get_##flag ();
#define CASE_EFLAG_SET(flag, val) \
    case BXP_CPU_EFLAGS_##flag: \
      BX_CPU_THIS_PTR set_##flag(val); \
      break;


// implement get/set handler for parameters that need unusual set/get
static Bit32s
cpu_param_handler (bx_param_c *param, int set, Bit32s val)
{
  bx_id id = param->get_id ();
  if (set) {
    switch (id) {
      CASE_SEG_REG_SET (CS, val);
      CASE_SEG_REG_SET (DS, val);
      CASE_SEG_REG_SET (SS, val);
      CASE_SEG_REG_SET (ES, val);
      CASE_SEG_REG_SET (FS, val);
      CASE_SEG_REG_SET (GS, val);
      case BXP_CPU_SEG_LDTR:
        BX_PANIC(("setting LDTR not implemented"));
	break;
      case BXP_CPU_SEG_TR:
        BX_PANIC(("setting TR not implemented"));
	break;
      CASE_LAZY_EFLAG_SET (OF, val);
      CASE_LAZY_EFLAG_SET (SF, val);
      CASE_LAZY_EFLAG_SET (ZF, val);
      CASE_LAZY_EFLAG_SET (AF, val);
      CASE_LAZY_EFLAG_SET (PF, val);
      CASE_LAZY_EFLAG_SET (CF, val);
      CASE_EFLAG_SET (ID,   val);
      //CASE_EFLAG_SET (VIP,  val);
      //CASE_EFLAG_SET (VIF,  val);
      CASE_EFLAG_SET (AC,   val);
      CASE_EFLAG_SET (VM,   val);
      CASE_EFLAG_SET (RF,   val);
      CASE_EFLAG_SET (NT,   val);
      CASE_EFLAG_SET (IOPL, val);
      CASE_EFLAG_SET (DF,   val);
      CASE_EFLAG_SET (IF,   val);
      CASE_EFLAG_SET (TF,   val);
      default:
        BX_PANIC (("cpu_param_handler set id %d not handled", id));
    }
  } else {
    switch (id) {
      CASE_SEG_REG_GET (CS);
      CASE_SEG_REG_GET (DS);
      CASE_SEG_REG_GET (SS);
      CASE_SEG_REG_GET (ES);
      CASE_SEG_REG_GET (FS);
      CASE_SEG_REG_GET (GS);
      case BXP_CPU_SEG_LDTR:
        return BX_CPU_THIS_PTR ldtr.selector.value;
        break;
      case BXP_CPU_SEG_TR:
        return BX_CPU_THIS_PTR tr.selector.value;
        break;
      CASE_LAZY_EFLAG_GET (OF);
      CASE_LAZY_EFLAG_GET (SF);
      CASE_LAZY_EFLAG_GET (ZF);
      CASE_LAZY_EFLAG_GET (AF);
      CASE_LAZY_EFLAG_GET (PF);
      CASE_LAZY_EFLAG_GET (CF);
      CASE_EFLAG_GET (ID);
      //CASE_EFLAG_GET (VIP);
      //CASE_EFLAG_GET (VIF);
      CASE_EFLAG_GET (AC);
      CASE_EFLAG_GET (VM);
      CASE_EFLAG_GET (RF);
      CASE_EFLAG_GET (NT);
      CASE_EFLAG_GET (IOPL);
      CASE_EFLAG_GET (DF);
      CASE_EFLAG_GET (IF);
      CASE_EFLAG_GET (TF);
      default:
        BX_PANIC (("cpu_param_handler get id %d ('%s') not handled", id, param->get_name ()));<commit_msg>- make cpu_param_handler compile with SMP enabled.  Unfortunately it will   read all param values from CPU #0.  The only solution I can come up with   is to change the siminterface handler function interface to pass a void*   to the callback function.  I'll take care of it eventually.<commit_after>/////////////////////////////////////////////////////////////////////////
// $Id$
/////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2001  MandrakeSoft S.A.
//
//    MandrakeSoft S.A.
//    43, rue d'Aboukir
//    75002 Paris - France
//    http://www.linux-mandrake.com/
//    http://www.mandrakesoft.com/
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA


#define NEED_CPU_REG_SHORTCUTS 1
#include "bochs.h"
#define LOG_THIS BX_CPU_THIS_PTR


/* the device id and stepping id are loaded into DH & DL upon processor
   startup.  for device id: 3 = 80386, 4 = 80486.  just make up a
   number for the stepping (revision) id. */
#define BX_DEVICE_ID     3
#define BX_STEPPING_ID   0

BX_CPU_C::BX_CPU_C()
#if BX_SUPPORT_APIC
   : local_apic (this)
#endif
{
  // in case of SMF, you cannot reference any member data
  // in the constructor because the only access to it is via
  // global variables which aren't initialized quite yet.
  put("CPU");
  settype (CPU0LOG);
}


#if BX_WITH_WX

#if BX_SMP_PROCESSORS!=1
#warning cpu_param_handler only supports parameters for one processor.
// To fix this, I think I will need to change bx_param_num_c::set_handler
// so that I pass in a void* data value.  The void* will be passed to each
// handler.  In this case, I would pass a pointer to the BX_CPU_C object
// in the void*, then in the handler I'd cast it back to BX_CPU_C and call
// BX_CPU_C::cpu_param_handler() which then could be a member function. -BBD
#endif

#define CASE_SEG_REG_GET(x) \
  case BXP_CPU_SEG_##x: \
    return BX_CPU(0)->sregs[BX_SEG_REG_##x].selector.value;
#define CASE_SEG_REG_SET(reg, val) \
  case BXP_CPU_SEG_##reg: \
    BX_CPU(0)->load_seg_reg (&BX_CPU(0)->sregs[BX_SEG_REG_##reg],val); \
    break;
#define CASE_LAZY_EFLAG_GET(flag) \
    case BXP_CPU_EFLAGS_##flag: \
      return BX_CPU(0)->get_##flag ();
#define CASE_LAZY_EFLAG_SET(flag, val) \
    case BXP_CPU_EFLAGS_##flag: \
      BX_CPU(0)->set_##flag(val); \
      break;
#define CASE_EFLAG_GET(flag) \
    case BXP_CPU_EFLAGS_##flag: \
      return BX_CPU(0)->get_##flag ();
#define CASE_EFLAG_SET(flag, val) \
    case BXP_CPU_EFLAGS_##flag: \
      BX_CPU(0)->set_##flag(val); \
      break;


// implement get/set handler for parameters that need unusual set/get
static Bit32s
cpu_param_handler (bx_param_c *param, int set, Bit32s val)
{
  bx_id id = param->get_id ();
  if (set) {
    switch (id) {
      CASE_SEG_REG_SET (CS, val);
      CASE_SEG_REG_SET (DS, val);
      CASE_SEG_REG_SET (SS, val);
      CASE_SEG_REG_SET (ES, val);
      CASE_SEG_REG_SET (FS, val);
      CASE_SEG_REG_SET (GS, val);
      case BXP_CPU_SEG_LDTR:
        BX_CPU(0)->panic("setting LDTR not implemented");
	break;
      case BXP_CPU_SEG_TR:
        BX_CPU(0)->panic ("setting TR not implemented");
	break;
      CASE_LAZY_EFLAG_SET (OF, val);
      CASE_LAZY_EFLAG_SET (SF, val);
      CASE_LAZY_EFLAG_SET (ZF, val);
      CASE_LAZY_EFLAG_SET (AF, val);
      CASE_LAZY_EFLAG_SET (PF, val);
      CASE_LAZY_EFLAG_SET (CF, val);
      CASE_EFLAG_SET (ID,   val);
      //CASE_EFLAG_SET (VIP,  val);
      //CASE_EFLAG_SET (VIF,  val);
      CASE_EFLAG_SET (AC,   val);
      CASE_EFLAG_SET (VM,   val);
      CASE_EFLAG_SET (RF,   val);
      CASE_EFLAG_SET (NT,   val);
      CASE_EFLAG_SET (IOPL, val);
      CASE_EFLAG_SET (DF,   val);
      CASE_EFLAG_SET (IF,   val);
      CASE_EFLAG_SET (TF,   val);
      default:
        BX_CPU(0)->panic ("cpu_param_handler set id %d not handled", id);
    }
  } else {
    switch (id) {
      CASE_SEG_REG_GET (CS);
      CASE_SEG_REG_GET (DS);
      CASE_SEG_REG_GET (SS);
      CASE_SEG_REG_GET (ES);
      CASE_SEG_REG_GET (FS);
      CASE_SEG_REG_GET (GS);
      case BXP_CPU_SEG_LDTR:
        return BX_CPU(0)->ldtr.selector.value;
        break;
      case BXP_CPU_SEG_TR:
        return BX_CPU(0)->tr.selector.value;
        break;
      CASE_LAZY_EFLAG_GET (OF);
      CASE_LAZY_EFLAG_GET (SF);
      CASE_LAZY_EFLAG_GET (ZF);
      CASE_LAZY_EFLAG_GET (AF);
      CASE_LAZY_EFLAG_GET (PF);
      CASE_LAZY_EFLAG_GET (CF);
      CASE_EFLAG_GET (ID);
      //CASE_EFLAG_GET (VIP);
      //CASE_EFLAG_GET (VIF);
      CASE_EFLAG_GET (AC);
      CASE_EFLAG_GET (VM);
      CASE_EFLAG_GET (RF);
      CASE_EFLAG_GET (NT);
      CASE_EFLAG_GET (IOPL);
      CASE_EFLAG_GET (DF);
      CASE_EFLAG_GET (IF);
      CASE_EFLAG_GET (TF);
      default:
        BX_CPU(0)->panic ("cpu_param_handler get id %d ('%s') not handled", id, param->get_name ());
{'fraction_non_alphanumeric': 0.13211026985051447, 'fraction_numerical': 0.01038633275092215, 'mean_word_length': 2.656139105748758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '166378', 'n_tokens_mistral': 3987, 'n_tokens_neox': 3751, 'n_words': 1021}