Re: [PATCH 1/7] Import wpa from FreeBSD

2017-08-17 Thread Christian Mauderer
Hello Sichen,

I get a

  error: corrupt patch at line 47434

for the first patch. That is the following part. The problem seems to be
the empty line.

Regards

Christian

Am 16.08.2017 um 18:10 schrieb Sichen Zhao:
> +#include "common/ieee802_11_defs.h"
> +#include "wps/wps.h"
> +
> +/* P2P ASP Setup Capability */
> +#define P2PS_SETUP_NONE 0
> +#define P2PS_SETUP_NEW BIT(0)
> +#define P2PS_SETUP_CLIENT BIT(1)
> +#define P2PS_SETUP_GROUP_OWNER BIT(2)
> 
> +
> +#define P2PS_WILD_HASH_STR "org.wi-fi.wfds"
> +#define P2PS_HASH_LEN 6
> +#define P2P_MAX_QUERY_HASH 6
> +#define P2PS_FEATURE_CAPAB_CPT_MAX 2
> +
> +/**
> + * P2P_MAX_PREF_CHANNELS - Maximum number of preferred channels
> + */
> +#define P2P_MAX_PREF_CHANNELS 100

-- 

embedded brains GmbH
Christian Mauderer
Dornierstr. 4
D-82178 Puchheim
Germany
email: christian.maude...@embedded-brains.de
Phone: +49-89-18 94 741 - 18
Fax:   +49-89-18 94 741 - 08
PGP: Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH 2/7] Port wpa supplicant to RTEMS.

2017-08-17 Thread Christian Mauderer
Am 16.08.2017 um 18:10 schrieb Sichen Zhao:
> Add wpa_supplicant lib support
> and shell command support in RTEMS.
> ---
>  builder.py  |   1 +
>  freebsd/contrib/wpa/src/utils/os_unix.c |  10 +-
>  freebsd/contrib/wpa/wpa_supplicant/config.h |   4 +-
>  freebsd/contrib/wpa/wpa_supplicant/main.c   |  15 ++
>  libbsd.py   | 285 
> 
>  libbsd_waf.py   | 114 +-
>  rtemsbsd/include/bsp/nexus-devices.h|   2 +
>  rtemsbsd/include/machine/rtems-bsd-commands.h   |   2 +
>  rtemsbsd/include/rtems/netcmds-config.h |   2 +
>  rtemsbsd/rtems/rtems-bsd-shell-wpa_supplicant.c |  36 +++
>  10 files changed, 465 insertions(+), 6 deletions(-)
>  create mode 100644 rtemsbsd/rtems/rtems-bsd-shell-wpa_supplicant.c
> 
> diff --git a/builder.py b/builder.py
> index b62f79d..b155fea 100755
> --- a/builder.py
> +++ b/builder.py
> @@ -174,6 +174,7 @@ def includes():
>  return ['-Irtemsbsd/include',
>  '-Ifreebsd/sys',
>  '-Ifreebsd/sys/contrib/pf',
> +'-Ifreebsd/crypto',
>  '-Ifreebsd/sys/net',
>  '-Ifreebsd/include',
>  '-Ifreebsd/lib',
> diff --git a/freebsd/contrib/wpa/src/utils/os_unix.c 
> b/freebsd/contrib/wpa/src/utils/os_unix.c
> index a3abce4..ac700db 100644
> --- a/freebsd/contrib/wpa/src/utils/os_unix.c
> +++ b/freebsd/contrib/wpa/src/utils/os_unix.c
> @@ -25,6 +25,10 @@
>  #include 
>  #endif /* __MACH__ */
>  
> +#ifdef __rtems__
> +#include 
> +#endif /* __rtems__ */
> +
>  #include "os.h"
>  #include "common.h"
>  
> @@ -225,7 +229,7 @@ static int os_daemon(int nochdir, int noclose)
>  
>  int os_daemonize(const char *pid_file)
>  {
> -#if defined(__uClinux__) || defined(__sun__)
> +#if defined(__uClinux__) || defined(__sun__) || defined(__rtems__)
>   return -1;
>  #else /* defined(__uClinux__) || defined(__sun__) */
>  #ifdef __FreeBSD__
> @@ -282,6 +286,9 @@ int os_get_random(unsigned char *buf, size_t len)
>   if (TEST_FAIL())
>   return -1;
>  
> +#ifdef __rtems__
> +return getentropy(buf, len);

The indentation is odd. It seems that you used spaces instead of tabs.
Please always try to use the same style like for the surrounding code.

I have seen a bad indentation in some of the next patches too (for
example Patch 6). Please take a look at all patches of that patch set
again (excluding the import patches).

> +#else /* __rtems__ */
>   f = fopen("/dev/urandom", "rb");
>   if (f == NULL) {
>   printf("Could not open /dev/urandom.\n");
> @@ -292,6 +299,7 @@ int os_get_random(unsigned char *buf, size_t len)
>   fclose(f);
>  
>   return rc != len ? -1 : 0;
> +#endif /* __rtems__ */
>  }
>  
>  
> diff --git a/freebsd/contrib/wpa/wpa_supplicant/config.h 
> b/freebsd/contrib/wpa/wpa_supplicant/config.h
> index 627f38b..425e55a 100644
> --- a/freebsd/contrib/wpa/wpa_supplicant/config.h
> +++ b/freebsd/contrib/wpa/wpa_supplicant/config.h
> @@ -44,7 +44,9 @@
>  #include "wps/wps.h"
>  #include "common/ieee802_11_defs.h"
>  #include "common/ieee802_11_common.h"
> -

A minus is always bad in libbsd. Please don't delete lines. Not even if
they are empty ;-)

> +#ifdef __rtems__
> +#include 
> +#endif /* __rtems__ */
>  
>  struct wpa_cred {
>   /**
> diff --git a/freebsd/contrib/wpa/wpa_supplicant/main.c 
> b/freebsd/contrib/wpa/wpa_supplicant/main.c
> index 0e86b93..7347951 100644
> --- a/freebsd/contrib/wpa/wpa_supplicant/main.c
> +++ b/freebsd/contrib/wpa/wpa_supplicant/main.c
> @@ -154,6 +154,21 @@ static void wpa_supplicant_fd_workaround(int start)
>  #endif /* __linux__ */
>  }
>  
> +#ifdef __rtems__
> +#include 
> +
> +static int
> +main(int argc, char **argv);
> +
> +int rtems_bsd_command_wpa_supplicant(int argc, char **argv)
> +{
> + int exit_code;
> +
> + exit_code = rtems_bsd_program_call_main("wpa_supplicant", main, argc, 
> argv);
> +
> + return exit_code;
> +}
> +#endif /* __rtems__ */
>  
>  int main(int argc, char *argv[])
>  {
> diff --git a/libbsd.py b/libbsd.py
> index b2f3977..ea469d3 100644
> --- a/libbsd.py
> +++ b/libbsd.py
> @@ -3958,6 +3958,290 @@ def usr_sbin_tcpdump(mm):
>  return mod
>  
>  #
> +# /usr/sbin/wpa_supplicant
> +#
> +def usr_sbin_wpa_supplicant(mm):
> +mod = builder.Module('usr_sbin_wpa_supplicant')
> +mod.addUserSpaceHeaderFiles(
> +[
> +'contrib/wpa/wpa_supplicant/ap.h',
> +'contrib/wpa/wpa_supplicant/blacklist.h',
> +'contrib/wpa/wpa_supplicant/bss.h',
> +'contrib/wpa/wpa_supplicant/config.h',
> +'contrib/wpa/wpa_supplicant/config_ssid.h',
> +'contrib/wpa/wpa_supplicant/ctrl_iface.h',
> +'contrib/wpa/wpa_supplicant/driver_i.h',
> +'contrib/wpa/wpa_supplicant/gas_query.h',
> +'contrib/wpa/wpa_supplicant/hs20_supplicant.h',
> +'co

Re: [PATCH 4/7] Port strnstr.c to FreeBSD.

2017-08-17 Thread Christian Mauderer
Two points regarding patch 3 and 4:

First the easy one: I expect that you need it for wpa_supplicant to
compile? In that case these two patches should be in front of 1 and 2.

The second point is harder to resolve. I wouldn't even be sure myself
what to do here: strnstr seems to be a function provided by the C
library. In our case that would be newlib. I'm not sure whether it is a
good idea to import some parts of the BSD C library. On the other hand,
there are already some other function imported from there too.

To our C-library experts: What would be the right way of handling this?

Am 17.08.2017 um 02:23 schrieb Sichen Zhao:
> ---
>  libbsd.py | 1 +
>  libbsd_waf.py | 1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/libbsd.py b/libbsd.py
> index ea469d3..a0b7f1a 100644
> --- a/libbsd.py
> +++ b/libbsd.py
> @@ -2534,6 +2534,7 @@ def user_space(mm):
>  'lib/libc/stdlib/strtonum.c',
>  'lib/libc/stdlib/strtoumax.c',
>  'lib/libc/string/strsep.c',
> +'lib/libc/string/strnstr.c',
>  'lib/libc/xdr/xdr_array.c',
>  'lib/libc/xdr/xdr.c',
>  'lib/libc/xdr/xdr_float.c',
> diff --git a/libbsd_waf.py b/libbsd_waf.py
> index 329a62a..02b2cbd 100644
> --- a/libbsd_waf.py
> +++ b/libbsd_waf.py
> @@ -465,6 +465,7 @@ def build(bld):
>   'freebsd/lib/libc/stdlib/strtoimax.c',
>   'freebsd/lib/libc/stdlib/strtonum.c',
>   'freebsd/lib/libc/stdlib/strtoumax.c',
> + 'freebsd/lib/libc/string/strnstr.c',
>   'freebsd/lib/libc/string/strsep.c',
>   'freebsd/lib/libc/xdr/xdr.c',
>   'freebsd/lib/libc/xdr/xdr_array.c',
> 

-- 

embedded brains GmbH
Christian Mauderer
Dornierstr. 4
D-82178 Puchheim
Germany
email: christian.maude...@embedded-brains.de
Phone: +49-89-18 94 741 - 18
Fax:   +49-89-18 94 741 - 08
PGP: Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH 6/7] Add wpa_supplicant_fork command.

2017-08-17 Thread Christian Mauderer
That's a great function for debugging but I'm not sure whether it would
be good as a command available to all. There should be at least some big
warning that it can't be started multiple times. In the ideal case, add
a lock so that it can only be started once.

A little more into the future, it most likely should be replaced by a
deamon similar to the dhcpcd. Or it should be started from the rc.conf
parser.

Am 17.08.2017 um 03:33 schrieb Sichen Zhao:
> Add fork command for wpa supplicant
> to start a new task.
> ---
>  freebsd/contrib/wpa/wpa_supplicant/main.c  | 67 
> +-
>  libbsd.py  |  1 +
>  libbsd_waf.py  |  1 +
>  rtemsbsd/include/machine/rtems-bsd-commands.h  |  2 +
>  rtemsbsd/include/rtems/netcmds-config.h|  2 +
>  .../rtems/rtems-bsd-shell-wpa_supplicant_fork.c| 36 
>  6 files changed, 108 insertions(+), 1 deletion(-)
>  create mode 100644 rtemsbsd/rtems/rtems-bsd-shell-wpa_supplicant_fork.c
> 
> diff --git a/freebsd/contrib/wpa/wpa_supplicant/main.c 
> b/freebsd/contrib/wpa/wpa_supplicant/main.c
> index 7347951..b2af31e 100644
> --- a/freebsd/contrib/wpa/wpa_supplicant/main.c
> +++ b/freebsd/contrib/wpa/wpa_supplicant/main.c
> @@ -18,7 +18,9 @@
>  #include "wpa_supplicant_i.h"
>  #include "driver_i.h"
>  #include "p2p_supplicant.h"
> -

Again: Minus is bad.

> +#ifdef __rtems__
> +#include 
> +#endif /* __rtems__ */
>  
>  static void usage(void)
>  {
> @@ -168,6 +170,69 @@ int rtems_bsd_command_wpa_supplicant(int argc, char 
> **argv)
>  
>   return exit_code;
>  }
> +
> +struct myparams {
> +   int argc;
> +   char ** argv;

Use BSD-Style indentations. There are some more places in that file with
wrong indentation. Please fix them too.

> +};
> +
> +static void
> +new_wpa_supplicant_task(rtems_task_argument arg)
> +{
> +   int argc;
> +   char ** argv;
> +   int i;
> +
> +   struct myparams *params = (struct myparams *)arg;
> +   argc = params->argc;
> +   argv = params->argv;
> +
> +   rtems_bsd_command_wpa_supplicant(argc, argv);
> +
> +   for (i = 0; i < params->argc; i++) {
> + free(params->argv[i]);
> + }
> + free(params->argv);
> + free(params);
> +
> + rtems_task_delete( RTEMS_SELF );
> +}
> +
> +int rtems_bsd_command_wpa_supplicant_fork(int argc, char **argv)
> +{
> +rtems_status_code sc;
> + rtems_id id;
> +int i;
> +
> +struct myparams *params = malloc(sizeof(struct myparams));
> +if (params == NULL)
> + return NULL;
> +
> + params->argc = argc;
> + params->argv = malloc((argc + 1) * sizeof(argv[0]));
> + if (params->argv == NULL)
> + return NULL;
> +
> + for (i = 0; i < argc; i++) {
> + params->argv[i] = strdup(argv[i]);
> + if (params->argv[i] == NULL)

You should free params->argv[x] for all x < i in that case. After that
you should also free params->argv. Then you can return. Otherwise this
might be a memory leak.

> + return NULL;
> + }
> +params->argv[argc] = NULL;
> +
> + sc = rtems_task_create(
> + rtems_build_name('W', 'P', 'A', 'S'),
> + RTEMS_MAXIMUM_PRIORITY - 1,
> + 8 * RTEMS_MINIMUM_STACK_SIZE,
> + RTEMS_DEFAULT_MODES,
> + RTEMS_FLOATING_POINT,
> + &id
> + );
> + assert(sc == RTEMS_SUCCESSFUL);
> +
> +sc = rtems_task_start(id, new_wpa_supplicant_task, params);
> + assert(sc == RTEMS_SUCCESSFUL);
> +}
>  #endif /* __rtems__ */
>  
>  int main(int argc, char *argv[])
> diff --git a/libbsd.py b/libbsd.py
> index a0b7f1a..9bb6f0b 100644
> --- a/libbsd.py
> +++ b/libbsd.py
> @@ -4237,6 +4237,7 @@ def usr_sbin_wpa_supplicant(mm):
>  mod.addRTEMSSourceFiles(
>  [
>  'rtems/rtems-bsd-shell-wpa_supplicant.c',
> +'rtems/rtems-bsd-shell-wpa_supplicant_fork.c',
>  ],
>  mm.generator['source']()
>  )
> diff --git a/libbsd_waf.py b/libbsd_waf.py
> index 02b2cbd..28e3cf0 100644
> --- a/libbsd_waf.py
> +++ b/libbsd_waf.py
> @@ -2288,6 +2288,7 @@ def build(bld):
>'rtemsbsd/rtems/rtems-bsd-shell-vmstat.c',
>'rtemsbsd/rtems/rtems-bsd-shell-wlanstats.c',
>'rtemsbsd/rtems/rtems-bsd-shell-wpa_supplicant.c',
> +  'rtemsbsd/rtems/rtems-bsd-shell-wpa_supplicant_fork.c',
>'rtemsbsd/rtems/rtems-bsd-syscall-api.c',
>'rtemsbsd/rtems/rtems-kernel-assert.c',
>'rtemsbsd/rtems/rtems-kernel-autoconf.c',
> diff --git a/rtemsbsd/include/machine/rtems-bsd-commands.h 
> b/rtemsbsd/include/machine/rtems-bsd-commands.h
> index 03a09bc..32aba44 100644
> --- a/rtemsbsd/include/machine/rtems-bsd-commands.h
> +++ b/rtemsbsd/include/machine/rtems-bsd-commands.h
> @@ -64,6 +64,8 @@ int rtems_bsd_command_dhcpcd(int argc, char **argv);
>  
>  int rtems_bsd_command_wpa_supplicant(int argc, c

Re: [PATCH 7/7] Add wpa_spplicant_fork command in test suite media01

2017-08-17 Thread Christian Mauderer
I think you can integrate that one into Patch 6.

Am 17.08.2017 um 03:33 schrieb Sichen Zhao:
> ---
>  testsuite/media01/test_main.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/testsuite/media01/test_main.c b/testsuite/media01/test_main.c
> index 5ca88fb..acc24f2 100644
> --- a/testsuite/media01/test_main.c
> +++ b/testsuite/media01/test_main.c
> @@ -205,7 +205,8 @@ early_initialization(void)
>&rtems_shell_SYSCTL_Command, \
>&rtems_shell_IFCONFIG_Command, \
>&rtems_shell_VMSTAT_Command, \
> -  &rtems_shell_WPA_SUPPLICANT_Command
> +  &rtems_shell_WPA_SUPPLICANT_Command, \
> +  &rtems_shell_WPA_SUPPLICANT_FORK_Command
>  
>  #define CONFIGURE_SHELL_COMMAND_CPUINFO
>  #define CONFIGURE_SHELL_COMMAND_CPUUSE
> 

-- 

embedded brains GmbH
Christian Mauderer
Dornierstr. 4
D-82178 Puchheim
Germany
email: christian.maude...@embedded-brains.de
Phone: +49-89-18 94 741 - 18
Fax:   +49-89-18 94 741 - 08
PGP: Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH 4/7] Port strnstr.c to FreeBSD.

2017-08-17 Thread Gedare Bloom
On Thu, Aug 17, 2017 at 4:12 AM, Christian Mauderer
 wrote:
> Two points regarding patch 3 and 4:
>
> First the easy one: I expect that you need it for wpa_supplicant to
> compile? In that case these two patches should be in front of 1 and 2.
>
> The second point is harder to resolve. I wouldn't even be sure myself
> what to do here: strnstr seems to be a function provided by the C
> library. In our case that would be newlib. I'm not sure whether it is a
> good idea to import some parts of the BSD C library. On the other hand,
> there are already some other function imported from there too.
>
> To our C-library experts: What would be the right way of handling this?
>
It is best to bring it in to newlib. It can temporarily come into the
libbsd if needed, but a note should be made to port it to newlib.

> Am 17.08.2017 um 02:23 schrieb Sichen Zhao:
>> ---
>>  libbsd.py | 1 +
>>  libbsd_waf.py | 1 +
>>  2 files changed, 2 insertions(+)
>>
>> diff --git a/libbsd.py b/libbsd.py
>> index ea469d3..a0b7f1a 100644
>> --- a/libbsd.py
>> +++ b/libbsd.py
>> @@ -2534,6 +2534,7 @@ def user_space(mm):
>>  'lib/libc/stdlib/strtonum.c',
>>  'lib/libc/stdlib/strtoumax.c',
>>  'lib/libc/string/strsep.c',
>> +'lib/libc/string/strnstr.c',
>>  'lib/libc/xdr/xdr_array.c',
>>  'lib/libc/xdr/xdr.c',
>>  'lib/libc/xdr/xdr_float.c',
>> diff --git a/libbsd_waf.py b/libbsd_waf.py
>> index 329a62a..02b2cbd 100644
>> --- a/libbsd_waf.py
>> +++ b/libbsd_waf.py
>> @@ -465,6 +465,7 @@ def build(bld):
>>   'freebsd/lib/libc/stdlib/strtoimax.c',
>>   'freebsd/lib/libc/stdlib/strtonum.c',
>>   'freebsd/lib/libc/stdlib/strtoumax.c',
>> + 'freebsd/lib/libc/string/strnstr.c',
>>   'freebsd/lib/libc/string/strsep.c',
>>   'freebsd/lib/libc/xdr/xdr.c',
>>   'freebsd/lib/libc/xdr/xdr_array.c',
>>
>
> --
> 
> embedded brains GmbH
> Christian Mauderer
> Dornierstr. 4
> D-82178 Puchheim
> Germany
> email: christian.maude...@embedded-brains.de
> Phone: +49-89-18 94 741 - 18
> Fax:   +49-89-18 94 741 - 08
> PGP: Public key available on request.
>
> Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH 3/7] Import strnstr.c from FreeBSD.

2017-08-17 Thread Gedare Bloom
On Wed, Aug 16, 2017 at 8:14 PM, Sichen Zhao <1473996...@qq.com> wrote:
> ---
>  freebsd/lib/libc/string/strnstr.c | 67 
> +++
>  1 file changed, 67 insertions(+)
>  create mode 100644 freebsd/lib/libc/string/strnstr.c
>
> diff --git a/freebsd/lib/libc/string/strnstr.c 
> b/freebsd/lib/libc/string/strnstr.c
> new file mode 100644
> index 000..247a2b5
> --- /dev/null
> +++ b/freebsd/lib/libc/string/strnstr.c
> @@ -0,0 +1,67 @@
> +#include 
> +
> +/*-
> + * Copyright (c) 2001 Mike Barcroft 
> + * Copyright (c) 1990, 1993
> + * The Regents of the University of California.  All rights reserved.
> + *
> + * This code is derived from software contributed to Berkeley by
> + * Chris Torek.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *notice, this list of conditions and the following disclaimer in the
> + *documentation and/or other materials provided with the distribution.
> + * 3. Neither the name of the University nor the names of its contributors
> + *may be used to endorse or promote products derived from this software
> + *without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#if defined(LIBC_SCCS) && !defined(lint)
> +static char sccsid[] = "@(#)strstr.c   8.1 (Berkeley) 6/4/93";
> +#endif /* LIBC_SCCS and not lint */
> +#include 
> +__FBSDID("$FreeBSD$");
> +
> +#include 
> +
> +/*
> + * Find the first occurrence of find in s, where the search is limited to the
> + * first slen characters of s.
> + */
> +char *
> +strnstr(const char *s, const char *find, size_t slen)
> +{
> +   char c, sc;
> +   size_t len;
> +
> +   if ((c = *find++) != '\0') {
> +   len = strlen(find);
> +   do {
> +   do {
> +   if (slen-- < 1 || (sc = *s++) == '\0')
> +   return (NULL);
> +   } while (sc != c);
> +   if (len > slen)
> +   return (NULL);
> +   } while (strncmp(s, find, len) != 0);
> +   s--;
> +   }
> +   return ((char *)s);
> +}

This can definitely be added in newlib. Aditya may be able to assist
in the process?


> --
> 2.7.4
>
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 3/7] Import strnstr.c from FreeBSD.

2017-08-17 Thread Joel Sherrill
On Aug 17, 2017 8:19 AM, "Gedare Bloom"  wrote:

On Wed, Aug 16, 2017 at 8:14 PM, Sichen Zhao <1473996...@qq.com> wrote:
> ---
>  freebsd/lib/libc/string/strnstr.c | 67 ++
+
>  1 file changed, 67 insertions(+)
>  create mode 100644 freebsd/lib/libc/string/strnstr.c
>
> diff --git a/freebsd/lib/libc/string/strnstr.c b/freebsd/lib/libc/string/
strnstr.c
> new file mode 100644
> index 000..247a2b5
> --- /dev/null
> +++ b/freebsd/lib/libc/string/strnstr.c
> @@ -0,0 +1,67 @@
> +#include 
> +
> +/*-
> + * Copyright (c) 2001 Mike Barcroft 
> + * Copyright (c) 1990, 1993
> + * The Regents of the University of California.  All rights reserved.
> + *
> + * This code is derived from software contributed to Berkeley by
> + * Chris Torek.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *notice, this list of conditions and the following disclaimer in the
> + *documentation and/or other materials provided with the
distribution.
> + * 3. Neither the name of the University nor the names of its
contributors
> + *may be used to endorse or promote products derived from this
software
> + *without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#if defined(LIBC_SCCS) && !defined(lint)
> +static char sccsid[] = "@(#)strstr.c   8.1 (Berkeley) 6/4/93";
> +#endif /* LIBC_SCCS and not lint */
> +#include 
> +__FBSDID("$FreeBSD$");
> +
> +#include 
> +
> +/*
> + * Find the first occurrence of find in s, where the search is limited
to the
> + * first slen characters of s.
> + */
> +char *
> +strnstr(const char *s, const char *find, size_t slen)
> +{
> +   char c, sc;
> +   size_t len;
> +
> +   if ((c = *find++) != '\0') {
> +   len = strlen(find);
> +   do {
> +   do {
> +   if (slen-- < 1 || (sc = *s++) == '\0')
> +   return (NULL);
> +   } while (sc != c);
> +   if (len > slen)
> +   return (NULL);
> +   } while (strncmp(s, find, len) != 0);
> +   s--;
> +   }
> +   return ((char *)s);
> +}

This can definitely be added in newlib. Aditya may be able to assist
in the process?


Agreed. This should be as widely available to RTEMS applications as
possible.



> --
> 2.7.4
>
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH 01/15] Add build support files for HiFive1 BSP

2017-08-17 Thread Gedare Bloom
Generally you should add the build system files after you add the
source files so that the rtems build isn't broken on this particular
commit. This is helpful for git-bisect. So please re-arrange your
commits so the build won't fail on any particular commit.

On Wed, Aug 16, 2017 at 11:12 AM, Denis Obrezkov
 wrote:
> ---
>  c/src/lib/libbsp/riscv32/hifive1/Makefile.am  | 104 
> ++
>  c/src/lib/libbsp/riscv32/hifive1/bsp_specs|  13 
>  c/src/lib/libbsp/riscv32/hifive1/configure.ac |  39 ++
>  3 files changed, 156 insertions(+)
>  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/Makefile.am
>  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/bsp_specs
>  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/configure.ac
>
> diff --git a/c/src/lib/libbsp/riscv32/hifive1/Makefile.am 
> b/c/src/lib/libbsp/riscv32/hifive1/Makefile.am
> new file mode 100644
> index 000..f8332d7
> --- /dev/null
> +++ b/c/src/lib/libbsp/riscv32/hifive1/Makefile.am
> @@ -0,0 +1,104 @@
> +##
> +#
> +# @brief Makefile of LibBSP for the RISCV HiFive1 board.
> +#
> +#
> +ACLOCAL_AMFLAGS = -I ../../../../aclocal
> +
> +include $(top_srcdir)/../../../../automake/compile.am
> +
> +include_bspdir = $(includedir)/bsp
> +include_libcpudir = $(includedir)/libcpu
> +
> +dist_project_lib_DATA = bsp_specs
> +
> +###
> +#  Header
>  #
> +###
> +
> +include_HEADERS = include/bsp.h
> +include_HEADERS += ../../shared/include/tm27.h
> +include_HEADERS += ../../shared/include/coverhd.h
> +
> +nodist_include_bsp_HEADERS = ../../shared/include/bootcard.h
> +include_bsp_HEADERS = ../shared/include/linker-symbols.h
> +
> +include_bsp_HEADERS += ../../../libbsp/shared/include/mm.h
> +include_bsp_HEADERS += ../../shared/include/utility.h
> +include_bsp_HEADERS += ../../shared/include/irq-generic.h
> +include_bsp_HEADERS += ../../shared/include/irq-info.h
> +include_bsp_HEADERS += ../../shared/include/stackalloc.h
> +include_bsp_HEADERS += ../../shared/include/console-termios.h
> +include_bsp_HEADERS += ../../shared/include/console-polled.h
> +include_bsp_HEADERS += include/irq.h
> +include_bsp_HEADERS += include/prci.h
> +include_bsp_HEADERS += include/fe310.h
> +include_bsp_HEADERS += include/fe310-uart.h
> +include_bsp_HEADERS += include/fe310-gpio.h
> +
> +
> +nodist_include_HEADERS = include/bspopts.h
> +
> +###
> +#  Data  
>  #
> +###
> +noinst_LIBRARIES = libbspstart.a
> +
> +libbspstart_a_SOURCES = start/start.S
> +
> +project_lib_DATA = start.$(OBJEXT)
> +# project_lib_DATA = start/start.$(OBJEXT)
> +
> +project_lib_DATA += startup/linkcmds
> +
> +###
> +#  LibBSP
>  #
> +###
> +
> +noinst_LIBRARIES += libbsp.a
> +
> +# Startup
> +libbsp_a_SOURCES = ../../shared/bspreset.c
> +libbsp_a_SOURCES += start/bspstart.c
> +
> +# Start
> +libbsp_a_SOURCES += start/prci.c
> +
> +# Shared
> +libbsp_a_SOURCES += ../../shared/bootcard.c
> +libbsp_a_SOURCES += ../../shared/bspclean.c
> +libbsp_a_SOURCES += ../../shared/bsppredriverhook.c
> +libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c
> +libbsp_a_SOURCES += ../../shared/sbrk.c
> +libbsp_a_SOURCES += ../../shared/src/stackalloc.c
> +libbsp_a_SOURCES += ../../shared/bspgetworkarea.c
> +
> +# clock
> +libbsp_a_SOURCES += clock/clock.c
> +
> +# Timer
> +libbsp_a_SOURCES += timer/timer.c
> +
> +# console
> +libbsp_a_SOURCES += ../../shared/console-termios.c
> +libbsp_a_SOURCES += ../../shared/console-polled.c
> +libbsp_a_SOURCES += console/fe310-uart.c
> +
> +# IRQ
> +libbsp_a_SOURCES += ../../shared/src/irq-default-handler.c
> +libbsp_a_SOURCES += ../../shared/src/irq-generic.c
> +libbsp_a_SOURCES += ../../shared/src/irq-info.c
> +libbsp_a_SOURCES += irq/irq.c
> +
> +# Cache
> +libbsp_a_SOURCES += ../../../libcpu/shared/src/cache_manager.c
> +libbsp_a_SOURCES += ../../shared/include/cache_.h
> +libbsp_a_CPPFLAGS = -I$(srcdir)/../../shared/include
> +
> +# debugio
> +#libbsp_a_SOURCES += console/console-io.c
> +
> +DISTCLEANFILES = include/bspopts.h
> +
> +include $(srcdir)/preinstall.am
> +include $(top_srcdir)/../../../../automake/local.am
> diff --git a/c/src/lib/libbsp/riscv32/hifive1/bsp_specs 
> b/c/src/lib/libbsp/riscv32/hifive1/bsp_specs
> new file mode 100644
> index 000..32c105f
> --- /dev/null
> +++ b/c/src/lib/libbsp/riscv32/hifive1/bsp_specs
> @@ -0,0 +1,13 @@
> +%rename endfile old_endfile
> +%ren

Re: [PATCH 02/15] HiFive1: add linker file

2017-08-17 Thread Gedare Bloom
On Wed, Aug 16, 2017 at 11:12 AM, Denis Obrezkov
 wrote:
> ---
>  c/src/lib/libbsp/riscv32/hifive1/startup/linkcmds | 379 
> ++
>  1 file changed, 379 insertions(+)
>  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/startup/linkcmds
>
> diff --git a/c/src/lib/libbsp/riscv32/hifive1/startup/linkcmds 
> b/c/src/lib/libbsp/riscv32/hifive1/startup/linkcmds
> new file mode 100644
> index 000..8bf56a0
> --- /dev/null
> +++ b/c/src/lib/libbsp/riscv32/hifive1/startup/linkcmds
> @@ -0,0 +1,379 @@
> +/**
> + * @file
> + *
> + * @ingroup bsp_linker
> + *
> + * @brief Memory map
> + */
> +
> +/*
> + *
> + * Copyright (c) 2015 University of York.
> + * Hesham ALMatary 
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *notice, this list of conditions and the following disclaimer in the
> + *documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +OUTPUT_FORMAT("elf32-littleriscv", "elf32-littleriscv", "elf32-littleriscv")
> +OUTPUT_ARCH (riscv)
> +
> +ENTRY (_start)
> +
> +MEMORY
> +{
> +ROM  : ORIGIN = 0x2040, LENGTH = 16M
> +RAM  : ORIGIN = 0x8000, LENGTH = 16K /* 64KiB external RAM, but 
> gdb knows only about 16 KiB */
Is there actually 64K ram?

I don't have the knowledge to review the rest of this for correctness.
It  would be good to have a shared linkcmds approach though, like ARM.

> +ITIM : ORIGIN = 0x0800, LENGTH = 8K
> +}
> +
> +REGION_ALIAS ("REGION_VECTOR", ROM);
> +REGION_ALIAS ("REGION_START", ROM);
> +REGION_ALIAS ("REGION_TEXT", ROM);
> +REGION_ALIAS ("REGION_TEXT_LOAD", ROM);
> +REGION_ALIAS ("REGION_RODATA", ROM);
> +REGION_ALIAS ("REGION_RODATA_LOAD", ROM);
> +REGION_ALIAS ("REGION_DATA", RAM);
> +REGION_ALIAS ("REGION_DATA_LOAD", ROM);
> +REGION_ALIAS ("REGION_FAST_DATA", RAM);
> +REGION_ALIAS ("REGION_FAST_DATA_LOAD", ROM);
> +REGION_ALIAS ("REGION_BSS", RAM);
> +REGION_ALIAS ("REGION_WORK", RAM);
> +REGION_ALIAS ("REGION_STACK", RAM);
> +
> +/* The following address is used for text output */
> +/* bsp_section_outbut_buffer = 0x8F80; */
> + bsp_section_vector_begin  = 0x2040;
> +
> +
> +STACK_LENGTH = 0;
> +/*
> + * Global symbols that may be defined externally
> + */
> +bsp_vector_table_size = DEFINED (bsp_vector_table_size) ? 
> bsp_vector_table_size : 64;
> +
> +bsp_section_xbarrier_align  = DEFINED (bsp_section_xbarrier_align) ? 
> bsp_section_xbarrier_align : 1;
> +bsp_section_robarrier_align = DEFINED (bsp_section_robarrier_align) ? 
> bsp_section_robarrier_align : 1;
> +bsp_section_rwbarrier_align = DEFINED (bsp_section_rwbarrier_align) ? 
> bsp_section_rwbarrier_align : 1;
> +
> +bsp_stack_align = DEFINED (bsp_stack_align) ? bsp_stack_align : 8;
> +
> +bsp_stack_main_size = DEFINED (bsp_stack_main_size) ? bsp_stack_main_size : 
> 1024;
> +bsp_stack_main_size = ALIGN (bsp_stack_main_size, bsp_stack_align);
> +
> +_bsp_processor_count = DEFINED (_bsp_processor_count) ? _bsp_processor_count 
> : 1;
> +
> +SECTIONS {
> +
> +  .vector :
> +  {
> +   . = 0x100;
> +*(.vector)
> +. = ALIGN(bsp_vector_table_size);
> +bsp_section_vector_end = .;
> +  } > REGION_VECTOR AT > REGION_VECTOR
> +  bsp_section_vector_size = bsp_section_vector_end - 
> bsp_section_vector_begin;
> +  bsp_vector_table_begin = bsp_section_vector_begin;
> +  bsp_vector_table_end = bsp_vector_table_begin + bsp_vector_table_size;
> +
> +  .start :
> +  {
> +. = ALIGN(8);
> +bsp_section_start_begin = .;
> +KEEP (*(.bsp_start_text))
> +KEEP (*(.bsp_start_data))
> +bsp_section_start_end = .;
> +  } > REGION_START AT > REGION_START
> +  bsp_section_start_size = bsp_section_start_end - bsp_section_start_begin;
> +
> +.xbarrier :   {
> +. = ALIGN (bsp_section_xbarrier_align);
> +  } > REGION_VECTOR AT > REGION_VECTOR
> +
> +.text :   {
> +. = ALIGN(8);

Re: [PATCH 3/7] Import strnstr.c from FreeBSD.

2017-08-17 Thread Aditya Upadhyay
Yes.. Definitely i will do. Sichen can directly send the patch for strnstr
to newlib ml.

Thanks,
Aditya Upadhyay

On 17 Aug 2017 7:03 p.m., "Joel Sherrill"  wrote:

>
>
> On Aug 17, 2017 8:19 AM, "Gedare Bloom"  wrote:
>
> On Wed, Aug 16, 2017 at 8:14 PM, Sichen Zhao <1473996...@qq.com> wrote:
> > ---
> >  freebsd/lib/libc/string/strnstr.c | 67 ++
> +
> >  1 file changed, 67 insertions(+)
> >  create mode 100644 freebsd/lib/libc/string/strnstr.c
> >
> > diff --git a/freebsd/lib/libc/string/strnstr.c
> b/freebsd/lib/libc/string/strnstr.c
> > new file mode 100644
> > index 000..247a2b5
> > --- /dev/null
> > +++ b/freebsd/lib/libc/string/strnstr.c
> > @@ -0,0 +1,67 @@
> > +#include 
> > +
> > +/*-
> > + * Copyright (c) 2001 Mike Barcroft 
> > + * Copyright (c) 1990, 1993
> > + * The Regents of the University of California.  All rights
> reserved.
> > + *
> > + * This code is derived from software contributed to Berkeley by
> > + * Chris Torek.
> > + *
> > + * Redistribution and use in source and binary forms, with or without
> > + * modification, are permitted provided that the following conditions
> > + * are met:
> > + * 1. Redistributions of source code must retain the above copyright
> > + *notice, this list of conditions and the following disclaimer.
> > + * 2. Redistributions in binary form must reproduce the above copyright
> > + *notice, this list of conditions and the following disclaimer in
> the
> > + *documentation and/or other materials provided with the
> distribution.
> > + * 3. Neither the name of the University nor the names of its
> contributors
> > + *may be used to endorse or promote products derived from this
> software
> > + *without specific prior written permission.
> > + *
> > + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
> AND
> > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
> PURPOSE
> > + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
> LIABLE
> > + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> CONSEQUENTIAL
> > + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
> GOODS
> > + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> > + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
> STRICT
> > + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
> ANY WAY
> > + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
> OF
> > + * SUCH DAMAGE.
> > + */
> > +
> > +#if defined(LIBC_SCCS) && !defined(lint)
> > +static char sccsid[] = "@(#)strstr.c   8.1 (Berkeley) 6/4/93";
> > +#endif /* LIBC_SCCS and not lint */
> > +#include 
> > +__FBSDID("$FreeBSD$");
> > +
> > +#include 
> > +
> > +/*
> > + * Find the first occurrence of find in s, where the search is limited
> to the
> > + * first slen characters of s.
> > + */
> > +char *
> > +strnstr(const char *s, const char *find, size_t slen)
> > +{
> > +   char c, sc;
> > +   size_t len;
> > +
> > +   if ((c = *find++) != '\0') {
> > +   len = strlen(find);
> > +   do {
> > +   do {
> > +   if (slen-- < 1 || (sc = *s++) == '\0')
> > +   return (NULL);
> > +   } while (sc != c);
> > +   if (len > slen)
> > +   return (NULL);
> > +   } while (strncmp(s, find, len) != 0);
> > +   s--;
> > +   }
> > +   return ((char *)s);
> > +}
>
> This can definitely be added in newlib. Aditya may be able to assist
> in the process?
>
>
> Agreed. This should be as widely available to RTEMS applications as
> possible.
>
>
>
> > --
> > 2.7.4
> >
> > ___
> > devel mailing list
> > devel@rtems.org
> > http://lists.rtems.org/mailman/listinfo/devel
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
>
>
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH 04/15] HiFive1: add start.S file with basic initialization

2017-08-17 Thread Gedare Bloom
On Wed, Aug 16, 2017 at 11:12 AM, Denis Obrezkov
 wrote:
> ---
>  c/src/lib/libbsp/riscv32/hifive1/start/start.S | 290 
> +
>  1 file changed, 290 insertions(+)
>  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/start/start.S
>
> diff --git a/c/src/lib/libbsp/riscv32/hifive1/start/start.S 
> b/c/src/lib/libbsp/riscv32/hifive1/start/start.S
> new file mode 100644
> index 000..9531998
> --- /dev/null
> +++ b/c/src/lib/libbsp/riscv32/hifive1/start/start.S
> @@ -0,0 +1,290 @@
> +/*
> + * Copyright (c) 2015 University of York.
> + * Hesham ALMatary 
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *notice, this list of conditions and the following disclaimer in the
> + *documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +#include 
> +#include 
> +
> +# define LREG lw
> +# define SREG sw
> +
> +#define CLINT_BASE 0x0200
> +#define MTIME_OFFSET 0xBFF8
> +#define MTIMECMP_OFFSET 0x4000
> +#define MTIME_REG CLINT_BASE+MTIME_OFFSET
> +#define MTIMECMP CLINT_BASE+MTIMECMP_OFFSET
> +
> +#define REGBYTES 4
> +
> +EXTERN(bsp_section_bss_begin)
> +EXTERN(bsp_section_bss_end)
> +EXTERN(ISR_Handler)
> +EXTERN(bsp_start_vector_table_end)
> +EXTERN(bsp_start_vector_table_size)
> +EXTERN(bsp_vector_table_size)
> +EXTERN(bsp_section_stack_begin)
> +
> +
> +.balign 4
> +PUBLIC(RISCV_Exception_default)
> +/* PUBLIC(bsp_start_vector_table_begin) */
> +PUBLIC(_start)
> +
> +.section .vector, "ax"
this .section directive appears misplaced, or at least not doing
anything useful here.

> +
> +
Avoid having more than one blank line in a row.

> +.section .start, "wax"
> +TYPE_FUNC(_start)
> +SYM(_start):
> +  li x2, 0
> +  li x3, 0
> +  li x4, 0
> +  li x5, 0
> +  li x6, 0
> +  li x7, 0
> +  li x8, 0
> +  li x9, 0
> +  li x10,0
> +  li x11,0
> +  li x12,0
> +  li x13,0
> +  li x14,0
> +  li x15,0
> +  li x16,0
> +  li x17,0
> +  li x18,0
> +  li x19,0
> +  li x20,0
> +  li x21,0
> +  li x22,0
> +  li x23,0
> +  li x24,0
> +  li x25,0
> +  li x26,0
> +  li x27,0
> +  li x28,0
> +  li x29,0
> +  li x30,0
> +  li x31,0
> +
> +  /* load stack and frame pointers */
> +  la sp, bsp_section_stack_begin
> +
> +
> +
> +/* Clearing .bss */
> +  la t0, bsp_section_bss_begin
> +  la t1, bsp_section_bss_end
> +
> +_loop_clear_bss:
> +  bge t0, t1, _end_clear_bss
> +  addi  t0, t0, 4
> +  swx0, 0(t0)
> +  j _loop_clear_bss
> +  nop
> +_end_clear_bss:
> +
> +
> +/* Copy data */
> +  la t0, _copy_start
> +  la t1, _copy_end
> +  la t3, __data_start_rom
> +
> +_loop_copy_data:
> +  bge t0, t1, _end_copy_data
> +  lb  t4, 0(t3)
> +  sb   t4, 0(t0)
> +  addi t0, t0, 1
> +  addi t3, t3, 1
> +  j_loop_copy_data
> +  nop
> +_end_copy_data:
> +
> +
> +
> +/*
> + * Examples of generating clock and software interrupts.
> + * interrupts won't be generated because they are turned off
> + */
> +irq_gen:
> +/*  sw t0, 0(t1) */
> +  li t2, MTIME_REG
> +  li t4, 0x30
> +  lw t0, 0(t2)
> +  add t0, t0, t4
> +  li t3, MTIMECMP
> +  sw t0, 0(t3)
> +
> +/* copy MSB of mtime */
> +  addi t3, t3, 4
> +  addi t2, t2, 4
> +/* race condition may arise here */
> +  lw t0, 0(t2)
> +  sw t0, 0(t3)
> +
> +  li t3, 0x0200
> +  li t4, 0x1
> +  /* sw t4, 0(t3) */
> +  nop
> +
> +
> +/* Enable interrupts in mie register (not enabled in mstatus yet) */
> +  la t0, RISCV_Exception_default
> +  csrw mtvec, t0
> +  li t0, 0x088
> +  csrs mie, t0
> +  csrci mstatus, 0x8
> +  csrwi mie, 0x088
> +  csrsi mstatus, 0x8
> +
> +  call boot_card
> +  nop
> +
> +
> +
> +
> +bsp_start_vector_table_begin:

Should this be in the .vector section?

> +
> +  .word RISCV_Exception_default /* bad_trap */
> +  .word RISCV_Exception_default /* pmp_trap */
> +  .word RISCV_Exception_default /* illegal_insn_trap */
> +  .word RISCV_Exception_default /* bad_trap */
> +  .word RISCV_Exceptio

Re: [PATCH 3/7] Import strnstr.c from FreeBSD.

2017-08-17 Thread Gedare Bloom
Aditya,

Can you help Sichen to put the file in the right place in newlib and
add to the build? Either help him understand how to do it, or do it
with/for him?

On Thu, Aug 17, 2017 at 10:58 AM, Aditya Upadhyay  wrote:
> Yes.. Definitely i will do. Sichen can directly send the patch for strnstr
> to newlib ml.
>
> Thanks,
> Aditya Upadhyay
>
> On 17 Aug 2017 7:03 p.m., "Joel Sherrill"  wrote:
>>
>>
>>
>> On Aug 17, 2017 8:19 AM, "Gedare Bloom"  wrote:
>>
>> On Wed, Aug 16, 2017 at 8:14 PM, Sichen Zhao <1473996...@qq.com> wrote:
>> > ---
>> >  freebsd/lib/libc/string/strnstr.c | 67
>> > +++
>> >  1 file changed, 67 insertions(+)
>> >  create mode 100644 freebsd/lib/libc/string/strnstr.c
>> >
>> > diff --git a/freebsd/lib/libc/string/strnstr.c
>> > b/freebsd/lib/libc/string/strnstr.c
>> > new file mode 100644
>> > index 000..247a2b5
>> > --- /dev/null
>> > +++ b/freebsd/lib/libc/string/strnstr.c
>> > @@ -0,0 +1,67 @@
>> > +#include 
>> > +
>> > +/*-
>> > + * Copyright (c) 2001 Mike Barcroft 
>> > + * Copyright (c) 1990, 1993
>> > + * The Regents of the University of California.  All rights
>> > reserved.
>> > + *
>> > + * This code is derived from software contributed to Berkeley by
>> > + * Chris Torek.
>> > + *
>> > + * Redistribution and use in source and binary forms, with or without
>> > + * modification, are permitted provided that the following conditions
>> > + * are met:
>> > + * 1. Redistributions of source code must retain the above copyright
>> > + *notice, this list of conditions and the following disclaimer.
>> > + * 2. Redistributions in binary form must reproduce the above copyright
>> > + *notice, this list of conditions and the following disclaimer in
>> > the
>> > + *documentation and/or other materials provided with the
>> > distribution.
>> > + * 3. Neither the name of the University nor the names of its
>> > contributors
>> > + *may be used to endorse or promote products derived from this
>> > software
>> > + *without specific prior written permission.
>> > + *
>> > + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
>> > AND
>> > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
>> > THE
>> > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
>> > PURPOSE
>> > + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
>> > LIABLE
>> > + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
>> > CONSEQUENTIAL
>> > + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
>> > GOODS
>> > + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
>> > INTERRUPTION)
>> > + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
>> > STRICT
>> > + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
>> > ANY WAY
>> > + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
>> > OF
>> > + * SUCH DAMAGE.
>> > + */
>> > +
>> > +#if defined(LIBC_SCCS) && !defined(lint)
>> > +static char sccsid[] = "@(#)strstr.c   8.1 (Berkeley) 6/4/93";
>> > +#endif /* LIBC_SCCS and not lint */
>> > +#include 
>> > +__FBSDID("$FreeBSD$");
>> > +
>> > +#include 
>> > +
>> > +/*
>> > + * Find the first occurrence of find in s, where the search is limited
>> > to the
>> > + * first slen characters of s.
>> > + */
>> > +char *
>> > +strnstr(const char *s, const char *find, size_t slen)
>> > +{
>> > +   char c, sc;
>> > +   size_t len;
>> > +
>> > +   if ((c = *find++) != '\0') {
>> > +   len = strlen(find);
>> > +   do {
>> > +   do {
>> > +   if (slen-- < 1 || (sc = *s++) == '\0')
>> > +   return (NULL);
>> > +   } while (sc != c);
>> > +   if (len > slen)
>> > +   return (NULL);
>> > +   } while (strncmp(s, find, len) != 0);
>> > +   s--;
>> > +   }
>> > +   return ((char *)s);
>> > +}
>>
>> This can definitely be added in newlib. Aditya may be able to assist
>> in the process?
>>
>>
>> Agreed. This should be as widely available to RTEMS applications as
>> possible.
>>
>>
>>
>> > --
>> > 2.7.4
>> >
>> > ___
>> > devel mailing list
>> > devel@rtems.org
>> > http://lists.rtems.org/mailman/listinfo/devel
>> ___
>> devel mailing list
>> devel@rtems.org
>> http://lists.rtems.org/mailman/listinfo/devel
>>
>>
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 07/15] HiFive1: add PRCI support files

2017-08-17 Thread Gedare Bloom
On Wed, Aug 16, 2017 at 11:12 AM, Denis Obrezkov
 wrote:
> ---
>  c/src/lib/libbsp/riscv32/hifive1/include/prci.h | 74 
> +
>  c/src/lib/libbsp/riscv32/hifive1/start/prci.c   | 33 +++
>  2 files changed, 107 insertions(+)
>  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/include/prci.h
>  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/start/prci.c
>
> diff --git a/c/src/lib/libbsp/riscv32/hifive1/include/prci.h 
> b/c/src/lib/libbsp/riscv32/hifive1/include/prci.h
> new file mode 100644
> index 000..a3432a8
> --- /dev/null
> +++ b/c/src/lib/libbsp/riscv32/hifive1/include/prci.h
> @@ -0,0 +1,74 @@
> +/*
> + *
> + * Copyright (c) 2017
> + * Denis Obrezkov 
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *notice, this list of conditions and the following disclaimer in the
> + *documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#ifndef PRCI_H
> +#define PRCI_H
> +
> +/*
> + * PRCI description for HiFive1 system
> + */
> +#define PRCI_BASE 0x10008000
> +#define PRCI_HFROSCCFG 0x10008000
> +#define PRCI_HFXOSCCFG 0x10008004
> +#define PRCI_PLLCFG 0x10008008
> +#define PRCI_PLLOUTDIV 0x1000800C
> +#define PRCI_CORECLKCFG 0x10008010
> +
> +//16 MHz from external crystall oscillator
Prefer to use /* */ comments. Typo: crystal

> +#define hifive1_default_freq 1600
> +
> +/*
> + * HFROSCCFG configuration register values
> + */
> +#define HFROSC_DIV_VAL 4
> +#define HFROSC_TRIM_VAL 16
> +#define HFROSC_EN_VAL 1
> +#define HFROSC_RDY_VAL 1
> +#define HFROSC_DIV_OFFSET 0
> +#define HFROSC_TRIM_OFFSET 16
> +#define HFROSC_EN_OFFSET 30
> +#define HFROSC_RDY_OFFSET 31
> +
> +/*
> + * HFXOSCCFG configuration register values
> + */
> +#define HFXOSC_EN_VAL 1
> +#define HFXOSC_RDY_VAL 1
> +#define HFXOSC_EN_OFFSET 30
> +#define HFXOSC_RDY_OFFSET 31
> +
> +
> +
Avoid more than 1 blank line in a row.

> +/*
> + * PLLCFG configuration register
> + */
> +#define PLL_SEL_OFFSET 16
> +
> +
> +static int hifive1_current_freq();
I'm not sure what the point of a static function prototype in a header
file is. this should probably be removed, or made non-static.

> +
> +#endif /* PRCI_H */
> diff --git a/c/src/lib/libbsp/riscv32/hifive1/start/prci.c 
> b/c/src/lib/libbsp/riscv32/hifive1/start/prci.c
> new file mode 100644
> index 000..7e5237f
> --- /dev/null
> +++ b/c/src/lib/libbsp/riscv32/hifive1/start/prci.c
> @@ -0,0 +1,33 @@
> +/*
> + *
> + * Copyright (c) 2017
> + * Denis Obrezkov 
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *notice, this list of conditions and the following disclaimer in the
> + *documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + *

Re: [PATCH 08/15] HiFive1: add irq dispatching function

2017-08-17 Thread Gedare Bloom
On Wed, Aug 16, 2017 at 11:12 AM, Denis Obrezkov
 wrote:
> ---
>  c/src/lib/libbsp/riscv32/hifive1/irq/irq.c | 90 
> ++
>  1 file changed, 90 insertions(+)
>  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/irq/irq.c
>
> diff --git a/c/src/lib/libbsp/riscv32/hifive1/irq/irq.c 
> b/c/src/lib/libbsp/riscv32/hifive1/irq/irq.c
> new file mode 100644
> index 000..6fd4e75
> --- /dev/null
> +++ b/c/src/lib/libbsp/riscv32/hifive1/irq/irq.c
> @@ -0,0 +1,90 @@
> +/**
> + * @file
> + *
> + * @ingroup riscv_interrupt
> + *
> + * @brief Interrupt support.
> + */
> +
> +/*
> + * RISCV CPU Dependent Source
> + *
> + * Copyright (c) 2015 University of York.
> + * Hesham ALMatary 
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *notice, this list of conditions and the following disclaimer in the
> + *documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#include 
> +#include 
> +#include 
> +
> +/* Almost all of the jobs that the following functions should
> + * do are implemented in cpukit
> + */
> +
> +void bsp_interrupt_handler_default(rtems_vector_number vector)
> +{
> +printk("spurious interrupt: %u\n", vector);
> +}
> +
> +rtems_status_code bsp_interrupt_facility_initialize()
> +{
> +  return 0;
> +}
> +
> +rtems_status_code bsp_interrupt_vector_enable(rtems_vector_number vector)
> +{
> +  return 0;
> +}
> +
> +rtems_status_code bsp_interrupt_vector_disable(rtems_vector_number vector)
> +{
> +  return 0;
> +}
> +
> +static uint32_t cause = 0;
> +volatile uint64_t * mtimecmp = (volatile uint64_t *)0x02004000;
> +volatile uint64_t * mtime = (volatile uint64_t *)0x0200bff8;
> +
What are these global variables used for?

> +void handle_trap_new ()
What is the purpose of this function?

> +{
> +asm volatile ("csrr %0, mcause": "=r" (cause));
It would be good to have a static inline function for reading this register.

> +if (cause & MCAUSE_INT) {
> +  /* an interrupt occurred */
> +  if ((cause & MCAUSE_MTIME) == MCAUSE_MTIME) {
> +   /* Timer interrupt */
> +   (*mtimecmp) = (*mtime) + FE310_CLOCK_PERIOD;
> +
> bsp_interrupt_handler_table[1].handler(bsp_interrupt_handler_table[1].arg);
> +  } else if ((cause & MCAUSE_MEXT) == MCAUSE_MEXT) {
> + /*External interrupt */
> +  asm volatile ("csrci mie, 0x800");
> +  } else if ((cause & MCAUSE_MSWI) == MCAUSE_MSWI) {
> + /* Software interrupt */
> + volatile uint32_t * msip_reg = (volatile uint32_t *) 0x0200;
> + *msip_reg = 0;
> +  }
> +} else {
> +  /* an exception occurred */
> +}
> +
> +}
> --
> 2.1.4
>
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 10/15] HiFive1: add clock driver support

2017-08-17 Thread Gedare Bloom
On Wed, Aug 16, 2017 at 11:13 AM, Denis Obrezkov
 wrote:
> ---
>  c/src/lib/libbsp/riscv32/hifive1/clock/clock.c | 67 
> ++
>  1 file changed, 67 insertions(+)
>  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/clock/clock.c
>
> diff --git a/c/src/lib/libbsp/riscv32/hifive1/clock/clock.c 
> b/c/src/lib/libbsp/riscv32/hifive1/clock/clock.c
> new file mode 100644
> index 000..74132ed
> --- /dev/null
> +++ b/c/src/lib/libbsp/riscv32/hifive1/clock/clock.c
> @@ -0,0 +1,67 @@
> +/*
> + * Copyright (c) 2017 Denis Obrezkov 
> + *
> + * The license and distribution terms for this file may be
> + * found in the file LICENSE in this distribution or at
> + * http://www.rtems.org/license/LICENSE.
> + */
> +
> +
> +#include 
> +#include 
> +#include 
> +
> +
> +static void FE310_clock_driver_support_install_isr(
> +  rtems_isr_entry Clock_isr
> +)
> +{
> +  rtems_status_code sc = RTEMS_SUCCESSFUL;
> +
> +  sc = rtems_interrupt_handler_install(
> +1,
> +"Clock",
> +RTEMS_INTERRUPT_UNIQUE,
> +(rtems_interrupt_handler) Clock_isr,
> +NULL
> +  );
> +  if ( sc != RTEMS_SUCCESSFUL ) {
> +rtems_fatal_error_occurred(0xdeadbeef);
> +  }
> +}
> +
> +static void FE310_clock_driver_support_at_tick ( void )
> +{
Does the timer automatically re-load?

> +}
> +
> +static void FE310_clock_init ( void )
> +{
> +  volatile uint64_t * mtime = (volatile uint64_t *)0x0200bff8;
> +  volatile uint64_t * mtimecmp = (volatile uint64_t *)0x02004000;
> +  (*mtimecmp) = (*mtime) + FE310_CLOCK_PERIOD + 0x3000;
> +  asm volatile ("csrci mstatus, 0x8");
> +  asm volatile ("li t0, 0x80\n\t"
> +"csrs mie, t0");
> +  asm volatile ("csrsi mstatus, 0x8");
It would be good to have inline functions for reading/writing all of
these special purpose registers.

> +}
> +
> +static void FE310_clock_driver_support_shutdown_hardware( void )
> +{
> +}
> +
> +#define Clock_driver_support_initialize_hardware() \
> +  FE310_clock_init()
> +
> +#define CLOCK_DRIVER_USE_DUMMY_TIMECOUNTER
> +
> +#define Clock_driver_support_install_isr(isr,old) \
> +  FE310_clock_driver_support_install_isr ( isr )
> +
> +#define Clock_driver_support_at_tick() \
> +  FE310_clock_driver_support_at_tick()
> +
> +#define Clock_driver_support_shutdown_hardware() \
> +  FE310_clock_driver_support_shutdown_hardware()
> +
> +#include "../../../shared/clockdrv_shell.h"
> +
> --
> 2.1.4
>
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 11/15] HiFive1: set up oscillators

2017-08-17 Thread Gedare Bloom
On Wed, Aug 16, 2017 at 11:13 AM, Denis Obrezkov
 wrote:
> ---
>  c/src/lib/libbsp/riscv32/hifive1/start/bspstart.c | 65 
> +++
>  1 file changed, 65 insertions(+)
>  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/start/bspstart.c
>
> diff --git a/c/src/lib/libbsp/riscv32/hifive1/start/bspstart.c 
> b/c/src/lib/libbsp/riscv32/hifive1/start/bspstart.c
> new file mode 100644
> index 000..efef4e0
> --- /dev/null
> +++ b/c/src/lib/libbsp/riscv32/hifive1/start/bspstart.c
> @@ -0,0 +1,65 @@
> +/*
> + *  Copyright (c) 2017
> + *  Denis Obrezkov 
> + *
> + *  The license and distribution terms for this file may be
> + *  found in the file LICENSE in this distribution or at
> + *  http://www.rtems.org/license/LICENSE.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/*
> + * This routine make initialization of HiFive1 (FE310) counters.
> + */
> +
> +void bsp_start( void )
> +{
> +  volatile uint32_t * pll_reg = (volatile uint32_t *) PRCI_PLLCFG;
> +  volatile uint32_t * high_freq_reg = (volatile uint32_t *) PRCI_HFROSCCFG;
> +  volatile uint32_t * spi0 = (volatile uint32_t *) 0x10014000;
> +
> +  volatile uint64_t * mtime_reg = (volatile uint64_t * ) 0x0200bff8;
> +  volatile uint64_t * mtimecmp_reg = (volatile uint64_t * ) 0x02004000;
> +
> +#ifdef USE_HFROSC
> +  /* Setting up osc frequency */
> +  uint32_t tmp_reg = 0;
> +  /* Install divider in high frequency oscillator */
> +  tmp_reg |= (HFROSC_DIV_VAL & 0x2f) << HFROSC_DIV_OFFSET;
> +  tmp_reg |= (HFROSC_TRIM_VAL & 0x1F) << HFROSC_TRIM_OFFSET;
> +  tmp_reg |= (HFROSC_EN_VAL & 0x1) << HFROSC_EN_OFFSET;
> +  (*high_freq_reg) = tmp_reg;
It would be good to make the above into a function.

> +  while (( (*high_freq_reg) & ((HFROSC_RDY_VAL & 0x1) \
> +  << HFROSC_RDY_OFFSET)) == 0 ) {
> +;
> +  }
> +#endif /* USE_HFROSC */
> +
> +#ifdef USE_HFXOSC
> +  volatile uint32_t * ext_freq_reg = (volatile uint32_t *) PRCI_HFXOSCCFG;
> +  (*ext_freq_reg) |= ((HFXOSC_EN_VAL & 0x1) << HFXOSC_EN_OFFSET);
> +  while (( (*ext_freq_reg) & ((HFXOSC_RDY_VAL & 0x1) \
> +  << HFXOSC_RDY_OFFSET)) == 0 ) {
> +;
> +  }
> +  (*pll_reg) |= (0x1 << 18);
> +  (*pll_reg) |= (0x1 << 17);
> +  (*pll_reg) |= (0x1 << PLL_SEL_OFFSET);
> +  (*high_freq_reg) &= ~(0x1 << HFROSC_EN_OFFSET);
> +
> +#endif /* USE_HFXOSC */
> +#ifndef USE_PLL
> +  /* Disable PLL */
> +  (*pll_reg) &= ~(0x1 << PLL_SEL_OFFSET);
> +#else
> +
> +#endif
> +
> +  bsp_interrupt_initialize();
> +
> +}
> +
> --
> 2.1.4
>
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 12/15] HiFive1: add UART support

2017-08-17 Thread Gedare Bloom
Remove the extra blank lines, and consider adding some helper
functions (for enable/disable UARTx, for example)

On Wed, Aug 16, 2017 at 11:13 AM, Denis Obrezkov
 wrote:
> ---
>  .../libbsp/riscv32/hifive1/console/fe310-uart.c| 215 
> +
>  .../libbsp/riscv32/hifive1/include/fe310-gpio.h|  41 
>  .../libbsp/riscv32/hifive1/include/fe310-uart.h|  38 
>  3 files changed, 294 insertions(+)
>  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/console/fe310-uart.c
>  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/include/fe310-gpio.h
>  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/include/fe310-uart.h
>
> diff --git a/c/src/lib/libbsp/riscv32/hifive1/console/fe310-uart.c 
> b/c/src/lib/libbsp/riscv32/hifive1/console/fe310-uart.c
> new file mode 100644
> index 000..1784ff7
> --- /dev/null
> +++ b/c/src/lib/libbsp/riscv32/hifive1/console/fe310-uart.c
> @@ -0,0 +1,215 @@
> +/*
> + * Copyright (c) 2017 Denis Obrezkov 
> + *
> + * The license and distribution terms for this file may be
> + * found in the file LICENSE in this distribution or at
> + * http://www.rtems.org/license/LICENSE.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +static void fe310_console_putc (char ch);
> +
> +fe310_uart_context driver_context = {
> +  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("FE310_UART0"),
> +  .device_name = "/dev/console",
> +  .regs = (volatile fe310_uart_t *) &FE310_UART0,
> +};
> +
> +
> +rtems_device_driver console_initialize(
> +  rtems_device_major_number  major,
> +  rtems_device_minor_number  minor,
> +  void  *arg
> +)
> +{
> +  rtems_status_code sc;
> +  const rtems_termios_device_handler *handler = &fe310_uart_handler_polled;
> +
> +  /*
> +   * Initialize the Termios infrastructure.  If Termios has already
> +   * been initialized by another device driver, then this call will
> +   * have no effect.
> +   */
> +  rtems_termios_initialize();
> +  fe310_uart_context * ctx = &driver_context;
> +/*
> + * Install this device in the file system and Termios.  In order
> + * to use the console (i.e. being able to do printf, scanf etc.
> + * on stdin, stdout and stderr), one device must be registered as
> + * "/dev/console" (CONSOLE_DEVICE_NAME).
> + */
> +  sc = rtems_termios_device_install(
> +  ctx->device_name,
> +  handler,
> +  NULL,
> +  &ctx->base
> +  );
> +  if ( sc != RTEMS_SUCCESSFUL ) {
> +bsp_fatal(BSP_FATAL_CONSOLE_NO_DEV);
> +  }
> +
> +  return RTEMS_SUCCESSFUL;
> +}
> +
> +
> +
> +static bool fe310_uart_first_open (
> +  rtems_termios_tty *tty,
> +  rtems_termios_device_context  *base,
> +  struct termios*term,
> +  rtems_libio_open_close_args_t *args
> +)
> +{
> +  volatile fe310_gpio_t * gpio;
> +  fe310_uart_context * ctx;
> +  rtems_status_code sc;
> +
> +
> +  /* Configure GPIO to be UART */
> +  gpio = (volatile fe310_gpio_t *)&FE310_GPIO;
> +  gpio->iof_sel &= ~IOF0_UART0_MASK;
> +  gpio->iof_en |= ~IOF0_UART0_MASK;
> +
> +
> +  sc = rtems_termios_set_initial_baud (tty, B115200);
> +  if ( sc != RTEMS_SUCCESSFUL ) {
> +return false;
> +  }
> +
> +  /* Set up a baud rate and enable tx and rx */
> +  ctx = (fe310_uart_context *) base;
> +  (ctx->regs)->div = hifive1_default_freq / 115200 - 1;
> +  (ctx->regs)->txctrl |= 1;
> +  (ctx->regs)->rxctrl |= 1;
> +  return true;
> +};
> +
> +static void fe310_uart_last_close (
> +  rtems_termios_tty *tty,
> +  rtems_termios_device_context  *base,
> +  rtems_libio_open_close_args_t *args
> +)
> +{
> +  return;
> +}
> +
> +static int fe310_uart_poll_read (
> +  rtems_termios_device_context  *base
> +)
> +{
> +  fe310_uart_context * ctx = (fe310_uart_context*) base;
> +  size_t i;
> +
> +  if (((ctx->regs->rxdata) & 0x8000) != 0) {
> +return -1;
> +  } else {
> +return ctx->regs->rxdata;
> +  }
> +}
> +
> +static uint32_t freq = 0;
> +
> +static ssize_t fe310_uart_poll_write (
> +  rtems_termios_device_context  *base,
> +  const char*buf,
> +  size_tn
> +)
> +{
> +
> +  fe310_uart_context * ctx = (fe310_uart_context*) base;
> +  size_t i;
> +
> +
> +  volatile fe310_gpio_t * gpio;
> +  rtems_status_code sc;
> +
> +  gpio = (volatile fe310_gpio_t *)&FE310_GPIO;
> +  gpio->iof_sel &= ~IOF0_UART0_MASK;
> +  gpio->iof_en |= ~IOF0_UART0_MASK;
> +
> +  gpio->iof_sel &= ~IOF0_UART1_MASK;
> +  gpio->iof_en |= ~IOF0_UART1_MASK;
> +
> +
> +  (ctx->regs)->div = hifive1_default_freq / 115200 - 1;
> +  (ctx->regs)->txctrl |= 1;
> +  (ctx->regs)->rxctrl |= 1;
> +
> +
> +
> +  for (i = 0; i < n; ++i) {
> +while (((ctx->regs->txdata) & 0x8000) != 0) {
> +;
> +}
> +ctx->regs->txdata = buf[i];
> +  }
> +  return n;
> +}
> +
> +static void fe310_console_putc (char ch) {
> +  fe310_uart_poll_write ( (rtems_termios_device_context *)&driver_contex

Re: [PATCH 3/7] Import strnstr.c from FreeBSD.

2017-08-17 Thread Aditya Upadhyay
Yes, I can.

On 17 Aug 2017 8:32 p.m., "Gedare Bloom"  wrote:

> Aditya,
>
> Can you help Sichen to put the file in the right place in newlib and
> add to the build? Either help him understand how to do it, or do it
> with/for him?
>
> On Thu, Aug 17, 2017 at 10:58 AM, Aditya Upadhyay 
> wrote:
> > Yes.. Definitely i will do. Sichen can directly send the patch for
> strnstr
> > to newlib ml.
> >
> > Thanks,
> > Aditya Upadhyay
> >
> > On 17 Aug 2017 7:03 p.m., "Joel Sherrill"  wrote:
> >>
> >>
> >>
> >> On Aug 17, 2017 8:19 AM, "Gedare Bloom"  wrote:
> >>
> >> On Wed, Aug 16, 2017 at 8:14 PM, Sichen Zhao <1473996...@qq.com> wrote:
> >> > ---
> >> >  freebsd/lib/libc/string/strnstr.c | 67
> >> > +++
> >> >  1 file changed, 67 insertions(+)
> >> >  create mode 100644 freebsd/lib/libc/string/strnstr.c
> >> >
> >> > diff --git a/freebsd/lib/libc/string/strnstr.c
> >> > b/freebsd/lib/libc/string/strnstr.c
> >> > new file mode 100644
> >> > index 000..247a2b5
> >> > --- /dev/null
> >> > +++ b/freebsd/lib/libc/string/strnstr.c
> >> > @@ -0,0 +1,67 @@
> >> > +#include 
> >> > +
> >> > +/*-
> >> > + * Copyright (c) 2001 Mike Barcroft 
> >> > + * Copyright (c) 1990, 1993
> >> > + * The Regents of the University of California.  All rights
> >> > reserved.
> >> > + *
> >> > + * This code is derived from software contributed to Berkeley by
> >> > + * Chris Torek.
> >> > + *
> >> > + * Redistribution and use in source and binary forms, with or without
> >> > + * modification, are permitted provided that the following conditions
> >> > + * are met:
> >> > + * 1. Redistributions of source code must retain the above copyright
> >> > + *notice, this list of conditions and the following disclaimer.
> >> > + * 2. Redistributions in binary form must reproduce the above
> copyright
> >> > + *notice, this list of conditions and the following disclaimer in
> >> > the
> >> > + *documentation and/or other materials provided with the
> >> > distribution.
> >> > + * 3. Neither the name of the University nor the names of its
> >> > contributors
> >> > + *may be used to endorse or promote products derived from this
> >> > software
> >> > + *without specific prior written permission.
> >> > + *
> >> > + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS
> IS''
> >> > AND
> >> > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
> >> > THE
> >> > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
> >> > PURPOSE
> >> > + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
> >> > LIABLE
> >> > + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> >> > CONSEQUENTIAL
> >> > + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
> >> > GOODS
> >> > + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> >> > INTERRUPTION)
> >> > + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> CONTRACT,
> >> > STRICT
> >> > + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
> >> > ANY WAY
> >> > + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> POSSIBILITY
> >> > OF
> >> > + * SUCH DAMAGE.
> >> > + */
> >> > +
> >> > +#if defined(LIBC_SCCS) && !defined(lint)
> >> > +static char sccsid[] = "@(#)strstr.c   8.1 (Berkeley) 6/4/93";
> >> > +#endif /* LIBC_SCCS and not lint */
> >> > +#include 
> >> > +__FBSDID("$FreeBSD$");
> >> > +
> >> > +#include 
> >> > +
> >> > +/*
> >> > + * Find the first occurrence of find in s, where the search is
> limited
> >> > to the
> >> > + * first slen characters of s.
> >> > + */
> >> > +char *
> >> > +strnstr(const char *s, const char *find, size_t slen)
> >> > +{
> >> > +   char c, sc;
> >> > +   size_t len;
> >> > +
> >> > +   if ((c = *find++) != '\0') {
> >> > +   len = strlen(find);
> >> > +   do {
> >> > +   do {
> >> > +   if (slen-- < 1 || (sc = *s++) == '\0')
> >> > +   return (NULL);
> >> > +   } while (sc != c);
> >> > +   if (len > slen)
> >> > +   return (NULL);
> >> > +   } while (strncmp(s, find, len) != 0);
> >> > +   s--;
> >> > +   }
> >> > +   return ((char *)s);
> >> > +}
> >>
> >> This can definitely be added in newlib. Aditya may be able to assist
> >> in the process?
> >>
> >>
> >> Agreed. This should be as widely available to RTEMS applications as
> >> possible.
> >>
> >>
> >>
> >> > --
> >> > 2.7.4
> >> >
> >> > ___
> >> > devel mailing list
> >> > devel@rtems.org
> >> > http://lists.rtems.org/mailman/listinfo/devel
> >> ___
> >> devel mailing list
> >> devel@rtems.org
> >> http://lists.rtems.org/mailman/listinfo/devel
> >>
> >>
> >
>
___
devel mailin

Re: [PATCH 15/15] HiFive1: disable/enable interrupts during context switch

2017-08-17 Thread Gedare Bloom
On Wed, Aug 16, 2017 at 11:13 AM, Denis Obrezkov
 wrote:
> ---
>  cpukit/score/cpu/riscv32/riscv-context-switch.S | 12 ++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/cpukit/score/cpu/riscv32/riscv-context-switch.S 
> b/cpukit/score/cpu/riscv32/riscv-context-switch.S
> index a199596..bcdfe0e 100644
> --- a/cpukit/score/cpu/riscv32/riscv-context-switch.S
> +++ b/cpukit/score/cpu/riscv32/riscv-context-switch.S
> @@ -46,6 +46,7 @@ PUBLIC(restore)
>
>  SYM(_CPU_Context_switch):
>/* Disable interrupts and store all registers */
> +  csrci mstatus, 0x8
Why is this necessary?

>SREG x1, 4(a0)
>SREG x2, 8(a0)
>SREG x3, 12(a0)
> @@ -78,8 +79,9 @@ SYM(_CPU_Context_switch):
>SREG x30, 120(a0)
>SREG x31, 124(a0)
>
> -SYM(restore):
>
> +SYM(restore):
> +
>LREG x1, 4(a1)
>LREG x2, 8(a1)
>LREG x3, 12(a1)
> @@ -111,9 +113,15 @@ SYM(restore):
>LREG x29, 116(a1)
>LREG x30, 120(a1)
>LREG x31, 124(a1)
> -   ret
> +
> +
> +  csrsi mstatus, 0x8
> +  nop
> +  nop
Why the nops?

> +  ret
>
>  SYM(_CPU_Context_restore):
> +  csrci mstatus, 0x8
>mv a1, a0
>j   restore
>nop
> --
> 2.1.4
>
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 02/15] HiFive1: add linker file

2017-08-17 Thread Denis Obrezkov
2017-08-17 16:57 GMT+02:00 Gedare Bloom :

> On Wed, Aug 16, 2017 at 11:12 AM, Denis Obrezkov
>  wrote:
> > ---
> >  c/src/lib/libbsp/riscv32/hifive1/startup/linkcmds | 379
> ++
> >  1 file changed, 379 insertions(+)
> >  create mode 100644 c/src/lib/libbsp/riscv32/hifive1/startup/linkcmds
> >
> > diff --git a/c/src/lib/libbsp/riscv32/hifive1/startup/linkcmds
> b/c/src/lib/libbsp/riscv32/hifive1/startup/linkcmds
> > new file mode 100644
> > index 000..8bf56a0
> > --- /dev/null
> > +++ b/c/src/lib/libbsp/riscv32/hifive1/startup/linkcmds
> > @@ -0,0 +1,379 @@
> > +/**
> > + * @file
> > + *
> > + * @ingroup bsp_linker
> > + *
> > + * @brief Memory map
> > + */
> > +
> > +/*
> > + *
> > + * Copyright (c) 2015 University of York.
> > + * Hesham ALMatary 
> > + *
> > + * Redistribution and use in source and binary forms, with or without
> > + * modification, are permitted provided that the following conditions
> > + * are met:
> > + * 1. Redistributions of source code must retain the above copyright
> > + *notice, this list of conditions and the following disclaimer.
> > + * 2. Redistributions in binary form must reproduce the above copyright
> > + *notice, this list of conditions and the following disclaimer in
> the
> > + *documentation and/or other materials provided with the
> distribution.
> > + *
> > + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
> AND
> > + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> > + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
> PURPOSE
> > + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
> LIABLE
> > + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> CONSEQUENTIAL
> > + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
> GOODS
> > + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> > + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
> STRICT
> > + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
> ANY WAY
> > + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
> OF
> > + * SUCH DAMAGE.
> > + */
> > +
> > +OUTPUT_FORMAT("elf32-littleriscv", "elf32-littleriscv",
> "elf32-littleriscv")
> > +OUTPUT_ARCH (riscv)
> > +
> > +ENTRY (_start)
> > +
> > +MEMORY
> > +{
> > +ROM  : ORIGIN = 0x2040, LENGTH = 16M
> > +RAM  : ORIGIN = 0x8000, LENGTH = 16K /* 64KiB external RAM,
> but gdb knows only about 16 KiB */
> Is there actually 64K ram?
>
> I don't have the knowledge to review the rest of this for correctness.
> It  would be good to have a shared linkcmds approach though, like ARM.
>
> > +ITIM : ORIGIN = 0x0800, LENGTH = 8K
> > +}
> > +
> > +REGION_ALIAS ("REGION_VECTOR", ROM);
> > +REGION_ALIAS ("REGION_START", ROM);
> > +REGION_ALIAS ("REGION_TEXT", ROM);
> > +REGION_ALIAS ("REGION_TEXT_LOAD", ROM);
> > +REGION_ALIAS ("REGION_RODATA", ROM);
> > +REGION_ALIAS ("REGION_RODATA_LOAD", ROM);
> > +REGION_ALIAS ("REGION_DATA", RAM);
> > +REGION_ALIAS ("REGION_DATA_LOAD", ROM);
> > +REGION_ALIAS ("REGION_FAST_DATA", RAM);
> > +REGION_ALIAS ("REGION_FAST_DATA_LOAD", ROM);
> > +REGION_ALIAS ("REGION_BSS", RAM);
> > +REGION_ALIAS ("REGION_WORK", RAM);
> > +REGION_ALIAS ("REGION_STACK", RAM);
> > +
> > +/* The following address is used for text output */
> > +/* bsp_section_outbut_buffer = 0x8F80; */
> > + bsp_section_vector_begin  = 0x2040;
> > +
> > +
> > +STACK_LENGTH = 0;
> > +/*
> > + * Global symbols that may be defined externally
> > + */
> > +bsp_vector_table_size = DEFINED (bsp_vector_table_size) ?
> bsp_vector_table_size : 64;
> > +
> > +bsp_section_xbarrier_align  = DEFINED (bsp_section_xbarrier_align) ?
> bsp_section_xbarrier_align : 1;
> > +bsp_section_robarrier_align = DEFINED (bsp_section_robarrier_align) ?
> bsp_section_robarrier_align : 1;
> > +bsp_section_rwbarrier_align = DEFINED (bsp_section_rwbarrier_align) ?
> bsp_section_rwbarrier_align : 1;
> > +
> > +bsp_stack_align = DEFINED (bsp_stack_align) ? bsp_stack_align : 8;
> > +
> > +bsp_stack_main_size = DEFINED (bsp_stack_main_size) ?
> bsp_stack_main_size : 1024;
> > +bsp_stack_main_size = ALIGN (bsp_stack_main_size, bsp_stack_align);
> > +
> > +_bsp_processor_count = DEFINED (_bsp_processor_count) ?
> _bsp_processor_count : 1;
> > +
> > +SECTIONS {
> > +
> > +  .vector :
> > +  {
> > +   . = 0x100;
> > +*(.vector)
> > +. = ALIGN(bsp_vector_table_size);
> > +bsp_section_vector_end = .;
> > +  } > REGION_VECTOR AT > REGION_VECTOR
> > +  bsp_section_vector_size = bsp_section_vector_end -
> bsp_section_vector_begin;
> > +  bsp_vector_table_begin = bsp_section_vector_begin;
> > +  bsp_vector_table_end = bsp_vector_table_begin + bsp_vector_table_size;
> > +
> > +  .start :
> > +  {
> > +. = ALIGN(8);
> > +bsp_section_start_begin = .;
> > +KEEP (*(.bsp_start_text))
> > +KEEP (*(.bsp_start_data))
> > +bs

Re: [PATCH 15/15] HiFive1: disable/enable interrupts during context switch

2017-08-17 Thread Denis Obrezkov
2017-08-17 17:25 GMT+02:00 Gedare Bloom :

> On Wed, Aug 16, 2017 at 11:13 AM, Denis Obrezkov
>  wrote:
> > ---
> >  cpukit/score/cpu/riscv32/riscv-context-switch.S | 12 ++--
> >  1 file changed, 10 insertions(+), 2 deletions(-)
> >
> > diff --git a/cpukit/score/cpu/riscv32/riscv-context-switch.S
> b/cpukit/score/cpu/riscv32/riscv-context-switch.S
> > index a199596..bcdfe0e 100644
> > --- a/cpukit/score/cpu/riscv32/riscv-context-switch.S
> > +++ b/cpukit/score/cpu/riscv32/riscv-context-switch.S
> > @@ -46,6 +46,7 @@ PUBLIC(restore)
> >
> >  SYM(_CPU_Context_switch):
> >/* Disable interrupts and store all registers */
> > +  csrci mstatus, 0x8
> Why is this necessary?
>
> >SREG x1, 4(a0)
> >SREG x2, 8(a0)
> >SREG x3, 12(a0)
> > @@ -78,8 +79,9 @@ SYM(_CPU_Context_switch):
> >SREG x30, 120(a0)
> >SREG x31, 124(a0)
> >
> > -SYM(restore):
> >
> > +SYM(restore):
> > +
> >LREG x1, 4(a1)
> >LREG x2, 8(a1)
> >LREG x3, 12(a1)
> > @@ -111,9 +113,15 @@ SYM(restore):
> >LREG x29, 116(a1)
> >LREG x30, 120(a1)
> >LREG x31, 124(a1)
> > -   ret
> > +
> > +
> > +  csrsi mstatus, 0x8
> > +  nop
> > +  nop
> Why the nops?
>
> > +  ret
> >
> >  SYM(_CPU_Context_restore):
> > +  csrci mstatus, 0x8
> >mv a1, a0
> >j   restore
> >nop
> > --
> > 2.1.4
> >
> > ___
> > devel mailing list
> > devel@rtems.org
> > http://lists.rtems.org/mailman/listinfo/devel
>
So, don't we turn off interrupts during the context switch?
Yes, nops are unnecessary.


-- 
Regards, Denis Obrezkov
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH 15/15] HiFive1: disable/enable interrupts during context switch

2017-08-17 Thread Gedare Bloom
On Thu, Aug 17, 2017 at 1:48 PM, Denis Obrezkov  wrote:
> 2017-08-17 17:25 GMT+02:00 Gedare Bloom :
>>
>> On Wed, Aug 16, 2017 at 11:13 AM, Denis Obrezkov
>>  wrote:
>> > ---
>> >  cpukit/score/cpu/riscv32/riscv-context-switch.S | 12 ++--
>> >  1 file changed, 10 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/cpukit/score/cpu/riscv32/riscv-context-switch.S
>> > b/cpukit/score/cpu/riscv32/riscv-context-switch.S
>> > index a199596..bcdfe0e 100644
>> > --- a/cpukit/score/cpu/riscv32/riscv-context-switch.S
>> > +++ b/cpukit/score/cpu/riscv32/riscv-context-switch.S
>> > @@ -46,6 +46,7 @@ PUBLIC(restore)
>> >
>> >  SYM(_CPU_Context_switch):
>> >/* Disable interrupts and store all registers */
>> > +  csrci mstatus, 0x8
>> Why is this necessary?
>>
>> >SREG x1, 4(a0)
>> >SREG x2, 8(a0)
>> >SREG x3, 12(a0)
>> > @@ -78,8 +79,9 @@ SYM(_CPU_Context_switch):
>> >SREG x30, 120(a0)
>> >SREG x31, 124(a0)
>> >
>> > -SYM(restore):
>> >
>> > +SYM(restore):
>> > +
>> >LREG x1, 4(a1)
>> >LREG x2, 8(a1)
>> >LREG x3, 12(a1)
>> > @@ -111,9 +113,15 @@ SYM(restore):
>> >LREG x29, 116(a1)
>> >LREG x30, 120(a1)
>> >LREG x31, 124(a1)
>> > -   ret
>> > +
>> > +
>> > +  csrsi mstatus, 0x8
>> > +  nop
>> > +  nop
>> Why the nops?
>>
>> > +  ret
>> >
>> >  SYM(_CPU_Context_restore):
>> > +  csrci mstatus, 0x8
>> >mv a1, a0
>> >j   restore
>> >nop
>> > --
>> > 2.1.4
>> >
>> > ___
>> > devel mailing list
>> > devel@rtems.org
>> > http://lists.rtems.org/mailman/listinfo/devel
>
> So, don't we turn off interrupts during the context switch?

Nope, and turning them back on unconditionally is wrong too.

> Yes, nops are unnecessary.
>
>
> --
> Regards, Denis Obrezkov
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 15/15] HiFive1: disable/enable interrupts during context switch

2017-08-17 Thread Denis Obrezkov
2017-08-17 22:07 GMT+02:00 Gedare Bloom :

> On Thu, Aug 17, 2017 at 1:48 PM, Denis Obrezkov 
> wrote:
> > 2017-08-17 17:25 GMT+02:00 Gedare Bloom :
> >>
> >> On Wed, Aug 16, 2017 at 11:13 AM, Denis Obrezkov
> >>  wrote:
> >> > ---
> >> >  cpukit/score/cpu/riscv32/riscv-context-switch.S | 12 ++--
> >> >  1 file changed, 10 insertions(+), 2 deletions(-)
> >> >
> >> > diff --git a/cpukit/score/cpu/riscv32/riscv-context-switch.S
> >> > b/cpukit/score/cpu/riscv32/riscv-context-switch.S
> >> > index a199596..bcdfe0e 100644
> >> > --- a/cpukit/score/cpu/riscv32/riscv-context-switch.S
> >> > +++ b/cpukit/score/cpu/riscv32/riscv-context-switch.S
> >> > @@ -46,6 +46,7 @@ PUBLIC(restore)
> >> >
> >> >  SYM(_CPU_Context_switch):
> >> >/* Disable interrupts and store all registers */
> >> > +  csrci mstatus, 0x8
> >> Why is this necessary?
> >>
> >> >SREG x1, 4(a0)
> >> >SREG x2, 8(a0)
> >> >SREG x3, 12(a0)
> >> > @@ -78,8 +79,9 @@ SYM(_CPU_Context_switch):
> >> >SREG x30, 120(a0)
> >> >SREG x31, 124(a0)
> >> >
> >> > -SYM(restore):
> >> >
> >> > +SYM(restore):
> >> > +
> >> >LREG x1, 4(a1)
> >> >LREG x2, 8(a1)
> >> >LREG x3, 12(a1)
> >> > @@ -111,9 +113,15 @@ SYM(restore):
> >> >LREG x29, 116(a1)
> >> >LREG x30, 120(a1)
> >> >LREG x31, 124(a1)
> >> > -   ret
> >> > +
> >> > +
> >> > +  csrsi mstatus, 0x8
> >> > +  nop
> >> > +  nop
> >> Why the nops?
> >>
> >> > +  ret
> >> >
> >> >  SYM(_CPU_Context_restore):
> >> > +  csrci mstatus, 0x8
> >> >mv a1, a0
> >> >j   restore
> >> >nop
> >> > --
> >> > 2.1.4
> >> >
> >> > ___
> >> > devel mailing list
> >> > devel@rtems.org
> >> > http://lists.rtems.org/mailman/listinfo/devel
> >
> > So, don't we turn off interrupts during the context switch?
>
> Nope, and turning them back on unconditionally is wrong too.
>
> > Yes, nops are unnecessary.
> >
> >
> > --
> > Regards, Denis Obrezkov
>
Ok, I was confused by this obsolete comment:
/* Disable interrupts and store all registers */
Will remove all that enabling/disabling.

Is the same true for start.S file with interrupted task's stack saving?



-- 
Regards, Denis Obrezkov
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH 15/15] HiFive1: disable/enable interrupts during context switch

2017-08-17 Thread Gedare Bloom
On Thu, Aug 17, 2017 at 4:17 PM, Denis Obrezkov  wrote:
> 2017-08-17 22:07 GMT+02:00 Gedare Bloom :
>>
>> On Thu, Aug 17, 2017 at 1:48 PM, Denis Obrezkov 
>> wrote:
>> > 2017-08-17 17:25 GMT+02:00 Gedare Bloom :
>> >>
>> >> On Wed, Aug 16, 2017 at 11:13 AM, Denis Obrezkov
>> >>  wrote:
>> >> > ---
>> >> >  cpukit/score/cpu/riscv32/riscv-context-switch.S | 12 ++--
>> >> >  1 file changed, 10 insertions(+), 2 deletions(-)
>> >> >
>> >> > diff --git a/cpukit/score/cpu/riscv32/riscv-context-switch.S
>> >> > b/cpukit/score/cpu/riscv32/riscv-context-switch.S
>> >> > index a199596..bcdfe0e 100644
>> >> > --- a/cpukit/score/cpu/riscv32/riscv-context-switch.S
>> >> > +++ b/cpukit/score/cpu/riscv32/riscv-context-switch.S
>> >> > @@ -46,6 +46,7 @@ PUBLIC(restore)
>> >> >
>> >> >  SYM(_CPU_Context_switch):
>> >> >/* Disable interrupts and store all registers */
>> >> > +  csrci mstatus, 0x8
>> >> Why is this necessary?
>> >>
>> >> >SREG x1, 4(a0)
>> >> >SREG x2, 8(a0)
>> >> >SREG x3, 12(a0)
>> >> > @@ -78,8 +79,9 @@ SYM(_CPU_Context_switch):
>> >> >SREG x30, 120(a0)
>> >> >SREG x31, 124(a0)
>> >> >
>> >> > -SYM(restore):
>> >> >
>> >> > +SYM(restore):
>> >> > +
>> >> >LREG x1, 4(a1)
>> >> >LREG x2, 8(a1)
>> >> >LREG x3, 12(a1)
>> >> > @@ -111,9 +113,15 @@ SYM(restore):
>> >> >LREG x29, 116(a1)
>> >> >LREG x30, 120(a1)
>> >> >LREG x31, 124(a1)
>> >> > -   ret
>> >> > +
>> >> > +
>> >> > +  csrsi mstatus, 0x8
>> >> > +  nop
>> >> > +  nop
>> >> Why the nops?
>> >>
>> >> > +  ret
>> >> >
>> >> >  SYM(_CPU_Context_restore):
>> >> > +  csrci mstatus, 0x8
>> >> >mv a1, a0
>> >> >j   restore
>> >> >nop
>> >> > --
>> >> > 2.1.4
>> >> >
>> >> > ___
>> >> > devel mailing list
>> >> > devel@rtems.org
>> >> > http://lists.rtems.org/mailman/listinfo/devel
>> >
>> > So, don't we turn off interrupts during the context switch?
>>
>> Nope, and turning them back on unconditionally is wrong too.
>>
>> > Yes, nops are unnecessary.
>> >
>> >
>> > --
>> > Regards, Denis Obrezkov
>
> Ok, I was confused by this obsolete comment:
> /* Disable interrupts and store all registers */
> Will remove all that enabling/disabling.
>
> Is the same true for start.S file with interrupted task's stack saving?
>
I'm not sure exactly what you're referring to, but usually start.S
will, among other things, turn off and ack pending interrupts to
quiesce the hardware before handing off the rest of system init to
boot_card. Eventually RTEMS will enable interrupts again using the
cpukit's interrupt_enable layer.

>
>
> --
> Regards, Denis Obrezkov
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel