Skip to contentSkip to conversation

Add MIPS arch support to barebox

PATCH In review Antony Pavlov 3 participants 10 messages Jun 30, 2011 – Jul 4, 2011

Subsystems (3)
lore
Share & tools
lore
#2 lore raw

PATCH v3 3/3 MIPS: add qemu malta board support to barebox

In reply to Antony Pavlov

The only supported peripheral is ns16550 serial port.

---
 arch/mips/Makefile                     |    1 +
 arch/mips/boards/qemu-malta/Kconfig    |    2 +
 arch/mips/boards/qemu-malta/Makefile   |    1 +
 arch/mips/boards/qemu-malta/config.h   |   19 ++++++++++
 arch/mips/boards/qemu-malta/serial.c   |   61 ++++++++++++++++++++++++++++++++
 arch/mips/configs/qemu-malta_defconfig |   45 +++++++++++++++++++++++
 arch/mips/mach-mti-malta/Kconfig       |    5 +++
 7 files changed, 134 insertions(+), 0 deletions(-)
 create mode 100644 arch/mips/boards/qemu-malta/Kconfig
 create mode 100644 arch/mips/boards/qemu-malta/Makefile
 create mode 100644 arch/mips/boards/qemu-malta/config.h
 create mode 100644 arch/mips/boards/qemu-malta/serial.c
 create mode 100644 arch/mips/configs/qemu-malta_defconfig
arch/mips/Makefile +1 -0
index 7bcc518..4a39af3 100644
@@ -35,6 +35,7 @@ endif
 LDFLAGS_barebox += -nostdlib
 
 machine-$(CONFIG_MACH_MIPS_MALTA)	:= mti-malta
+board-$(CONFIG_BOARD_QEMU_MALTA)	:= qemu-malta
 
 machdirs := $(patsubst %,arch/mips/mach-%/,$(machine-y))
 
arch/mips/boards/qemu-malta/Kconfig new file +2 -0
new file mode 100644
index 0000000..ab93116
@@ -0,0 +1,2 @@
+config BOARDINFO
+	default "qemu malta"
arch/mips/boards/qemu-malta/Makefile new file +1 -0
new file mode 100644
index 0000000..ff1a655
@@ -0,0 +1 @@
+obj-$(CONFIG_DRIVER_SERIAL_NS16550) += serial.o
arch/mips/boards/qemu-malta/config.h new file +19 -0
new file mode 100644
index 0000000..eb4ab08
@@ -0,0 +1,19 @@
+/*
+ * 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
+ *
+ */
+
+/* nothing special yet */
arch/mips/boards/qemu-malta/serial.c new file +61 -0

61 lines not on this page · raw message

arch/mips/configs/qemu-malta_defconfig new file +45 -0

45 lines not on this page · raw message

arch/mips/mach-mti-malta/Kconfig +5 -0
index c2ee6f3..ca5b879 100644
@@ -10,6 +10,11 @@ config DEBUG_LL
 choice
 	prompt "Board type"
 
+config BOARD_QEMU_MALTA
+	bool "qemu malta"
+
 endchoice
 
+source arch/mips/boards/qemu-malta/Kconfig
+
 endif
Signature · 7 lines
1.7.5.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#0 lore raw

PATCH v3 1/3 Add MIPS arch support to barebox

Barebox can use only uncached memory.

---
 arch/mips/Kconfig                   |  184 +++++++
 arch/mips/Makefile                  |   72 +++
 arch/mips/boot/Makefile             |    1 +
 arch/mips/boot/head.S               |  102 ++++
 arch/mips/include/asm/barebox.h     |   24 +
 arch/mips/include/asm/bitops.h      |   32 ++
 arch/mips/include/asm/byteorder.h   |   30 +
 arch/mips/include/asm/common.h      |   29 +
 arch/mips/include/asm/elf.h         |   30 +
 arch/mips/include/asm/io.h          |   73 +++
 arch/mips/include/asm/mipsregs.h    |  988 +++++++++++++++++++++++++++++++++++
 arch/mips/include/asm/module.h      |   36 ++
 arch/mips/include/asm/posix_types.h |   48 ++
 arch/mips/include/asm/regdef.h      |  100 ++++
 arch/mips/include/asm/sections.h    |    1 +
 arch/mips/include/asm/sgidefs.h     |   44 ++
 arch/mips/include/asm/string.h      |   31 ++
 arch/mips/include/asm/swab.h        |   59 ++
 arch/mips/include/asm/types.h       |   44 ++
 arch/mips/include/mach/debug_ll.h   |   35 ++
 arch/mips/lib/Makefile              |    6 +
 arch/mips/lib/ashldi3.c             |   27 +
 arch/mips/lib/ashrdi3.c             |   29 +
 arch/mips/lib/barebox.lds.S         |   76 +++
 arch/mips/lib/csrc-r4k.c            |   50 ++
 arch/mips/lib/libgcc.h              |   25 +
 arch/mips/lib/lshrdi3.c             |   27 +
 arch/mips/lib/memory.c              |   34 ++
 28 files changed, 2237 insertions(+), 0 deletions(-)
 create mode 100644 arch/mips/Kconfig
 create mode 100644 arch/mips/Makefile
 create mode 100644 arch/mips/boot/Makefile
 create mode 100644 arch/mips/boot/head.S
 create mode 100644 arch/mips/include/asm/barebox.h
 create mode 100644 arch/mips/include/asm/bitops.h
 create mode 100644 arch/mips/include/asm/byteorder.h
 create mode 100644 arch/mips/include/asm/common.h
 create mode 100644 arch/mips/include/asm/elf.h
 create mode 100644 arch/mips/include/asm/io.h
 create mode 100644 arch/mips/include/asm/mipsregs.h
 create mode 100644 arch/mips/include/asm/module.h
 create mode 100644 arch/mips/include/asm/posix_types.h
 create mode 100644 arch/mips/include/asm/regdef.h
 create mode 100644 arch/mips/include/asm/sections.h
 create mode 100644 arch/mips/include/asm/sgidefs.h
 create mode 100644 arch/mips/include/asm/string.h
 create mode 100644 arch/mips/include/asm/swab.h
 create mode 100644 arch/mips/include/asm/types.h
 create mode 100644 arch/mips/include/mach/debug_ll.h
 create mode 100644 arch/mips/lib/Makefile
 create mode 100644 arch/mips/lib/ashldi3.c
 create mode 100644 arch/mips/lib/ashrdi3.c
 create mode 100644 arch/mips/lib/barebox.lds.S
 create mode 100644 arch/mips/lib/csrc-r4k.c
 create mode 100644 arch/mips/lib/libgcc.h
 create mode 100644 arch/mips/lib/lshrdi3.c
 create mode 100644 arch/mips/lib/memory.c
arch/mips/Kconfig new file +184 -0
new file mode 100644
index 0000000..f35aa8c
@@ -0,0 +1,184 @@
+#
+#
+#
+config MIPS
+	bool
+	select HAS_KALLSYMS
+	select HAVE_CONFIGURABLE_MEMORY_LAYOUT
+	select HAVE_CONFIGURABLE_TEXT_BASE
+	default y
+
+config SYS_SUPPORTS_BIG_ENDIAN
+	bool
+
+config SYS_SUPPORTS_LITTLE_ENDIAN
+	bool
+
+config CSRC_R4K_LIB
+	bool
+
+config GENERIC_LINKER_SCRIPT
+	bool
+	default y
+
+#
+# Endianess selection.  Sufficiently obscure so many users don't know what to
+# answer,so we try hard to limit the available choices.  Also the use of a
+# choice statement should be more obvious to the user.
+#
+choice
+	prompt "Endianess selection"
+	help
+	  Some MIPS machines can be configured for either little or big endian
+	  byte order. These modes require different kernels and a different
+	  Linux distribution.  In general there is one preferred byteorder for a
+	  particular system but some systems are just as commonly used in the
+	  one or the other endianness.
+
+config CPU_BIG_ENDIAN
+	bool "Big endian"
+	depends on SYS_SUPPORTS_BIG_ENDIAN
+
+config CPU_LITTLE_ENDIAN
+	bool "Little endian"
+	depends on SYS_SUPPORTS_LITTLE_ENDIAN
+	help
+
+endchoice
+
+menu "CPU selection"
+
+choice
+	prompt "CPU selection"
+	default CPU_MIPS32_R2
+
+config CPU_MIPS32_R1
+	bool "MIPS32 Release 1"
+	depends on SYS_HAS_CPU_MIPS32_R1
+	select CPU_SUPPORTS_32BIT_KERNEL
+	help
+	  Choose this option to build a kernel for release 1 or later of the
+	  MIPS32 architecture.  Most modern embedded systems with a 32-bit
+	  MIPS processor are based on a MIPS32 processor.  If you know the
+	  specific type of processor in your system, choose those that one
+	  otherwise CPU_MIPS32_R1 is a safe bet for any MIPS32 system.
+	  Release 2 of the MIPS32 architecture is available since several
+	  years so chances are you even have a MIPS32 Release 2 processor
+	  in which case you should choose CPU_MIPS32_R2 instead for better
+	  performance.
+
+config CPU_MIPS32_R2
+	bool "MIPS32 Release 2"
+	depends on SYS_HAS_CPU_MIPS32_R2
+	select CPU_SUPPORTS_32BIT_KERNEL
+	help
+	  Choose this option to build a kernel for release 2 or later of the
+	  MIPS32 architecture.  Most modern embedded systems with a 32-bit
+	  MIPS processor are based on a MIPS32 processor.  If you know the
+	  specific type of processor in your system, choose those that one
+	  otherwise CPU_MIPS32_R1 is a safe bet for any MIPS32 system.
+
+config CPU_MIPS64_R1
+	bool "MIPS64 Release 1"
+	depends on SYS_HAS_CPU_MIPS64_R1
+	select CPU_SUPPORTS_32BIT_KERNEL
+	select CPU_SUPPORTS_64BIT_KERNEL
+	help
+	  Choose this option to build a kernel for release 1 or later of the
+	  MIPS64 architecture.  Many modern embedded systems with a 64-bit
+	  MIPS processor are based on a MIPS64 processor.  If you know the
+	  specific type of processor in your system, choose those that one
+	  otherwise CPU_MIPS64_R1 is a safe bet for any MIPS64 system.
+	  Release 2 of the MIPS64 architecture is available since several
+	  years so chances are you even have a MIPS64 Release 2 processor
+	  in which case you should choose CPU_MIPS64_R2 instead for better
+	  performance.
+
+config CPU_MIPS64_R2
+	bool "MIPS64 Release 2"
+	depends on SYS_HAS_CPU_MIPS64_R2
+	select CPU_SUPPORTS_32BIT_KERNEL
+	select CPU_SUPPORTS_64BIT_KERNEL
+	help
+	  Choose this option to build a kernel for release 2 or later of the
+	  MIPS64 architecture.  Many modern embedded systems with a 64-bit
+	  MIPS processor are based on a MIPS64 processor.  If you know the
+	  specific type of processor in your system, choose those that one
+	  otherwise CPU_MIPS64_R1 is a safe bet for any MIPS64 system.
+
+endchoice
+
+
+config SYS_HAS_CPU_MIPS32_R1
+	bool
+
+config SYS_HAS_CPU_MIPS32_R2
+	bool
+
+config SYS_HAS_CPU_MIPS64_R1
+	bool
+
+config SYS_HAS_CPU_MIPS64_R2
+	bool
+
+#
+# These two indicate any level of the MIPS32 and MIPS64 architecture
+#
+config CPU_MIPS32
+	bool
+	default y if CPU_MIPS32_R1 || CPU_MIPS32_R2
+
+config CPU_MIPS64
+	bool
+	default y if CPU_MIPS64_R1 || CPU_MIPS64_R2
+
+#
+# These two indicate the revision of the architecture, either Release 1 or Release 2
+#
+config CPU_MIPSR1
+	bool
+	default y if CPU_MIPS32_R1 || CPU_MIPS64_R1
+
+config CPU_MIPSR2
+	bool
+	default y if CPU_MIPS32_R2 || CPU_MIPS64_R2
+
+config SYS_SUPPORTS_32BIT_KERNEL
+	bool
+config SYS_SUPPORTS_64BIT_KERNEL
+	bool
+config CPU_SUPPORTS_32BIT_KERNEL
+	bool
+config CPU_SUPPORTS_64BIT_KERNEL
+	bool
+
+endmenu
+
+choice
+	prompt "Kernel code model"
+	help
+	  You should only select this option if you have a workload that
+	  actually benefits from 64-bit processing or if your machine has
+	  large memory.  You will only be presented a single option in this
+	  menu if your system does not support both 32-bit and 64-bit kernels.
+
+config 32BIT
+	bool "32-bit kernel"
+	depends on CPU_SUPPORTS_32BIT_KERNEL && SYS_SUPPORTS_32BIT_KERNEL
+	help
+	  Select this option if you want to build a 32-bit kernel.
+
+config 64BIT
+	bool "64-bit kernel"
+	depends on CPU_SUPPORTS_64BIT_KERNEL && SYS_SUPPORTS_64BIT_KERNEL
+	help
+	  Select this option if you want to build a 64-bit kernel.
+
+endchoice
+
+source common/Kconfig
+source commands/Kconfig
+source net/Kconfig
+source drivers/Kconfig
+source fs/Kconfig
+source lib/Kconfig
arch/mips/Makefile new file +72 -0

72 lines not on this page · raw message

arch/mips/boot/Makefile new file +1 -0
new file mode 100644
index 0000000..3340058
@@ -0,0 +1 @@
+obj-y += head.o
arch/mips/boot/head.S new file +102 -0

102 lines not on this page · raw message

arch/mips/include/asm/barebox.h new file +24 -0
new file mode 100644
index 0000000..b42c9ff
@@ -0,0 +1,24 @@
+/*
+ * 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
+ *
+ */
+
+#ifndef _ASM_MIPS_BAREBOX_H_
+#define _ASM_MIPS_BAREBOX_H_
+
+/* nothing special yet */
+
+#endif /* _ASM_MIPS_BAREBOX_H_ */
arch/mips/include/asm/bitops.h new file +32 -0
new file mode 100644
index 0000000..36d34b6
@@ -0,0 +1,32 @@
+/*
+ * 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
+ *
+ */
+
+/**
+ * @file
+ * @brief mips bit operations
+ *
+ * This file is required only to make all sources happy including
+ * 'linux/bitops.h'
+ */
+
+#ifndef _ASM_MIPS_BITOPS_H_
+#define _ASM_MIPS_BITOPS_H_
+
+/* nothing special yet */
+
+#endif /* _ASM_MIPS_BITOPS_H_ */
arch/mips/include/asm/byteorder.h new file +30 -0
new file mode 100644
index 0000000..5fcdd9f
@@ -0,0 +1,30 @@
+/*
+ * 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
+ *
+ */
+
+/**
+ * @file
+ * @brief mips endianess declaration
+ */
+
+#ifndef __ASM_MIPS_BYTEORDER_H
+#define __ASM_MIPS_BYTEORDER_H
+
+#include <asm/types.h>
+#include <linux/byteorder/big_endian.h>
+
+#endif
arch/mips/include/asm/common.h new file +29 -0
new file mode 100644
index 0000000..f0aef01
@@ -0,0 +1,29 @@
+/*
+ * 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
+ *
+ */
+
+/**
+ * @file
+ * @brief mips common declarations
+ */
+
+#ifndef _ASM_MIPS_COMMON_H_
+#define _ASM_MIPS_COMMON_H_
+
+void mips_machine_restart(void);
+
+#endif /* _ASM_MIPS_COMMON_H_ */
arch/mips/include/asm/elf.h new file +30 -0
new file mode 100644
index 0000000..d88863d
@@ -0,0 +1,30 @@
+/*
+ * 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
+ *
+ */
+
+/**
+ * @file
+ * @brief mips specific elf information
+ *
+ */
+
+#ifndef _ASM_MIPS_ELF_H
+#define _ASM_MIPS_ELF_H
+
+#define ELF_CLASS ELFCLASS32
+
+#endif /* _ASM_MIPS_ELF_H */
arch/mips/include/asm/io.h new file +73 -0

73 lines not on this page · raw message

arch/mips/include/asm/mipsregs.h new file +988 -0

988 lines not on this page · raw message

arch/mips/include/asm/module.h new file +36 -0
new file mode 100644
index 0000000..0463565
@@ -0,0 +1,36 @@
+/*
+ * 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
+ *
+ */
+
+/**
+ * @file
+ * @brief mips module support
+ *
+ */
+
+#ifndef _ASM_MIPS_MODULE_H_
+#define _ASM_MIPS_MODULE_H_
+
+struct mod_arch_specific
+{
+        int foo;
+};
+
+#define Elf_Shdr        Elf32_Shdr
+#define Elf_Ehdr        Elf32_Ehdr
+
+#endif /* _ASM_MIPS_MODULE_H_ */
arch/mips/include/asm/posix_types.h new file +48 -0

48 lines not on this page · raw message

arch/mips/include/asm/regdef.h new file +100 -0

100 lines not on this page · raw message

arch/mips/include/asm/sections.h new file +1 -0
new file mode 100644
index 0000000..2b8c516
@@ -0,0 +1 @@
+#include <asm-generic/sections.h>
arch/mips/include/asm/sgidefs.h new file +44 -0

44 lines not on this page · raw message

arch/mips/include/asm/string.h new file +31 -0
new file mode 100644
index 0000000..9e334a2
@@ -0,0 +1,31 @@
+/*
+ * 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
+ *
+ */
+
+/**
+ * @file
+ * @brief mips specific string optimizations
+ *
+ * Thanks to the Linux kernel here we can add many micro optimized string
+ * functions. But currently it makes no sense, to do so.
+ */
+#ifndef __ASM_MIPS_STRING_H
+#define __ASM_MIPS_STRING_H
+
+/* nothing special yet */
+
+#endif
arch/mips/include/asm/swab.h new file +59 -0

59 lines not on this page · raw message

arch/mips/include/asm/types.h new file +44 -0

44 lines not on this page · raw message

arch/mips/include/mach/debug_ll.h new file +35 -0
new file mode 100644
index 0000000..9fff7be
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2008 Carsten Schlote <[email protected]>
+ * See file CREDITS for list of people who contributed to this project.
+ *
+ * This file is part of barebox.
+ *
+ * barebox 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * barebox 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 barebox.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/** @file
+ *  This File contains declaration for early output support
+ */
+#ifndef __INCLUDE_ARCH_DEBUG_LL_H__
+#define   __INCLUDE_ARCH_DEBUG_LL_H__
+
+#include <asm/io.h>
+#include <mach/hardware.h>
+
+extern __inline__ void putc( char ch )
+{
+	writeb(ch, DEBUG_LL_UART_ADDR);
+}
+
+#endif  /* __INCLUDE_ARCH_DEBUG_LL_H__ */
arch/mips/lib/Makefile new file +6 -0
new file mode 100644
index 0000000..67e4e8a
@@ -0,0 +1,6 @@
+extra-$(CONFIG_GENERIC_LINKER_SCRIPT) += barebox.lds
+obj-$(CONFIG_CSRC_R4K_LIB) += csrc-r4k.o
+obj-y += lshrdi3.o
+obj-y += ashldi3.o
+obj-y += ashrdi3.o
+obj-y += memory.o
arch/mips/lib/ashldi3.c new file +27 -0
new file mode 100644
index 0000000..461450a
@@ -0,0 +1,27 @@
+#include "libgcc.h"
+
+long long __ashldi3(long long u, word_type b)
+{
+	DWunion uu, w;
+	word_type bm;
+
+	if (b == 0)
+		return u;
+
+	uu.ll = u;
+	bm = 32 - b;
+
+	if (bm <= 0) {
+		w.s.low = 0;
+		w.s.high = (unsigned int) uu.s.low << -bm;
+	} else {
+		const unsigned int carries = (unsigned int) uu.s.low >> bm;
+
+		w.s.low = (unsigned int) uu.s.low << b;
+		w.s.high = ((unsigned int) uu.s.high << b) | carries;
+	}
+
+	return w.ll;
+}
+
+EXPORT_SYMBOL(__ashldi3);
arch/mips/lib/ashrdi3.c new file +29 -0
new file mode 100644
index 0000000..a0d005b
@@ -0,0 +1,29 @@
+#include "libgcc.h"
+
+long long __ashrdi3(long long u, word_type b)
+{
+	DWunion uu, w;
+	word_type bm;
+
+	if (b == 0)
+		return u;
+
+	uu.ll = u;
+	bm = 32 - b;
+
+	if (bm <= 0) {
+		/* w.s.high = 1..1 or 0..0 */
+		w.s.high =
+		    uu.s.high >> 31;
+		w.s.low = uu.s.high >> -bm;
+	} else {
+		const unsigned int carries = (unsigned int) uu.s.high << bm;
+
+		w.s.high = uu.s.high >> b;
+		w.s.low = ((unsigned int) uu.s.low >> b) | carries;
+	}
+
+	return w.ll;
+}
+
+EXPORT_SYMBOL(__ashrdi3);
arch/mips/lib/barebox.lds.S new file +76 -0

76 lines not on this page · raw message

arch/mips/lib/csrc-r4k.c new file +50 -0

50 lines not on this page · raw message

arch/mips/lib/libgcc.h new file +25 -0
new file mode 100644
index 0000000..05909d5
@@ -0,0 +1,25 @@
+#ifndef __ASM_LIBGCC_H
+#define __ASM_LIBGCC_H
+
+#include <asm/byteorder.h>
+
+typedef int word_type __attribute__ ((mode (__word__)));
+
+#ifdef __BIG_ENDIAN
+struct DWstruct {
+	int high, low;
+};
+#elif defined(__LITTLE_ENDIAN)
+struct DWstruct {
+	int low, high;
+};
+#else
+#error I feel sick.
+#endif
+
+typedef union {
+	struct DWstruct s;
+	long long ll;
+} DWunion;
+
+#endif /* __ASM_LIBGCC_H */
arch/mips/lib/lshrdi3.c new file +27 -0
new file mode 100644
index 0000000..154757c
@@ -0,0 +1,27 @@
+#include "libgcc.h"
+
+long long __lshrdi3(long long u, word_type b)
+{
+	DWunion uu, w;
+	word_type bm;
+
+	if (b == 0)
+		return u;
+
+	uu.ll = u;
+	bm = 32 - b;
+
+	if (bm <= 0) {
+		w.s.high = 0;
+		w.s.low = (unsigned int) uu.s.high >> -bm;
+	} else {
+		const unsigned int carries = (unsigned int) uu.s.high << bm;
+
+		w.s.high = (unsigned int) uu.s.high >> b;
+		w.s.low = ((unsigned int) uu.s.low >> b) | carries;
+	}
+
+	return w.ll;
+}
+
+EXPORT_SYMBOL(__lshrdi3);
arch/mips/lib/memory.c new file +34 -0
new file mode 100644
index 0000000..0adb24b
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2011 Antony Pavlov <[email protected]>
+ * See file CREDITS for list of people who contributed to this project.
+ *
+ * This file is part of barebox.
+ *
+ * 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
+ */
+
+#include <common.h>
+#include <init.h>
+#include <mem_malloc.h>
+#include <asm-generic/memory_layout.h>
+
+static int mips_mem_malloc_init(void)
+{
+	mem_malloc_init((void *)MALLOC_BASE,
+			(void *)(MALLOC_BASE + MALLOC_SIZE));
+	return 0;
+}
+core_initcall(mips_mem_malloc_init);
Signature · 7 lines
1.7.5.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH v3 2/3 MIPS: add Malta machine support to barebox

The machine uses only big-endian mode.
Only supported peripheral is serial port.
The machine supports only MIPS32 CPUs.

---
 arch/mips/Kconfig                                |   21 +++++++++++++
 arch/mips/Makefile                               |    2 +
 arch/mips/mach-mti-malta/Kconfig                 |   15 +++++++++
 arch/mips/mach-mti-malta/Makefile                |    1 +
 arch/mips/mach-mti-malta/include/mach/hardware.h |   32 +++++++++++++++++++
 arch/mips/mach-mti-malta/reset.c                 |   36 ++++++++++++++++++++++
 6 files changed, 107 insertions(+), 0 deletions(-)
 create mode 100644 arch/mips/mach-mti-malta/Kconfig
 create mode 100644 arch/mips/mach-mti-malta/Makefile
 create mode 100644 arch/mips/mach-mti-malta/include/mach/hardware.h
 create mode 100644 arch/mips/mach-mti-malta/reset.c
arch/mips/Kconfig +21 -0
index f35aa8c..c2834eb 100644
@@ -21,6 +21,27 @@ config GENERIC_LINKER_SCRIPT
 	bool
 	default y
 
+menu "Machine selection"
+
+choice
+	prompt "System type"
+	default MACH_MIPS_MALTA
+
+config MACH_MIPS_MALTA
+	bool "MIPS Malta"
+	select CSRC_R4K_LIB
+	select DRIVER_SERIAL_NS16550
+	select SYS_HAS_CPU_MIPS32_R1
+	select SYS_HAS_CPU_MIPS32_R2
+	select SYS_SUPPORTS_32BIT_KERNEL
+	select SYS_SUPPORTS_BIG_ENDIAN
+
+endchoice
+
+source arch/mips/mach-mti-malta/Kconfig
+
+endmenu
+
 #
 # Endianess selection.  Sufficiently obscure so many users don't know what to
 # answer,so we try hard to limit the available choices.  Also the use of a
arch/mips/Makefile +2 -0
index 34ac8ad..7bcc518 100644
@@ -34,6 +34,8 @@ endif
 
 LDFLAGS_barebox += -nostdlib
 
+machine-$(CONFIG_MACH_MIPS_MALTA)	:= mti-malta
+
 machdirs := $(patsubst %,arch/mips/mach-%/,$(machine-y))
 
 ifeq ($(KBUILD_SRC),)
arch/mips/mach-mti-malta/Kconfig new file +15 -0
new file mode 100644
index 0000000..c2ee6f3
@@ -0,0 +1,15 @@
+if MACH_MIPS_MALTA
+
+config ARCH_TEXT_BASE
+        hex
+        default 0xa0800000
+
+config DEBUG_LL
+	bool "DEBUG_LL messages"
+
+choice
+	prompt "Board type"
+
+endchoice
+
+endif
arch/mips/mach-mti-malta/Makefile new file +1 -0
new file mode 100644
index 0000000..f3cc668
@@ -0,0 +1 @@
+obj-y += reset.o
arch/mips/mach-mti-malta/include/mach/hardware.h new file +32 -0
new file mode 100644
index 0000000..42e8116
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2011 Antony Pavlov <[email protected]>
+ * See file CREDITS for list of people who contributed to this project.
+ *
+ * This file is part of barebox.
+ *
+ * barebox 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * barebox 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 barebox.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __INCLUDE_ARCH_HARDWARE_H__
+#define   __INCLUDE_ARCH_HARDWARE_H__
+
+#define DEBUG_LL_UART_ADDR	0xb00003f8
+
+/*
+ * Reset register.
+ */
+#define SOFTRES_REG	0xbf000500
+#define GORESET		0x42
+
+#endif  /* __INCLUDE_ARCH_HARDWARE_H__ */
arch/mips/mach-mti-malta/reset.c new file +36 -0
new file mode 100644
index 0000000..3fcf7aa
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2011 Antony Pavlov <[email protected]>
+ *
+ * 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
+ *
+ */
+
+/**
+ * @file
+ * @brief Resetting an CPU
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <mach/hardware.h>
+
+void __noreturn reset_cpu(ulong addr)
+{
+	__raw_writel(GORESET, (char *)SOFTRES_REG);
+	while (1);
+	/*NOTREACHED*/
+}
+EXPORT_SYMBOL(reset_cpu);
Signature · 7 lines
1.7.5.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw
In reply to Antony Pavlov
Quoted 2 lines

+ *
+ * Copyright (c) 2003 Wolfgang Denk <[email protected]>

no need if u use the relocate and stack setup of Shinya-san

Quoted 23 lines

+ * Further modifications by Antony Pavlov
+ * Used code written by Shinya Kuribayashi <[email protected]>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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
+ */

arch/mips/boot/head.S new file +2 -0
+
+#include <asm/regdef.h>

arch/mips/boot/head.S line 37

Quoted 10 lines
arch/mips/boot/head.S new file +10 -0
+#include <asm/mipsregs.h>
+#include <asm-generic/memory_layout.h>
+
+	.set noreorder
+        .text
+	.section ".text_bare_init"
+        .globl _start
+	.align 4
+
+_start:

here the EXPORT

IIRC we will need to preserve ra for NMI case

please use the comment of Shinya-san they are realy good

Quoted 12 lines
arch/mips/boot/head.S new file +12 -0
+	/* Clear watch registers */
+	mtc0	zero, CP0_WATCHLO
+	mtc0	zero, CP0_WATCHHI
+
+	/* STATUS register: disable interrupts */
+	mfc0	k0, CP0_STATUS
+	li	k1, ~ST0_IE
+	and	k0, k1
+	mtc0	k0, CP0_STATUS
+
+	/* CAUSE register */
+	mtc0	zero, CP0_CAUSE

arch/mips/boot/head.S line 59

Quoted 10 lines
arch/mips/boot/head.S new file +10 -0
+
+	/* Init Timer */
+	mtc0	zero, CP0_COUNT
+	mtc0	zero, CP0_COMPARE
+
+	/* Compute _start load address */
+	bal	compute_load_address
+	 nop
+
+compute_load_address:

why don't you use the relocate from Shinya-san?

Quoted 21 lines
arch/mips/boot/head.S new file +21 -0
+	move	a0, ra
+	and	a0, 0xffff0000		/* Mask off lower bits: a0 <- load address (souce start) */
+
+	la	a1, _start		/* RAM start address */
+
+	la	t0, _start
+	la	t1, __bss_start
+	subu	t2, t1, t0			# t2 <- size of barebox
+	addu	a2, a0, t2			# a2 <- source end address
+
+copy_to_link_address:
+	b	2f
+	sltu	v0, a0, a2
+1:	addiu	a0, a0, 4
+	sw	v0, (a1)
+	addiu	a1, a1, 4
+	sltu	v0, a0, a2
+2:	bnezl	v0, 1b
+	lw	v0, (a0)
+
+clear_bss:

arch/mips/boot/head.S line 90

Quoted 10 lines
arch/mips/boot/head.S new file +10 -0
+	la	t0, __bss_start
+	sw	zero, (t0)
+	la	t1, _end - 4
+1:
+	addiu	t0, 4
+	sw	zero, (t0)
+	bne	t0, t1, 1b
+	 nop
+
+stack_setup:

his stack setup is more clean

arch/mips/boot/head.S line 102

Quoted 12 lines
arch/mips/boot/head.S new file +12 -0
+	la	sp, STACK_BASE + STACK_SIZE
+	addiu	sp, -32			# init stack pointer
+
+	la	v0, start_barebox
+        jal     v0
+	 nop
+
+	/* No return */
+
+__error:
+	b __error
+	 nop

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw
Quoted 9 lines · On Fri, 1 Jul 2011 02:28:15 +0200 Jean-Christophe PLAGNIOL-VILLARD…

arch/mips/boot/head.S line 37

Quoted 8 lines
arch/mips/boot/head.S new file +8 -0
+
+	.set noreorder
+        .text
+	.section ".text_bare_init"
+        .globl _start
+	.align 4
+
+_start:

here the EXPORT

EXPORT(_start)? Ok.

Quoted 1 line

IIRC we will need to preserve ra for NMI case

How this preserved value can be used?

We have no need to preserve ra because we have no full-grown exception handlers.

Quoted 6 lines

arch/mips/boot/head.S line 59

Quoted 5 lines
arch/mips/boot/head.S new file +5 -0
+	/* Compute _start load address */
+	bal	compute_load_address
+	 nop
+
+compute_load_address:

why don't you use the relocate from Shinya-san?

Because my memory usage is differ.
I will try to explain my view on the memory usage in a separate letter.

Shinya-san's memory usage:

CONFIG_TEXT_BASE=0x9fc00000
_start link address = CONFIG_TEXT_BASE

Let's use 32-bit CPU, CONFIG_64BIT is not set.

The MIPS cpu reset entry point is 0xbfc00000 (KSEG1, unmapped and uncached region).
So code after _start label run from 0xbfc00000.

Let's see Shinya-san's code
---- Shinya-san's code start (arch/mips/cpu/start.S) ----

	setup_c0_status_reset

	/*
	 * Config: K0 should be set to the desired Cache Coherency
	 * Algorithm (CCA) prior to accessing Kseg0.
	 */
	mfc0	t0, CP0_CONFIG
	/* T.B.D. */
	mtc0	t0, CP0_CONFIG

	/*
	 * Config: (4KEm and 4KEp cores only) KU and K23 should be set to
	 * the desired CCA for USeg/KUSeg and KSeg2/3 respectively prior to
	 * accessing those regions.
	 */
	mfc0	t0, CP0_CONFIG
	/* T.B.D. */
	mtc0	t0, CP0_CONFIG

---- Shinya-san's code end ----

does this code initialise KSEG0 cache mode?
does this code change CP0_CONFIG at all?
My answer is "no".

But bellow, you can see switching to KSEG0 (label 1f linked to 0x9fc00xxx) ...

---- Shinya-san's code start (arch/mips/cpu/start.S) ----

	/* Switch to CKSEG0 segment */
	la	t0, 1f
	/* T.B.D. -- Convert an addree of the label '1f' into CKSEG0 */
	jr	t0

1:
---- Shinya-san's code end ----

Let's see relocate code:
---- Shinya-san's code start (arch/mips/cpu/start.S) ---- relocate:
ADR t0, _start, t1 # t0 <- current position of code
PTR_LI t1, TEXT_BASE
beq t0, t1, stack_setup
nop
---- Shinya-san's code end ----

This code try to check if relocation needs. It try to compute _start <<current>> address.

But
* _start link address is KSEG0 address 0x9fc00000;
* we have already switched to KSEG0, so _start <<current>> address
is 0x9fc00000 too.

So we __always__ skip copy_loop and go to stack_setup.

But ...
imagine that t0 != t1.

9fc00000 may be KSEG0 address for boot ROM (flash chip) how we can relocate to ROM?

Running from 0x9fc00000 (even with cache) may be bad idea, because flash may be connected via narrow and slow bus. barebox must run from cached RAM.

For simplification I use uncached KSEG1 region for barebox, so I can skip all cache business. But it is temporary measure.

Let's see the copy_loop:
---- Shinya-san's code start (arch/mips/cpu/start.S) ---- copy_loop:

	LONG_L		t4, LONGSIZE*0(t0)	# copy from source address [t0]
	LONG_L		t5, LONGSIZE*1(t0)
	LONG_L		t6, LONGSIZE*2(t0)
	LONG_L		t7, LONGSIZE*3(t0)
	LONG_S		t4, LONGSIZE*0(t1)	# copy fo target address [t1]
	LONG_S		t5, LONGSIZE*1(t1)
	LONG_S		t6, LONGSIZE*2(t1)
	LONG_S		t7, LONGSIZE*3(t1)
	PTR_ADDI	t0, LONGSIZE
	PTR_SUBU	t3, t0, t2
	blez		t3, copy_loop
	 nop

---- Shinya-san's code end ----
Shinya-san use effective unrolled loop. Very good for pipelined CPU.

Every loop this code copy 4 portions of memory.
The size of a portion may be 4 or 8 bytes (depends on cpu type).

But, look here:
PTR_ADDI t0, LONGSIZE

This will increase the source address counter (t0) by size of the only one portion, but __we copy 4 portions__!

Shinya-san's code is very unified code based on Linux macros. The Linux macros make possible to write code for running on very different MIPS CPU (e.g. 32-bit or 64-bit). The macros code has a long history. It was tested many times in very many different situations. It is proven. The macros has need of tricky and complex header files.

But today barebox run on only one 32bit emulated CPU. It has no need of hairy header files.

On the other hand, I can unroll my loop.
I can use Shinya-san's ADR macro instruction.
ADR macro is valuable. My code use assumption about 64K-alignment of barebox image in ROM. It's true in most cases. Many flash chips used to store boot code have 64K sector size (or even more). But ADR macro is more flexible solution.

Quoted 12 lines

arch/mips/boot/head.S line 90

Quoted 11 lines
arch/mips/boot/head.S new file +11 -0
+clear_bss:
+	la	t0, __bss_start
+	sw	zero, (t0)
+	la	t1, _end - 4
+1:
+	addiu	t0, 4
+	sw	zero, (t0)
+	bne	t0, t1, 1b
+	 nop
+
+stack_setup:

his stack setup is more clean

Quoted 9 lines

arch/mips/boot/head.S line 99

Quoted 9 lines
arch/mips/boot/head.S new file +9 -0
+	la	sp, STACK_BASE + STACK_SIZE
+	addiu	sp, -32			# init stack pointer
+
+	la	v0, start_barebox
+        jal     v0
+	 nop
+
+	/* No return */
+

But I have already used Shinya-san's code!

Here is Shinya-san's code.

---- Shinya-san's code start (arch/mips/cpu/start.) ---- stack_setup:

	PTR_LA		t0, __bss_start		# clear .bss
	LONG_S		zero, (t0)
	PTR_LA		t1, _end - LONGSIZE
1:
	PTR_ADDIU	t0, LONGSIZE
	LONG_S		zero, (t0)
	bne		t0, t1, 1b
	 nop

	/* Set the SP */
	PTR_LI		sp, STACK_BASE + STACK_SIZE
	PTR_SUB		sp, 4 * SZREG		# init stack pointer

	j		start_barebox
	END(barebox_entry)

---- Shinya-san's code end ----

Shinya-san uses macros. This is the main difference.

I think that where is no place for such macros in the initial mips support because there is no need of them.

We can add 64bit CPU support and add macros in the future.

--
Best regards,
Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#5 lore raw
In reply to Jean-Christophe PLAGNIOL-VILLARD

Hi!

I posted message to maillist some hours ago. I have got the message
to my mailbox, but can't see the message in maillist archive via http.

I will resend message.

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw
In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 9 lines · On Fri, 1 Jul 2011 02:28:15 +0200 Jean-Christophe PLAGNIOL-VILLARD…

arch/mips/boot/head.S line 37

Quoted 8 lines
arch/mips/boot/head.S new file +8 -0
+
+	.set noreorder
+        .text
+	.section ".text_bare_init"
+        .globl _start
+	.align 4
+
+_start:

here the EXPORT

EXPORT(_start)? Ok.

Quoted 1 line

IIRC we will need to preserve ra for NMI case

How this preserved value can be used?

We have no need to preserve ra because we have no full-grown exception handlers.

Quoted 6 lines

arch/mips/boot/head.S line 59

Quoted 5 lines
arch/mips/boot/head.S new file +5 -0
+	/* Compute _start load address */
+	bal	compute_load_address
+	 nop
+
+compute_load_address:

why don't you use the relocate from Shinya-san?

Because my memory usage is differ.
I will try to explain my view on the memory usage in a separate letter.

Shinya-san's memory usage:

CONFIG_TEXT_BASE=0x9fc00000
_start link address = CONFIG_TEXT_BASE

Let's use 32-bit CPU, CONFIG_64BIT is not set.

The MIPS cpu reset entry point is 0xbfc00000 (KSEG1, unmapped and uncached region).
So code after _start label run from 0xbfc00000.

Let's see Shinya-san's code
---- Shinya-san's code start (arch/mips/cpu/start.S) ----

	setup_c0_status_reset

	/*
	 * Config: K0 should be set to the desired Cache Coherency
	 * Algorithm (CCA) prior to accessing Kseg0.
	 */
	mfc0	t0, CP0_CONFIG
	/* T.B.D. */
	mtc0	t0, CP0_CONFIG

	/*
	 * Config: (4KEm and 4KEp cores only) KU and K23 should be set to
	 * the desired CCA for USeg/KUSeg and KSeg2/3 respectively prior to
	 * accessing those regions.
	 */
	mfc0	t0, CP0_CONFIG
	/* T.B.D. */
	mtc0	t0, CP0_CONFIG

---- Shinya-san's code end ----

does this code initialise KSEG0 cache mode?
does this code change CP0_CONFIG at all?
My answer is "no".

But bellow, you can see switching to KSEG0 (label 1f linked to 0x9fc00xxx) ...

---- Shinya-san's code start (arch/mips/cpu/start.S) ----

	/* Switch to CKSEG0 segment */
	la	t0, 1f
	/* T.B.D. -- Convert an addree of the label '1f' into CKSEG0 */
	jr	t0

1:
---- Shinya-san's code end ----

Let's see relocate code:
---- Shinya-san's code start (arch/mips/cpu/start.S) ---- relocate:
ADR t0, _start, t1 # t0 <- current position of code
PTR_LI t1, TEXT_BASE
beq t0, t1, stack_setup
nop
---- Shinya-san's code end ----

This code try to check if relocation needs. It try to compute _start <<current>> address.

But
* _start link address is KSEG0 address 0x9fc00000;
* we have already switched to KSEG0, so _start <<current>> address
is 0x9fc00000 too.

So we __always__ skip copy_loop and go to stack_setup.

But ...
imagine that t0 != t1.

9fc00000 may be KSEG0 address for boot ROM (flash chip) how we can relocate to ROM?

Running from 0x9fc00000 (even with cache) may be bad idea, because flash may be connected via narrow and slow bus. barebox must run from cached RAM.

For simplification I use uncached KSEG1 region for barebox, so I can skip all cache business. But it is temporary measure.

Let's see the copy_loop:
---- Shinya-san's code start (arch/mips/cpu/start.S) ---- copy_loop:

	LONG_L		t4, LONGSIZE*0(t0)	# copy from source address [t0]
	LONG_L		t5, LONGSIZE*1(t0)
	LONG_L		t6, LONGSIZE*2(t0)
	LONG_L		t7, LONGSIZE*3(t0)
	LONG_S		t4, LONGSIZE*0(t1)	# copy fo target address [t1]
	LONG_S		t5, LONGSIZE*1(t1)
	LONG_S		t6, LONGSIZE*2(t1)
	LONG_S		t7, LONGSIZE*3(t1)
	PTR_ADDI	t0, LONGSIZE
	PTR_SUBU	t3, t0, t2
	blez		t3, copy_loop
	 nop

---- Shinya-san's code end ----
Shinya-san use effective unrolled loop. Very good for pipelined CPU.

Every loop this code copy 4 portions of memory.
The size of a portion may be 4 or 8 bytes (depends on cpu type).

But, look here:
PTR_ADDI t0, LONGSIZE

This will increase the source address counter (t0) by size of the only one portion, but __we copy 4 portions__!

Shinya-san's code is very unified code based on Linux macros. The Linux macros make possible to write code for running on very different MIPS CPU (e.g. 32-bit or 64-bit). The macros code has a long history. It was tested many times in very many different situations. It is proven. The macros has need of tricky and complex header files.

But today barebox run on only one 32bit emulated CPU. It has no need of hairy header files.

On the other hand, I can unroll my loop.
I can use Shinya-san's ADR macro instruction.
ADR macro is valuable. My code use assumption about 64K-alignment of barebox image in ROM. It's true in most cases. Many flash chips used to store boot code have 64K sector size (or even more). But ADR macro is more flexible solution.

Quoted 12 lines

arch/mips/boot/head.S line 90

Quoted 11 lines
arch/mips/boot/head.S new file +11 -0
+clear_bss:
+	la	t0, __bss_start
+	sw	zero, (t0)
+	la	t1, _end - 4
+1:
+	addiu	t0, 4
+	sw	zero, (t0)
+	bne	t0, t1, 1b
+	 nop
+
+stack_setup:

his stack setup is more clean

Quoted 9 lines

arch/mips/boot/head.S line 99

Quoted 9 lines
arch/mips/boot/head.S new file +9 -0
+	la	sp, STACK_BASE + STACK_SIZE
+	addiu	sp, -32			# init stack pointer
+
+	la	v0, start_barebox
+        jal     v0
+	 nop
+
+	/* No return */
+

But I have already used Shinya-san's code!

Here is Shinya-san's code.

---- Shinya-san's code start (arch/mips/cpu/start.) ---- stack_setup:

	PTR_LA		t0, __bss_start		# clear .bss
	LONG_S		zero, (t0)
	PTR_LA		t1, _end - LONGSIZE
1:
	PTR_ADDIU	t0, LONGSIZE
	LONG_S		zero, (t0)
	bne		t0, t1, 1b
	 nop

	/* Set the SP */
	PTR_LI		sp, STACK_BASE + STACK_SIZE
	PTR_SUB		sp, 4 * SZREG		# init stack pointer

	j		start_barebox
	END(barebox_entry)

---- Shinya-san's code end ----

Shinya-san uses macros. This is the main difference.

I think that where is no place for such macros in the initial mips support because there is no need of them.

We can add 64bit CPU support and add macros in the future.

--
Best regards,
Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#7 lore raw

Hi,

Quoted 3 lines · antonynpavlov
Quoted 1 line

IIRC we will need to preserve ra for NMI case

How this preserved value can be used?

Not used right now.

Quoted 1 line

We have no need to preserve ra because we have no full-grown exception handlers.

True.

Quoted 3 lines

The MIPS cpu reset entry point is 0xbfc00000 (KSEG1, unmapped and uncached region).
So code after _start label run from 0xbfc00000.

Starting from 0xBFC00000 might be a primary boot scenario in MIPS systems, but in my opinion it's just one of the use cases. Memory- type flash devices are getting less used with newer MIPS SoCs.

Quoted 19 lines

---- Shinya-san's code start (arch/mips/cpu/start.S) ----

	setup_c0_status_reset

	/*
	 * Config: K0 should be set to the desired Cache Coherency
	 * Algorithm (CCA) prior to accessing Kseg0.
	 */
	mfc0	t0, CP0_CONFIG
	/* T.B.D. */
	mtc0	t0, CP0_CONFIG

	/*
	 * Config: (4KEm and 4KEp cores only) KU and K23 should be set to
	 * the desired CCA for USeg/KUSeg and KSeg2/3 respectively prior to
	 * accessing those regions.
	 */
	mfc0	t0, CP0_CONFIG
	/* T.B.D. */
	mtc0	t0, CP0_CONFIG
Quoted 5 lines

---- Shinya-san's code end ----

does this code initialise KSEG0 cache mode?
does this code change CP0_CONFIG at all?
My answer is "no".

Correct. Please keep in mind I didn't do anything set up in start.S. I was thinking around how to generalize the initialization procedures how we could maintain/support various MIPS processors, and what shape of code would be reasonable (and scalable).

Quoted 10 lines

But bellow, you can see switching to KSEG0 (label 1f linked to 0x9fc00xxx) ...

---- Shinya-san's code start (arch/mips/cpu/start.S) ----

	/* Switch to CKSEG0 segment */
	la	t0, 1f
	/* T.B.D. -- Convert an addree of the label '1f' into CKSEG0 */
	jr	t0

1:
---- Shinya-san's code end ----

It's intended to be converted to CKSEG0, but it's not necessarily 0x9fc00xxx.

Quoted 9 lines

Let's see relocate code:
---- Shinya-san's code start (arch/mips/cpu/start.S) ---- relocate:
ADR t0, _start, t1 # t0<- current position of code
PTR_LI t1, TEXT_BASE
beq t0, t1, stack_setup
nop
---- Shinya-san's code end ----

Quoted 7 lines

This code try to check if relocation needs. It try to compute _start<<current>> address.

But
* _start link address is KSEG0 address 0x9fc00000;
* we have already switched to KSEG0, so _start<<current>> address
is 0x9fc00000 too.

No. ADR tries to compute 'PC-relative' _start address. If it starts from physical 0xbfc0000, t0 is set up to 0xbfc0000 even if _start link address is CKSEG0. If it starts from physical 0xA0100000, t0 is set up to 0xA0100000, and in that case _start link address is supposed to be set to 0x80100000. The 'link address' is supposed to be used
_after_ relocation. You see?

I'm afraid there might be something missing in my prototyoe, though.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#8 lore raw
Quoted 21 lines · Shinya Kuribayashi
Quoted 21 lines

---- Shinya-san's code start (arch/mips/cpu/start.S) ---- setup_c0_status_reset

       /*
        * Config: K0 should be set to the desired Cache Coherency
        * Algorithm (CCA) prior to accessing Kseg0.
        */
       mfc0    t0, CP0_CONFIG
       /* T.B.D. */
       mtc0    t0, CP0_CONFIG

       /*
        * Config: (4KEm and 4KEp cores only) KU and K23 should be set to
        * the desired CCA for USeg/KUSeg and KSeg2/3 respectively prior to
        * accessing those regions.
        */
       mfc0    t0, CP0_CONFIG
       /* T.B.D. */
       mtc0    t0, CP0_CONFIG
---- Shinya-san's code end ----

Quoted 8 lines
Quoted 3 lines

does this code initialise KSEG0 cache mode?
does this code change CP0_CONFIG at all?
My answer is "no".

Correct.  Please keep in mind I didn't do anything set up in start.S. I was thinking around how to generalize the initialization procedures how we could maintain/support various MIPS processors, and what shape of code would be reasonable (and scalable).

The generalization is possible if you have the piece of code for the processor A and the piece of code for the processor B.
Then you can make generalization and produce the piece of code for the both processors.

But it is very difficult to write universal code without attempts to check of it ability to work.

Quoted 9 lines
Quoted 9 lines

But bellow, you can see switching to KSEG0 (label 1f linked to 0x9fc00xxx)
...

---- Shinya-san's code start (arch/mips/cpu/start.S) ---- /* Switch to CKSEG0 segment */
       la      t0, 1f
       /* T.B.D. -- Convert an addree of the label '1f' into CKSEG0 */ jr      t0

Quoted 5 lines
Quoted 2 lines

1:
---- Shinya-san's code end ----

It's intended to be converted to CKSEG0, but it's not necessarily 0x9fc00xxx.

In this particular example it is necessarily 0x9fc00xxx. You have set CONFIG_TEXT_BASE=0x9fc00000.

Quoted 20 lines
Quoted 11 lines

Let's see relocate code:
---- Shinya-san's code start (arch/mips/cpu/start.S) ---- relocate:
       ADR     t0, _start, t1                  # t0<- current position of code
       PTR_LI  t1, TEXT_BASE
       beq     t0, t1, stack_setup
        nop
---- Shinya-san's code end ----

Quoted 8 lines

This code try to check if relocation needs. It try to compute _start<<current>>
address.

But
  * _start link address is KSEG0 address 0x9fc00000;
  * we have already switched to KSEG0, so _start<<current>>  address is 0x9fc00000 too.

Quoted 6 lines

No.  ADR tries to compute 'PC-relative' _start address.  If it starts from physical 0xbfc0000, t0 is set up to 0xbfc0000 even if _start link address is CKSEG0.  If it starts from physical 0xA0100000, t0 is set up to 0xA0100000, and in that case _start link address is supposed to be set to 0x80100000.  The 'link address' is supposed to be used _after_ relocation.   You see?

No, I don't.

in barebox.lds.S you have:
---- begin ----
SECTIONS

{
        . = TEXT_BASE;
        /* read-only */
        _text = .;      /* Text and read-only data */
        .text : {

----- end ----

So '_start' link address is always TEXT_BASE.

Here is the code:
---- Shinya-san's code start (arch/mips/cpu/start.S) ----

        la      t0, 1f     // pc = 0xbfc00xxx
        jr      t0

1:
relocate:
ADR t0, _start, t1
PTR_LI t1, TEXT_BASE
---- Shinya-san's code end ----

ADR macro always run with pc == 'relocate' link address. So ADR will compute '_start' link address.
This code always make t0 == t1.

Eventually you can try to check the code using an emulator.

--- Shinya-san's code start (arch/mips/cpu/start.S) ----

        la      t0, 1f     // pc = 0xbfc00xxx
        jr      t0
1:
relocate:
	ADR	t0, _start, t1		// pc = 0x9fc00xxx, t0=0x9fc00000
	PTR_LI	t1, TEXT_BASE           // t1 = 0x9fc00000
	beq	t0, t1, stack_setup
	 nop

---- Shinya-san's code end ----

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw
In reply to Shinya Kuribayashi
Quoted 19 lines · Shinya Kuribayashi
Quoted 10 lines

Let's see relocate code:
---- Shinya-san's code start (arch/mips/cpu/start.S) ---- relocate:
       ADR     t0, _start, t1                  # t0<- current position of code
       PTR_LI  t1, TEXT_BASE
       beq     t0, t1, stack_setup
        nop
---- Shinya-san's code end ----

Quoted 8 lines

This code try to check if relocation needs. It try to compute _start<<current>>
address.

But
  * _start link address is KSEG0 address 0x9fc00000;
  * we have already switched to KSEG0, so _start<<current>>  address is 0x9fc00000 too.

Quoted 5 lines

No.  ADR tries to compute 'PC-relative' _start address.  If it starts from physical 0xbfc0000, t0 is set up to 0xbfc0000 even if _start link address is CKSEG0.  If it starts from physical 0xA0100000, t0 is set up to 0xA0100000, and in that case _start link address is supposed to be set to 0x80100000.

The main problem is <<_start link address is supposed to
be set to 0x80100000>>.

But if not?

Imagine that you have Momentus Ocelot evolution board equipped with 8MB of memory-mapped flash starting at 0xb8000000.

you get you barebox.bin (linked to 0x9fc00000), burn it to 0xb8000000 and jump to 0xb8000000. Will it work correctly?

My answer is <<no>>.

See the code:

Quoted 8 lines
Quoted 8 lines

---- Shinya-san's code start (arch/mips/cpu/start.S) ---- /* Switch to CKSEG0 segment */
       la      t0, 1f
       /* T.B.D. -- Convert an addree of the label '1f' into CKSEG0 */ jr      t0

1:
---- Shinya-san's code end ----

The command 'la' will set t0 to 0x9fc00xxx, the command 'jr' will make jump to 0x9fc00xxx, but we work in the 0xb8000xxx addresses!

We can't use link addresses to jump if we want to make possible to run from any KSEG0 or KSEG1 address.

Signature · 7 lines
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox