Beispiel #1
0
void armv7a::arm_add_sp_plus_reg(armv7a_ir& inst)
{
    inst.print_inst("arm_add_sp_plus_reg");
    inst.check(27, 21, B(100));
    inst.check(19, 16, B(1101));
    inst.check(4, 0);

    if(rf.condition_passed(inst.cond()))
    {
        uint32_t s = inst(20);
        uint32_t rd = inst(15, 12);
        uint32_t imm5 = inst(11, 7);
        uint32_t type = inst(6, 5);
        uint32_t rm = inst(3, 0);

        if((rd == B(1111) && (s == 1)))
        {
            printb(d_inst, "arm_add_sp_plus_reg SUBS PC, LR");
        }

        uint32_t d = rd;
        uint32_t m = rm;
        bool setflags = s == 1;
        sr_type shift_t;
        uint32_t shift_n;
        decode_imm_shift(&shift_t, &shift_n, type, imm5);
        //ESO
        bits shifted;
        bits _rm(rf.r_read(m), 32);
        shift(&shifted, _rm, shift_t, shift_n, rf.cpsr_C());
        bits result;
        uint32_t carry;
        uint32_t overflow;
        bits _sp(rf.r_read(SP), 32);
        add_with_carry(&result, &carry, &overflow, _sp, shifted, 0);

        if(d == 15)
        {
            rf.alu_write_pc(result.val);
        }

        else
        {
            rf.r_write(d, result.val);
            uint32_t tmp = rf.r_read(d);
            printd(d_inst, "shifted:%X result:%X R%d:%X", shifted.val, result.val, d, tmp);

            if(setflags)
            {
                rf.cpsr_N(result(31));
                rf.cpsr_Z(is_zero_bit(result));
                rf.cpsr_C(carry);
                rf.cpsr_V(overflow);
            }
        }
    }
}
Beispiel #2
0
int rm_proc(const char *buf, int fileNo) {
	char arg[CMDBUF] = "";
	
	if (_rm_Arg(buf, arg) == -1)
		return(-1);
	
	if (_rm(arg, fileNo) == -1)
		return(-1);
	
	return(0);
}
Beispiel #3
0
int
update_localdb(int verbose)
{
    struct stat s;
    char tmp[255];
    char outpath[255];
    char outfile[255];
    char outhome[255];
    char const* homedir;
    char* url = "https://github.com/tldr-pages/tldr/archive/master.zip";
    char* dir = "/tmp/tldrXXXXXX";
    char* file = "/master.zip";
    char* tldrdir = "/tldr-master";
    char* tldrhomedir = "/.tldr";
    int homedirlen;
    int dirlen = strlen(dir);
    int filelen = strlen(file);
    int tldrdirlen = strlen(tldrdir);
    int tldrhomedirlen = strlen(tldrhomedir);

    memcpy(outfile, dir, dirlen);
    if (!mkdtemp(outfile)) { return 1; }

    memcpy(outpath, outfile, dirlen);
    memcpy(outfile + dirlen, file, filelen);
    outfile[dirlen + filelen] = '\0';

    if (download_file(url, outfile, verbose))
    { return 1; }

    if (_unzip(outfile, outpath))
    {
        _rm(outpath);
        return 1;
    }

    memcpy(tmp, outpath, dirlen);
    memcpy(tmp + dirlen, tldrdir, tldrdirlen);
    tmp[dirlen + tldrdirlen] = '\0';

    if ((homedir = getenv("HOME")) == NULL)
    {
        homedir = getpwuid(getuid())->pw_dir;
    }

    homedirlen = strlen(homedir);
    memcpy(outhome, homedir, homedirlen);
    memcpy(outhome + homedirlen, tldrhomedir, tldrhomedirlen);
    outhome[homedirlen + tldrhomedirlen] = '\0';
    if (mkdir(outhome, 0755) > 0)
    {
        if (errno != EEXIST)
        {
            _rm(outpath);
            return 1;
        }
    }

    memcpy(outhome + homedirlen + tldrhomedirlen, tldrdir, tldrdirlen);
    outhome[homedirlen + tldrhomedirlen + tldrdirlen] = '/';
    outhome[homedirlen + tldrhomedirlen + tldrdirlen + 1] = '\0';
    if (stat(outhome, &s) == 0 && S_ISDIR(s.st_mode))
    {
        if (_rm(outhome)) { return 1; }
    }

    if (rename(tmp, outhome))
    {
        _rm(outpath);
        return 1;
    }

    if (_rm(outpath))
    { return 1; }

    update_localdate();
    return 0;
}
Beispiel #4
0
void armv7a::arm_subs_pc_lr(armv7a_ir& inst)
{
    inst.print_inst("arm_subs_pc_lr");

    if(rf.condition_passed(inst.cond()))
    {
        uint32_t opcode;
        uint32_t n;
        bits imm32;
        bool register_form;
        printd(d_inst, "original cpsr:%X", rf.cpsr());
        printd(d_inst, "original spsr:%X", rf.spsr());
        uint32_t m;
        sr_type shift_t;
        uint32_t shift_n;

        if(inst(25) == 1)
        {
            //Encoding A1
            inst.check(27, 25, 1);
            inst.check(20, 1);
            inst.check(15, 12, B(1111));
            opcode = inst(24, 21);
            uint32_t rn = inst(19, 16);
            bits imm12(inst(11, 0), 12);
            n = rn;
            arm_expand_imm(&imm32, imm12);
            register_form = false;
        }

        else
        {
            //Encoding A2
            inst.check(27, 25, 0);
            inst.check(20, 1);
            inst.check(15, 12, B(1111));
            inst.check(4, 0);
            opcode = inst(24, 21);
            uint32_t rn = inst(19, 16);
            uint32_t imm5 = inst(11, 7);
            uint32_t type = inst(6, 5);
            uint32_t rm = inst(3, 0);
            n = rn;
            m = rm;
            register_form = true;
            decode_imm_shift(&shift_t, &shift_n, type, imm5);
        }

        //ESO

        if(rf.current_inst_set() == InstSet_ThumbEE)
        {
            printb(d_inst, "arm_subs_pc_lr error");
        }

        bits operand2;

        if(register_form)
        {
            bits _rm(rf.r_read(m), 32);
            shift(&operand2, _rm, shift_t, shift_n, rf.cpsr_C());
        }

        else
        {
            operand2 = imm32;
        }

        bits result(0, 32);
        uint32_t carry;
        uint32_t overflow;
        bits _rn(rf.r_read(n), 32);
        bits not_rn(~rf.r_read(n), 32);
        bits not_operand2(~operand2.val, operand2.n);

        switch(opcode)
        {
            case B(0000):
                result.val = _rn.val & operand2.val;
                break;       //AND
            case B(0001):
                result.val = _rn.val ^ operand2.val;
                break;       //EOR
            case B(0010):
                add_with_carry(&result, &carry, &overflow, _rn, not_operand2, 1);
                break;      //SUB
            case B(0011):
                add_with_carry(&result, &carry, &overflow, not_rn, operand2, 1);
                break;       //RSB
            case B(0100):
                add_with_carry(&result, &carry, &overflow, _rn, operand2, 0);
                break;       //ADD
            case B(0101):
                add_with_carry(&result, &carry, &overflow, _rn, operand2, rf.cpsr_C());
                break;     //ADC
            case B(0110):
                add_with_carry(&result, &carry, &overflow, _rn, not_operand2, rf.cpsr_C());
                break;     //SBC
            case B(0111):
                add_with_carry(&result, &carry, &overflow, not_rn, operand2, rf.cpsr_C());
                break;     //RSC
            case B(1100):
                result.val = _rn.val | operand2.val;
                break;       //ORR
            case B(1101):
                result.val = operand2.val;
                break;     //MOV
            case B(1110):
                result.val = _rn.val & not_operand2.val;
                break;       //BIC
            case B(1111):
                result.val = not_operand2.val;
                break;     //MVN
            default:
                printb(d_inst, "arm_subs_pc_lr error 2");
        }

        cpsr_write_by_inst(rf.spsr(), B(1111), true);
        printd(d_inst, "new cpsr:%X", rf.cpsr());
        rf.branch_write_pc(result.val);
    }
}
Beispiel #5
0
void syscall_handler()
{
	static int free_vm_proc;        
	int syscall_num;
	unsigned int mem_size;
	struct t_process_context* current_process_context;
	struct t_processor_reg processor_reg;
	int* params;
	char data;
	unsigned int on_exit_action;

 	SAVE_PROCESSOR_REG
	//call can come from kernel mode (sleep)
	SWITCH_DS_TO_KERNEL_MODE
	on_exit_action=0;
	current_process_context=system.process_info->current_process->val;
	t_console_desc *console_desc=current_process_context->console_desc;
	syscall_num=processor_reg.eax;
	params=processor_reg.ecx;
	if (syscall_num==1) 
	{
		params[0]=_fork(processor_reg);
	}
	else if (syscall_num==2)
	{ 
		params[1]=_malloc(params[0]);
	}
	else if (syscall_num==3)
	{ 
		_free(params[0]);
	}
	else if (syscall_num==150)
	{ 
		params[1]=_bigMalloc(params[0]);
	}
	else if (syscall_num==151)
	{ 
		_bigFree(params[0]);
	}
	else if (syscall_num==4)
	{ 
		_write_char(console_desc,params[0]);
	}
	else if (syscall_num==5)
	{ 
		data=_read_char(console_desc);
		*((char*)params[0])=data;	
		if (data==NULL)
		{
			on_exit_action=1; 
		}
	}
	else if (syscall_num==6)
	{ 
		_echo_char(console_desc,params[0]);
	}
	else if (syscall_num==7)
	{ 
		_enable_cursor(console_desc);	
	}
	else if (syscall_num==8)
	{ 
		_disable_cursor(console_desc);
	}
	else if (syscall_num==9)
	{ 
		_update_cursor(console_desc);	
	}
	else if (syscall_num==10)
	{
		_delete_char(console_desc);
	}
	else if (syscall_num==11)
	{
		_pause();	
		on_exit_action=1; 
	}
	else if (syscall_num==12)
	{
		_awake(params[0]);
	}
	else if (syscall_num==13)
	{
		_exit(params[0]);
		on_exit_action=2;
	}
	else if (syscall_num==14) 
	{
		params[2]=_exec(params[0],params[1]); 
	}
	else if (syscall_num==15) 
	{
		_sleep_time(params[0]);	
		on_exit_action=1; 
	}
	else if (syscall_num==18) 
	{
		params[2]=_open(system.root_fs,(char*) params[0],params[1]); 
		on_exit_action=1; 
	}

	else if (syscall_num==19) 
	{
		params[1]=_close(system.root_fs,params[0]);
		on_exit_action=1; 
	}

	else if (syscall_num==20) 
	{
		params[3]=_read(system.root_fs,params[0],params[1],params[2]); 
		on_exit_action=1; 
	}

	else if (syscall_num==21) 
	{
		params[3]=_write(system.root_fs,(void*)params[0],params[1],params[2]);
		on_exit_action=1;  
	}
	
	else if (syscall_num==22)
	{
		params[1]=_rm(system.root_fs,(char*)params[0]);
		on_exit_action=1; 
	}

	else if (syscall_num==23) 
	{
		params[1]=_mkdir(system.root_fs,params[0]);
		on_exit_action=1; 
	}
	//syscall 24 and 25 test only
	else if (syscall_num==24) 
	{
		t_io_request* io_request;
		io_request=kmalloc(sizeof(t_io_request));
		io_request->device_desc=system.device_desc;
		io_request->sector_count=params[0];
		io_request->lba=params[1];
		io_request->io_buffer=params[2];
		io_request->process_context=current_process_context;
		_read_28_ata(io_request);
		kfree(io_request);
	}
	else if (syscall_num==25) 
	{
		t_io_request* io_request;
		io_request=kmalloc(sizeof(t_io_request));
		io_request->device_desc=system.device_desc;
		io_request->sector_count=params[0];
		io_request->lba=params[1];
		io_request->io_buffer=params[2];
		io_request->process_context=current_process_context;
		_write_28_ata(io_request);
		kfree(io_request);
	}
	else if (syscall_num==26) 
	{
		params[1]=_chdir(system.root_fs,(char*) params[0]); 
		on_exit_action=1; 	
	}
	else if (syscall_num==27)
	{
		params[2]=_stat(system.root_fs,(char*) params[0],params[1]); 	
	}

	else if (syscall_num==28)
	{
 		params[1]=_open_socket(system.network_desc->socket_desc,params[0]); 
	}
	else if (syscall_num==29)
	{
 		params[3]=_bind(system.network_desc->socket_desc,params[0],params[1],params[2]);
	}
	else if (syscall_num==30)
	{
 		params[5]=_recvfrom(system.network_desc->socket_desc,params[0],params[1],params[2],params[3],params[4]);
	}
	else if (syscall_num==31)
	{
 		params[5]=_sendto(system.network_desc->socket_desc,params[0],params[1],params[2],params[3],params[4]);
	}
	else if (syscall_num==32)
	{
 		params[1]=_close_socket(system.network_desc->socket_desc,params[0]);
	}

	else if (syscall_num==101) 
	{
		on_exit_action=1; 
	}
	else if (syscall_num==102) 
	{
		_flush_ata_pending_request();
	}
	//DEBUG WRAPPER
	else if (syscall_num==103)
	{
		check_free_mem();
	}
	else if (syscall_num==104)
	{
		debug_network(params[0],params[1]);
	}
	else
	{
		panic();
	}
//	EXIT_INT_HANDLER(on_exit_action,processor_reg)

	static struct t_process_context _current_process_context;                                          
	static struct t_process_context _old_process_context;                                              
	static struct t_process_context _new_process_context;	                                            
	static struct t_processor_reg _processor_reg;                                                       
	static unsigned int _action;
//	static short _ds;                                                                        
                                                                                                            
	CLI
//	_ds=ds;                                                                         
	_action=on_exit_action;                                                                                
	_current_process_context=*(struct t_process_context*)system.process_info->current_process->val;                                  
	_old_process_context=_current_process_context;                                                      
	_processor_reg=processor_reg;                                                           
	if (_action>0)                                                                                      
	{                                                                                   
		schedule(&_current_process_context,&_processor_reg);                            
		_new_process_context=*(struct t_process_context*)(system.process_info->current_process->val);
		_processor_reg=_new_process_context.processor_reg;                          
		SWITCH_PAGE_DIR(FROM_VIRT_TO_PHY(((unsigned int) _new_process_context.page_dir)))                                                          
		DO_STACK_FRAME(_processor_reg.esp-8);

//		unsigned int* xxx;
//		unsigned int* yyy;
//		unsigned int* zzz;
//		xxx=FROM_PHY_TO_VIRT(((unsigned int*)_new_process_context.page_dir)[0]) & 0xFFFFF000;
//		zzz=FROM_PHY_TO_VIRT(xxx[256]);
	
		if (_action==2)                                                                              
		{                                                                           
			DO_STACK_FRAME(_processor_reg.esp-8);                                               
//			free_vm_process(_old_process_context.page_dir,INIT_VM_USERSPACE);
			free_vm_process(&_old_process_context);
//			if (_old_process_context.phy_add_space!=NULL)
//			{ 
//				buddy_free_page(&system.buddy_desc,FROM_PHY_TO_VIRT(_old_process_context.phy_add_space));
//				buddy_free_page(system.buddy_desc,FROM_PHY_TO_VIRT(_old_process_context.phy_user_stack));
//			}
			buddy_free_page(system.buddy_desc,FROM_PHY_TO_VIRT(_old_process_context.phy_kernel_stack)); 	                                  
		}                                                                             
		RESTORE_PROCESSOR_REG                                
		EXIT_SYSCALL_HANDLER                                                        
	}                                                                                                   
Beispiel #6
0
int main(int argc, char * argv[], char * env[])
{
	char line[128], command[128], pathname[128];
	int ID;
	
	// DEVICE SELECT
	get_device();

	// INITIALIZE 
	init();
	
	// MOUNT ROOT
	mount_root();

	// PROCESS LOOP
	while(1)
	{
		strcpy(line, "");
		strcpy(command, "");
		strcpy(pathname, "");
		strcpy(completePath, "");

		printf("\n\ninput a command (type help for more info): ");
		//read a line containting  command [pathname]; // [ ] means optional
		fgets(line, 256, stdin);
		line[strlen(line)-1] = '\0';

		//Find the command string and call the corresponding function;
		parseString(line, arg1, command, pathname);

		compPath(pathname);
		
		
		printf("PATHNAME: %s\n", pathname);
		ID = findCommand(command);
		switch(ID)
		{
			case -1 : printDir(running->cwd->ino);	break;
			case  0 : _menu  (arg1, pathname);	break;
			case  1 : _ls    (arg1, pathname);	break;
			case  2 : _cd    (arg1, pathname);	break;
			case  3 : _mkdir (arg1, pathname);	break;
			case  4 : _rmdir (arg1, pathname);	break;
			case  5 : _pwd   (arg1, pathname);	break;
			case  6 : _creat0(arg1, pathname);	break;
			case  7 : _rm    (arg1, pathname);	break;
			case  8 : _stat  (arg1, pathname);	break;
			case  9 : compPath(arg1); _link(arg1, pathname); break;
			case  10: _unlink(arg1, pathname); break;
			case  11: compPath(arg1); _symlink(arg1, pathname); break;
			case  12: _touch (arg1, pathname);	break;
			case  13: _chmod (arg1, pathname);	break;
			case  14: _chown (arg1, pathname);	break;
			case  15: _chgrp (arg1, pathname);	break;
			case  16: _open  (arg1, pathname);	break;
			case  17: _close (arg1, pathname);	break;
			case  18: _read  (arg1, pathname);	break;
			case  19: _write (arg1, pathname);	break;
			case  20: _pfd   (arg1, pathname);	break;
			case  21: _lseek (arg1, pathname);	break;
			case  22: _cat   (arg1, pathname);	break;
			case  23: _cp    (arg1, pathname);	break;
			case  24: _mv    (arg1, pathname);	break;
			case  25: __exit (arg1, pathname);	break;
		}
	}
	
	quit();
	return 0;
}