mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
clean up the ffi-test library for integration to main
checked all licenses, added some comments, etc.
This commit is contained in:
parent
3878208a8b
commit
d1a471b51c
8 changed files with 100 additions and 98 deletions
|
|
@ -1,8 +1,9 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
|
||||
pub mod api;
|
||||
use xous::{CID, send_message};
|
||||
use num_traits::ToPrimitive;
|
||||
use xous::CID;
|
||||
|
||||
/// A test stub for checking FFI integration routines.
|
||||
|
||||
pub struct FfiTest {
|
||||
conn: CID,
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ pub use bindings::*;
|
|||
|
||||
use num_traits::FromPrimitive;
|
||||
|
||||
use utralib::utra::ticktimer;
|
||||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
log_server::init_wait().unwrap();
|
||||
|
|
|
|||
|
|
@ -5,34 +5,24 @@ use std::env::set_var;
|
|||
fn main() {
|
||||
set_var("CC", "riscv64-unknown-elf-gcc"); // set the compiler to what's installed on the system
|
||||
|
||||
let espeak_srcs = vec![
|
||||
let ffi_srcs = vec![
|
||||
"ffi/ffi.c",
|
||||
"ffi/libc.c",
|
||||
"ffi/libc_split.c",
|
||||
"ffi/scanf.c",
|
||||
];
|
||||
let espeak_includes = vec![
|
||||
let ffi_includes = vec![
|
||||
"./",
|
||||
// "espeak-ng/src",
|
||||
// "espeak-ng/src/include/compat",
|
||||
// "espeak-ng/src/include/espeak",
|
||||
// "espeak-ng/src/include/espeak-ng",
|
||||
// "espeak-ng/src/ucd-tools/src/include",
|
||||
// "espeak-ng/src/include",
|
||||
];
|
||||
|
||||
let mut base_config = cc::Build::new();
|
||||
base_config.target("riscv32imac-unknown-none-elf");
|
||||
|
||||
for inc in espeak_includes {
|
||||
for inc in ffi_includes {
|
||||
base_config.include(inc);
|
||||
}
|
||||
base_config.include("C:\\Users\\bunnie\\riscv64\\riscv64-unknown-elf\\include");
|
||||
base_config.include("C:\\Users\\bunnie\\riscv64\\riscv64-unknown-elf\\include\\sys");
|
||||
base_config.include("C:\\Users\\bunnie\\riscv64\\riscv64-unknown-elf\\include\\machine");
|
||||
base_config.include("C:\\Users\\bunnie\\riscv64\\riscv64-unknown-elf\\include\\bits");
|
||||
|
||||
for src in espeak_srcs {
|
||||
for src in ffi_srcs {
|
||||
base_config.file(src);
|
||||
}
|
||||
base_config.define("XOUS", None);
|
||||
|
|
|
|||
|
|
@ -6,37 +6,6 @@ int add_one(int a) {
|
|||
return a + 1;
|
||||
}
|
||||
|
||||
/* returns an array of arrays of char*, all of which NULL */
|
||||
char ***alloc_matrix(unsigned rows, unsigned columns) {
|
||||
char ***matrix = malloc(rows * sizeof(char **));
|
||||
unsigned row = 0;
|
||||
unsigned column = 0;
|
||||
if (!matrix) return NULL;
|
||||
|
||||
for (row = 0; row < rows; row++) {
|
||||
matrix[row] = calloc(columns, sizeof(char *));
|
||||
if (!matrix[row]) return NULL;
|
||||
for (column = 0; column < columns; column++) {
|
||||
matrix[row][column] = NULL;
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
/* deallocates an array of arrays of char*, calling free() on each */
|
||||
void free_matrix(char ***matrix, unsigned rows, unsigned columns) {
|
||||
unsigned row = 0;
|
||||
unsigned column = 0;
|
||||
for (row = 0; row < rows; row++) {
|
||||
for (column = 0; column < columns; column++) {
|
||||
printf("column %d row %d\n", column, row);
|
||||
free(matrix[row][column]);
|
||||
}
|
||||
free(matrix[row]);
|
||||
}
|
||||
free(matrix);
|
||||
}
|
||||
|
||||
int malloc_test() {
|
||||
int i;
|
||||
|
||||
|
|
@ -86,11 +55,6 @@ int malloc_test() {
|
|||
if (pass == 1) {
|
||||
printf("memset passed\n");
|
||||
}
|
||||
/*
|
||||
int x = 6;
|
||||
char *** matrix = alloc_matrix(x, x);
|
||||
if (matrix == NULL) return 1;
|
||||
free_matrix(matrix, x, x);
|
||||
*/
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ void* calloc(size_t nmemb, size_t size) {
|
|||
return malloc(nmemb * size);
|
||||
}
|
||||
|
||||
|
||||
// ctype table from https://android.googlesource.com/platform/bionic/+/779585f/libc/stdlib/ctype_.c
|
||||
// openBSD licensed
|
||||
#define CTYPE_NUM_CHARS 256
|
||||
const char _ctype_[1 + CTYPE_NUM_CHARS] = {
|
||||
0,
|
||||
|
|
@ -68,7 +69,7 @@ const char _ctype_[1 + CTYPE_NUM_CHARS] = {
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// printf
|
||||
// printf is from https://github.com/mpaland/printf (MIT license)
|
||||
|
||||
// 'ntoa' conversion buffer size, this must be big enough to hold one converted
|
||||
// numeric number including padded zeros (dynamically created on stack)
|
||||
|
|
@ -966,9 +967,9 @@ __dorand48(unsigned short xseed[3])
|
|||
xseed[1] = temp[1];
|
||||
xseed[2] = (unsigned short) accu;
|
||||
}
|
||||
long
|
||||
int
|
||||
rand(void)
|
||||
{
|
||||
__dorand48(__rand48_seed);
|
||||
return ((long) __rand48_seed[2] << 15) + ((long) __rand48_seed[1] >> 1);
|
||||
return ((int) __rand48_seed[2] << 15) + ((int) __rand48_seed[1] >> 1);
|
||||
}
|
||||
|
|
@ -45,5 +45,4 @@ extern void free(void *);
|
|||
extern void libc_putchar(char c);
|
||||
void _putchar(char c);
|
||||
|
||||
#define RAND_MAX 0x7fffffff
|
||||
long rand(void);
|
||||
int rand(void);
|
||||
|
|
@ -21,45 +21,35 @@
|
|||
|
||||
#include "libc.h"
|
||||
|
||||
// libc code lifted from the android open source project https://android.googlesource.com/platform/bionic/+/ics-mr0/libc
|
||||
/*
|
||||
void *
|
||||
memcpy (void *dest, const void *src, size_t len)
|
||||
{
|
||||
char *d = dest;
|
||||
const char *s = src;
|
||||
while (len--)
|
||||
*d++ = *s++;
|
||||
return dest;
|
||||
}
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
void *
|
||||
memset (void *dest, int val, size_t len)
|
||||
{
|
||||
unsigned char *ptr = dest;
|
||||
while (len-- > 0)
|
||||
*ptr++ = val;
|
||||
return dest;
|
||||
}
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
const unsigned char* p1 = s1;
|
||||
const unsigned char* end1 = p1 + n;
|
||||
const unsigned char* p2 = s2;
|
||||
int d = 0;
|
||||
for (;;) {
|
||||
if (d || p1 >= end1) break;
|
||||
d = (int)*p1++ - (int)*p2++;
|
||||
if (d || p1 >= end1) break;
|
||||
d = (int)*p1++ - (int)*p2++;
|
||||
if (d || p1 >= end1) break;
|
||||
d = (int)*p1++ - (int)*p2++;
|
||||
if (d || p1 >= end1) break;
|
||||
d = (int)*p1++ - (int)*p2++;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
*/
|
||||
|
||||
wchar_t *
|
||||
wcschr(const wchar_t *s, wchar_t c)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,65 @@
|
|||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
// scanf code is from https://opensource.apple.com/source/xnu/xnu-792/libkern/stdio/scanf.c.auto.html
|
||||
/*
|
||||
* Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_START@
|
||||
*
|
||||
* This file contains Original Code and/or Modifications of Original Code
|
||||
* as defined in and that are subject to the Apple Public Source License
|
||||
* Version 2.0 (the 'License'). You may not use this file except in
|
||||
* compliance with the License. Please obtain a copy of the License at
|
||||
* http://www.opensource.apple.com/apsl/ and read it before using this
|
||||
* file.
|
||||
*
|
||||
* The Original Code and all software distributed under the License are
|
||||
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
|
||||
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
|
||||
* Please see the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @APPLE_LICENSE_HEADER_END@
|
||||
*/
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define BUF 32 /* Maximum length of numeric string. */
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in a new issue