Changeset 390 for soft/giet_vm
- Timestamp:
- Aug 7, 2014, 4:57:07 PM (10 years ago)
- Location:
- soft/giet_vm/giet_libs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_libs/malloc.c
r382 r390 78 78 } 79 79 80 // compute alloc[] minimal array size80 // compute size of block containin alloc[] array 81 81 alloc_size = heap_size / MIN_BLOCK_SIZE; 82 if ( alloc_size < MIN_BLOCK_SIZE) alloc_size = MIN_BLOCK_SIZE; 82 83 83 84 // get index for the corresponding block … … 98 99 unsigned int base = heap_base; 99 100 unsigned int* ptr; 100 for ( index = heap_index-1 ; index > alloc_index ; index-- )101 for ( index = heap_index-1 ; index >= alloc_index ; index-- ) 101 102 { 102 103 heap[x][y].free[index] = base; … … 247 248 } 248 249 250 // normalize size 251 if ( size < MIN_BLOCK_SIZE ) size = MIN_BLOCK_SIZE; 252 249 253 // compute requested_index for the free[] array 250 254 unsigned int requested_index = GET_SIZE_INDEX( size ); … … 258 262 requested_index ); 259 263 260 // update the alloc[] array 261 unsigned offset = (base - heap[x][y].heap_base) / MIN_BLOCK_SIZE; 262 unsigned char* ptr = (unsigned char*)(heap[x][y].alloc_base + offset); 263 *ptr = requested_index; 264 // update the alloc[] array if block found 265 if ( base != 0 ) 266 { 267 unsigned offset = (base - heap[x][y].heap_base) / MIN_BLOCK_SIZE; 268 unsigned char* ptr = (unsigned char*)(heap[x][y].alloc_base + offset); 269 *ptr = requested_index; 270 } 264 271 265 272 // release the lock … … 286 293 void free( void* ptr ) 287 294 { 288 // To be done 289 // - first : to compute the cluster coordinate 290 // - second : retrieve the block length from the 291 // - third : try to concatenate with another free block of same size 292 // - fourth : update the free[] array 295 unsigned int vaddr = (unsigned int)ptr; 296 297 // get the cluster coordinate 298 unsigned int x; 299 unsigned int y; 300 giet_get_xy( ptr, &x, &y ); 301 302 // compute index in alloc[] array 303 unsigned index = ( (unsigned int)ptr - heap[x][y].heap_base ) / MAX_BLOCK_SIZE; 304 305 // get the freed block size_index 306 unsigned char* p i = (unsigned char*)(heap[x][y].alloc_base + index); 307 unsigned int size_index = (unsigned int)*p; 308 309 // update the free[] array and NEXT pointer 310 *(unsigned int*)ptr = heap[x][y].free[size_index]; 311 heap[x][y].free[size_index] = (unsigned int)ptr; 312 313 // TODO try to concatenate with another free block of same size 314 // this require probably to replace this simple push by a recursive function 293 315 } 294 316 -
soft/giet_vm/giet_libs/stdio.c
r382 r390 5 5 // Copyright (c) UPMC-LIP6 6 6 /////////////////////////////////////////////////////////////////////////////////// 7 // The stdio.c and stdio.h files are part of the GIET_VM nano-kernel.8 // This library contains all user-level functions that contain a system call9 // to access protected or shared ressources.10 ///////////////////////////////////////////////////////////////////////////////////11 7 12 8 #include <stdarg.h> 13 9 #include <stdio.h> 14 10 #include <giet_config.h> 11 12 //////////////////////////////////////////////////////////////////////////////////// 13 ///////////////////// MIPS32 related system calls ///////////////////////////// 14 //////////////////////////////////////////////////////////////////////////////////// 15 16 ///////////////// 17 int giet_procid() 18 { 19 return sys_call( SYSCALL_PROCID, 20 0, 0, 0, 0 ); 21 } 22 23 //////////////////// 24 int giet_proctime() 25 { 26 return sys_call( SYSCALL_PROCTIME, 27 0, 0, 0, 0 ); 28 } 29 30 /////////////// 31 int giet_rand() 32 { 33 unsigned int x = sys_call(SYSCALL_PROCTIME, 34 0, 0, 0, 0); 35 if ((x & 0xF) > 7) 36 { 37 return (x*x & 0xFFFF); 38 } 39 else 40 { 41 return (x*x*x & 0xFFFF); 42 } 43 } 15 44 16 45 //////////////////////////////////////////////////////////////////////////////////// … … 498 527 (unsigned int)buffer, 499 528 count, 500 offset ) != count ) giet_exit(" in giet_fat_read()");529 offset ) != count ) giet_exit("ERROR in giet_fat_read()"); 501 530 } 502 531 … … 511 540 (unsigned int)buffer, 512 541 count, 513 offset ) != count ) giet_exit(" in giet_fat_write()");542 offset ) != count ) giet_exit("ERROR in giet_fat_write()"); 514 543 } 515 544 … … 541 570 offset, 542 571 whence, 543 0 ) ) giet_exit(" in giet_fat_lseek()");572 0 ) ) giet_exit("ERROR in giet_fat_lseek()"); 544 573 } 545 574 … … 549 578 if ( sys_call( SYSCALL_FAT_FSTAT, 550 579 fd, 551 0, 0, 0 ) ) giet_exit(" in giet_fat_lseek()");580 0, 0, 0 ) ) giet_exit("ERROR in giet_fat_lseek()"); 552 581 } 553 582 … … 557 586 if ( sys_call( SYSCALL_FAT_CLOSE, 558 587 fd, 559 0, 0, 0 ) ) giet_exit("in giet_fat_close()"); 560 } 561 562 563 ////////////////////////////////////////////////////////////////////////////////// 564 ///////////////////// Miscellaneous system calls ///////////////////////////////// 565 ////////////////////////////////////////////////////////////////////////////////// 566 567 ///////////////// 568 int giet_procid() 569 { 570 return sys_call( SYSCALL_PROCID, 571 0, 0, 0, 0 ); 572 } 573 574 //////////////////// 575 int giet_proctime() 576 { 577 return sys_call( SYSCALL_PROCTIME, 578 0, 0, 0, 0 ); 579 } 588 0, 0, 0 ) ) giet_exit("ERROR in giet_fat_close()"); 589 } 590 591 592 ////////////////////////////////////////////////////////////////////////////////// 593 ///////////////////// Task context system calls ///////////////////////////////// 594 ////////////////////////////////////////////////////////////////////////////////// 580 595 581 596 /////////////////////// … … 600 615 } 601 616 602 /////////////// 603 int giet_rand() 604 { 605 unsigned int x = sys_call(SYSCALL_PROCTIME, 0, 0, 0, 0); 606 if ((x & 0xF) > 7) { 607 return (x*x & 0xFFFF); 608 } 609 else { 610 return (x*x*x & 0xFFFF); 611 } 612 } 617 618 ////////////////////////////////////////////////////////////////////////////////// 619 ///////////////////// Miscellaneous system calls ///////////////////////////////// 620 ////////////////////////////////////////////////////////////////////////////////// 613 621 614 622 ////////////////////////////// … … 625 633 { 626 634 if ( condition == 0 ) giet_exit( string ); 635 } 636 637 ////////////////////////// 638 void giet_context_switch() 639 { 640 sys_call( SYSCALL_CTX_SWITCH, 641 0, 0, 0, 0 ); 627 642 } 628 643 … … 636 651 (unsigned int) vobj_name, 637 652 (unsigned int) vobj_vaddr, 638 0 ) ) giet_exit(" in giet_vobj_get_vbase()");653 0 ) ) giet_exit("ERROR in giet_vobj_get_vbase()"); 639 654 } 640 655 … … 646 661 cluster_id, 647 662 (unsigned int) buffer, 648 0, 0) ) giet_exit("in giet_proc_number()"); 649 } 650 651 ////////////////////////// 652 void giet_context_switch() 653 { 654 sys_call( SYSCALL_CTX_SWITCH, 655 0, 0, 0, 0 ); 663 0, 0) ) giet_exit("ERROR in giet_proc_number()"); 656 664 } 657 665 … … 666 674 (unsigned int)length, 667 675 x, 668 y ) ) giet_exit("in giet_heap_info()"); 676 y ) ) giet_exit("ERROR in giet_heap_info()"); 677 } 678 679 ///////////////////////////////////////// 680 void giet_get_xy( void* ptr, 681 unsigned int* px, 682 unsigned int* py ) 683 { 684 if ( sys_call( SYSCALL_GET_XY, 685 (unsigned int)ptr, 686 (unsigned int)px, 687 (unsigned int)py, 688 0 ) ) giet_exit("ERROR in giet_get_xy()"); 669 689 } 670 690 -
soft/giet_vm/giet_libs/stdio.h
r389 r390 4 4 // Author : alain greiner & Joel Porquet 5 5 // Copyright (c) UPMC-LIP6 6 /////////////////////////////////////////////////////////////////////////////////// 7 // The stdio.c and stdio.h files are part of the GIET_VM nano-kernel. 8 // This library contains all user-level functions that contain a system call 9 // to access protected or shared ressources. 6 10 /////////////////////////////////////////////////////////////////////////////////// 7 11 … … 40 44 #define SYSCALL_CTX_SWITCH 0x19 41 45 #define SYSCALL_VOBJ_GET_VBASE 0x1A 42 #define SYSCALL_ FREE_1B0x1B46 #define SYSCALL_GET_XY 0x1B 43 47 #define SYSCALL_NIC_CMA_START 0x1C 44 48 #define SYSCALL_NIC_CMA_STOP 0x1D … … 446 450 unsigned int y ); 447 451 452 ////////////////////////////////////////////////////////////////////////// 453 // This function takes as input a virtual address (ptr argument), 454 // and returns through the (px,py) arguments the coordinates of 455 // the cluster containing the physical address associated to ptr. 456 // In case of error (unmapped virtual address), it makes a giet_exit(). 457 ////////////////////////////////////////////////////////////////////////// 458 extern void giet_get_xy( void* ptr, 459 unsigned int* px, 460 unsigned int* py ); 461 448 462 #endif 449 463
Note: See TracChangeset
for help on using the changeset viewer.