void  map_Matrix()
{

	int i,j,k,index;
	int fd=open("./MatrixC",O_RDWR);
	if(fd==-1)
	{
		perror("File not opened ");
		exit(1);

	}

	for(i=0;i<(nRows);i++)
	{
		//printf(" %d \n ",i+1);
		for(j=0;j<(nCols);j++)
		{
			printf("\n ------------- i    and   j   vale is %d %d\n",i,j);
			if(j%(block_size/4)==0)
			{
				MatrixC=map_block("./MatrixC",2,i,j%(block_size/4));
				memset(MatrixC,0,block_size);
				index=0;
			}
			for(k=0;k<(nCols*4/block_size);k++)
			{
				MatrixA=map_block("./MatrixA",1,i,k);
				MatrixB=map_block("./MatrixB",1,j,k);
				MatrixC[index]+=block_by_block_multiply();
				munmap(MatrixB,block_size);
				munmap(MatrixA,block_size);
			}
			index++;

			if((j+1)%(block_size/4)==0)
			{

                              	int loc=0,w,buf=0;
				for(loc=0;loc<block_size/4;loc++)
				{ 
					buf=MatrixC[loc];
					//printf("%d ",buf);
 					w=write(fd,&buf,4);
				}
				munmap(MatrixC,block_size);

			}
	        }
	}

	close(fd);
}
Exemplo n.º 2
0
Arquivo: fs.c Projeto: yaobaiwei/JOS
// Make sure a particular disk block is loaded into memory.
// Returns 0 on success, or a negative error code on error.
// 
// If blk != 0, set *blk to the address of the block in memory.
//
// Hint: Use diskaddr, map_block, and ide_read.
static int
read_block(uint32_t blockno, char **blk)
{
	int r;
	char *addr;

	if (super && blockno >= super->s_nblocks)
		panic("reading non-existent block %08x\n", blockno);

	if (bitmap && block_is_free(blockno))
		panic("reading free block %08x\n", blockno);
	
	addr = diskaddr(blockno);
    if(!block_is_mapped(blockno)){
        if((r = map_block(blockno)) < 0)
            return r;
        r = ide_read(blockno*BLKSECTS, (void *)addr, BLKSECTS);
        if(r < 0)
            return r;
    }
    if(blk)
        *blk = addr;
	
	return 0;
}
Exemplo n.º 3
0
Arquivo: fs.c Projeto: darfux/jos
// Make sure a particular disk block is loaded into memory.
// Returns 0 on success, or a negative error code on error.
// 
// If blk != 0, set *blk to the address of the block in memory.
//
// Hint: Use diskaddr, map_block, and ide_read.
static int
read_block(uint32_t blockno, char **blk)
{
	int r;
	char *addr;

	if (super && blockno >= super->s_nblocks)
		panic("reading non-existent block %08x\n", blockno);

	if (bitmap && block_is_free(blockno))
		panic("reading free block %08x\n", blockno);

	// LAB 5: Your code here.
	addr = diskaddr(blockno);
	int error = map_block(blockno);
	if(error<0) return error;

	int secno = blockno*BLKSECTS;
	error = ide_read(secno, addr, (size_t)BLKSECTS);
	if(error) return error;

	if(blk) *blk = addr;
	// panic("read_block not implemented");

	return 0;
}
Exemplo n.º 4
0
Arquivo: fs.c Projeto: sunrenjie/jos
// Make sure a particular disk block is loaded into memory.
// Returns 0 on success, or a negative error code on error.
// 
// If blk != 0, set *blk to the address of the block in memory.
//
// Hint: Use diskaddr, map_block, and ide_read.
static int
read_block(uint32_t blockno, char **blk)
{
	int r;
	char *addr;

	if (super && blockno >= super->s_nblocks)
		panic("reading non-existent block %08x\n", blockno);

	if (bitmap && block_is_free(blockno))
		panic("reading free block %08x\n", blockno);

	// LAB 5: Your code here.
	addr = diskaddr(blockno);
	if (block_is_mapped(blockno)) {
		goto succeeded;
	}

	// now that the block is not in memory, allocate memory and read it in.
	if ((r = map_block(blockno)) < 0)
		return r;
	if ((r = ide_read(blockno * BLKSECTS, addr, BLKSECTS)) < 0)
		return r;

succeeded:
	if (blk)
		*blk = addr;
	return 0;
}
Exemplo n.º 5
0
Arquivo: fs.c Projeto: reesun/guavaos
// Make sure a particular disk block is loaded into memory.
// Returns 0 on success, or a negative error code on error.
// 
// If blk != 0, set *blk to the address of the block in memory.
//
// Hint: Use diskaddr, map_block, and ide_read.
static int
read_block(uint32_t blockno, char **blk)
{
	int r;
	char *addr;

	if (super && blockno >= super->s_nblocks)
		panic("reading non-existent block %08x\n", blockno);

	if (bitmap && block_is_free(blockno))
		panic("reading free block %08x\n", blockno);

	// LAB 5: Your code here.
	r = map_block(blockno);
	if (r)
		return r;

	addr = diskaddr(blockno);
	r = ide_read(blockno * BLKSECTS, addr, BLKSECTS);
	if (r)
		return r;

	if (blk)
		*blk = addr;

	return sys_page_map(0, addr, 0, addr, vpt[VPN(addr)] & PTE_USER);
}
Exemplo n.º 6
0
Arquivo: ex8.c Projeto: 128keaton/ltdc
// do the whole preview table and stuff :)
void do_preview(u_char* buf) {
	int asc, x, y, addr;
	u_char st;

	set_color(15, 4, 4);
	set_sprite_8(0, square);

	fill(MODE2_ATTR, 0xF0, MODE2_MAX);

	// start blitting buffer at pixel (16,16)
	addr = map_block(16, 16);

	// 16 chars of width (*8), 16 "lines", jump 256 in VRAM for each line
	blit_ram_vram(buf, addr, 16 * 8, 16, 16 * 8, 256);

	// fill yellow background
	blit_fill_vram(MODE2_ATTR + map_block(8, 8), 0x1A, 8 * 18, 18, 256);

	x = 0; y = 0;

	// preview loop
	while (!get_trigger(0)) {
		// move the cursor and set the zooming
		st = st_dir[get_stick(0)];

		x += (st & st_right) ? 1 : ((st & st_left) ? -1 : 0);
		y += (st & st_down) ? 1 : ((st & st_up) ? -1 : 0);

		x &= 15;
		y &= 15;
		asc = (y << 4) + x;
		put_sprite_8(0, (x + 2) << 3, (y + 2) << 3, 0, 9);

		preview_char(buf + (asc << 3));
	}	
}
Exemplo n.º 7
0
Arquivo: fs.c Projeto: ren85/jos2006
// Allocate a block -- first find a free block in the bitmap,
// then map it into memory.
int
alloc_block(void)
{
	int r, bno;

	if ((r = alloc_block_num()) < 0)
		return r;
	bno = r;

	if ((r = map_block(bno)) < 0) {
		free_block(bno);
		return r;
	}
	return bno;
}
Exemplo n.º 8
0
Arquivo: fs.c Projeto: sunrenjie/jos
// Allocate a block -- first find a free block in the bitmap,
// then map it into memory.
int
alloc_block(void)
{
	int r, bno;

	if ((r = alloc_block_num()) < 0)
		return r;
	bno = r;

	if ((r = map_block(bno)) < 0) {
		free_block(bno);
		return r;
	}
	memset(diskaddr(bno), 0, BLKSIZE);
	return bno;
}
Exemplo n.º 9
0
extern void UArray2b_map(T array2b, void apply(int col, int row, T array2b,
                         void *elem, void *cl), void *cl)
{
        assert(array2b);
        assert(apply);

        int block_width = ceil((float)array2b->width /
                               (float)array2b->blocksize);
        int block_height = ceil((float)array2b->height /
                                (float)array2b->blocksize);
        int col, row;

        for(row = 0; row < block_height; row++) {
                for (col = 0; col < block_width; col++) {
                        map_block(array2b, 
                                *(UArray2_T *)UArray2_at(array2b->blockarray,
                                  col, row), col, row, apply, cl); 
                }
        }
}
Exemplo n.º 10
0
Arquivo: fs.c Projeto: mainboy/xv6
// Make sure a particular disk block is loaded into memory.
// Returns 0 on success, or a negative error code on error.
// 
// If blk != 0, set *blk to the address of the block in memory.
//
// Hint: Use diskaddr, map_block, and ide_read.
static int
read_block(uint32_t blockno, char **blk)
{
	int r;
	char *addr;

	if (super && blockno >= super->s_nblocks)
		panic("reading non-existent block %08x\n", blockno);

	if (bitmap && block_is_free(blockno))
		panic("reading free block %08x\n", blockno);

	// LAB 5: Your code here.
	addr = diskaddr(blockno);
	if(blk != NULL)
		*blk = addr;
	if(va_is_mapped(addr) == 1)
		return 0;
	if((r = map_block(blockno)) < 0)
		return r;
	if((r = ide_read(blockno * BLKSECTS, addr, BLKSECTS)) < 0)
		return r;
	return 0;
}
Exemplo n.º 11
0
__NO_SAFESTACK thrd_t __allocate_thread(
    size_t requested_guard_size,
    size_t requested_stack_size,
    const char* thread_name,
    char vmo_name[ZX_MAX_NAME_LEN]) {
    thread_allocation_acquire();

    const size_t guard_size =
        requested_guard_size == 0 ? 0 : round_up_to_page(requested_guard_size);
    const size_t stack_size = round_up_to_page(requested_stack_size);

    const size_t tls_size = libc.tls_size;
    const size_t tcb_size = round_up_to_page(tls_size);

    const size_t vmo_size = tcb_size + stack_size * 2;
    zx_handle_t vmo;
    zx_status_t status = _zx_vmo_create(vmo_size, 0, &vmo);
    if (status != ZX_OK) {
        __thread_allocation_release();
        return NULL;
    }
    struct iovec tcb, tcb_region;
    if (map_block(_zx_vmar_root_self(), vmo, 0, tcb_size, PAGE_SIZE, PAGE_SIZE,
                  &tcb, &tcb_region)) {
        __thread_allocation_release();
        _zx_handle_close(vmo);
        return NULL;
    }

    thrd_t td = copy_tls(tcb.iov_base, tcb.iov_len);

    // At this point all our access to global TLS state is done, so we
    // can allow dlopen again.
    __thread_allocation_release();

    // For the initial thread, it's too early to call snprintf because
    // it's not __NO_SAFESTACK.
    if (vmo_name != NULL) {
        // For other threads, try to give the VMO a name that includes
        // the thrd_t value (and the TLS size if that fits too), but
        // don't use a truncated value since that would be confusing to
        // interpret.
        if (snprintf(vmo_name, ZX_MAX_NAME_LEN, "%s:%p/TLS=%#zx",
                     thread_name, td, tls_size) < ZX_MAX_NAME_LEN ||
            snprintf(vmo_name, ZX_MAX_NAME_LEN, "%s:%p",
                     thread_name, td) < ZX_MAX_NAME_LEN)
            thread_name = vmo_name;
    }
    _zx_object_set_property(vmo, ZX_PROP_NAME,
                            thread_name, strlen(thread_name));

    if (map_block(_zx_vmar_root_self(), vmo,
                  tcb_size, stack_size, guard_size, 0,
                  &td->safe_stack, &td->safe_stack_region)) {
        _zx_vmar_unmap(_zx_vmar_root_self(),
                       (uintptr_t)tcb_region.iov_base, tcb_region.iov_len);
        _zx_handle_close(vmo);
        return NULL;
    }

    if (map_block(_zx_vmar_root_self(), vmo,
                  tcb_size + stack_size, stack_size, guard_size, 0,
                  &td->unsafe_stack, &td->unsafe_stack_region)) {
        _zx_vmar_unmap(_zx_vmar_root_self(),
                       (uintptr_t)td->safe_stack_region.iov_base,
                       td->safe_stack_region.iov_len);
        _zx_vmar_unmap(_zx_vmar_root_self(),
                       (uintptr_t)tcb_region.iov_base, tcb_region.iov_len);
        _zx_handle_close(vmo);
        return NULL;
    }

    _zx_handle_close(vmo);
    td->tcb_region = tcb_region;
    td->locale = &libc.global_locale;
    td->head.tp = (uintptr_t)pthread_to_tp(td);
    td->abi.stack_guard = __stack_chk_guard;
    td->abi.unsafe_sp =
        (uintptr_t)td->unsafe_stack.iov_base + td->unsafe_stack.iov_len;
    return td;
}