Merge branch 'master' of git://www.b-labs.co.uk/bora/git/codezero into bora

Conflicts:
	config/cml/container_ruleset.template
	config/configuration.py
	conts/examples/example1/SConstruct
	conts/libl4thread/include/l4thread/thread.h
This commit is contained in:
Bahadir Balban
2009-11-19 14:41:07 +02:00
37 changed files with 604 additions and 67 deletions

View File

@@ -0,0 +1,55 @@
# -*- mode: python; coding: utf-8; -*-
#
# Codezero -- Virtualization microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
import os, shelve, sys
from os.path import *
PROJRELROOT = '../..'
sys.path.append(PROJRELROOT)
from config.projpaths import *
from config.configuration import *
config = configuration_retrieve()
arch = config.arch
LIBL4_RELDIR = 'conts/libl4'
KERNEL_INCLUDE = join(PROJROOT, 'include')
LIBL4_DIR = join(PROJROOT, LIBL4_RELDIR)
LIBL4_INCLUDE = join(LIBL4_DIR, 'include')
LIBL4_LIBPATH = join(BUILDDIR, LIBL4_RELDIR)
# Locally important paths are here
LIBC_RELDIR = 'conts/libc'
LIBC_DIR = join(PROJROOT, LIBC_RELDIR)
LIBC_LIBPATH = join(BUILDDIR, LIBC_RELDIR)
LIBC_INCLUDE = [join(LIBC_DIR, 'include'), \
join(LIBC_DIR, 'include/arch' + '/' + arch)]
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
# 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', '-mcpu=arm926ej-s', '-nostdlib', '-ffreestanding', \
'-std=gnu99', '-Wall', '-Werror'], \
LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"],\
ASFLAGS = ['-D__ASSEMBLY__'], \
PROGSUFFIX = '.elf', # The suffix to use for final executable\
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path\
LIBS = ['gcc', 'libl4', 'c-userspace', 'gcc', 'c-userspace'], # libgcc.a - This is required for division routines.
CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBC_INCLUDE],
LIBPATH = [LIBL4_LIBPATH, LIBC_LIBPATH],
CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h')
src = Glob('*.[cS]')
src += Glob('src/*.[cS]')
objs = env.Object(src)
prog = env.Program('main.elf', objs)
Depends(prog, 'include/linker.lds')

View File

@@ -8,7 +8,7 @@
#include <l4lib/utcb.h>
void main(void);
extern void main(void);
void __container_init(void)
{

View File

@@ -0,0 +1,12 @@
/*
* Main function for this container
*/
#include <l4lib/arch/syslib.h>
#include <l4lib/arch/syscalls.h>
#include <l4/api/space.h>
int main(void)
{
return 0;
}

View File

@@ -13,20 +13,19 @@ sys.path.append(PROJRELROOT)
from config.projpaths import *
from config.configuration import *
from configure import *
config = configuration_retrieve()
arch = config.arch
gcc_cpu_flag = config.gcc_cpu_flag
# Wrapper library for system calls
arch = config.arch
LIBL4_RELDIR = 'conts/libl4'
KERNEL_INCLUDE = join(PROJROOT, 'include')
LIBL4_DIR = join(PROJROOT, LIBL4_RELDIR)
LIBL4_INCLUDE = join(LIBL4_DIR, 'include')
LIBL4_LIBPATH = join(BUILDDIR, LIBL4_RELDIR)
# Some user-space libraries
# Locally important paths are here
LIBC_RELDIR = 'conts/libc'
LIBC_DIR = join(PROJROOT, LIBC_RELDIR)
LIBC_LIBPATH = join(BUILDDIR, LIBC_RELDIR)
@@ -43,11 +42,11 @@ LIBMEM_DIR = join(PROJROOT, LIBMEM_RELDIR)
LIBMEM_LIBPATH = join(BUILDDIR, LIBMEM_RELDIR)
LIBMEM_INCLUDE = LIBMEM_DIR
env = Environment(CC = config.user_toolchain + 'gcc',
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
# 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', ('-mcpu=' + gcc_cpu_flag)], \
CCFLAGS = ['-g', '-mcpu=arm926ej-s', '-nostdlib', '-ffreestanding', \
'-std=gnu99', '-Wall', '-Werror'], \
LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"],\
ASFLAGS = ['-D__ASSEMBLY__'], \
PROGSUFFIX = '.elf', # The suffix to use for final executable

View File

@@ -0,0 +1,21 @@
/*
* Container entry point for pager
*
* Copyright (C) 2007-2009 B Labs Ltd.
*/
#include <l4lib/init.h>
#include <l4lib/utcb.h>
extern void main(void);
void __container_init(void)
{
/* Generic L4 initialisation */
__l4_init();
/* Entry to main */
main();
}

View File

View File

View File

@@ -0,0 +1,67 @@
# -*- mode: python; coding: utf-8; -*-
#
# Codezero -- Virtualization microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
#
import os, shelve, sys
from os.path import *
PROJRELROOT = '../..'
sys.path.append(PROJRELROOT)
from config.projpaths import *
from config.configuration import *
config = configuration_retrieve()
arch = config.arch
LIBL4_RELDIR = 'conts/libl4'
KERNEL_INCLUDE = join(PROJROOT, 'include')
LIBL4_DIR = join(PROJROOT, LIBL4_RELDIR)
LIBL4_INCLUDE = join(LIBL4_DIR, 'include')
LIBL4_LIBPATH = join(BUILDDIR, LIBL4_RELDIR)
# Locally important paths are here
LIBC_RELDIR = 'conts/libc'
LIBC_DIR = join(PROJROOT, LIBC_RELDIR)
LIBC_LIBPATH = join(BUILDDIR, LIBC_RELDIR)
LIBC_INCLUDE = [join(LIBC_DIR, 'include'), \
join(LIBC_DIR, 'include/arch' + '/' + arch)]
LIBL4THREAD_RELDIR = 'conts/libl4thread'
LIBL4THREAD_DIR = join(PROJROOT, LIBL4THREAD_RELDIR)
LIBL4THREAD_LIBPATH = join(BUILDDIR, LIBL4THREAD_RELDIR)
LIBL4THREAD_INCLUDE = join(LIBL4THREAD_DIR, 'include')
LIBMEM_RELDIR = 'conts/libmem'
LIBMEM_DIR = join(PROJROOT, LIBMEM_RELDIR)
LIBMEM_LIBPATH = join(BUILDDIR, LIBMEM_RELDIR)
LIBMEM_INCLUDE = LIBMEM_DIR
env = Environment(CC = 'arm-none-linux-gnueabi-gcc',
# 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', '-mcpu=arm926ej-s', '-nostdlib', '-ffreestanding', \
'-std=gnu99', '-Wall', '-Werror'],
LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"],
ASFLAGS = ['-D__ASSEMBLY__'],
PROGSUFFIX = '.elf', # The suffix to use for final executable
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path
LIBS = ['libl4thread', 'libl4', 'libmalloc', 'c-userspace', \
'gcc', 'c-userspace'], # libgcc.a - This is required for division routines.
CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBC_INCLUDE, \
LIBL4THREAD_INCLUDE],
LIBPATH = [LIBL4_LIBPATH, LIBC_LIBPATH, LIBL4THREAD_LIBPATH, \
LIBMEM_LIBPATH],
CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h')
src = Glob('*.[cS]')
src += Glob('src/*.[cS]')
objs = env.Object(src)
prog = env.Program('main.elf', objs)
Depends(prog, 'include/linker.lds')

View File

@@ -0,0 +1,21 @@
/*
* Container entry point for pager
*
* Copyright (C) 2007-2009 B Labs Ltd.
*/
#include <l4lib/init.h>
#include <l4lib/utcb.h>
extern void main(void);
void __container_init(void)
{
/* Generic L4 initialisation */
__l4_init();
/* Entry to main */
main();
}

View File

@@ -0,0 +1,116 @@
/*
* Main function for this container
*/
#include <l4lib/arch/syslib.h>
#include <l4lib/arch/syscalls.h>
#include <l4/api/space.h>
#include <l4thread/thread.h>
/* Symbolic constants */
#define STACK_SIZE 0x1000
#define NTHREADS 10
/* Stack and utcb region */
static char stack[NTHREADS * STACK_SIZE];
DECLARE_UTCB_SPACE(utcb, NTHREADS)
/* Function definitions */
static void init_thread_lib(void)
{
/* Thread lib is informed about the stack region. */
l4_set_stack_params((unsigned long)stack,
(unsigned long)(stack + sizeof(stack)),
STACK_SIZE);
/* Thread lib is informed about the utcb region. */
l4_set_utcb_params((unsigned long)utcb,
(unsigned long)(utcb + sizeof(utcb)));
/* Now, we are ready to make calls to the library. */
}
static int do_some_work1(void *arg)
{
struct task_ids ids;
int value = *(int *)arg;
int j;
l4_getid(&ids);
printf("tid = %d is called with the value of (%d).\n",
__raw_tid(ids.tid), value);
/* Wait for a while before exiting */
j = 0x400000;
while (--j)
;
return ids.tid;
}
static int do_some_work2(void *arg)
{
struct task_ids ids;
int value = *(int *)arg;
int j;
l4_getid(&ids);
printf("tid = %d is called with the value of (%d).\n",
__raw_tid(ids.tid), value);
/* Wait for a while before exiting */
j = 0x400000;
while (--j)
;
l4_thread_exit(ids.tid);
/* Should never reach here */
return 0;
}
static int thread_demo(void)
{
struct task_ids ids[NTHREADS];
int arg[NTHREADS];
int j;
memset(ids, 0, sizeof(ids));
/* Create threads. */
for (int i = 0; i < NTHREADS; ++i) {
/* The argument passed to the thread in question. */
arg[i] = i;
/* Threads are created. */
if (i % 2)
l4_thread_create(&ids[i], TC_SHARE_SPACE | TC_SHARE_PAGER,
do_some_work1, (void *)&arg[i]);
else
l4_thread_create(&ids[i], TC_SHARE_SPACE | TC_SHARE_PAGER,
do_some_work2, (void *)&arg[i]);
/* Wait for a while before launching another thread. */
j = 0x100000;
while (--j)
;
}
/* Wait for them to exit. */
for (int i = 0; i < NTHREADS; ++i)
printf("tid = %d exited with (%d).\n", __raw_tid(ids[i].tid),
l4_thread_control(THREAD_WAIT, &ids[i]));
return 0;
}
int main(void)
{
/* Before using the thread lib, we have to initialize it. */
init_thread_lib();
/* Demonstrates the usage of the thread lib. */
thread_demo();
return 0;
}

View File

@@ -0,0 +1,32 @@
# -*- mode: python; coding: utf-8; -*-
#
# Codezero -- Virtualization microkernel for embedded systems.
#
# Copyright © 2009 B Labs Ltd
import os, sys
# Get global paths
PROJRELROOT = '../..'
sys.path.append(PROJRELROOT)
from config.projpaths import *
Import('env')
LIBMEM_RELDIR = 'conts/libmem'
LIBMEM_DIR = join(PROJROOT, LIBMEM_RELDIR)
LIBL4_RELDIR = 'conts/libl4'
LIBL4_DIR = join(PROJROOT, LIBL4_RELDIR)
LIBL4_INCLUDE = join(LIBL4_DIR, 'include')
e = env.Clone()
e.Append(CPPPATH = ['include/l4thread', LIBMEM_DIR, LIBL4_INCLUDE])
source = [Glob('*.[cS]') + Glob('src/*.[cS]') + Glob('src/arch/*.[cS]')]
objects = e.StaticObject(source)
library = e.StaticLibrary('l4thread', objects)
Return('library')

View File

@@ -0,0 +1,42 @@
#ifndef __BIT_H__
#define __BIT_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,30 @@
#ifndef __IDPOOL_H__
#define __IDPOOL_H__
#include <bit.h>
#include <string.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));
}
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

@@ -6,6 +6,10 @@
#ifndef __LIB_THREAD_H__
#define __LIB_THREAD_H__
/* A helper macro easing utcb space creation. */
#define DECLARE_UTCB_SPACE(name, entries) \
char name[(entries + PAGE_SIZE / UTCB_SIZE) * UTCB_SIZE] ALIGN(PAGE_SIZE);
int l4_set_stack_params(unsigned long stack_top,
unsigned long stack_bottom,
unsigned long stack_size);

1
conts/libl4thread/src/arch Symbolic link
View File

@@ -0,0 +1 @@
arch-arm/

108
conts/libl4thread/src/bit.c Normal file
View File

@@ -0,0 +1,108 @@
/*
* Bit manipulation functions.
*
* Copyright (C) 2007 Bahadir Balban
*/
#include <bit.h>
#include <stdio.h>
#include INC_GLUE(memory.h)
/* Emulation of ARM's CLZ (count leading zeroes) instruction */
unsigned int __clz(unsigned int bitvector)
{
unsigned int x = 0;
while((!(bitvector & ((unsigned)1 << 31))) && (x < 32)) {
bitvector <<= 1;
x++;
}
return x;
}
int find_and_set_first_free_bit(u32 *word, unsigned int limit)
{
int success = 0;
int i;
for(i = 0; i < limit; i++) {
/* Find first unset bit */
if (!(word[BITWISE_GETWORD(i)] & BITWISE_GETBIT(i))) {
/* Set it */
word[BITWISE_GETWORD(i)] |= BITWISE_GETBIT(i);
success = 1;
break;
}
}
/* Return bit just set */
if (success)
return i;
else
return -1;
}
int find_and_set_first_free_contig_bits(u32 *word, unsigned int limit,
int nbits)
{
int i = 0, first = 0, last = 0, found = 0;
/* Can't allocate more than the limit */
if (nbits > limit)
return -1;
/* This is a state machine that checks n contiguous free bits. */
while (i + nbits <= limit) {
first = i;
last = i;
while (!(word[BITWISE_GETWORD(last)] & BITWISE_GETBIT(last))) {
last++;
i++;
if (last == first + nbits) {
found = 1;
break;
}
}
if (found)
break;
i++;
}
/* If found, set the bits */
if (found) {
for (int x = first; x < first + nbits; x++)
word[BITWISE_GETWORD(x)] |= BITWISE_GETBIT(x);
return first;
} else
return -1;
}
int check_and_clear_bit(u32 *word, int bit)
{
/* Check that bit was set */
if (word[BITWISE_GETWORD(bit)] & BITWISE_GETBIT(bit)) {
word[BITWISE_GETWORD(bit)] &= ~BITWISE_GETBIT(bit);
return 0;
} else {
printf("Trying to clear already clear bit\n");
return -1;
}
}
int check_and_set_bit(u32 *word, int bit)
{
/* Check that bit was clear */
if (!(word[BITWISE_GETWORD(bit)] & BITWISE_GETBIT(bit))) {
word[BITWISE_GETWORD(bit)] |= BITWISE_GETBIT(bit);
return 0;
} else {
//printf("Trying to set already set bit\n");
return -1;
}
}
int check_and_clear_contig_bits(u32 *word, int first, int nbits)
{
for (int i = first; i < first + nbits; i++)
if (check_and_clear_bit(word, i) < 0)
return -1;
return 0;
}

View File

@@ -51,8 +51,7 @@ int find_and_set_first_free_contig_bits(u32 *word, unsigned int limit,
return -1;
/* This is a state machine that checks n contiguous free bits. */
/* FIXME: It should be <= instead of <. Fix & test in a single patch */
while (i + nbits < limit) {
while (i + nbits <= limit) {
first = i;
last = i;
while (!(word[BITWISE_GETWORD(last)] & BITWISE_GETBIT(last))) {