2012-05-22 16:59:27 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the libopencm3 project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net>
|
2012-05-22 19:55:50 +00:00
|
|
|
* Copyright (C) 2012 Michael Ossmann <mike@ossmann.com>
|
2012-05-22 16:59:27 +00:00
|
|
|
*
|
|
|
|
* This library is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-10-03 16:15:20 +00:00
|
|
|
#include <libopencm3/cm3/common.h>
|
2012-05-22 16:59:27 +00:00
|
|
|
|
2012-06-10 09:44:36 +00:00
|
|
|
extern unsigned _etext_ram, _text_ram, _etext_rom;
|
2012-05-22 16:59:27 +00:00
|
|
|
|
2014-01-19 23:51:14 +00:00
|
|
|
#define CREG_M4MEMMAP MMIO32((0x40043000U + 0x100))
|
2012-06-10 09:44:36 +00:00
|
|
|
|
2012-10-18 14:29:58 +00:00
|
|
|
static void pre_main(void)
|
2012-05-22 16:59:27 +00:00
|
|
|
{
|
|
|
|
volatile unsigned *src, *dest;
|
2012-09-03 17:49:47 +00:00
|
|
|
|
2012-06-10 09:44:36 +00:00
|
|
|
/* Copy the code from ROM to Real RAM (if enabled) */
|
2013-06-13 00:44:07 +00:00
|
|
|
if ((&_etext_ram-&_text_ram) > 0) {
|
2012-06-10 09:44:36 +00:00
|
|
|
src = &_etext_rom-(&_etext_ram-&_text_ram);
|
2013-06-13 00:44:07 +00:00
|
|
|
/* Change Shadow memory to ROM (for Debug Purpose in case Boot
|
|
|
|
* has not set correctly the M4MEMMAP because of debug)
|
|
|
|
*/
|
2012-06-12 23:05:49 +00:00
|
|
|
CREG_M4MEMMAP = (unsigned long)src;
|
|
|
|
|
2013-06-13 00:44:07 +00:00
|
|
|
for (dest = &_text_ram; dest < &_etext_ram; ) {
|
2012-06-10 09:44:36 +00:00
|
|
|
*dest++ = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Change Shadow memory to Real RAM */
|
|
|
|
CREG_M4MEMMAP = (unsigned long)&_text_ram;
|
|
|
|
|
|
|
|
/* Continue Execution in RAM */
|
|
|
|
}
|
2012-05-22 16:59:27 +00:00
|
|
|
}
|