checker.c

Description | Download | Table of Contents | Modules | Compound List | File List | Functions


Overview
Compiler
Documentation
Examples
Misc
Help
IDE & Tools

Download
Install

Links
Projects






00001 /* checker.c -- Check the memory and return the target board memory layout
00002    Copyright 2000, 2001 Free Software Foundation, Inc.
00003    Written by Stephane Carrez (stcarrez@worldnet.fr)
00004 
00005 This file is part of GTAM.
00006 
00007 GTAM is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2, or (at your option)
00010 any later version.
00011 
00012 GTAM is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with GTAM; see the file COPYING.  If not, write to
00019 the Free Software Foundation, 59 Temple Place - Suite 330,
00020 Boston, MA 02111-1307, USA.  */
00021 
00091 #include <sys/ports.h>
00092 
00093 static void put_addr(unsigned short value);
00094 static void put_char(unsigned char c);
00095 
00096 static inline void
00097 reboot()
00098 {
00099 #ifndef NO_REBOOT
00100   /* The 'func' type is marked as 'noreturn' to optimize the
00101      generated code.  */
00102   typedef void __attribute__ ((noreturn)) (* func)();
00103 
00104   func handler;
00105 
00106   set_bus_single_chip ();
00107 
00108   /* To reboot, get the reset vector and go to the start of the ROM.  */
00109   handler = *((func*) 0xbffe);
00110   handler ();
00111 #endif
00112 }
00113 
00114 void
00115 _start()
00116 {
00117   unsigned char c;
00118   volatile unsigned char* addr;
00119   unsigned char nok = 1;
00120 
00121   set_bus_expanded ();
00122 
00123   /* Start at end of the RAM.  The algorithm is basic and destructive.
00124      We can't apply it to the RAM where this program is mapped.  */
00125   addr = (volatile unsigned char*) 0x0ff;
00126   while (1)
00127     {
00128       addr++;
00129 
00130       /* If we reached the end of memory space, flush the SCI by writing
00131          spurious characters and go back to the ROM.  If we don't print
00132          some characters, the BREAK generated by the ROM can eat the
00133          last byte.  */
00134       if (addr == (unsigned char*) 0)
00135         {
00136           for (c = 5; --c != 0; )
00137             put_char ('\n');
00138 
00139           reboot ();
00140 
00141           /* Skip the .page0 if reboot() is not supported.
00142              Otherwise, this code is not reached and not generated.  */
00143           addr += 0xff;
00144           continue;
00145         }
00146 
00147       /* Skip the IO registers.  */
00148       if (addr == _io_ports)
00149         {
00150           addr += M6811_IO_SIZE;
00151           continue;
00152         }
00153 
00154       /* Check the memory by inverting its content.
00155          If this succeeds, we have some kind of RAM.  */
00156       c = ~*addr;
00157       *addr = c;
00158       if (c != *addr)
00159         {
00160           if (nok)
00161             continue;
00162 
00163           /* Beginning of non-RAM bank.  */
00164           nok = 1;
00165           put_char ('-');
00166           put_addr ((unsigned short) addr);
00167         }
00168       else
00169         {
00170           if (nok == 0)
00171              continue;
00172 
00173           /* Beginning of RAM bank.  */
00174           nok = 0;
00175           put_char ('+');
00176           put_addr ((unsigned short) addr);
00177         }
00178     }
00179 }
00180 
00181 
00182 /* Translate and print the 8-bit value in hexadecimal on the serial line.  */
00183 static void
00184 put_hex(unsigned short value)
00185 {
00186   put_char ("0123456789ABCDEF"[(value >> 4) & 0x0F]);
00187   put_char ("0123456789ABCDEF"[value & 0x0F]);
00188 }
00189 
00190 
00191 /* Translate and print the address on the serial line.  */
00192 static void
00193 put_addr(unsigned short value)
00194 {
00195   put_hex (value >> 8);
00196   put_hex (value);
00197   put_char ('\n');
00198 }
00199 
00200 
00201 /* Write a character on the serial line.  */
00202 static void
00203 put_char(unsigned char c)
00204 {
00205   while (!(_io_ports[M6811_SCSR] & M6811_TDRE))
00206     continue;
00207 
00208   _io_ports[M6811_SCDR] = c;
00209   _io_ports[M6811_SCCR2] |= M6811_TE;
00210 }

Description | Download | Table of Contents | Modules | Compound List | File List | Functions

    Last modified,
    Apr 16, 2001
[ Copying ]     [ Feedback to Stephane.Carrez@worldnet.fr ]