Exemplo n.º 1
0
int do_exit(long code)
{
	int i;

	free_page_tables(get_base(current->ldt[1]),get_limit(0x0f));
	free_page_tables(get_base(current->ldt[2]),get_limit(0x17));
	for (i=0 ; i<NR_TASKS ; i++)
		if (task[i] && task[i]->father == current->pid)
			task[i]->father = 0;
	for (i=0 ; i<NR_OPEN ; i++)
		if (current->filp[i])
			sys_close(i);
	iput(current->pwd);
	current->pwd=NULL;
	iput(current->root);
	current->root=NULL;
	if (current->leader && current->tty >= 0)
		tty_table[current->tty].pgrp = 0;
	if (last_task_used_math == current)
		last_task_used_math = NULL;
	if (current->father) {
		current->state = TASK_ZOMBIE;
		do_kill(current->father,SIGCHLD,1);
		current->exit_code = code;
	} else
		release(current);
	schedule();
	return (-1);	/* just to suppress warnings */
}
Exemplo n.º 2
0
Arquivo: traps.c Projeto: hhxu/hhxu
static void die(char * str,long esp_ptr,long nr)
{
	long * esp = (long *) esp_ptr;
	int i;

	printk("%s: %04x\n\r",str,nr&0xffff);
	printk("EIP:\t%04x:%p\nEFLAGS:\t%p\nESP:\t%04x:%p\n",
		esp[1],esp[0],esp[2],esp[4],esp[3]);
	printk("fs: %04x\n",_fs());
	printk("code base: %p, limit: %p\n",get_base(current->ldt[1]),get_limit(0x17));
	printk("data base: %p, limit: %p\n",get_base(current->ldt[2]),get_limit(0x17));	
	long line = get_base(current->ldt[1])+esp[0];
	long ph0 = (*(long *)(current->tss.cr3 + ((line>>20) & 0xffc )));
	long ph1 = *(long*)(((line>>10) & 0xffc)+(*(long *)(current->tss.cr3 + ((line>>20) & 0xffc ))));
	printk("line: %p, ph: %p  %p\n",line,ph0,ph1);
	if (esp[4] == 0x17) {
		printk("Stack: ");
		for (i=0;i<4;i++)
			printk("%p ",get_seg_long(0x17,i+(long *)esp[3]));
		printk("\n");
	}
	str(i);
	printk("Pid: %d, process nr: %d\n\r",current->pid,0xffff & i);
	for(i=0;i<10;i++)
		printk("%02x ",0xff & get_seg_byte(esp[1],(i+(char *)esp[0])));
	printk("\n\r");
	do_exit(11);		/* play segment exception */
}
Exemplo n.º 3
0
////复制父进程的地址空间
static int copy_mem(int pid,struct task_struct *p)
{
    struct descriptor *dp = &proc_table[pid].ldts[INDEX_LDT_C];
    int text_base = get_base(dp);
    int text_limit = get_limit(dp);
    int text_size = (text_limit + 1) * ((dp->limit_high_attr2 * 0x80)?4096:1);

    dp = &proc_table[pid].ldts[INDEX_LDT_D]; 
    int data_base =  get_base(dp);
    int data_limit= get_limit(dp);
    int data_size = (text_limit + 1) * ((dp->limit_high_attr2 * 0x80)?4096:1);

    assert((text_base == data_base)  && 
            (text_limit == data_limit) &&
            (text_size == data_size)
          );

    int child_base = alloc_mem(p->pid,text_size);

    //	printk("child_base = %d\t text_base = %d\t text_size = %d\n",child_base,text_base,text_size);
    //	memcpy((void *)child_base,(void *)(text_base),text_size);

    //	printk("child_base = %d\t text_base = %d\t text_size = %d\n",child_base,text_base,text_size);
    phys_copy((char *)child_base,(char *)(text_base),text_size);
    return child_base;
}
Exemplo n.º 4
0
TIMESTAMP collector::commit(TIMESTAMP t0, TIMESTAMP t1)
{
	TIMESTAMP dt = (TIMESTAMP)get_interval();
	if ( dt==0 || ( t1==next_t && next_t!=TS_NEVER ) )
	{
		char buffer[4096];
		size_t eos = sprintf(buffer,"INSERT INTO `%s` (t", get_table());
		int n;
		for ( n=0 ; n<n_aggregates ; n++ )
			eos += sprintf(buffer+eos,",`%s`",names[n]);
		eos += sprintf(buffer+eos,") VALUES (from_unixtime(%lli)",gl_globalclock);
		for ( n=0 ; n<n_aggregates ; n++ )
			eos += sprintf(buffer+eos,",%g",list[n].get_value());
		sprintf(buffer+eos,"%s",")");

		if ( !db->query(buffer) )
			exception("unable to add data to '%s' - %s", get_table(), mysql_error(mysql));
		else
			gl_verbose("%s: sample added to '%s' ok", get_name(), get_table());

		// check limit
		if ( get_limit()>0 && db->get_last_index()>=get_limit() )
		{
			gl_verbose("%s: limit of %d records reached", get_name(), get_limit());
			next_t = TS_NEVER;
		}
		else
		{
			next_t = (dt==0 ? TS_NEVER : (TIMESTAMP)(t1/dt+1)*dt);
		}
		set_clock(t1);
	}
	return TS_NEVER;
}
Exemplo n.º 5
0
Arquivo: exit.c Projeto: gozfree/src
int do_exit(long code)
{
	int i;

	free_page_tables(get_base(current->ldt[1]),get_limit(0x0f));
	free_page_tables(get_base(current->ldt[2]),get_limit(0x17));
	for (i=0 ; i<NR_TASKS ; i++)
		if (task[i] && task[i]->father == current->pid) {
			task[i]->father = 1;
			if (task[i]->state == TASK_ZOMBIE)
				/* assumption task[1] is always init */
				(void) send_sig(SIGCHLD, task[1], 1);
		}
	for (i=0 ; i<NR_OPEN ; i++)
		if (current->filp[i])
			sys_close(i);
	iput(current->pwd);
	current->pwd=NULL;
	iput(current->root);
	current->root=NULL;
	iput(current->executable);
	current->executable=NULL;
	if (current->leader && current->tty >= 0)
		tty_table[current->tty].pgrp = 0;
	if (last_task_used_math == current)
		last_task_used_math = NULL;
	if (current->leader)
		kill_session();
	current->state = TASK_ZOMBIE;
	current->exit_code = code;
	tell_father(current->father);
	schedule();
	return (-1);	/* just to suppress warnings */
}
Exemplo n.º 6
0
int do_exit(long code)
{
	int i;
	// TODO 待看页表
	free_page_tables(get_base(current->ldt[1]),get_limit(0x0f));
	free_page_tables(get_base(current->ldt[2]),get_limit(0x17));
	/*
	 * 找出所有子进程,将它们的父亲设为 init 进程,将状态标记为僵尸
	 * 然后给 init 进程发送一个 SIGCHLD 信号,提醒 init 进程回收子进程
	 */
	for (i=0 ; i<NR_TASKS ; i++)
		if (task[i] && task[i]->father == current->pid) {
			task[i]->father = 1;
			if (task[i]->state == TASK_ZOMBIE)
				/* assumption task[1] is always init */
				// 最后一个参数 1 代表 privilege,此处为强制发送
				(void) send_sig(SIGCHLD, task[1], 1);
		}
	// TODO 关闭文件?
	/*
	 * NR_OPEN 是一个进程可以打开的最大文件数
	 * 而 NR_FILE 是系统在某时刻的限制文件总数
	 */
	for (i=0 ; i<NR_OPEN ; i++)
		if (current->filp[i])
			sys_close(i);
	// 进程的当前工作目录 inode
	iput(current->pwd);
	current->pwd=NULL;
	// 进程的根目录 inode
	iput(current->root);
	current->root=NULL;
	// 进程本身可执行文件的 inode
	iput(current->executable);
	current->executable=NULL;
	if (current->leader && current->tty >= 0)
		tty_table[current->tty].pgrp = 0;
	if (last_task_used_math == current)
		last_task_used_math = NULL;
	/*
	 * 如果是 session leader 会话领头进程,则向该会话所有进程发送 SIGHUP 信号
	 * PID, PPID, PGID, SID
	 * http://unix.stackexchange.com/questions/18166/what-are-session-leaders-in-ps
	 * 在同一次 ssh 会话中,用户对应的 shell 最先被启动,成为 session leader,
	 * 所有在同一次会话中产生的进程 session id 都等于这个 session leader 的 pid
	 * 当 session leader 退出时,它会向所有同一 session 中的进程发送 SIGHUP,
	 * 这个信号是可以被捕获的,如果进程忽略这个 SIGHUP,它则可以以一个孤儿进程继续执行
	 * http://www.firefoxbug.com/index.php/archives/2782/
	 */
	if (current->leader)
		kill_session();
	// 将自己设为僵尸,设置退出状态码,同时告诉父进程回收子进程
	current->state = TASK_ZOMBIE;
	current->exit_code = code;
	tell_father(current->father);
	// 如果 tell_father 中找不到父进程,自己把自己释放掉了,那也不会有机会继续执行下面代码了
	schedule();
	return (-1);	/* just to suppress warnings */
}
Exemplo n.º 7
0
// 该子程序用来打印出错中断的名称、出错号、调用程序的EIP、EFLAGS、ESP、fs段寄存器值、
// 段的基址、段的长度、进程号PID、任务号、10字节指令码。如果堆栈在用户数据段,则还
// 打印16字节的堆栈内容。
static void die(char * str,long esp_ptr,long nr)
{
	long * esp = (long *) esp_ptr;
	int i;

	printk("%s: %04x\n\r",str,nr&0xffff);
    // 下行打印语句显示当前调用进程的CS:EIP、EFLAGS和SS:ESP的值。
    // EIP:\t%04x:%p\n - esp[1]是段选择符(cs),esp[0]是eip.
    // EFLAGS:\t%p\n - esp[2]是eflags
    // ESP:\t%04x:%p\n - esp[4]是源ss,esp[3]是源esp
	printk("EIP:\t%04x:%p\nEFLAGS:\t%p\nESP:\t%04x:%p\n",
		esp[1],esp[0],esp[2],esp[4],esp[3]);
	printk("fs: %04x\n",_fs());
	printk("base: %p, limit: %p\n",get_base(current->ldt[1]),get_limit(0x17));
	if (esp[4] == 0x17) {
		printk("Stack: ");
		for (i=0;i<4;i++)
			printk("%p ",get_seg_long(0x17,i+(long *)esp[3]));
		printk("\n");
	}
	str(i);                 // 取当前运行任务的任务号
	printk("Pid: %d, process nr: %d\n\r",current->pid,0xffff & i);
	for(i=0;i<10;i++)
		printk("%02x ",0xff & get_seg_byte(esp[1],(i+(char *)esp[0])));
	printk("\n\r");
	do_exit(11);		/* play segment exception */
}
Exemplo n.º 8
0
// 该子程序用来打印出错中断的名称、出错号、调用程序的EIP、EFLAGS、ESP、fs寄存器值、
// 段的基址、段的长度、进程号pid、任务号、10字节指令码。如果堆栈在用户数据段,则还
// 打印16字节的堆栈内容。
static void die(char * str,long esp_ptr,long nr)
{
	long * esp = (long *) esp_ptr;
	int i;

	printk("%s: %04x\n\r",str,nr&0xffff);
// 下行打印语句显示当前调用进程的CS:EIP、EFLAGS和SS:ESP的值。参照图8-4,这里esp[0]即为
// 图中的esp0位置。因此我们把这句拆分开来看为:
// 1)EIP:\t%04x:%p\n	--	esp[1]是段选择符(cs),esp[0]是eip
// 2)EFLAGS:\t%p		--	esp[2]是EFLAGS
// 3)ESP:\t%04x:%p\n	--	esp[4]是原ss,esp[3]是原esp
	printk("EIP:\t%04x:%p\nEFLAGS:\t%p\nESP:\t%04x:%p\n",
		esp[1],esp[0],esp[2],esp[4],esp[3]);
	printk("fs: %04x\n",_fs());
	printk("base: %p, limit: %p\n",get_base(current->ldt[1]),get_limit(0x17));
	if (esp[4] == 0x17) {
		printk("Stack: ");
		for (i=0;i<4;i++)
			printk("%p ",get_seg_long(0x17,i+(long *)esp[3]));
		printk("\n");
	}
	str(i);						// 取当前运行任务的任务号(include/linux/sched.h 159)
	printk("Pid: %d, process nr: %d\n\r",current->pid,0xffff & i);
	for(i=0;i<10;i++)
		printk("%02x ",0xff & get_seg_byte(esp[1],(i+(char *)esp[0])));
	printk("\n\r");
	do_exit(11);		/* play segment exception */
}
Exemplo n.º 9
0
static int
dccrecv_cb (char *word[], void *userdata)
{
	int result;
	struct stat64 buffer;									/* buffer for storing file info */
	char sum[65];											/* buffer for checksum */

	result = stat64 (word[2], &buffer);
	if (result == 0)										/* stat returns 0 on success */
	{
		if (buffer.st_size <= (unsigned long long) get_limit () * 1048576)
		{
			sha256_file (word[2], sum);						/* word[2] is the full filename */
			/* try to print the checksum in the privmsg tab of the sender */
			xchat_set_context (ph, xchat_find_context (ph, NULL, word[3]));
			xchat_printf (ph, "SHA-256 checksum for %s (local):  %s\n", word[1], sum);
		}
		else
		{
			xchat_set_context (ph, xchat_find_context (ph, NULL, word[3]));
			xchat_printf (ph, "SHA-256 checksum for %s (local):  (size limit reached, no checksum calculated, you can increase it with /CHECKSUM INC)\n", word[1]);
		}
	}
	else
	{
		xchat_printf (ph, "File access error!\n");
	}

	return XCHAT_EAT_NONE;
}
Exemplo n.º 10
0
int main(int argc, char *argv[])
{

	
	strcpy(act_info.prog_id,argv[0]);	
        //creep_capacity = 10;
   // strcpy(act_info.prog_id,argv[0]);
	strcpy(date, argv[1]);	
	init_prog();
        printf("here\n");
	get_unit_info();

	
	get_limit();
	check();
	init_to_downlimit_power();
	print_unit("用最小出力初始化电厂出力后打印");
	
	cal_unit_gen();	
	
	printf("\n\n\n");
	

	
    //write_act_info( 1, "执行定电量负荷分配程序成功");
	free_memory();	
    close_database();



	printf("\n\n");
}
Exemplo n.º 11
0
static int
dccoffer_cb (char *word[], void *userdata)
{
	int result;
	struct stat buffer;									/* buffer for storing file info */
	char sum[65];											/* buffer for checksum */

	result = stat (word[3], &buffer);
	if (result == 0)										/* stat returns 0 on success */
	{
		if (buffer.st_size <= (unsigned long long) get_limit () * 1048576)
		{
			sha256_file (word[3], sum);						/* word[3] is the full filename */
			hexchat_commandf (ph, "quote PRIVMSG %s :SHA-256 checksum for %s (remote): %s", word[2], word[1], sum);
		}
		else
		{
			hexchat_set_context (ph, hexchat_find_context (ph, NULL, word[3]));
			hexchat_printf (ph, "quote PRIVMSG %s :SHA-256 checksum for %s (remote): (size limit reached, no checksum calculated)", word[2], word[1]);
		}
	}
	else
	{
		hexchat_printf (ph, "File access error!\n");
	}

	return HEXCHAT_EAT_NONE;
}
Exemplo n.º 12
0
int get_num_of_blocks (int all) {
    int limit = get_limit();
    int num_of_blocks = 0;
    if ((all%limit) == 0) num_of_blocks = all/limit;
    else num_of_blocks = all/limit + 1;
    return num_of_blocks;
}
Exemplo n.º 13
0
//// 程序退出处理程序。在系统调用的中断处理程序中被调用。
int
do_exit (long code)		// code 是错误码。
{
  int i;

// 释放当前进程代码段和数据段所占的内存页(free_page_tables()在mm/memory.c,105 行)。
  free_page_tables (get_base (current->ldt[1]), get_limit (0x0f));
  free_page_tables (get_base (current->ldt[2]), get_limit (0x17));
// 如果当前进程有子进程,就将子进程的father 置为1(其父进程改为进程1)。如果该子进程已经
// 处于僵死(ZOMBIE)状态,则向进程1 发送子进程终止信号SIGCHLD。
  for (i = 0; i < NR_TASKS; i++)
    if (task[i] && task[i]->father == current->pid)
      {
	task[i]->father = 1;
	if (task[i]->state == TASK_ZOMBIE)
/* assumption task[1] is always init */
	  (void) send_sig (SIGCHLD, task[1], 1);
      }
// 关闭当前进程打开着的所有文件。
  for (i = 0; i < NR_OPEN; i++)
    if (current->filp[i])
      sys_close (i);
// 对当前进程工作目录pwd、根目录root 以及运行程序的i 节点进行同步操作,并分别置空。
  iput (current->pwd);
  current->pwd = NULL;
  iput (current->root);
  current->root = NULL;
  iput (current->executable);
  current->executable = NULL;
// 如果当前进程是领头(leader)进程并且其有控制的终端,则释放该终端。
  if (current->leader && current->tty >= 0)
    tty_table[current->tty].pgrp = 0;
// 如果当前进程上次使用过协处理器,则将last_task_used_math 置空。
  if (last_task_used_math == current)
    last_task_used_math = NULL;
// 如果当前进程是leader 进程,则终止所有相关进程。
  if (current->leader)
    kill_session ();
// 把当前进程置为僵死状态,并设置退出码。
  current->state = TASK_ZOMBIE;
  current->exit_code = code;
// 通知父进程,也即向父进程发送信号SIGCHLD -- 子进程将停止或终止。
  tell_father (current->father);
  schedule ();			// 重新调度进程的运行。
  return (-1);			/* just to suppress warnings */
}
Exemplo n.º 14
0
bool check_limits( TRAP_DATA *trap, CHAR_DATA *ch )
{
	int limit_dex = 0, limit_skill = 0, limit_level = 0;

	if ( trap->limit == 0 )
		return TRUE;

	limit_skill = get_limit( trap, LIMIT_SKILL );
	limit_dex = get_limit( trap, LIMIT_DEX );
	limit_level = get_limit( trap, LIMIT_LEVEL );

	if ( limit_level > ch->level ||
	     limit_skill > get_skill( ch, gsn_disarm_traps ) ||
	     limit_dex > get_curr_stat_deprecated( ch, STAT_DEX ) )
		return FALSE;

	return TRUE;
}
Exemplo n.º 15
0
int sys_munmap(unsigned long addr, size_t len)
{
	unsigned long base, limit;

	base = get_base(current->ldt[2]);	/* map into ds */
	limit = get_limit(0x17);		/* ds limit */

	if ((addr & 0xfff) || addr > 0x7fffffff || addr == 0 ||
	    addr + len > limit)
		return -EINVAL;
	if (unmap_page_range(base + addr, len))
		return -EAGAIN; /* should never happen */
	return 0;
}
Exemplo n.º 16
0
// 设置新任务的代码和数据段基址、限长并复制页表。
// nr 为新任务号;p 是新任务数据结构的指针。
int copy_mem (int nr, struct task_struct *p)
{
	unsigned long old_data_base, new_data_base, data_limit;
	unsigned long old_code_base, new_code_base, code_limit;

	code_limit = get_limit (0x0f);	// 取局部描述符表中代码段描述符项中段限长。
	data_limit = get_limit (0x17);	// 取局部描述符表中数据段描述符项中段限长。
	old_code_base = get_base (current->ldt[1]);	// 取原代码段基址。
	old_data_base = get_base (current->ldt[2]);	// 取原数据段基址。
	if (old_data_base != old_code_base)	// 0.11 版不支持代码和数据段分立的情况。
		panic ("We don't support separate I&D");
	if (data_limit < code_limit)	// 如果数据段长度 < 代码段长度也不对。
		panic ("Bad data_limit");
	new_data_base = new_code_base = nr * 0x4000000;	// 新基址=任务号*64Mb(任务大小)。
	p->start_code = new_code_base;
	set_base (p->ldt[1], new_code_base);	// 设置代码段描述符中基址域。
	set_base (p->ldt[2], new_data_base);	// 设置数据段描述符中基址域。
	if (copy_page_tables (old_data_base, new_data_base, data_limit))
    {				// 复制代码和数据段。
		free_page_tables (new_data_base, data_limit);	// 如果出错则释放申请的内存。
		return -ENOMEM;
    }
	return 0;
}
Exemplo n.º 17
0
int nm_read_query(CONTEXT *ctx)
{
    notmuch_query_t *q;
    struct nm_ctxdata *data;
    int rc = -1;

    if (init_context(ctx) != 0)
        return -1;

    data = get_ctxdata(ctx);
    if (!data)
        return -1;

    dprint(1, (debugfile, "nm: reading messages...[current count=%d]\n",
               ctx->msgcount));

    nm_progress_reset(ctx);

    q = get_query(data, FALSE);
    if (q) {
        switch(get_query_type(data)) {
        case NM_QUERY_TYPE_MESGS:
            read_mesgs_query(ctx, q, 0);
            break;
        case NM_QUERY_TYPE_THREADS:
            read_threads_query(ctx, q, 0, get_limit(data));
            break;
        }
        notmuch_query_destroy(q);
        rc = 0;

    }

    if (!is_longrun(data))
        release_db(data);

    ctx->mtime = time(NULL);

    mx_update_context(ctx, ctx->msgcount);
    data->oldmsgcount = 0;

    dprint(1, (debugfile, "nm: reading messages... done [rc=%d, count=%d]\n",
               rc, ctx->msgcount));
    return rc;
}
Exemplo n.º 18
0
static int
dccrecv_cb (char *word[], void *userdata)
{
	int result;
	struct stat buffer;									/* buffer for storing file info */
	char sum[65];											/* buffer for checksum */
	const char *file;
	char *cfile;

	if (hexchat_get_prefs (ph, "dcc_completed_dir", &file, NULL) == 1 && file[0] != 0)
	{
		cfile = g_strconcat (file, G_DIR_SEPARATOR_S, word[1], NULL);
	}
	else
	{
		cfile = g_strdup(word[2]);
	}

	result = stat (cfile, &buffer);
	if (result == 0)										/* stat returns 0 on success */
	{
		if (buffer.st_size <= (unsigned long long) get_limit () * 1048576)
		{
			sha256_file (cfile, sum);						/* file is the full filename even if completed dir set */
			/* try to print the checksum in the privmsg tab of the sender */
			hexchat_set_context (ph, hexchat_find_context (ph, NULL, word[3]));
			hexchat_printf (ph, "SHA-256 checksum for %s (local):  %s\n", word[1], sum);
		}
		else
		{
			hexchat_set_context (ph, hexchat_find_context (ph, NULL, word[3]));
			hexchat_printf (ph, "SHA-256 checksum for %s (local):  (size limit reached, no checksum calculated, you can increase it with /CHECKSUM INC)\n", word[1]);
		}
	}
	else
	{
		hexchat_printf (ph, "File access error!\n");
	}

	g_free (cfile);
	return HEXCHAT_EAT_NONE;
}
Exemplo n.º 19
0
static void read_mesgs_query(CONTEXT *ctx, notmuch_query_t *q, int dedup)
{
    struct nm_ctxdata *data = get_ctxdata(ctx);
    int limit;
    notmuch_messages_t *msgs;

    if (!data)
        return;

    limit = get_limit(data);

    for (msgs = notmuch_query_search_messages(q);
            notmuch_messages_valid(msgs) &&
            (limit == 0 || ctx->msgcount < limit);
            notmuch_messages_move_to_next(msgs)) {

        notmuch_message_t *m = notmuch_messages_get(msgs);
        append_message(ctx, q, m, dedup);
        notmuch_message_destroy(m);
    }
}
Exemplo n.º 20
0
static void read_threads_query(CONTEXT *ctx, notmuch_query_t *q)
{
	struct nm_ctxdata *data = get_ctxdata(ctx);
	int limit;
	notmuch_threads_t *threads;

	if (!data)
		return;

	limit = get_limit(data);

	for (threads = notmuch_query_search_threads(q);
	     notmuch_threads_valid(threads) &&
		(limit == 0 || ctx->msgcount < limit);
	     notmuch_threads_move_to_next(threads)) {

		notmuch_thread_t *thread = notmuch_threads_get(threads);
		append_thread(ctx, thread);
		notmuch_thread_destroy(thread);
	}
}
Exemplo n.º 21
0
Arquivo: emu.c Projeto: aunali1/exopc
int emu_leave(unsigned char *lina)
{
    if (opa.pe) {
	u_int base = get_base(REG(ss));
	if (REG(ebp) < base || REG(ebp) > base + get_limit(REG(ss))) {
	    set_guest_exc(EXC_SS, 0);
	    return -1;
	}
    } else {
	if (REG(ebp)>0xffff) {
	    set_guest_exc(EXC_GP, 0);
	    return -1;
	}
    }

    REG(esp) = REG(ebp);
    if (get_memory(REG(ss), REG(esp), &REG(ebp), opa.opb))
	return -1;

    REG(eip) ++;
    return 0;
}
Exemplo n.º 22
0
static void die(char * str,long esp_ptr,long nr)
{
	long * esp = (long *) esp_ptr;
	int i;

	printk("%s: %04x\n\r",str,nr&0xffff);
	printk("EIP:\t%04x:%p\nEFLAGS:\t%p\nESP:\t%04x:%p\n",
		esp[1],esp[0],esp[2],esp[4],esp[3]);
	printk("fs: %04x\n",_fs());
	printk("base: %p, limit: %p\n",get_base(current->ldt[1]),get_limit(0x17));
	if (esp[4] == 0x17) {
		printk("Stack: ");
		for (i=0;i<4;i++)
			printk("%p ",get_seg_long(0x17,i+(long *)esp[3]));
		printk("\n");
	}
	str(i);
	printk("Pid: %d, process nr: %d\n\r",current->pid,0xffff & i);
	for(i=0;i<10;i++)
		printk("%02x ",0xff & get_seg_byte(esp[1],(i+(char *)esp[0])));
	printk("\n\r");
	do_exit(11);		/* play segment exception */
}
Exemplo n.º 23
0
TIMESTAMP recorder::commit(TIMESTAMP t0, TIMESTAMP t1)
{
	// check trigger
	if ( trigger_on )
	{
		// trigger condition
		if ( target.compare(compare_op,compare_val) )
		{
			// disable trigger and enable data collection
			trigger_on = false;
			enabled = true;
		}
#ifdef _DEBUG
		else
		{
			char buffer[1024];
			target.to_string(buffer,sizeof(buffer));
			gl_verbose("trigger %s.%s not activated - '%s %s %s' did not pass", get_name(), get_property(), buffer, compare_op,compare_val);
		}
#endif
	}

	// collect data
	if ( enabled )
	{
		// convert data
		bool have_data = false;
		if ( target.is_double() )
		{
			real = target.get_double()*scale;
			gl_verbose("%s sampling: %s=%g", get_name(), target.get_name(), real);
			have_data = true;
		}
		else if ( target.is_integer() ) 
		{
			integer = target.get_integer();
			gl_verbose("%s sampling: %s=%lli", get_name(), target.get_name(), integer);
			have_data = true;
		}
		else if ( db->get_sqldata(string,sizeof(string)-1,target) )
		{
			gl_verbose("%s sampling: %s='%s'", get_name(), target.get_name(), (const char*)string);
			have_data = true;
		}
		else
		{
			gl_verbose("%s sampling: unable to sample %s", get_name(), target.get_name());
			have_data = false;
		}

		if ( have_data )
		{
			// use prepared statement if possible
			if ( insert )
			{
				if ( mysql_stmt_execute(insert)!=0 || stmt_error || mysql_stmt_affected_rows(insert)==0 )
				{
					int64 n = mysql_stmt_affected_rows(insert);
					gl_warning("unable to execute insert statement for target '%s' (%s) - reverting to slower INSERT", target.get_name(), mysql_stmt_error(insert));
					mysql_stmt_close(insert);
					insert = NULL;

					// if insert totally failed to add the row
					if ( n==0 )
						goto Insert;
				}
			}

			// use slower INSERT statement
			else
			{
Insert:
				// send data
				if ( target.is_double() )
				{
					db->query("INSERT INTO `%s` (t, `%s`) VALUES (from_unixtime('%"FMT_INT64"d'), '%.8g')",
						get_table(), (const char*)field, gl_globalclock, real);
				}
				else if ( target.is_integer() )
				{
					db->query("INSERT INTO `%s` (t, `%s`) VALUES (from_unixtime('%"FMT_INT64"d'), '%lli')",
						get_table(), (const char*)field, gl_globalclock, integer);
				}
				else{
					db->query("INSERT INTO `%s` (t, `%s`) VALUES (from_unixtime('%"FMT_INT64"d'), '%s')",
						get_table(), (const char*)field, gl_globalclock, (const char*)string);
				}
			}

			// check limit
			if ( get_limit()>0 && db->get_last_index()>=get_limit() )
			{
				// shut off recorder
				enabled=false;
				gl_verbose("table '%s' size limit %d reached", get_table(), get_limit());
			}
		}
	}
	
	return TS_NEVER;
}
Exemplo n.º 24
0
long sys_timer_create(clockid_t clockid,struct sigevent *evp,
                      posixid_t *timerid)
{
  task_t *caller=current_task(), *target=NULL;
  posix_stuff_t *stuff;
  struct sigevent kevp;
  long id,r;
  posix_timer_t *ptimer=NULL;
  ksiginfo_t *ksiginfo;

  if( !s_check_system_capability(SYS_CAP_TIMER) ) {
    return ERR(-EPERM);
  }

  if( clockid != CLOCK_REALTIME ) {
    return ERR(-EINVAL);
  }

  if( evp ) {
    if( copy_from_user(&kevp,evp,sizeof(kevp)) ) {
      return ERR(-EFAULT);
    }
    if( !posix_validate_sigevent(&kevp) ) {
      return ERR(-EINVAL);
    }
  } else {
    INIT_SIGEVENT(kevp);
  }

  ptimer=memalloc(sizeof(*ptimer));
  if( !ptimer ) {
    return ERR(-ENOMEM);
  }

  memset(ptimer,0,sizeof(*ptimer));
  stuff=caller->posix_stuff;

  LOCK_POSIX_STUFF_W(stuff);
  r=-EAGAIN;
  if( ++stuff->timers > get_limit(caller->limits, LIMIT_TIMERS) ) {
    goto out;
  }
  id=posix_allocate_obj_id(stuff);
  if( id < 0 ) {
    goto out;
  }
  UNLOCK_POSIX_STUFF_W(stuff);

  if( !evp ) {
    kevp.sigev_value.sival_int=id;
  }

  POSIX_KOBJ_INIT(&ptimer->kpo,POSIX_OBJ_TIMER,id);
  init_timer(&ptimer->ktimer,0,DEF_ACTION_SIGACTION);
  ptimer->ktimer.da.kern_priv=ptimer;
  ptimer->overrun=0;

  ksiginfo=&ptimer->ktimer.da.d.siginfo;
  siginfo_initialize(current_task(), &ksiginfo->user_siginfo);
  ksiginfo->user_siginfo.si_signo=kevp.sigev_signo;
  ksiginfo->user_siginfo.si_value=kevp.sigev_value;

  switch( kevp.sigev_notify ) {
    case SIGEV_SIGNAL_THREAD:
      target=lookup_task(current_task()->pid,kevp.tid,0);
      if( !target ) {
        r=-ESRCH;
        goto free_id;
      }

#ifdef CONFIG_DEBUG_TIMERS
      kprintf_fault("sys_timer_create() [%d:%d] timer %d will target task %d:%d by signal %d\n",
                    current_task()->pid,current_task()->tid,
                    id,target->pid,target->tid);
#endif

      ksiginfo->target=target;
      break;
  }

  if( copy_to_user(timerid,&id,sizeof(id)) ) {
    r=-EFAULT;
    goto free_target;
  }

  LOCK_POSIX_STUFF_W(stuff);
  posix_insert_object(stuff,&ptimer->kpo,id);
  stuff->timers++;
  UNLOCK_POSIX_STUFF_W(stuff);

#ifdef CONFIG_DEBUG_TIMERS
  kprintf_fault("sys_timer_create() [%d:%d] created POSIX timer (%p) N %d %p\n",
                current_task()->pid,current_task()->tid,ptimer,id,
                &ptimer->ktimer);
#endif

  return 0;
free_target:
  if( target ) {
    release_task_struct(target);
  }
free_id:
  LOCK_POSIX_STUFF_W(stuff);
  posix_free_obj_id(stuff,id);
out:
  stuff->timers--;
  UNLOCK_POSIX_STUFF_W(stuff);

  if( ptimer ) {
    memfree(ptimer);
  }
  return ERR(r);
}
Exemplo n.º 25
0
	limited_value_range(void)
	 : limited_value_range(get_limit(identity<_lv_t>()).value())
	{ }
Exemplo n.º 26
0
int sys_mmap(unsigned long *buffer)
{
	unsigned long base, addr;
	unsigned long len, limit, off;
	int prot, flags, mask, fd, error;
	struct file *file;

	addr = (unsigned long)	get_fs_long(buffer);	/* user address space*/
	len = (size_t)		get_fs_long(buffer+1);	/* nbytes of mapping */
	prot = (int)		get_fs_long(buffer+2);	/* protection */
	flags = (int)		get_fs_long(buffer+3);	/* mapping type */
	fd = (int) 		get_fs_long(buffer+4);	/* object to map */
	off = (unsigned long)	get_fs_long(buffer+5);	/* offset in object */

	if (fd >= NR_OPEN || fd < 0 || !(file = current->filp[fd]))
		return -EBADF;
	if (addr > TASK_SIZE || len > TASK_SIZE || addr > TASK_SIZE-len)
		return -EINVAL;

	/*
	 * do simple checking here so the lower-level routines won't have
	 * to. we assume access permissions have been handled by the open
	 * of the memory object, so we don't do any here.
	 */

	switch (flags & MAP_TYPE) {
	case MAP_SHARED:
		if ((prot & PROT_WRITE) && !(file->f_mode & 2))
			return -EINVAL;
		/* fall through */
	case MAP_PRIVATE:
		if (!(file->f_mode & 1))
			return -EINVAL;
		break;

	default:
		return -EINVAL;
	}

	/*
	 * obtain the address to map to. we verify (or select) it and ensure
	 * that it represents a valid section of the address space. we assume
	 * that if PROT_EXEC is specified this should be in the code segment.
	 */
	if (prot & PROT_EXEC) {
		base = get_base(current->ldt[1]);	/* cs */
		limit = get_limit(0x0f);		/* cs limit */
	} else {
		base = get_base(current->ldt[2]);	/* ds */
		limit = get_limit(0x17);		/* ds limit */
	}

	if (flags & MAP_FIXED) {
		/*
		 * if MAP_FIXED is specified, we have to map exactly at this
		 * address. it must be page aligned and not ambiguous.
		 */
		if ((addr & 0xfff) || addr > 0x7fffffff || addr == 0 ||
		    (off & 0xfff))
			return -EINVAL;
		if (addr + len > limit)
			return -ENOMEM;
	} else {
		/*
		 * we're given a hint as to where to put the address.
		 * that we still need to search for a range of pages which
		 * are not mapped and which won't impact the stack or data
		 * segment.
		 * in linux, we only have a code segment and data segment.
		 * since data grows up and stack grows down, we're sort of
		 * stuck. placing above the data will break malloc, below
		 * the stack will cause stack overflow. because of this
		 * we don't allow nonspecified mappings...
		 */
		return -ENOMEM;
	}

	/*
	 * determine the object being mapped and call the appropriate
	 * specific mapper. the address has already been validated, but
	 * not unmapped
	 */
	if (!file->f_op || !file->f_op->mmap)
		return -ENODEV;
	mask = 0;
	if (prot & (PROT_READ | PROT_EXEC))
		mask |= PAGE_READONLY;
	if (prot & PROT_WRITE)
		mask |= PAGE_RW;
	if (!mask)
		return -EINVAL;
	if ((flags & MAP_TYPE) == MAP_PRIVATE) {
		mask |= PAGE_COW;
		mask &= ~PAGE_RW;
	}
	error = file->f_op->mmap(file->f_inode, file, base + addr, len, mask, off);
	if (error)
		return error;
	return addr;
}
Exemplo n.º 27
0
static void
print_limit ()
{
	hexchat_printf (ph, "File size limit for checksums: %d MiB", get_limit ());
}
// mode - 0:For sensor, 1:For FPC, 2:CheckTSPConnection, 3:Baseline, 4:Delta image
int F54_GetFullRawCap(int mode, char *buf) {
    signed short temp=0;
    //int Result = 0;
    int ret = 0;
    unsigned char product_id[11];
    int TSPCheckLimit=700;
    // short Flex_LowerLimit = -100;
    // short Flex_UpperLimit = 500;

    int i, j, k;
    unsigned short length;

    unsigned char command;

    int waitcount;

    if (mode < 0 && mode > 4)
        return ret;

    length = numberOfTx * numberOfRx * 2;

    //check product id to set basecap array
    readRMI(F01_Query_Base + 11, &product_id[0], sizeof(product_id));

    if(!strncmp(product_id, "PLG245", 6)) {
        pr_info("set limit array to PLG245 value.\n");
        //memcpy(Limit, Limit_PLG245, sizeof(Limit_PLG245));
    } else if(!strncmp(product_id, "PLG260", 6)) {
        pr_info("set limit array to PLG260 value.\n");
        //memcpy(Limit, Limit_PLG260, sizeof(Limit_PLG260));
    } else {
        pr_info("set limit array to LGIT value.\n");
    }

    //set limit array
    if (call_cnt == 0)
    {
        pr_info("Backup Limit to LimitBack array\n");
        memset(LimitBack, 0, sizeof(LimitBack));
//        memcpy(LimitBack, Limit, sizeof(LimitBack));
#if defined(LGE_USE_DOME_KEY)
        memcpy(LimitBack, Limit_PLG260, sizeof(LimitBack));
#else
        memcpy(LimitBack, Limit_PLG245, sizeof(LimitBack));
#endif
    }

    if (get_limit(numberOfTx, numberOfRx) > 0) {
        pr_info("Get limit from file success!!Use Limit array from file data.\n");
//        memcpy(Limit, LimitFile, sizeof(Limit));
#if defined(LGE_USE_DOME_KEY)
        memcpy(Limit_PLG260, LimitFile, sizeof(Limit_PLG260));
#else
        memcpy(Limit_PLG245, LimitFile, sizeof(Limit_PLG245));
#endif
    } else {
        pr_info("Get limit from file fail!!Use Limit array from image data\n");
//        memcpy(Limit, LimitBack, sizeof(Limit));
#if defined(LGE_USE_DOME_KEY)
        memcpy(Limit_PLG260, LimitBack, sizeof(Limit_PLG260));
#else
        memcpy(Limit_PLG245, LimitBack, sizeof(Limit_PLG245));
#endif
    }

    call_cnt++;

    if (call_cnt > 0)
        call_cnt = 1;

    // No sleep
    command = 0x04;
    writeRMI(F01_Ctrl_Base, &command, 1);

    // Set report mode to to run the AutoScan
    command = (mode == 4) ? 0x02 : 0x03;
    writeRMI(F54_Data_Base, &command, 1);

#if 0
    if (mode == 3 || mode == 4) {
        /*        //NoCDM4
                command = 0x01;
                writeRMI(NoiseMitigation, &command, 1);
         */
    }


    if (mode != 3 && mode != 4) {
        // Force update & Force cal
        command = 0x06;
        writeRMI(F54_Command_Base, &command, 1);

        waitcount = 0;
        do {
            if (++waitcount > 100) {
                pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
                break;
            }
            delayMS(1); //wait 1ms
            readRMI(F54_Command_Base, &command, 1);
        } while (command != 0x00);
    }
#endif

    // Enabling only the analog image reporting interrupt, and turn off the rest
    readRMI(F01_Cmd_Base+1, &command, 1);
    command |= 0x08;
    writeRMI(F01_Cmd_Base+1, &command, 1);

    command = 0x00;
    writeRMI(F54_Data_LowIndex, &command, 1);
    writeRMI(F54_Data_HighIndex, &command, 1);

    // Set the GetReport bit to run the AutoScan
    command = 0x01;
    writeRMI(F54_Command_Base, &command, 1);

    // Wait until the command is completed
    waitcount = 0;
    do {
        if (++waitcount > 100) {
            pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
            break;
        }
        delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
    } while (command != 0x00);

    //readRMI(F54_Data_Buffer, &ImageBuffer[0], length);
    longReadRMI(F54_Data_Buffer, &ImageBuffer[0], length);

    readRMI(F01_Cmd_Base+1, &command, 1);
    command &= ~0x08;
    writeRMI(F01_Cmd_Base+1, &command, 1);

    if ( (numberOfTx > 29) || (numberOfRx > 45) ) {
        ret = sprintf(buf, "ERROR: Limit Index overflow. Test result: Fail\n");
        return ret;
    }

    *buf = 0;

    ret = sprintf(buf, "Info: Tx=%d Rx=%d\n", numberOfTx, numberOfRx);

    switch(mode) {
    case 0:
    case 1:
        //ret += sprintf(buf+ret, "Full raw capacitance Test\n");
        k = 0;
        for (i = 0; i < numberOfTx; i++) {
            // ret += sprintf(buf+ret, "%d\t", i);
            for (j = 0; j < numberOfRx; j++) {
                temp = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
                /*
                if(CheckButton[i][j] != 1) {
                    if(mode==0) {
                        if ((temp >= Limit[i][j*2]) && (temp <= Limit[i][j*2+1]))
                            Result++;
                    } else {
                        if ((temp >= Flex_LowerLimit) && (temp <= Flex_UpperLimit))
                            Result++;
                    }
                } else {
                    Result++;
                }
                */
                ret += sprintf(buf+ret, "%d", temp); //It's for getting log for limit set

                if(j < (numberOfRx-1))
                    ret += sprintf(buf+ret, " ");

                k = k + 2;
            }
            ret += sprintf(buf+ret, "\n");
        }
        break;

    case 2:
        k = 0;
        for (i = 0; i < numberOfTx; i++) {
            for (j = 0; j < numberOfRx; j++) {
                temp = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));

                if (temp > TSPCheckLimit) {
                    ret += sprintf(buf+ret, "1");
                    //Result++;
                } else {
                    ret += sprintf(buf+ret, "0");
                }

                if(j < (numberOfRx-1))
                    ret += sprintf(buf+ret, " ");

                k = k + 2;
            }
            ret += sprintf(ret+buf, "\n");
        }
        break;

    case 3:
    case 4:
        k = 0;

        for (i = 0; i < numberOfTx; i++) {
            for (j = 0; j < numberOfRx; j++) {
                ImageArray[i][j] = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
                k = k + 2;
            }
        }

        for (i = 0; i < numberOfTx; i++) {
            //ret += sprintf(buf+ret, "TX%d\t", TxChannelUsed[i]);
            for (j = 0; j < numberOfRx; j++) {
                ret += sprintf(buf+ret, "%d", ((mode == 3) ? (ImageArray[i][j] / 1000) : (ImageArray[i][j])));

                if(j < (numberOfRx - 1))
                    ret += sprintf(buf+ret, " ");
            }
            ret += sprintf(ret+buf, "\n");
        }
        break;

    default:
        break;
    }
    //if (mode < 3)
    /*
    {
        //Reset
        command = 0x01;
        writeRMI(F01_Cmd_Base, &command, 1);
        //delayMS(200);
        delayMS(1);
        readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high
    }
    */
    return ret;
}
Exemplo n.º 29
0
	static
	void
define_coordinate_axes (

struct pset *		pts,		/* IN - terminals to plot */
struct scale_info *	sip		/* IN - problem scaling info */
)
{
int			i;
int			n;
struct point *		p1;
double			x, y;
double			minxcoord, maxxcoord;
double			minycoord, maxycoord;
double			xspan, yspan, span;
double			axmin, axmax;
double			aymin, aymax;

	n = pts -> n;

	if (n < 1) {
		printf ("\n0 1 0 1 SetAxes\n");
		return;
	}

	p1 = &(pts -> a [0]);

	minxcoord = maxxcoord = p1 -> x;
	minycoord = maxycoord = p1 -> y;
	++p1;

	for (i = 1; i < n; i++, p1++) {
		x = p1 -> x;
		y = p1 -> y;
		if (x < minxcoord) {
			minxcoord = x;
		}
		else if (x > maxxcoord) {
			maxxcoord = x;
		}
		if (y < minycoord) {
			minycoord = y;
		}
		else if (y > maxycoord) {
			maxycoord = y;
		}
	}

	minxcoord = UNSCALE (minxcoord, sip);
	maxxcoord = UNSCALE (maxxcoord, sip);
	minycoord = UNSCALE (minycoord, sip);
	maxycoord = UNSCALE (maxycoord, sip);

	/* We only generate square plots having equal scales on both	*/
	/* axes.  Determine the "span" of the plot, i.e., the length of	*/
	/* each axis in the plot.					*/

	xspan = maxxcoord - minxcoord;
	yspan = maxycoord - minycoord;

	if (xspan EQ 0.0) {
		if (yspan EQ 0.0) {
			/* Single point. */
			if (maxxcoord NE 0.0) {
				if (fabs (maxxcoord) >= fabs (maxycoord)) {
					span = 2.0 * fabs (maxxcoord);
				}
				else {
					span = 2.0 * fabs (maxycoord);
				}
			}
			else if (maxycoord NE 0.0) {
				span = 2.0 * fabs (maxycoord);
			}
			else {
				/* Single point at the origin. */
				span = 2.0;
			}
		}
		else {
			span = get_limit (yspan);
		}
	}
	else if (yspan EQ 0.0) {
		span = get_limit (xspan);
	}
	else if (xspan >= yspan) {
		span = get_limit (xspan);
	}
	else {
		span = get_limit (yspan);
	}

	/* Determine the minimum x axis value. */

	if (xspan EQ 0.0) {
		goto center_x;
	}
	else if ((0.0 <= minxcoord) AND (maxxcoord <= span)) {
		axmin = 0.0;
	}
	else if ((-span <= minxcoord) AND (maxxcoord <= 0.0)) {
		axmin = -span;
	}
	else if ((-0.5 * span <= minxcoord) AND (maxxcoord <= 0.5 * span)) {
		axmin = -0.5 * span;
	}
	else {
center_x:
		/* Center the x coordinates. */
		axmin = 0.5 * (minxcoord + maxxcoord - span);
	}
	axmax = axmin + span;

	/* Determine the minimum y axis value. */

	if (yspan EQ 0.0) {
		goto center_y;
	}
	else if ((0.0 <= minycoord) AND (maxycoord <= span)) {
		aymin = 0.0;
	}
	else if ((-span <= minycoord) AND (maxycoord <= 0.0)) {
		aymin = -span;
	}
	else if ((-0.5 * span <= minycoord) AND (maxycoord <= 0.5 * span)) {
		aymin = -0.5 * span;
	}
	else {
center_y:
		/* Center the y coordinates */
		aymin = 0.5 * (minycoord + maxycoord - span);
	}
	aymax = aymin + span;

	/* Good enough for now... */
	printf ("\n%g %g %g %g SetAxes\n", axmin, axmax, aymin, aymax);
}
Exemplo n.º 30
0
unsigned char F54_FullRawCap(int mode)
// mode - 0:For sensor, 1:For FPC, 2:CheckTSPConnection, 3:Baseline, 4:Delta image
{
   signed short temp=0;
   int Result = 0;
#ifdef F54_Porting
	int ret = 0;
	unsigned char product_id[11];
#endif
    int TSPCheckLimit=700;
	short Flex_LowerLimit = -100;
	short Flex_UpperLimit = 500;

	int i, j, k;
	unsigned short length;
	
	unsigned char command;

	length = numberOfTx * numberOfRx* 2;

	//check product id to set basecap array
	readRMI(F01_Query_Base+11, &product_id[0], sizeof(product_id));
	
	if(!strncmp(product_id, "TM2369", 6)) {
		printk("set limit array to TPK value.\n");
		memcpy(Limit, Limit_TPK, sizeof(Limit_TPK));
	} else if(!strncmp(product_id, "PLG192", 6)) {
		printk("set limit array to PLG192 value.\n");
		memcpy(Limit, Limit_PLG192, sizeof(Limit_PLG192));
	} else if(!strncmp(product_id, "PLG193", 6)) {
		printk("set limit array to PLG193 value.\n");
		memcpy(Limit, Limit_PLG193, sizeof(Limit_PLG193));
	} else if(!strncmp(product_id, "PLG121", 6)) {
		printk("set limit array to PLG121 value.\n");
		memcpy(Limit, Limit_PLG121, sizeof(Limit_PLG121));
	} else {
		printk("set limit array to LGIT value.\n");
	}
	
	//set limit array
	if(call_cnt == 0){
		printk("Backup Limit to LimitBack array\n");
		memset(LimitBack, 0, sizeof(LimitBack));
		memcpy(LimitBack, Limit, sizeof(LimitBack));
	}
	if(get_limit(numberOfTx, numberOfRx) > 0) {
		printk("Get limit from file success!!Use Limit array from file data.\n");
		memcpy(Limit, LimitFile, sizeof(Limit));
	} else {
		printk("Get limit from file fail!!Use Limit array from image data\n");
		memcpy(Limit, LimitBack, sizeof(Limit));
	}
	call_cnt++;
	if(call_cnt > 0) call_cnt = 1;

	if(mode == 3 || mode == 4)
	{
/*		// Disable CBC
		command = 0x00;
		writeRMI(F54_CBCSettings, &command, 1);
		writeRMI(F54_CBCPolarity, &command, 1);
*/	}

	// No sleep
	command = 0x04;
	writeRMI(F01_Ctrl_Base, &command, 1);

	// Set report mode to to run the AutoScan
	if(mode >= 0 && mode < 4)	command = 0x03;
	if(mode == 4)				command = 0x02;
	writeRMI(F54_Data_Base, &command, 1);

	if(mode == 3 || mode == 4)
	{
/*		//NoCDM4
		command = 0x01;
		writeRMI(NoiseMitigation, &command, 1);
*/	}

	if(mode != 3 && mode != 4)
	{
		// Force update & Force cal
		command = 0x06;
		writeRMI(F54_Command_Base, &command, 1);

		do {
			delayMS(1); //wait 1ms
			readRMI(F54_Command_Base, &command, 1);
		} while (command != 0x00);
	}

	// Enabling only the analog image reporting interrupt, and turn off the rest
	command = 0x08;
	writeRMI(F01_Cmd_Base+1, &command, 1);

	command = 0x00;
	writeRMI(F54_Data_LowIndex, &command, 1);
	writeRMI(F54_Data_HighIndex, &command, 1);
 
	// Set the GetReport bit to run the AutoScan
	command = 0x01;
	writeRMI(F54_Command_Base, &command, 1);
 
	// Wait until the command is completed
	do {
	 delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);
 
	readRMI(F54_Data_Buffer, &ImageBuffer[0], length);

	if( (numberOfTx > 29) || (numberOfRx > 45) ) {
		printk("Limit Index overflow. Test result: Fail\n");
		return 0;
	}

	switch(mode)
	{
		case 0:
		case 1:
#ifdef F54_Porting
			memset(buf, 0, sizeof(buf));
			ret = sprintf(buf, "#ofTx\t%d\n", numberOfTx);
			ret += sprintf(buf+ret, "#ofRx\t%d\n", numberOfRx);

			ret += sprintf(buf+ret, "\n#3.03	Full raw capacitance Test\n");
#else
			printk("#ofTx\t%d\n", numberOfTx);
			printk("#ofRx\t%d\n", numberOfRx);

			printk("\n#3.03	Full raw capacitance Test\n");
#endif
			k = 0;	   
			for (i = 0; i < numberOfTx; i++)
			{
#ifdef F54_Porting
				ret += sprintf(buf+ret, "%d\t", i);
#else
				printk("%d\t", i);
#endif
				for (j = 0; j < numberOfRx; j++)
				{
						temp = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
						if(CheckButton[i][j] != 1)
						{
							if(mode==0)
							{
#ifdef F54_Porting
								if ((temp >= Limit[i][j*2]) && (temp <= Limit[i][j*2+1]))
#else
								if ((temp >= Limit[i][j*2]*1000) && (temp <= Limit[i][j*2+1]*1000))
#endif
								{
									Result++;
#ifdef F54_Porting									
									ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
									printk("%d\t", temp); //It's for getting log for limit set
#endif
								}
								else {
#ifdef F54_Porting
									ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
									printk("%d\t", temp); //It's for getting log for limit set
#endif
								}
							}
							else
							{
								if ((temp >= Flex_LowerLimit) && (temp <= Flex_UpperLimit))
								{
									Result++;
#ifdef F54_Porting
									ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
									printk("%d\t", temp); //It's for getting log for limit set
#endif									
								}
								else {
#ifdef F54_Porting
									ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
									printk("%d\t", temp); //It's for getting log for limit set
#endif
								}
							}
						}
						else
						{
							Result++;
#ifdef F54_Porting
							ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
							printk("%d\t", temp); //It's for getting log for limit set
#endif							
						}
				  k = k + 2;
				}
#ifdef F54_Porting
				ret += sprintf(buf+ret, "\n");
#else
				printk("\n"); //It's for getting log for limit set
#endif				
			}

#ifdef F54_Porting
			ret += sprintf(buf+ret, "#3.04	Full raw capacitance Test END\n");
			ret += sprintf(buf+ret, "\n#3.01	Full raw capacitance Test Limit\n");

			// Print Capacitance Imgae for getting log for Excel format
			ret += sprintf(buf+ret, "\t");
#else
			printk("#3.04	Full raw capacitance Test END\n");

			printk("\n#3.01	Full raw capacitance Test Limit\n");
			// Print Capacitance Imgae for getting log for Excel format
			printk("\t");
#endif			
			for (j = 0; j < numberOfRx; j++) {
#ifdef F54_Porting
				ret += sprintf(buf+ret, "%d-Min\t%d-Max\t", j, j);
#else
				printk("%d-Min\t%d-Max\t", j, j);
#endif
			}

#ifdef F54_Porting
			ret += sprintf(buf+ret, "\n");
#else
			printk("\n");
#endif

			for (i = 0; i < numberOfTx; i++)
			{
#ifdef F54_Porting
				ret += sprintf(buf+ret, "%d\t", i);
#else
				printk("%d\t", i);
#endif
				for (j = 0; j < numberOfRx; j++)
				{
					if(mode==0) {
#ifdef F54_Porting
						//printk("%d\t%d\t", Limit[i][j*2], Limit[i][j*2+1]);
						ret += sprintf(buf+ret, "%d\t%d\t", Limit[i][j*2], Limit[i][j*2+1]);
#else
						printk("%d\t%d\t", Limit[i][j*2]*1000, Limit[i][j*2+1]*1000);
#endif
					} else {
#ifdef F54_Porting
						ret += sprintf(buf+ret, "%d\t%d\t", Flex_LowerLimit, Flex_UpperLimit);
#else
						printk("%d\t%d\t", Flex_LowerLimit, Flex_UpperLimit);
#endif
					}
				}
#ifdef F54_Porting
				ret += sprintf(buf+ret, "\n");
#else
				printk("\n");
#endif
			}
#ifdef F54_Porting
			ret += sprintf(buf+ret, "#3.02	Full raw cap Limit END\n");
#else
			printk("#3.02	Full raw cap Limit END\n");
#endif
			break;

		case 2:
			k = 0;	   
			for (i = 0; i < numberOfTx; i++)
			{
				for (j = 0; j < numberOfRx; j++)
				{
						temp = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
						   if (temp > TSPCheckLimit)
						   Result++;
				  k = k + 2;
				}	   
			}
			break;

		case 3:
		case 4:
			k = 0;	   
			for (i = 0; i < numberOfTx; i++)
			{
				for (j = 0; j < numberOfRx; j++)
				{
						ImageArray[i][j] = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
				  k = k + 2;
				}	   
			}
#ifdef F54_Porting
				 // Print Capacitance Imgae for getting log for Excel format
				 ret += sprintf(ret+buf, "\n\t");
#else
				 // Print Capacitance Imgae for getting log for Excel format
				 printk("\n\t");
#endif
				 for (j = 0; j < numberOfRx; j++) {
#ifdef F54_Porting
					ret += sprintf(ret+buf, "RX%d\t", RxChannelUsed[j]);
#else
				 	printk("RX%d\t", RxChannelUsed[j]);
#endif
				 }
				 
#ifdef F54_Porting
				 ret += sprintf(buf+ret, "\n");
#else
				 printk("\n");
#endif
				 
				 for (i = 0; i < numberOfTx; i++)
				 {
#ifdef F54_Porting
					 ret += sprintf(buf+ret, "TX%d\t", TxChannelUsed[i]);
#else
					 printk("TX%d\t", TxChannelUsed[i]);
#endif
					 for (j = 0; j < numberOfRx; j++)
					 {
#ifdef F54_Porting					 
						if(mode == 3)		ret += sprintf(buf+ret, "%d\t", (ImageArray[i][j]) / 1000);
						else if(mode == 4)	ret += sprintf(buf+ret, "%d\t", ImageArray[i][j]);
#else
						if(mode == 3)	   printk("%d\t", (ImageArray[i][j]) / 1000);
						else if(mode == 4) printk("%d\t", ImageArray[i][j]);
						//if(mode == 3)	   printk("%1.3f\t", (float)(ImageArray[i][j]) / 1000);
						//else if(mode == 4) printk("%d\t", ImageArray[i][j]);
#endif
						 
					  }
#ifdef F54_Porting
				  ret += sprintf(ret+buf, "\n");
#else
				  printk("\n");
#endif
				 }
			break;

		default:
			break;
	}

	if(mode != 3 && mode != 4)
	{
		//Reset
		command= 0x01;
		writeRMI(F01_Cmd_Base, &command, 1);
		delayMS(200);
		readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high
	}
	
	if(mode >= 0 && mode < 2)
	{
		if(Result == numberOfTx * numberOfRx)
		{
#ifdef F54_Porting
			ret += sprintf(buf+ret, "Test Result: Pass\n");
			write_log(buf);
#else
			printk("Test Result: Pass\n");
#endif
			return 1; //Pass
		}
		else
		{
#ifdef F54_Porting
			ret += sprintf(buf+ret, "Test Result: Fail\n");
			write_log(buf);
#else
			printk("Test Result: Fail\n");
#endif
			return 0; //Fail
		}
	}
	else if(mode == 2)
	{
		if(Result == 0) return 0; //TSP Not connected
		else return 1; //TSP connected 
	 }
	else
	{
#ifdef F54_Porting
		write_log(buf);
#endif
		return 0;
	}
 }