/[gxemul]/upstream/0.3.3.1/tests/test_common.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /upstream/0.3.3.1/tests/test_common.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (hide annotations)
Mon Oct 8 16:18:14 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 2976 byte(s)
0.3.3.1
1 dpavlin 2 /*
2     * Copyright (C) 2004-2005 Anders Gavare. All rights reserved.
3     *
4     * Redistribution and use in source and binary forms, with or without
5     * modification, are permitted provided that the following conditions are met:
6     *
7     * 1. Redistributions of source code must retain the above copyright
8     * notice, this list of conditions and the following disclaimer.
9     * 2. Redistributions in binary form must reproduce the above copyright
10     * notice, this list of conditions and the following disclaimer in the
11     * documentation and/or other materials provided with the distribution.
12     * 3. The name of the author may not be used to endorse or promote products
13     * derived from this software without specific prior written permission.
14     *
15     * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16     * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18     * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19     * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20     * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21     * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24     * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25     * SUCH DAMAGE.
26     *
27     *
28     * $Id: test_common.c,v 1.3 2005/01/09 01:55:32 debug Exp $
29     *
30     * This module contains common routines used by all the regression tests.
31     * Each test should be linked with this module, but have its own main()
32     * routine.
33     */
34    
35    
36     /*
37     * printchar():
38     *
39     * This function should print a character to the (serial) console.
40     * In the emulator, it is as simple as storing a byte at a specific
41     * address.
42     */
43     #define PUTCHAR_ADDRESS 0xb0000000
44     void printchar(char ch)
45     {
46     *((volatile unsigned char *) PUTCHAR_ADDRESS) = ch;
47     }
48    
49    
50     /*
51     * printstr():
52     */
53     void printstr(char *s)
54     {
55     while (*s)
56     printchar(*s++);
57     }
58    
59    
60     /*
61     * printhex():
62     *
63     * Print a number in hex. len is the number of characters to output.
64     * (This should be sizeof(value).)
65     */
66     void printhex(long n, int len)
67     {
68     char *hex = "0123456789abcdef";
69     int i;
70    
71     printstr("0x");
72     for (i=len*2-1; i>=0; i--)
73     printchar(hex[(n >> (4*i)) & 15]);
74     }
75    
76    
77     /*
78     * printdec():
79     *
80     * Print a number in decimal form.
81     */
82     void printdec(long x)
83     {
84     if (x == 0)
85     printchar('0');
86     else if (x < 0) {
87     printchar('-');
88     printdec(-x);
89     } else {
90     int y = x / 10;
91     if (y > 0)
92     printdec(y);
93     printchar('0' + (x % 10));
94     }
95     }
96    
97    
98     /*
99     * main():
100     */
101     int main(int argc, char *argv[])
102     {
103     unsigned int x;
104    
105     x = testmain();
106    
107     printhex(x, 4);
108     printstr("\n");
109    
110     /* This should shut down the emulator: */
111     (*(volatile char *)0xb0000010) = 0;
112    
113     /* This should never be reached: */
114     for (;;)
115     ;
116    
117     return 0;
118     }
119    

  ViewVC Help
Powered by ViewVC 1.1.26