int main(void)
{
	int rc;

	if (map_mem("/dev/mem", 0, 0xA0000, 1) == 0)
		fprintf(stderr, "PASS: /dev/mem 0x0-0xa0000 is readable\n");
	else
		fprintf(stderr, "FAIL: /dev/mem 0x0-0xa0000 not accessible\n");

	/*
	 * It's not safe to blindly read the VGA frame buffer.  If you know
	 * how to poke the card the right way, it should respond, but it's
	 * not safe in general.  Many machines, e.g., Intel chipsets, cover
	 * up a non-responding card by just returning -1, but others will
	 * report the failure as a machine check.
	 */
	if (map_mem("/dev/mem", 0xA0000, 0x20000, 0) == 0)
		fprintf(stderr, "PASS: /dev/mem 0xa0000-0xc0000 is mappable\n");
	else
		fprintf(stderr, "FAIL: /dev/mem 0xa0000-0xc0000 not accessible\n");

	if (map_mem("/dev/mem", 0xC0000, 0x40000, 1) == 0)
		fprintf(stderr, "PASS: /dev/mem 0xc0000-0x100000 is readable\n");
	else
		fprintf(stderr, "FAIL: /dev/mem 0xc0000-0x100000 not accessible\n");

	/*
	 * Often you can map all the individual pieces above (0-0xA0000,
	 * 0xA0000-0xC0000, and 0xC0000-0x100000), but can't map the whole
	 * thing at once.  This is because the individual pieces use different
	 * attributes, and there's no single attribute supported over the
	 * whole region.
	 */
	rc = map_mem("/dev/mem", 0, 1024*1024, 0);
	if (rc == 0)
		fprintf(stderr, "PASS: /dev/mem 0x0-0x100000 is mappable\n");
	else if (rc > 0)
		fprintf(stderr, "PASS: /dev/mem 0x0-0x100000 not mappable\n");
	else
		fprintf(stderr, "FAIL: /dev/mem 0x0-0x100000 not accessible\n");

	scan_tree("/sys/class/pci_bus", "legacy_mem", 0, 0xA0000, 1);
	scan_tree("/sys/class/pci_bus", "legacy_mem", 0xA0000, 0x20000, 0);
	scan_tree("/sys/class/pci_bus", "legacy_mem", 0xC0000, 0x40000, 1);
	scan_tree("/sys/class/pci_bus", "legacy_mem", 0, 1024*1024, 0);

	scan_rom("/sys/devices", "rom");

	scan_tree("/proc/bus/pci", "??.?", 0, 0xA0000, 1);
	scan_tree("/proc/bus/pci", "??.?", 0xA0000, 0x20000, 0);
	scan_tree("/proc/bus/pci", "??.?", 0xC0000, 0x40000, 1);
	scan_tree("/proc/bus/pci", "??.?", 0, 1024*1024, 0);

	return rc;
}
Пример #2
0
void timer2_enable()
{
	int i;

	map_mem(TIMER2_BASE, TIMER2_BASE, MMU_SECTION, USER_NO_ACCESS);

	for(i = 0; i < NUM_CALLBACKS; i++)
	{
		callback_vectors[i] = 0x00000000;
	}

        set_register_bit_value(TIMER2_BASE + TIOCP_CFG, 0, 1);

        while(get_register_bit(TIMER2_BASE + TIOCP_CFG, 0));

        set_register_bit_value(TIMER2_BASE + IRQENABLE_SET, 1, 1); // Enable overflow interrupt

        while(get_register_bit(TIMER2_BASE + TWPS, W_PEND_TCLR));

        set_register_bit_value(TIMER2_BASE + TCLR, 1, 1); // Auto reload

        while(get_register_bit(TIMER2_BASE + TWPS, W_PEND_TLDR));

        set_register(TIMER2_BASE + TLDR, 0xff000000); // Load value on reload

        while(get_register_bit(TIMER2_BASE + TWPS, W_PEND_TTGR));
        set_register(TIMER2_BASE + TTGR, 0x00000000);

        while(get_register_bit(TIMER2_BASE + TWPS, W_PEND_TCLR));
        set_register_bit_value(TIMER2_BASE + TCLR, 0, 1); // Start!
}
Пример #3
0
/* tercer argument */
int main(int n_args, char *ll_args[])
{
  int i,fil,n_v, id_win,n_fil,n_col;
  int *p_lletres, id_lletres;
  void *p_win;

  if (n_args < 7)
  {   fprintf(stderr,"\tproces (%d): mp_car2 fila n_veg id_lletres id_win n_fil n_col\n",(int) getpid());
	exit(0);
  }
  fil = atoi(ll_args[1]);
  n_v = atoi(ll_args[2]);
  if (n_v > MAX_VEGADES) n_v = MAX_VEGADES;

  id_lletres = atoi(ll_args[3]);
  p_lletres = map_mem(id_lletres);	/* obtenir adres. de mem. compartida */
  if (p_lletres == (int*) -1)
  {   fprintf(stderr,"proces (%d): error en identificador de memoria\n",(int)getpid());
	exit(0);
  }

  id_win = atoi(ll_args[4]);
  p_win = map_mem(id_win);
  if (p_win == (int*) -1)
  {   fprintf(stderr,"proces (%d): error en identificador de finestra\n",(int)getpid());
	exit(0);
  }
  n_fil = atoi(ll_args[5]);		/* obtenir dimensions del camp de joc */
  n_col = atoi(ll_args[6]);

  win_set(p_win,n_fil,n_col);	/* crea acces a finestra oberta pel proces pare */

  srand(getpid());
  for (i=0; i < n_v; i++)	/* per a totes les vegades (n_v) */
  {
    win_retard((1 + rand() % 3)*100);	/* dormir entre 0.1 i 0.3 segons */
    if (*p_lletres > 0)			/* si falten lletres */
    {
	win_escricar(fil,i+1,'a'+fil-1,NO_INV);	/* escriure marca del proces */
 	(*p_lletres)--;				/* una lletra menys */
     }
     else exit(i);	/* provoca sortida del proces */
  }
  return(i);	/* retorna el numero de lletres que ha impres el proces */
}
Пример #4
0
/* Paging Initialization
*/
void init_paging()
{
  map_mem();
  printf("before: %b,%b ---",read_cr0(),read_cr3());
  write_cr3((unsigned long)page_directory);
  unsigned long cr0 = read_cr0();
  cr0 = cr0 | 0x8000000;
  write_cr0(cr0);
  printf(" after: %b,%b\n",read_cr0(),read_cr3());
}
Пример #5
0
/* This function is actually a basic version of set_card.
/  It mainly copies the entries of the card list and maps 
/  the video registers. We need this function because we need
/  access to the videocard from the config file creation code.
/  At that stage we can't use the normal set_card because that
/  function also sets function pointers and uses bios/config
/  file info which we don't have yet.
*/
int set_card_info(int number)
{
	nv_card = &nvclock.card[number];

	if(!nv_card->mem_mapped)
		if(!map_mem(nv_card->dev_name))
			return 0; /* map_mem already took care of the error */
    
	return 1;
}
static int scan_tree(char *path, char *file, off_t offset, size_t length, int touch)
{
	struct dirent **namelist;
	char *name, *path2;
	int i, n, r, rc = 0, result = 0;
	struct stat buf;

	n = scandir(path, &namelist, 0, alphasort);
	if (n < 0) {
		perror("scandir");
		return -1;
	}

	for (i = 0; i < n; i++) {
		name = namelist[i]->d_name;

		if (fnmatch(".", name, 0) == 0)
			goto skip;
		if (fnmatch("..", name, 0) == 0)
			goto skip;

		path2 = malloc(strlen(path) + strlen(name) + 3);
		strcpy(path2, path);
		strcat(path2, "/");
		strcat(path2, name);

		if (fnmatch(file, name, 0) == 0) {
			rc = map_mem(path2, offset, length, touch);
			if (rc == 0)
				fprintf(stderr, "PASS: %s 0x%lx-0x%lx is %s\n", path2, offset, offset + length, touch ? "readable" : "mappable");
			else if (rc > 0)
				fprintf(stderr, "PASS: %s 0x%lx-0x%lx not mappable\n", path2, offset, offset + length);
			else {
				fprintf(stderr, "FAIL: %s 0x%lx-0x%lx not accessible\n", path2, offset, offset + length);
				return rc;
			}
		} else {
			r = lstat(path2, &buf);
			if (r == 0 && S_ISDIR(buf.st_mode)) {
				rc = scan_tree(path2, file, offset, length, touch);
				if (rc < 0)
					return rc;
			}
		}

		result |= rc;
		free(path2);

skip:
		free(namelist[i]);
	}
	free(namelist);
	return result;
}
Пример #7
0
int main(void)
{
	int rc;

	if (map_mem("/dev/mem", 0, 0xA0000, 1) == 0)
		fprintf(stderr, "PASS: /dev/mem 0x0-0xa0000 is readable\n");
	else
		fprintf(stderr, "FAIL: /dev/mem 0x0-0xa0000 not accessible\n");

	if (map_mem("/dev/mem", 0xA0000, 0x20000, 0) == 0)
		fprintf(stderr, "PASS: /dev/mem 0xa0000-0xc0000 is mappable\n");
	else
		fprintf(stderr, "FAIL: /dev/mem 0xa0000-0xc0000 not accessible\n");

	if (map_mem("/dev/mem", 0xC0000, 0x40000, 1) == 0)
		fprintf(stderr, "PASS: /dev/mem 0xc0000-0x100000 is readable\n");
	else
		fprintf(stderr, "FAIL: /dev/mem 0xc0000-0x100000 not accessible\n");

	rc = map_mem("/dev/mem", 0, 1024*1024, 0);
	if (rc == 0)
		fprintf(stderr, "PASS: /dev/mem 0x0-0x100000 is mappable\n");
	else if (rc > 0)
		fprintf(stderr, "PASS: /dev/mem 0x0-0x100000 not mappable\n");
	else
		fprintf(stderr, "FAIL: /dev/mem 0x0-0x100000 not accessible\n");

	scan_tree("/sys/class/pci_bus", "legacy_mem", 0, 0xA0000, 1);
	scan_tree("/sys/class/pci_bus", "legacy_mem", 0xA0000, 0x20000, 0);
	scan_tree("/sys/class/pci_bus", "legacy_mem", 0xC0000, 0x40000, 1);
	scan_tree("/sys/class/pci_bus", "legacy_mem", 0, 1024*1024, 0);

	scan_rom("/sys/devices", "rom");

	scan_tree("/proc/bus/pci", "??.?", 0, 0xA0000, 1);
	scan_tree("/proc/bus/pci", "??.?", 0xA0000, 0x20000, 0);
	scan_tree("/proc/bus/pci", "??.?", 0xC0000, 0x40000, 1);
	scan_tree("/proc/bus/pci", "??.?", 0, 1024*1024, 0);

	return rc;
}
Пример #8
0
void irq_controller_start()
{
        uint32_t INTC_BASE = 0x48200000;
	int i;

	map_mem(INTC_BASE, INTC_BASE, MMU_SECTION, USER_NO_ACCESS);

	for(i = 0; i < 128; i++)
	{
		irq_vectors[i] = 0x00000000;
	}

        set_register_bit_value(INTC_BASE + INTC_SYSCONFIG, SOFTRESET, 1);
        while(!get_register_bit(INTC_BASE + INTC_SYSSTATUS, RESETDONE));

        set_register_bit_value(INTC_BASE + INTC_CONTROL, 0, 1);
}
Пример #9
0
static void host1x_gr3d_reset_hw(void)
{
	void *CAR_io_mem_virt;
	int err;

	err = map_mem(&CAR_io_mem_virt, 0x60006000, 0x1000);
	if (err < 0) {
		host1x_error("host1x_gr3d_reset_hw() failed\n");
		return;
	}

	reg_write(CAR_io_mem_virt,
		  CLK_RST_CONTROLLER_RST_DEV_L_SET_0, CAR_3D);

	usleep(1000);

	reg_write(CAR_io_mem_virt,
		  CLK_RST_CONTROLLER_RST_DEV_L_CLR_0, CAR_3D);
}
Пример #10
0
struct resource *
bus_alloc_resource(device_t dev, int type, int *rid, int d, int e, int f, int g)
{
	switch (type) {
		case SYS_RES_IOPORT:
		{
			uint32 v = pci_read_config(dev, *rid, 4) & PCI_address_io_mask;
			INIT_DEBUGOUT2("bus_alloc_resource SYS_RES_IOPORT, reg 0x%x, adr %p\n", *rid, (void *)v);
			return (struct resource *) v;
		}

		case SYS_RES_MEMORY:
		{
			uint32 v = pci_read_config(dev, *rid, 4) & PCI_address_memory_32_mask;
			uint32 size = 128 * 1024; // XXX get size from BAR
			void *virt;
			INIT_DEBUGOUT2("bus_alloc_resource SYS_RES_MEMORY, reg 0x%x, adr %p\n", *rid, (void *)v);
			if (map_mem(&virt, (void *)v, size, 0, "SYS_RES_MEMORY") < 0)
				return 0;
			return (struct resource *) virt;
		}

		case SYS_RES_IRQ:
		{
			uint8 v = pci_read_config(dev, PCI_interrupt_line, 1);
			if (v == 0 || v == 0xff) {
				ERROROUT("bus_alloc_resource SYS_RES_IRQ: no irq");
				return 0;
			}
			return (struct resource *)(int)v;
		}

		default:
			INIT_DEBUGOUT("bus_alloc_resource default!\n");
			return 0;
	}
}
Пример #11
0
int main(int n_args, char * ll_args[])
{
  int i,n,t,t_total,n_proc,n_veg;
  int *p_lletres,id_lletres;
  int id_win,n_fil,n_col,mida_camp;
  char a1[20],a3[20],a4[20],a5[10],a6[10], fmis[80];
  void *p_win;

  if (n_args != 4)
  {	fprintf(stderr,"comanda: multiproc2 num_procs n_vegades n_lletres\n");
	exit(1);
  }
  n_proc = atoi(ll_args[1]);		/* convertir arguments a num. enter */
  n_veg = atoi(ll_args[2]);
  if (n_proc < 1) n_proc = 1;		/* i filtrar el seu valor */
  if (n_proc > MAX_PROCS) n_proc = MAX_PROCS;
  if (n_veg < 1) n_veg = 1;
  if (n_veg > MAX_VEGADES) n_veg = MAX_VEGADES;

  id_lletres = ini_mem(sizeof(int));	/* crear zona mem. compartida */
  p_lletres = map_mem(id_lletres);	/* obtenir adres. de mem. compartida */
  *p_lletres = atoi(ll_args[3]);	/* inicialitza variable compartida */
  if (*p_lletres < 1) *p_lletres = 1;
  if (*p_lletres > n_proc*n_veg) *p_lletres = n_proc*n_veg;
  sprintf(a3,"%i",id_lletres);	/* convertir identificador mem. en string */

  n_fil = n_proc+3;
  n_col = n_veg+2;
  mida_camp = win_ini(&n_fil,&n_col,'+',INVERS);
  if (mida_camp < 0)
  {			/* si no pot crear l'entorn de joc amb les curses */
    switch (mida_camp)
    {	case -1: fprintf(stderr,"camp de joc ja creat!\n"); break;
	case -2: fprintf(stderr,"no s'ha pogut inicialitzar l'entorn de curses!\n"); break;
	case -3: fprintf(stderr,"les mides del camp demanades son massa grans!\n"); break;
	case -4: fprintf(stderr,"no s'ha pogut crear la finestra!\n"); break;
    }
    elim_mem(id_lletres);	/* elimina zona de memoria compartida */
    exit(2);
  }
  id_win = ini_mem(mida_camp);	/* crear zona mem. compartida */
  p_win = map_mem(id_win);	/* obtenir adres. de mem. compartida */
  sprintf(a4,"%i",id_win);
  sprintf(a5,"%i",n_fil);	/* convertir mides camp en string */
  sprintf(a6,"%i",n_col);

  win_set(p_win,n_fil,n_col);		/* crea acces a finestra oberta */

  n = 0;
  for ( i = 0; i < n_proc; i++)
  {
    tpid[n] = fork();		/* crea un nou proces */
    if (tpid[n] == (pid_t) 0)		/* branca del fill */
    {
	sprintf(a1,"%i",(i+1));
	execlp("./mp_car2", "mp_car2", a1, ll_args[2], a3, a4, a5, a6, (char *)0);
	fprintf(stderr,"error: no puc executar el process fill \'mp_car2\'\n");
	exit(0);
    }
    else if (tpid[n] > 0) n++;		/* branca del pare */
  }
/* fprintf(stderr,"Pare: he creat %d processos fill, espero que acabin!\n\n",n);*/
      
  do
  { sprintf(fmis,"lletres = %d",*p_lletres);
    win_escristr(fmis);
    win_update();			/* actualitza visualitzacio CURSES */
    win_retard(20);
  } while (*p_lletres != 0);
      
  t_total = 0;
  for (i = 0; i < n; i++)
  {
    waitpid(tpid[i],&t,0);	/* espera finalitzacio d'un fill */
    t = t >> 8;			/* normalitza resultat	*/
/* 	fprintf(stderr,"el proces (%d) ha escrit %d lletres\n",tpid[i],t); */
    t_total += t;
  }
  win_fi();

  printf("\nJa han acabat tots els processos creats!\n");
  printf("Entre tots els processos han escrit %d lletres.\n",t_total);

  elim_mem(id_win);		/* elimina zones de memoria compartida */
  elim_mem(id_lletres);
  return(0);
}
Пример #12
0
void kmain(void)
{
	kernel_end = (uint64_t)heap_addr;
	kernel_heap_ptr = (uint8_t*)((uint64_t)&VMA + kernel_end + heap_size) ;
	UPD = (uint64_t*)((uint64_t)&VMA + kernel_end + 0x3000);
	KPD = (uint64_t*)((uint64_t)&VMA + kernel_end + 0x4000);
	PML4 = (uint64_t*)((uint64_t)&VMA + kernel_end);
	*(KPD + 511) = (kernel_end + 0x4000) | 3;
	map_mem(mboot_info);

#if _GFX_
	init_video();
#endif
	
	idt_install();
	isr_install();

	vmem_init();
	
	serial.init();

	extern void load_tss(void);
	load_tss();
	extern uint64_t k_tss64_sp;
	*(uint64_t*)( (uint64_t)&VMA + (uint64_t)&k_tss64_sp ) = 0xFFFFFFFFC0008000;

	pit_set_freq(2000);	// timer tick = 500 us
	pit_install();
	irq_install();

	extern void mouse_init();
	//mouse_init();
	extern void mouse_handler(void*);
	//irq_install_handler(12, mouse_handler);

	multiboot_module_t *mod = (multiboot_module_t*)(uint64_t)mboot_info->mods_addr;

	ramdev_private_t ramdev_private = 
		(ramdev_private_t) 
		{ 
			.ptr  = (void*)((uint64_t)&VMA + mod->mod_start),
			.size = (uint32_t)(mod->mod_end - mod->mod_start),
		};
		
 	inode_t ramdisk_inode =
	 	(inode_t) 
 		{
 			.name 	= "ramdisk",
 			.type	= FS_CHRDEV,
 			.fs		= &devfs,
 			.dev	= &ramdev,
 			.p 		= &ramdev_private, 
 		};
 	
 	vfs_create(&dev_root, "/", &ramdisk_inode);

	inode_t *rootfs = initramfs.load(&ramdisk_inode);
	
	vfs_mount_root(rootfs);
	
	irq_install_handler(1, kbd_handler);
	
	devman.init();
	fsman.init();
	
#if _DBG_CON_
	// We should disable debugging by this stage!
	serial.end();
#endif

	process_t *init = load_elf("/bin/init");
		
	extern void spawn_init(process_t*);
	spawn_init(init);
	for(;;);
}
Пример #13
0
int main(int n_args, char *ll_args[])
{
	
	int id_win,n_fil,n_col;
	void *p_win;
	int moviments,*p_moviments;
	int retard;
	int tecla,*p_tecla;
	int cont,*p_cont;
	int MAX_MOV;
	
	int l_pal;
	
	
	int ipo_pf;
	int ipo_pc;
	float po_pf;
	float v_pal;
	
	float aux1,aux2;
	int index;
	
	id_win = atoi(ll_args[1]);
	p_win = map_mem(id_win);
	
	n_fil = atoi(ll_args[2]);		/* obtenir dimensions del camp de joc */
	n_col = atoi(ll_args[3]);
	
	win_set(p_win,n_fil,n_col);	/* crea acces a finestra oberta pel proces pare */
	
	
	/* moviments,retard,tecla,cont,MAX_MOV,index,l_pal*/
	
	moviments= atoi(ll_args[4]);
	p_moviments = map_mem(moviments);	/* obtenir adres. de mem. compartida */
	
	
	
	retard= atoi(ll_args[5]);
	tecla= atoi(ll_args[6]);
	p_tecla = map_mem(tecla);	/* obtenir adres. de mem. compartida */
	
	cont= atoi(ll_args[7]);
	p_cont = map_mem(cont);	/* obtenir adres. de mem. compartida */
	
	
	MAX_MOV= atoi(ll_args[8]);
	index= atoi(ll_args[9]);	
	l_pal= atoi(ll_args[10]);
	ipo_pf= atoi(ll_args[11]);
	ipo_pc= atoi(ll_args[12]);
	aux1= atoi(ll_args[13]);
	aux2= atoi(ll_args[14]);
	
	po_pf=aux1/100;
	v_pal=aux2/100;
	
	
	
	
	
	int f_h;
	
	/* char rh,rv,rd; */
	int i= index; 
	int j=i+1;
	char c = j +'0';
  
do{
  
  f_h = po_pf + v_pal;		/* posicio hipotetica de la paleta */
 
  if (f_h != ipo_pf)	/* si pos. hipotetica no coincideix amb pos. actual */
  { 
    if (v_pal > 0.0)			/* verificar moviment cap avall */
    {
	
	if (win_quincar(f_h+l_pal-1,ipo_pc) == ' ')   /* si no hi ha obstacle */
	{
	  
	  win_escricar(ipo_pf, ipo_pc,' ',NO_INV);      /* esborra primer bloc */
	 
	  po_pf += v_pal; ipo_pf = po_pf;		/* actualitza posicio */
	  
	  win_escricar(ipo_pf+l_pal-1, ipo_pc,c,INVERS); /* impr. ultim bloc */
    

	}
	else{		/* si hi ha obstacle, canvia el sentit del moviment */
	   v_pal = -v_pal;
	  *p_moviments=*p_moviments+1;
      

       
     }}
    else			/* verificar moviment cap amunt */
    {

	if (win_quincar(f_h,ipo_pc) == ' ')        /* si no hi ha obstacle */
	{
	   			
	  win_escricar(ipo_pf+l_pal-1,ipo_pc,' ',NO_INV); /* esbo. ultim bloc */
	 
	  po_pf += v_pal; ipo_pf = po_pf;		/* actualitza posicio */
	  
	  win_escricar(ipo_pf, ipo_pc,c,INVERS);	/* impr. primer bloc */
	 
	}
	else{		/* si hi ha obstacle, canvia el sentit del moviment */
	   v_pal = -v_pal;
	   *p_moviments=*p_moviments+1;
        
         
     }}
  }
  else 
  
  po_pf += v_pal; 	/* actualitza posicio vertical real de la paleta */
  
  
  win_retard(retard);
  
	 } while (*p_tecla != TEC_RETURN && (*p_cont==-1) && *p_moviments<MAX_MOV);

return(0);
}