Print this page
9210 remove KMDB branch debugging support
9211 ::crregs could do with cr2/cr3 support
9209 ::ttrace should be able to filter by thread
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/intel/kdi/ia32/kdi_asm.s
          +++ new/usr/src/uts/intel/kdi/ia32/kdi_asm.s
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
       25 + *
       26 + * Copyright 2018 Joyent, Inc.
  25   27   */
  26   28  
  27      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  28      -
  29   29  /*
  30   30   * Debugger entry for both master and slave CPUs
  31   31   */
  32   32  
  33   33  #if defined(__lint)
  34   34  #include <sys/types.h>
  35   35  #endif
  36   36  
  37   37  #include <sys/segments.h>
  38   38  #include <sys/asm_linkage.h>
↓ open down ↓ 31 lines elided ↑ open up ↑
  70   70          cmpl    $kdi_idt, %edx;                 \
  71   71          je      1f;                             \
  72   72          movl    %edx, KRS_IDT(%eax);            \
  73   73          movl    %gs:CPU_GDT, %edx;              \
  74   74          movl    %edx, KRS_GDT(%eax);            \
  75   75  1:
  76   76  
  77   77  /*
  78   78   * Given the address of the current CPU's cpusave area in %edi, the following
  79   79   * macro restores the debugging state to said CPU.  Restored state includes
  80      - * the debug registers from the global %dr variables, and debugging MSRs from
  81      - * the CPU save area.  This code would be in a separate routine, but for the
  82      - * fact that some of the MSRs are jump-sensitive.  As such, we need to minimize
  83      - * the number of jumps taken subsequent to the update of said MSRs.  We can
  84      - * remove one jump (the ret) by using a macro instead of a function for the
  85      - * debugging state restoration code.
  86      - *
  87      - * Takes the cpusave area in %edi as a parameter, clobbers %eax-%edx
  88      - */     
       80 + * the debug registers from the global %dr variables.
       81 + */
  89   82  #define KDI_RESTORE_DEBUGGING_STATE \
  90   83          leal    kdi_drreg, %ebx;                                \
  91   84                                                                  \
  92   85          pushl   DR_CTL(%ebx);                                   \
  93   86          pushl   $7;                                             \
  94   87          call    kdi_dreg_set;                                   \
  95   88          addl    $8, %esp;                                       \
  96   89                                                                  \
  97   90          pushl   $KDIREG_DRSTAT_RESERVED;                                \
  98   91          pushl   $6;                                             \
↓ open down ↓ 11 lines elided ↑ open up ↑
 110  103          addl    $8, %esp;                                       \
 111  104                                                                  \
 112  105          pushl   DRADDR_OFF(2)(%ebx);                            \
 113  106          pushl   $2;                                             \
 114  107          call    kdi_dreg_set;                                   \
 115  108          addl    $8, %esp;                                       \
 116  109                                                                  \
 117  110          pushl   DRADDR_OFF(3)(%ebx);                            \
 118  111          pushl   $3;                                             \
 119  112          call    kdi_dreg_set;                                   \
 120      -        addl    $8, %esp;                                       \
 121      -                                                                \
 122      -        /*                                                      \
 123      -         * Write any requested MSRs.                            \
 124      -         */                                                     \
 125      -        movl    KRS_MSR(%edi), %ebx;                            \
 126      -        cmpl    $0, %ebx;                                       \
 127      -        je      3f;                                             \
 128      -1:                                                              \
 129      -        movl    MSR_NUM(%ebx), %ecx;                            \
 130      -        cmpl    $0, %ecx;                                       \
 131      -        je      3f;                                             \
 132      -                                                                \
 133      -        movl    MSR_TYPE(%ebx), %edx;                           \
 134      -        cmpl    $KDI_MSR_WRITE, %edx;                           \
 135      -        jne     2f;                                             \
 136      -                                                                \
 137      -        movl    MSR_VALP(%ebx), %edx;                           \
 138      -        movl    0(%edx), %eax;                                  \
 139      -        movl    4(%edx), %edx;                                  \
 140      -        wrmsr;                                                  \
 141      -2:                                                              \
 142      -        addl    $MSR_SIZE, %ebx;                                \
 143      -        jmp     1b;                                             \
 144      -3:                                                              \
 145      -        /*                                                      \
 146      -         * We must not branch after re-enabling LBR.  If        \
 147      -         * kdi_wsr_wrexit_msr is set, it contains the number    \
 148      -         * of the MSR that controls LBR.  kdi_wsr_wrexit_valp   \
 149      -         * contains the value that is to be written to enable   \
 150      -         * LBR.                                                 \
 151      -         */                                                     \
 152      -        movl    kdi_msr_wrexit_msr, %ecx;                       \
 153      -        cmpl    $0, %ecx;                                       \
 154      -        je      1f;                                             \
 155      -                                                                \
 156      -        movl    kdi_msr_wrexit_valp, %edx;                      \
 157      -        movl    0(%edx), %eax;                                  \
 158      -        movl    4(%edx), %edx;                                  \
 159      -                                                                \
 160      -        wrmsr;                                                  \
 161      -1:
      113 +        addl    $8, %esp;
 162  114  
 163  115  #define KDI_RESTORE_REGS() \
 164  116          /* Discard savfp and savpc */ \
 165  117          addl    $8, %esp; \
 166  118          popl    %ss; \
 167  119          popl    %gs; \
 168  120          popl    %fs; \
 169  121          popl    %es; \
 170  122          popl    %ds; \
 171  123          popal; \
↓ open down ↓ 195 lines elided ↑ open up ↑
 367  319   * The cross-call handler for slave CPUs.
 368  320   *
 369  321   * The debugger is single-threaded, so only one CPU, called the master, may be
 370  322   * running it at any given time.  The other CPUs, known as slaves, spin in a
 371  323   * busy loop until there's something for them to do.  This is the entry point
 372  324   * for the slaves - they'll be sent here in response to a cross-call sent by the
 373  325   * master.
 374  326   */
 375  327  
 376  328  #if defined(__lint)
 377      -char kdi_slave_entry_patch;
 378      -
 379  329  void
 380  330  kdi_slave_entry(void)
 381  331  {
 382  332  }
 383  333  #else /* __lint */
 384      -        .globl  kdi_slave_entry_patch;
 385      -
 386  334          ENTRY_NP(kdi_slave_entry)
 387  335  
 388      -        /* kdi_msr_add_clrentry knows where this is */
 389      -kdi_slave_entry_patch:
 390      -        KDI_MSR_PATCH;
 391      -
 392  336          /*
 393  337           * Cross calls are implemented as function calls, so our stack
 394  338           * currently looks like one you'd get from a zero-argument function
 395  339           * call. There's an %eip at %esp, and that's about it.  We want to
 396  340           * make it look like the master CPU's stack.  By doing this, we can
 397  341           * use the same resume code for both master and slave.  We need to
 398  342           * make our stack look like a `struct regs' before we jump into the
 399  343           * common save routine.
 400  344           */
 401  345  
↓ open down ↓ 133 lines elided ↑ open up ↑
 535  479          movl    %eax, KRS_DROFF(2)(%edi)
 536  480  
 537  481          pushl   $3
 538  482          call    kdi_dreg_get
 539  483          addl    $4, %esp
 540  484          movl    %eax, KRS_DROFF(3)(%edi)
 541  485  
 542  486          movl    %edi, %eax
 543  487          popl    %edi
 544  488  
 545      -        /*
 546      -         * Save any requested MSRs.
 547      -         */
 548      -        movl    KRS_MSR(%eax), %ecx
 549      -        cmpl    $0, %ecx
 550      -        je      no_msr
 551      -
 552      -        pushl   %eax            /* rdmsr clobbers %eax */
 553      -        movl    %ecx, %ebx
 554      -1:
 555      -        movl    MSR_NUM(%ebx), %ecx
 556      -        cmpl    $0, %ecx
 557      -        je      msr_done
 558      -
 559      -        movl    MSR_TYPE(%ebx), %edx
 560      -        cmpl    $KDI_MSR_READ, %edx
 561      -        jne     msr_next
 562      -
 563      -        rdmsr                   /* addr in %ecx, value into %edx:%eax */
 564      -        movl    %eax, MSR_VAL(%ebx)
 565      -        movl    %edx, _CONST(MSR_VAL + 4)(%ebx)
 566      -
 567      -msr_next:
 568      -        addl    $MSR_SIZE, %ebx
 569      -        jmp     1b
 570      -
 571      -msr_done:
 572      -        popl    %eax
 573      -
 574      -no_msr:
 575  489          clr     %ebp            /* stack traces should end here */
 576  490  
 577  491          pushl   %eax
 578  492          call    kdi_debugger_entry
 579  493          popl    %eax
 580      - 
      494 +
 581  495          jmp     kdi_resume
 582  496  
 583  497          SET_SIZE(kdi_save_common_state)
 584  498  
 585  499  #endif  /* !__lint */
 586  500  
 587  501  /*
 588  502   * Resume the world.  The code that calls kdi_resume has already
 589  503   * decided whether or not to restore the IDT.
 590  504   */
↓ open down ↓ 158 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX