$OpenBSD: patch-cpu_protect_ctrl_cc,v 1.2 2001/03/30 18:53:25 todd Exp $
--- cpu/protect_ctrl.cc.orig	Sat Mar 25 21:39:09 2000
+++ cpu/protect_ctrl.cc	Fri Mar 30 11:26:13 2001
@@ -35,7 +35,7 @@
 BX_CPU_C::ARPL_EwGw(BxInstruction_t *i)
 {
 #if BX_CPU_LEVEL < 2
-  bx_panic("ARPL_EwRw: not supported on 8086!\n");
+  bio->panic("ARPL_EwRw: not supported on 8086!\n");
 #else /* 286+ */
 
   Bit16u op2_16, op1_16;
@@ -98,10 +98,10 @@ BX_CPU_C::LAR_GvEw(BxInstruction_t *i)
   Bit32u dword1, dword2;
 
 
-  if (v8086_mode()) bx_panic("protect_ctrl: v8086 mode unsupported\n");
+  if (v8086_mode()) bio->panic("protect_ctrl: v8086 mode unsupported\n");
 
   if (real_mode()) {
-    bx_panic("LAR_GvEw: not recognized in real mode\n");
+    bio->panic("LAR_GvEw: not recognized in real mode\n");
     UndefinedOpcode(i);
     return;
     }
@@ -133,7 +133,7 @@ BX_CPU_C::LAR_GvEw(BxInstruction_t *i)
 
   if (descriptor.valid==0) {
     set_ZF(0);
-    //bx_printf("lar(): descriptor valid bit cleared\n");
+    //bio->printd("[CPU%u] lar(): descriptor valid bit cleared\n", BX_SIM_ID);
     return;
     }
 
@@ -177,7 +177,8 @@ BX_CPU_C::LAR_GvEw(BxInstruction_t *i)
         break;
       default: /* rest not accepted types to LAR */
         set_ZF(0);
-        bx_printf("lar(): not accepted type\n");
+		if(bio->getdbg().cpu)
+        bio->printd("[CPU%u] lar(): not accepted type\n", BX_SIM_ID);
         return;
         break;
       }
@@ -209,11 +210,11 @@ BX_CPU_C::LSL_GvEw(BxInstruction_t *i)
   Bit32u dword1, dword2;
   Bit32u descriptor_dpl;
 
-  if (v8086_mode()) bx_panic("protect_ctrl: v8086 mode unsupported\n");
+  if (v8086_mode()) bio->panic("protect_ctrl: v8086 mode unsupported\n");
 
 
   if (real_mode()) {
-    bx_panic("LSL_GvEw: not recognized in real mode\n");
+    bio->panic("LSL_GvEw: not recognized in real mode\n");
     UndefinedOpcode(i);
     return;
     }
@@ -300,13 +301,13 @@ lsl_ok:
 BX_CPU_C::SLDT_Ew(BxInstruction_t *i)
 {
 #if BX_CPU_LEVEL < 2
-  bx_panic("SLDT_Ew: not supported on 8086!\n");
+  bio->panic("SLDT_Ew: not supported on 8086!\n");
 #else
-  if (v8086_mode()) bx_panic("protect_ctrl: v8086 mode unsupported\n");
+  if (v8086_mode()) bio->panic("protect_ctrl: v8086 mode unsupported\n");
 
   if (real_mode()) {
     /* not recognized in real address mode */
-    bx_panic("SLDT_Ew: encountered in real mode.\n");
+    bio->panic("SLDT_Ew: encountered in real mode.\n");
     UndefinedOpcode(i);
     }
   else {
@@ -326,11 +327,11 @@ BX_CPU_C::SLDT_Ew(BxInstruction_t *i)
   void
 BX_CPU_C::STR_Ew(BxInstruction_t *i)
 {
-  if (v8086_mode()) bx_panic("protect_ctrl: v8086 mode unsupported\n");
+  if (v8086_mode()) bio->panic("protect_ctrl: v8086 mode unsupported\n");
 
   if (real_mode()) {
     // not recognized in real address mode
-    bx_panic("STR_Ew: encountered in real mode.\n");
+    bio->panic("STR_Ew: encountered in real mode.\n");
     UndefinedOpcode(i);
     }
   else {
@@ -350,14 +351,14 @@ BX_CPU_C::STR_Ew(BxInstruction_t *i)
 BX_CPU_C::LLDT_Ew(BxInstruction_t *i)
 {
 #if BX_CPU_LEVEL < 2
-  bx_panic("LLDT_Ew: not supported on 8086!\n");
+  bio->panic("LLDT_Ew: not supported on 8086!\n");
 #else
-  if (v8086_mode()) bx_panic("protect_ctrl: v8086 mode unsupported\n");
+  if (v8086_mode()) bio->panic("protect_ctrl: v8086 mode unsupported\n");
 
   invalidate_prefetch_q();
 
   if (real_mode()) {
-    bx_panic("lldt: not recognized in real mode\n");
+    bio->panic("lldt: not recognized in real mode\n");
     UndefinedOpcode(i);
     return;
     }
@@ -370,7 +371,7 @@ BX_CPU_C::LLDT_Ew(BxInstruction_t *i)
 
     /* #GP(0) if the current privilege level is not 0 */
     if (CPL != 0) {
-      bx_panic("LLDT: CPL != 0\n");
+      bio->panic("LLDT: CPL != 0\n");
       exception(BX_GP_EXCEPTION, 0, 0);
       return;
       }
@@ -394,12 +395,13 @@ BX_CPU_C::LLDT_Ew(BxInstruction_t *i)
 
     // #GP(selector) if the selector operand does not point into GDT
     if (selector.ti != 0) {
-      bx_printf("LLDT: selector.ti != 0\n");
+		if(bio->getdbg().cpu)
+      bio->printd("[CPU%u] LLDT: selector.ti != 0\n", BX_SIM_ID);
       exception(BX_GP_EXCEPTION, raw_selector & 0xfffc, 0);
       }
 
     if ((selector.index*8 + 7) > BX_CPU_THIS_PTR gdtr.limit) {
-      bx_panic("lldt: GDT: index > limit\n");
+      bio->panic("lldt: GDT: index > limit\n");
       exception(BX_GP_EXCEPTION, raw_selector & 0xfffc, 0);
       return;
       }
@@ -415,18 +417,20 @@ BX_CPU_C::LLDT_Ew(BxInstruction_t *i)
     if ( (descriptor.valid==0) ||
         descriptor.segment  ||
         (descriptor.type!=2) ) {
-      bx_printf("lldt: doesn't point to an LDT descriptor!\n");
+		if(bio->getdbg().cpu)
+      bio->printd("[CPU%u] lldt: doesn't point to an LDT descriptor!\n", BX_SIM_ID);
       exception(BX_GP_EXCEPTION, raw_selector & 0xfffc, 0);
       }
 
     /* #NP(selector) if LDT descriptor is not present */
     if (descriptor.p==0) {
-      bx_printf("lldt: LDT descriptor not present!\n");
+		if(bio->getdbg().cpu)
+      bio->printd("[CPU%u] lldt: LDT descriptor not present!\n", BX_SIM_ID);
       exception(BX_NP_EXCEPTION, raw_selector & 0xfffc, 0);
       }
 
     if (descriptor.u.ldt.limit < 7) {
-      bx_printf("lldt: ldtr.limit < 7\n");
+      bio->printd("[CPU%u] lldt: ldtr.limit < 7\n", BX_SIM_ID);
       }
 
     BX_CPU_THIS_PTR ldtr.selector = selector;
@@ -442,9 +446,9 @@ BX_CPU_C::LLDT_Ew(BxInstruction_t *i)
 BX_CPU_C::LTR_Ew(BxInstruction_t *i)
 {
 #if BX_CPU_LEVEL < 2
-  bx_panic("LTR_Ew: not supported on 8086!\n");
+  bio->panic("LTR_Ew: not supported on 8086!\n");
 #else
-  if (v8086_mode()) bx_panic("protect_ctrl: v8086 mode unsupported\n");
+  if (v8086_mode()) bio->panic("protect_ctrl: v8086 mode unsupported\n");
 
 
   invalidate_prefetch_q();
@@ -458,7 +462,7 @@ BX_CPU_C::LTR_Ew(BxInstruction_t *i)
 
     /* #GP(0) if the current privilege level is not 0 */
     if (CPL != 0) {
-      bx_panic("LTR: CPL != 0\n");
+      bio->panic("LTR: CPL != 0\n");
       exception(BX_GP_EXCEPTION, 0, 0);
       return;
       }
@@ -472,7 +476,7 @@ BX_CPU_C::LTR_Ew(BxInstruction_t *i)
 
     /* if selector is NULL, invalidate and done */
     if ((raw_selector & 0xfffc) == 0) {
-      bx_panic("ltr: loading with NULL selector!\n");
+      bio->panic("ltr: loading with NULL selector!\n");
       /* if this is OK, then invalidate and load selector & descriptor cache */
       /* load here */
       BX_CPU_THIS_PTR tr.selector.value = raw_selector;
@@ -484,7 +488,7 @@ BX_CPU_C::LTR_Ew(BxInstruction_t *i)
     parse_selector(raw_selector, &selector);
 
     if (selector.ti) {
-      bx_panic("ltr: selector.ti != 0\n");
+      bio->panic("ltr: selector.ti != 0\n");
       return;
       }
 
@@ -496,23 +500,23 @@ BX_CPU_C::LTR_Ew(BxInstruction_t *i)
     /* #GP(selector) if object is not a TSS or is already busy */
     if ( (descriptor.valid==0) || descriptor.segment  ||
          (descriptor.type!=1 && descriptor.type!=9) ) {
-      bx_panic("ltr: doesn't point to an available TSS descriptor!\n");
+      bio->panic("ltr: doesn't point to an available TSS descriptor!\n");
       exception(BX_GP_EXCEPTION, raw_selector & 0xfffc, 0); /* 0 ??? */
       return;
       }
 
     /* #NP(selector) if TSS descriptor is not present */
     if (descriptor.p==0) {
-      bx_panic("ltr: LDT descriptor not present!\n");
+      bio->panic("ltr: LDT descriptor not present!\n");
       exception(BX_NP_EXCEPTION, raw_selector & 0xfffc, 0); /* 0 ??? */
       return;
       }
 
     if (descriptor.type==1 && descriptor.u.tss286.limit<43) {
-      bx_panic("ltr:286TSS: loading tr.limit < 43\n");
+      bio->panic("ltr:286TSS: loading tr.limit < 43\n");
       }
     else if (descriptor.type==9 && descriptor.u.tss386.limit_scaled<103) {
-      bx_panic("ltr:386TSS: loading tr.limit < 103\n");
+      bio->panic("ltr:386TSS: loading tr.limit < 103\n");
       }
 
     BX_CPU_THIS_PTR tr.selector = selector;
@@ -527,7 +531,7 @@ BX_CPU_C::LTR_Ew(BxInstruction_t *i)
     return;
     }
   else {
-    bx_panic("ltr_ew: not recognized in real-mode!\n");
+    bio->panic("ltr_ew: not recognized in real-mode!\n");
     UndefinedOpcode(i);
     return;
     }
@@ -543,11 +547,11 @@ BX_CPU_C::VERR_Ew(BxInstruction_t *i)
   bx_selector_t   selector;
   Bit32u dword1, dword2;
 
-  if (v8086_mode()) bx_panic("protect_ctrl: v8086 mode unsupported\n");
+  if (v8086_mode()) bio->panic("protect_ctrl: v8086 mode unsupported\n");
 
 
   if (real_mode()) {
-    bx_panic("VERR_Ew: not recognized in real mode\n");
+    bio->panic("VERR_Ew: not recognized in real mode\n");
     UndefinedOpcode(i);
     return;
     }
@@ -563,7 +567,8 @@ BX_CPU_C::VERR_Ew(BxInstruction_t *i)
   /* if selector null, clear ZF and done */
   if ( (raw_selector & 0xfffc) == 0 ) {
     set_ZF(0);
-    bx_printf("VERR: null selector\n");
+		if(bio->getdbg().cpu)
+    bio->printd("[CPU%u] VERR: null selector\n", BX_SIM_ID);
     return;
     }
 
@@ -575,7 +580,8 @@ BX_CPU_C::VERR_Ew(BxInstruction_t *i)
   if ( !fetch_raw_descriptor2(&selector, &dword1, &dword2) ) {
     /* not within descriptor table */
     set_ZF(0);
-    bx_printf("VERR: not in table\n");
+		if(bio->getdbg().cpu)
+    bio->printd("[CPU%u] VERR: not in table\n", BX_SIM_ID);
     return;
     }
 
@@ -583,13 +589,15 @@ BX_CPU_C::VERR_Ew(BxInstruction_t *i)
 
   if ( descriptor.segment==0 ) { /* system or gate descriptor */
     set_ZF(0); /* inaccessible */
-    bx_printf("VERR: system descriptor\n");
+		if(bio->getdbg().cpu)
+    bio->printd("[CPU%u] VERR: system descriptor\n", BX_SIM_ID);
     return;
     }
 
   if ( descriptor.valid==0 ) {
     set_ZF(0);
-    bx_printf("VERR: valid bit cleared\n");
+		if(bio->getdbg().cpu)
+    bio->printd("[CPU%u] VERR: valid bit cleared\n", BX_SIM_ID);
     return;
     }
 
@@ -599,32 +607,38 @@ BX_CPU_C::VERR_Ew(BxInstruction_t *i)
     if ( descriptor.u.segment.c_ed &&
          descriptor.u.segment.r_w) {
       set_ZF(1); /* accessible */
-      bx_printf("VERR: conforming code, OK\n");
+		if(bio->getdbg().cpu)
+      bio->printd("[CPU%u] VERR: conforming code, OK\n", BX_SIM_ID);
       return;
       }
     if ( descriptor.u.segment.r_w==0 ) {
       set_ZF(0); /* inaccessible */
-      bx_printf("VERR: code not readable\n");
+		if(bio->getdbg().cpu)
+      bio->printd("[CPU%u] VERR: code not readable\n", BX_SIM_ID);
       return;
       }
     /* readable, non-conforming code segment */
     if ( (descriptor.dpl<CPL) || (descriptor.dpl<selector.rpl) ) {
       set_ZF(0); /* inaccessible */
-      bx_printf("VERR: non-coforming code not withing priv level\n");
+		if(bio->getdbg().cpu)
+      bio->printd("[CPU%u] VERR: non-coforming code not withing priv level\n", BX_SIM_ID);
       return;
       }
     set_ZF(1); /* accessible */
-    bx_printf("VERR: code seg readable\n");
+		if(bio->getdbg().cpu)
+    bio->printd("[CPU%u] VERR: code seg readable\n", BX_SIM_ID);
     return;
     }
   else { /* data segment */
     if ( (descriptor.dpl<CPL) || (descriptor.dpl<selector.rpl) ) {
       set_ZF(0); /* not accessible */
-      bx_printf("VERR: data seg not withing priv level\n");
+		if(bio->getdbg().cpu)
+      bio->printd("[CPU%u] VERR: data seg not withing priv level\n", BX_SIM_ID);
       return;
       }
     set_ZF(1); /* accessible */
-    bx_printf("VERR: data segment OK\n");
+		if(bio->getdbg().cpu)
+    bio->printd("[CPU%u] VERR: data segment OK\n", BX_SIM_ID);
     return;
     }
 }
@@ -638,11 +652,11 @@ BX_CPU_C::VERW_Ew(BxInstruction_t *i)
   bx_selector_t   selector;
   Bit32u dword1, dword2;
 
-  if (v8086_mode()) bx_panic("protect_ctrl: v8086 mode unsupported\n");
+  if (v8086_mode()) bio->panic("protect_ctrl: v8086 mode unsupported\n");
 
 
   if (real_mode()) {
-    bx_panic("VERW_Ew: not recognized in real mode\n");
+    bio->panic("VERW_Ew: not recognized in real mode\n");
     UndefinedOpcode(i);
     return;
     }
@@ -658,7 +672,8 @@ BX_CPU_C::VERW_Ew(BxInstruction_t *i)
   /* if selector null, clear ZF and done */
   if ( (raw_selector & 0xfffc) == 0 ) {
     set_ZF(0);
-    bx_printf("VERW: null selector\n");
+		if(bio->getdbg().cpu)
+    bio->printd("[CPU%u] VERW: null selector\n", BX_SIM_ID);
     return;
     }
 
@@ -670,7 +685,8 @@ BX_CPU_C::VERW_Ew(BxInstruction_t *i)
   if ( !fetch_raw_descriptor2(&selector, &dword1, &dword2) ) {
     /* not within descriptor table */
     set_ZF(0);
-    bx_printf("VERW: not in table\n");
+		if(bio->getdbg().cpu)
+    bio->printd("[CPU%u] VERW: not in table\n", BX_SIM_ID);
     return;
     }
 
@@ -679,13 +695,15 @@ BX_CPU_C::VERW_Ew(BxInstruction_t *i)
   /* rule out system segments & code segments */
   if ( descriptor.segment==0 || descriptor.u.segment.executable ) {
     set_ZF(0);
-    bx_printf("VERW: system seg or code\n");
+		if(bio->getdbg().cpu)
+    bio->printd("[CPU%u] VERW: system seg or code\n", BX_SIM_ID);
     return;
     }
 
   if ( descriptor.valid==0 ) {
     set_ZF(0);
-    bx_printf("VERW: valid bit cleared\n");
+		if(bio->getdbg().cpu)
+    bio->printd("[CPU%u] VERW: valid bit cleared\n", BX_SIM_ID);
     return;
     }
 
@@ -693,16 +711,17 @@ BX_CPU_C::VERW_Ew(BxInstruction_t *i)
   if ( descriptor.u.segment.r_w ) { /* writable */
     if ( (descriptor.dpl<CPL) || (descriptor.dpl<selector.rpl) ) {
       set_ZF(0); /* not accessible */
-      bx_printf("VERW: writable data seg not within priv level\n");
+		if(bio->getdbg().cpu)
+      bio->printd("[CPU%u] VERW: writable data seg not within priv level\n", BX_SIM_ID);
       return;
       }
     set_ZF(1); /* accessible */
-    bx_printf("VERW: data seg writable\n");
+    bio->printd("[CPU%u] VERW: data seg writable\n", BX_SIM_ID);
     return;
     }
 
   set_ZF(0); /* not accessible */
-  bx_printf("VERW: data seg not writable\n");
+  bio->printd("[CPU%u] VERW: data seg not writable\n", BX_SIM_ID);
   return;
 }
 
@@ -710,18 +729,18 @@ BX_CPU_C::VERW_Ew(BxInstruction_t *i)
 BX_CPU_C::SGDT_Ms(BxInstruction_t *i)
 {
 #if BX_CPU_LEVEL < 2
-  bx_panic("SGDT_Ms: not supported on 8086!\n");
+  bio->panic("SGDT_Ms: not supported on 8086!\n");
 #else
   Bit16u limit_16;
   Bit32u base_32;
 
-  if (v8086_mode()) bx_panic("protect_ctrl: v8086 mode unsupported\n");
+  if (v8086_mode()) bio->panic("protect_ctrl: v8086 mode unsupported\n");
 
 
   /* op1 is a register or memory reference */
   if (i->mod == 0xc0) {
     /* undefined opcode exception */
-    bx_panic("SGDT_Ms: use of register is undefined opcode.\n");
+    bio->panic("SGDT_Ms: use of register is undefined opcode.\n");
     UndefinedOpcode(i);
     return;
     }
@@ -744,17 +763,17 @@ BX_CPU_C::SGDT_Ms(BxInstruction_t *i)
 BX_CPU_C::SIDT_Ms(BxInstruction_t *i)
 {
 #if BX_CPU_LEVEL < 2
-  bx_panic("SIDT_Ms: not supported on 8086!\n");
+  bio->panic("SIDT_Ms: not supported on 8086!\n");
 #else
   Bit16u limit_16;
   Bit32u base_32;
 
-  if (v8086_mode()) bx_panic("protect_ctrl: v8086 mode unsupported\n");
+  if (v8086_mode()) bio->panic("protect_ctrl: v8086 mode unsupported\n");
 
   /* op1 is a register or memory reference */
   if (i->mod == 0xc0) {
     /* undefined opcode exception */
-    bx_panic("SIDT: use of register is undefined opcode.\n");
+    bio->panic("SIDT: use of register is undefined opcode.\n");
     UndefinedOpcode(i);
     return;
     }
@@ -779,22 +798,22 @@ BX_CPU_C::SIDT_Ms(BxInstruction_t *i)
 BX_CPU_C::LGDT_Ms(BxInstruction_t *i)
 {
 #if BX_CPU_LEVEL < 2
-  bx_panic("LGDT_Ms: not supported on 8086!\n");
+  bio->panic("LGDT_Ms: not supported on 8086!\n");
 #else
 
-  if (v8086_mode()) bx_panic("protect_ctrl: v8086 mode unsupported\n");
+  if (v8086_mode()) bio->panic("protect_ctrl: v8086 mode unsupported\n");
 
   invalidate_prefetch_q();
 
   if (protected_mode() && (CPL!=0)) {
-    bx_panic("LGDT: protected mode: CPL!=0\n");
+    bio->panic("LGDT: protected mode: CPL!=0\n");
     exception(BX_GP_EXCEPTION, 0, 0);
     return;
     }
 
   /* op1 is a register or memory reference */
   if (i->mod == 0xc0) {
-    bx_panic("LGDT generating exception 6\n");
+    bio->panic("LGDT generating exception 6\n");
     UndefinedOpcode(i);
     return;
     }
@@ -835,19 +854,19 @@ BX_CPU_C::LGDT_Ms(BxInstruction_t *i)
 BX_CPU_C::LIDT_Ms(BxInstruction_t *i)
 {
 #if BX_CPU_LEVEL < 2
-  bx_panic("LIDT_Ms: not supported on 8086!\n");
+  bio->panic("LIDT_Ms: not supported on 8086!\n");
 #else
   Bit16u limit_16;
   Bit32u base_32;
 
 
-  if (v8086_mode()) bx_panic("protect_ctrl: v8086 mode unsupported\n");
+  if (v8086_mode()) bio->panic("protect_ctrl: v8086 mode unsupported\n");
 
   invalidate_prefetch_q();
 
   if (protected_mode()) {
     if (CPL != 0) {
-      bx_panic("LIDT(): CPL(%u) != 0\n", (unsigned) CPL);
+      bio->panic("LIDT(): CPL(%u) != 0\n", (unsigned) CPL);
       exception(BX_GP_EXCEPTION, 0, 0);
       return;
       }
@@ -856,7 +875,7 @@ BX_CPU_C::LIDT_Ms(BxInstruction_t *i)
   /* op1 is a register or memory reference */
   if (i->mod == 0xc0) {
     /* undefined opcode exception */
-    bx_panic("LIDT generating exception 6\n");
+    bio->panic("LIDT generating exception 6\n");
     UndefinedOpcode(i);
     return;
     }
