blob: d510cca1f6c85d7c9d69874e1670df2418d451ac [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2001
3 * Bill Hunter, Wave 7 Optics, william.hunter@mediaone.net
4 * and
5 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25/*
26 * Description:
27 * Routine to exercise memory for the bringing up of our boards.
28 */
29#include <config.h>
30#include <ppc4xx.h>
31
32#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
33
34#include <ppc_asm.tmpl>
35#include <ppc_defs.h>
36
37#include <asm/cache.h>
38#include <asm/mmu.h>
39
40#include <watchdog.h>
41
42#include "errors.h"
43
44#define _ASMLANGUAGE
45
46 .globl test_sdram
47 .globl test_led
48 .globl log_stat
49 .globl log_warn
50 .globl log_err
51 .globl temp_uart_init
52 .globl post_puts
53 .globl disp_hex
54
55/*****************************************************
56******* Text Strings for low level printing ******
57******* In section got2 *******
58*****************************************************/
59
60/*
61 * Define the text strings for errors and warnings.
62 * Switch to .data section.
63 */
64 .section ".data"
65err_str: .asciz "*** POST ERROR = "
66warn_str: .asciz "*** POST WARNING = "
67end_str: .asciz "\r\n"
68
69/*
70 * Enter the labels in Global Entry Table (GOT).
71 * Switch to .got2 section.
72 */
73 START_GOT
74 GOT_ENTRY(err_str)
75 GOT_ENTRY(warn_str)
76 GOT_ENTRY(end_str)
77 END_GOT
78
79/*
80 * Switch back to .text section.
81 */
82 .text
83
84/****************************************
85 ****************************************
86 ******** LED register test ********
87 ****************************************
88 ***************************************/
89test_led:
90 /* save the return info on stack */
91 mflr r0 /* Get link register */
92 stwu r1, -12(r1) /* Save back chain and move SP */
93 stw r0, +16(r1) /* Save link register */
94 stw r4, +8(r1) /* save R4 */
95
96 WATCHDOG_RESET /* Reset the watchdog */
97
98 addi r3, 0, ERR_FF /* first test value is ffff */
99 addi r4, r3, 0 /* save copy of pattern */
100 bl set_led /* store first test value */
101 bl get_led /* read it back */
102 xor. r4, r4, r3 /* compare to original */
103#if defined(CONFIG_W7OLMC)
104 andi. r4, r4, 0x00ff /* lmc has 8 bits */
105#else
106 andi. r4, r4, 0xffff /* lmg has 16 bits */
107#endif
108 beq LED2 /* next test */
109 addi r3, 0, ERR_LED /* error code = 1 */
110 bl log_err /* display error and halt */
111LED2: addi r3, 0, ERR_00 /* 2nd test value is 0000 */
112 addi r4, r3, 0 /* save copy of pattern */
113 bl set_led /* store first test value */
114 bl get_led /* read it back */
115 xor. r4, r4, r3 /* compare to original */
116#if defined(CONFIG_W7OLMC)
117 andi. r4, r4, 0x00ff /* lmc has 8 bits */
118#else
119 andi. r4, r4, 0xffff /* lmg has 16 bits */
120#endif
121 beq LED3 /* next test */
122 addi r3, 0, ERR_LED /* error code = 1 */
123 bl log_err /* display error and halt */
124
125LED3: /* restore stack and return */
126 lwz r0, +16(r1) /* Get saved link register */
127 mtlr r0 /* Restore link register */
128 lwz r4, +8(r1) /* restore r4 */
129 addi r1, r1, +12 /* Remove frame from stack */
130 blr /* Return to calling function */
131
132/****************************************
133 ****************************************
134 ******** SDRAM TESTS ********
135 ****************************************
136 ***************************************/
137test_sdram:
138 /* called with mem size in r3 */
139 /* save the return info on stack */
140 mflr r0 /* Get link register */
141 stwu r1, -16(r1) /* Save back chain and move SP */
142 stw r0, +20(r1) /* Save link register */
143 stmw r30, +8(r1) /* save R30,R31 */
144 /* r30 is log2(mem size) */
145 /* r31 is mem size */
146
147 /* take log2 of total mem size */
148 addi r31, r3, 0 /* save total mem size */
149 addi r30, 0, 0 /* clear r30 */
150l2_loop:
151 srwi. r31, r31, 1 /* shift right 1 */
152 addi r30, r30, 1 /* count shifts */
153 bne l2_loop /* loop till done */
154 addi r30, r30, -1 /* correct for over count */
155 addi r31, r3, 0 /* save original size */
156
157 /* now kick the dog and test the mem */
158 WATCHDOG_RESET /* Reset the watchdog */
159 bl Data_Buster /* test crossed/shorted data lines */
160 addi r3, r30, 0 /* get log2(memsize) */
161 addi r4, r31, 0 /* get memsize */
162 bl Ghost_Buster /* test crossed/shorted addr lines */
163 addi r3, r31, 0 /* get mem size */
164 bl Bit_Buster /* check for bad internal bits */
165
166 /* restore stack and return */
167 lmw r30, +8(r1) /* Restore r30, r31 */
168 lwz r0, +20(r1) /* Get saved link register */
169 mtlr r0 /* Restore link register */
170 addi r1, r1, +16 /* Remove frame from stack */
171 blr /* Return to calling function */
172
173
174/****************************************
175 ******** sdram data bus test ********
176 ***************************************/
177Data_Buster:
178 /* save the return info on stack */
179 mflr r0 /* Get link register */
180 stwu r1, -24(r1) /* Save back chain and move SP */
181 stw r0, +28(r1) /* Save link register */
182 stmw r28, 8(r1) /* save r28 - r31 on stack */
183 /* r31 i/o register */
184 /* r30 sdram base address */
185 /* r29 5555 syndrom */
186 /* r28 aaaa syndrom */
187
188 /* set up led register for this test */
189 addi r3, 0, ERR_RAMG /* set led code to 1 */
190 bl log_stat /* store test value */
191 /* now test the dram data bus */
192 xor r30, r30, r30 /* load r30 with base addr of sdram */
193 addis r31, 0, 0x5555 /* load r31 with test value */
194 ori r31, r31, 0x5555
195 stw r31,0(r30) /* sto the value */
196 lwz r29,0(r30) /* read it back */
197 xor r29,r31,r29 /* compare it to original */
198 addis r31, 0, 0xaaaa /* load r31 with test value */
199 ori r31, r31, 0xaaaa
200 stw r31,0(r30) /* sto the value */
201 lwz r28,0(r30) /* read it back */
202 xor r28,r31,r28 /* compare it to original */
203 or r3,r28,r29 /* or together both error terms */
204 /*
205 * Now that we have the error bits,
206 * we have to decide which part they are in.
207 */
208 bl get_idx /* r5 is now index to error */
209 addi r3, r3, ERR_RAMG
210 cmpwi r3, ERR_RAMG /* check for errors */
211 beq db_done /* skip if no errors */
212 bl log_err /* log the error */
213
214db_done:
215 lmw r28, 8(r1) /* restore r28 - r31 from stack */
216 lwz r0, +28(r1) /* Get saved link register */
217 addi r1, r1, +24 /* Remove frame from stack */
218 mtlr r0 /* Restore link register */
219 blr /* Return to calling function */
220
221
222/****************************************************
223 ******** test for address ghosting in dram ********
224 ***************************************************/
225
226Ghost_Buster:
227 /* save the return info on stack */
228 mflr r0 /* Get link register */
229 stwu r1, -36(r1) /* Save back chain and move SP */
230 stw r0, +40(r1) /* Save link register */
231 stmw r25, 8(r1) /* save r25 - r31 on stack */
232 /* r31 = scratch register */
233 /* r30 is main referance loop counter,
234 0 to 23 */
235 /* r29 is ghost loop count, 0 to 22 */
236 /* r28 is referance address */
237 /* r27 is ghost address */
238 /* r26 is log2 (mem size) =
239 number of byte addr bits */
240 /* r25 is mem size */
241
242 /* save the log2(mem size) and mem size */
243 addi r26, r3, 0 /* r26 is number of byte addr bits */
244 addi r25, r4, 0 /* r25 is mem size in bytes */
245
246 /* set the leds for address ghost test */
247 addi r3, 0, ERR_ADDG
248 bl set_led
249
250 /* first fill memory with zeros */
251 srwi r31, r25, 2 /* convert bytes to longs */
252 mtctr r31 /* setup byte counter */
253 addi r28, 0, 0 /* start at address at 0 */
254 addi r31, 0, 0 /* data value = 0 */
255clr_loop:
256 stw r31, 0(r28) /* Store zero value */
257 addi r28, r28, 4 /* Increment to next word */
258 andi. r27, r28, 0xffff /* check for 2^16 loops */
259 bne clr_skip /* if not there, then skip */
260 WATCHDOG_RESET /* kick the dog every now and then */
261clr_skip:
262 bdnz clr_loop /* Round and round... */
263
264 /* now do main test */
265 addi r30, 0, 0 /* start referance counter at 0 */
266outside:
267 /*
268 * Calculate the referance address
269 * the referance address is calculated by setting the (r30-1)
270 * bit of the base address
271 * when r30=0, the referance address is the base address.
272 * thus the sequence 0,1,2,4,8,..,2^(n-1)
273 * setting the bit is done with the following shift functions.
274 */
275 WATCHDOG_RESET /* Reset the watchdog */
276
277 addi r31, 0, 1 /* r31 = 1 */
278 slw r28, r31, r30 /* set bit coresponding to loop cnt */
279 srwi r28, r28, 1 /* then shift it right one so */
280 /* we start at location 0 */
281 /* fill referance address with Fs */
282 addi r31, 0, 0x00ff /* r31 = one byte of set bits */
283 stb r31,0(r28) /* save ff in referance address */
284
285 /* ghost (inner) loop, now check all posible ghosted addresses */
286 addi r29, 0, 0 /* start ghosted loop counter at 0 */
287inside:
288 /*
289 * Calculate the ghost address by flipping one
290 * bit of referance address. This gives the
291 * sequence 1,2,4,8,...,2^(n-1)
292 */
293 addi r31, 0, 1 /* r31 = 1 */
294 slw r27, r31, r29 /* set bit coresponding to loop cnt */
295 xor r27, r28, r27 /* ghost address = ref addr with
296 bit flipped*/
297
298 /* now check for ghosting */
299 lbz r31,0(r27) /* get content of ghost addr */
300 cmpwi r31, 0 /* compare read value to 0 */
301 bne Casper /* we found a ghost! */
302
303 /* now close ghost ( inner ) loop */
304 addi r29, r29, 1 /* increment inner loop counter */
305 cmpw r29, r26 /* check for last inner loop */
306 blt inside /* do more inner loops */
307
308 /* now close referance ( outer ) loop */
309 addi r31, 0, 0 /* r31 = zero */
310 stb r31, 0(28) /* zero out the altered address loc. */
311 /*
312 * Increment and check for end, count is zero based.
313 * With the ble, this gives us one more loops than
314 * address bits for sequence 0,1,2,4,8,...2^(n-1)
315 */
316 addi r30, r30, 1 /* increment outer loop counter */
317 cmpw r30, r26 /* check for last inner loop */
318 ble outside /* do more outer loops */
319
320 /* were done, lets go home */
321 b gb_done
322Casper: /* we found a ghost !! */
323 addi r3, 0, ERR_ADDF /* get indexed error message */
324 bl log_err /* log error led error code */
325gb_done: /* pack your bags, and go home */
326 lmw r25, 8(r1) /* restore r25 - r31 from stack */
327 lwz r0, +40(r1) /* Get saved link register */
328 addi r1, r1, +36 /* Remove frame from stack */
329 mtlr r0 /* Restore link register */
330 blr /* Return to calling function */
331
332/****************************************************
333 ******** SDRAM data fill tests **********
334 ***************************************************/
335Bit_Buster:
336 /* called with mem size in r3 */
337 /* save the return info on stack */
338 mflr r0 /* Get link register */
339 stwu r1, -16(r1) /* Save back chain and move SP */
340 stw r0, +20(r1) /* Save link register */
341 stw r4, +8(r1) /* save R4 */
342 stw r5, +12(r1) /* save r5 */
343
344 addis r5, r3, 0 /* save mem size */
345
346 /* Test 55555555 */
347 addi r3, 0, ERR_R55G /* set up error code in case we fail */
348 bl log_stat /* store test value */
349 addis r4, 0, 0x5555
350 ori r4, r4, 0x5555
351 bl fill_test
352
353 /* Test aaaaaaaa */
354 addi r3, 0, ERR_RAAG /* set up error code in case we fail */
355 bl log_stat /* store test value */
356 addis r4, 0, 0xAAAA
357 ori r4, r4, 0xAAAA
358 bl fill_test
359
360 /* Test 00000000 */
361 addi r3, 0, ERR_R00G /* set up error code in case we fail */
362 bl log_stat /* store test value */
363 addis r4, 0, 0
364 ori r4, r4, 0
365 bl fill_test
366
367 /* restore stack and return */
368 lwz r5, +12(r1) /* restore r4 */
369 lwz r4, +8(r1) /* restore r4 */
370 lwz r0, +20(r1) /* Get saved link register */
371 addi r1, r1, +16 /* Remove frame from stack */
372 mtlr r0 /* Restore link register */
373 blr /* Return to calling function */
374
375
376
377/****************************************************
378 ******** fill test ********
379 ***************************************************/
380/* tests memory by filling with value, and reading back */
381/* r5 = Size of memory in bytes */
382/* r4 = Value to write */
383/* r3 = Error code */
384fill_test:
385 mflr r0 /* Get link register */
386 stwu r1, -32(r1) /* Save back chain and move SP */
387 stw r0, +36(r1) /* Save link register */
388 stmw r27, 8(r1) /* save r27 - r31 on stack */
389 /* r31 - scratch register */
390 /* r30 - memory address */
391 mr r27, r3
392 mr r28, r4
393 mr r29, r5
394
395 WATCHDOG_RESET /* Reset the watchdog */
396
397 /* first fill memory with Value */
398 srawi r31, r29, 2 /* convert bytes to longs */
399 mtctr r31 /* setup counter */
400 addi r30, 0, 0 /* Make r30 = addr 0 */
401ft_0: stw r28, 0(r30) /* Store value */
402 addi r30, r30, 4 /* Increment to next word */
403 andi. r31, r30, 0xffff /* check for 2^16 loops */
404 bne ft_0a /* if not there, then skip */
405 WATCHDOG_RESET /* kick the dog every now and then */
406ft_0a: bdnz ft_0 /* Round and round... */
407
408 WATCHDOG_RESET /* Reset the watchdog */
409
410 /* Now confirm Value is in memory */
411 srawi r31, r29, 2 /* convert bytes to longs */
412 mtctr r31 /* setup counter */
413 addi r30, 0, 0 /* Make r30 = addr 0 */
414ft_1: lwz r31, 0(r30) /* get value from memory */
415 xor. r31, r31, r28 /* Writen = Read ? */
416 bne ft_err /* If bad, than halt */
417 addi r30, r30, 4 /* Increment to next word */
418 andi. r31, r30, 0xffff /* check for 2^16 loops*/
419 bne ft_1a /* if not there, then skip */
420 WATCHDOG_RESET /* kick the dog every now and then */
421ft_1a: bdnz ft_1 /* Round and round... */
422
423 WATCHDOG_RESET /* Reset the watchdog */
424
425 b fill_done /* restore and return */
426
427ft_err: addi r29, r27, 0 /* save current led code */
428 addi r27, r31, 0 /* get pattern in r27 */
429 bl get_idx /* get index from r27 */
430 add r27, r27, r29 /* add index to old led code */
431 bl log_err /* output led err code, halt CPU */
432
433fill_done:
434 lmw r27, 8(r1) /* restore r27 - r31 from stack */
435 lwz r0, +36(r1) /* Get saved link register */
436 addi r1, r1, +32 /* Remove frame from stack */
437 mtlr r0 /* Restore link register */
438 blr /* Return to calling function */
439
440
441/****************************************************
442 ******* get error index from r3 pattern ********
443 ***************************************************/
444get_idx: /* r3 = (MSW(r3) !=0)*2 +
445 (LSW(r3) !=0) */
446 /* save the return info on stack */
447 mflr r0 /* Get link register */
448 stwu r1, -12(r1) /* Save back chain and move SP */
449 stw r0, +16(r1) /* Save link register */
450 stw r4, +8(r1) /* save R4 */
451
452 andi. r4, r3, 0xffff /* check for lower bits */
453 beq gi2 /* skip if no bits set */
454 andis. r4, r3, 0xffff /* check for upper bits */
455 beq gi3 /* skip if no bits set */
456 addi r3, 0, 3 /* both upper and lower bits set */
457 b gi_done
458gi2: andis. r4, r3, 0xffff /* check for upper bits*/
459 beq gi4 /* skip if no bits set */
460 addi r3, 0, 2 /* only upper bits set */
461 b gi_done
462gi3: addi r3, 0, 1 /* only lower bits set */
463 b gi_done
464gi4: addi r3, 0, 0 /* no bits set */
465gi_done:
466 /* restore stack and return */
467 lwz r0, +16(r1) /* Get saved link register */
468 mtlr r0 /* Restore link register */
469 lwz r4, +8(r1) /* restore r4 */
470 addi r1, r1, +12 /* Remove frame from stack */
471 blr /* Return to calling function */
472
473/****************************************************
474 ******** set LED to R5 and hang ********
475 ***************************************************/
476log_stat: /* output a led code and continue */
477set_led:
478 /* save the return info on stack */
479 mflr r0 /* Get link register */
480 stwu r1, -12(r1) /* Save back chain and move SP */
481 stw r0, +16(r1) /* Save link register */
482 stw r4, +8(r1) /* save R4 */
483
484 addis r4, 0, 0xfe00 /* LED buffer is at 0xfe000000 */
485#if defined(CONFIG_W7OLMG) /* only on gateway, invert outputs */
486 xori r3,r3, 0xffff /* complement led code, active low */
487 sth r3, 0(r4) /* store first test value */
488 xori r3,r3, 0xffff /* complement led code, active low */
489#else /* if not gateway, then don't invert */
490 sth r3, 0(r4) /* store first test value */
491#endif
492
493 /* restore stack and return */
494 lwz r0, +16(r1) /* Get saved link register */
495 mtlr r0 /* Restore link register */
496 lwz r4, +8(r1) /* restore r4 */
497 addi r1, r1, +12 /* Remove frame from stack */
498 blr /* Return to calling function */
499
500get_led:
501 /* save the return info on stack */
502 mflr r0 /* Get link register */
503 stwu r1, -12(r1) /* Save back chain and move SP */
504 stw r0, +16(r1) /* Save link register */
505 stw r4, +8(r1) /* save R4 */
506
507 addis r4, 0, 0xfe00 /* LED buffer is at 0xfe000000 */
508 lhz r3, 0(r4) /* store first test value */
509#if defined(CONFIG_W7OLMG) /* only on gateway, invert inputs */
510 xori r3,r3, 0xffff /* complement led code, active low */
511#endif
512
513 /* restore stack and return */
514 lwz r0, +16(r1) /* Get saved link register */
515 mtlr r0 /* Restore link register */
516 lwz r4, +8(r1) /* restore r4 */
517 addi r1, r1, +12 /* Remove frame from stack */
518 blr /* Return to calling function */
519
520log_err: /* output the error and hang the board ( for now ) */
521 /* save the return info on stack */
522 mflr r0 /* Get link register */
523 stwu r1, -12(r1) /* Save back chain and move SP */
524 stw r0, +16(r1) /* Save link register */
525 stw r3, +8(r1) /* save a copy of error code */
526 bl set_led /* set the led pattern */
527 GET_GOT /* get GOT address in r14 */
528 lwz r3,GOT(err_str) /* get address of string */
529 bl post_puts /* output the warning string */
530 lwz r3, +8(r1) /* get error code */
531 addi r4, 0, 2 /* set disp length to 2 nibbles */
532 bl disp_hex /* output the error code */
533 lwz r3,GOT(end_str) /* get address of string */
534 bl post_puts /* output the warning string */
535halt:
536 b halt /* hang */
537
538 /* restore stack and return */
539 lwz r0, +16(r1) /* Get saved link register */
540 mtlr r0 /* Restore link register */
541 addi r1, r1, +12 /* Remove frame from stack */
542 blr /* Return to calling function */
543
544log_warn: /* output a warning, then continue with operations */
545 /* save the return info on stack */
546 mflr r0 /* Get link register */
547 stwu r1, -16(r1) /* Save back chain and move SP */
548 stw r0, +20(r1) /* Save link register */
549 stw r3, +8(r1) /* save a copy of error code */
550 stw r14, +12(r1) /* save a copy of r14 (used by GOT) */
551
552 bl set_led /* set the led pattern */
553 GET_GOT /* get GOT address in r14 */
554 lwz r3,GOT(warn_str) /* get address of string */
555 bl post_puts /* output the warning string */
556 lwz r3, +8(r1) /* get error code */
557 addi r4, 0, 2 /* set disp length to 2 nibbles */
558 bl disp_hex /* output the error code */
559 lwz r3,GOT(end_str) /* get address of string */
560 bl post_puts /* output the warning string */
561
562 addis r3, 0, 64 /* has a long delay */
563 mtctr r3
564log_2:
565 WATCHDOG_RESET /* this keeps dog from barking, */
566 /* and takes time */
567 bdnz log_2 /* loop till time expires */
568
569 /* restore stack and return */
570 lwz r0, +20(r1) /* Get saved link register */
571 lwz r14, +12(r1) /* restore r14 */
572 mtlr r0 /* Restore link register */
573 addi r1, r1, +16 /* Remove frame from stack */
574 blr /* Return to calling function */
575
576/*******************************************************************
577 * temp_uart_init
578 * Temporary UART initialization routine
579 * Sets up UART0 to run at 9600N81 off of the internal clock.
580 * R3-R4 are used.
581 ******************************************************************/
582temp_uart_init:
583 /* save the return info on stack */
584 mflr r0 /* Get link register */
585 stwu r1, -8(r1) /* Save back chain and move SP */
586 stw r0, +12(r1) /* Save link register */
587
588 addis r3, 0, 0xef60
589 ori r3, r3, 0x0303 /* r3 = UART0_LCR */
590 addi r4, 0, 0x83 /* n81 format, divisor regs enabled */
591 stb r4, 0(r3)
592
593 /* set baud rate to use internal clock,
594 baud = (200e6/16)/31/42 = 9600 */
595
596 addis r3, 0, 0xef60 /* Address of baud divisor reg */
597 ori r3, r3, 0x0300 /* UART0_DLM */
598 addi r4, 0, +42 /* uart baud divisor LSB = 93 */
599 stb r4, 0(r3) /* baud = (200 /16)/14/93 */
600
601 addi r3, r3, 0x0001 /* uart baud divisor addr */
602 addi r4, 0, 0
603 stb r4, 0(r3) /* Divisor Latch MSB = 0 */
604
605 addis r3, 0, 0xef60
606 ori r3, r3, 0x0303 /* r3 = UART0_LCR */
607 addi r4, 0, 0x03 /* n81 format, tx/rx regs enabled */
608 stb r4, 0(r3)
609
610 /* output a few line feeds */
611 addi r3, 0, '\n' /* load line feed */
612 bl post_putc /* output the char */
613 addi r3, 0, '\n' /* load line feed */
614 bl post_putc /* output the char */
615
616 /* restore stack and return */
617 lwz r0, +12(r1) /* Get saved link register */
618 mtlr r0 /* Restore link register */
619 addi r1, r1, +8 /* Remove frame from stack */
620 blr /* Return to calling function */
621
622/**********************************************************************
623 ** post_putc
624 ** outputs charactor in R3
625 ** r3 returns the error code ( -1 if there is an error )
626 *********************************************************************/
627
628post_putc:
629
630 /* save the return info on stack */
631 mflr r0 /* Get link register */
632 stwu r1, -20(r1) /* Save back chain and move SP */
633 stw r0, +24(r1) /* Save link register */
634 stmw r29, 8(r1) /* save r29 - r31 on stack
635 r31 - uart base address
636 r30 - delay counter
637 r29 - scratch reg */
638
639 addis r31, 0, 0xef60 /* Point to uart base */
640 ori r31, r31, 0x0300
641 addis r30, 0, 152 /* Load about 10,000,000 ticks. */
642pputc_lp:
643 lbz r29, 5(r31) /* Read Line Status Register */
644 andi. r29, r29, 0x20 /* Check THRE status */
645 bne thre_set /* Branch if FIFO empty */
646 addic. r30, r30, -1 /* Decrement and check if empty. */
647 bne pputc_lp /* Try, try again */
648 addi r3, 0, -1 /* Load error code for timeout */
649 b pputc_done /* Bail out with error code set */
650thre_set:
651 stb r3, 0(r31) /* Store character to UART */
652 addi r3, 0, 0 /* clear error code */
653pputc_done:
654 lmw r29, 8(r1) /*restore r29 - r31 from stack */
655 lwz r0, +24(r1) /* Get saved link register */
656 addi r1, r1, +20 /* Remove frame from stack */
657 mtlr r0 /* Restore link register */
658 blr /* Return to calling function */
659
660
661/****************************************************************
662 post_puts
663 Accepts a null-terminated string pointed to by R3
664 Outputs to the serial port until 0x00 is found.
665 r3 returns the error code ( -1 if there is an error )
666*****************************************************************/
667post_puts:
668
669 /* save the return info on stack */
670 mflr r0 /* Get link register */
671 stwu r1, -12(r1) /* Save back chain and move SP */
672 stw r0, +16(r1) /* Save link register */
673 stw r31, 8(r1) /* save r31 - char pointer */
674
675 addi r31, r3, 0 /* move pointer to R31 */
676pputs_nxt:
677 lbz r3, 0(r31) /* Get next character */
678 addic. r3, r3, 0 /* Check for zero */
679 beq pputs_term /* bail out if zero */
680 bl post_putc /* output the char */
681 addic. r3, r3, 0 /* check for error */
682 bne pputs_err
683 addi r31, r31, 1 /* point to next char */
684 b pputs_nxt /* loop till term */
685pputs_err:
686 addi r3, 0, -1 /* set error code */
687 b pputs_end /* were outa here */
688pputs_term:
689 addi r3, 0, 1 /* set success code */
690 /* restore stack and return */
691pputs_end:
692 lwz r31, 8(r1) /* restore r27 - r31 from stack */
693 lwz r0, +16(r1) /* Get saved link register */
694 addi r1, r1, +12 /* Remove frame from stack */
695 mtlr r0 /* Restore link register */
696 blr /* Return to calling function */
697
698
699
700/********************************************************************
701 ***** disp_hex
702 ***** Routine to display a hex value from a register.
703 ***** R3 is value to display
704 ***** R4 is number of nibbles to display ie 2 for byte 8 for (long)word
705 ***** Returns -1 in R3 if there is an error ( ie serial port hangs )
706 ***** Returns 0 in R3 if no error
707 *******************************************************************/
708disp_hex:
709 /* save the return info on stack */
710 mflr r0 /* Get link register */
711 stwu r1, -16(r1) /* Save back chain and move SP */
712 stw r0, +20(r1) /* Save link register */
713 stmw r30, 8(r1) /* save r30 - r31 on stack */
714 /* r31 output char */
715 /* r30 uart base address */
716 addi r30, 0, 8 /* Go through 8 nibbles. */
717 addi r31, r3, 0
718pputh_nxt:
719 rlwinm r31, r31, 4, 0, 31 /* Rotate next nibble into position */
720 andi. r3, r31, 0x0f /* Get nibble. */
721 addi r3, r3, 0x30 /* Add zero's ASCII code. */
722 cmpwi r3, 0x03a
723 blt pputh_out
724 addi r3, r3, 0x07 /* 0x27 for lower case. */
725pputh_out:
726 cmpw r30, r4
727 bgt pputh_skip
728 bl post_putc
729 addic. r3, r3, 0 /* check for error */
730 bne pputh_err
731pputh_skip:
732 addic. r30, r30, -1
733 bne pputh_nxt
734 xor r3, r3, r3 /* Clear error code */
735 b pputh_done
736pputh_err:
737 addi r3, 0, -1 /* set error code */
738pputh_done:
739 /* restore stack and return */
740 lmw r30, 8(r1) /* restore r30 - r31 from stack */
741 lwz r0, +20(r1) /* Get saved link register */
742 addi r1, r1, +16 /* Remove frame from stack */
743 mtlr r0 /* Restore link register */
744 blr /* Return to calling function */
745