Hi,
Having a bit of a tidy up and found the src to the various ram loaders i
have written over the years - no objections i will commit.
Cheers
Spen
>From 5c25c2cbec8d4a7966ccb18b8dadbde5da59b4b9 Mon Sep 17 00:00:00 2001
From: Spencer Oliver <ntfr...@users.sourceforge.net>
Date: Wed, 27 Oct 2010 11:03:16 +0100
Subject: [PATCH] contrib: add ram loader src code
Add src code for ram loaders to contrib directory.
Signed-off-by: Spencer Oliver <ntfr...@users.sourceforge.net>
---
contrib/loaders/checksum/armv4_5_crc.s | 58 ++++++++++++++++++++++++++++
contrib/loaders/checksum/armv7m_crc.s | 66 ++++++++++++++++++++++++++++++++
contrib/loaders/flash/stellaris.s | 66 ++++++++++++++++++++++++++++++++
contrib/loaders/flash/stm32x.s | 52 +++++++++++++++++++++++++
contrib/loaders/flash/str7x.s | 57 +++++++++++++++++++++++++++
contrib/loaders/flash/str9x.s | 54 ++++++++++++++++++++++++++
6 files changed, 353 insertions(+), 0 deletions(-)
create mode 100644 contrib/loaders/checksum/armv4_5_crc.s
create mode 100644 contrib/loaders/checksum/armv7m_crc.s
create mode 100644 contrib/loaders/flash/stellaris.s
create mode 100644 contrib/loaders/flash/stm32x.s
create mode 100644 contrib/loaders/flash/str7x.s
create mode 100644 contrib/loaders/flash/str9x.s
diff --git a/contrib/loaders/checksum/armv4_5_crc.s
b/contrib/loaders/checksum/armv4_5_crc.s
new file mode 100644
index 0000000..950a8d0
--- /dev/null
+++ b/contrib/loaders/checksum/armv4_5_crc.s
@@ -0,0 +1,58 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Spencer Oliver *
+ * s...@spen-soft.co.uk *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+/*
+ r0 - address in - crc out
+ r1 - char count
+*/
+
+ .text
+ .arm
+
+_start:
+main:
+ mov r2, r0
+ mov r0, #0xffffffff /* crc */
+ mov r3, r1
+ mov r4, #0
+ b ncomp
+nbyte:
+ ldrb r1, [r2, r4]
+ ldr r7, CRC32XOR
+ eor r0, r0, r1, asl #24
+ mov r5, #0
+loop:
+ cmp r0, #0
+ mov r6, r0, asl #1
+ add r5, r5, #1
+ mov r0, r6
+ eorlt r0, r6, r7
+ cmp r5, #8
+ bne loop
+ add r4, r4, #1
+ncomp:
+ cmp r4, r3
+ bne nbyte
+end:
+ bkpt #0
+
+CRC32XOR: .word 0x04c11db7
+
+ .end
diff --git a/contrib/loaders/checksum/armv7m_crc.s
b/contrib/loaders/checksum/armv7m_crc.s
new file mode 100644
index 0000000..e50db0a
--- /dev/null
+++ b/contrib/loaders/checksum/armv7m_crc.s
@@ -0,0 +1,66 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Spencer Oliver *
+ * s...@spen-soft.co.uk *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+/*
+ parameters:
+ r0 - address in - crc out
+ r1 - char count
+*/
+
+ .text
+ .syntax unified
+ .cpu cortex-m3
+ .thumb
+ .thumb_func
+
+ .align 2
+
+_start:
+main:
+ mov r2, r0
+ mov r0, #0xffffffff /* crc */
+ mov r3, r1
+ mov r4, #0
+ b ncomp
+nbyte:
+ ldrb r1, [r2, r4]
+
+ ldr r7, CRC32XOR
+ eor r0, r0, r1, asl #24
+ mov r5, #0
+loop:
+ cmp r0, #0
+ mov r6, r0, asl #1
+ add r5, r5, #1
+ mov r0, r6
+ it lt
+ eorlt r0, r6, r7
+ cmp r5, #8
+ bne loop
+
+ add r4, r4, #1
+ncomp:
+ cmp r4, r3
+ bne nbyte
+ bkpt #0
+
+CRC32XOR: .word 0x04c11db7
+
+ .end
diff --git a/contrib/loaders/flash/stellaris.s
b/contrib/loaders/flash/stellaris.s
new file mode 100644
index 0000000..166dd52
--- /dev/null
+++ b/contrib/loaders/flash/stellaris.s
@@ -0,0 +1,66 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Magnus Lundin *
+ * lun...@mlu.mine.nu *
+ * *
+ * Copyright (C) 2008 by Spencer Oliver *
+ * s...@spen-soft.co.uk *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+ .text
+ .syntax unified
+ .cpu cortex-m3
+ .thumb
+ .thumb_func
+ .align 2
+
+/*
+ Call with :
+ r0 = buffer address
+ r1 = destination address
+ r2 = bytecount (in) - endaddr (work)
+
+ Used registers:
+ r3 = pFLASH_CTRL_BASE
+ r4 = FLASHWRITECMD
+ r5 = #1
+ r6 = bytes written
+ r7 = temp reg
+*/
+
+write:
+ ldr r3,pFLASH_CTRL_BASE
+ ldr r4,FLASHWRITECMD
+ movs r5, 1
+ movs r6, #0
+mainloop:
+ str r1, [r3, #0]
+ ldr r7, [r0, r6]
+ str r7, [r3, #4]
+ str r4, [r3, #8]
+waitloop:
+ ldr r7, [r3, #8]
+ tst r7, r5
+ bne waitloop
+ adds r1, r1, #4
+ adds r6, r6, #4
+ cmp r6, r2
+ bne mainloop
+ bkpt #0
+
+pFLASH_CTRL_BASE: .word 0x400FD000
+FLASHWRITECMD: .word 0xA4420001
diff --git a/contrib/loaders/flash/stm32x.s b/contrib/loaders/flash/stm32x.s
new file mode 100644
index 0000000..dcf2b83
--- /dev/null
+++ b/contrib/loaders/flash/stm32x.s
@@ -0,0 +1,52 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Spencer Oliver *
+ * s...@spen-soft.co.uk *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+ .text
+ .arm
+
+/*
+ r0 - source address
+ r1 - target address
+ r2 - count (halfword-16bit)
+ r3 - result
+ r4 - temp
+ r5 - temp
+*/
+
+write:
+ ldr r4, STM32_FLASH_CR
+ ldr r5, STM32_FLASH_SR
+ mov r3, #1
+ str r3, [r4, #0]
+ ldrh r3, [r0], #2
+ strh r3, [r1], #2
+busy:
+ ldr r3, [r5, #0]
+ tst r3, #0x01
+ beq busy
+ tst r3, #0x14
+ bne exit
+ subs r2, r2, #1
+ bne write
+exit:
+ bkpt #0
+
+STM32_FLASH_CR: .word 0x40022010
+STM32_FLASH_SR: .word 0x4002200C
diff --git a/contrib/loaders/flash/str7x.s b/contrib/loaders/flash/str7x.s
new file mode 100644
index 0000000..fcdb007
--- /dev/null
+++ b/contrib/loaders/flash/str7x.s
@@ -0,0 +1,57 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Spencer Oliver *
+ * s...@spen-soft.co.uk *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+ .text
+ .arm
+ .section .init
+/*
+ r0 source address
+ r1 address
+ r2 FLASH_CR0
+ r3 dword count
+ r4 result
+ r5 busy mask
+*/
+
+write:
+ mov r4, #0x10000000 /* set DWPG bit */
+ str r4, [r2, #0x0] /* FLASH_CR0 */
+ str r1, [r2, #0x10] /* FLASH_AR */
+ ldr r4, [r0], #4 /* load data */
+ str r4, [r2, #0x8] /* FLASH_DR0 */
+ ldr r4, [r0], #4 /* load data */
+ str r4, [r2, #0xc] /* FLASH_DR1 */
+ mov r4, #0x90000000 /* set DWPG and WMS
bits */
+ str r4, [r2, #0x0] /* FLASH_CR0 */
+busy:
+ ldr r4, [r2, #0x0] /* FLASH_CR0 */
+ tst r4, r5
+ bne busy
+ ldr r4, [r2, #0x14] /* FLASH_ER */
+ tst r4, #0xff /* do we have
errors */
+ tsteq r4, #0x100 /* write protection set */
+ bne exit
+ add r1, r1, #0x8 /* next 8 bytes */
+ subs r3, r3, #1 /* decremment dword
count */
+ bne write
+exit:
+ b exit
+
+ .end
diff --git a/contrib/loaders/flash/str9x.s b/contrib/loaders/flash/str9x.s
new file mode 100644
index 0000000..9b15b3d
--- /dev/null
+++ b/contrib/loaders/flash/str9x.s
@@ -0,0 +1,54 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Spencer Oliver *
+ * s...@spen-soft.co.uk *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+ .text
+ .arm
+ .section .init
+/*
+ r0 source address (in)
+ r1 target address (in)
+ r2 word count (in)
+ r3 result (out)
+*/
+
+write:
+ bic r4, r1, #3 /* word address */
+ mov r3, #0x40 /* write command */
+ strh r3, [r4, #0]
+ ldrh r3, [r0], #2 /* read data */
+ strh r3, [r1], #2 /* write data */
+ mov r3, #0x70 /* status command */
+ strh r3, [r4, #0]
+busy:
+ ldrb r3, [r4, #0] /* status */
+ tst r3, #0x80
+ beq busy
+ mov r5, #0x50 /* clear status command
*/
+ strh r5, [r4, #0]
+ mov r5, #0xFF /* read array */
+ strh r5, [r4, #0]
+ tst r3, #0x12
+ bne exit
+ subs r2, r2, #1 /* decremment word count */
+ bne write
+exit:
+ bkpt #0
+
+ .end
--
1.7.1
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development