GEL  0.99
Block Cursor

Macros

#define gel_cursor_at_end(c)   ((c).cur_addr >= (c).base_addr + (c).size)
 
#define gel_cursor_avail(c)   ((c).base_addr + (c).size - (c).cur_addr)
 
#define gel_read_data(c, b, s)   { memcpy((b), (c).cur_addr, (s)); (c).cur_addr += (s); }
 
#define gel_read_u8(c)   ((c).cur_addr += 1 , *((u8_t*)((c).cur_addr - 1)))
 
#define gel_read_s8(c)   ((c).cur_addr += 1 , *((s8_t*)((c).cur_addr - 1)))
 
#define gel_read_u16(c)   ((c).cur_addr += 2, ENDIAN2((c).endianness, (*((u16_t*)((c).cur_addr - 2)))))
 
#define gel_read_s16(c)   ((c).cur_addr += 2, ENDIAN2((c).endianness, (*((s16_t*)((c).cur_addr - 2)))))
 
#define gel_read_u32(c)   ((c).cur_addr += 4, ENDIAN4((c).endianness, (*((u32_t*)((c).cur_addr - 4)))))
 
#define gel_read_s32(c)   ((c).cur_addr += 4, ENDIAN4((c).endianness, (*((s32_t*)((c).cur_addr - 4)))))
 
#define gel_read_vaddr(c)   ((c).cur_addr += 4, ENDIAN4((c).endianness, (*((vaddr_t*)((c).cur_addr - 4)))))
 
#define gel_read_raddr(c)   ((c).cur_addr += 4, ENDIAN4((c).endianness, (*((raddr_t*)((c).cur_addr - 4)))))
 
#define gel_write_u8(c, v)   {*((u8_t*)((c).cur_addr)) = (v) ; (c).cur_addr += 1; } while (0)
 
#define gel_write_s8(c, v)   {*((s8_t*)((c).cur_addr)) = (v) ; (c).cur_addr += 1; } while (0)
 
#define gel_write_u16(c, v)   {*((u16_t*)((c).cur_addr)) = ENDIAN2((c).endianness,(v)) ; (c).cur_addr += 2; } while (0)
 
#define gel_write_s16(c, v)   {*((s16_t*)((c).cur_addr)) = ENDIAN2((c).endianness,(v)) ; (c).cur_addr += 2; } while (0)
 
#define gel_write_u32(c, v)   {*((u32_t*)((c).cur_addr)) = ENDIAN4((c).endianness,(v)) ; (c).cur_addr += 4; } while (0)
 
#define gel_write_s32(c, v)   {*((s32_t*)((c).cur_addr)) = ENDIAN4((c).endianness,(v)) ; (c).cur_addr += 4; } while (0)
 
#define gel_write_vaddr(c, v)   {*((vaddr_t*)((c).cur_addr)) = ENDIAN4((c).endianness,(v)) ; (c).cur_addr += 4; } while (0)
 
#define gel_write_raddr(c, v)   {*((raddr_t*)((c).cur_addr)) = ENDIAN4((c).endianness,(v)) ; (c).cur_addr += 4; } while (0)
 
#define gel_cursor_reset(c)   { (c).cur_addr = (c).base_addr; }
 
#define GEL_ALIGN(v, n)   (((v) + (n) - 1) & ~((n) - 1))
 
#define GEL_ALIGNP(t, p, n)   ((t *)GEL_ALIGN((intptr_t)(p), (n)))
 

Typedefs

typedef struct gel_cursor_s gel_cursor_t
 

Functions

int gel_move (gel_cursor_t *p, u32_t off)
 
int gel_move_abs (gel_cursor_t *p, raddr_t addr)
 
int gel_move_rel (gel_cursor_t *p, s32_t off)
 
raddr_t gel_cursor_addr (gel_cursor_t *c)
 
int gel_cursor_bounds (gel_cursor_t *p)
 
int gel_write_block (gel_cursor_t *bc, char *blk, int blksize, raddr_t dest)
 
int gel_read_block (gel_cursor_t *bc, char *blk, int blksize, raddr_t src)
 
void gel_align_hi (gel_cursor_t *p)
 
void gel_align_lo (gel_cursor_t *p)
 
int gel_subcursor (gel_cursor_t *base, size_t size, gel_cursor_t *sub)
 

Detailed Description

This group contains definitions of items used to handle cursor to read or write in section and segments. The cursor perform two tasks:

Cursor may be obtained from:

Warning
For efficiency purpose, the cursor does not check if the accessed data are in the buffer bounds.
Date
2012/01/07
Author
S. Lemouzy, H. Cassé

Macro Definition Documentation

◆ GEL_ALIGN

#define GEL_ALIGN (   v,
 
)    (((v) + (n) - 1) & ~((n) - 1))

Align an integer value to an upper bound multiple of v.

Parameters
vInteger value to align.
nMultiple to align to (must be a power of 2).
Returns
v aligned to n.

◆ GEL_ALIGNP

#define GEL_ALIGNP (   t,
  p,
 
)    ((t *)GEL_ALIGN((intptr_t)(p), (n)))

Align a real pointer value to an upper bound multiple of v.

Parameters
tPointed type.
pReal pointer value to align.
nMultiple to align to (must be a power of 2).
Returns
p aligned to n.

◆ gel_cursor_at_end

#define gel_cursor_at_end (   c)    ((c).cur_addr >= (c).base_addr + (c).size)

Test if the end of the buffer is reached.

Parameters
cCurrent cursor.
Returns
1 if the end is reached, 0 else.

◆ gel_cursor_avail

#define gel_cursor_avail (   c)    ((c).base_addr + (c).size - (c).cur_addr)

Compute the number of available bytes in the current block.

Parameters
cUsed cursor.
Returns
Available bytes count.

◆ gel_cursor_reset

#define gel_cursor_reset (   c)    { (c).cur_addr = (c).base_addr; }

Reset the position of the cursor to the start.

Parameters
cCursor to reset.

◆ gel_read_data

#define gel_read_data (   c,
  b,
 
)    { memcpy((b), (c).cur_addr, (s)); (c).cur_addr += (s); }

Read a block of data.

Parameters
cCursor to read from.
bByte buffer to write to.
sNumber of bytes to read.

◆ gel_read_raddr

#define gel_read_raddr (   c)    ((c).cur_addr += 4, ENDIAN4((c).endianness, (*((raddr_t*)((c).cur_addr - 4)))))

Read an actual address and increment the cursor.

Parameters
cUsed cursor.
Returns
Read value.

◆ gel_read_s16

#define gel_read_s16 (   c)    ((c).cur_addr += 2, ENDIAN2((c).endianness, (*((s16_t*)((c).cur_addr - 2)))))

Read a signed half-word and increment the cursor.

Parameters
cUsed cursor.
Returns
Read value.

◆ gel_read_s32

#define gel_read_s32 (   c)    ((c).cur_addr += 4, ENDIAN4((c).endianness, (*((s32_t*)((c).cur_addr - 4)))))

Read a signed word and increment the cursor.

Parameters
cUsed cursor.
Returns
Read value.

◆ gel_read_s8

#define gel_read_s8 (   c)    ((c).cur_addr += 1 , *((s8_t*)((c).cur_addr - 1)))

Read a signed byte and increment the cursor.

Parameters
cUsed cursor.
Returns
Read value.

◆ gel_read_u16

#define gel_read_u16 (   c)    ((c).cur_addr += 2, ENDIAN2((c).endianness, (*((u16_t*)((c).cur_addr - 2)))))

Read an unsigned half-word and increment the cursor.

Parameters
cUsed cursor.
Returns
Read value.

◆ gel_read_u32

#define gel_read_u32 (   c)    ((c).cur_addr += 4, ENDIAN4((c).endianness, (*((u32_t*)((c).cur_addr - 4)))))

Read an unsigned word and increment the cursor.

Parameters
cUsed cursor.
Returns
Read value.

◆ gel_read_u8

#define gel_read_u8 (   c)    ((c).cur_addr += 1 , *((u8_t*)((c).cur_addr - 1)))

Read an unsigned byte and increment the cursor.

Parameters
cUsed cursor.
Returns
Read value.

◆ gel_read_vaddr

#define gel_read_vaddr (   c)    ((c).cur_addr += 4, ENDIAN4((c).endianness, (*((vaddr_t*)((c).cur_addr - 4)))))

Read a virtual address and increment the cursor.

Parameters
cUsed cursor.
Returns
Read value.

◆ gel_write_raddr

#define gel_write_raddr (   c,
 
)    {*((raddr_t*)((c).cur_addr)) = ENDIAN4((c).endianness,(v)) ; (c).cur_addr += 4; } while (0)

Write an actual address and increment the cursor.

Parameters
cCurrent cursor.
vValue to write.

◆ gel_write_s16

#define gel_write_s16 (   c,
 
)    {*((s16_t*)((c).cur_addr)) = ENDIAN2((c).endianness,(v)) ; (c).cur_addr += 2; } while (0)

Write a signed half-word and increment the cursor.

Parameters
cCurrent cursor.
vValue to write.

◆ gel_write_s32

#define gel_write_s32 (   c,
 
)    {*((s32_t*)((c).cur_addr)) = ENDIAN4((c).endianness,(v)) ; (c).cur_addr += 4; } while (0)

Write a signed byte word and increment the cursor.

Parameters
cCurrent cursor.
vValue to write.

◆ gel_write_s8

#define gel_write_s8 (   c,
 
)    {*((s8_t*)((c).cur_addr)) = (v) ; (c).cur_addr += 1; } while (0)

Write a signed byte and increment the cursor.

Parameters
cCurrent cursor.
vValue to write.

◆ gel_write_u16

#define gel_write_u16 (   c,
 
)    {*((u16_t*)((c).cur_addr)) = ENDIAN2((c).endianness,(v)) ; (c).cur_addr += 2; } while (0)

Write an unsigned half-word and increment the cursor.

Parameters
cCurrent cursor.
vValue to write.

◆ gel_write_u32

#define gel_write_u32 (   c,
 
)    {*((u32_t*)((c).cur_addr)) = ENDIAN4((c).endianness,(v)) ; (c).cur_addr += 4; } while (0)

Write an unsigned word and increment the cursor.

Parameters
cCurrent cursor.
vValue to write.

◆ gel_write_u8

#define gel_write_u8 (   c,
 
)    {*((u8_t*)((c).cur_addr)) = (v) ; (c).cur_addr += 1; } while (0)

Write an unsigned byte and increment the cursor.

Parameters
cCurrent cursor.
vValue to write.

◆ gel_write_vaddr

#define gel_write_vaddr (   c,
 
)    {*((vaddr_t*)((c).cur_addr)) = ENDIAN4((c).endianness,(v)) ; (c).cur_addr += 4; } while (0)

Write a virtual address and increment the cursor.

Parameters
cCurrent cursor.
vValue to write.

Typedef Documentation

◆ gel_cursor_t

Datastructure to represent a cursor on memory block, allowing to read or write in it (independently of the endianness of executable or host machine).

Function Documentation

◆ gel_align_hi()

void gel_align_hi ( gel_cursor_t p)

Align the cursor on the higher bound.

Parameters
pCursor to move.

◆ gel_align_lo()

void gel_align_lo ( gel_cursor_t p)

Align the cursor on the lower bound.

Parameters
pCursor to move.

◆ gel_cursor_addr()

raddr_t gel_cursor_addr ( gel_cursor_t c)

Get the current actual address of the cursor.

Parameters
cCursor to get address of.
Returns
Current actual address.

◆ gel_cursor_bounds()

int gel_cursor_bounds ( gel_cursor_t p)

Check if the current cursor is in the buffer bounds.

Parameters
pCurrent cursor.
Returns
0 if cursor is in bounds, -1 else.

◆ gel_move()

int gel_move ( gel_cursor_t p,
u32_t  off 
)

Move the cursor the position given by the offset from the start of the buffer.

Parameters
pCursor to set.
offOffset to move to.
Returns
Error code (0 for success, -1 for failure)

◆ gel_move_abs()

int gel_move_abs ( gel_cursor_t p,
raddr_t  addr 
)

Move the cursor to an actual addresse (that must be in the cursor buffer).

Parameters
pCursor to set.
addrActual address to set.
Returns
Error code (0 for success, -1 for failure)

◆ gel_move_rel()

int gel_move_rel ( gel_cursor_t p,
s32_t  off 
)

Move the cursor relatively to the current position.

Parameters
pCursot to set.
offOffset to add to the current position (may be negative).
Returns
Error code (0 for success, -1 for failure)

◆ gel_read_block()

int gel_read_block ( gel_cursor_t bc,
char *  blk,
int  blksize,
raddr_t  src 
)

Read a block from a cursor buffer at the given actual address with bound checking.

Parameters
bcCurrent cursor.
blkBase block to copy to.
blksizeBlock size.
srcActual address in the buffer of the block to copy.
Returns
Error code (0 for success, -1 for failure)

◆ gel_subcursor()

int gel_subcursor ( gel_cursor_t base,
size_t  size,
gel_cursor_t sub 
)

Build a cursor as sub-cursor on the buffer the base cursor.

Parameters
baseBase cursor.
sizeSize of the sub-buffer.
subNew sub-cursor.
Returns
0 for success, -1 if the size creates a sub-buffer out of bounds of the enclosing buffer.

◆ gel_write_block()

int gel_write_block ( gel_cursor_t bc,
char *  blk,
int  blksize,
raddr_t  dest 
)

Write a block in the cursor buffer with bound checking.

Parameters
bcCurrent cursor.
blkBase address of the block to copy.
blksizeBlock size.
destActual destination address.
Returns
Error code (0 for success, -1 for failure)