Skip to content

Commit

Permalink
Added 2.2.80-132
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jul 13, 2020
1 parent a47808b commit 2a55256
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 50 deletions.
1 change: 1 addition & 0 deletions libspe2-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ enum ps_area { SPE_MSSYNC_AREA, SPE_MFC_COMMAND_AREA, SPE_CONTROL_AREA, SPE_SIG_
#define SPE_ISOLATE_EMULATE 0x00000100
#define SPE_EVENTS_ENABLE 0x00001000
#define SPE_AFFINITY_MEMORY 0x00002000
#define SPE_NOSCHED 0x00004000


/**
Expand Down
4 changes: 4 additions & 0 deletions libspe2.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ spe_context_ptr_t spe_context_create(unsigned int flags, spe_gang_context_ptr_t
*/
spe_context_ptr_t spe_context_create_affinity(unsigned int flags, spe_context_ptr_t affinity_neighbor, spe_gang_context_ptr_t gang)
{
if ( gang == NULL ) {
errno = ESRCH;
return NULL;
}
spe_context_ptr_t spe = _base_spe_context_create(flags, gang, affinity_neighbor);
if ( spe == NULL ) {
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion spebase/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ libspebase_SONAME := libspebase.so.${MAJOR_VERSION}

libspebase_OBJS := create.o elf_loader.o load.o run.o image.o lib_builtin.o \
default_c99_handler.o default_posix1_handler.o default_libea_handler.o \
dma.o mbox.o accessors.o info.o
dma.o mbox.o accessors.o info.o regs.o

CFLAGS += -I..
CFLAGS += -D_ATFILE_SOURCE
Expand Down
3 changes: 3 additions & 0 deletions spebase/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ spe_context_ptr_t _base_spe_context_create(unsigned int flags,
}

/* initialise spu_createflags */
if (flags & SPE_NOSCHED)
spu_createflags |= SPU_CREATE_NOSCHED;

if (flags & SPE_ISOLATE) {
flags |= SPE_MAP_PS;
spu_createflags |= SPU_CREATE_ISOLATE | SPU_CREATE_NOSCHED;
Expand Down
1 change: 1 addition & 0 deletions spebase/default_c99_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "default_c99_handler.h"
#include "handler_utils.h"
#include "spebase.h"

/* SPE C99 Handlers - Overview:
* This file implements handlers for SPE C99 library operations such
Expand Down
1 change: 1 addition & 0 deletions spebase/default_libea_handler.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define _GNU_SOURCE

#include "default_libea_handler.h"
#include "spebase.h"
#include "handler_utils.h"
#include <stdlib.h>
#include <stdio.h>
Expand Down
1 change: 1 addition & 0 deletions spebase/default_posix1_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#include "default_posix1_handler.h"
#include "handler_utils.h"
#include "spebase.h"

/* SPE POSIX.1 Handlers - Overview:
* This file implements handlers for SPE POSIX.1 library calls such as
Expand Down
9 changes: 0 additions & 9 deletions spebase/handler_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
#ifndef __HANDLER_UTILS_H__
#define __HANDLER_UTILS_H__

struct spe_reg128 {
unsigned int slot[4];
};

#ifndef LS_SIZE
#define LS_SIZE 0x40000 /* 256K (in bytes) */
#define LS_ADDR_MASK (LS_SIZE - 1)
#endif /* LS_SIZE */

#define __PRINTF(fmt, args...) { fprintf(stderr,fmt , ## args); }
#ifdef DEBUG
#define DEBUG_PRINTF(fmt, args...) __PRINTF(fmt , ## args)
Expand Down
104 changes: 104 additions & 0 deletions spebase/regs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* libspe2 - A wrapper library to adapt the JSRE SPU usage model to SPUFS
* Copyright (C) 2008 IBM Corp.
*
* Author: Jeremy Kerr <[email protected]>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License,
* or (at your option) any later version.
*
* This library 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 Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <stdint.h>
#include <string.h>

#include "spebase.h"
#include "regs.h"

/**
* A little PIC trampoline that is written to the end of local store, which
* will later be overwritten by the stack.
*
* This trampoline provides an area for a struct spe_reg_state, and a little
* code to load the appropriate areas of the reg_state into the actual regs,
* then branch to the entry point of the program
*
* After loading this trampoline, we need to copy the spe_reg_state struct
* into the base address of the trampoline.
*/

#if 0
reg_state:
.space 80 /* sizeof(spe_reg_state) */
_start:
lqr r3,reg_state + 0 /* r3 = spe_reg_state.r3 */
lqr r4,reg_state + 16 /* r4 = spe_reg_state.r4 */
lqr r5,reg_state + 32 /* r5 = spe_reg_state.r5 */

/* we have two alignment requirements here: reg_state needs to sit
* on a quadword boundary, and the bisl instruction needs to be
* the last word before the backchain pointer. So, align here, then
* add three instructions after the alignment, leaving bisl on the
* 4th word. */
.balign 16

lqr r6,reg_state + 48 /* r6 = spe_reg_state.r6 */
lqr r1,reg_state + 64 /* r1 = spe_reg_state.entry */
il r2,0 /* stack size: 0 = default */

bisl r1,r1 /* branch to the program entry, and
set the stack pointer to the
following word */
backchain:
/* initial stack backchain pointer - NULL*/
.long 0x0
.long 0x0
.long 0x0
.long 0x0
#endif
static uint32_t reg_setup_trampoline[] = {
/* reg_state: */
[sizeof(struct spe_reg_state) / sizeof(uint32_t)] =
/* _start: */
0x33fff603, /* lqr r3,0 <reg_state> */
0x33fff784, /* lqr r4,10 <reg_state+0x10> */
0x33fff905, /* lqr r5,20 <reg_state+0x20> */
0x00200000, /* lnop */
0x33fffa06, /* lqr r6,30 <reg_state+0x30> */
0x33fffb81, /* lqr r1,40 <reg_state+0x40> */
0x40800002, /* il r2,0 */
0x35200081, /* bisl r1,r1 */
/* backchain: */
0x00000000, /* stop */
0x00000000, /* stop */
0x00000000, /* stop */
0x00000000, /* stop */
};

int _base_spe_setup_registers(struct spe_context *spe,
struct spe_reg_state *regs,
unsigned int *entry)
{
unsigned int base_addr = LS_SIZE - sizeof(reg_setup_trampoline);

memcpy(spe->base_private->mem_mmap_base + base_addr,
reg_setup_trampoline, sizeof(reg_setup_trampoline));

memcpy(spe->base_private->mem_mmap_base + base_addr,
regs, sizeof(*regs));

*entry = base_addr + sizeof(struct spe_reg_state);

return 0;
}

36 changes: 36 additions & 0 deletions spebase/regs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* libspe2 - A wrapper library to adapt the JSRE SPU usage model to SPUFS
* Copyright (C) 2008 IBM Corp.
*
* Author: Jeremy Kerr <[email protected]>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License,
* or (at your option) any later version.
*
* This library 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 Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#ifndef _regs_h_
#define _regs_h_

#include "spebase.h"

struct spe_reg_state {
struct spe_reg128 r3, r4, r5, r6;
struct spe_reg128 entry;
};

int _base_spe_setup_registers(struct spe_context *spe,
struct spe_reg_state *regs,
unsigned int *entry);

#endif
58 changes: 18 additions & 40 deletions spebase/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "elf_loader.h"
#include "lib_builtin.h"
#include "spebase.h"
#include "regs.h"

/*Thread-local variable for use by the debugger*/
__thread struct spe_context_info {
Expand All @@ -51,27 +52,6 @@ static void cleanupspeinfo(struct spe_context_info *ctxinfo)
__spe_current_active_context = tmp;
}

static int set_regs(struct spe_context *spe, void *regs)
{
int fd_regs, rc;

fd_regs = openat(spe->base_private->fd_spe_dir, "regs", O_RDWR);
if (fd_regs < 0) {
DEBUG_PRINTF("Could not open SPE regs file.\n");
errno = EFAULT;
return -1;
}

rc = write(fd_regs, regs, 2048);

close(fd_regs);

if (rc < 0)
return -1;

return 0;
}

static int issue_isolated_exit(struct spe_context *spe)
{
struct spe_spu_control_area *cntl_area =
Expand Down Expand Up @@ -128,43 +108,41 @@ int _base_spe_context_run(spe_context_ptr_t spe, unsigned int *entry,
(SPE_ISOLATE | SPE_ISOLATE_EMULATE))) {

addr64 argp64, envp64, tid64, ls64;
unsigned int regs[128][4];
struct spe_reg_state reg_state;

/* setup parameters */
argp64.ull = (uint64_t)(unsigned long)argp;
envp64.ull = (uint64_t)(unsigned long)envp;
tid64.ull = (uint64_t)(unsigned long)spe;
ls64.ull = (uint64_t)(unsigned long)
spe->base_private->mem_mmap_base;

/* make sure the register values are 0 */
memset(regs, 0, sizeof(regs));

/* set sensible values for stack_ptr and stack_size */
regs[1][0] = (unsigned int) LS_SIZE - 16; /* stack_ptr */
regs[2][0] = 0; /* stack_size ( 0 = default ) */
memset(&reg_state, 0, sizeof(reg_state));

if (runflags & SPE_RUN_USER_REGS) {
/* When SPE_USER_REGS is set, argp points to an array
* of 3x128b registers to be passed directly to the SPE
* program.
*/
memcpy(regs[3], argp, sizeof(unsigned int) * 12);
memcpy(&reg_state, argp, 3 * sizeof(struct spe_reg128));
} else {
regs[3][0] = tid64.ui[0];
regs[3][1] = tid64.ui[1];
reg_state.r3.slot[0] = tid64.ui[0];
reg_state.r3.slot[1] = tid64.ui[1];

regs[4][0] = argp64.ui[0];
regs[4][1] = argp64.ui[1];
reg_state.r4.slot[0] = argp64.ui[0];
reg_state.r4.slot[1] = argp64.ui[1];

reg_state.r5.slot[0] = envp64.ui[0];
reg_state.r5.slot[1] = envp64.ui[1];

regs[5][0] = envp64.ui[0];
regs[5][1] = envp64.ui[1];
}

/* Store the LS base address in R6 */
ls64.ull = (uint64_t)(unsigned long)spe->base_private->mem_mmap_base;
regs[6][0] = ls64.ui[0];
regs[6][1] = ls64.ui[1];
reg_state.r6.slot[0] = ls64.ui[0];
reg_state.r6.slot[1] = ls64.ui[1];

reg_state.entry.slot[0] = tmp_entry;

if (set_regs(spe, regs))
if (_base_spe_setup_registers(spe, &reg_state, &tmp_entry))
return -1;
}

Expand Down
6 changes: 6 additions & 0 deletions spebase/spebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ struct spe_context_base_priv {
int active_tagmask;
};

struct spe_reg128 {
unsigned int slot[4];
};


/* spe related sizes
*/
Expand All @@ -125,6 +129,8 @@ struct spe_context_base_priv {
#define SIGNAL1_OFFSET 0x14000
#define SIGNAL2_OFFSET 0x1c000

#define LS_ADDR_MASK (LS_SIZE - 1)

/**
* Location of the PPE-assisted library call buffer
* for emulated isolation contexts.
Expand Down

0 comments on commit 2a55256

Please sign in to comment.