1/* $OpenBSD: debug_i386.S,v 1.9 1998/04/18 07:39:46 deraadt Exp $ */ 2 3/* 4 * Copyright (c) 1997 Michael Shalayeff 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Michael Shalayeff. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 */ 34 35#include <machine/asm.h> 36#include <machine/psl.h> 37#define _LOCORE 38#include <machine/segments.h> 39#include <machine/trap.h> 40#include <debug_md.h> 41#undef _LOCORE 42 43 /* do this way because some cpus (like cyrix 6x86) store garbage 44 * into high word, instead of zeroes. 45 */ 46#define pushsr(sr) movl sr, %eax; pushl %eax 47 48 .text 49 .globl alltraps 50 51alltraps: 52 pushal 53 pushsr(%ds) 54 pushsr(%es) 55 pushsr(%fs) 56 pushsr(%gs) 57 /* muck %cs, see note about pushsr() above */ 58 movl 0xf*4(%esp), %eax 59 movzwl %ax, %eax 60 movl %eax, 0xf*4(%esp) 61#ifdef DEBUG_DEBUG 62 movl $0xb8280, %edi 63 movl 0x0c*4(%esp), %eax /* trapno */ 64 addb $'0', %al 65 movb $0x17, %ah 66 shll $16, %eax 67 movb 0x0d*4(%esp), %al /* error */ 68 addb $'0', %al 69 movb $0x17, %ah 70 movl %eax, (%edi) 71#endif 72 call _C_LABEL(check_regs) 73#ifdef DEBUG_DEBUG 74 movl $0xb8290, %edi 75 movl $0x47394738, (%edi) 76#endif 77 popl %gs 78 popl %fs 79 popl %es 80 popl %ds 81 popal 82 addl $0x8, %esp 83 hlt 84 iret 85 86ENTRY(check_regs) 87#ifdef DEBUG_DEBUG 88 movl $0xb8284, %edi 89 movl $0x47334732, (%edi) 90#endif 91 movl $0x10, %eax 92 movl %ax, %ds 93 movl %ax, %es 94 movl $_reg, %edi 95 cld 96 movl 0x0c*4(%esp), %eax; stosl /* %eax */ 97 movl 0x0b*4(%esp), %eax; stosl /* %ecx */ 98 movl 0x0a*4(%esp), %eax; stosl /* %edx */ 99 movl 0x09*4(%esp), %eax; stosl /* %ebx */ 100 movl 0x08*4(%esp), %eax; stosl /* %esp */ 101 movl 0x07*4(%esp), %eax; stosl /* %ebp */ 102 movl 0x06*4(%esp), %eax; stosl /* %esi */ 103 movl 0x05*4(%esp), %eax; stosl /* %edi */ 104 movl 0x0f*4(%esp), %eax; stosl /* %eip */ 105 movl 0x11*4(%esp), %eax; stosl /* %eflags */ 106 movl 0x10*4(%esp), %eax; stosl /* %cs */ 107 movl %ss, %ax ; stosl /* %ss */ 108 movl 0x04*4(%esp), %eax; stosl /* %ds */ 109 movl 0x03*4(%esp), %eax; stosl /* %es */ 110 movl 0x02*4(%esp), %eax; stosl /* %fs */ 111 movl 0x01*4(%esp), %eax; stosl /* %gs */ 112 113#ifdef DEBUG_DEBUG 114 movl $0xb8288, %edi 115 movl $0x47354734, (%edi) 116#endif 117 movl 0x0e*4(%esp), %ecx /* error */ 118 movl 0x0d*4(%esp), %eax /* trapno */ 119 pushl %ecx 120 pushl %eax 121 call _C_LABEL(dump_regs) 122 popl %eax 123 popl %eax 124 125#ifdef DEBUG_DEBUG 126 movl $0xb828c, %edi 127 movl $0x47374736, (%edi) 128#endif 129 ret 130 131 132