11.10Smbalmer/* $NetBSD: abortfixup.c,v 1.10 2011/10/17 16:39:15 mbalmer Exp $ */
21.1Sreinoud
31.1Sreinoud/*-
41.1Sreinoud * Copyright (c) 2001 The NetBSD Foundation, Inc.
51.1Sreinoud * All rights reserved.
61.1Sreinoud *
71.1Sreinoud * Redistribution and use in source and binary forms, with or without
81.1Sreinoud * modification, are permitted provided that the following conditions
91.1Sreinoud * are met:
101.1Sreinoud * 1. Redistributions of source code must retain the above copyright
111.1Sreinoud *    notice, this list of conditions and the following disclaimer.
121.1Sreinoud * 2. Redistributions in binary form must reproduce the above copyright
131.1Sreinoud *    notice, this list of conditions and the following disclaimer in the
141.1Sreinoud *    documentation and/or other materials provided with the distribution.
151.1Sreinoud *
161.1Sreinoud * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.1Sreinoud * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.1Sreinoud * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.1Sreinoud * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.1Sreinoud * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.1Sreinoud * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.1Sreinoud * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.1Sreinoud * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.1Sreinoud * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.1Sreinoud * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.1Sreinoud * POSSIBILITY OF SUCH DAMAGE.
271.1Sreinoud *
281.1Sreinoud *
291.1Sreinoud * Trying out if an unhandled instruction pattern in the late abort fixup
301.1Sreinoud * generates a panic or sysfaults like it ought to do.
311.1Sreinoud */
321.1Sreinoud
331.1Sreinoud#include <sys/types.h>
341.1Sreinoud
351.10Smbalmer__RCSID("$NetBSD: abortfixup.c,v 1.10 2011/10/17 16:39:15 mbalmer Exp $");
361.1Sreinoud
371.5Sbjh21#include <setjmp.h>
381.1Sreinoud#include <signal.h>
391.1Sreinoud#include <stdio.h>
401.1Sreinoud#include <stdlib.h>
411.1Sreinoud#include <stdio.h>
421.9Smellon#include <err.h>
431.1Sreinoud
441.5Sbjh21jmp_buf buf;
451.5Sbjh21
461.3Sbjh21void
471.3Sbjh21sighandler(int sig)
481.3Sbjh21{
491.3Sbjh21
501.3Sbjh21	/* Catching SIGSEGV means the test passed. */
511.5Sbjh21	longjmp(buf, 1);
521.3Sbjh21}
531.3Sbjh21
541.3Sbjh21int
551.3Sbjh21main(void)
561.3Sbjh21{
571.3Sbjh21
581.3Sbjh21	if (signal(SIGSEGV, sighandler) == SIG_ERR)
591.3Sbjh21		err(1, "signal");
601.1Sreinoud
611.5Sbjh21	printf("ARM6/7 abort fixup panic\n");
621.1Sreinoud
631.1Sreinoud	/*
641.1Sreinoud 	 * issue an instruction that for certain generates a page
651.1Sreinoud	 * fault but _can't_ be fixed up by late abort fixup
661.1Sreinoud	 * routines due to its structure.
671.1Sreinoud	 */
681.3Sbjh21
691.5Sbjh21	if (setjmp(buf) == 0) {
701.7Sperry		__asm volatile (
711.6Sthorpej		"	mov r0, #0			\n"
721.6Sthorpej		"	mov r1, r0			\n"
731.6Sthorpej		"	str r1, [r0], r1, ror #10");
741.5Sbjh21
751.5Sbjh21		/* Should not be reached if OK */
761.10Smbalmer		printf("!!! Regression test FAILED - no SEGV received\n");
771.5Sbjh21		exit(1);
781.5Sbjh21	}
791.5Sbjh21
801.5Sbjh21	printf("ARM2/3 abort address panic\n");
811.5Sbjh21
821.5Sbjh21	/* Similar but pre-indexed, to check ARM2/3 abort address function. */
831.5Sbjh21
841.5Sbjh21	if (setjmp(buf) == 0) {
851.7Sperry		__asm volatile (
861.6Sthorpej		"	mov r0, #0			\n"
871.6Sthorpej		"	mov r1, r0			\n"
881.6Sthorpej		"	str r1, [r0, r1, ror #10]");
891.5Sbjh21
901.5Sbjh21		/* Should not be reached if OK */
911.10Smbalmer		printf("!!! Regression test FAILED - no SEGV received\n");
921.5Sbjh21		exit(1);
931.5Sbjh21	}
941.5Sbjh21
951.5Sbjh21	printf("All OK\n");
961.5Sbjh21
971.5Sbjh21	exit(0);
981.1Sreinoud};
99