17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _IA32_SYS_PRIVREGS_H 287c478bd9Sstevel@tonic-gate #define _IA32_SYS_PRIVREGS_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #ifdef __cplusplus 337c478bd9Sstevel@tonic-gate extern "C" { 347c478bd9Sstevel@tonic-gate #endif 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate /* 377c478bd9Sstevel@tonic-gate * This file describes the cpu's privileged register set, and 387c478bd9Sstevel@tonic-gate * how the machine state is saved on the stack when a trap occurs. 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #if !defined(__i386) 427c478bd9Sstevel@tonic-gate #error "non-i386 code depends on i386 privileged header!" 437c478bd9Sstevel@tonic-gate #endif 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #ifndef _ASM 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* 487c478bd9Sstevel@tonic-gate * This is NOT the structure to use for general purpose debugging; 497c478bd9Sstevel@tonic-gate * see /proc for that. This is NOT the structure to use to decode 507c478bd9Sstevel@tonic-gate * the ucontext or grovel about in a core file; see <sys/regset.h>. 517c478bd9Sstevel@tonic-gate */ 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate struct regs { 547c478bd9Sstevel@tonic-gate /* 557c478bd9Sstevel@tonic-gate * Extra frame for mdb to follow through high level interrupts and 567c478bd9Sstevel@tonic-gate * system traps. Set them to 0 to terminate stacktrace. 577c478bd9Sstevel@tonic-gate */ 587c478bd9Sstevel@tonic-gate greg_t r_savfp; /* a copy of %ebp */ 597c478bd9Sstevel@tonic-gate greg_t r_savpc; /* a copy of %eip */ 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate greg_t r_gs; 627c478bd9Sstevel@tonic-gate greg_t r_fs; 637c478bd9Sstevel@tonic-gate greg_t r_es; 647c478bd9Sstevel@tonic-gate greg_t r_ds; 657c478bd9Sstevel@tonic-gate greg_t r_edi; 667c478bd9Sstevel@tonic-gate greg_t r_esi; 677c478bd9Sstevel@tonic-gate greg_t r_ebp; 687c478bd9Sstevel@tonic-gate greg_t r_esp; 697c478bd9Sstevel@tonic-gate greg_t r_ebx; 707c478bd9Sstevel@tonic-gate greg_t r_edx; 717c478bd9Sstevel@tonic-gate greg_t r_ecx; 727c478bd9Sstevel@tonic-gate greg_t r_eax; 737c478bd9Sstevel@tonic-gate greg_t r_trapno; 747c478bd9Sstevel@tonic-gate greg_t r_err; 757c478bd9Sstevel@tonic-gate greg_t r_eip; 767c478bd9Sstevel@tonic-gate greg_t r_cs; 777c478bd9Sstevel@tonic-gate greg_t r_efl; 787c478bd9Sstevel@tonic-gate greg_t r_uesp; 797c478bd9Sstevel@tonic-gate greg_t r_ss; 807c478bd9Sstevel@tonic-gate }; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate #define r_r0 r_eax /* r0 for portability */ 837c478bd9Sstevel@tonic-gate #define r_r1 r_edx /* r1 for portability */ 847c478bd9Sstevel@tonic-gate #define r_fp r_ebp /* system frame pointer */ 857c478bd9Sstevel@tonic-gate #define r_sp r_uesp /* user stack pointer */ 867c478bd9Sstevel@tonic-gate #define r_pc r_eip /* user's instruction pointer */ 877c478bd9Sstevel@tonic-gate #define r_ps r_efl /* user's EFLAGS */ 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate #define GREG_NUM 8 /* Number of regs between %edi and %eax */ 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate #endif /* !_ASM */ 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate #ifdef _KERNEL 947c478bd9Sstevel@tonic-gate #define lwptoregs(lwp) ((struct regs *)((lwp)->lwp_regs)) 957c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate /* 987c478bd9Sstevel@tonic-gate * Save current frame on the stack. Uses %eax. 997c478bd9Sstevel@tonic-gate */ 1007c478bd9Sstevel@tonic-gate #define __FRAME_PUSH \ 1017c478bd9Sstevel@tonic-gate subl $8, %esp; \ 1027c478bd9Sstevel@tonic-gate movl REGOFF_EIP(%esp), %eax; \ 1037c478bd9Sstevel@tonic-gate movl %eax, REGOFF_SAVPC(%esp); \ 1047c478bd9Sstevel@tonic-gate movl %ebp, REGOFF_SAVFP(%esp); 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * Save segment registers on the stack. 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate #define __SEGREGS_PUSH \ 1107c478bd9Sstevel@tonic-gate subl $16, %esp; \ 1117c478bd9Sstevel@tonic-gate movw %ds, 12(%esp); \ 1127c478bd9Sstevel@tonic-gate movw %es, 8(%esp); \ 1137c478bd9Sstevel@tonic-gate movw %fs, 4(%esp); \ 1147c478bd9Sstevel@tonic-gate movw %gs, 0(%esp); 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate /* 1177c478bd9Sstevel@tonic-gate * Load segment register with kernel selectors. 1187c478bd9Sstevel@tonic-gate * %gs must be the last one to be set to make the 1197c478bd9Sstevel@tonic-gate * check in cmnint valid. 1207c478bd9Sstevel@tonic-gate */ 1217c478bd9Sstevel@tonic-gate #define __SEGREGS_LOAD_KERNEL \ 122*990a5ef8Ssherrym movw $KDS_SEL, %cx; \ 123*990a5ef8Ssherrym movw %cx, %ds; \ 124*990a5ef8Ssherrym movw %cx, %es; \ 1257c478bd9Sstevel@tonic-gate movw $KFS_SEL, %cx; \ 1267c478bd9Sstevel@tonic-gate movw $KGS_SEL, %dx; \ 1277c478bd9Sstevel@tonic-gate movw %cx, %fs; \ 1287c478bd9Sstevel@tonic-gate movw %dx, %gs; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate /* 1317c478bd9Sstevel@tonic-gate * Restore segment registers off the stack. 1327c478bd9Sstevel@tonic-gate * 1337c478bd9Sstevel@tonic-gate * NOTE THE ORDER IS VITAL! 1347c478bd9Sstevel@tonic-gate * 1357c478bd9Sstevel@tonic-gate * Also note the subtle interdependency with kern_gpfault() 1367c478bd9Sstevel@tonic-gate * that needs to disassemble these instructions to diagnose 1377c478bd9Sstevel@tonic-gate * what happened when things (like bad segment register 1387c478bd9Sstevel@tonic-gate * values) go horribly wrong. 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate #define __SEGREGS_POP \ 1417c478bd9Sstevel@tonic-gate movw 0(%esp), %gs; \ 1427c478bd9Sstevel@tonic-gate movw 4(%esp), %fs; \ 1437c478bd9Sstevel@tonic-gate movw 8(%esp), %es; \ 1447c478bd9Sstevel@tonic-gate movw 12(%esp), %ds; \ 1457c478bd9Sstevel@tonic-gate addl $16, %esp; 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate /* 1487c478bd9Sstevel@tonic-gate * Macros for saving all registers necessary on interrupt entry, 1497c478bd9Sstevel@tonic-gate * and restoring them on exit. 1507c478bd9Sstevel@tonic-gate */ 1517c478bd9Sstevel@tonic-gate #define INTR_PUSH \ 1527c478bd9Sstevel@tonic-gate pusha; \ 1537c478bd9Sstevel@tonic-gate __SEGREGS_PUSH \ 1547c478bd9Sstevel@tonic-gate __FRAME_PUSH \ 1557c478bd9Sstevel@tonic-gate cmpw $KGS_SEL, REGOFF_GS(%esp); \ 1567c478bd9Sstevel@tonic-gate je 7f; \ 1577c478bd9Sstevel@tonic-gate movl $0, REGOFF_SAVFP(%esp); \ 1587c478bd9Sstevel@tonic-gate __SEGREGS_LOAD_KERNEL \ 1597c478bd9Sstevel@tonic-gate 7: 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate #define INTR_POP \ 1627c478bd9Sstevel@tonic-gate popa; \ 1637c478bd9Sstevel@tonic-gate addl $8, %esp; /* get TRAPNO and ERR off the stack */ 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate #define INTR_POP_USER \ 1667c478bd9Sstevel@tonic-gate addl $8, %esp; /* get extra frame off the stack */ \ 1677c478bd9Sstevel@tonic-gate __SEGREGS_POP \ 1687c478bd9Sstevel@tonic-gate INTR_POP 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate #define INTR_POP_KERNEL \ 1717c478bd9Sstevel@tonic-gate addl $24, %esp; /* skip extra frame and segment registers */ \ 1727c478bd9Sstevel@tonic-gate INTR_POP 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate /* 1757c478bd9Sstevel@tonic-gate * Macros for saving the original segment registers and restoring them 1767c478bd9Sstevel@tonic-gate * for fast traps. 1777c478bd9Sstevel@tonic-gate */ 1787c478bd9Sstevel@tonic-gate #define FAST_INTR_PUSH \ 1797c478bd9Sstevel@tonic-gate __SEGREGS_PUSH \ 1807c478bd9Sstevel@tonic-gate __SEGREGS_LOAD_KERNEL 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate #define FAST_INTR_POP \ 1837c478bd9Sstevel@tonic-gate __SEGREGS_POP 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate #define DISABLE_INTR_FLAGS \ 1867c478bd9Sstevel@tonic-gate pushl $F_OFF; \ 1877c478bd9Sstevel@tonic-gate popfl; 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate #define ENABLE_INTR_FLAGS \ 1907c478bd9Sstevel@tonic-gate pushl $F_ON; \ 1917c478bd9Sstevel@tonic-gate popfl; 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate /* 1947c478bd9Sstevel@tonic-gate * Macros for saving all registers necessary on system call entry, 1957c478bd9Sstevel@tonic-gate * and restoring them on exit. 1967c478bd9Sstevel@tonic-gate */ 1977c478bd9Sstevel@tonic-gate #define SYSCALL_PUSH \ 1987c478bd9Sstevel@tonic-gate pusha; \ 1997c478bd9Sstevel@tonic-gate __SEGREGS_PUSH \ 200*990a5ef8Ssherrym subl $8, %esp; \ 2017c478bd9Sstevel@tonic-gate pushfl; \ 2027c478bd9Sstevel@tonic-gate popl %ecx; \ 2037c478bd9Sstevel@tonic-gate orl $PS_IE, %ecx; \ 2047c478bd9Sstevel@tonic-gate movl %ecx, REGOFF_EFL(%esp); \ 205*990a5ef8Ssherrym movl $0, REGOFF_SAVPC(%esp); \ 2067c478bd9Sstevel@tonic-gate movl $0, REGOFF_SAVFP(%esp); \ 2077c478bd9Sstevel@tonic-gate __SEGREGS_LOAD_KERNEL 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate #define SYSENTER_PUSH \ 2107c478bd9Sstevel@tonic-gate pusha; \ 2117c478bd9Sstevel@tonic-gate __SEGREGS_PUSH \ 212*990a5ef8Ssherrym subl $8, %esp; \ 213*990a5ef8Ssherrym movl $0, REGOFF_SAVPC(%esp); \ 2147c478bd9Sstevel@tonic-gate movl $0, REGOFF_SAVFP(%esp); \ 2157c478bd9Sstevel@tonic-gate __SEGREGS_LOAD_KERNEL 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate #define SYSCALL_POP \ 2187c478bd9Sstevel@tonic-gate INTR_POP_USER 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate #include <sys/controlregs.h> 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* Control register layout for panic dump */ 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate #define CREGSZ 36 2277c478bd9Sstevel@tonic-gate #define CREG_GDT 0 2287c478bd9Sstevel@tonic-gate #define CREG_IDT 8 2297c478bd9Sstevel@tonic-gate #define CREG_LDT 16 2307c478bd9Sstevel@tonic-gate #define CREG_TASKR 18 2317c478bd9Sstevel@tonic-gate #define CREG_CR0 20 2327c478bd9Sstevel@tonic-gate #define CREG_CR2 24 2337c478bd9Sstevel@tonic-gate #define CREG_CR3 28 2347c478bd9Sstevel@tonic-gate #define CREG_CR4 32 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate #if !defined(_ASM) && defined(_INT64_TYPE) 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate typedef uint64_t creg64_t; 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate struct cregs { 2417c478bd9Sstevel@tonic-gate creg64_t cr_gdt; 2427c478bd9Sstevel@tonic-gate creg64_t cr_idt; 2437c478bd9Sstevel@tonic-gate uint16_t cr_ldt; 2447c478bd9Sstevel@tonic-gate uint16_t cr_task; 2457c478bd9Sstevel@tonic-gate uint32_t cr_cr0; 2467c478bd9Sstevel@tonic-gate uint32_t cr_cr2; 2477c478bd9Sstevel@tonic-gate uint32_t cr_cr3; 2487c478bd9Sstevel@tonic-gate uint32_t cr_cr4; 2497c478bd9Sstevel@tonic-gate }; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 2527c478bd9Sstevel@tonic-gate extern void getcregs(struct cregs *); 2537c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate #endif /* !_ASM && _INT64_TYPE */ 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate #endif 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate #endif /* !_IA32_SYS_PRIVREGS_H */ 262