libspe2 0.9a
Defines | Functions
load.c File Reference
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include "elf_loader.h"
#include "create.h"
#include "spebase.h"
Include dependency graph for load.c:

Go to the source code of this file.

Defines

#define SPE_EMULATED_LOADER_FILE   "/usr/lib/spe/emulated-loader.bin"

Functions

void _base_spe_program_load_complete (spe_context_ptr_t spectx)
int _base_spe_emulated_loader_present (void)
int _base_spe_program_load (spe_context_ptr_t spe, spe_program_handle_t *program)

Define Documentation

#define SPE_EMULATED_LOADER_FILE   "/usr/lib/spe/emulated-loader.bin"

Definition at line 31 of file load.c.


Function Documentation

int _base_spe_emulated_loader_present ( void  )

Check if the emulated loader is present in the filesystem

Returns:
Non-zero if the loader is available, otherwise zero.

Definition at line 159 of file load.c.

References _base_spe_verify_spe_elf_image().

Referenced by _base_spe_context_create().

{
        spe_program_handle_t *loader = emulated_loader_program();

        if (!loader)
                return 0;

        return !_base_spe_verify_spe_elf_image(loader);
}

Here is the call graph for this function:

int _base_spe_program_load ( spe_context_ptr_t  spectx,
spe_program_handle_t program 
)

_base_spe_program_load loads an ELF image into a context

Parameters:
spectxSpecifies the SPE context
programhandle to the ELF image

Definition at line 203 of file load.c.

References _base_spe_load_spe_elf(), _base_spe_program_load_complete(), spe_context::base_private, DEBUG_PRINTF, spe_context_base_priv::emulated_entry, spe_ld_info::entry, spe_context_base_priv::entry, spe_context_base_priv::flags, spe_context_base_priv::loaded_program, spe_context_base_priv::mem_mmap_base, SPE_ISOLATE, and SPE_ISOLATE_EMULATE.

{
        int rc = 0;
        struct spe_ld_info ld_info;

        spe->base_private->loaded_program = program;

        if (spe->base_private->flags & SPE_ISOLATE) {
                rc = spe_start_isolated_app(spe, program);

        } else if (spe->base_private->flags & SPE_ISOLATE_EMULATE) {
                rc = spe_start_emulated_isolated_app(spe, program, &ld_info);

        } else {
                rc = _base_spe_load_spe_elf(program,
                                spe->base_private->mem_mmap_base, &ld_info);
                if (!rc)
                        _base_spe_program_load_complete(spe);
        }

        if (rc != 0) {
                DEBUG_PRINTF ("Load SPE ELF failed..\n");
                return -1;
        }

        spe->base_private->entry = ld_info.entry;
        spe->base_private->emulated_entry = ld_info.entry;

        return 0;
}

Here is the call graph for this function:

void _base_spe_program_load_complete ( spe_context_ptr_t  spectx)

Register the SPE program's start address with the oprofile and gdb, by writing to the object-id file.

Definition at line 38 of file load.c.

References __spe_context_update_event(), spe_context::base_private, DEBUG_PRINTF, spe_program_handle::elf_image, spe_context_base_priv::fd_spe_dir, and spe_context_base_priv::loaded_program.

Referenced by _base_spe_context_run(), and _base_spe_program_load().

{
        int objfd, len;
        char buf[20];
        spe_program_handle_t *program;

        program = spectx->base_private->loaded_program;

        if (!program || !program->elf_image) {
                DEBUG_PRINTF("%s called, but no program loaded\n", __func__);
                return;
        }

        objfd = openat(spectx->base_private->fd_spe_dir, "object-id", O_RDWR);
        if (objfd < 0)
                return;

        len = sprintf(buf, "%p", program->elf_image);
        write(objfd, buf, len + 1);
        close(objfd);

        __spe_context_update_event();
}

Here is the call graph for this function: