Print this page
9723 provide support for VMM's GDT handling
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>


1273         CPU->cpu_idt = idt0;
1274 
1275 #if defined(__i386)
1276         /*
1277          * We maintain a description of idt0 in convenient IDTR format
1278          * for #pf's on some older pentium processors. See pentium_pftrap().
1279          */
1280         idt0_default_r = idtr;
1281 #endif  /* __i386 */
1282 
1283         init_tss();
1284         CPU->cpu_tss = ktss0;
1285         init_ldt();
1286 
1287         /* Stash this so that the NMI,MCE,#DF and KDI handlers can use it. */
1288         kpti_safe_cr3 = (uint64_t)getcr3();
1289 }
1290 
1291 #endif  /* __xpv */
1292 

1293 /*





















1294  * In the early kernel, we need to set up a simple GDT to run on.
1295  *
1296  * XXPV Can dboot use this too?  See dboot_gdt.s
1297  */
1298 void
1299 init_boot_gdt(user_desc_t *bgdt)
1300 {
1301 #if defined(__amd64)
1302         set_usegd(&bgdt[GDT_B32DATA], SDP_LONG, NULL, -1, SDT_MEMRWA, SEL_KPL,
1303             SDP_PAGES, SDP_OP32);
1304         set_usegd(&bgdt[GDT_B64CODE], SDP_LONG, NULL, -1, SDT_MEMERA, SEL_KPL,
1305             SDP_PAGES, SDP_OP32);
1306 #elif defined(__i386)
1307         set_usegd(&bgdt[GDT_B32DATA], NULL, -1, SDT_MEMRWA, SEL_KPL,
1308             SDP_PAGES, SDP_OP32);
1309         set_usegd(&bgdt[GDT_B32CODE], NULL, -1, SDT_MEMERA, SEL_KPL,
1310             SDP_PAGES, SDP_OP32);
1311 #endif  /* __i386 */
1312 }
1313 




1273         CPU->cpu_idt = idt0;
1274 
1275 #if defined(__i386)
1276         /*
1277          * We maintain a description of idt0 in convenient IDTR format
1278          * for #pf's on some older pentium processors. See pentium_pftrap().
1279          */
1280         idt0_default_r = idtr;
1281 #endif  /* __i386 */
1282 
1283         init_tss();
1284         CPU->cpu_tss = ktss0;
1285         init_ldt();
1286 
1287         /* Stash this so that the NMI,MCE,#DF and KDI handlers can use it. */
1288         kpti_safe_cr3 = (uint64_t)getcr3();
1289 }
1290 
1291 #endif  /* __xpv */
1292 
1293 #ifndef __xpv
1294 /*
1295  * As per Intel Vol 3 27.5.2, the GDTR limit is reset to 64Kb on a VM exit, so
1296  * we have to manually fix it up ourselves.
1297  *
1298  * The caller may still need to make sure that it can't go off-CPU with the
1299  * incorrect limit, before calling this (such as disabling pre-emption).
1300  */
1301 void
1302 reset_gdtr_limit(void)
1303 {
1304         ulong_t flags = intr_clear();
1305         desctbr_t gdtr;
1306 
1307         rd_gdtr(&gdtr);
1308         gdtr.dtr_limit = (sizeof (user_desc_t) * NGDT) - 1;
1309         wr_gdtr(&gdtr);
1310 
1311         intr_restore(flags);
1312 }
1313 #endif /* __xpv */
1314 
1315 /*
1316  * In the early kernel, we need to set up a simple GDT to run on.
1317  *
1318  * XXPV Can dboot use this too?  See dboot_gdt.s
1319  */
1320 void
1321 init_boot_gdt(user_desc_t *bgdt)
1322 {
1323 #if defined(__amd64)
1324         set_usegd(&bgdt[GDT_B32DATA], SDP_LONG, NULL, -1, SDT_MEMRWA, SEL_KPL,
1325             SDP_PAGES, SDP_OP32);
1326         set_usegd(&bgdt[GDT_B64CODE], SDP_LONG, NULL, -1, SDT_MEMERA, SEL_KPL,
1327             SDP_PAGES, SDP_OP32);
1328 #elif defined(__i386)
1329         set_usegd(&bgdt[GDT_B32DATA], NULL, -1, SDT_MEMRWA, SEL_KPL,
1330             SDP_PAGES, SDP_OP32);
1331         set_usegd(&bgdt[GDT_B32CODE], NULL, -1, SDT_MEMERA, SEL_KPL,
1332             SDP_PAGES, SDP_OP32);
1333 #endif  /* __i386 */
1334 }
1335