static inline int check_link_status(struct mem_link_device *mld)
{
	unsigned int magic = get_magic(mld);
	int cnt;

	if (gpio_get_value(mld->gpio_cp_status) != 0 && magic == MEM_IPC_MAGIC)
		return 0;

	cnt = 0;
	while (gpio_get_value(mld->gpio_cp_status) == 0) {
		if (gpio_get_value(mld->gpio_ap_status) == 0) {
			print_pm_status(mld);
			gpio_set_value(mld->gpio_ap_status, 1);
		}

		cnt++;
		if (cnt >= 100) {
			mif_err("ERR! cp_status != 1 (cnt %d)\n", cnt);
			return -EACCES;
		}

		if (in_interrupt())
			udelay(100);
		else
			usleep_range(100, 200);
	}

	cnt = 0;
	while (1) {
		magic = get_magic(mld);
		if (magic == MEM_IPC_MAGIC)
			break;

		cnt++;
		if (cnt >= 100) {
			mif_err("ERR! magic 0x%X != IPC_MAGIC (cnt %d)\n",
				magic, cnt);
			return -EACCES;
		}

		if (in_interrupt())
			udelay(100);
		else
			usleep_range(100, 200);
	}

	return 0;
}
/**
@brief		take a snapshot of the current status of a memory interface

Get a memory status and store the status data to @b @@mst

@param mld	the pointer to a mem_link_device instance
@param dir	the direction of a communication (TX or RX)
@param[out] mst	the pointer to a mem_status instance
*/
static void __take_mem_status(struct mem_link_device *mld, enum direction dir,
			      struct mem_snapshot *mst)
{
	int i;

	getnstimeofday(&mst->ts);

	mst->dir = dir;

	mst->magic = get_magic(mld);
	mst->access = get_access(mld);

	for (i = 0; i < MAX_SIPC5_DEVICES; i++) {
		struct mem_ipc_device *dev = mld->dev[i];
		mst->head[i][TX] = get_txq_head(dev);
		mst->tail[i][TX] = get_txq_tail(dev);
		mst->head[i][RX] = get_rxq_head(dev);
		mst->tail[i][RX] = get_rxq_tail(dev);
	}

	if (mld->recv_cp2ap_irq)
		mst->int2ap = mld->recv_cp2ap_irq(mld);
	else
		mst->int2ap = 0;

	if (mld->read_ap2cp_irq)
		mst->int2cp = mld->read_ap2cp_irq(mld);
	else
		mst->int2cp = 0;
}
Exemple #3
0
/**
@brief		function for the @b dump_start method in a link_device instance

@param ld	the pointer to a link_device instance
@param iod	the pointer to an io_device instance
*/
int mem_start_upload(struct link_device *ld, struct io_device *iod)
{
	struct mem_link_device *mld = to_mem_link_device(ld);

	if (mld->attrs & LINK_ATTR(LINK_ATTR_MEM_DUMP))
		sbd_deactivate(&mld->sbd_link_dev);

	reset_ipc_map(mld);

	if (mld->attrs & LINK_ATTR(LINK_ATTR_DUMP_ALIGNED))
		ld->aligned = true;
	else
		ld->aligned = false;

	if (mld->dpram_magic) {
		unsigned int magic;

		set_magic(mld, MEM_DUMP_MAGIC);
		magic = get_magic(mld);
		if (magic != MEM_DUMP_MAGIC) {
			mif_err("%s: ERR! magic 0x%08X != DUMP_MAGIC 0x%08X\n",
				ld->name, magic, MEM_DUMP_MAGIC);
			return -EFAULT;
		}
		mif_info("%s: magic == 0x%08X\n", ld->name, magic);
	}

	return 0;
}
int main(int argc, char *argv[])
{ 
    int fd;
    char *disk;

    if (argc > 1)
        disk = argv[1];
    else
        disk = "mydisk"; 

    if((fd = open(disk, O_RDONLY)) < 0)
    {
        perror("Open disk");
        exit(1);
    }

    if(get_magic(fd) != 0xEF53)
    {
        printf("Not an ext2 file system\n");
        exit(1);
    }

    putchar('\n');
    print_inode(fd, ROOT_INODE);
    putchar('\n');

    return 0;
}
Exemple #5
0
/**
@brief		check whether or not IPC link is active

@param mld	the pointer to a mem_link_device instance

@retval "TRUE"	if IPC via the mem_link_device instance is possible.
@retval "FALSE"	otherwise.
*/
static inline bool ipc_active(struct mem_link_device *mld)
{
	struct link_device *ld = &mld->link_dev;
	struct modem_ctl *mc = ld->mc;

	if (unlikely(!cp_online(mc))) {
		mif_err("%s<->%s: %s.state %s != ONLINE <%pf>\n",
			ld->name, mc->name, mc->name, mc_state(mc), CALLER);
		return false;
	}

	if (atomic_read(&mc->forced_cp_crash)) {
		mif_err("%s<->%s: ERR! forced_cp_crash:%d <%pf>\n",
			ld->name, mc->name, atomic_read(&mc->forced_cp_crash),
			CALLER);
		return false;
	}

	if (mld->dpram_magic) {
		unsigned int magic = get_magic(mld);
		unsigned int access = get_access(mld);
		if (magic != MEM_IPC_MAGIC || access != 1) {
			mif_err("%s<->%s: ERR! magic:0x%X access:%d <%pf>\n",
				ld->name, mc->name, magic, access, CALLER);
			return false;
		}
	}

	return true;
}
static int mem_start_download(struct link_device *ld, struct io_device *iod)
{
	struct mem_link_device *mld = to_mem_link_device(ld);

	reset_ipc_map(mld);

#ifdef CONFIG_LINK_DEVICE_WITH_SBD_ARCH
	if (mld->attrs & LINK_ATTR(LINK_ATTR_MEM_BOOT))
		sbd_deactivate(&mld->sbd_link_dev);
#endif

	if (mld->attrs & LINK_ATTR(LINK_ATTR_BOOT_ALIGNED))
		ld->aligned = true;
	else
		ld->aligned = false;

	if (mld->dpram_magic) {
		unsigned int magic;

		set_magic(mld, MEM_BOOT_MAGIC);
		magic = get_magic(mld);
		if (magic != MEM_BOOT_MAGIC) {
			mif_err("%s: ERR! magic 0x%08X != BOOT_MAGIC 0x%08X\n",
				ld->name, magic, MEM_BOOT_MAGIC);
			return -EFAULT;
		}
		mif_err("%s: magic == 0x%08X\n", ld->name, magic);
	}

	return 0;
}
static int dpram_init_ipc(struct dpram_link_device *dpld)
{
	struct link_device *ld = &dpld->ld;
	int i;

	if (ld->mode == LINK_MODE_IPC &&
	    get_magic(dpld) == DPRAM_MAGIC_CODE &&
	    get_access(dpld) == 1)
		mif_info("%s: IPC already initialized\n", ld->name);

	/* Clear pointers in every circular queue */
	for (i = 0; i < dpld->max_ipc_dev; i++) {
		set_tx_head(dpld, i, 0);
		set_tx_tail(dpld, i, 0);
		set_rx_head(dpld, i, 0);
		set_rx_tail(dpld, i, 0);
	}

	/* Initialize variables for efficient TX/RX processing */
	for (i = 0; i < dpld->max_ipc_dev; i++)
		dpld->iod[i] = link_get_iod_with_format(ld, i);
	dpld->iod[IPC_RAW] = link_get_iod_with_format(ld, IPC_MULTI_RAW);

	if (dpld->iod[IPC_RAW]->recv_skb)
		dpld->use_skb = true;

	for (i = 0; i < dpld->max_ipc_dev; i++) {
		spin_lock_init(&dpld->tx_lock[i]);
		atomic_set(&dpld->res_required[i], 0);
		skb_queue_purge(&dpld->skb_rxq[i]);
	}

	/* Enable IPC */
	atomic_set(&dpld->accessing, 0);

	set_magic(dpld, DPRAM_MAGIC_CODE);
	set_access(dpld, 1);
	if (get_magic(dpld) != DPRAM_MAGIC_CODE || get_access(dpld) != 1)
		return -EACCES;

	ld->mode = LINK_MODE_IPC;

	if (wake_lock_active(&dpld->wlock))
		wake_unlock(&dpld->wlock);

	return 0;
}
Exemple #8
0
void catalog_object::serialize()
{
    cs_stream stream(p_object, cs_stream::mode_write);
    int magic = get_magic();
    stream.write(&magic, sizeof(int));
    serialize_data(stream);
    stream.commit();
    if (p_object == XNULL) { p_object = stream.get_xptr(); };
}
void CNatOption::dump(FILE *fd){

    fprintf(fd,"  op        : %x \n",get_option_type());
    fprintf(fd,"  ol        : %x \n",get_option_len());
    fprintf(fd,"  thread_id : %x \n",get_thread_id());
    fprintf(fd,"  magic     : %x \n",get_magic());
    fprintf(fd,"  fid       : %x \n",get_fid());
    utl_DumpBuffer(stdout,(void *)&u.m_data[0],8,0);
}
Exemple #10
0
static int get_ppm_hdr(FILE *fp, ppm_hdr_t *ppm_hdr){
    get_magic(fp, ppm_hdr);
    if(!get_image_size(fp, ppm_hdr)){
        return 0;
    }
    if(!get_pixmax(fp, ppm_hdr)){
        return 0;
    }
    return 1;
}
Exemple #11
0
bool Fs::fsck(void) {
  fileoffset_t first_empty_byte;
  uint8_t sum = 0xFF;
  filecount_t exists;
  size_t status;

  mtd.read(dbg_super, sizeof(dbg_super), 0);

  /* open superblock */
  osalDbgCheck((this->files_opened == 0) && (nullptr == super.mtd));
  open_super();

  /* check magic */
  get_magic(toc_buf);
  sum = nvramcrc(toc_buf, sizeof(magic), sum);
  if (0 != memcmp(magic, toc_buf, sizeof(magic)))
    goto FAILED;

  /* check existing files number */
  exists = get_file_cnt();
  sum = nvramcrc(&exists, sizeof(exists), sum);
  if (exists > NVRAM_FS_MAX_FILE_CNT)
    goto FAILED;

  /* verify check sum */
  for (size_t i=0; i<NVRAM_FS_MAX_FILE_CNT; i++){
    status = super.read(toc_buf, sizeof(toc_buf));
    osalDbgCheck(sizeof(toc_buf) == status);
    sum = nvramcrc(toc_buf, sizeof(toc_buf), sum);
  }
  if (sum != get_checksum())
    goto FAILED;

  /* verify file names */
  first_empty_byte = super.start + super.size;
  super.setPosition(FAT_OFFSET);
  for (size_t i=0; i<exists; i++){
    toc_item_t ti;
    read_toc_item(&ti, i);

    if (OSAL_FAILED == check_name(ti.name, NVRAM_FS_MAX_FILE_NAME_LEN))
      goto FAILED;
    if ((ti.start + ti.size) >= mtd.capacity())
      goto FAILED;
    if (ti.start < first_empty_byte)
      goto FAILED;
  }

  super.close();
  return OSAL_SUCCESS;

FAILED:
  super.close();
  return OSAL_FAILED;
}
/*
** Functions for debugging
*/
static inline void log_dpram_status(struct dpram_link_device *dpld)
{
	pr_info("mif: %s: {M:0x%X A:%d} {FMT TI:%u TO:%u RI:%u RO:%u} "
		"{RAW TI:%u TO:%u RI:%u RO:%u} {INT:0x%X}\n",
		dpld->ld.mc->name,
		get_magic(dpld), get_access(dpld),
		get_tx_head(dpld, IPC_FMT), get_tx_tail(dpld, IPC_FMT),
		get_rx_head(dpld, IPC_FMT), get_rx_tail(dpld, IPC_FMT),
		get_tx_head(dpld, IPC_RAW), get_tx_tail(dpld, IPC_RAW),
		get_rx_head(dpld, IPC_RAW), get_rx_tail(dpld, IPC_RAW),
		recv_intr(dpld));
}
static bool link_active(struct mem_link_device *mld)
{
	unsigned int magic = get_magic(mld);

	if (magic == MEM_PM_MAGIC) {
		mif_err("%s: Going to SLEEP\n", ld->name);
		return true;
	} else {
		mif_err("%s: magic 0x%X\n", ld->name, magic);
		return false;
	}
}
Exemple #14
0
static int dpram_init_ipc(struct dpram_link_device *dpld)
{
	struct link_device *ld = &dpld->ld;
	int i;

	if (ld->mode == LINK_MODE_IPC &&
	    get_magic(dpld) == DPRAM_MAGIC_CODE &&
	    get_access(dpld) == 1)
		mif_info("%s: IPC already initialized\n", ld->name);

	/* Clear pointers in every circular queue */
	for (i = 0; i < dpld->max_ipc_dev; i++) {
		set_tx_head(dpld, i, 0);
		set_tx_tail(dpld, i, 0);
		set_rx_head(dpld, i, 0);
		set_rx_tail(dpld, i, 0);
	}

	for (i = 0; i < dpld->max_ipc_dev; i++) {
		spin_lock_init(&dpld->tx_lock[i]);
		atomic_set(&dpld->res_required[i], 0);
	}

	atomic_set(&dpld->accessing, 0);

	/* Enable IPC */
	set_magic(dpld, DPRAM_MAGIC_CODE);
	set_access(dpld, 1);
	if (get_magic(dpld) != DPRAM_MAGIC_CODE || get_access(dpld) != 1)
		return -EACCES;

	ld->mode = LINK_MODE_IPC;

	if (wake_lock_active(&dpld->wlock))
		wake_unlock(&dpld->wlock);

	return 0;
}
Exemple #15
0
/* Encode the PE header into disk format */
void *
SgAsmPEFileHeader::encode(PEFileHeader_disk *disk) const
{
    for (size_t i=0; i<NELMTS(disk->e_magic); i++)
        disk->e_magic[i] = get_magic()[i];
    host_to_le(p_e_cpu_type,           &(disk->e_cpu_type));
    host_to_le(p_e_nsections,          &(disk->e_nsections));
    host_to_le(p_e_time,               &(disk->e_time));
    host_to_le(p_e_coff_symtab,        &(disk->e_coff_symtab));
    host_to_le(p_e_coff_nsyms,         &(disk->e_coff_nsyms));
    host_to_le(p_e_nt_hdr_size,        &(disk->e_nt_hdr_size));
    host_to_le(p_e_flags,              &(disk->e_flags));

    return disk;
}
Exemple #16
0
static int dpram_check_access(struct dpram_link_device *dpld)
{
	struct link_device *ld = &dpld->ld;
	int i;
	u16 magic = get_magic(dpld);
	u16 access = get_access(dpld);

	if (likely(magic == DPRAM_MAGIC_CODE && access == 1))
		return 0;

	for (i = 1; i <= 10; i++) {
		mif_info("%s: ERR! magic:%X access:%X -> retry:%d\n",
			ld->name, magic, access, i);
		mdelay(1);

		magic = get_magic(dpld);
		access = get_access(dpld);
		if (likely(magic == DPRAM_MAGIC_CODE && access == 1))
			return 0;
	}

	mif_info("%s: !CRISIS! magic:%X access:%X\n", ld->name, magic, access);
	return -EACCES;
}
Exemple #17
0
static void set_dpram_map(struct dpram_link_device *dpld,
	struct mif_irq_map *map)
{
	map->magic = get_magic(dpld);
	map->access = get_access(dpld);

	map->fmt_tx_in = get_tx_head(dpld, IPC_FMT);
	map->fmt_tx_out = get_tx_tail(dpld, IPC_FMT);
	map->fmt_rx_in = get_rx_head(dpld, IPC_FMT);
	map->fmt_rx_out = get_rx_tail(dpld, IPC_FMT);
	map->raw_tx_in = get_tx_head(dpld, IPC_RAW);
	map->raw_tx_out = get_tx_tail(dpld, IPC_RAW);
	map->raw_rx_in = get_rx_head(dpld, IPC_RAW);
	map->raw_rx_out = get_rx_tail(dpld, IPC_RAW);

	map->cp2ap = recv_intr(dpld);
}
/**
@brief		take a snapshot of the current status of a memory interface

Get a memory status and store the status data to @b @@mst

@param mld	the pointer to a mem_link_device instance
@param dir	the direction of a communication (TX or RX)
@param[out] mst	the pointer to a mem_status instance
*/
static void __take_sbd_status(struct mem_link_device *mld, enum direction dir,
			      struct mem_snapshot *mst)
{
	mst->dir = dir;

	mst->magic = get_magic(mld);
	mst->access = get_access(mld);

	if (mld->recv_cp2ap_irq)
		mst->int2ap = mld->recv_cp2ap_irq(mld);
	else
		mst->int2ap = 0;

	if (mld->read_ap2cp_irq)
		mst->int2cp = mld->read_ap2cp_irq(mld);
	else
		mst->int2cp = 0;
}
/**
@brief		function for the @b dload_start method in a link_device instance

Set all flags and environments for CP binary download

@param ld	the pointer to a link_device instance
@param iod	the pointer to an io_device instance
*/
static int mem_start_download(struct link_device *ld, struct io_device *iod)
{
	struct mem_link_device *mld = to_mem_link_device(ld);
	unsigned int magic;

	atomic_set(&mld->cp_boot_done, 0);

	reset_ipc_map(mld);
	reset_ipc_devices(mld);

	set_magic(mld, SHM_BOOT_MAGIC);
	magic = get_magic(mld);
	if (magic != SHM_BOOT_MAGIC) {
		mif_err("%s: ERR! magic 0x%08X != SHM_BOOT_MAGIC 0x%08X\n",
			ld->name, magic, SHM_BOOT_MAGIC);
		return -EFAULT;
	}

	return 0;
}
/**
@brief		check whether or not IPC link is active

@param mld	the pointer to a mem_link_device instance

@retval "TRUE"	if IPC via the mem_link_device instance is possible.
@retval "FALSE"	otherwise.
*/
static inline bool ipc_active(struct mem_link_device *mld)
{
	bool active;
	unsigned int magic = get_magic(mld);
	unsigned int access = get_access(mld);
	bool crash = mld->forced_cp_crash;

	if (magic != MEM_IPC_MAGIC || access != 1 || crash)
		active =  false;
	else
		active = true;

#ifdef DEBUG_MODEM_IF
	if (!active) {
		struct link_device *ld = &mld->link_dev;
		struct modem_ctl *mc = ld->mc;
		mif_err("%s<->%s: ERR! magic:0x%X access:%d crash:%d <%pf>\n",
			ld->name, mc->name, magic, access, crash, CALLER);
	}
#endif

	return active;
}
static void print_pm_status(struct mem_link_device *mld)
{
#ifdef DEBUG_MODEM_IF
	struct link_device *ld = &mld->link_dev;
	unsigned int magic;
	int ap_wakeup;
	int ap_status;
	int cp_wakeup;
	int cp_status;

	magic = get_magic(mld);
	ap_wakeup = gpio_get_value(mld->gpio_ap_wakeup);
	ap_status = gpio_get_value(mld->gpio_ap_status);
	cp_wakeup = gpio_get_value(mld->gpio_cp_wakeup);
	cp_status = gpio_get_value(mld->gpio_cp_status);

	/*
	** PM {ap_wakeup:cp_wakeup:cp_status:ap_status:magic} <CALLER>
	*/
	mif_info("%s: PM {%d:%d:%d:%d:%X} <%pf>\n", ld->name,
		ap_wakeup, cp_wakeup, cp_status, ap_status, magic, CALLER);
#endif
}
int mem_reset_ipc_link(struct mem_link_device *mld)
{
	struct link_device *ld = &mld->link_dev;
	unsigned int magic;
	unsigned int access;

	set_access(mld, 0);
	set_magic(mld, 0);

	reset_ipc_map(mld);
	reset_ipc_devices(mld);

	atomic_set(&ld->netif_stopped, 0);

	set_magic(mld, MEM_IPC_MAGIC);
	set_access(mld, 1);

	magic = get_magic(mld);
	access = get_access(mld);
	if (magic != MEM_IPC_MAGIC || access != 1)
		return -EACCES;

	return 0;
}
int mem_reset_ipc_link(struct mem_link_device *mld)
{
	struct link_device *ld = &mld->link_dev;
	unsigned int magic;
	unsigned int access;
	int i;

	set_access(mld, 0);
	set_magic(mld, 0);

	reset_ipc_map(mld);

	for (i = 0; i < MAX_SIPC5_DEVICES; i++) {
		struct mem_ipc_device *dev = mld->dev[i];

		skb_queue_purge(dev->skb_txq);
		atomic_set(&dev->txq.busy, 0);
		dev->req_ack_cnt[TX] = 0;

		skb_queue_purge(dev->skb_rxq);
		atomic_set(&dev->rxq.busy, 0);
		dev->req_ack_cnt[RX] = 0;
	}

	atomic_set(&ld->netif_stopped, 0);

	set_magic(mld, MEM_IPC_MAGIC);
	set_access(mld, 1);

	magic = get_magic(mld);
	access = get_access(mld);
	if (magic != MEM_IPC_MAGIC || access != 1)
		return -EACCES;

	return 0;
}
void print_pm_status(struct mem_link_device *mld)
{
#if defined(DEBUG_MODEM_IF) && defined(CONFIG_LINK_POWER_MANAGEMENT)
	struct link_device *ld = &mld->link_dev;
	unsigned int magic;
	int ap_wakeup;
	int ap_status;
	int cp_wakeup;
	int cp_status;

	magic = get_magic(mld);
	ap_wakeup = gpio_get_value(mld->gpio_ap_wakeup);
	ap_status = gpio_get_value(mld->gpio_ap_status);
	cp_wakeup = gpio_get_value(mld->gpio_cp_wakeup);
	cp_status = gpio_get_value(mld->gpio_cp_status);

	/*
	** PM {ap_wakeup:cp_wakeup:cp_status:ap_status:magic} <CALLER>
	*/
	mif_info("%s: PM {%d:%d:%d:%d:%X} %d <%pf>\n", ld->name,
		ap_wakeup, cp_wakeup, cp_status, ap_status, magic,
		atomic_read(&mld->ref_cnt), CALLER);
#endif
}
Exemple #25
0
/**
 * \brief Removes some magic points from the player.
 *
 * If the number of magic points reaches zero, no more magic points
 * are removed.
 *
 * \param magic_to_remove Number of magic poits to remove.
 * Must be positive of zero.
 */
void Equipment::remove_magic(int magic_to_remove) {

  Debug::check_assertion(magic_to_remove >= 0, "Invalid magic amount to remove");

  set_magic(get_magic() - magic_to_remove);
}
Exemple #26
0
/**
 * \brief Adds some magic points to the player.
 *
 * If the maximum value is reached, no more magic points are added.
 *
 * \param magic_to_add Number of magic points to add.
 * Must be positive of zero.
 */
void Equipment::add_magic(int magic_to_add) {

  Debug::check_assertion(magic_to_add >= 0, "Invalid magic amount to add");

  set_magic(get_magic() + magic_to_add);
}
Exemple #27
0
void * get_entry(struct LX_module * lx_mod, int entry_ord_to_search,
                                        int * ret_flags,
                                        int * ret_offset,
                                        int * ret_obj,
                                        int * ret_modord,
                                        int * ret_type) {

        enum
        {
          UNUSED_ENTRY_SIZE = 2,
          _16BIT_ENTRY_SIZE = 3,
          ENTRY_HEADER_SIZE = 4, /* For all entries except UNUSED ENTRY.*/
          _286_CALL_GATE_ENTRY_SIZE = 5,
          _32BIT_ENTRY_SIZE         = 5,
          FORWARD_ENTRY_SIZE        = 7
	};
        /* For testing: lx_mod is null and ret_type contains a pointer to some entry table.*/
        int offs_to_entry_tbl;
        struct b32_bundle *entry_table,
                          *prev_entry_table = 0;
        char *cptr_ent_tbl;
        struct e32_entry *entry_post;
        unsigned char * magic;
        char bbuf[3];
        int entry_ord_index;
        int prev_ord_index = 0;
        int unused_entry;
        unsigned long int i_cptr_ent_tbl;
        int elements_in_bundle;

        if(lx_mod != 0) {

                /* Offset to Entry Table inside the Loader Section. */
                offs_to_entry_tbl = lx_mod->lx_head_e32_exe->e32_enttab - lx_mod->lx_head_e32_exe->e32_objtab;

                entry_table = (struct b32_bundle *) &lx_mod->loader_section[offs_to_entry_tbl];
                cptr_ent_tbl = &lx_mod->loader_section[offs_to_entry_tbl];

                magic = get_magic(lx_mod);
                if((magic[0] != 'L') && (magic[1] != 'X')) { /* Invalid module */
                        *ret_type = -1;
                        return (void *)0;
                }

                bbuf[0] = magic[0];
                bbuf[1] = magic[1];
                bbuf[2] = 0;
                /*io_log("magic: %s \n", (char *)&bbuf);
                  io_log("get_entry( lx_mod: %p, entry_ord_to_search: %d \n",
                              lx_mod, entry_ord_to_search); */
        }
        else {
                //io_log("Testing get_entry.\n");
                cptr_ent_tbl = (char*) *ret_type;
                entry_table = (struct b32_bundle *)cptr_ent_tbl;
        }

        entry_ord_index=1;

        /*io_log("entry_table: %p \n", entry_table);*/

      /*io_log(
          "get_entry: entry_ord_to_search: %d, b32_cnt: %d, b32_type: %d, b32_obj: %d\n",
                          entry_ord_to_search,
                         entry_table->b32_cnt, entry_table->b32_type, entry_table->b32_obj);
         */

        /*io_log("EMPTY: %d, ENTRYFWD: %d, _32BIT_ENTRY_SIZE: %d \n",
          EMPTY, ENTRYFWD, _32BIT_ENTRY_SIZE);*/

        unused_entry = 0;
        while(entry_ord_index <= entry_ord_to_search) {
                while (entry_table->b32_type == EMPTY) { /* Unused Entry, just skip over them.*/
                        prev_ord_index = entry_ord_index;
                        entry_ord_index += entry_table->b32_cnt;
                        unused_entry += UNUSED_ENTRY_SIZE;
                        cptr_ent_tbl += UNUSED_ENTRY_SIZE;
                        entry_table = (struct b32_bundle *)cptr_ent_tbl;
                        prev_entry_table = entry_table;
                        io_log("EMPTY, entry_table: %p\n", entry_table);
                }
                io_log("entry_ord_index: %d (0x%x), entry_ord_to_search: %d (0x%x)\n",
                  entry_ord_index,entry_ord_index,
                  entry_ord_to_search,entry_ord_to_search);
                if(entry_ord_to_search < entry_ord_index) {
                        if (prev_ord_index <= entry_ord_to_search)
                        {
                                entry_ord_index = prev_ord_index;
                                entry_table = prev_entry_table;
                                goto sw;
                        }
                        *ret_flags = 0; // Unused entry ==0
                        *ret_offset = 0;
                        *ret_obj = 0;
                        *ret_type = 0;
                        io_log("RET, Can't find entry.\n");
                        io_log("entry_ord_index: %d, entry_ord_to_search: %d\n", entry_ord_index, entry_ord_to_search);
                        return (void *) 0; // Can't find entry.
                }
                if(entry_table->b32_cnt == 0) {
                       //io_log("End of entry table reached! %d, entry_table: %p\n",
                       //                  entry_table->b32_cnt, entry_table);
                                *ret_flags = 0;
                                *ret_offset = 0;
                                *ret_obj = 0;
                                *ret_type = 0;
                                return (void *) 0; /* Invalid entry.*/
                }
        sw:
                switch(entry_table->b32_type) {
                    case EMPTY:;
                    case ENTRYFWD:;
                    case ENTRY32: break;
                        default: io_log("Invalid entry type! %d, entry_table: %p\n",
                                         entry_table->b32_type, entry_table);
                                *ret_flags = 0;
                                *ret_offset = 0;
                                *ret_obj = 0;
                                *ret_type = 0;
                                return (void *) 0; /* Invalid entry.*/
                }


                /*io_log("get_entry,2nd bundle: cnt: %d, type: %d, obj: %d\n",
                                entry_table->b32_cnt, entry_table->b32_type, entry_table->b32_obj);     */
                /* If ordinal to search for is less than present index ordinal and
                   ordinal to search for is less than the number of ordinals plus current index ordinal and
                   the type of bundle is 32-bit entry.
                */
//                if((entry_ord_to_search >= entry_ord_index)
//                   && (entry_ord_to_search<(entry_table->b32_cnt+entry_ord_index))
//                   &&  (entry_table->b32_type == ENTRY32))
                if((entry_ord_to_search <= entry_ord_index)
                   && (entry_ord_index - entry_ord_to_search <= entry_table->b32_cnt)
                   &&  (entry_table->b32_type == ENTRY32))
                { /* 32-bit Entry.*/

                                //io_log("32-bit Entry.\n");
                                cptr_ent_tbl = (char*)entry_table;
                                cptr_ent_tbl += ENTRY_HEADER_SIZE;
                                entry_post = (struct e32_entry *)cptr_ent_tbl;
                                i_cptr_ent_tbl = (unsigned long)cptr_ent_tbl;
                                elements_in_bundle = entry_table->b32_cnt + entry_ord_index;
                                for (entry_ord_index; entry_ord_index < elements_in_bundle; entry_ord_index++) 
				{
                                    io_log("(entry_ord_to_search %d == entry_ord_index %d)\n",
                                              entry_ord_to_search, entry_ord_index);
                                    if (entry_ord_to_search == entry_ord_index)
                                                break;
                                    i_cptr_ent_tbl += _32BIT_ENTRY_SIZE;
                                }
                                /*entry_ord_index += entry_table->b32_cnt;
                                i_cptr_ent_tbl += _32BIT_ENTRY_SIZE*entry_table->b32_cnt;*/

                                cptr_ent_tbl = (char*)i_cptr_ent_tbl;
                                entry_post = (struct e32_entry *)cptr_ent_tbl;
                                //io_log("cptr_ent_tbl: %p \n", cptr_ent_tbl);

                                //io_log("entry_post: %p \n", entry_post);
                                //io_log("32-bit Entry: Flags=0x%x, Offset=%lu \n",
                                //                entry_post->e32_flags, entry_post->e32_variant.e32_offset.offset32);
                                *ret_flags = entry_post->e32_flags;
                                *ret_offset = entry_post->e32_variant.e32_offset.offset32;
                                *ret_obj = entry_table->b32_obj;
                                *ret_type = entry_table->b32_type;
                                return (void *) entry_table;

                } else if (entry_table->b32_type == ENTRY32) { /* Jump over that bundle. */
                        //io_log("ENTRY32\n")
                        cptr_ent_tbl = (char*)entry_table;
                        cptr_ent_tbl += ENTRY_HEADER_SIZE;
                        //prev_ord_index = entry_ord_index;
                        //prev_entry_table = entry_table;
                        i_cptr_ent_tbl = (unsigned long)cptr_ent_tbl;
                        entry_ord_index += entry_table->b32_cnt;
                        i_cptr_ent_tbl += _32BIT_ENTRY_SIZE*entry_table->b32_cnt;

                        cptr_ent_tbl = (char*)i_cptr_ent_tbl;
                        entry_table= (struct b32_bundle *)cptr_ent_tbl;
                        io_log("ENTRY32, entry_table: %p\n", entry_table);
                }

                if((entry_ord_to_search >= entry_ord_index)
                    && (entry_ord_to_search<(entry_table->b32_cnt+entry_ord_index))
                    && (entry_table->b32_type == ENTRYFWD)) { /* Forward Entry.*/
                        //io_log("Forward Entry.\n");
                        cptr_ent_tbl = (char*)entry_table;
                        //io_log("cptr_ent_tbl: %p \n", cptr_ent_tbl);
                        entry_post = (struct e32_entry *)&cptr_ent_tbl[ENTRY_HEADER_SIZE];
                        cptr_ent_tbl = &cptr_ent_tbl[ENTRY_HEADER_SIZE];
                        //io_log("cptr_ent_tbl: %p \n", cptr_ent_tbl);
                                i_cptr_ent_tbl = (unsigned long int)cptr_ent_tbl;
                                elements_in_bundle = entry_table->b32_cnt + entry_ord_index;
                                for (entry_ord_index; entry_ord_index < elements_in_bundle; entry_ord_index++) 
				{
                                    io_log("(entry_ord_to_search %d == entry_ord_index %d)\n",
                                                        entry_ord_to_search, entry_ord_index);
                                    if (entry_ord_to_search == entry_ord_index)
                                           break;
                                    i_cptr_ent_tbl += FORWARD_ENTRY_SIZE;
                                }
                                cptr_ent_tbl = (char*)i_cptr_ent_tbl;
                                entry_post = (struct e32_entry *)cptr_ent_tbl;
                        io_log("entry_post: %p \n", entry_post);
                        io_log("Forward Entry: Flags=0x%x, Proc name offset or ordinal=%lu, Module ordinal number: %d \n",
                                        entry_post->e32_flags,
                                        entry_post->e32_variant.e32_fwd.value,
                                        entry_post->e32_variant.e32_fwd.modord);
                                 /* Flags */
                        *ret_flags = entry_post->e32_flags;
                         /* Procedure Name Offset or Import Ordinal Number */
                        *ret_offset = entry_post->e32_variant.e32_fwd.value;
                                /* Module ordinal */
                        *ret_modord = entry_post->e32_variant.e32_fwd.modord;
                                /* Not used */
                        *ret_obj = entry_table->b32_obj;
                                /* Entry type*/
                        *ret_type = entry_table->b32_type;
                         /* unsigned short  modord;     / Module ordinal number
                unsigned long   value;      / Proc name offset or ordinal

                                e32_fwd;        / Forwarder */
                        return (void *) entry_table;
                } else if(entry_table->b32_type == ENTRYFWD) { /* Jump over the that bundle. */
                    //io_log("ENTRYFWD\n");

                        cptr_ent_tbl = (char*)entry_table;
                        //io_log("cptr_ent_tbl: %p\n", cptr_ent_tbl);
                        cptr_ent_tbl = &cptr_ent_tbl[ENTRY_HEADER_SIZE];
                        //io_log("cptr_ent_tbl: %p\n", cptr_ent_tbl);
                        i_cptr_ent_tbl = (unsigned long int)cptr_ent_tbl;
                        entry_ord_index += entry_table->b32_cnt;
                        //io_log("FORWARD_ENTRY_SIZE: %d, entry_table->b32_cnt: %d\n", FORWARD_ENTRY_SIZE, entry_table->b32_cnt);
                        i_cptr_ent_tbl += FORWARD_ENTRY_SIZE*entry_table->b32_cnt;

                        cptr_ent_tbl = (char*)i_cptr_ent_tbl;
                        entry_table= (struct b32_bundle *)cptr_ent_tbl;
                        //io_log("ENTRYFWD, entry_table: %p\n", entry_table);
                }

        }
        //io_log("RET, get_entry()\n");
        return (void *) entry_table;
}
Exemple #28
0
/**
 * \brief Adds some magic points to the player.
 *
 * If the maximum value is reached, no more magic points are added.
 * 
 * \param magic_to_add number of magic points to add
 */
void Equipment::add_magic(int magic_to_add) {

  set_magic(get_magic() + magic_to_add);
}
Exemple #29
0
/**
 * \brief Removes some magic points from the player.
 *
 * If the number of magic points reaches zero, no more magic points
 * are removed.
 *
 * \param magic_to_remove number of magic poits to remove
 */
void Equipment::remove_magic(int magic_to_remove) {

  set_magic(get_magic() - magic_to_remove);
}