Changes since April

Clean up of build directories.
Simplifications to capability model.
This commit is contained in:
Bahadir Balban
2010-06-01 15:08:13 +03:00
parent aef14b55ec
commit 6fa4884a5a
450 changed files with 10449 additions and 7383 deletions

39
conts/userlibs/SConscript Normal file
View File

@@ -0,0 +1,39 @@
# -*- mode: python; coding: utf-8; -*-
#
# Codezero -- Virtualization microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
import os, sys
from os.path import *
Import('env', 'build_dir')
PROJRELROOT = '../..'
sys.path.append(PROJRELROOT)
libl4 = SConscript('libl4/SConscript', duplicate = 0,
exports = { 'env' : env },
variant_dir = join(build_dir, 'libl4'))
e = env.Clone()
e.Replace(CPPFLAGS = '')
type = 'userspace'
libdev_builddir = join(join(build_dir, 'libdev'), 'sys-' + type)
libdev = SConscript('libdev/SConscript', duplicate = 0,
exports = { 'env' : e, 'type' : type, 'build_dir' : libdev_builddir })
libc = SConscript('libc/SConscript', duplicate = 0,
exports = { 'env' : env, 'type' : 'userspace' },
variant_dir = join(build_dir, 'libc'))
libmem = SConscript('libmem/SConscript', duplicate = 0,
exports = { 'env' : env, },
variant_dir = join(build_dir, 'libmem'))
Alias('libl4', libl4)
Alias('libdev', libdev)
Alias('libc', libc)
Alias('libmem', libmem)
#Alias('libmc', libmc)
#Alias('libmalloc',libmalloc)

39
conts/userlibs/SConstruct Normal file
View File

@@ -0,0 +1,39 @@
# -*- mode: python; coding: utf-8; -*-
#
# Codezero -- Virtualization microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
import os, sys
from os.path import *
PROJRELROOT = '../..'
sys.path.append(PROJRELROOT)
from scripts.config.config_invoke import *
config = configuration_retrieve()
gcc_arch_flag = config.gcc_arch_flag
builddir = join(BUILDDIR, USERLIBS_RELDIR)
env = Environment(CC = config.toolchain_userspace + 'gcc',
AR = config.toolchain_userspace + 'ar',
RANLIB = config.toolchain_userspace + 'ranlib',
# We don't use -nostdinc because sometimes we need standard headers,
# such as stdarg.h e.g. for variable args, as in printk().
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall',
'-Werror', '-march=' + gcc_arch_flag],
LINKFLAGS = ['-nostdlib'],
ASFLAGS = ['-D__ASSEMBLY__', '-march=' + gcc_arch_flag],
ENV = {'PATH' : os.environ['PATH']},
LIBS = 'gcc', # libgcc.a - Required for division routines.
CPPPATH = KERNEL_HEADERS,
CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h')
# Set the build directory for this source tree
VariantDir(builddir, os.getcwd())
SConscript('SConscript', duplicate = 0,
exports = { 'env' : env, 'build_dir' : builddir })

View File

@@ -0,0 +1,37 @@
# -*- mode: python; coding: utf-8; -*-
#
# Codezero -- Virtualization microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
import os, sys, shelve
from os.path import join
# Get global paths
PROJRELROOT = '../../../'
sys.path.append(PROJRELROOT)
from scripts.config.configuration import *
from scripts.config.projpaths import *
config = configuration_retrieve()
arch = config.arch
Import('env', 'type')
e = env.Clone()
e.Append(CPPPATH = ['include', 'include/sys-' + type + '/arch-' + arch, LIBDEV_INCLUDE],
CCFLAGS = ['-nostdinc'])
source = \
Glob('src/*.[cS]') + \
Glob('src/sys-' + type + '/*.c') + \
Glob('src/sys-' + type + '/arch-' + arch + '/*.c') + \
Glob('src/arch-' + arch + '/*.c') + \
Glob('src/arch-' + arch + '/*.S') + \
Glob('crt/sys-' + type + '/arch-' + arch + '/*.[cS]')
objects = e.StaticObject(source)
library = e.StaticLibrary('c-' + type, objects)
Return('library')

View File

@@ -0,0 +1,40 @@
# -*- mode: python; coding: utf-8; -*-
#
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
import os, sys
PROJRELROOT = '../../..'
sys.path.append(PROJRELROOT)
from scripts.config.projpaths import *
from scripts.config.configuration import *
config = configuration_retrieve()
gcc_arch_flag = config.gcc_arch_flag
arch = config.arch
# We assume we are compiling for userspace.
# variant can be specified from cmdline using
# scons variant=xxx
variant = ARGUMENTS.get('variant', 'userspace')
print '\nCompiling for variant: ' + variant + '\n'
builddir = join(BUILDDIR, LIBC_RELDIR)
VariantDir(builddir, os.getcwd(), 0)
env = Environment(CC = config.toolchain_userspace + 'gcc',
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99',
'-nostdinc', '-Wall', '-Werror', '-march=' + gcc_arch_flag],
LINKFLAGS = ['-nostdlib'],
ASFLAGS = ['-D__ASSEMBLY__'],
ENV = {'PATH' : os.environ['PATH']},
CPPPATH = ['include', LIBDEV_INCLUDE, KERNEL_HEADERS,
'include/sys-' + variant + '/arch-' + arch],
CPPFLAGS = '-include l4/macros.h')
objects = SConscript('SConscript', exports = { 'env' : env, 'type' : variant },
duplicate=0, build_dir = builddir)

View File

@@ -0,0 +1,93 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
#ifdef __thumb__
#define bl blx
#endif
.section .text.head
.code 32
.global _start;
.align;
_start:
ldr sp, =__stack
bl platform_init
bl __container_init
1:
b 1b

View File

@@ -0,0 +1,102 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Authors: Cristan Szmajda, Ben Leslie
Description:
Program diagnostics as per 7.2
Status: Complete.
*/
/*
* <assert.h> may safely be included multiple times with or without NDEBUG
*/
#undef assert
/* Defining NDEBUG removes asserts */
#ifdef NDEBUG
#define assert(e) ((void)0)
#else
#define assert(e) ((e) ? (void)0 : __assert(#e, __FILE__, __func__, __LINE__))
#endif
/* Implemented in src/assert.c */
void __assert(const char *, const char *, const char *, int);

View File

@@ -0,0 +1,116 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Ben Leslie
*/
#ifndef _LIMITS_H_
#define _LIMITS_H_
#define CHAR_BIT 8
#define SCHAR_MIN (-128)
#define SCHAR_MAX 127
#define UCHAR_MAX 255
#ifdef __CHAR_UNSIGNED__
#define CHAR_MIN 0
#define CHAR_MAX UCHAR_MAX
#else
#define CHAR_MIN SCHAR_MIN
#define CHAR_MAX SCHAR_MAX
#endif
#define MB_LEN_MAX 1
#define SHRT_MIN (-32768)
#define SHRT_MAX 32767
#define USHRT_MAX 65535U
#define INT_MIN (-2147483648)
#define INT_MAX 2147483647
#define UINT_MAX 4294967295U
#define LONG_MIN (-2147483648)
#define LONG_MAX 2147483647
#define ULONG_MAX 4294967295U
#define LLONG_MIN (-9223372036854775808LL)
#define LLONG_MAX 9223372036854775807LL
#define ULLONG_MAX 18446744073709551615ULL
#endif /* _LIMITS_H_ */

View File

@@ -0,0 +1,101 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Authors: Ben Leslie
*/
/*
Implementation based on C99 Section 7.15 Variable arguments
*/
#ifndef _STDARG_H_
#define _STDARG_H_
typedef __builtin_va_list va_list;
#define va_arg(ap, type) __builtin_va_arg((ap), type)
#define va_copy(dest, src) __builtin_va_copy((ap), type)
#define va_end(ap) __builtin_va_end((ap))
#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
#define va_start(v,l)__builtin_va_start((v),l)
#else
#define va_start(v,l)__builtin_stdarg_start((v),l)
#endif
#endif /* _STDARG_H_ */

View File

@@ -0,0 +1,98 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Ben Leslie
Description:
Implementation based on C99 Section 7.16 Boolean type and values
*/
#ifndef __STDBOOL_H__
#define __STDBOOL_H__
#ifndef __bool_true_false_are_defined
#define __bool_true_false_are_defined 1
#define bool _Bool
#define true 1
#define false 0
#endif /* __bool_true_false_are_defined */
#endif /* __STDBOOL_H__ */

View File

@@ -0,0 +1,119 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Authors: Ben Leslie
*/
#ifndef _STDDEF_H_
#define _STDDEF_H_
/* See C99 spec 7.17 */
/* We rely on the compiler telling us the right types to go in
here -- this makes a lot of sense, the compiler knows how big
these things are
*/
#ifndef __SIZE_TYPE__
#ifdef __mips__
#define __SIZE_TYPE__ long unsigned int
#endif
#endif
#ifndef __PTRDIFF_TYPE__
#ifdef __mips__
#define __PTRDIFF_TYPE__ long int
#endif
#endif
typedef __PTRDIFF_TYPE__ ptrdiff_t ;
typedef __SIZE_TYPE__ size_t;
#ifndef __cplusplus /* FIXME: This is the one concession to C++ programmers that I make.
Allowing them to compile and use the standard C library. This is
more because C++ people shouldn't be restricted from using wonderful
things such as varargs and printf */
typedef __WCHAR_TYPE__ wchar_t;
#endif
#ifndef NULL
#define NULL ((void *)0)
#endif
#define offsetof(type, member) ((size_t) &((type *)0)->member)
#endif /* _STDDEF_H_ */

View File

@@ -0,0 +1,276 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
#ifndef _STDINT_H_
#define _STDINT_H_
#include <limits.h>
/*
* 7.18.1.1 Exact-width integers
*/
#include <arch/stdint.h>
/*
* 7.18.2.1 Limits of exact-wdith integer types
*/
#define INT8_MIN SCHAR_MIN
#define INT16_MIN SHRT_MIN
#define INT32_MIN INT_MIN
#define INT64_MIN LLONG_MIN
#define INT8_MAX SCHAR_MAX
#define INT16_MAX SHRT_MAX
#define INT32_MAX INT_MAX
#define INT64_MAX LLONG_MAX
#define UINT8_MAX UCHAR_MAX
#define UINT16_MAX USHRT_MAX
#define UINT32_MAX UINT_MAX
#define UINT64_MAX ULLONG_MAX
#ifndef __ARCH_HAS_LEAST
/*
* 7.18.1.2 Minimum-width integers
*/
typedef int8_t int_least8_t;
typedef int16_t int_least16_t;
typedef int32_t int_least32_t;
typedef int64_t int_least64_t;
typedef uint8_t uint_least8_t;
typedef uint16_t uint_least16_t;
typedef uint32_t uint_least32_t;
typedef uint64_t uint_least64_t;
/*
* 7.18.2.2 Limits of minimum-width integers
*/
#define INT_LEAST8_MIN INT8_MIN
#define INT_LEAST16_MIN INT16_MIN
#define INT_LEAST32_MIN INT32_MIN
#define INT_LEAST64_MIN INT64_MIN
#define INT_LEAST8_MAX INT8_MAX
#define INT_LEAST16_MAX INT16_MAX
#define INT_LEAST32_MAX INT32_MAX
#define INT_LEAST64_MAX INT64_MAX
#define UINT_LEAST8_MAX UINT8_MAX
#define UINT_LEAST16_MAX UINT16_MAX
#define UINT_LEAST32_MAX UINT32_MAX
#define UINT_LEAST64_MAX UINT64_MAX
#else
#undef __ARCH_HAS_LEAST
#endif
#ifndef __ARCH_HAS_FAST
/*
* 7.8.1.3 Fastest minimum-width integer types
* Note -- We fulfil the spec, however we don't really know
* which are fastest here. I assume `int' is probably fastest
* more most, and should be used for [u]int_fast[8,16,32]_t.
*/
typedef int8_t int_fast8_t;
typedef int16_t int_fast16_t;
typedef int32_t int_fast32_t;
typedef int64_t int_fast64_t;
typedef uint8_t uint_fast8_t;
typedef uint16_t uint_fast16_t;
typedef uint32_t uint_fast32_t;
typedef uint64_t uint_fast64_t;
/*
* 7.18.2.2 Limits of fastest minimum-width integers
*/
#define INT_FAST8_MIN INT8_MIN
#define INT_FAST16_MIN INT16_MIN
#define INT_FAST32_MIN INT32_MIN
#define INT_FAST64_MIN INT64_MIN
#define INT_FAST8_MAX INT8_MAX
#define INT_FAST16_MAX INT16_MAX
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST64_MAX INT64_MAX
#define UINT_FAST8_MAX UINT8_MAX
#define UINT_FAST16_MAX UINT16_MAX
#define UINT_FAST32_MAX UINT32_MAX
#define UINT_FAST64_MAX UINT64_MAX
#else
#undef __ARCH_HAS_FAST
#endif
/*
* 7.18.1.4 Integer types capable of holding object pointers
* We should fix this to be 32/64 clean.
*/
#if __PTR_SIZE==32
typedef int32_t intptr_t;
typedef uint32_t uintptr_t;
#define INTPTR_MIN INT32_MIN
#define INTPTR_MAX INT32_MAX
#define UINTPTR_MAX UINT32_MAX
#elif __PTR_SIZE==64
typedef int64_t intptr_t;
typedef uint64_t uintptr_t;
#define INTPTR_MIN INT64_MIN
#define INTPTR_MAX INT64_MAX
#define UINTPTR_MAX UINT64_MAX
#else
#error Unknown pointer size
#endif
#undef __PTR_SIZE
/*
* 7.18.1.5 Greatest-wdith integer types
*/
typedef long long int intmax_t;
typedef unsigned long long int uintmax_t;
/*
* 7.18.2.5 Limits of greateast-width integer types
*/
#define INTMAX_MIN LLONG_MIN
#define INTMAX_MAX LLONG_MAX
#define UINTMAX_MAX ULLONG_MAX
/*
* 7.18.3 Limits of other integer types
*/
/* FIXME: Check these limits are correct */
#define PTRDIFF_MIN INTPTR_MIN
#define PTRDIFF_MAX INTPTR_MAX
#define SIG_ATOMIC_MIN INT_MIN
#define SIG_ATOMIC_MAX INT_MAX
#define SIZE_MAX UINTPTR_MAX
#define WCHAR_MIN 0
#define WCHAR_MAX UINT16_MAX
#define WINT_MIN 0
#define WINT_MAX UINT16_MAX
/*
* 7.18.4 Macros for integer constants
*/
#define INT8_C(x) (int8_t)(x)
#define INT16_C(x) (int16_t)(x)
#define INT32_C(x) (int32_t)(x)
#define INT64_C(x) (int64_t)(x)
#define UINT8_C(x) (uint8_t)(x)
#define UINT16_C(x) (uint16_t)(x)
#define UINT32_C(x) (uint32_t)(x)
#define UINT64_C(x) (uint64_t)(x)
#define INT_FAST8_C(x) (int_fast8_t)(x)
#define INT_FAST16_C(x) (int_fast16_t)(x)
#define INT_FAST32_C(x) (int_fast32_t)(x)
#define INT_FAST64_C(x) (int_fast64_t)(x)
#define UINT_FAST8_C(x) (uint_fast8_t)(x)
#define UINT_FAST16_C(x) (uint_fast16_t)(x)
#define UINT_FAST32_C(x) (uint_fast32_t)(x)
#define UINT_FAST64_C(x) (uint_fast64_t)(x)
#define INT_LEAST8_C(x) (int_least8_t)(x)
#define INT_LEAST16_C(x) (int_least16_t)(x)
#define INT_LEAST32_C(x) (int_least32_t)(x)
#define INT_LEAST64_C(x) (int_least64_t)(x)
#define UINT_LEAST8_C(x) (uint_least8_t)(x)
#define UINT_LEAST16_C(x) (uint_least16_t)(x)
#define UINT_LEAST32_C(x) (uint_least32_t)(x)
#define UINT_LEAST64_C(x) (uint_least64_t)(x)
#define INTPTR_C(x) (intptr_t)(x)
#define UINTPTR_C(x) (uintptr_t)(x)
#define INTMAX_C(x) (intmax_t)(x)
#define UINTMAX_C(x) (uintmax_t)(x)
#endif /* _STDINT_H_ */

View File

@@ -0,0 +1,222 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Ben Leslie
*/
#ifndef _STDIO_H_
#define _STDIO_H_
#include <stddef.h>
#include <stdarg.h>
#ifdef THREAD_SAFE
#include <mutex/mutex.h>
#define lock_stream(s) mutex_count_lock(&(s)->mutex)
#define unlock_stream(s) mutex_count_unlock(&(s)->mutex)
#else
#define lock_stream(s)
#define unlock_stream(s)
#endif
#define __UNGET_SIZE 10
struct __file {
void *handle;
size_t (*read_fn)(void *, long int, size_t, void *);
size_t (*write_fn)(void *, long int, size_t, void *);
int (*close_fn)(void *);
long int (*eof_fn)(void *);
unsigned char buffering_mode;
char *buffer;
unsigned char unget_pos;
long int current_pos;
#ifdef THREAD_SAFE
struct mutex mutex;
#endif
int eof;
int error;
char unget_stack[__UNGET_SIZE];
};
typedef struct __file FILE; /* This needs to be done correctly */
typedef long fpos_t; /* same */
#define _IOFBF 0
#define _IOLBF 1
#define _IONBF 2
#define BUFSIZ 37
#define EOF (-1)
#define FOPEN_MAX 37
#define FILENAME_MAX 37
#define L_tmpnam 37
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
#ifndef SEEK_CUR
#define SEEK_CUR 1
#endif
#ifndef SEEK_END
#define SEEK_END 2
#endif
#define TMP_MAX 37
extern FILE *stderr;
extern FILE *stdin;
extern FILE *stdout;
/* 7.19.4 Operations on files */
int remove(const char *);
int rename(const char *, const char *);
FILE *tmpfile(void);
char *tmpnam(char *);
int fclose(FILE *);
int fflush(FILE *);
FILE *fopen(const char *, const char *);
FILE *freopen(const char *, const char *, FILE *);
void setbuf(FILE *, char *);
int setvbuf(FILE *, char *, int, size_t);
/* 7.19.6 Format i/o functions */
int fprintf(FILE *, const char *, ...);
int fscanf(FILE *, const char *, ...);
int printf(const char *format, ...) __attribute__((format (printf, 1, 2)));
int scanf(const char *, ...);
int snprintf(char *, size_t , const char *, ...);
int sprintf(char *, const char *, ...);
int sscanf(const char *, const char *, ...);
int vfprintf(FILE *, const char *, va_list);
int vfscanf(FILE *, const char *, va_list);
int vprintf(const char *, va_list);
int vscanf(const char *, va_list);
int vsnprintf(char *, size_t, const char *, va_list );
int vsprintf(char *, const char *format, va_list arg);
int vsscanf(const char *s, const char *format, va_list arg);
/* 7.19.7 Character i/o functions */
char fgetc(FILE *);
char *fgetline(FILE *);
char *fgets(char *, int, FILE *);
int fputc(int, FILE *);
int fputs(const char *, FILE *);
/* getc is specified to be the same as fgetc, so it makes
the most sense to implement as a macro here */
#define getc fgetc /*int getc(FILE *); */
int getchar(void);
char *gets(char *);
/* putc is specified to be the same as fputc, so it makes
the most sense to implement as a macro here */
#define putc fputc /*int fetc(int, FILE *); */
int putchar(int);
int puts(const char *);
int ungetc(int, FILE *);
/* 7.19.8 Direct I/O functions */
size_t fread(void *, size_t, size_t, FILE *);
size_t fwrite(const void *, size_t, size_t, FILE *);
/* 7.19.9 File positioning functions */
int fgetpos(FILE *, fpos_t *);
int fseek(FILE *, long int, int);
int fsetpos(FILE *, const fpos_t *);
long int ftell(FILE *);
void rewind(FILE *);
/* 7.19.10 Error-handling functions */
void clearerr(FILE *);
int feof(FILE *);
int ferror(FILE *);
void perror(const char *);
#endif /* _STDIO_H_ */

View File

@@ -0,0 +1,122 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
#ifndef _STRING_H_
#define _STRING_H_
#include <stddef.h>
/* 7.21.2 Copying functions */
void *memcpy(void *s1, const void *s2, size_t n);
void *memmove(void *s1, const void *s2, size_t n);
char *strcpy(char *s1, const char *s2);
char *strncpy(char *s1, const char *s2, size_t n);
/* 7.21.3 Concatenation functions */
char *strcat(char *s1, const char *s2);
char *strncat(char *s1, const char *s2, size_t n);
/* 7.21.4 Comparison functions */
int memcmp(const void *s1, const void *s2, size_t n);
int strcmp(const char *s1, const char *s2);
int strcoll(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
size_t strxfrm(char *s1, const char *s2, size_t n);
/* 7.21.5 Search functions */
void *memchr(const void *s, int c, size_t n);
char *strchr(const char *s, int c);
size_t strcspn(const char *s1, const char *s2);
char *strpbrk(const char *s1, const char *s2);
char *strrchr(const char *s, int c);
size_t strspn(const char *s1, const char *s2);
char *strstr(const char *s1, const char *s2);
char *strtok(char *s1, const char *s2);
/* 7.21.6 Miscellaneous functions */
void *memset(void *, int, size_t);
char *strerror(int errnum);
size_t strlen(const char *);
/* Extra POSIX defined thigns that aren't part of the C standard */
#ifdef _USE_XOPEN
char *strdup(const char *);
#endif
#endif /* _STRING_H_ */

View File

@@ -0,0 +1,92 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Ben Leslie
*/
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
#define __PTR_SIZE 32

View File

@@ -0,0 +1,92 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Ben Leslie
*/
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
#define __PTR_SIZE 32

View File

@@ -0,0 +1,11 @@
/* Dummies to keep Codesourcery 4.1.1 libgcc division exceptions silent. */
void raise(void)
{
}
void __aeabi_unwind_cpp_pr0(void)
{
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2010 B Labs.Ltd.
*
* Author: Prem Mallappa <prem.mallappa@b-labs.co.uk>
*
* Description: Optimized memcpy for ARM
*
*/
#include INC_ARCH(asm.h)
/*
void*
memcpy(void *dst, const void *src, register uint len)
*/
BEGIN_PROC(memcpy)
push {r0, r4-r11, lr}
loop32:
cmp r2, #32
blt loop16
ldmia r1!, {r4 - r11}
stmia r0!, {r4 - r11}
sub r2, r2, #32
b loop32
loop16:
cmp r2, #16
blt loop8
ldmia r1!, {r4 - r7}
stmia r0!, {r4 - r7}
sub r2, r2, #16
b loop16
loop8:
cmp r2, #8
blt loop4
ldmia r1!, {r4, r5}
stmia r0!, {r4, r5}
sub r2, r2, #8
b loop8
loop4:
cmp r2, #4
blt end
ldmia r1!, {r4}
stmia r0!, {r4}
sub r2, r2, #4
b loop4
end:
last:
teq r2, #0
ldrgtb r4, [r1]
strneb r4, [r0] // V7 supports strneb <rt>, [<rb>, +/-<index>] !, with write back
lsrne r4, r4, #8
subne r2, r2, #1 // Can be reduced to 1 LDR, but has a catch if it is end of memory
addne r0, r0, #1 // we dont want to fetch 1 byte extra to end up in abort
addne r1, r1, #1 // so, playing safe, worst case 3 LDRs
bne last
1:
pop {r0, r4 - r11, pc}
END_PROC(_memcpy)

View File

@@ -0,0 +1,68 @@
/*
* Copyright 2010 (C) B Labs.
* Author: Prem Mallappa <prem.mallappa@b-labs.co.uk>
* Description: Optimized memset for ARM
*/
#include INC_ARCH(asm.h)
/*
void *
memset(void *dst, int c, int len)
*/
BEGIN_PROC(memset)
stmfd sp!, {r4 - r11, lr}
and r1, r1, #255 /* c &= 0xff */
orr r1, r1, lsl #8 /* c |= c<<8 */
orr r1, r1, lsl #16 /* c |= c<<16 */
mov r4, r1
cmp r2, #8
blt 4f
movge r5, r4
cmpge r2, #16
blt 8f
movge r6, r4
movge r7, r4
cmpge r2, #32
blt 16f
movge r8, r4
movge r9, r4
movge r10, r4
movge r11, r4
32:
cmp r2, #32
blt 16f
stmia r0!, {r4 - r11}
sub r2, r2, #32
b 32b
16:
cmp r2, #16
blt 8f
stmia r0!, {r4 - r7}
sub r2, r2, #16
b 16b
8:
cmp r2, #8
blt 4f
stmia r0!, {r4, r5}
sub r2, r2, #8
b 8b
4:
cmp r2, #4
blt end
stmia r0!, {r4}
sub r2, r2, #4
b 4b
end:
teq r2, #0
strneb r4, [r0, #0]
subne r2, r2, #1
addne r0, r0, #1
bne end
ldmfd sp!, {r4 - r11, pc}
END_PROC(_memset)

View File

@@ -0,0 +1,542 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 University of New South Wales
*
* All rights reserved.
*
* Developed by: Operating Systems and Distributed Systems Group (DiSy)
* University of New South Wales
* http://www.disy.cse.unsw.edu.au
*
* Permission is granted by University of New South Wales, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of University of New South Wales, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on University of New South
* Wales or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of University of New South Wales or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Authors: Cristan Szmadja, Ben Leslie
*/
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include "format.h"
/*
* lookup tables for umaxtostr
*/
static const char xdigits[16] = "0123456789abcdef";
static const char Xdigits[16] = "0123456789ABCDEF";
/*
* Convert an unsigned integer to a string of digits in the specified base.
* Buf should point to the END of the buffer: 22 characters is probably big
* enough. NO '\0' is appended to buf.
*
* If u == 0, NO digits are generated. The '0' is supplied by vfprintf using
* its default zero padding, except in certain rare situations (e.g., "%.0d").
*/
static inline char *
umaxtostr(char *buf, uintmax_t u, int base, const char *digits)
{
unsigned long u2;
/*
* generate the digits in reverse order
*/
#if UINTMAX_MAX > ULONG_MAX
/*
* Uintmax_t arithmetic may be very slow. Use it only until the
* residual fits in an unsigned long.
*/
while (u > ULONG_MAX) {
*--buf = digits[u % base];
u /= base;
}
#endif
for (u2 = u; u2 != 0UL;) {
*--buf = digits[u2 % base];
u2 /= base;
}
return buf;
}
/*
This macro is *really* nasty.
It isn't an inline function because it relies on variables declared in the
surrounding scope. Specifically:
stream_or_memory -> Indicates if we are going to a file, or memory
r -> The output counter
n -> max size
output -> output buffer (if going to memory)
stream -> output stream (if going to file)
*/
#define WRITE_CHAR(x) { \
if (n != -1 && r == n) { \
*output++ = '\0'; \
overflowed = 1; \
} \
if (stream_or_memory) { \
fputc(x, stream); \
} else if (! overflowed) { \
*output++ = x; \
} \
r++; \
} \
/*
* Print one formatted field. The length of s is len; any '\0's in s are
* IGNORED. The field may have an optional prefix ('+', ' ', '-', '0x', or
* '0X', packed into an unsigned int), and is padded appropriately to the
* specified width. If width < 0, the field is left-justified.
*/
static inline int
fprintf1(char *output, FILE *stream, bool stream_or_memory, size_t r, size_t n,
const char *s, int len, unsigned int prefix,
int prefixlen, int width, int prec, bool *over)
{
size_t i;
size_t y = r; /* Keep a copy the starting value */
bool overflowed = *over; /* Current start of overflow flag */
if (stream != NULL)
lock_stream(stream);
if (width - prec - prefixlen > 0) {
for (i = 0; i < width - prec - prefixlen; i++) {
WRITE_CHAR(' '); /* left-padding (if any) */
}
}
for (; prefix != 0; prefix >>= 8) {
WRITE_CHAR(prefix & 0377); /* prefix string */
}
for (i = 0; i < prec - len; i++) {
WRITE_CHAR('0'); /* zero-padding (if any) */
}
for (i = 0; i < len; i++) {
WRITE_CHAR(s[i]); /* actual string */
}
if (width < 0) {
while(y < -width) {
WRITE_CHAR(' '); /* right-padding (if any) */
}
}
*over = overflowed; /* Set overflow flag in the caller */
if (stream != NULL)
unlock_stream(stream);
return r - y; /* We return the number of chars added */
}
#include <assert.h>
/*
* parse printf format string
* if stream_or_memory == 1 -> use fputc, otherwise write to memory
* if n == -1, then don't check overflow
*/
int
format_string(char *output, FILE *stream, bool stream_or_memory, size_t n,
const char *fmt, va_list ap)
{
bool alt, ljust, point, zeropad, overflowed = 0;
int lflags; /* 'h', 'j', 'l', 't', 'z' */
unsigned int prefix; /* a very small string */
int width, prec, base = 0, prefixlen;
size_t r, len;
const char *p, *s, *digits;
char buf[24], *const buf_end = buf + sizeof buf;
intmax_t d;
uintmax_t u = 0;
r = 0;
if (stream != NULL)
lock_stream(stream);
for (p = fmt; *p != '\0'; p++) {
if (*p != '%') {
putc:
WRITE_CHAR(*p);
continue;
}
alt = false;
ljust = false;
point = false;
zeropad = false;
lflags = 0;
prefix = '\0';
prefixlen = 0;
width = 0;
prec = 1; /* make sure 0 prints as "0" */
digits = xdigits;
for (p++;; p++) {
again:
switch (*p) {
case '%':
goto putc;
case '#':
alt = true;
continue;
case '-': /* takes precedence over '0' */
ljust = true;
continue;
case '0':
zeropad = true;
continue;
case '+': /* XXX should take precedence over
* ' ' */
case ' ':
prefix = *p;
prefixlen = 1;
continue;
case '*':
width = va_arg(ap, int);
if (ljust)
width = -width;
continue;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
/*
* width = strtol(p, &p, 10), sort of
*/
width = *p - '0';
for (p++; (unsigned int) (*p - '0') < 10;
p++)
width = width * 10 + (*p - '0');
if (ljust)
width = -width;
goto again; /* don't increment p */
case '.':
point = true;
if (*++p == '*') {
prec = va_arg(ap, int);
continue;
} else {
/*
* prec = strtol(p, &p, 10), sort
* of
*/
for (prec = 0;
(unsigned int) (*p - '0') <
10; p++)
prec =
prec * 10 + (*p - '0');
goto again; /* don't increment
* p */
}
case 'h':
lflags--;
continue;
case 'L':
case 'l':
lflags++;
continue;
case 't':
case 'z':
lflags = 1; /* assume ptrdiff_t and
* size_t are long */
continue;
case 'j':
lflags = 2; /* assume intmax_t is long
* long */
continue;
#ifndef NO_FLOAT
case 'a':
case 'A':
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
/*
* NOT IMPLEMENTED
*/
switch (lflags) {
case 0:
va_arg(ap, double);
break;
case 1:
va_arg(ap, long double);
break;
default:
goto default_case;
}
break;
#endif /* !NO_FLOAT */
case 'c':
#ifndef NO_WCHAR
/*
* NOT IMPLEMENTED
*/
if (lflags > 0)
va_arg(ap, wchar_t);
else
#endif
*(buf_end - 1) = va_arg(ap, int);
s = buf_end - 1;
len = 1;
goto common3;
case 'd':
case 'i':
switch (lflags) {
case -2:
// d = va_arg(ap, signed char);
d = va_arg(ap, int);
break;
case -1:
// d = va_arg(ap, short);
d = va_arg(ap, int);
break;
case 0:
d = va_arg(ap, int);
break;
case 1:
d = va_arg(ap, long);
break;
#ifndef NO_LONG_LONG
case 2:
d = va_arg(ap, long long);
break;
#endif
default:
goto default_case;
}
if (d < 0LL) {
/*
* safely negate d, even
* INTMAX_MIN
*/
u = -(uintmax_t) d;
prefix = '-'; /* override ' ' or
* '+' */
prefixlen = 1;
} else {
u = d;
}
base = 10;
goto common2;
case 'n':
switch (lflags) {
case -2:
*va_arg(ap, signed char *) = r;
break;
case -1:
*va_arg(ap, short *) = r;
break;
case 0:
*va_arg(ap, int *) = r;
break;
case 1:
*va_arg(ap, long *) = r;
break;
case 2:
*va_arg(ap, long long *) = r;
break;
default:
goto default_case;
}
break;
case 'o':
base = 8;
goto common1;
case 'p':
u = (uintptr_t) va_arg(ap, const void *);
if (u != (uintptr_t) NULL) {
base = 16;
prec = 2 * sizeof(const void *);
prefix = '0' | 'x' << 8;
prefixlen = 2;
goto common2;
} else {
s = "(nil)";
len = 5;
goto common3;
}
case 's':
s = va_arg(ap, const char *);
/*
* XXX left-justified strings are scanned
* twice
*/
if (point) {
/*
* len = min(prec, strlen(s))
*/
for (len = 0; len < prec; len++)
if (s[len] == '\0')
break;
} else {
len = strlen(s);
}
goto common3;
case 'u':
base = 10;
goto common1;
case 'X':
digits = Xdigits;
/*
* FALLTHROUGH
*/
case 'x':
base = 16;
if (alt) {
prefix = '0' | *p << 8;
prefixlen = 2;
}
/*
* FALLTHROUGH
*/
common1:
/*
* common code for %o, %u, %X, and %x
*/
switch (lflags) {
case -2:
// u = va_arg(ap, unsigned char);
u = va_arg(ap, int);
break;
case -1:
// u = va_arg(ap, unsigned short);
u = va_arg(ap, int);
break;
case 0:
u = va_arg(ap, unsigned int);
break;
case 1:
u = va_arg(ap, unsigned long);
break;
#ifndef NO_LONG_LONG
case 2:
u = va_arg(ap, unsigned long long);
break;
#endif
default:
goto default_case;
}
/*
* FALLTHROUGH
*/
common2:
s = umaxtostr(buf_end, u, base, digits);
len = buf_end - s;
/*
* the field may overflow prec
*/
if (prec < len)
/*
* FALLTHOUGH
*/
common3:
prec = len;
if (zeropad && prec < width - prefixlen)
prec = width - prefixlen;
else if (alt && base == 8 && u != 0LL)
prec++;
{
int tmp = fprintf1(output, stream, stream_or_memory, r, n,
s, len, prefix,
prefixlen, width, prec, &overflowed);
r += tmp;
output += tmp;
}
break;
default: /* unrecognized conversion
* specifier */
default_case:
/*
* print uninterpreted
*/
for (s = p - 1; *s != '%'; s--);
for (; s <= p; s++) {
WRITE_CHAR(*p);
}
break;
}
break; /* finished the conversion specifier */
}
}
if (! stream_or_memory && ! overflowed)
*output++ = '\0';
if (stream != NULL)
unlock_stream(stream);
return r;
}

View File

@@ -0,0 +1,86 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Ben Leslie
*/
#ifndef _FORMAT_H_
#define _FORMAT_H_
#include <stdbool.h>
int format_string(char *output, FILE *stream, bool stream_or_memory, size_t n, const char *fmt, va_list ap);
#endif

View File

@@ -0,0 +1,19 @@
#include <stdio.h>
int
fputc(int c, FILE *stream)
{
unsigned char ch = (unsigned char) c;
/* This is where we should do output buffering */
lock_stream(stream);
if (stream->write_fn(&ch, stream->current_pos, 1, stream->handle) == 1) {
/* Success */
stream->current_pos++;
unlock_stream(stream);
return c;
} else {
unlock_stream(stream);
return EOF;
}
}

View File

@@ -0,0 +1,98 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 University of New South Wales
*
* All rights reserved.
*
* Developed by: Operating Systems and Distributed Systems Group (DiSy)
* University of New South Wales
* http://www.disy.cse.unsw.edu.au
*
* Permission is granted by University of New South Wales, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of University of New South Wales, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on University of New South
* Wales or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of University of New South Wales or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Cristan Szmadja
*/
#include <string.h>
/* THREAD SAFE */
int
memcmp(const void *s1, const void *s2, size_t n)
{
size_t i;
int diff;
for (i = 0; i < n; i++) {
diff =
((unsigned char *) s1)[i] - ((unsigned char *) s2)[i];
if (diff != 0)
return diff;
}
return 0;
}

View File

@@ -0,0 +1,117 @@
/*
* Copyright B Labs(R) Ltd.
* Author: Prem Mallappa < prem.mallappa@b-labs.co.uk >
* Generic memcpy, fairly optimized
*/
void
__attribute__ ((weak))
*memcpy(void *dst, void *src, size_t len)
{
unsigned char *s=src, *d=dst;
unsigned remain = 0;
unsigned align_mask = sizeof(unsigned long) - 1;
unsigned alignment = ((unsigned long)s & align_mask) |
((unsigned long)d & align_mask);
remain = len & align_mask;
if (alignment == 0) {
unsigned long *sl = (unsigned long*)s, *dl = (unsigned long*)d;
while(len > remain) {
*dl++ = *sl++;
len -= sizeof(unsigned long);
}
s = (unsigned char *)sl; d = (unsigned char *)dl;
}
else if (alignment == 2) {
unsigned short *sh = (unsigned short *)s, *dh = (unsigned short *)d;
while (len > remain) {
*dh++ = *sh++;
len -= sizeof(unsigned short);
}
s = (unsigned char *)sh; d = (unsigned char *)dh;
}
else {
while (len--)
*d++ = *s++;
}
switch(remain) {
case 3:
*d++ = *s++;
case 2:
*d++ = *s++;
case 1:
*d++ = *s++;
default: break;
}
return dst;
}
#if 0
/* TEST */
int memcmp1(void *src, void *dst, size_t len)
{
char *s = src, *d = dst;
int i;
for(i=0; i < len; i++) {
printf("%d %x %x\n", i, s[i], d[i]);
if(s[i] != d[i])
break;
}
if (i!=len) {
printf("diff at %d, src: %x, dst: %x\n", i, s[i], d[i]);
return 1;
}
return 0;
}
int main(void)
{
char s[100]__attribute__((aligned (8))), d[100]__attribute__((aligned (8)));
int i;
/* TEST 1 */
for (i = 0; i < sizeof(s); i++) {
s[i] = i;
d[i] = 0;
}
memcpy1(&s[0], &d[0], 3);
if(memcmp(&s[0], &d[0], 3))
memcmp1(&s[0], &d[0], 3);
/* TEST 2 */
for (i = 0; i < sizeof(s); i++) {
s[i] = i;
d[i] = 0;
}
memcpy1(&s[1], &d[0], 6);
if(memcmp(&s[1], &d[0], 6))
memcmp1(&s[1], &d[0], 6);
/* TEST 3 */
for (i = 0; i < sizeof(s); i++) {
s[i] = i;
d[i] = 0;
}
memcpy1(&s[2], &d[1], 7);
if(memcmp(&s[2], &d[1], 7))
memcmp1(&s[2], &d[1], 7);
/* TEST 4 */
for (i = 0; i < sizeof(s); i++) {
s[i] = i;
d[i] = 0;
}
memcpy1(&s[2], &d[3], 7);
if(memcmp(&s[2], &d[3], 7))
memcmp1(&s[2], &d[3], 7);
return 0;
}
#endif

View File

@@ -0,0 +1,122 @@
/*
* Copyright B Labs(R) Ltd.
* Author: Prem Mallappa < prem.mallappa@b-labs.co.uk >
* Generic memset, still optimized
*/
void
__attribute__ ((weak))
*memset(void *dst, int c, size_t len)
{
unsigned char *d=dst;
c &= 0xff;
unsigned short cs = (c << 8) | c;
unsigned long cl = (cs << 16) | cs;
unsigned align_mask = sizeof(unsigned long) - 1;
unsigned alignment = (len & align_mask) |
((unsigned long)dst & (unsigned long)align_mask);
switch (alignment) {
case 3:
if (len--) {
*d++ = c;
alignment--;
}
case 2:
if (len--) {
*d++ = c;
alignment--;
}
case 1:
if (len--) {
*d++ = c;
alignment--;
}
default: break;
}
unsigned remain = len & align_mask;
len -= remain;
unsigned long *dl = (unsigned long*)d;
while (len > remain) {
*dl++ = cl;
len -= sizeof(unsigned long);
}
d = (unsigned char *)dl;
switch(remain) {
case 3:
*d++ = c;
case 2:
*d++ = c;
case 1:
*d++ = c;
default: break;
}
return dst;
}
#if 0
/* TEST */
int memcmp1(void *dst, int c, size_t len)
{
char *d = dst;
int i;
for(i=0; i < len; i++) {
printf(" %d: %x \n",i, d[i]);
if(d[i] != c & 0xff)
break;
}
if (i < len) {
printf("diff at %d, dst: %x\n", i, d[i]);
return 1;
}
return 0;
}
int main(void)
{
char d[100];
int i;
for (i = 0; i < sizeof(d); i++) {
d[i] = 0;
}
memset1(&d[0], 0x55, 4);
memcmp1(&d[0], 0x55, 4);
memset(&d, 0x0, 100);
memset1(&d[0], 0x55, 2);
memcmp1(&d[0], 0x55, 2);
memset(&d, 0x0, 100);
memset1(&d[0], 0x55, 1);
memcmp1(&d[0], 0x55, 1);
memset(&d, 0x0, 100);
memset1(&d[1], 0x55, 8);
memcmp1(&d[1], 0x55, 8);
memset(&d, 0x0, 100);
memset1(&d[1], 0x55, 1);
memcmp1(&d[1], 0x55, 1);
memset(&d, 0x0, 100);
memset1(&d[1], 0x55, 3);
memcmp1(&d[1], 0x55, 3);
return 0;
}
#endif

View File

@@ -0,0 +1,100 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Ben Leslie <benjl@cse.unsw.edu.au>
*/
#include <stdio.h>
#include "format.h"
/* All of these functions do not lock the I/O stream. They all end up calling
* format which handles the locking. */
int
printf(const char *format, ...)
{
int ret;
va_list ap;
va_start(ap, format);
ret = vfprintf(stdout, format, ap);
va_end(ap);
return ret;
}

View File

@@ -0,0 +1,104 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Ben Leslie <benjl@cse.unsw.edu.au>
*/
#include <stdio.h>
#include "format.h"
#include <assert.h>
int
sprintf(char *s, const char *format, ...)
{
int ret;
va_list ap;
va_start(ap, format);
ret = vsprintf(s, format, ap);
va_end(ap);
return ret;
}
int
vsprintf(char *s, const char *format, va_list arg)
{
return format_string(s, NULL, 0, -1, format, arg);
}

View File

@@ -0,0 +1,99 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 University of New South Wales
*
* All rights reserved.
*
* Developed by: Operating Systems and Distributed Systems Group (DiSy)
* University of New South Wales
* http://www.disy.cse.unsw.edu.au
*
* Permission is granted by University of New South Wales, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of University of New South Wales, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on University of New South
* Wales or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of University of New South Wales or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Cristan Szmadja
*/
#include <string.h>
/*
* compare s1 and s2
*/
int
strcmp(const char *s1, const char *s2)
{
size_t i;
int diff;
for (i = 0;; i++) {
diff =
((unsigned char *) s1)[i] - ((unsigned char *) s2)[i];
if (diff != 0 || s1[i] == '\0')
return diff;
}
}

View File

@@ -0,0 +1,91 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 University of New South Wales
*
* All rights reserved.
*
* Developed by: Operating Systems and Distributed Systems Group (DiSy)
* University of New South Wales
* http://www.disy.cse.unsw.edu.au
*
* Permission is granted by University of New South Wales, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of University of New South Wales, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on University of New South
* Wales or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of University of New South Wales or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Cristan Szmadja
*/
#include <string.h>
char *
strcpy(char *d, const char *s)
{
size_t i;
for (i = 0; (d[i] = s[i]) != '\0'; i++);
return d;
}

View File

@@ -0,0 +1,92 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 University of New South Wales
*
* All rights reserved.
*
* Developed by: Operating Systems and Distributed Systems Group (DiSy)
* University of New South Wales
* http://www.disy.cse.unsw.edu.au
*
* Permission is granted by University of New South Wales, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of University of New South Wales, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on University of New South
* Wales or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of University of New South Wales or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Cristan Szmadja
*/
#include <string.h>
size_t
strlen(const char *s)
{
const char *p;
for (p = s; *p != '\0'; p++);
return p - s;
}

View File

@@ -0,0 +1,100 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 University of New South Wales
*
* All rights reserved.
*
* Developed by: Operating Systems and Distributed Systems Group (DiSy)
* University of New South Wales
* http://www.disy.cse.unsw.edu.au
*
* Permission is granted by University of New South Wales, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of University of New South Wales, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on University of New South
* Wales or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of University of New South Wales or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Cristan Szmadja
*/
#include <string.h>
/*
* compare s1 and s2 in the first n bytes
*/
int
strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
int diff;
for (i = 0; i < n; i++) {
diff =
((unsigned char *) s1)[i] - ((unsigned char *) s2)[i];
if (diff != 0 || s1[i] == '\0')
return diff;
}
return 0;
}

View File

@@ -0,0 +1,102 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2004 University of New South Wales
*
* All rights reserved.
*
* Developed by: Operating Systems and Distributed Systems Group (DiSy)
* University of New South Wales
* http://www.disy.cse.unsw.edu.au
*
* Permission is granted by University of New South Wales, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of University of New South Wales, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on University of New South
* Wales or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of University of New South Wales or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Cristan Szmadja
*/
#include <string.h>
/*
* copy n bytes from s to d; pads with '\0' and may not '\0'-terminate
*/
char *
strncpy(char *d, const char *s, size_t n)
{
size_t i;
for (i = 0; i < n; i++) {
if ((d[i] = s[i]) == '\0') {
/* pad with NUL */
for (i++; i < n; i++) {
d[i] = '\0';
}
}
}
return d;
}

View File

@@ -0,0 +1,13 @@
/*
* Ties up platform's uart driver functions with printf
*
* Copyright (C) 2009 B Labs Ltd.
*/
#include <stdio.h>
#include <dev/uart.h>
int __fputc(int c, FILE *stream)
{
uart_tx_char(uart_print_base, c);
return 0;
}

View File

@@ -0,0 +1,31 @@
/*
* Library calls for uart rx.
*
* Copyright (C) 2009 B Labs Ltd.
*
*/
#include <stdio.h>
#include <dev/uart.h>
char fgetc(FILE * file)
{
return uart_rx_char(uart_print_base);
}
#define MAX_LINE_LEN 256
char data[MAX_LINE_LEN];
char *fgetline(FILE * file)
{
int index = 0;
/*
* Line will end if,
* 1. We have recieved 256 chars or
* 2. we recieved EOL: '\n' followed by '\r'
*/
while((data[index] != '\n' && ((data[index++] = fgetc(file)) != '\r')) ||
index != MAX_LINE_LEN);
return data;
}

View File

@@ -0,0 +1,67 @@
#include <stdio.h>
#include <stdint.h>
extern int __fputc(int c, FILE *stream);
static int ser_out(int c)
{
__fputc(c, 0);
if (c == '\n')
ser_out('\r');
return 0;
}
static size_t
l4kdb_write(void *data, long int position, size_t count, void *handle /*unused*/)
{
size_t i;
char *real_data = data;
for (i = 0; i < count; i++)
ser_out(real_data[i]);
return count;
}
struct __file __stdin = {
.handle = NULL,
.read_fn = NULL,
.write_fn = NULL,
.close_fn = NULL,
.eof_fn = NULL,
.buffering_mode = _IONBF,
.buffer = NULL,
.unget_pos = 0,
.current_pos = 0,
.eof = 0
};
struct __file __stdout = {
.handle = NULL,
.read_fn = NULL,
.write_fn = l4kdb_write,
.close_fn = NULL,
.eof_fn = NULL,
.buffering_mode = _IONBF,
.buffer = NULL,
.unget_pos = 0,
.current_pos = 0,
.eof = 0
};
struct __file __stderr = {
.handle = NULL,
.read_fn = NULL,
.write_fn = l4kdb_write,
.close_fn = NULL,
.eof_fn = NULL,
.buffering_mode = _IONBF,
.buffer = NULL,
.unget_pos = 0,
.current_pos = 0,
.eof = 0
};
FILE *stdin = &__stdin;
FILE *stdout = &__stdout;
FILE *stderr = &__stderr;

View File

@@ -0,0 +1,91 @@
/*
* Australian Public Licence B (OZPLB)
*
* Version 1-0
*
* Copyright (c) 2005 National ICT Australia
*
* All rights reserved.
*
* Developed by: Embedded, Real-time and Operating Systems Program (ERTOS)
* National ICT Australia
* http://www.ertos.nicta.com.au
*
* Permission is granted by National ICT Australia, free of charge, to
* any person obtaining a copy of this software and any associated
* documentation files (the "Software") to deal with the Software without
* restriction, including (without limitation) the rights to use, copy,
* modify, adapt, merge, publish, distribute, communicate to the public,
* sublicense, and/or sell, lend or rent out copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimers.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of National ICT Australia, nor the names of its
* contributors, may be used to endorse or promote products derived
* from this Software without specific prior written permission.
*
* EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT
* PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND
* NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS,
* WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS
* REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
* THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF
* ERRORS, WHETHER OR NOT DISCOVERABLE.
*
* TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL
* NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL
* THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER
* LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR
* OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS
* OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR
* OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT,
* CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN
* CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER
* DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS
* CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS,
* DAMAGES OR OTHER LIABILITY.
*
* If applicable legislation implies representations, warranties, or
* conditions, or imposes obligations or liability on National ICT
* Australia or one of its contributors in respect of the Software that
* cannot be wholly or partly excluded, restricted or modified, the
* liability of National ICT Australia or the contributor is limited, to
* the full extent permitted by the applicable legislation, at its
* option, to:
* a. in the case of goods, any one or more of the following:
* i. the replacement of the goods or the supply of equivalent goods;
* ii. the repair of the goods;
* iii. the payment of the cost of replacing the goods or of acquiring
* equivalent goods;
* iv. the payment of the cost of having the goods repaired; or
* b. in the case of services:
* i. the supplying of the services again; or
* ii. the payment of the cost of having the services supplied again.
*
* The construction, validity and performance of this licence is governed
* by the laws in force in New South Wales, Australia.
*/
/*
Author: Ben Leslie <benjl@cse.unsw.edu.au>
*/
#include <stdio.h>
#include "format.h"
int
vfprintf(FILE *stream, const char *format, va_list arg)
{
return format_string(NULL, stream, 1, -1, format, arg);
}

View File

@@ -0,0 +1,40 @@
# -*- mode: python; coding: utf-8; -*-
#
# Codezero -- Virtualization microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
import os, sys
from os.path import join
# Get global paths
PROJRELROOT = '../../../'
sys.path.append(PROJRELROOT)
from scripts.config.projpaths import *
Import('env', 'type', 'build_dir')
env.Append(CPPPATH = [LIBDEV_INCLUDE, LIBC_INCLUDE, LIBL4_INCLUDE],
CCFLAGS = ['-DVARIANT_' + type.upper()])
objects = SConscript('uart/pl011/SConscript', duplicate=0, exports = { 'env' : env },
variant_dir = join(build_dir, 'uart/pl011'))
objects += SConscript('timer/sp804/SConscript', duplicate=0, exports = { 'env' : env },
variant_dir = join(build_dir, 'timer/sp804'))
objects += SConscript('kmi/pl050/SConscript', duplicate=0, exports = { 'env' : env },
variant_dir = join(build_dir, 'kmi/pl050'))
objects += SConscript('clcd/pl110/SConscript', duplicate=0, exports = { 'env' : env },
variant_dir = join(build_dir, 'clcd/pl110'))
objects += SConscript('uart/omap/SConscript', duplicate=0, exports = { 'env' : env },
variant_dir = join(build_dir, 'uart/omap'))
objects += SConscript('timer/omap/SConscript', duplicate=0, exports = { 'env' : env },
variant_dir = join(build_dir, 'timer/omap'))
library = env.StaticLibrary(join(build_dir, 'libdev-' + type), objects)
Return('library')

View File

@@ -0,0 +1,56 @@
# -*- mode: python; coding: utf-8; -*-
#
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
import os, sys
PROJRELROOT = '../../..'
sys.path.append(PROJRELROOT)
from scripts.config.projpaths import *
from scripts.config.configuration import *
config = configuration_retrieve()
gcc_arch_flag = config.gcc_arch_flag
# We assume we are compiling for userspace.
# variant can be specified from cmdline using
# scons variant=xxx
variant = ARGUMENTS.get('variant', 'userspace')
print '\nCompiling for variant: ' + variant + '\n'
builddir = join(join(BUILDDIR, LIBDEV_RELDIR), 'sys-' + variant)
VariantDir(builddir, os.getcwd())
env = Environment(CC = config.toolchain_userspace + 'gcc',
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99',
'-nostdinc', '-Wall', '-DVARIANT_' + variant.upper(),
'-march=' + gcc_arch_flag, '-Werror'],
LINKFLAGS = ['-nostdlib'],
ASFLAGS = ['-D__ASSEMBLY__'],
ENV = {'PATH' : os.environ['PATH']},
CPPPATH = ['#include', LIBC_INCLUDE, LIBL4_INCLUDE, KERNEL_HEADERS])
objects = SConscript('uart/pl011/SConscript', duplicate=0,
exports = { 'env' : env },
variant_dir = join(builddir, 'uart/pl011'))
objects += SConscript('timer/sp804/SConscript', duplicate=0,
exports = { 'env' : env },
variant_dir = join(builddir, 'timer/sp804'))
objects += SConscript('kmi/pl050/SConscript', duplicate=0,
exports = { 'env' : env },
variant_dir = join(builddir, 'kmi/pl050'))
objects += SConscript('clcd/pl110/SConscript', duplicate=0,
exports = { 'env' : env },
variant_dir = join(builddir, 'clcd/pl110'))
objects += SConscript('uart/omap/SConscript', duplicate=0,
exports = { 'env' : env },
variant_dir = join(builddir, 'uart/omap'))
objects += SConscript('timer/omap/SConscript', duplicate=0,
exports = { 'env' : env },
variant_dir = join(builddir, 'timer/omap'))
library = env.StaticLibrary(join(builddir, 'libdev-' + variant), objects)

View File

@@ -0,0 +1,23 @@
import sys
Import('env')
# Get global paths
PROJRELROOT = '../../../'
sys.path.append(PROJRELROOT)
from scripts.config.configuration import *
config = configuration_retrieve()
platform = config.platform
#Platforms using pl110
plat_list = ('eb', 'pba9', 'pb926')
# The set of source files associated with this SConscript file.
src_local = []
for plat_supported in plat_list:
if plat_supported == platform:
src_local += Glob('*.c')
obj = env.StaticObject(src_local)
Return('obj')

View File

@@ -0,0 +1,3 @@

View File

@@ -0,0 +1,5 @@
#ifndef __CLCD_H__
#define __CLCD_H__
#endif /* __CLCD_H__ */

View File

@@ -0,0 +1,12 @@
/*
* IO functions/macros.
*
* Copyright (C) 2007 Bahadir Balban
*/
#ifndef __LIBDEV_IO_H__
#define __LIBDEV_IO_H__
#define read(address) *((volatile unsigned int *)(address))
#define write(val, address) *((volatile unsigned int *)(address)) = val
#endif /* __LIBDEV_IO_H__ */

View File

@@ -0,0 +1,26 @@
#ifndef __KMI_H__
#define __KMI_H__
/*
* Current keyboard state
*/
struct keyboard_state{
int keyup;
int shift;
int caps_lock;
};
/* Common functions */
void kmi_rx_irq_enable(unsigned long base);
int kmi_data_read(unsigned long base);
/* Keyboard specific calls */
char kmi_keyboard_read(unsigned long base, struct keyboard_state *state);
void kmi_keyboard_init(unsigned long base, unsigned int div);
/* Mouse specific calls */
void kmi_mouse_enable(unsigned long base);
void kmi_mouse_init(unsigned long base, unsigned int div);
#endif /* __KMI_H__ */

View File

@@ -0,0 +1,17 @@
/*
* Generic platform file.
*
* Copyright (C) 2010 B Labs Ltd.
*
* Author: Bahadir Balban
*/
#ifndef __LIBDEV_PLATFORM_H__
#define __LIBDEV_PLATFORM_H__
#define INC_LIBDEV_PLAT(x) <dev/platform/__PLATFORM__/x>
/* paths realtive to conts/dev/ */
#include INC_LIBDEV_PLAT(irq.h)
#include INC_LIBDEV_PLAT(platform.h)
#endif /* __LIBDEV_PLATFORM_H__ */

View File

@@ -0,0 +1,13 @@
/*
* IRQ numbers for beagle board.
*
* Copyright (C) 2010 B Labs Ltd.
*
*/
#ifndef __LIBDEV_BEAGLE_IRQ_H__
#define __LIBDEV_BEAGLE_IRQ_H__
#define IRQ_TIMER0 37
#define IRQ_TIMER1 38
#endif /* __LIBDEV_BEAGLE_IRQ_H__ */

View File

@@ -0,0 +1,13 @@
/*
* Platform offsets for beagle board.
*
* Copyright (C) 2010 B Labs Ltd.
*
*/
#ifndef __LIBDEV_PLATFORM_BEAGLE_H__
#define __LIBDEV_PLATFORM_BEAGLE_H__
#define PLATFORM_TIMER1_BASE 0x49032000 /* GPTIMER2 */
#define PLATFORM_TIMER2_BASE 0x49034000 /* GPTIMER3 */
#endif /* __LIBDEV_PLATFORM_BEAGLE_H__ */

View File

@@ -0,0 +1,22 @@
/*
* IRQ numbers for eb.
*
* Copyright (C) 2010 B Labs Ltd.
*
*/
#ifndef __LIBDEV_EB_IRQ_H__
#define __LIBDEV_EB_IRQ_H__
#if defined (CONFIG_CPU_ARM11MPCORE) || defined (CONFIG_CPU_CORTEXA9)
#define IRQ_TIMER1 34
#define IRQ_KEYBOARD0 39
#define IRQ_MOUSE0 40
#define IRQ_CLCD0 55
#else
#define IRQ_TIMER1 37
#define IRQ_KEYBOARD0 52
#define IRQ_MOUSE0 53
#define IRQ_CLCD0 55
#endif /* CONFIG_CPU_ARM11MPCORE || CONFIG_CPU_CORTEXA9 */
#endif /* __LIBDEV_EB_IRQ_H__ */

View File

@@ -0,0 +1,14 @@
/*
* Platform offsets for eb.
*
* Copyright (C) 2010 B Labs Ltd.
*
*/
#ifndef __LIBDEV_PLATFORM_EB_H__
#define __LIBDEV_PLATFORM_EB_H__
#include <dev/platform/realview/platform.h>
#define PLATFORM_CLCD0_BASE 0x10020000 /* CLCD0 */
#endif /* __LIBDEV_PLATFORM_EB_H__ */

View File

@@ -0,0 +1,15 @@
/*
* IRQ numbers for pb926.
*
* Copyright (C) 2010 B Labs Ltd.
*
*/
#ifndef __LIBDEV_PB926_IRQ_H__
#define __LIBDEV_PB926_IRQ_H__
#define IRQ_TIMER1 5
#define IRQ_CLCD0 16
#define IRQ_KEYBOARD0 34
#define IRQ_MOUSE0 35
#endif /* __LIBDEV_PB926_IRQ_H__ */

View File

@@ -0,0 +1,15 @@
/*
* Platform offsets for pb926.
*
* Copyright (C) 2010 B Labs Ltd.
*
*/
#ifndef __LIBDEV_PLATFORM_PB926_H__
#define __LIBDEV_PLATFORM_PB926_H__
#define PLATFORM_KEYBOARD0_BASE 0x10006000 /* Keyboard */
#define PLATFORM_MOUSE0_BASE 0x10007000 /* Mouse */
#define PLATFORM_TIMER1_BASE 0x101E3000 /* Timers 2 and 3 */
#define PLATFORM_CLCD0_BASE 0x10120000 /* Color LCD */
#endif /* __LIBDEV_PLATFORM_PB926_H__ */

View File

@@ -0,0 +1,15 @@
/*
* IRQ numbers for pba9.
*
* Copyright (C) 2010 B Labs Ltd.
*
*/
#ifndef __LIBDEV_PBA9_IRQ_H__
#define __LIBDEV_PBA9_IRQ_H__
#define IRQ_TIMER1 35
#define IRQ_KEYBOARD0 44
#define IRQ_MOUSE0 45
#define IRQ_CLCD0 46
#endif /* __LIBDEV_PBA9_IRQ_H__ */

View File

@@ -0,0 +1,14 @@
/*
* Platform offsets for versatile express.
*
* Copyright (C) 2010 B Labs Ltd.
*
*/
#ifndef __LIBDEV_PLATFORM_PBA9_H__
#define __LIBDEV_PLATFORM_PBA9_H__
#include <dev/platform/realview/platform.h>
#define PLATFORM_CLCD0_BASE 0x1001F000 /* CLCD */
#endif /* __LIBDEV_PLATFORM_PBA9_H__ */

View File

@@ -0,0 +1,17 @@
/*
* Common Platform offsets for realview platforms.
* It includes:
* a. pba9
* b. eb
*
* Copyright (C) 2010 B Labs Ltd.
*
*/
#ifndef __LIBDEV_PLATFORM_REALVIEW_H__
#define __LIBDEV_PLATFORM_REALVIEW_H__
#define PLATFORM_KEYBOARD0_BASE 0x10006000 /* Keyboard */
#define PLATFORM_MOUSE0_BASE 0x10007000 /* Mouse */
#define PLATFORM_TIMER1_BASE 0x10012000 /* Timers 2 and 3 */
#endif /* __LIBDEV_PLATFORM_REALVIEW_H__ */

View File

@@ -0,0 +1,23 @@
/*
* Generic timer library API
*
* Copyright (C) 2010 B Labs Ltd.
*
* Author: Bahadir Balban
*/
#ifndef __LIBDEV_TIMER_H__
#define __LIBDEV_TIMER_H__
/*
* Simple API for the primary timer
* for userspace
*/
void timer_start(unsigned long timer_base);
void timer_load(u32 val, unsigned long timer_base);
u32 timer_read(unsigned long timer_base);
void timer_stop(unsigned long timer_base);
void timer_init_oneshot(unsigned long timer_base);
void timer_init_periodic(unsigned long timer_base, u32 load_value);
void timer_init(unsigned long timer_base, u32 load_value);
#endif /* __LIBDEV_TIMER_H__ */

View File

@@ -0,0 +1,21 @@
/*
* Generic uart API
*
* Copyright (C) 2010 B Labs Ltd.
*
* Author: Bahadir Balban
*/
#ifndef __LIBDEV_UART_H__
#define __LIBDEV_UART_H__
void uart_tx_char(unsigned long uart_base, char c);
char uart_rx_char(unsigned long uart_base);
void uart_set_baudrate(unsigned long uart_base, unsigned int val);
void uart_init(unsigned long base);
/*
* Base of primary uart used for printf
*/
extern unsigned long uart_print_base;
#endif /* __LIBDEV_UART_H__ */

View File

@@ -0,0 +1,24 @@
import sys
Import('env')
# Get global paths
PROJRELROOT = '../../../'
sys.path.append(PROJRELROOT)
from scripts.config.configuration import *
config = configuration_retrieve()
platform = config.platform
#Platforms using pl050
plat_list = ('eb', 'pba9', 'pb926')
# The set of source files associated with this SConscript file.
src_local = []
for plat_supported in plat_list:
if plat_supported == platform:
src_local += Glob('*.c')
obj = env.StaticObject(src_local)
Return('obj')

View File

@@ -0,0 +1,286 @@
#ifndef __KEYMAP_H__
#define __KEYMAP_H__
/* Special meaning keys */
#define KEYCODE_LSHIFT 0x101
#define KEYCODE_RSHIFT 0x102
#define KEYCODE_LCTRL 0x103
#define KEYCODE_RCTRL 0x104
#define KEYCODE_ALT 0x105
#define KEYCODE_ALTGR 0x106
#define KEYCODE_CAPSLK 0x201
#define KEYCODE_SCRLK 0x202
#define KEYCODE_NUMLK 0x203
#define KEYCODE_RETURN 0x303
#define KEYCODE_ESCAPE 0x304
#if 0
#define KEYCODE_TAB 0x301
#define KEYCODE_BACKSP 0x302
#define KEYCODE_ENTER 0x305
#else
#define KEYCODE_TAB '\t'
#define KEYCODE_BACKSP '\b'
#define KEYCODE_ENTER '\n'
#endif
#define KEYCODE_PRTSCR 0x401
#define KEYCODE_BREAK 0x402
#define KEYCODE_INSERT 0x403
#define KEYCODE_HOME 0x404
#define KEYCODE_PAGEUP 0x405
#define KEYCODE_DELETE 0x406
#define KEYCODE_END 0x407
#define KEYCODE_PAGEDN 0x408
#define KEYCODE_UP 0x501
#define KEYCODE_DOWN 0x502
#define KEYCODE_LEFT 0x503
#define KEYCODE_RIGHT 0x504
#define KEYCODE_CENTER 0x505
#define KEYCODE_F1 0x601
#define KEYCODE_F2 0x602
#define KEYCODE_F3 0x603
#define KEYCODE_F4 0x604
#define KEYCODE_F5 0x605
#define KEYCODE_F6 0x606
#define KEYCODE_F7 0x607
#define KEYCODE_F8 0x608
#define KEYCODE_F9 0x609
#define KEYCODE_F10 0x60A
#define KEYCODE_F11 0x60B
#define KEYCODE_F12 0x60C
#define KEYCODE_WINL 0x701
#define KEYCODE_WINR 0x702
#define KEYCODE_MENU 0x703
#define MODIFIER_EXTENDED 0x00100000
#define MODIFIER_EXTENDED2 0x00200000
#define MODIFIER_RCTRL 0x00400000
#define MODIFIER_RSHIFT 0x00800000
#define MODIFIER_LSHIFT 0x01000000
#define MODIFIER_LCTRL 0x02000000
#define MODIFIER_ALT 0x04000000
#define MODIFIER_ALTGR 0x08000000
#define MODIFIER_SCRLK 0x10000000
#define MODIFIER_NUMLK 0x20000000
#define MODIFIER_CAPSLK 0x40000000
#define MODIFIER_RELEASE 0x80000000
#define MODIFIER_SHIFT (MODIFIER_LSHIFT | MODIFIER_RSHIFT)
#define MODIFIER_CTRL (MODIFIER_LCTRL | MODIFIER_RCTRL)
struct keyboard_key {
int nomods;
int shift;
int ext_nomods;
int ext_shift;
};
/*
* Keymap for a UK keyboard
* maps key numbers->key codes
*
* We will use scan code index to get the key
*
* FIXME: element 1 and 4 gives, muticharacter
* character constant error, fix this.
*/
struct keyboard_key keymap_uk2[256] = {
/* 0 */ {0,0,0,0},
#if 0
/* 1 */ {'`','¬',0,0},
#else
/* 1 */ {'`',0,0,0},
#endif
/* 2 */ {'1','!',0,0},
/* 3 */ {'2','"',0,0},
#if 0
/* 4 */ {'3','£',0,0},
#else
/* 4 */ {'3',0,0,0},
#endif
/* 5 */ {'4','$',0,0},
/* 6 */ {'5','%',0,0},
/* 7 */ {'6','^',0,0},
/* 8 */ {'7','&',0,0},
/* 9 */ {'8','*',0,0},
/* 10 */ {'9','(',0,0},
/* 11 */ {'0',')',0,0},
/* 12 */ {'-','_',0,0},
/* 13 */ {'=','+',0,0},
/* 14 */ {0,0,0,0},
/* 15 */ {KEYCODE_BACKSP,0,0,0},
/* 16 */ {KEYCODE_TAB,0,0,0},
/* 17 */ {'q','Q',0,0},
/* 18 */ {'w','W',0,0},
/* 19 */ {'e','E',0,0},
/* 20 */ {'r','R',0,0},
/* 21 */ {'t','T',0,0},
/* 22 */ {'y','Y',0,0},
/* 23 */ {'u','U',0,0},
/* 24 */ {'i','I',0,0},
/* 25 */ {'o','O',0,0},
/* 26 */ {'p','P',0,0},
/* 27 */ {'[','{',0,0},
/* 28 */ {']','}',0,0},
/* 29 */ {'#','~',0,0},
/* 30 */ {KEYCODE_CAPSLK,0,0,0},
/* 31 */ {'a','A',0,0},
/* 32 */ {'s','S',0,0},
/* 33 */ {'d','D',0,0},
/* 34 */ {'f','F',0,0},
/* 35 */ {'g','G',0,0},
/* 36 */ {'h','H',0,0},
/* 37 */ {'j','J',0,0},
/* 38 */ {'k','K',0,0},
/* 39 */ {'l','L',0,0},
/* 40 */ {';',':',0,0},
/* 41 */ {'\'','@',0,0},
/* 42 */ {0,0,0,0},
/* 43 */ {'\n','\n',KEYCODE_ENTER,0},
/* 44 */ {KEYCODE_LSHIFT,0,0,0},
/* 45 */ {'\\','|',0,0},
/* 46 */ {'z','Z',0,0},
/* 47 */ {'x','X',0,0},
/* 48 */ {'c','C',0,0},
/* 49 */ {'v','V',0,0},
/* 50 */ {'b','B',0,0},
/* 51 */ {'n','N',0,0},
/* 52 */ {'m','M',0,0},
/* 53 */ {',','<',0,0},
/* 54 */ {'.','>',0,0},
/* 55 */ {'/','?','/' | MODIFIER_NUMLK,0},
/* 56 */ {0,0,0,0},
/* 57 */ {KEYCODE_RSHIFT,0,0,0},
/* 58 */ {KEYCODE_LCTRL,0,KEYCODE_RCTRL,0},
/* 59 */ {0,0,0,0},
/* 60 */ {KEYCODE_ALT,0,KEYCODE_ALTGR,0},
/* 61 */ {' ',0,0,0},
/* 62 */ {KEYCODE_ALTGR,0,0,0},
/* 63 */ {0,0,0,0},
/* 64 */ {KEYCODE_RCTRL,0,0,0},
/* 65 */ {0,0,0,0},
/* 66 */ {0,0,0,0},
/* 67 */ {0,0,0,0},
/* 68 */ {0,0,0,0},
/* 69 */ {0,0,0,0},
/* 70 */ {0,0,0,0},
/* 71 */ {0,0,0,0},
/* 72 */ {0,0,0,0},
/* 73 */ {0,0,0,0},
/* 74 */ {0,0,0,0},
/* 75 */ {KEYCODE_INSERT,0,0,0},
/* 76 */ {KEYCODE_DELETE,0,0,0},
/* 77 */ {0,0,0,0},
/* 78 */ {0,0,0,0},
/* 79 */ {KEYCODE_LEFT,0,0,0},
/* 80 */ {KEYCODE_HOME,0,0,0},
/* 81 */ {KEYCODE_END,0,0,0},
/* 82 */ {0,0,0,0},
/* 83 */ {KEYCODE_UP,0,0,0},
/* 84 */ {KEYCODE_DOWN,0,0,0},
/* 85 */ {KEYCODE_PAGEUP,0,0,0},
/* 86 */ {KEYCODE_PAGEDN,0,0,0},
/* 87 */ {0,0,0,0},
/* 88 */ {0,0,0,0},
/* 89 */ {KEYCODE_RIGHT,0,0,0},
/* 90 */ {KEYCODE_NUMLK,0,KEYCODE_BREAK,0},
/* 91 */ {KEYCODE_HOME | MODIFIER_NUMLK,0,KEYCODE_HOME,0},
/* 92 */ {KEYCODE_LEFT | MODIFIER_NUMLK,0,KEYCODE_LEFT,0},
/* 93 */ {KEYCODE_END | MODIFIER_NUMLK,0,KEYCODE_END,0},
/* 94 */ {0,0,0,0},
/* 95 */ {'/' | MODIFIER_NUMLK,0,0},
/* 96 */ {KEYCODE_UP | MODIFIER_NUMLK,0,KEYCODE_UP,0},
/* 97 */ {KEYCODE_CENTER | MODIFIER_NUMLK,0,KEYCODE_CENTER,0},
/* 98 */ {KEYCODE_DOWN | MODIFIER_NUMLK,0,KEYCODE_DOWN,0},
/* 99 */ {KEYCODE_INSERT | MODIFIER_NUMLK,0,KEYCODE_INSERT,0},
/* 100 */ {'*' | MODIFIER_NUMLK,0,KEYCODE_PRTSCR,0},
/* 101 */ {KEYCODE_PAGEUP | MODIFIER_NUMLK,0,KEYCODE_PAGEUP,0},
/* 102 */ {KEYCODE_RIGHT | MODIFIER_NUMLK,0,KEYCODE_RIGHT,0},
/* 103 */ {KEYCODE_PAGEDN | MODIFIER_NUMLK,0,KEYCODE_PAGEDN,0},
/* 104 */ {KEYCODE_DELETE | MODIFIER_NUMLK,0,KEYCODE_DELETE,0},
/* 105 */ {'-' | MODIFIER_NUMLK,0,0,0},
/* 106 */ {'+' | MODIFIER_NUMLK,0,0,0},
/* 107 */ {KEYCODE_ENTER,0,0,0},
/* 108 */ {0,0,0,0},
/* 109 */ {0,0,0,0},
/* 110 */ {KEYCODE_ESCAPE,0,0,0},
/* 111 */ {0,0,0,0},
/* 112 */ {KEYCODE_F1,0,0,7},
/* 113 */ {KEYCODE_F2,0,0,0},
/* 114 */ {KEYCODE_F3,0,0,0},
/* 115 */ {KEYCODE_F4,0,0,0},
/* 116 */ {KEYCODE_F5,0,0,0},
/* 117 */ {KEYCODE_F6,0,0,0},
/* 118 */ {KEYCODE_F7,0,0,0},
/* 119 */ {KEYCODE_F8,0,0,0},
/* 120 */ {KEYCODE_F9,0,0,0},
/* 121 */ {KEYCODE_F10,0,0,0},
/* 122 */ {KEYCODE_F11,0,0,0},
/* 123 */ {KEYCODE_F12,0,0,0},
/* 124 */ {KEYCODE_PRTSCR,0,0,0},
/* 125 */ {KEYCODE_SCRLK,0,KEYCODE_BREAK,0},
/* 126 */ {KEYCODE_BREAK,0,0,0},
/* 127 */ {0,0,0,0},
/* 128 */ {KEYCODE_WINL,0,KEYCODE_WINL,0},
/* 129 */ {KEYCODE_WINR,0,KEYCODE_WINR,0},
/* 130 */ {KEYCODE_MENU,0,KEYCODE_MENU,0},
/* currently no keys with numbers > 130 */
/* 131 */ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
/* 140 */ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
/* 150 */ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
/* 160 */ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
/* 170 */ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
/* 180 */ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
/* 190 */ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
/* 200 */ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
/* 210 */ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
/* 220 */ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
/* 230 */ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
/* 240 */ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
/* 250 */ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}
};
/*
* Scan code to key number conversion table for
* an extended AT keyboard in mode 2
*
* This will give us the key index for keyboard
*/
int scancode_mode2_extended[256] = {
0, 120, 0, 116, 114, 112, 113,
123, 0, 121, 119, 117, 115, 16,
1, 0, 0, 60, 44, 0, 58,
17, 2, 0, 0, 0, 46, 32,
31, 18, 3, 128, 0, 48, 47,
33, 19, 5, 4, 129, 0, 61,
49, 34, 21, 20, 6, 130, 0,
51, 50, 36, 35, 22, 7, 0,
0, 0, 52, 37, 23, 8, 9,
0, 0, 53, 38, 24, 25, 11,
10, 0, 0, 54, 55, 39, 40,
26, 12, 0, 0, 0, 41, 0,
27, 13, 0, 0, 30, 57, 43,
28, 0, 29, 0, 0, 0, 45,
0, 0, 0, 0, 15, 0, 0,
93, 0, 92, 91, 0, 0, 0,
99, 104, 98, 97, 102, 96, 110,
90, 122, 106, 103, 105, 100, 101,
125, 0, 0, 0, 0, 118, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0,
/* no keys with codes > 0x8F */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
#endif /* __KEYMAP_H__ */

View File

@@ -0,0 +1,386 @@
/*
* PL050 Primecell Keyboard, Mouse driver
*
* Copyright (C) 2010 Amit Mahajan
*/
#include <dev/kmi.h>
#include "kmi.h"
#include "keymap.h"
/* Enable Rx irq */
void kmi_rx_irq_enable(unsigned long base)
{
*(volatile unsigned long *)(base + PL050_KMICR) = KMI_RXINTR;
}
int kmi_data_read(unsigned long base)
{
/* Check and return if data present */
if (*(volatile unsigned long *)(base + PL050_KMISTAT) & KMI_RXFULL)
return *(volatile unsigned long *)(base + PL050_KMIDATA);
else
return 0;
}
#if 0
char kmi_keyboard_read(int c, struct keyboard_state *state)
{
int keycode, shkeycode;
int keynum;
int extflag;
int modmask;
/* Special codes */
switch (c) {
case 0xF0:
/* release */
state->modifiers |= MODIFIER_RELEASE;
return 0;
case 0xE0:
/* extended */
state->modifiers |= MODIFIER_EXTENDED;
return 0;
case 0xE1:
/* extended for 2 characters - only used for Break in mode 2 */
state->modifiers |= MODIFIER_EXTENDED;
state->modifiers |= MODIFIER_EXTENDED2;
return 0;
}
extflag = 1;
modmask = 0xFFFFFFFF;
/* Is this a scan code? */
if (c > 0 && c <= 0x9F)
{
keynum = scancode_mode2_extended[c];
/* ignore unrecognised codes */
if (!keynum)
{
state->modifiers &= ~MODIFIER_RELEASE;
return 0;
}
/* is this an extended code? */
if (state->modifiers & MODIFIER_EXTENDED)
{
keycode = keymap_uk2[keynum].ext_nomods;
extflag = 0;
state->modifiers &= ~MODIFIER_EXTENDED;
if (!keycode)
{
state->modifiers &= ~MODIFIER_RELEASE;
return 0;
}
}
else if (state->modifiers & MODIFIER_EXTENDED2)
{
keycode = keymap_uk2[keynum].ext_nomods;
extflag = 0;
state->modifiers &= ~MODIFIER_EXTENDED2;
if (!keycode)
{
state->modifiers &= ~MODIFIER_RELEASE;
return 0;
}
}
else
{
keycode = keymap_uk2[keynum].nomods;
if (!keycode)
{
state->modifiers &= ~MODIFIER_RELEASE;
return 0;
}
}
/* handle shift */
if (state->modifiers & MODIFIER_CAPSLK)
{
if (keycode >= 'a' && keycode <= 'z')
{
if (!(state->modifiers & MODIFIER_SHIFT))
{
shkeycode = !extflag ? keymap_uk2[keynum].ext_shift : keymap_uk2[keynum].shift;
if (shkeycode)
keycode = shkeycode;
}
}
else
{
if (state->modifiers & MODIFIER_SHIFT)
{
shkeycode = !extflag ? keymap_uk2[keynum].ext_shift : keymap_uk2[keynum].shift;
if (shkeycode)
keycode = shkeycode;
}
}
}
else
{
if (state->modifiers & MODIFIER_SHIFT)
{
shkeycode = extflag ? keymap_uk2[keynum].ext_shift : keymap_uk2[keynum].shift;
if (shkeycode)
keycode = shkeycode;
}
}
/* handle the numeric keypad */
if (keycode & MODIFIER_NUMLK)
{
keycode &= ~MODIFIER_NUMLK;
if (state->modifiers & MODIFIER_NUMLK)
{
if (!(state->modifiers & MODIFIER_SHIFT))
{
switch (keycode)
{
case KEYCODE_HOME:
keycode = '7';
break;
case KEYCODE_UP:
keycode = '8';
break;
case KEYCODE_PAGEUP:
keycode = '9';
break;
case KEYCODE_LEFT:
keycode = '4';
break;
case KEYCODE_CENTER:
keycode = '5';
break;
case KEYCODE_RIGHT:
keycode = '6';
break;
case KEYCODE_END:
keycode = '1';
break;
case KEYCODE_DOWN:
keycode = '2';
break;
case KEYCODE_PAGEDN:
keycode = '3';
break;
case KEYCODE_INSERT:
keycode = '0';
break;
case KEYCODE_DELETE:
keycode = '.';
break;
}
}
else
modmask = ~MODIFIER_SHIFT;
}
}
/* modifier keys */
switch (keycode)
{
case KEYCODE_LSHIFT:
if (state->modifiers & MODIFIER_RELEASE)
state->modifiers &= ~(MODIFIER_LSHIFT | MODIFIER_RELEASE);
else
state->modifiers |= MODIFIER_LSHIFT;
return 0;
case KEYCODE_RSHIFT:
if (state->modifiers & MODIFIER_RELEASE)
state->modifiers &= ~(MODIFIER_RSHIFT | MODIFIER_RELEASE);
else
state->modifiers |= MODIFIER_RSHIFT;
return 0;
case KEYCODE_LCTRL:
if (state->modifiers & MODIFIER_RELEASE)
state->modifiers &= ~(MODIFIER_LCTRL | MODIFIER_RELEASE);
else
state->modifiers |= MODIFIER_LCTRL;
return 0;
case KEYCODE_RCTRL:
if (state->modifiers & MODIFIER_RELEASE)
state->modifiers &= ~(MODIFIER_RCTRL | MODIFIER_RELEASE);
else
state->modifiers |= MODIFIER_RCTRL;
return 0;
case KEYCODE_ALT:
if (state->modifiers & MODIFIER_RELEASE)
state->modifiers &= ~(MODIFIER_ALT | MODIFIER_RELEASE);
else
state->modifiers |= MODIFIER_ALT;
return 0;
case KEYCODE_ALTGR:
if (state->modifiers & MODIFIER_RELEASE)
state->modifiers &= ~(MODIFIER_ALTGR | MODIFIER_RELEASE);
else
state->modifiers |= MODIFIER_ALTGR;
return 0;
case KEYCODE_CAPSLK:
if (state->modifiers & MODIFIER_RELEASE)
state->modifiers &= ~MODIFIER_RELEASE;
else
{
state->modifiers ^= MODIFIER_CAPSLK;
//__keyb_update_locks (state);
}
return 0;
case KEYCODE_SCRLK:
if (state->modifiers & MODIFIER_RELEASE)
state->modifiers &= ~MODIFIER_RELEASE;
else
{
state->modifiers ^= MODIFIER_SCRLK;
//__keyb_update_locks (state);
}
return 0;
case KEYCODE_NUMLK:
if (state->modifiers & MODIFIER_RELEASE)
state->modifiers &= ~MODIFIER_RELEASE;
else
{
state->modifiers ^= MODIFIER_NUMLK;
//__keyb_update_locks (state);
}
return 0;
}
if (state->modifiers & MODIFIER_RELEASE)
{
/* clear release condition */
state->modifiers &= ~MODIFIER_RELEASE;
}
else
{
/* write code into the buffer */
return keycode;
}
return 0;
}
return 0;
}
#endif
/*
* Simple logic to interpret keyboard keys and shift keys
* TODO: Add support for all the modifier keys
*
* Keyevents work in 3 phase manner, if you press 'A':
* 1. scan code for 'A' is generated
* 2. Key release event i.e KYBD_DATA_KEYUP
* 3. scan code for 'A' again is generated
*/
char kmi_keyboard_read(unsigned long base, struct keyboard_state *state)
{
int keynum, keycode = 0;
/* Read Keyboard RX buffer */
unsigned char data = kmi_data_read(base);
/* if a key up occurred (key released) occured */
if (data == KYBD_DATA_KEYUP) {
state->keyup = 1;
return 0;
}
else if (state->keyup){
state->keyup = 0;
/* Check if shift was lifted */
if ((data == KYBD_DATA_SHIFTL) || (data == KYBD_DATA_SHIFTR)) {
state->shift = 0;
}
else {
/* Find key number */
keynum = scancode_mode2_extended[data];
if(state->shift)
keycode = keymap_uk2[keynum].shift;
else
keycode = keymap_uk2[keynum].nomods;
}
}
else if ((data == KYBD_DATA_SHIFTL) || (data == KYBD_DATA_SHIFTR)) {
state->shift = 1;
}
return (unsigned char)keycode;
}
void kmi_keyboard_init(unsigned long base, unsigned int div)
{
/* STOP KMI */
*(volatile unsigned long *)(base + PL050_KMICR) = 0x0;
/*
* For versatile, KMI refernce clock = 24MHz
* KMI manual says we need 8MHz clock,
* so divide by 3
*/
*(volatile unsigned long *)(base + PL050_KMICLKDIV) = div;
/* Enable KMI and TX/RX interrupts */
*(volatile unsigned long *)(base + PL050_KMICR) =
KMI_RXINTR | KMI_EN;
/* Reset and wait for reset to complete */
*(volatile unsigned long *)(base + PL050_KMIDATA) =
KYBD_DATA_RESET;
while(kmi_data_read(base) != KYBD_DATA_RTR);
}
void kmi_mouse_enable(unsigned long base)
{
unsigned long *datareg = (unsigned long *)(base + PL050_KMIDATA);
*datareg = MOUSE_DATA_ENABLE;
/*sleep for sometime here */
while (*datareg != MOUSE_DATA_ACK);
}
void kmi_mouse_init(unsigned long base, unsigned int div)
{
int data[2];
/* STOP KMI */
*(volatile unsigned long *)(base + PL050_KMICR) = 0x0;
/*
* For versatile, KMI refernce clock = 24MHz
* KMI manual says we need 8MHz clock,
* so divide by 3
*/
*(volatile unsigned long *)(base + PL050_KMICLKDIV) = div;
/* Enable KMI and TX/RX interrupts */
*(volatile unsigned long *)(base + PL050_KMICR) =
KMI_RXINTR | KMI_EN;
/* Reset and wait for reset to complete */
*(volatile unsigned long *)(base + PL050_KMIDATA) =
MOUSE_DATA_RESET;
do {
data[0] = kmi_data_read(base);
/* Some sleep here */
data[1] = kmi_data_read(base);
}while((data[0] != MOUSE_DATA_ACK) && (data[1] != MOUSE_DATA_RTR));
/* Set enable data code to mouse */
kmi_mouse_enable(base);
}

View File

@@ -0,0 +1,59 @@
#ifndef __PL050_KMI_H__
#define __PL050_KMI_H__
/* Register offsets */
#define PL050_KMICR 0x00
#define PL050_KMISTAT 0x04
#define PL050_KMIDATA 0x08
#define PL050_KMICLKDIV 0x0C
#define PL050_KMIIR 0x10
/* Bit definitions for KMI control register */
#define KMI_TYPE (1 << 0x5)
#define KMI_RXINTR (1 << 0x4)
#define KMI_TXINTR (1 << 0x3)
#define KMI_EN (1 << 0x2)
#define KMI_FD (1 << 0x1)
#define KMI_FC (1 << 0x0)
/* KMI generic defines */
#define KMI_DATA_RESET 0xFF
#define KMI_DATA_RTR 0xAA
/* Keyboard special defines */
#define KYBD_DATA_RESET KMI_DATA_RESET // Keyboard reset
#define KYBD_DATA_RTR KMI_DATA_RTR // Keyboard response to reset
#define KYBD_DATA_KEYUP 0xF0 // Key up control code
#define KYBD_DATA_SHIFTL 18 // Shift key left
#define KYBD_DATA_SHIFTR 89 // Shift key right
/* Bit definitions for KMI STAT register */
#define KMI_TXEMPTY (1 << 0x6)
#define KMI_TXBUSY (1 << 0x5)
#define KMI_RXFULL (1 << 0x4)
#define KMI_RXBUSY (1 << 0x3)
#define KMI_RXPARITY (1 << 0x2)
#define KMI_CLKIN (1 << 0x1)
#define KMI_DATAIN (1 << 0x0)
/* Mouse special defines */
#define MOUSE_DATA_RESET KMI_DATA_RESET // Mouse reset
#define MOUSE_DATA_RTR KMI_DATA_RTR // Mouse response to reset
#define MOUSE_DATA_ACK 0xFA
#define MOUSE_DATA_ENABLE 0xF4 // Mouse enable
/* Common functions */
void kmi_rx_irq_enable(unsigned long base);
int kmi_data_read(unsigned long base);
/* Keyboard specific calls */
char kmi_keyboard_read(unsigned long base, struct keyboard_state *state);
void kmi_keyboard_init(unsigned long base, unsigned int div);
/* Mouse specific calls */
void kmi_mouse_enable(unsigned long base);
void kmi_mouse_init(unsigned long base, unsigned int div);
#endif /* __PL050_KMI_H__ */

View File

@@ -0,0 +1,25 @@
import sys
Import('env')
# Get global paths
PROJRELROOT = '../../../'
sys.path.append(PROJRELROOT)
from scripts.config.configuration import *
config = configuration_retrieve()
platform = config.platform
#Platforms using omap_uart
plat_list = 'beagle'
# The set of source files associated with this SConscript file.
src_local = []
#for plat_supported in plat_list:
#if plat_supported == platform:
if plat_list == platform:
src_local += ['timer.c']
obj = env.StaticObject(src_local)
Return('obj')

View File

@@ -0,0 +1,97 @@
/*
* omap GP timer driver honoring generic
* timer library API
*
* Copyright (C) 2010 B Labs Ltd.
*
* Author: Bahadir Balban
*/
#include <dev/io.h>
#include <l4lib/types.h>
#include "timer.h"
#define OMAP_TIMER_MAT_IT_FLAG (1 << 0)
#define OMAP_TIMER_OVR_IT_FLAG (1 << 1)
#define OMAP_TIMER_TCAR_IT_FLAG (1 << 2)
u32 timer_periodic_intr_status(unsigned long timer_base)
{
volatile u32 reg = read(timer_base + OMAP_TIMER_TISR);
return (reg & OMAP_TIMER_OVR_IT_FLAG);
}
#define OMAP_TIMER_SOFT_RESET (1 << 1)
void timer_reset(unsigned long timer_base)
{
/* Reset Timer */
write(OMAP_TIMER_SOFT_RESET, timer_base + OMAP_TIMER_TIOCP);
/* Wait for reset completion */
while (!read(timer_base + OMAP_TIMER_TSTAT));
}
void timer_load(unsigned long timer_base, u32 value)
{
write(value, timer_base + OMAP_TIMER_TLDR);
write(value, timer_base + OMAP_TIMER_TCRR);
}
u32 timer_read(unsigned long timer_base)
{
return read(timer_base + OMAP_TIMER_TCRR);
}
#define OMAP_TIMER_START (1 << 0)
void timer_start(unsigned long timer_base)
{
volatile u32 reg = read(timer_base + OMAP_TIMER_TCLR);
reg |= OMAP_TIMER_START;
write(reg, timer_base + OMAP_TIMER_TCLR);
}
void timer_stop(unsigned long timer_base)
{
volatile u32 reg = read(timer_base + OMAP_TIMER_TCLR);
reg &= (~OMAP_TIMER_START);
write(reg, timer_base + OMAP_TIMER_TCLR);
}
void timer_init_periodic(unsigned long timer_base)
{
volatile u32 reg;
/* Reset the timer */
timer_reset(timer_base);
/* Set timer to autoreload mode */
reg = read(timer_base + OMAP_TIMER_TCLR);
reg |= (1 << OMAP_TIMER_MODE_AUTORELAOD);
write(reg, timer_base + OMAP_TIMER_TCLR);
/*
* Beagle Board RevC manual:
* overflow period = (0xffffffff - TLDR + 1)*PS*(1/TIMER_FCLK)
* where,
* PS: Prescaler divisor (we are not using this)
*
* Beagle board manual says, 26MHz oscillator present on board.
* U-Boot divides the sys_clock by 2 if sys_clk is >19MHz,
* so,we have sys_clk frequency = 13MHz
*
* TIMER_FCLK = 13MHz
* So, for 1ms period, TLDR = 0xffffcd38
*
*/
timer_load(timer_base, 0xffffcd38);
/* Clear pending Interrupts, if any */
write(7, timer_base + OMAP_TIMER_TISR);
/* Enable inteerupts */
write((1 << OMAP_TIMER_INTR_OVERFLOW), timer_base + OMAP_TIMER_TIER);
}
void timer_init(unsigned long timer_base)
{
timer_init_periodic(timer_base);
}

View File

@@ -0,0 +1,51 @@
/*
* OMAP GP Timer offsets
*
* Copyright (C) 2007 Bahadir Balban
*
*/
#ifndef __OMAP_GPTIMER_H__
#define __OMAP_GPTIMER_H__
/* Register offsets */
#define OMAP_TIMER_TIOCP 0x10
#define OMAP_TIMER_TSTAT 0x14
#define OMAP_TIMER_TISR 0x18
#define OMAP_TIMER_TIER 0x1C
#define OMAP_TIMER_TCLR 0x24
#define OMAP_TIMER_TCRR 0x28
#define OMAP_TIMER_TLDR 0x2C
#define OMAP_TIMER_TPIR 0x48
#define OMAP_TIMER_TNIR 0x4C
#define OMAP_TIMER_TCVR 0x50
/* Enable/Disable IRQ */
#define OMAP_TIMER_IRQENABLE 1
#define OMAP_TIMER_IRQDISABLE 0
/* Timer modes supported */
#define OMAP_TIMER_MODE_AUTORELAOD 1
#define OMAP_TIMER_MODE_COMPARE 6
#define OMAP_TIMER_MODE_CAPTURE 13
/* Interrupt types */
#define OMAP_TIMER_INTR_MATCH 0x0
#define OMAP_TIMER_INTR_OVERFLOW 0x1
#define OMAP_TIMER_INTR_CAPTURE 0x2
/* Clock source for timer */
#define OMAP_TIMER_CLKSRC_SYS_CLK 0x1
#define OMAP_TIMER_CLKSRC_32KHZ_CLK 0x0
u32 timer_periodic_intr_status(unsigned long timer_base);
void timer_start(unsigned long base);
void timer_set_mode(unsigned long base, int mode);
void timer_reset(unsigned long timer_base);
void timer_load(unsigned long timer_base, u32 value);
u32 timer_read(unsigned long timer_base);
void timer_start(unsigned long timer_base);
void timer_stop(unsigned long timer_base);
void timer_init_periodic(unsigned long timer_base);
void timer_init(unsigned long timer_base);
#endif /* __OMAP_GPTIMER_H__*/

View File

@@ -0,0 +1,24 @@
import sys
Import('env')
# Get global paths
PROJRELROOT = '../../../'
sys.path.append(PROJRELROOT)
from scripts.config.configuration import *
config = configuration_retrieve()
platform = config.platform
#Platforms using sp804
plat_list = ('eb', 'pba9', 'pb926')
# The set of source files associated with this SConscript file.
src_local = []
for plat_supported in plat_list:
if plat_supported == platform:
src_local += Glob('*.c')
obj = env.StaticObject(src_local)
Return('obj')

View File

@@ -0,0 +1,68 @@
/*
* SP804 primecell driver honoring generic
* timer library API
*
* Copyright (C) 2010 B Labs Ltd.
*
* Author: Bahadir Balban
*/
#include <l4lib/types.h>
#include "timer.h"
/* Enable timer with its current configuration */
void timer_start(unsigned long timer_base)
{
volatile u32 reg = read(timer_base + SP804_CTRL);
reg |= SP804_ENABLE;
write(reg, timer_base + SP804_CTRL);
}
/* Load the timer with ticks value */
void timer_load(u32 loadval, unsigned long timer_base)
{
write(loadval, timer_base + SP804_LOAD);
}
u32 timer_read(unsigned long timer_base)
{
return read(timer_base + SP804_VALUE);
}
void timer_stop(unsigned long timer_base)
{
write(0, timer_base + SP804_CTRL);
}
void timer_init_periodic(unsigned long timer_base, u32 load_value)
{
volatile u32 reg = read(timer_base + SP804_CTRL);
reg |= SP804_PERIODIC | SP804_32BIT | SP804_IRQEN;
write(reg, timer_base + SP804_CTRL);
if (load_value)
timer_load(load_value, timer_base);
else
/* 1 tick per usec, 1 irq per msec */
timer_load(1000, timer_base);
}
void timer_init_oneshot(unsigned long timer_base)
{
volatile u32 reg = read(timer_base + SP804_CTRL);
/* One shot, 32 bits, no irqs */
reg |= SP804_32BIT | SP804_ONESHOT;
write(reg, timer_base + SP804_CTRL);
}
void timer_init(unsigned long timer_base, u32 load_value)
{
timer_stop(timer_base);
timer_init_periodic(timer_base, load_value);
}

View File

@@ -0,0 +1,63 @@
/*
* SP804 Primecell Timer offsets
*
* Copyright (C) 2007 Bahadir Balban
*
*/
#ifndef __SP804_TIMER_H__
#define __SP804_TIMER_H__
#include <dev/io.h>
/* Register offsets */
#define SP804_LOAD 0x0
#define SP804_VALUE 0x4
#define SP804_CTRL 0x8
#define SP804_INTCLR 0xC
#define SP804_RIS 0x10
#define SP804_MIS 0x14
#define SP804_BGLOAD 0x18
#define SP804_ENABLE (1 << 7)
#define SP804_PERIODIC (1 << 6)
#define SP804_IRQEN (1 << 5)
#define SP804_32BIT (1 << 1)
#define SP804_ONESHOT (1 << 0)
/* Timer prescaling */
#define SP804_SCALE_SHIFT 2
#define SP804_SCALE_DIV16 1
#define SP804_SCALE_DIV256 2
/* Wrapping = 0, Oneshot = 1 */
#define SP804_ONESHOT (1 << 0)
static inline __attribute__ ((always_inline))
void sp804_load(unsigned long timer_base, u32 val)
{
write(val, timer_base + SP804_LOAD);
}
static inline __attribute__ ((always_inline))
void sp804_irq_clear(unsigned long timer_base)
{
write(1, timer_base + SP804_INTCLR);
}
static inline __attribute__ ((always_inline))
void sp804_enable(unsigned long timer_base)
{
volatile u32 reg = read(timer_base + SP804_CTRL);
write(reg | SP804_ENABLE, timer_base + SP804_CTRL);
}
void timer_start(unsigned long timer_base);
void timer_load(u32 loadval, unsigned long timer_base);
u32 timer_read(unsigned long timer_base);
void timer_stop(unsigned long timer_base);
void timer_init_periodic(unsigned long timer_base, u32 load_value);
void timer_init_oneshot(unsigned long timer_base);
void timer_init(unsigned long timer_base, u32 load_value);
#endif /* __SP804_TIMER_H__ */

View File

@@ -0,0 +1,25 @@
import sys
Import('env')
# Get global paths
PROJRELROOT = '../../../'
sys.path.append(PROJRELROOT)
from scripts.config.configuration import *
config = configuration_retrieve()
platform = config.platform
#Platforms using omap_uart
plat_list = 'beagle'
# The set of source files associated with this SConscript file.
src_local = []
#for plat_supported in plat_list:
#if plat_supported == platform:
if plat_list == platform:
src_local += ['uart.c']
obj = env.StaticObject(src_local)
Return('obj')

View File

@@ -0,0 +1,115 @@
/*
* UART driver used by OMAP devices
*
* Copyright (C) 2007 Bahadir Balban
*/
#include <dev/uart.h>
#include <dev/io.h>
#include "uart.h"
#define OMAP_UART_TXFE 0x20
void uart_tx_char(unsigned long uart_base, char c)
{
volatile u32 reg;
/* Check if there is space for tx */
do {
reg = read(uart_base + OMAP_UART_LSR);
} while(!(reg & OMAP_UART_TXFE));
write(c, uart_base + OMAP_UART_THR);
}
#define OMAP_UART_RXFNE 0x1
#define OMAP_UART_RX_FIFO_STATUS 0x8
char uart_rx_char(unsigned long uart_base)
{
volatile u32 reg;
/* Check if pending data is there */
do {
reg = read(uart_base + OMAP_UART_LSR);
} while(!(reg & OMAP_UART_RXFNE));
#if 0
/* Check if there is some error in recieve */
if(reg & OMAP_UART_RX_FIFO_STATUS)
return -1;
#endif
return (char)read(uart_base + OMAP_UART_RHR);
}
void uart_set_baudrate(unsigned long uart_base, u32 baudrate)
{
u32 clk_div;
/* 48Mhz clock fixed on beagleboard */
const u32 clkrate = 48000000;
/* If baud out of range, set default rate */
if(baudrate > 3686400 || baudrate < 300)
baudrate = 115200;
clk_div = clkrate/(16 * baudrate);
/* Set clockrate in DLH and DLL */
write((clk_div & 0xff), uart_base + OMAP_UART_DLL);
write(((clk_div >> 8) & 0xff ), uart_base + OMAP_UART_DLH);
}
void uart_init(unsigned long uart_base)
{
/* Disable UART */
uart_select_mode(uart_base, OMAP_UART_MODE_DEFAULT);
/* Disable interrupts */
uart_disable_interrupt(uart_base);
/* Change to config mode, to set baud divisor */
uart_set_link_control(uart_base, OMAP_UART_BANKED_MODE_CONFIG_A);
/* Set the baud rate */
uart_set_baudrate(uart_base, 115200);
/* Switch to operational mode */
uart_set_link_control(uart_base, OMAP_UART_BANKED_MODE_OPERATIONAL);
/* Set up the link- parity, data bits stop bits to 8N1 */
uart_disable_parity(uart_base);
uart_set_data_bits(uart_base, OMAP_UART_DATA_BITS_8);
uart_set_stop_bits(uart_base, OMAP_UART_STOP_BITS_1);
/* Disable Fifos */
uart_disable_fifo(uart_base);
/* Enable modem Rx/Tx */
uart_enable_tx(uart_base);
uart_enable_rx(uart_base);
/* Enable UART in 16x mode */
uart_select_mode(uart_base, OMAP_UART_MODE_UART16X);
}
unsigned long uart_print_base;
void platform_init(void)
{
uart_print_base = OMAP_UART_BASE;
/*
* We dont need to initialize uart here for variant-userspace,
* as this is the same uart as used by kernel and hence
* already initialized, we just need
* a uart struct instance with proper base address.
*
* But in case of baremetal like loader, no one has done
* initialization, so we need to do it.
*/
#if defined(VARIANT_BAREMETAL)
uart_init(uart_print_base);
#endif
}

View File

@@ -0,0 +1,195 @@
/*
* OMAP UART Generic driver implementation.
*
* Copyright (C) 2007 Bahadir Balban
*
* The particular intention of this code is that it has been carefully written
* as decoupled from os-specific code and in a verbose way such that it clearly
* demonstrates how the device operates, reducing the amount of time to be spent
* for understanding the operational model and implementing a driver from
* scratch. This is the very first to be such a driver so far, hopefully it will
* turn out to be useful.
*/
#ifndef __OMAP_UART_H__
#define __OMAP_UART_H__
#include <l4/config.h> /* To get PLATFORM */
#include <l4lib/types.h>
#if defined(VARIANT_USERSPACE)
/* FIXME: Take this value in agreement from kernel, or from kernel only */
#include <l4/macros.h>
#include INC_ARCH(io.h)
#define OMAP_UART_BASE USERSPACE_CONSOLE_VBASE
#endif
#if defined(VARIANT_BAREMETAL)
#if defined(CONFIG_PLATFORM_BEAGLE)
#define OMAP_UART_BASE 0x49020000
#endif
#endif
/* Register offsets */
#define OMAP_UART_DLL 0x00
#define OMAP_UART_THR 0x00
#define OMAP_UART_RHR 0x00
#define OMAP_UART_DLH 0x04
#define OMAP_UART_IER 0x04
#define OMAP_UART_FCR 0x08
#define OMAP_UART_MCR 0x10
#define OMAP_UART_LSR 0x14
#define OMAP_UART_MDR1 0x20
#define OMAP_UART_LCR 0x0C
/* Modes supported by OMAP UART/IRDA/CIR IP */
#define OMAP_UART_MODE_UART16X 0x0
#define OMAP_UART_MODE_SIR 0x1
#define OMAP_UART_MODE_UART16X_AUTO_BAUD 0x2
#define OMAP_UART_MODE_UART13X 0x3
#define OMAP_UART_MODE_MIR 0x4
#define OMAP_UART_MODE_FIR 0x5
#define OMAP_UART_MODE_CIR 0x6
#define OMAP_UART_MODE_DEFAULT 0x7 /* Disable */
/* Number of data bits for UART */
#define OMAP_UART_DATA_BITS_5 0x0
#define OMAP_UART_DATA_BITS_6 0x1
#define OMAP_UART_DATA_BITS_7 0x2
#define OMAP_UART_DATA_BITS_8 0x3
/* Stop bits to be used for UART data */
#define OMAP_UART_STOP_BITS_1 0x0
#define OMAP_UART_STOP_BITS_1_5 0x1
/* Banked Register modes- ConfigA, ConfigB, Operational */
#define OMAP_UART_BANKED_MODE_OPERATIONAL 0x00
#define OMAP_UART_BANKED_MODE_CONFIG_A 0x80
#define OMAP_UART_BANKED_MODE_CONFIG_B 0xBF
void uart_tx_char(unsigned long uart_base, char c);
char uart_rx_char(unsigned long uart_base);
void uart_set_baudrate(unsigned long uart_base, u32 baudrate);
void uart_init(unsigned long uart_base);
#define OMAP_UART_FIFO_ENABLE (1 << 0)
#define OMAP_UART_RX_FIFO_CLR (1 << 1)
#define OMAP_UART_TX_FIFO_CLR (1 << 2)
static inline void uart_enable_fifo(unsigned long uart_base)
{
volatile u32 reg = read(uart_base + OMAP_UART_FCR);
reg |= (OMAP_UART_FIFO_ENABLE | OMAP_UART_RX_FIFO_CLR |
OMAP_UART_TX_FIFO_CLR);
write(reg, uart_base + OMAP_UART_FCR);
}
static inline void uart_disable_fifo(unsigned long uart_base)
{
volatile u32 reg= read(uart_base + OMAP_UART_FCR);
reg &= (~OMAP_UART_FIFO_ENABLE | OMAP_UART_RX_FIFO_CLR |
OMAP_UART_TX_FIFO_CLR);
write(reg, uart_base + OMAP_UART_FCR);
}
#define OMAP_UART_TX_ENABLE (1 << 0)
static inline void uart_enable_tx(unsigned long uart_base)
{
volatile u32 reg = read(uart_base + OMAP_UART_MCR);
reg |= OMAP_UART_TX_ENABLE;
write(reg, uart_base + OMAP_UART_MCR);
}
static inline void uart_disable_tx(unsigned long uart_base)
{
volatile u32 reg = read(uart_base + OMAP_UART_MCR);
reg &= ~OMAP_UART_TX_ENABLE;
write(reg, uart_base + OMAP_UART_MCR);
}
#define OMAP_UART_RX_ENABLE (1 << 1)
static inline void uart_enable_rx(unsigned long uart_base)
{
volatile u32 reg = read(uart_base + OMAP_UART_MCR);
reg |= OMAP_UART_RX_ENABLE;
write(reg, uart_base + OMAP_UART_MCR);
}
static inline void uart_disable_rx(unsigned long uart_base)
{
volatile u32 reg = read(uart_base + OMAP_UART_MCR);
reg &= ~OMAP_UART_RX_ENABLE;
write(reg, uart_base + OMAP_UART_MCR);
}
#define OMAP_UART_STOP_BITS_MASK (1 << 2)
static inline void uart_set_stop_bits(unsigned long uart_base, int bits)
{
volatile u32 reg = read(uart_base + OMAP_UART_LCR);
reg &= ~OMAP_UART_STOP_BITS_MASK;
reg |= (bits << 2);
write(reg, uart_base + OMAP_UART_LCR);
}
#define OMAP_UART_DATA_BITS_MASK (0x3)
static inline void uart_set_data_bits(unsigned long uart_base, int bits)
{
volatile u32 reg = read(uart_base + OMAP_UART_LCR);
reg &= ~OMAP_UART_DATA_BITS_MASK;
reg |= bits;
write(reg, uart_base + OMAP_UART_LCR);
}
#define OMAP_UART_PARITY_ENABLE (1 << 3)
static inline void uart_enable_parity(unsigned long uart_base)
{
volatile u32 reg = read(uart_base + OMAP_UART_LCR);
reg |= OMAP_UART_PARITY_ENABLE;
write(reg, uart_base + OMAP_UART_LCR);
}
static inline void uart_disable_parity(unsigned long uart_base)
{
volatile u32 reg = read(uart_base + OMAP_UART_LCR);
reg &= ~OMAP_UART_PARITY_ENABLE;
write(reg, uart_base + OMAP_UART_LCR);
}
#define OMAP_UART_PARITY_EVEN (1 << 4)
static inline void uart_set_even_parity(unsigned long uart_base)
{
volatile u32 reg = read(uart_base + OMAP_UART_LCR);
reg |= OMAP_UART_PARITY_EVEN;
write(reg, uart_base + OMAP_UART_LCR);
}
static inline void uart_set_odd_parity(unsigned long uart_base)
{
volatile u32 reg = read(uart_base + OMAP_UART_LCR);
reg &= ~OMAP_UART_PARITY_EVEN;
write(reg, uart_base + OMAP_UART_LCR);
}
static inline void uart_select_mode(unsigned long uart_base, int mode)
{
write(mode, uart_base + OMAP_UART_MDR1);
}
#define OMAP_UART_INTR_EN 1
static inline void uart_enable_interrupt(unsigned long uart_base)
{
write(OMAP_UART_INTR_EN, uart_base + OMAP_UART_IER);
}
static inline void uart_disable_interrupt(unsigned long uart_base)
{
write((~OMAP_UART_INTR_EN), uart_base + OMAP_UART_IER);
}
static inline void uart_set_link_control(unsigned long uart_base, int mode)
{
write(mode, uart_base + OMAP_UART_LCR);
}
#endif /* __OMAP_UART_H__ */

View File

@@ -0,0 +1,24 @@
import sys
Import('env')
# Get global paths
PROJRELROOT = '../../../'
sys.path.append(PROJRELROOT)
from scripts.config.configuration import *
config = configuration_retrieve()
platform = config.platform
#Platforms using pl011
plat_list = ('eb', 'pba9', 'pb926')
# The set of source files associated with this SConscript file.
src_local = []
for plat_supported in plat_list:
if plat_supported == platform:
src_local += Glob('*.c')
obj = env.StaticObject(src_local)
Return('obj')

View File

@@ -0,0 +1,127 @@
/*
* PL011 UART driver
*
* Copyright (C) 2009 B Labs Ltd.
*/
#include <dev/uart.h>
#include <dev/io.h>
#include "uart.h"
/* Error status bits in receive status register */
#define PL011_FE (1 << 0)
#define PL011_PE (1 << 1)
#define PL011_BE (1 << 2)
#define PL011_OE (1 << 3)
/* Status bits in flag register */
#define PL011_TXFE (1 << 7)
#define PL011_RXFF (1 << 6)
#define PL011_TXFF (1 << 5)
#define PL011_RXFE (1 << 4)
#define PL011_BUSY (1 << 3)
#define PL011_DCD (1 << 2)
#define PL011_DSR (1 << 1)
#define PL011_CTS (1 << 0)
void uart_tx_char(unsigned long base, char c)
{
unsigned int val = 0;
do {
val = read((base + PL011_UARTFR));
} while (val & PL011_TXFF); /* TX FIFO FULL */
write(c, (base + PL011_UARTDR));
}
char uart_rx_char(unsigned long base)
{
unsigned int val = 0;
do {
val = read(base + PL011_UARTFR);
} while (val & PL011_RXFE); /* RX FIFO Empty */
return (char)read((base + PL011_UARTDR));
}
/*
* Sets the baud rate in kbps. It is recommended to use
* standard rates such as: 1200, 2400, 3600, 4800, 7200,
* 9600, 14400, 19200, 28800, 38400, 57600 76800, 115200.
*/
void pl011_set_baudrate(unsigned long base, unsigned int baud,
unsigned int clkrate)
{
const unsigned int uartclk = 24000000; /* 24Mhz clock fixed on pb926 */
unsigned int val = 0, ipart = 0, fpart = 0;
/* Use default pb926 rate if no rate is supplied */
if (clkrate == 0)
clkrate = uartclk;
if (baud > 115200 || baud < 1200)
baud = 38400; /* Default rate. */
/* 24000000 / (38400 * 16) */
ipart = 39;
write(ipart, base + PL011_UARTIBRD);
write(fpart, base + PL011_UARTFBRD);
/*
* For the IBAUD and FBAUD to update, we need to
* write to UARTLCR_H because the 3 registers are
* actually part of a single register in hardware
* which only updates by a write to UARTLCR_H
*/
val = read(base + PL011_UARTLCR_H);
write(val, base + PL011_UARTLCR_H);
}
void uart_init(unsigned long uart_base)
{
/* Initialise data register for 8 bit data read/writes */
pl011_set_word_width(uart_base, 8);
/*
* Fifos are disabled because by default it is assumed the port
* will be used as a user terminal, and in that case the typed
* characters will only show up when fifos are flushed, rather than
* when each character is typed. We avoid this by not using fifos.
*/
pl011_disable_fifos(uart_base);
/* Set default baud rate of 38400 */
pl011_set_baudrate(uart_base, 38400, 24000000);
/* Set default settings of 1 stop bit, no parity, no hw flow ctrl */
pl011_set_stopbits(uart_base, 1);
pl011_parity_disable(uart_base);
/* Enable rx, tx, and uart chip */
pl011_tx_enable(uart_base);
pl011_rx_enable(uart_base);
pl011_uart_enable(uart_base);
}
unsigned long uart_print_base;
void platform_init(void)
{
uart_print_base = PL011_BASE;
/*
* We dont need to initialize uart here for variant-userspace,
* as this is the same uart as used by kernel and hence
* already initialized, we just need
* a uart struct instance with proper base address.
*
* But in case of baremetal like loader, no one has done
* initialization, so we need to do it.
*/
#if defined(VARIANT_BAREMETAL)
uart_init(uart_print_base);
#endif
}

View File

@@ -0,0 +1,249 @@
/*
* PL011 UART Generic driver implementation.
* Copyright Bahadir Balban (C) 2009
*/
#ifndef __PL011_H__
#define __PL011_H__
#include <l4/config.h> /* To get PLATFORM */
#include <dev/io.h>
#if defined(VARIANT_USERSPACE)
#include <l4/macros.h>
#include INC_ARCH(io.h)
#define PL011_BASE USERSPACE_CONSOLE_VBASE
#endif
#if defined(VARIANT_BAREMETAL)
#if defined(CONFIG_PLATFORM_PB926)
#define PL011_BASE 0x101F1000
#elif defined(CONFIG_PLATFORM_EB) || defined(CONFIG_PLATFORM_PBA9)
#define PL011_BASE 0x10009000
#endif
#endif
/* Register offsets */
#define PL011_UARTDR 0x00
#define PL011_UARTRSR 0x04
#define PL011_UARTECR 0x04
#define PL011_UARTFR 0x18
#define PL011_UARTILPR 0x20
#define PL011_UARTIBRD 0x24
#define PL011_UARTFBRD 0x28
#define PL011_UARTLCR_H 0x2C
#define PL011_UARTCR 0x30
#define PL011_UARTIFLS 0x34
#define PL011_UARTIMSC 0x38
#define PL011_UARTRIS 0x3C
#define PL011_UARTMIS 0x40
#define PL011_UARTICR 0x44
#define PL011_UARTDMACR 0x48
/* IRQ bits for each uart irq event */
#define PL011_RXIRQ (1 << 4)
#define PL011_TXIRQ (1 << 5)
#define PL011_RXTIMEOUTIRQ (1 << 6)
#define PL011_FEIRQ (1 << 7)
#define PL011_PEIRQ (1 << 8)
#define PL011_BEIRQ (1 << 9)
#define PL011_OEIRQ (1 << 10)
void pl011_set_baudrate(unsigned long base, unsigned int baud,
unsigned int clkrate);
#define PL011_UARTEN (1 << 0)
static inline void pl011_uart_enable(unsigned long base)
{
unsigned int val = 0;
val = read((base + PL011_UARTCR));
val |= PL011_UARTEN;
write(val, (base + PL011_UARTCR));
return;
}
static inline void pl011_uart_disable(unsigned long base)
{
unsigned int val = 0;
val = read((base + PL011_UARTCR));
val &= ~PL011_UARTEN;
write(val, (base + PL011_UARTCR));
return;
}
#define PL011_TXE (1 << 8)
static inline void pl011_tx_enable(unsigned long base)
{
unsigned int val = 0;
val = read((base + PL011_UARTCR));
val |= PL011_TXE;
write(val, (base + PL011_UARTCR));
return;
}
static inline void pl011_tx_disable(unsigned long base)
{
unsigned int val = 0;
val =read((base + PL011_UARTCR));
val &= ~PL011_TXE;
write(val, (base + PL011_UARTCR));
return;
}
#define PL011_RXE (1 << 9)
static inline void pl011_rx_enable(unsigned long base)
{
unsigned int val = 0;
val = read((base + PL011_UARTCR));
val |= PL011_RXE;
write(val, (base + PL011_UARTCR));
return;
}
static inline void pl011_rx_disable(unsigned long base)
{
unsigned int val = 0;
val = read((base + PL011_UARTCR));
val &= ~PL011_RXE;
write(val, (base + PL011_UARTCR));
return;
}
#define PL011_TWO_STOPBITS_SELECT (1 << 3)
static inline void pl011_set_stopbits(unsigned long base, int stopbits)
{
unsigned int val = 0;
val = read((base + PL011_UARTLCR_H));
if(stopbits == 2) { /* Set to two bits */
val |= PL011_TWO_STOPBITS_SELECT;
} else { /* Default is 1 */
val &= ~PL011_TWO_STOPBITS_SELECT;
}
write(val, (base + PL011_UARTLCR_H));
return;
}
#define PL011_PARITY_ENABLE (1 << 1)
static inline void pl011_parity_enable(unsigned long base)
{
unsigned int val = 0;
val = read((base +PL011_UARTLCR_H));
val |= PL011_PARITY_ENABLE;
write(val, (base + PL011_UARTLCR_H));
return;
}
static inline void pl011_parity_disable(unsigned long base)
{
unsigned int val = 0;
val = read((base + PL011_UARTLCR_H));
val &= ~PL011_PARITY_ENABLE;
write(val, (base + PL011_UARTLCR_H));
return;
}
#define PL011_PARITY_EVEN (1 << 2)
static inline void pl011_set_parity_even(unsigned long base)
{
unsigned int val = 0;
val = read((base + PL011_UARTLCR_H));
val |= PL011_PARITY_EVEN;
write(val, (base + PL011_UARTLCR_H));
return;
}
static inline void pl011_set_parity_odd(unsigned long base)
{
unsigned int val = 0;
val = read((base + PL011_UARTLCR_H));
val &= ~PL011_PARITY_EVEN;
write(val, (base + PL011_UARTLCR_H));
return;
}
#define PL011_ENABLE_FIFOS (1 << 4)
static inline void pl011_enable_fifos(unsigned long base)
{
unsigned int val = 0;
val = read((base + PL011_UARTLCR_H));
val |= PL011_ENABLE_FIFOS;
write(val, (base + PL011_UARTLCR_H));
return;
}
static inline void pl011_disable_fifos(unsigned long base)
{
unsigned int val = 0;
val = read((base + PL011_UARTLCR_H));
val &= ~PL011_ENABLE_FIFOS;
write(val, (base + PL011_UARTLCR_H));
return;
}
/* Sets the transfer word width for the data register. */
static inline void pl011_set_word_width(unsigned long base, int size)
{
unsigned int val = 0;
if(size < 5 || size > 8) /* Default is 8 */
size = 8;
/* Clear size field */
val = read((base + PL011_UARTLCR_H));
val &= ~(0x3 << 5);
write(val, (base + PL011_UARTLCR_H));
/*
* The formula is to write 5 less of size given:
* 11 = 8 bits
* 10 = 7 bits
* 01 = 6 bits
* 00 = 5 bits
*/
val = read((base + PL011_UARTLCR_H));
val |= (size - 5) << 5;
write(val, (base + PL011_UARTLCR_H));
return;
}
/*
* Defines at which level of fifo fullness an irq will be generated.
* @xfer: tx fifo = 0, rx fifo = 1
* @level: Generate irq if:
* 0 rxfifo >= 1/8 full txfifo <= 1/8 full
* 1 rxfifo >= 1/4 full txfifo <= 1/4 full
* 2 rxfifo >= 1/2 full txfifo <= 1/2 full
* 3 rxfifo >= 3/4 full txfifo <= 3/4 full
* 4 rxfifo >= 7/8 full txfifo <= 7/8 full
* 5-7 reserved reserved
*/
static inline void pl011_set_irq_fifolevel(unsigned long base, \
unsigned int xfer, unsigned int level)
{
if(xfer != 1 && xfer != 0) /* Invalid fifo */
return;
if(level > 4) /* Invalid level */
return;
write(level << (xfer * 3), (base + PL011_UARTIFLS));
return;
}
#endif /* __PL011__UART__ */

View File

@@ -0,0 +1,47 @@
# -*- mode: python; coding: utf-8; -*-
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
# 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 3 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, see
# <http://www.gnu.org/licenses/>.
#
# Author: Russel Winder
import os, sys
Import('env')
PROJRELROOT = '../../..'
sys.path.append(PROJRELROOT)
from scripts.config.projpaths import *
from scripts.config.configuration import *
config = configuration_retrieve()
arch = config.arch
subarch = config.subarch
e = env.Clone()
e.Append(CPPPATH = ['include', 'include/l4lib/arch', LIBMEM_INCLUDE],
CPPFLAGS = ' -include l4lib/macros.h ')
objects = e.StaticObject(Glob('src/*.c') + \
Glob('src/lib/*.c') + \
Glob('src/lib/cap/*.c')) + \
Glob('src/lib/thread/*.c') + \
Glob('src/arch/' + arch + '/exregs.c') + \
Glob('src/arch/' + arch + '/*.S') + \
Glob('src/arch/' + arch + '/' + subarch + '/*.[cS]')
library = e.StaticLibrary('l4', objects)
Return('library')

View File

@@ -0,0 +1,31 @@
# -*- mode: python; coding: utf-8; -*-
#
# Codezero -- a microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
import os, sys
PROJRELROOT = '../../..'
sys.path.append(PROJRELROOT)
from scripts.config.projpaths import *
from scripts.config.configuration import *
config = configuration_retrieve()
gcc_arch_flag = config.gcc_arch_flag
builddir = join(BUILDDIR, LIBL4_RELDIR)
VariantDir(builddir, os.getcwd(), 0)
env = Environment(CC = config.toolchain_userspace + 'gcc',
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99',
'-nostdinc', '-Wall', '-Werror', '-march=' + gcc_arch_flag],
LINKFLAGS = ['-nostdlib'],
ASFLAGS = ['-D__ASSEMBLY__', '-march=' + gcc_arch_flag],
ENV = {'PATH' : os.environ['PATH']},
CPPPATH = ['#include', LIBC_INCLUDE, KERNEL_HEADERS, LIBMEM_INCLUDE],
CPPFLAGS = ' -include l4lib/macros.h ')
objects = SConscript('SConscript', exports = { 'env' : env }, duplicate=0, build_dir = builddir)

View File

@@ -0,0 +1,15 @@
#ifndef __ARM_ASM_H__
#define __ARM_ASM_H__
#define BEGIN_PROC(name) \
.global name; \
.type name,function; \
.align; \
name:
#define END_PROC(name) \
.fend_##name: \
.size name,.fend_##name - name;
#endif /* __ARM_ASM_H__ */

View File

@@ -0,0 +1,11 @@
#ifndef __L4LIB_ARCH_IRQ_H__
#define __L4LIB_ARCH_IRQ_H__
/*
* Destructive atomic-read.
*
* Write 0 to byte at @location as its contents are read back.
*/
char l4_atomic_dest_readb(void *location);
#endif

View File

@@ -0,0 +1,95 @@
/*
* System call prototypes.
*
* Copyright (C) 2007 Bahadir Balban
*/
#ifndef __ARM_SYSCALLS_H__
#define __ARM_SYSCALLS_H__
#include L4LIB_INC_ARCH(types.h)
#include L4LIB_INC_ARCH(utcb.h)
#include <l4/generic/space.h>
#include <l4/api/space.h>
#include <l4/api/kip.h>
#include <l4/api/ipc.h>
#include <l4/api/thread.h>
struct task_ids {
l4id_t tid;
l4id_t spid;
l4id_t tgid;
};
static inline void *
l4_kernel_interface(unsigned int *api_version, unsigned int *api_flags,
unsigned int *kernel_id)
{
return (void *)L4_KIP_ADDRESS;
}
typedef unsigned int (*__l4_thread_switch_t)(u32);
extern __l4_thread_switch_t __l4_thread_switch;
unsigned int l4_thread_switch (u32 dest);
typedef int (*__l4_getid_t)(struct task_ids *ids);
extern __l4_getid_t __l4_getid;
int l4_getid(struct task_ids *ids);
typedef int (*__l4_ipc_t)(l4id_t to, l4id_t from, u32 flags);
extern __l4_ipc_t __l4_ipc;
int l4_ipc(l4id_t to, l4id_t from, u32 flags);
typedef int (*__l4_capability_control_t)(unsigned int req, unsigned int flags, void *buf);
extern __l4_capability_control_t __l4_capability_control;
int l4_capability_control(unsigned int req, unsigned int flags, void *buf);
typedef int (*__l4_map_t)(void *phys, void *virt,
u32 npages, u32 flags, l4id_t tid);
extern __l4_map_t __l4_map;
int l4_map(void *p, void *v, u32 npages, u32 flags, l4id_t tid);
typedef int (*__l4_unmap_t)(void *virt, unsigned long npages, l4id_t tid);
extern __l4_unmap_t __l4_unmap;
int l4_unmap(void *virtual, unsigned long numpages, l4id_t tid);
typedef int (*__l4_thread_control_t)(unsigned int action, struct task_ids *ids);
extern __l4_thread_control_t __l4_thread_control;
int l4_thread_control(unsigned int action, struct task_ids *ids);
typedef int (*__l4_irq_control_t)(unsigned int req, unsigned int flags, l4id_t id);
extern __l4_irq_control_t __l4_irq_control;
int l4_irq_control(unsigned int req, unsigned int flags, l4id_t id);
typedef int (*__l4_ipc_control_t)(unsigned int action, l4id_t blocked_sender,
u32 blocked_tag);
extern __l4_ipc_control_t __l4_ipc_control;
int l4_ipc_control(unsigned int, l4id_t blocked_sender, u32 blocked_tag);
typedef int (*__l4_exchange_registers_t)(void *exregs_struct, l4id_t tid);
extern __l4_exchange_registers_t __l4_exchange_registers;
int l4_exchange_registers(void *exregs_struct, l4id_t tid);
typedef int (*__l4_container_control_t)(unsigned int req, unsigned int flags, void *buf);
extern __l4_container_control_t __l4_container_control;
int l4_container_control(unsigned int req, unsigned int flags, void *buf);
typedef int (*__l4_time_t)(void *timeval, int set);
extern __l4_time_t __l4_time;
int l4_time(void *timeval, int set);
typedef int (*__l4_mutex_control_t)(void *mutex_word, int op);
extern __l4_mutex_control_t __l4_mutex_control;
int l4_mutex_control(void *mutex_word, int op);
typedef int (*__l4_cache_control_t)(void *start, void *end, unsigned int flags);
extern __l4_cache_control_t __l4_cache_control;
int l4_cache_control(void *start, void *end, unsigned int flags);
/* To be supplied by server tasks. */
void *virt_to_phys(void *);
void *phys_to_virt(void *);
#endif /* __ARM_SYSCALLS_H__ */

View File

@@ -0,0 +1,366 @@
/*
* Helper functions that wrap raw l4 syscalls.
*
* Copyright (C) 2007-2009 Bahadir Bilgehan Balban
*/
#ifndef __L4LIB_SYSLIB_H__
#define __L4LIB_SYSLIB_H__
#include <stdio.h>
#include <l4/macros.h>
#include L4LIB_INC_ARCH(syscalls.h)
/*
* NOTE:
* Its best to use these wrappers because they generalise the way
* common ipc data like sender id, error, ipc tag are passed
* between ipc parties.
*
* The arguments to l4_ipc() are used by the microkernel to initiate
* the ipc. Any data passed in message registers may or may not be
* a duplicate of this data, but the distinction is that anything
* that is passed via the mrs are meant to be used by the other party
* participating in the ipc.
*/
/* For system call arguments */
#define L4SYS_ARG0 (MR_UNUSED_START)
#define L4SYS_ARG1 (MR_UNUSED_START + 1)
#define L4SYS_ARG2 (MR_UNUSED_START + 2)
#define L4SYS_ARG3 (MR_UNUSED_START + 3)
#define L4_IPC_TAG_MASK 0x00000FFF
/*
* Servers get sender.
*/
static inline l4id_t l4_get_sender(void)
{
return (l4id_t)read_mr(MR_SENDER);
}
/*
* When doing an ipc the sender never has to be explicitly set in
* the utcb via this function since this information is found out
* by the microkernel by checking the system caller's id. This is
* only used for restoring the sender on the utcb in order to
* complete an earlier ipc.
*/
static inline void l4_set_sender(l4id_t sender)
{
write_mr(MR_SENDER, sender);
}
static inline unsigned int l4_set_ipc_size(unsigned int word, unsigned int size)
{
word &= ~L4_IPC_FLAGS_SIZE_MASK;
word |= ((size << L4_IPC_FLAGS_SIZE_SHIFT) & L4_IPC_FLAGS_SIZE_MASK);
return word;
}
static inline unsigned int l4_get_ipc_size(unsigned int word)
{
return (word & L4_IPC_FLAGS_SIZE_MASK) >> L4_IPC_FLAGS_SIZE_SHIFT;
}
static inline unsigned int l4_set_ipc_msg_index(unsigned int word, unsigned int index)
{
/* FIXME: Define MR_PRIMARY_TOTAL, MR_TOTAL etc. and use MR_TOTAL HERE! */
BUG_ON(index > UTCB_SIZE);
word &= ~L4_IPC_FLAGS_MSG_INDEX_MASK;
word |= (index << L4_IPC_FLAGS_MSG_INDEX_SHIFT) &
L4_IPC_FLAGS_MSG_INDEX_MASK;
return word;
}
static inline unsigned int l4_get_ipc_msg_index(unsigned int word)
{
return (word & L4_IPC_FLAGS_MSG_INDEX_MASK)
>> L4_IPC_FLAGS_MSG_INDEX_SHIFT;
}
static inline unsigned int l4_set_ipc_flags(unsigned int word, unsigned int flags)
{
word &= ~L4_IPC_FLAGS_TYPE_MASK;
word |= flags & L4_IPC_FLAGS_TYPE_MASK;
return word;
}
static inline unsigned int l4_get_ipc_flags(unsigned int word)
{
return word & L4_IPC_FLAGS_TYPE_MASK;
}
static inline unsigned int l4_get_tag(void)
{
return read_mr(MR_TAG) & L4_IPC_TAG_MASK;
}
static inline void l4_set_tag(unsigned int tag)
{
unsigned int tag_flags = read_mr(MR_TAG);
tag_flags &= ~L4_IPC_TAG_MASK;
tag_flags |= tag & L4_IPC_TAG_MASK;
write_mr(MR_TAG, tag_flags);
}
/* Servers:
* Sets the message register for returning errors back to client task.
* These are usually posix error codes.
*/
static inline void l4_set_retval(int retval)
{
write_mr(MR_RETURN, retval);
}
/* Clients:
* Learn result of request.
*/
static inline int l4_get_retval(void)
{
return read_mr(MR_RETURN);
}
/*
* This is useful for stacked IPC. A stacked IPC happens
* when a new IPC is initiated before concluding the current
* one.
*
* This saves the last ipc's parameters such as the sender
* and tag information. Any previously saved data in save
* slots are destroyed. This is fine as IPC stacking is only
* useful if done once.
*/
static inline void l4_save_ipcregs(void)
{
l4_get_utcb()->saved_sender = l4_get_sender();
l4_get_utcb()->saved_tag = l4_get_tag();
}
static inline void l4_restore_ipcregs(void)
{
l4_set_tag(l4_get_utcb()->saved_tag);
l4_set_sender(l4_get_utcb()->saved_sender);
}
#define TASK_CID_MASK 0xFF000000
#define TASK_ID_MASK 0x00FFFFFF
#define TASK_CID_SHIFT 24
static inline l4id_t __raw_tid(l4id_t tid)
{
return tid & TASK_ID_MASK;
}
static inline l4id_t __cid(l4id_t tid)
{
return (tid & TASK_CID_MASK) >> TASK_CID_SHIFT;
}
static inline l4id_t self_tid(void)
{
struct task_ids ids;
l4_getid(&ids);
return ids.tid;
}
static inline l4id_t __raw_self_tid(void)
{
return __raw_tid(self_tid());
}
static inline int l4_send_full(l4id_t to, unsigned int tag)
{
l4_set_tag(tag);
return l4_ipc(to, L4_NILTHREAD, L4_IPC_FLAGS_FULL);
}
static inline int l4_receive_full(l4id_t from)
{
return l4_ipc(L4_NILTHREAD, from, L4_IPC_FLAGS_FULL);
}
static inline int l4_sendrecv_full(l4id_t to, l4id_t from, unsigned int tag)
{
int err;
BUG_ON(to == L4_NILTHREAD || from == L4_NILTHREAD);
l4_set_tag(tag);
err = l4_ipc(to, from, L4_IPC_FLAGS_FULL);
return err;
}
static inline int l4_send_extended(l4id_t to, unsigned int tag,
unsigned int size, void *buf)
{
unsigned int flags = 0;
l4_set_tag(tag);
/* Set up flags word for extended ipc */
flags = l4_set_ipc_flags(flags, L4_IPC_FLAGS_EXTENDED);
flags = l4_set_ipc_size(flags, size);
flags = l4_set_ipc_msg_index(flags, L4SYS_ARG0);
/* Write buffer pointer to MR index that we specified */
write_mr(L4SYS_ARG0, (unsigned long)buf);
return l4_ipc(to, L4_NILTHREAD, flags);
}
static inline int l4_receive_extended(l4id_t from, unsigned int size, void *buf)
{
unsigned int flags = 0;
/* Indicate extended receive */
flags = l4_set_ipc_flags(flags, L4_IPC_FLAGS_EXTENDED);
/* How much data is accepted */
flags = l4_set_ipc_size(flags, size);
/* Indicate which MR index buffer pointer is stored */
flags = l4_set_ipc_msg_index(flags, L4SYS_ARG0);
/* Set MR with buffer to receive data */
write_mr(L4SYS_ARG0, (unsigned long)buf);
return l4_ipc(L4_NILTHREAD, from, flags);
}
/*
* Return result value as extended IPC.
*
* Extended IPC copies up to 2KB user address space buffers.
* Along with such an ipc, a return value is sent using a primary
* mr that is used as the return register.
*
* It may not be desirable to return a payload on certain conditions,
* (such as an error return value) So a nopayload field is provided.
*/
static inline int l4_return_extended(int retval, unsigned int size,
void *buf, int nopayload)
{
unsigned int flags = 0;
l4id_t sender = l4_get_sender();
l4_set_retval(retval);
/* Set up flags word for extended ipc */
flags = l4_set_ipc_flags(flags, L4_IPC_FLAGS_EXTENDED);
flags = l4_set_ipc_msg_index(flags, L4SYS_ARG0);
/* Write buffer pointer to MR index that we specified */
write_mr(L4SYS_ARG0, (unsigned long)buf);
if (nopayload)
flags = l4_set_ipc_size(flags, 0);
else
flags = l4_set_ipc_size(flags, size);
return l4_ipc(sender, L4_NILTHREAD, flags);
}
static inline int l4_sendrecv_extended(l4id_t to, l4id_t from,
unsigned int tag, void *buf)
{
/* Need to imitate sendrecv but with extended send/recv flags */
return 0;
}
static inline int l4_send(l4id_t to, unsigned int tag)
{
l4_set_tag(tag);
return l4_ipc(to, L4_NILTHREAD, 0);
}
static inline int l4_sendrecv(l4id_t to, l4id_t from, unsigned int tag)
{
int err;
BUG_ON(to == L4_NILTHREAD || from == L4_NILTHREAD);
l4_set_tag(tag);
err = l4_ipc(to, from, 0);
return err;
}
static inline int l4_receive(l4id_t from)
{
return l4_ipc(L4_NILTHREAD, from, 0);
}
static inline void l4_print_mrs()
{
printf("Message registers: 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
read_mr(0), read_mr(1), read_mr(2), read_mr(3),
read_mr(4), read_mr(5));
}
/* Servers:
* Return the ipc result back to requesting task.
*/
static inline int l4_ipc_return(int retval)
{
l4id_t sender = l4_get_sender();
l4_set_retval(retval);
/* Setting the tag would overwrite retval so we l4_send without tagging */
return l4_ipc(sender, L4_NILTHREAD, 0);
}
void *l4_new_virtual(int npages);
void *l4_del_virtual(void *virt, int npages);
/* A helper that translates and maps a physical address to virtual */
static inline void *l4_map_helper(void *phys, int npages)
{
struct task_ids ids;
int err;
void *virt = l4_new_virtual(npages);
l4_getid(&ids);
if ((err = l4_map(phys, virt, npages,
MAP_USR_DEFAULT, ids.tid)) < 0)
return PTR_ERR(err);
return virt;
}
/* A helper that translates and maps a physical address to virtual */
static inline void *l4_unmap_helper(void *virt, int npages)
{
struct task_ids ids;
l4_getid(&ids);
l4_unmap(virt, npages, ids.tid);
l4_del_virtual(virt, npages);
return 0;
}
#define L4_EXIT_MASK 0xFFFF
static inline void l4_exit(unsigned int exit_code)
{
struct task_ids ids;
l4_getid(&ids);
l4_thread_control(THREAD_DESTROY |
(exit_code & L4_EXIT_MASK),
&ids);
}
#endif /* __L4LIB_SYSLIB_H__ */

View File

@@ -0,0 +1,8 @@
#ifndef __L4LIB_ARM_TYPES_H___
#define __L4LIB_ARM_TYPES_H__
#define TASK_ID_INVALID 0xFFFFFFFF
#include <l4/arch/arm/types.h>
#endif /* __L4LIB_ARM_TYPES_H__ */

View File

@@ -0,0 +1,78 @@
/*
* Copyright (C) 2009 Bahadir Bilgehan Balban
*/
#ifndef __ARM_UTCB_H__
#define __ARM_UTCB_H__
#define USER_UTCB_REF 0xFF000050
#define L4_KIP_ADDRESS 0xFF000000
#define UTCB_KIP_OFFSET 0x50
#ifndef __ASSEMBLY__
#include <l4lib/types.h>
#include <l4/macros.h>
#include <l4/lib/math.h>
#include INC_GLUE(message.h)
#include INC_GLUE(memory.h)
#include <string.h>
#include <stdio.h>
#include L4LIB_INC_SUBARCH(utcb.h)
/*
* See kernel glue/arch/message.h for utcb details
*/
extern struct kip *kip;
/* Functions to read/write utcb registers */
static inline unsigned int read_mr(int offset)
{
if (offset < MR_TOTAL)
return l4_get_utcb()->mr[offset];
else
return l4_get_utcb()->mr_rest[offset - MR_TOTAL];
}
static inline void write_mr(unsigned int offset, unsigned int val)
{
if (offset < MR_TOTAL)
l4_get_utcb()->mr[offset] = val;
else
l4_get_utcb()->mr_rest[offset - MR_TOTAL] = val;
}
static inline void *utcb_full_buffer()
{
return &l4_get_utcb()->mr_rest[0];
}
static inline char *utcb_full_strcpy_from(const char *src)
{
return strncpy((char *)&l4_get_utcb()->mr_rest[0], src,
L4_UTCB_FULL_BUFFER_SIZE);
}
static inline void *utcb_full_memcpy_from(const char *src, int size)
{
return memcpy(&l4_get_utcb()->mr_rest[0], src,
min(size, L4_UTCB_FULL_BUFFER_SIZE));
}
static inline char *utcb_full_strcpy_to(char *dst)
{
return strncpy(dst, (char *)&l4_get_utcb()->mr_rest[0],
L4_UTCB_FULL_BUFFER_SIZE);
}
static inline void *utcb_full_memcpy_to(char *dst, int size)
{
return memcpy(dst, &l4_get_utcb()->mr_rest[0],
min(size, L4_UTCB_FULL_BUFFER_SIZE));
}
#endif /* !__ASSEMBLY__ */
#endif /* __ARM_UTCB_H__ */

View File

@@ -0,0 +1,3 @@
#ifndef __PERFMON_H__
#endif

View File

@@ -0,0 +1,21 @@
#ifndef __ARM_V5_UTCB_H__
#define __ARM_V5_UTCB_H__
/*
* Pointer to Kernel Interface Page's UTCB pointer offset.
*/
extern struct utcb **kip_utcb_ref;
static inline struct utcb *l4_get_utcb()
{
/*
* By double dereferencing, we get the private TLS
* (aka UTCB). First reference is to the KIP's utcb
* offset, second is to the utcb itself, to which
* the KIP's utcb reference had been updated during
* context switch.
*/
return *kip_utcb_ref;
}
#endif /* __ARM_V5_UTCB_H__ */

View File

@@ -0,0 +1,405 @@
/*
* ARMv7 Performance Monitor operations
*
* Copyright (C) 2010 B Labs Ltd.
*
* Author: Bahadir Balban
*/
#ifndef __PERFMON_H__
#define __PERFMON_H__
#include <l4lib/types.h>
/* Perfmon control register */
#define PMCR_DP_BIT 5 /* Disable prohibited */
#define PMCR_X_BIT 4 /* Export event enable */
#define PMCR_D_BIT 3 /* 64-cycle granularity */
#define PMCR_C_BIT 2 /* PMCCNTR reset */
#define PMCR_P_BIT 1 /* Events all reset */
#define PMCR_E_BIT 0 /* Enable all */
/* Obtain number of event counters */
#define PMCR_N_SHIFT 11
#define PMCR_N_MASK 0x1F
/* Special bit for cycle counter */
#define PMCCNTR_BIT 31
/*
* Performance Events
*/
/* Generic v7 events */
#define PERFMON_EVENT_SOFTINC 0
#define PERFMON_EVENT_IFETCH_L1CREFILL 1
#define PERFMON_EVENT_IFETCH_TLBREFILL 2
#define PERFMON_EVENT_DFETCH_L1CREFILL 3
#define PERFMON_EVENT_DFETCH_L1CACCESS 4
#define PERFMON_EVENT_DFETCH_TLBREFILL 5
#define PERFMON_EVENT_MEMREAD_INSTR 6
#define PERFMON_EVENT_MEMWRITE_INSTR 7
#define PERFMON_EVENT_ALL_INSTR 8
#define PERFMON_EVENT_EXCEPTION 9
#define PERFMON_EVENT_EXCEPTION_RETURN 10
#define PERFMON_EVENT_CONTEXTIDR_CHANGE 11
#define PERFMON_EVENT_PC_CHANGE 12
#define PERFMON_EVENT_IMM_BRANCH 13
#define PERFMON_EVENT_FUNCTION_RETURN 14
#define PERFMON_EVENT_UNALIGNED_ACCESS 15
#define PERFMON_EVENT_BRANCH_MISS 16
#define PERFMON_EVENT_RAW_CYCLE_COUNT 17
#define PERFMON_EVENT_BRANCH_MAYBEHIT 18
/*
* Cortex-A9 events (only relevant ones)
* 0x40-2, 0x6E, 0x70, 0x71-4, 0x80-0x81, 0x8A-8B
* 0xA0-5 omitted
*/
/*
* Linefill not satisfied from other cpu caches but
* has to go to external memory
*/
#define PERFMON_EVENT_SMP_LINEFILL_MISS 0x50
/* Linefill satisfied from other cpu caches */
#define PERFMON_EVENT_SMP_LINEFILL_HIT 0x51
/* Icache refill stall cycles on cpu pipeline */
#define PERFMON_EVENT_ICACHE_CPU_STALL 0x60
/* Dcache refill stall cycles on cpu pipeline */
#define PERFMON_EVENT_DCACHE_CPU_STALL 0x61
/* TLB miss stall cycles on cpu pipeline */
#define PERFMON_EVENT_TLBMISS_CPU_STALL 0x62
#define PERFMON_EVENT_STREX_SUCCESS 0x63
#define PERFMON_EVENT_STREX_FAIL 0x64
#define PERFMON_EVENT_DCACHE_EVICTION 0x65
/* Issue stage can't proceed to dispatch any instruction */
#define PERFMON_EVENT_PIPELINE_CANT_ISSUE 0x66
/* Issue stage empty */
#define PERFMON_EVENT_PIPELINE_ISSUE_EMPTY 0x67
/* Register renamed instructions */
#define PERFMON_EVENT_REGRENAMED_INSTR 0x68
#define PERFMON_EVENT_CPUSTALL_ITLB_MISS 0x82
#define PERFMON_EVENT_CPUSTALL_DTLB_MISS 0x83
#define PERFMON_EVENT_CPUSTALL_IUTLB_MISS 0x84
#define PERFMON_EVENT_CPUSTALL_DUTLB_MISS 0x85
#define PERFMON_EVENT_CPUSTALL_DMB 0x86
#define PERFMON_EVENT_ISB_COUNT 0x90
#define PERFMON_EVENT_DSB_COUNT 0x91
#define PERFMON_EVENT_DMB_COUNT 0x92
#define PERFMON_EVENT_EXTIRQ_COUNT 0x93
static inline u32 __attribute__((always_inline))
cp15_read_perfmon_ctrl(void)
{
volatile u32 val = 0;
__asm__ __volatile__ (
"mrc p15, 0, %0, c9, c12, 0\n"
"isb\n"
: "=r" (val)
:
);
return val;
}
static inline void __attribute__((always_inline))
cp15_write_perfmon_ctrl(volatile u32 word)
{
__asm__ __volatile__ (
"mcr p15, 0, %0, c9, c12, 0"
:
: "r" (word)
);
}
static inline u32 __attribute__((always_inline))
cp15_read_perfmon_cntenset(void)
{
volatile u32 val = 0;
__asm__ __volatile__ (
"mrc p15, 0, %0, c9, c12, 1\n"
"isb\n"
: "=r" (val)
:
);
return val;
}
static inline void __attribute__((always_inline))
cp15_write_perfmon_cntenset(volatile u32 word)
{
__asm__ __volatile__ (
"mcr p15, 0, %0, c9, c12, 1"
:
: "r" (word)
);
}
static inline u32 __attribute__((always_inline))
cp15_read_perfmon_cntenclr(void)
{
u32 val = 0;
__asm__ __volatile__ (
"mrc p15, 0, %0, c9, c12, 2"
: "=r" (val)
:
);
return val;
}
static inline void __attribute__((always_inline))
cp15_write_perfmon_cntenclr(volatile u32 word)
{
__asm__ __volatile__ (
"mcr p15, 0, %0, c9, c12, 2"
:
: "r" (word)
);
}
static inline u32 __attribute__((always_inline))
cp15_read_perfmon_overflow(void)
{
u32 val = 0;
__asm__ __volatile__ (
"mrc p15, 0, %0, c9, c12, 3"
: "=r" (val)
:
);
return val;
}
static inline void __attribute__((always_inline))
cp15_write_perfmon_overflow(volatile u32 word)
{
__asm__ __volatile__ (
"mcr p15, 0, %0, c9, c12, 3"
:
: "r" (word)
);
}
static inline void __attribute__((always_inline))
cp15_write_perfmon_softinc(volatile u32 word)
{
__asm__ __volatile__ (
"mcr p15, 0, %0, c9, c12, 4"
:
: "r" (word)
);
}
static inline u32 __attribute__((always_inline))
cp15_read_perfmon_evcntsel(void)
{
u32 val = 0;
__asm__ __volatile__ (
"mrc p15, 0, %0, c9, c12, 5"
: "=r" (val)
:
);
return val;
}
static inline void __attribute__((always_inline))
cp15_write_perfmon_evcntsel(volatile u32 word)
{
__asm__ __volatile__ (
"mcr p15, 0, %0, c9, c12, 5"
:
: "r" (word)
);
}
static inline u32 __attribute__((always_inline))
cp15_read_perfmon_cyccnt(void)
{
volatile u32 val = 0;
__asm__ __volatile__ (
"mrc p15, 0, %0, c9, c13, 0\n"
"isb\n"
: "=r" (val)
:
);
return val;
}
static inline void __attribute__((always_inline))
cp15_write_perfmon_cyccnt(volatile u32 word)
{
__asm__ __volatile__ (
"mcr p15, 0, %0, c9, c13, 0"
:
: "r" (word)
);
}
static inline u32 __attribute__((always_inline))
cp15_read_perfmon_evtypesel(void)
{
u32 val = 0;
__asm__ __volatile__ (
"mrc p15, 0, %0, c9, c13, 1"
: "=r" (val)
:
);
return val;
}
static inline void __attribute__((always_inline))
cp15_write_perfmon_evtypesel(volatile u32 word)
{
__asm__ __volatile__ (
"mcr p15, 0, %0, c9, c13, 1"
:
: "r" (word)
);
}
static inline u32 __attribute__((always_inline))
cp15_read_perfmon_evcnt(void)
{
u32 val = 0;
__asm__ __volatile__ (
"mrc p15, 0, %0, c9, c13, 2"
: "=r" (val)
:
);
return val;
}
static inline void __attribute__((always_inline))
cp15_write_perfmon_evcnt(volatile u32 word)
{
__asm__ __volatile__ (
"mcr p15, 0, %0, c9, c13, 2"
:
: "r" (word)
);
}
static inline u32 __attribute__((always_inline))
cp15_read_perfmon_useren(void)
{
u32 val = 0;
__asm__ __volatile__ (
"mrc p15, 0, %0, c9, c14, 0"
: "=r" (val)
:
);
return val;
}
static inline void __attribute__((always_inline))
cp15_write_perfmon_useren(volatile u32 word)
{
__asm__ __volatile__ (
"mcr p15, 0, %0, c9, c14, 0"
:
: "r" (word)
);
}
static inline u32 __attribute__((always_inline))
cp15_read_perfmon_intenset(void)
{
u32 val = 0;
__asm__ __volatile__ (
"mrc p15, 0, %0, c9, c14, 1"
: "=r" (val)
:
);
return val;
}
static inline void __attribute__((always_inline))
cp15_write_perfmon_intenset(volatile u32 word)
{
__asm__ __volatile__ (
"mcr p15, 0, %0, c9, c14, 1"
:
: "r" (word)
);
}
static inline u32 __attribute__((always_inline))
cp15_read_perfmon_intenclr(void)
{
u32 val = 0;
__asm__ __volatile__ (
"mrc p15, 0, %0, c9, c14, 2"
: "=r" (val)
:
);
return val;
}
static inline void __attribute__((always_inline))
cp15_write_perfmon_intenclr(volatile u32 word)
{
__asm__ __volatile__ (
"mcr p15, 0, %0, c9, c14, 2"
:
: "r" (word)
);
}
#include <stdio.h>
#if defined (CONFIG_DEBUG_PERFMON_USER)
static inline
u32 perfmon_read_cyccnt()
{
u32 cnt = cp15_read_perfmon_cyccnt();
u32 ovfl = cp15_read_perfmon_overflow();
/* Detect overflow and signal something was wrong */
if (ovfl & (1 << PMCCNTR_BIT))
printf("%s: Overflow.\n", __FUNCTION__);
return cnt;
}
void perfmon_reset_start_cyccnt();
u32 perfmon_read_reset_start_cyccnt();
#endif
void perfmon_init();
#endif /* __PERFMON_H__ */

View File

@@ -0,0 +1,59 @@
#ifndef __ARM_V5_UTCB_H__
#define __ARM_V5_UTCB_H__
/*
* NOTE: Any changes you make here, you *MUST* change
* utcb_address() macro in syscall.S assembler.
*/
/* Read Thread ID User RW register */
static inline u32 l4_cp15_read_tid_usr_rw(void)
{
volatile u32 val;
__asm__ __volatile__ (
"mrc p15, 0, %0, c13, c0, 2"
: "=r" (val)
:
);
return val;
}
/* Write Thread ID User RW register */
static inline void l4_cp15_write_tid_usr_rw(volatile u32 val)
{
__asm__ __volatile__ (
"mcr p15, 0, %0, c13, c0, 2"
:
: "r" (val)
);
}
/* Read Thread ID User RO register */
static inline u32 l4_cp15_read_tid_usr_ro(void)
{
volatile u32 val;
__asm__ __volatile__ (
"mrc p15, 0, %0, c13, c0, 3"
: "=r" (val)
:
);
return val;
}
/*
* In ARMv7, utcb resides in the userspace read-only
* thread register. This adds the benefit of avoiding
* dirtying the cache and extra management for smp since
* it is per-cpu.
*/
static inline struct utcb *l4_get_utcb()
{
// printf("%s: UTCB Adddress: 0x%x\n", __FUNCTION__, l4_cp15_read_tid_usr_ro());
return (struct utcb *)l4_cp15_read_tid_usr_ro();
}
#endif /* __ARM_V5_UTCB_H__ */

View File

@@ -0,0 +1,13 @@
/*
* Cache control operations
*
* Copyright (C) 2009 Bora Sahin
*/
#ifndef __L4_CACHE_CONTROL__
#define __L4_CACHE_CONTROL__
#include <l4/api/cache.h>
#endif /* __L4_CACHE_CONTROL__ */

View File

@@ -0,0 +1,27 @@
#ifndef __MM0_EXREGS_H__
#define __MM0_EXREGS_H__
#include <l4/api/exregs.h>
void exregs_set_stack(struct exregs_data *s, unsigned long sp);
void exregs_set_mr(struct exregs_data *s, int offset, unsigned long val);
void exregs_set_pc(struct exregs_data *s, unsigned long pc);
void exregs_set_pager(struct exregs_data *s, l4id_t pagerid);
void exregs_set_utcb(struct exregs_data *s, unsigned long virt);
void exregs_set_read(struct exregs_data *exregs);
unsigned long exregs_get_utcb(struct exregs_data *s);
unsigned long exregs_get_stack(struct exregs_data *s);
/*
exregs_set_stack(unsigned long sp)
exregs_set_pc(unsigned long pc)
exregs_set_return(unsigned long retreg)
exregs_set_arg0(unsigned long arg0)
exregs_set_mr0(unsigned long mr0)
exregs_set_mr_sender(unsigned long sender)
exregs_set_mr_return(unsigned long retreg)
exregs_set_all(unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3,
unsigned long sp, unsigned long pc, u32 valid_vector, l4id_t pager);
*/
#endif /* __MM0_EXREGS_H__ */

View File

@@ -0,0 +1,6 @@
#ifndef __L4LIB_INIT__
#define __L4LIB_INIT__
void __l4_init(void);
#endif

View File

@@ -0,0 +1,77 @@
/*
* Copyright (C) 2007, 2008 Bahadir Balban
*
* This file contains ipc definitions that are needed for server tasks
* to communicate with each other. For example common shared memory ids
* between two servers, or common ipc tags used between two servers are
* defined here.
*/
#ifndef __IPCDEFS_H__
#define __IPCDEFS_H__
#include <l4/api/ipc.h>
#include <l4lib/types.h>
/*** IPC Tags used between server tasks ***/
/*
* Tag 0 for L4_IPC_TAG_PFAULT
* Tag 1 for L4_IPC_TAG_UNDEF_FAULT
*/
/* For ping ponging */
#define L4_IPC_TAG_SYNC_EXTENDED 3
#define L4_IPC_TAG_SYNC_FULL 4
#define L4_IPC_TAG_SYNC 5
/* Posix system call tags */
#define L4_IPC_TAG_SHMGET 6
#define L4_IPC_TAG_SHMAT 7
#define L4_IPC_TAG_SHMDT 8
#define L4_IPC_TAG_MMAP 9
#define L4_IPC_TAG_MUNMAP 10
#define L4_IPC_TAG_MSYNC 11
#define L4_IPC_TAG_OPEN 12
#define L4_IPC_TAG_READ 13
#define L4_IPC_TAG_WRITE 14
#define L4_IPC_TAG_LSEEK 15
#define L4_IPC_TAG_CLOSE 16
#define L4_IPC_TAG_BRK 17
#define L4_IPC_TAG_READDIR 18
#define L4_IPC_TAG_MKDIR 19
#define L4_IPC_TAG_EXECVE 20
#define L4_IPC_TAG_CHDIR 21
#define L4_IPC_TAG_FORK 22
#define L4_IPC_TAG_STAT 23
#define L4_IPC_TAG_FSTAT 24
#define L4_IPC_TAG_FSYNC 25
#define L4_IPC_TAG_CLONE 26
#define L4_IPC_TAG_EXIT 27
#define L4_IPC_TAG_WAIT 28
/* Tags for ipc between fs0 and mm0 */
#define L4_IPC_TAG_TASKDATA 40
#define L4_IPC_TAG_PAGER_OPEN 41 /* vfs sends the pager open file data. */
#define L4_IPC_TAG_PAGER_READ 42 /* Pager reads file contents from vfs */
#define L4_IPC_TAG_PAGER_WRITE 43 /* Pager writes file contents to vfs */
#define L4_IPC_TAG_PAGER_CLOSE 44 /* Pager notifies vfs of file close */
#define L4_IPC_TAG_PAGER_UPDATE_STATS 45 /* Pager updates file stats in vfs */
#define L4_IPC_TAG_NOTIFY_FORK 46 /* Pager notifies vfs of process fork */
#define L4_IPC_TAG_NOTIFY_EXIT 47 /* Pager notifies vfs of process exit */
#define L4_IPC_TAG_PAGER_OPEN_BYPATH 48 /* Pager opens a vfs file by pathname */
#define L4_REQUEST_CAPABILITY 50 /* Request a capability from pager */
extern l4id_t pagerid;
/* For ipc to uart service (TODO: Shared mapping buffers???) */
#define L4_IPC_TAG_UART_SENDCHAR 51 /* Single char send (output) */
#define L4_IPC_TAG_UART_RECVCHAR 52 /* Single char recv (input) */
#define L4_IPC_TAG_UART_SENDBUF 53 /* Buffered send */
#define L4_IPC_TAG_UART_RECVBUF 54 /* Buffered recv */
/* For ipc to timer service (TODO: Shared mapping buffers???) */
#define L4_IPC_TAG_TIMER_GETTIME 55
#define L4_IPC_TAG_TIMER_SLEEP 56
#define L4_IPC_TAG_TIMER_WAKE_THREADS 57
#endif /* __IPCDEFS_H__ */

View File

@@ -0,0 +1,7 @@
#ifndef __L4LIB_IRQ_H__
#define __L4LIB_IRQ_H__
int l4_irq_wait(int slot, int irqnum);
#endif /* __L4LIB_IRQ_H__ */

View File

@@ -0,0 +1,15 @@
/*
* Kernel Interface Page
*
* Copyright (C) 2007 Bahadir Balban
*
*/
#ifndef __L4LIB_KIP_H__
#define __L4LIB_KIP_H__
/* Use the kernel header */
#include <l4lib/types.h>
#include <l4/api/kip.h>
#include L4LIB_INC_ARCH(syscalls.h)
#endif /* __KIP_H__ */

View File

@@ -0,0 +1,27 @@
/*
* Address allocation pool.
*
* Copyright (C) 2007 Bahadir Balban
*/
#ifndef __ADDR_H__
#define __ADDR_H__
#include <l4lib/lib/idpool.h>
/* Address pool to allocate from a range of addresses */
struct address_pool {
struct id_pool *idpool;
unsigned long start;
unsigned long end;
};
int address_pool_init(struct address_pool *pool,
struct id_pool *idpool,
unsigned long start, unsigned long end);
int address_pool_alloc_init(struct address_pool *pool,
unsigned long start, unsigned long end,
unsigned int size);
void *address_new(struct address_pool *pool, int nitems, int size);
int address_del(struct address_pool *, void *addr, int nitems, int size);
#endif /* __ADDR_H__ */

View File

@@ -0,0 +1,44 @@
#ifndef __BIT_H__
#define __BIT_H__
#include <l4lib/types.h>
unsigned int __clz(unsigned int bitvector);
int find_and_set_first_free_bit(u32 *word, unsigned int lastbit);
int find_and_set_first_free_contig_bits(u32 *word, unsigned int limit,
int nbits);
int check_and_clear_bit(u32 *word, int bit);
int check_and_clear_contig_bits(u32 *word, int first, int nbits);
int check_and_set_bit(u32 *word, int bit);
/* Set */
static inline void setbit(unsigned int *w, unsigned int flags)
{
*w |= flags;
}
/* Clear */
static inline void clrbit(unsigned int *w, unsigned int flags)
{
*w &= ~flags;
}
/* Test */
static inline int tstbit(unsigned int *w, unsigned int flags)
{
return *w & flags;
}
/* Test and clear */
static inline int tstclr(unsigned int *w, unsigned int flags)
{
int res = tstbit(w, flags);
clrbit(w, flags);
return res;
}
#endif /* __BIT_H__ */

View File

@@ -0,0 +1,77 @@
/*
* Capability-related management.
*
* Copyright (C) 2009 Bahadir Balban
*/
#ifndef __LIBL4_CAPABILITY_H__
#define __LIBL4_CAPABILITY_H__
#include <l4lib/types.h>
#include <l4/lib/list.h>
#include <l4/api/capability.h>
#include <l4/generic/cap-types.h>
void cap_dev_print(struct capability *cap);
void cap_print(struct capability *cap);
void cap_array_print(int total_caps, struct capability *caparray);
/*
* Definitions for lists of capabilities
*/
struct cap_list {
int ncaps;
struct link caps;
};
static inline void cap_list_init(struct cap_list *clist)
{
clist->ncaps = 0;
link_init(&clist->caps);
}
static inline void cap_list_insert(struct capability *cap,
struct cap_list *clist)
{
list_insert(&cap->list, &clist->caps);
clist->ncaps++;
}
/* Detach a whole list of capabilities from list head */
static inline struct capability *
cap_list_detach(struct cap_list *clist)
{
struct link *list = list_detach(&clist->caps);
clist->ncaps = 0;
return link_to_struct(list, struct capability, list);
}
/* Attach a whole list of capabilities to list head */
static inline void cap_list_attach(struct capability *cap,
struct cap_list *clist)
{
/* Attach as if cap is the list and clist is the element */
list_insert(&clist->caps, &cap->list);
/* Count the number of caps attached */
list_foreach_struct(cap, &clist->caps, list)
clist->ncaps++;
}
static inline void cap_list_move(struct cap_list *to,
struct cap_list *from)
{
struct capability *cap_head = cap_list_detach(from);
cap_list_attach(cap_head, to);
}
/*
* Definitions for reading from the library capability array
*/
void __l4_capability_init(void);
struct capability *cap_get_by_type(unsigned int cap_type);
struct capability *cap_get_physmem(unsigned int cap_type);
int caps_read_all(void);
struct capability* cap_get_all();
int cap_get_count();
#endif /* __LIBL4_CAPABILITY_H__ */

View File

@@ -0,0 +1,32 @@
#ifndef __IDPOOL_H__
#define __IDPOOL_H__
#include <l4lib/lib/bit.h>
#include <string.h>
#include <l4/macros.h>
#include INC_GLUE(memory.h)
struct id_pool {
int nwords;
int bitlimit;
u32 bitmap[];
};
/* Copy one id pool to another by calculating its size */
static inline void id_pool_copy(struct id_pool *to, struct id_pool *from, int totalbits)
{
int nwords = BITWISE_GETWORD(totalbits);
memcpy(to, from, nwords * SZ_WORD + sizeof(struct id_pool));
}
void id_pool_init(struct id_pool *idpool, int bits);
struct id_pool *id_pool_new_init(int mapsize);
int id_new(struct id_pool *pool);
int id_del(struct id_pool *pool, int id);
int id_get(struct id_pool *pool, int id);
int id_is_empty(struct id_pool *pool);
int ids_new_contiguous(struct id_pool *pool, int numids);
int ids_del_contiguous(struct id_pool *pool, int first, int numids);
#endif /* __IDPOOL_H__ */

View File

@@ -0,0 +1,65 @@
#ifndef __THREAD_H__
#define __THREAD_H__
#include <l4lib/macros.h>
#include L4LIB_INC_ARCH(syslib.h)
#include L4LIB_INC_ARCH(syscalls.h)
#include <l4lib/exregs.h>
#include <l4lib/mutex.h>
#include <l4/api/thread.h>
#include <l4/lib/list.h>
/*
* Library specific-flags for thread creation
*/
#define TC_USER_FLAGS_MASK 0x000F0000
#define TC_NOSTART 0x00010000
/* For same space */
#define STACK_SIZE PAGE_SIZE
/* Total threads the library supports */
#define THREADS_TOTAL 10
/*
* Keeps track of threads in the system
* created by the pager
*/
struct l4_thread_list {
int total; /* Total number of threads */
struct l4_mutex lock; /* Threads list lock */
struct link thread_list; /* Threads list */
struct mem_cache *thread_cache; /* Cache for thread structures */
};
struct l4_thread {
struct task_ids ids; /* Thread ids */
struct l4_mutex lock; /* Lock for thread struct */
struct link list; /* Link to list of threads */
unsigned long *stack; /* Stack (grows downwards) */
struct utcb *utcb; /* UTCB address */
};
/*
* These are thread calls that are meant to be
* called by library users
*/
int thread_create(int (*func)(void *), void *args, unsigned int flags,
struct l4_thread **tptr);
int thread_wait(struct l4_thread *t);
void thread_exit(int exitcode);
/*
* This is to be called only if to-be-destroyed thread is in
* sane condition for destruction
*/
int thread_destroy(struct l4_thread *thread);
/* Library init function called by __container_init */
void __l4_threadlib_init(void);
void l4_parent_thread_init(void);
extern struct mem_cache *utcb_cache, *stack_cache;
extern struct l4_thread_list l4_thread_list;
extern void setup_new_thread(void);
#endif /* __THREAD_H__ */

View File

@@ -0,0 +1,17 @@
/*
* Generic macros for cache operations
*
* Copyright (C) 2009 B Labs Ltd.
*/
#ifndef __CACHE_CONTROL_H__
#define __CACHE_CONTROL_H__
#include L4LIB_INC_GLUE(cache.h)
#define L4_INVALIDATE_ICACHE ARCH_INVALIDATE_ICACHE
#define L4_INVALIDATE_DCACHE ARCH_INVALIDATE_DCACHE
#define L4_CLEAN_DCACHE ARCH_CLEAN_DCACHE
#define L4_CLEAN_INVALIDATE_DCACHE ARCH_CLEAN_INVALIDATE_DCACHE
#define L4_INVALIDATE_TLB ARCH_INVALIDATE_TLB
#endif /* __CACHE_CONTROL_H__ */

View File

@@ -0,0 +1,96 @@
/*
* Syscall API for capability manipulation
*
* Copyright (C) 2009 Bahadir Balban
*/
#ifndef __API_CAPABILITY_H__
#define __API_CAPABILITY_H__
#include <l4lib/lib/list.h>
#include L4LIB_INC_ARCH(types.h)
/* Capability syscall request types */
#define CAP_CONTROL_NCAPS 0x00000000
#define CAP_CONTROL_READ 0x00000001
#define CAP_CONTROL_SHARE 0x00000002
#define CAP_CONTROL_GRANT 0x00000003
#define CAP_CONTROL_REPLICATE 0x00000004
#define CAP_CONTROL_SPLIT 0x00000005
#define CAP_CONTROL_DEDUCE 0x00000006
#define CAP_CONTROL_DESTROY 0x00000007
#define CAP_SHARE_MASK 0x0000000F
#define CAP_SHARE_SINGLE 0x00000001
#define CAP_SHARE_ALL_CONTAINER 0x00000002
#define CAP_SHARE_ALL_SPACE 0x00000003
#define CAP_GRANT_MASK 0x0000000F
#define CAP_GRANT_SINGLE 0x00000001
#define CAP_GRANT_IMMUTABLE 0x00000004
#define CAP_SPLIT_MASK 0x0000000F
#define CAP_SPLIT_SIZE 0x00000001
#define CAP_SPLIT_ACCESS 0x00000002
#define CAP_SPLIT_RANGE 0x00000003 /* Returns -EPERM */
/*
* A capability is a unique representation of security
* qualifiers on a particular resource.
*
* In this structure:
*
* The capid denotes the unique capability ID.
* The resid denotes the unique ID of targeted resource.
* The owner denotes the unique ID of the one and only capability owner. This is
* almost always a thread ID.
*
* The type field contains two types:
* - The capability type,
* - The targeted resource type.
*
* The targeted resouce type denotes what type of resource the capability is
* allowed to operate on. For example a thread, a thread group, an address space
* or a memory can be of this type.
*
* The capability type defines the general set of operations allowed on a
* particular resource. For example a capability type may be thread_control,
* exchange_registers, ipc, or map operations. A resource type may be such as a
* thread, a thread group, a virtual or physical memory region.
*
* There are also quantitative capability types. While their names denote
* quantitative objects such as memory, threads, and address spaces, these
* types actually define the quantitative operations available on those
* resources such as creation and deletion of a thread, allocation and
* deallocation of a memory region etc.
*
* The access field denotes the fine-grain operations available on a particular
* resource. The meaning of each bitfield differs according to the type of the
* capability. For example, for a capability type thread_control, the bitfields
* may mean suspend, resume, create, delete etc.
*/
struct capability {
struct link list;
/* Capability identifiers */
l4id_t capid; /* Unique capability ID */
l4id_t owner; /* Capability owner ID */
l4id_t resid; /* Targeted resource ID */
unsigned int type; /* Capability and target resource type */
/* Capability limits/permissions */
u32 access; /* Permitted operations */
/* Limits on the resource (NOTE: must never have signed type) */
unsigned long start; /* Resource start value */
unsigned long end; /* Resource end value */
unsigned long size; /* Resource size */
/* Use count of resource */
unsigned long used;
/* Device attributes, if this is a device. */
unsigned int attr;
l4id_t irq;
};
#endif /* __API_CAPABILITY_H__ */

View File

@@ -0,0 +1,148 @@
#ifndef __ERRNO_H__
#define __ERRNO_H__
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Argument list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */
#define EDEADLK 35 /* Resource deadlock would occur */
#define ENAMETOOLONG 36 /* File name too long */
#define ENOLCK 37 /* No record locks available */
#define ENOSYS 38 /* Function not implemented */
#define ENOTEMPTY 39 /* Directory not empty */
#define ELOOP 40 /* Too many symbolic links encountered */
#define EWOULDBLOCK EAGAIN /* Operation would block */
#define ENOMSG 42 /* No message of desired type */
#define EIDRM 43 /* Identifier removed */
#define ECHRNG 44 /* Channel number out of range */
#define EL2NSYNC 45 /* Level 2 not synchronized */
#define EL3HLT 46 /* Level 3 halted */
#define EL3RST 47 /* Level 3 reset */
#define ELNRNG 48 /* Link number out of range */
#define EUNATCH 49 /* Protocol driver not attached */
#define ENOCSI 50 /* No CSI structure available */
#define EL2HLT 51 /* Level 2 halted */
#define EBADE 52 /* Invalid exchange */
#define EBADR 53 /* Invalid request descriptor */
#define EXFULL 54 /* Exchange full */
#define ENOANO 55 /* No anode */
#define EBADRQC 56 /* Invalid request code */
#define EBADSLT 57 /* Invalid slot */
#define EDEADLOCK EDEADLK
#define EBFONT 59 /* Bad font file format */
#define ENOSTR 60 /* Device not a stream */
#define ENODATA 61 /* No data available */
#define ETIME 62 /* Timer expired */
#define ENOSR 63 /* Out of streams resources */
#define ENONET 64 /* Machine is not on the network */
#define ENOPKG 65 /* Package not installed */
#define EREMOTE 66 /* Object is remote */
#define ENOLINK 67 /* Link has been severed */
#define EADV 68 /* Advertise error */
#define ESRMNT 69 /* Srmount error */
#define ECOMM 70 /* Communication error on send */
#define EPROTO 71 /* Protocol error */
#define EMULTIHOP 72 /* Multihop attempted */
#define EDOTDOT 73 /* RFS specific error */
#define EBADMSG 74 /* Not a data message */
#define EOVERFLOW 75 /* Value too large for defined data type */
#define ENOTUNIQ 76 /* Name not unique on network */
#define EBADFD 77 /* File descriptor in bad state */
#define EREMCHG 78 /* Remote address changed */
#define ELIBACC 79 /* Can not access a needed shared library */
#define ELIBBAD 80 /* Accessing a corrupted shared library */
#define ELIBSCN 81 /* .lib section in a.out corrupted */
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
#define EILSEQ 84 /* Illegal byte sequence */
#define ERESTART 85 /* Interrupted system call should be restarted */
#define ESTRPIPE 86 /* Streams pipe error */
#define EUSERS 87 /* Too many users */
#define ENOTSOCK 88 /* Socket operation on non-socket */
#define EDESTADDRREQ 89 /* Destination address required */
#define EMSGSIZE 90 /* Message too long */
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
#define ENOPROTOOPT 92 /* Protocol not available */
#define EPROTONOSUPPORT 93 /* Protocol not supported */
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#define EADDRINUSE 98 /* Address already in use */
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#define ENETDOWN 100 /* Network is down */
#define ENETUNREACH 101 /* Network is unreachable */
#define ENETRESET 102 /* Network dropped connection because of reset */
#define ECONNABORTED 103 /* Software caused connection abort */
#define ECONNRESET 104 /* Connection reset by peer */
#define ENOBUFS 105 /* No buffer space available */
#define EISCONN 106 /* Transport endpoint is already connected */
#define ENOTCONN 107 /* Transport endpoint is not connected */
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
#define ETIMEDOUT 110 /* Connection timed out */
#define ECONNREFUSED 111 /* Connection refused */
#define EHOSTDOWN 112 /* Host is down */
#define EHOSTUNREACH 113 /* No route to host */
#define EALREADY 114 /* Operation already in progress */
#define EINPROGRESS 115 /* Operation now in progress */
#define ESTALE 116 /* Stale NFS file handle */
#define EUCLEAN 117 /* Structure needs cleaning */
#define ENOTNAM 118 /* Not a XENIX named type file */
#define ENAVAIL 119 /* No XENIX semaphores available */
#define EISNAM 120 /* Is a named type file */
#define EREMOTEIO 121 /* Remote I/O error */
#define EDQUOT 122 /* Quota exceeded */
#define ENOMEDIUM 123 /* No medium found */
#define EMEDIUMTYPE 124 /* Wrong medium type */
#define ECANCELED 125 /* Operation Canceled */
#define ENOKEY 126 /* Required key not available */
#define EKEYEXPIRED 127 /* Key has expired */
#define EKEYREVOKED 128 /* Key has been revoked */
#define EKEYREJECTED 129 /* Key was rejected by service */
/* Codezero specific error codes */
#define EACTIVE 132 /* Task active */
#define ENOIPC 133 /* General IPC error */
#define ENOCAP 134 /* None or insufficient capability */
#define ENOUTCB 135 /* Task has no utcb set up */
#define ENOMAP 136 /* The memory area has unmapped regions */
#define ENOIRQ 137 /* Irq cannot be registered */
#define EABORT 138 /* Abort cannot be handled */
#define ENOCHILD 139 /* Task is not paged by caller */
#endif /* __ERRNO_H__ */

View File

@@ -0,0 +1,50 @@
/*
* Exchange registers system call data.
*
* Copyright (C) 2008 Bahadir Balban
*/
#ifndef __EXREGS_H__
#define __EXREGS_H__
#include L4LIB_INC_GLUE(syscall.h)
#include L4LIB_INC_GLUE(context.h)
#include <l4lib/types.h>
#define EXREGS_SET_PAGER 1
#define EXREGS_SET_UTCB 2
#define EXREGS_READ 4
#define EXREGS_VALID_REGULAR_REGS \
(FIELD_TO_BIT(exregs_context_t, r0) | \
FIELD_TO_BIT(exregs_context_t, r1) | \
FIELD_TO_BIT(exregs_context_t, r2) | \
FIELD_TO_BIT(exregs_context_t, r3) | \
FIELD_TO_BIT(exregs_context_t, r4) | \
FIELD_TO_BIT(exregs_context_t, r5) | \
FIELD_TO_BIT(exregs_context_t, r6) | \
FIELD_TO_BIT(exregs_context_t, r7) | \
FIELD_TO_BIT(exregs_context_t, r8) | \
FIELD_TO_BIT(exregs_context_t, r9) | \
FIELD_TO_BIT(exregs_context_t, r10) | \
FIELD_TO_BIT(exregs_context_t, r11) | \
FIELD_TO_BIT(exregs_context_t, r12) | \
FIELD_TO_BIT(exregs_context_t, lr)) \
#define EXREGS_VALID_SP \
FIELD_TO_BIT(exregs_context_t, sp) \
#define EXREGS_VALID_PC \
FIELD_TO_BIT(exregs_context_t, pc) \
/* Structure passed by userspace pagers for exchanging registers */
struct exregs_data {
exregs_context_t context;
u32 valid_vect;
u32 flags;
l4id_t pagerid;
unsigned long utcb_address;
};
#endif /* __EXREGS_H__ */

View File

@@ -0,0 +1,27 @@
#ifndef __IPC_H__
#define __IPC_H__
#define L4_NILTHREAD 0xFFFFFFFF
#define L4_ANYTHREAD 0xFFFFFFFE
#define L4_IPC_TAG_MR_OFFSET 0
/* Pagefault */
#define L4_IPC_TAG_PFAULT 0
#define L4_IPC_TAG_UNDEF_FAULT 1
#define L4_IPC_FLAGS_TYPE_MASK 0x0000000F
#define L4_IPC_FLAGS_SHORT 0x00000000 /* Short IPC involves just primary message registers */
#define L4_IPC_FLAGS_FULL 0x00000001 /* Full IPC involves full UTCB copy */
#define L4_IPC_FLAGS_EXTENDED 0x00000002 /* Extended IPC can page-fault and copy up to 2KB */
/* Extended IPC extra fields */
#define L4_IPC_FLAGS_MSG_INDEX_MASK 0x00000FF0 /* Index of message register with buffer pointer */
#define L4_IPC_FLAGS_SIZE_MASK 0x0FFF0000
#define L4_IPC_FLAGS_SIZE_SHIFT 16
#define L4_IPC_FLAGS_MSG_INDEX_SHIFT 4
#define L4_IPC_EXTENDED_MAX_SIZE (SZ_1K*2)
#endif /* __IPC_H__ */

View File

@@ -0,0 +1,10 @@
#ifndef __API_IRQ_H__
#define __API_IRQ_H__
#define IRQ_CONTROL_REGISTER 0
#define IRQ_CONTROL_RELEASE 1
#define IRQ_CONTROL_WAIT 2
#endif /* __API_IRQ_H__ */

View File

@@ -0,0 +1,82 @@
/*
* Kernel Interface Page
*
* Copyright (C) 2007 Bahadir Balban
*/
#ifndef __KIP_H__
#define __KIP_H__
#include <l4lib/types.h>
#define __YEAR__ ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \
+ (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))
#define __MONTH__ (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 0 : 5) \
: __DATE__ [2] == 'b' ? 1 \
: __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 2 : 3) \
: __DATE__ [2] == 'y' ? 4 \
: __DATE__ [2] == 'l' ? 6 \
: __DATE__ [2] == 'g' ? 7 \
: __DATE__ [2] == 'p' ? 8 \
: __DATE__ [2] == 't' ? 9 \
: __DATE__ [2] == 'v' ? 10 : 11)
#define __DAY__ ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 \
+ (__DATE__ [5] - '0'))
#define CODEZERO_VERSION 0
#define CODEZERO_SUBVERSION 2
#define KDESC_DATE_SIZE 12
#define KDESC_TIME_SIZE 9
struct kernel_descriptor {
u32 version;
u32 subversion;
u32 magic;
char date[KDESC_DATE_SIZE];
char time[KDESC_TIME_SIZE];
} __attribute__((__packed__));
/* Experimental KIP with non-standard offsets */
struct kip {
/* System descriptions */
u32 magic;
u16 version_rsrv;
u8 api_subversion;
u8 api_version;
u32 api_flags;
u32 container_control;
u32 time;
u32 irq_control;
u32 thread_control;
u32 ipc_control;
u32 map;
u32 ipc;
u32 capability_control;
u32 unmap;
u32 exchange_registers;
u32 thread_switch;
u32 schedule;
u32 getid;
u32 mutex_control;
u32 cache_control;
u32 arch_syscall0;
u32 arch_syscall1;
u32 arch_syscall2;
u32 utcb;
struct kernel_descriptor kdesc;
} __attribute__((__packed__));
#if defined (__KERNEL__)
extern struct kip kip;
#endif /* __KERNEL__ */
#endif /* __KIP_H__ */

Some files were not shown because too many files have changed in this diff Show More