Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / util / romcc / tests / simple_test.c
1 void land_test(void)
2 {
3         int i;
4         i = 1 && 2;
5 }
6 void lor_test(void)
7 {
8         int i;
9         i = 1 || 2;
10 }
11
12 void outb(unsigned char value, unsigned short port)
13 {
14         __builtin_outb(value, port);
15 }
16
17 unsigned char inb(unsigned short port)
18 {
19         return __builtin_inb(port);
20 }
21
22 static unsigned int config_cmd2(unsigned char bus, unsigned devfn, unsigned where)
23 {
24         return 0x80000000 | (bus << 16) | (devfn << 8) | (where & ~3)  ;
25 }
26
27 /* Base Address */
28 #ifndef CONFIG_TTYS0_BASE
29 #define CONFIG_TTYS0_BASE 0x3f8
30 #endif
31
32 #ifndef CONFIG_TTYS0_BAUD
33 #define CONFIG_TTYS0_BAUD 115200
34 #endif
35
36 #if ((115200%CONFIG_TTYS0_BAUD) != 0)
37 #error Bad ttys0 baud rate
38 #endif
39
40 #define CONFIG_TTYS0_DIV        (115200/CONFIG_TTYS0_BAUD)
41
42 /* Line Control Settings */
43 #ifndef CONFIG_TTYS0_LCS
44 /* Set 8bit, 1 stop bit, no parity */
45 #define CONFIG_TTYS0_LCS        0x3
46 #endif
47
48 #define UART_LCS        CONFIG_TTYS0_LCS
49
50 /* Data */
51 #define UART_RBR 0x00
52 #define UART_TBR 0x00
53
54 /* Control */
55 #define UART_IER 0x01
56 #define UART_IIR 0x02
57 #define UART_FCR 0x02
58 #define UART_LCR 0x03
59 #define UART_MCR 0x04
60 #define UART_DLL 0x00
61 #define UART_DLM 0x01
62
63 /* Status */
64 #define UART_LSR 0x05
65 #define UART_MSR 0x06
66 #define UART_SCR 0x07
67
68 int uart_can_tx_byte(void)
69 {
70         return inb(CONFIG_TTYS0_BASE + UART_LSR) & 0x20;
71 }
72
73 void uart_wait_to_tx_byte(void)
74 {
75         while(!uart_can_tx_byte())
76                 ;
77 }
78
79 void uart_wait_until_sent(void)
80 {
81         while(!(inb(CONFIG_TTYS0_BASE + UART_LSR) & 0x40))
82                 ;
83 }
84
85 void uart_tx_byte(unsigned char data)
86 {
87         uart_wait_to_tx_byte();
88         outb(data, CONFIG_TTYS0_BASE + UART_TBR);
89         /* Make certain the data clears the fifos */
90         uart_wait_until_sent();
91 }
92
93 void dummy(void)
94 {
95         uart_tx_byte(5);
96 }
97
98 #define PIIX4_DEVFN 0x90
99 #define SMBUS_MEM_DEVICE_START 0x50
100 #define SMBUS_MEM_DEVICE_END 0x53
101 #define SMBUS_MEM_DEVICE_INC 1
102
103
104 #define PM_BUS 0
105 #define PM_DEVFN (PIIX4_DEVFN+3)
106
107 #define SMBUS_IO_BASE 0x1000
108 #define SMBHSTSTAT 0
109 #define SMBHSTCTL  2
110 #define SMBHSTCMD  3
111 #define SMBHSTADD  4
112 #define SMBHSTDAT0 5
113 #define SMBHSTDAT1 6
114 #define SMBBLKDAT  7
115
116 static void smbus_wait_until_done(void)
117 {
118         unsigned char byte;
119         do {
120                 byte = inb(SMBUS_IO_BASE + SMBHSTSTAT);
121         }while((byte &1) == 1);
122 #if 1
123         while( (byte & ~1) == 0) {
124                 byte = inb(SMBUS_IO_BASE + SMBHSTSTAT);
125         }
126 #endif
127 }
128
129 #if 0
130 void ifthenelse(void)
131 {
132         int i;
133         if (5 > 2) {
134                 i = 1;
135         }
136         else {
137                 i = 2;
138         }
139         i = i + 3;
140 }
141 #endif
142 #if 0
143 static int add(int left, int right)
144 {
145         {
146                 return left + right;
147         }
148 }
149 #else
150 #if 0
151 static int add(int left, int right)
152 {
153         return left + right;
154 }
155 #endif
156 #endif
157
158 #if 0
159 static void assign(void)
160 {
161         int i, j;
162         i = j = 1;
163 }
164 #endif
165
166 #if 0
167 static void and(void)
168 {
169         int i, j, k;
170         i = 1;
171         j = 2;
172         k = i && j;
173
174 }
175 static void and_test(void)
176 {
177         and();
178 }
179 #endif
180 #if 0
181 #define INC_TEST 2
182 static void inc(void)
183 {
184         int i;
185         i = 5;
186 #if (INC_TEST == 1)
187         i += 7;
188 #endif
189 #if (INC_TEST == 2)
190         ++i;
191 #endif
192 #if (INC_TEST == 3)
193         i++;
194 #endif
195 }
196
197 #if 0
198 static void inc_test(void)
199 {
200         inc();
201 }
202 #endif
203 #endif
204 #if 0
205 static void loop(void)
206 {
207         int i;
208         for(i = 0; i < 10; i++) {
209                 ;
210         } while(i < 10);
211 }
212
213 static void loop_test(void)
214 {
215         loop();
216 }
217 #endif
218
219 #if 0
220 static void simple(void)
221 {
222         add(1,2);
223 }
224 #endif
225
226 #if 0
227 static void fun(void)
228 {
229         int bar;
230         bar = add(1, 2);
231 }
232 #endif
233
234
235 #if 0
236 static void func(void)
237 {
238         int bar, baz;
239         int i;
240
241         baz = add(1, 2);
242         baz = add(1, 2);
243         bar = 1;
244         baz = 2;
245         for(i = 0; i < 10; i = i + 1) {
246                 baz = i;
247         }
248         bar = 1 + 2 * 3;
249         bar = add(3, 4);
250         bar = add(bar, baz);
251 }
252 #endif