Version and Copyright Dynamic Memory Management
API Reference Manual  /  Device API  /  Device API Functions  / 

frags_t

FRAGS_INIT

Name

FRAGS_INIT — frags_t initializer

Synopsis

C and DML

#include <simics/device-api.h> // in C
// not available in DML

FRAGS_INIT;

Description

An frags_t initializer that can be used in variable declarations.

frags_add

Name

frags_add — add data to a frags_t

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

FORCE_INLINE void
frags_add(frags_t *buf, const void *data, size_t len);

Description

Append the new data data of size len to buf. A frags_t can hold up to 8 data fragments.

Return Value

None

Execution Context

Cell Context

Example

uint8 new_data[2] = { 7, 8 };
frags_add(&foo, new_data, sizeof(new_data));

See Also

frags_init_add, frags_init_add_from_frags, frags_add_from_frags

frags_add_from_frags

Name

frags_add_from_frags — append an existing frags_t to another

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

FORCE_INLINE void
frags_add_from_frags(frags_t *dst, const frags_t *src,
                     size_t offset, size_t len);

Description

Append len bytes of the data at offset offset in src to dst.

Return Value

None

Execution Context

Cell Context

Example

frags_add_from_frags(&foo, &bar, 4, frags_len(&bar) - 4);

See Also

frags_init_add, frags_add, frags_init_add_from_frags

frags_extract

Name

frags_extract — extract the contents of a frags_t

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

void frags_extract(const frags_t *buf, void *vdst);

Description

Copy the whole contents of buf to vdst. The destination buffer vdst should be large enough to contain all data in buf.

This function is completely equivalent to frags_extract_slice() with an offset and a length covering the whole contents of the frags_t, and is provided for convenience.

Return Value

None

Execution Context

Cell Context

Example

uint8 all_data[frags_len(&foo)];
frags_extract(&foo, all_data);

See Also

frags_extract_8, frags_extract_slice, frags_extract_alloc, frags_extract_slice_alloc

frags_extract_8, frags_extract_be16, frags_extract_le16, frags_extract_be32, frags_extract_le32, frags_extract_be64, frags_extract_le64

Name

frags_extract_8, frags_extract_be16, frags_extract_le16, frags_extract_be32, frags_extract_le32, frags_extract_be64, frags_extract_le64 — extract a value

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

uint8 frags_extract_8(const frags_t *buf, size_t offset);
uint16 frags_extract_be16(const frags_t *buf, size_t offset);
uint16 frags_extract_le16(const frags_t *buf, size_t offset);
uint32 frags_extract_be32(const frags_t *buf, size_t offset);
uint32 frags_extract_le32(const frags_t *buf, size_t offset);
uint64 frags_extract_be64(const frags_t *buf, size_t offset);
uint64 frags_extract_le64(const frags_t *buf, size_t offset);

Description

Extract a 8, 16, 32 or 64 bits value in either big-endian (_be) or little-endian (_le) format from the contents of the frags_t buf at offset offset.

Return Value

Extracted value

Execution Context

Cell Context

Example

uint8  val8  = frags_extract_8(&frame, 1);
uint16 val16 = frags_extract_be16(&frame, 2);
uint32 val32 = frags_extract_le32(&frame, 4);
uint32 val64 = frags_extract_be64(&frame, 8);

See Also

frags_extract, frags_extract_slice

frags_extract_alloc

Name

frags_extract_alloc — return a copy of the contents of a frags_t

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

void *frags_extract_alloc(const frags_t *buf);

Description

Return an allocated copy of the contents of buf. The buffer returned is allocated with MM_MALLOC(), and its ownership is passed to the caller, which should free it when appropriate.

This function is equivalent to allocating a buffer of the correct size with MM_MALLOC() followed by a call to frags_extract(), and is provided for convenience.

Return Value

A newly allocated copy of the contents

Execution Context

Cell Context

Example

uint8 *all = frags_extract_alloc(&foo);
/* ... */
MM_FREE(all);

See Also

frags_extract, frags_extract_slice, frags_extract_slice_alloc

frags_extract_slice

Name

frags_extract_slice — extract a slice of a frags_t

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

void frags_extract_slice(const frags_t *buf, void *vdst, size_t offset,
                         size_t len);

Description

Copy a slice of size len, starting at offset offset, of the contents of buf, to vdst. The destination buffer vdst should be able to contain at least len bytes.

Return Value

None

Execution Context

Cell Context

Example

uint8 some_data[16];
frags_extract_slice(&foo, some_data, 4, 16);

See Also

frags_extract_8, frags_extract, frags_extract_alloc, frags_extract_slice_alloc

frags_extract_slice_alloc

Name

frags_extract_slice_alloc — return a partial copy of the contents of a frags_t

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

void *frags_extract_slice_alloc(const frags_t *buf, size_t offset, size_t len);

Description

Return an allocated copy of a slice of size len, starting at offset offset, of the contents of buf. The return value is allocated with MM_MALLOC(), and its ownership is passed to the caller, which should free it when appropriate.

This function is equivalent to allocating a buffer of the correct size with MM_MALLOC() followed by a call to frags_extract_slice(), and is provided for convenience.

Return Value

A newly allocated, partial copy of the data

Execution Context

Cell Context

Example

uint8 *slice = frags_extract_slice_alloc(&foo, 4, 16);
/* ... */
MM_FREE(slice);

See Also

frags_extract, frags_extract_slice, frags_extract_alloc

frags_init

Name

frags_init — initialize a frags_t

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

FORCE_INLINE void frags_init(frags_t *buf);

Description

Initialize the frags_t buf. An alternative is to use the FRAGS_INIT constant value.

Return Value

None

Execution Context

Cell Context

Example

/* Initialization with frags_init() */
frags_t bar;
frags_init(&bar);
/* Initialization with FRAGS_INIT */
frags_t foo = FRAGS_INIT;

See Also

frags_init_add

frags_init_add

Name

frags_init_add — initialize a frags_t with an initial value

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

FORCE_INLINE void
frags_init_add(frags_t *buf, const void *data, size_t len);

Description

Initialize the frags_t buf and set it to represent the initial data data of size len.

This function is exactly equivalent to using frags_init(), followed by frags_add(), and is provided for convenience.

Return Value

None

Execution Context

Cell Context

Example

frags_t baz;
uint8 data[5] = { 0, 1, 2, 3, 4 };
frags_init_add(&baz, data, sizeof(data));

See Also

frags_init, frags_add

frags_init_add_from_frags

Name

frags_init_add_from_frags — initialize a frags_t from another

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

FORCE_INLINE void
frags_init_add_from_frags(frags_t *dst, const frags_t *src,
                          size_t offset, size_t len);

Description

Initialize dst and set its initial value to the data of size len starting at offset offset in src.

This function is exactly equivalent to using frags_init(), followed by frags_add_from_frags(), and is provided for convenience.

Return Value

None

Execution Context

Cell Context

Example

frags_t bat;
ASSERT(frags_len(&foo) > 16);
frags_init_add_from_frags(&bat, &foo, 16, frags_len(&foo) - 16);

See Also

frags_init_add, frags_add, frags_add_from_frags

frags_it

Name

frags_it — return an iterator

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

FORCE_INLINE frags_it_t
frags_it(const frags_t *buf, size_t offset, size_t len);

Description

Return an iterator on the fragments that compose the data in buf, starting from offset offset and up to a length of len. To iterate on all the data in buf, offset should be set to 0 and len to the value returned by frags_len().

Return Value

An iterator on the fragments covering the desired data range

Execution Context

Cell Context

Example

unsigned sum = 0;
for (frags_it_t it = frags_it(&foo, 0, frags_len(&foo));
     !frags_it_end(it);
     it = frags_it_next(it)) {
        unsigned f_len = frags_it_len(it);
        const uint8 *f_data = frags_it_data(it);

        for (int i=0; i<f_len; i++)
                sum += f_data[i];
}

See Also

frags_it_end, frags_it_next, frags_it_len, frags_it_data

frags_it_data

Name

frags_it_data — return the data of the current fragment

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

FORCE_INLINE const uint8 *
frags_it_data(frags_it_t it);

Description

Return a pointer to the data of the current fragment pointed by the iterator it.

Return Value

The data of the current fragment

Execution Context

Cell Context

Example

unsigned sum = 0;
for (frags_it_t it = frags_it(&foo, 0, frags_len(&foo));
     !frags_it_end(it);
     it = frags_it_next(it)) {
        unsigned f_len = frags_it_len(it);
        const uint8 *f_data = frags_it_data(it);

        for (int i=0; i<f_len; i++)
                sum += f_data[i];
}

See Also

frags_it, frags_it_end, frags_it_next, frags_it_len

frags_it_end

Name

frags_it_end — return whether an iterator is finished

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

FORCE_INLINE bool
frags_it_end(frags_it_t it);

Description

Return true when the iterator it does not have any next fragment to return at the next call of frags_it_next(), and false otherwise.

Return Value

true if the iterator is finished, false otherwise.

Execution Context

Cell Context

Example

unsigned sum = 0;
for (frags_it_t it = frags_it(&foo, 0, frags_len(&foo));
     !frags_it_end(it);
     it = frags_it_next(it)) {
        unsigned f_len = frags_it_len(it);
        const uint8 *f_data = frags_it_data(it);

        for (int i=0; i<f_len; i++)
                sum += f_data[i];
}

See Also

frags_it, frags_it_next, frags_it_len, frags_it_data

frags_it_len

Name

frags_it_len — return the length of the current fragment

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

FORCE_INLINE size_t
frags_it_len(frags_it_t it);

Description

Return the length of the current fragment pointed by the iterator it.

Return Value

The length of the current fragment

Execution Context

Cell Context

Example

unsigned sum = 0;
for (frags_it_t it = frags_it(&foo, 0, frags_len(&foo));
     !frags_it_end(it);
     it = frags_it_next(it)) {
        unsigned f_len = frags_it_len(it);
        const uint8 *f_data = frags_it_data(it);

        for (int i=0; i<f_len; i++)
                sum += f_data[i];
}

See Also

frags_it, frags_it_end, frags_it_next, frags_it_data

frags_it_next

Name

frags_it_next — return the next fragment’s iterator

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

FORCE_INLINE frags_it_t
frags_it_next(frags_it_t it);

Description

Return an iterator pointing at the next data fragment. This function should only be called if frags_end(it) returns false.

Return Value

An iterator on the next fragment

Execution Context

Cell Context

Example

unsigned sum = 0;
for (frags_it_t it = frags_it(&foo, 0, frags_len(&foo));
     !frags_it_end(it);
     it = frags_it_next(it)) {
        unsigned f_len = frags_it_len(it);
        const uint8 *f_data = frags_it_data(it);

        for (int i=0; i<f_len; i++)
                sum += f_data[i];
}

See Also

frags_it, frags_it_end, frags_it_len, frags_it_data

frags_len

Name

frags_len — return the total data length

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

FORCE_INLINE size_t frags_len(const frags_t *buf);

Description

Return the total length of the data represented by buf.

Return Value

The total data length

Execution Context

Cell Context

Example

unsigned len = frags_len(&foo);

frags_prefix

Name

frags_prefix — prefix a frags_t with a header

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

FORCE_INLINE frags_t
frags_prefix(const void *header, size_t header_len, const frags_t *body);

Description

Create a frags_t composed of the header header of size header_len, followed by the contents of the frags_t body.

This function is equivalent to a sequence of frags_init(), frags_add(), frags_add_from_frags() to build a new fragment containing the prefix. It is provided for convenience.

Return Value

A new frags_t including header and body

Execution Context

Cell Context

Example

uint8 eth_header[14] = { 0 };
frags_t packet = frags_prefix(eth_header, sizeof(eth_header), &foo);

See Also

frags_suffix, frags_add_from_frags

frags_suffix

Name

frags_suffix — append a suffix to a frags_t

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

FORCE_INLINE frags_t
frags_suffix(const frags_t *body, void *header, size_t header_len);

Description

Create a frags_t composed of the contents of the frags_t body, followed by the data header of size header_len.

This function is equivalent to a sequence of frags_init(), frags_add_from_frags(), frags_add() to build a new fragment containing the suffix. It is provided for convenience.

Return Value

A new frags_t including body and header

Execution Context

Cell Context

Example

uint8 eth_checksum[4] = { 0 };
frags_t frame = frags_suffix(&foo, eth_checksum, sizeof(eth_checksum));

See Also

frags_prefix, frags_add_from_frags

frags_t, frags_it_t

Name

frags_t, frags_it_t — encapsulate a data packet

Synopsis

C and DML

#include <simics/device-api.h> // in C
// always available in DML

typedef struct frags frags_t;
typedef struct frags_it frags_it_t;

Description

These types encapsulate a data packet, for use by models that send and receive data, such as network devices.

The structures should never be used directly. Only use the accessor functions.

Version and Copyright Dynamic Memory Management