mirror of
https://github.com/drasko/codezero.git
synced 2026-03-20 03:01:48 +01:00
Kernel updates since December 2009
This commit is contained in:
@@ -18,17 +18,18 @@ from config.projpaths import *
|
||||
Import('env', 'arch', 'type')
|
||||
variant = type
|
||||
|
||||
# Needed by fputc(), for declaration of pl011_uart_tx()
|
||||
LIBDEV_PATH = join(PROJROOT, 'conts/libdev')
|
||||
LIBDEV_INCPATH = [LIBDEV_PATH + '/uart/include']
|
||||
# Needed by fputc(), for declaration of uart_tx()
|
||||
LIBDEV_RELDIR = 'conts/libdev'
|
||||
LIBDEV_DIR = join(PROJROOT, LIBDEV_RELDIR)
|
||||
LIBDEV_INC = join(LIBDEV_DIR, 'include')
|
||||
|
||||
e = env.Clone()
|
||||
e.Append(CPPPATH = ['include', 'include/sys-' + variant + '/arch-' + arch,
|
||||
LIBDEV_INCPATH],
|
||||
CCFLAGS = '-nostdinc')
|
||||
e.Append(CPPPATH = ['include', 'include/sys-' + variant + \
|
||||
'/arch-' + arch, LIBDEV_INC],
|
||||
CCFLAGS = ['-nostdinc'])
|
||||
|
||||
source = \
|
||||
Glob('src/*.c') + \
|
||||
Glob('src/*.[cS]') + \
|
||||
Glob('src/sys-' + variant + '/*.c') + \
|
||||
Glob('src/sys-' + variant + '/arch-' + arch + '/*.c') + \
|
||||
Glob('src/arch-' + arch + '/*.c') + \
|
||||
|
||||
50
conts/libc/SConstruct
Normal file
50
conts/libc/SConstruct
Normal file
@@ -0,0 +1,50 @@
|
||||
# -*- 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 config.projpaths import *
|
||||
from 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'
|
||||
|
||||
# Needed by fputc(), for declaration of uart_tx()
|
||||
LIBDEV_RELDIR = 'conts/libdev'
|
||||
LIBDEV_DIR = join(PROJROOT, LIBDEV_RELDIR)
|
||||
LIBDEV_INC = join(LIBDEV_DIR, 'include')
|
||||
|
||||
env = Environment(CC = config.toolchain + '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_INC, join(PROJROOT,'include'), \
|
||||
'include/sys-' + variant + '/arch-' + arch])
|
||||
|
||||
source = \
|
||||
Glob('src/*.[cS]') + \
|
||||
Glob('src/sys-' + variant + '/*.c') + \
|
||||
Glob('src/sys-' + variant + '/arch-' + arch + '/*.c') + \
|
||||
Glob('src/arch-' + arch + '/*.c') + \
|
||||
Glob('src/arch-' + arch + '/*.S') + \
|
||||
Glob('crt/sys-' + variant + '/arch-' + arch + '/*.[cS]')
|
||||
|
||||
objects = env.StaticObject(source)
|
||||
library = env.StaticLibrary('c-' + variant, objects)
|
||||
|
||||
@@ -181,7 +181,8 @@ 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 */
|
||||
int fgetc(FILE *);
|
||||
char fgetc(FILE *);
|
||||
char *fgetline(FILE *);
|
||||
char *fgets(char *, int, FILE *);
|
||||
int fputc(int, FILE *);
|
||||
int fputs(const char *, FILE *);
|
||||
|
||||
92
conts/libc/include/sys-baremetal/arch-arm/arch/stdint.h
Normal file
92
conts/libc/include/sys-baremetal/arch-arm/arch/stdint.h
Normal 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
|
||||
60
conts/libc/src/memcpy.S
Normal file
60
conts/libc/src/memcpy.S
Normal 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)
|
||||
68
conts/libc/src/memset.S
Normal file
68
conts/libc/src/memset.S
Normal 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)
|
||||
@@ -2,19 +2,12 @@
|
||||
* Ties up platform's uart driver functions with printf
|
||||
*
|
||||
* Copyright (C) 2009 B Labs Ltd.
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <pl011_uart.h>
|
||||
|
||||
extern struct pl011_uart uart;
|
||||
#include <libdev/uart.h>
|
||||
|
||||
int __fputc(int c, FILE *stream)
|
||||
{
|
||||
int res;
|
||||
do {
|
||||
res = pl011_tx_char(uart.base, c);
|
||||
} while( res < 0);
|
||||
|
||||
return(0);
|
||||
uart_tx_char(uart_print_base, c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
31
conts/libc/src/sys-userspace/arch-arm/sys_getc.c
Normal file
31
conts/libc/src/sys-userspace/arch-arm/sys_getc.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Library calls for uart rx.
|
||||
*
|
||||
* Copyright (C) 2009 B Labs Ltd.
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <libdev/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;
|
||||
}
|
||||
Reference in New Issue
Block a user