Add changes to read syscall
This commit is contained in:
parent
86705308b1
commit
a56f7b5e31
|
@ -5,7 +5,7 @@ static unsigned char kbdus_sh[250];
|
|||
// static unsigned char kbdsp_sh[250];
|
||||
// static unsigned char kbdsp[250];
|
||||
|
||||
#define SIZE 30
|
||||
#define SIZE 1
|
||||
unsigned char buffer[SIZE] = {0};
|
||||
unsigned char * current = buffer;
|
||||
unsigned char * last = buffer;
|
||||
|
@ -34,10 +34,10 @@ void testKeyboardInterrupt(unsigned char c) {
|
|||
flag = ~(flag | 0xFE);
|
||||
}
|
||||
|
||||
else if (c == 0x38) { //ALT
|
||||
else if (c == 0x38) {
|
||||
flagChangeAlt = 0;
|
||||
}
|
||||
else if (c == 0x3B) { //F1
|
||||
else if (c == 0x3B) {
|
||||
flagChangeF1 = 0;
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,7 @@ unsigned char getKeyFromBuffer() {
|
|||
}
|
||||
|
||||
void keyboard_handler() {
|
||||
unblockIO();
|
||||
unsigned char c = getCharInterrupt();
|
||||
testKeyboardInterrupt(c);
|
||||
}
|
||||
|
|
|
@ -2,11 +2,7 @@
|
|||
#define KEYBOARD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// static unsigned char kbdsp[250];
|
||||
// static unsigned char kbdus[250];
|
||||
// static unsigned char kbdsp_sh[250];
|
||||
// static unsigned char kbdus_sh[250];
|
||||
#include "schedulerLib.h"
|
||||
|
||||
void keyboard_handler();
|
||||
unsigned char getKeyFromBuffer();
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#define SEM_NAME "Pipes"
|
||||
#define PIPE_DATA_MAX_SIZE 100
|
||||
#define MAX_PIDS_SIZE 50
|
||||
#define FULL_SEM_NAME "FullSem"
|
||||
|
||||
int exists(pipe_t * pipe);
|
||||
node_t * searchPipe(node_t ** previous, int fd);
|
||||
|
|
|
@ -13,6 +13,7 @@ typedef struct pipe_t {
|
|||
int currentW;
|
||||
char * name;
|
||||
sem_t * sem;
|
||||
sem_t * fullSem;
|
||||
} pipe_t;
|
||||
|
||||
typedef struct node_t {
|
||||
|
|
|
@ -12,8 +12,8 @@ void forceTimer();
|
|||
void haltcpu();
|
||||
|
||||
#define STACK_SIZE 1024 * 512
|
||||
#define MAX_PRIORITY 40 // Maximum number for a priority
|
||||
#define MIN_PRIORITY 0 // Minimum number for a priority (yet maximum level of priority)
|
||||
#define MAX_PRIORITY 40
|
||||
#define MIN_PRIORITY 0
|
||||
#define DEF_PRIORITY 0
|
||||
#define PROCESS_DATA_MAX_SIZE 100
|
||||
#define MAX_ATTR_SIZE 6
|
||||
|
|
|
@ -18,5 +18,7 @@ int getFdIn();
|
|||
void checkSleeping();
|
||||
char unblockFirst(int pid);
|
||||
void sleep(int secs);
|
||||
char blockIO();
|
||||
void unblockIO();
|
||||
|
||||
#endif
|
|
@ -42,10 +42,19 @@ uint64_t read(uint64_t fd, uint64_t buffer, uint64_t length) {
|
|||
if (fd == STDIN) {
|
||||
while (length-- > 0) {
|
||||
*bufferAux = getKeyFromBuffer();
|
||||
if (*bufferAux == 0)
|
||||
break;
|
||||
if (*bufferAux == 0) {
|
||||
bufferAux--;
|
||||
length++;
|
||||
readBytes--;
|
||||
blockIO();
|
||||
}
|
||||
if (*bufferAux == '\v') {
|
||||
return -1;
|
||||
// break;
|
||||
}
|
||||
readBytes++;
|
||||
bufferAux++;
|
||||
// blockIO();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -141,7 +141,7 @@ void test_mm(){
|
|||
}
|
||||
}
|
||||
|
||||
void enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *argv[], int * fd);
|
||||
// void enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *argv[], int * fd);
|
||||
void initScheduler();
|
||||
|
||||
void _cli();
|
||||
|
|
|
@ -1,336 +0,0 @@
|
|||
// #ifndef BUDDY
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include <stdint.h>
|
||||
// #include <assert.h>
|
||||
// #include <string.h>
|
||||
// #include <naiveConsole.h>
|
||||
|
||||
// #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
||||
|
||||
// #define portCHAR char
|
||||
// #define portFLOAT float
|
||||
// #define portDOUBLE double
|
||||
// #define portLONG long
|
||||
// #define portSHORT short
|
||||
// #define portSTACK_TYPE uint32_t
|
||||
// #define portBASE_TYPE long
|
||||
|
||||
// typedef portSTACK_TYPE StackType_t;
|
||||
// typedef long BaseType_t;
|
||||
// typedef unsigned long UBaseType_t;
|
||||
|
||||
// #define configSUPPORT_STATIC_ALLOCATION 1
|
||||
// #define configSUPPORT_DYNAMIC_ALLOCATION 1
|
||||
// #define configTOTAL_HEAP_SIZE 1024
|
||||
// #define configAPPLICATION_ALLOCATED_HEAP 0
|
||||
// #define portBYTE_ALIGNMENT 8
|
||||
// #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) // 8
|
||||
// #define pdFALSE ( ( BaseType_t ) 0 )
|
||||
// #define pdTRUE ( ( BaseType_t ) 1 )
|
||||
// #define portPOINTER_SIZE_TYPE uint32_t
|
||||
|
||||
// /* A few bytes might be lost to byte aligning the heap start address. */
|
||||
// #define configADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT )
|
||||
|
||||
// /*
|
||||
// * Initialises the heap structures before their first use.
|
||||
// */
|
||||
// static void prvHeapInit(void);
|
||||
|
||||
// /* Allocate the memory for the heap. */
|
||||
// // #if( configAPPLICATION_ALLOCATED_HEAP == 1 )
|
||||
// // /* The application writer has already defined the array used for the RTOS
|
||||
// // heap - probably so it can be placed in a special segment or address. */
|
||||
// // extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
|
||||
// // #else
|
||||
// // static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
|
||||
// // #endif /* configAPPLICATION_ALLOCATED_HEAP */
|
||||
|
||||
// static uint8_t *ucHeap;
|
||||
// void initMemoryManager(void * managedMemory) {
|
||||
// ucHeap = managedMemory;
|
||||
// }
|
||||
|
||||
// /* Define the linked list structure. This is used to link free blocks in order
|
||||
// of their size. */
|
||||
// typedef struct A_BLOCK_LINK
|
||||
// {
|
||||
// struct A_BLOCK_LINK *pxNextFreeBlock; /*<< The next free block in the list. */
|
||||
// size_t xBlockSize; /*<< The size of the free block. */
|
||||
// } BlockLink_t;
|
||||
|
||||
|
||||
// static const uint16_t heapSTRUCT_SIZE = ( ( sizeof ( BlockLink_t ) + ( portBYTE_ALIGNMENT - 1 ) ) & ~portBYTE_ALIGNMENT_MASK );
|
||||
// #define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) )
|
||||
|
||||
// /* Create a couple of list links to mark the start and end of the list. */
|
||||
// static BlockLink_t xStart, xEnd;
|
||||
|
||||
// /* Keeps track of the number of free bytes remaining, but says nothing about
|
||||
// fragmentation. */
|
||||
// static size_t xFreeBytesRemaining = configADJUSTED_HEAP_SIZE;
|
||||
|
||||
// /* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */
|
||||
|
||||
// /*
|
||||
// * Insert a block into the list of free blocks - which is ordered by size of
|
||||
// * the block. Small blocks at the start of the list and large blocks at the end
|
||||
// * of the list.
|
||||
// */
|
||||
/*
|
||||
// #define prvInsertBlockIntoFreeList( pxBlockToInsert ) \
|
||||
// { \
|
||||
// BlockLink_t *pxIterator; \
|
||||
// size_t xBlockSize; \
|
||||
// \
|
||||
// xBlockSize = pxBlockToInsert->xBlockSize; \
|
||||
// \
|
||||
// for( pxIterator = &xStart; pxIterator->pxNextFreeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextFreeBlock ) \
|
||||
// { \
|
||||
// } \
|
||||
// \
|
||||
// pxBlockToInsert->pxNextFreeBlock = pxIterator->pxNextFreeBlock; \
|
||||
// pxIterator->pxNextFreeBlock = pxBlockToInsert; \
|
||||
// }
|
||||
*/
|
||||
// /*-----------------------------------------------------------*/
|
||||
// void *pvPortMalloc( size_t xWantedSize )
|
||||
// {
|
||||
// BlockLink_t *pxBlock, *pxPreviousBlock, *pxNewBlockLink;
|
||||
// static BaseType_t xHeapHasBeenInitialised = pdFALSE;
|
||||
// void *pvReturn = NULL;
|
||||
// // vTaskSuspendAll();
|
||||
// {
|
||||
// /* If this is the first call to malloc then the heap will require
|
||||
// initialisation to setup the list of free blocks. */
|
||||
// if( xHeapHasBeenInitialised == pdFALSE )
|
||||
// {
|
||||
// prvHeapInit();
|
||||
// xHeapHasBeenInitialised = pdTRUE;
|
||||
// }
|
||||
|
||||
// /* The wanted size is increased so it can contain a BlockLink_t
|
||||
// structure in addition to the requested amount of bytes. */
|
||||
// if( xWantedSize > 0 )
|
||||
// {
|
||||
// xWantedSize += heapSTRUCT_SIZE;
|
||||
|
||||
// /* Ensure that blocks are always aligned to the required number of bytes. */
|
||||
// if( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) != 0 )
|
||||
// {
|
||||
// /* Byte alignment required. */
|
||||
// xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
|
||||
// }
|
||||
// }
|
||||
|
||||
// ncPrint("MALLOC: ");
|
||||
// ncPrintDec(xFreeBytesRemaining);
|
||||
// ncPrint(" ");
|
||||
// ncPrintDec(xWantedSize);
|
||||
// ncPrint(" ");
|
||||
// ncPrintDec(configADJUSTED_HEAP_SIZE);
|
||||
// ncPrint(" ---- ");
|
||||
// if( ( xWantedSize > 0 ) && ( xWantedSize < configADJUSTED_HEAP_SIZE ) )
|
||||
// {
|
||||
// /* Blocks are stored in byte order - traverse the list from the start
|
||||
// (smallest) block until one of adequate size is found. */
|
||||
// pxPreviousBlock = &xStart;
|
||||
// pxBlock = xStart.pxNextFreeBlock;
|
||||
// while( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextFreeBlock != NULL ) )
|
||||
// {
|
||||
// pxPreviousBlock = pxBlock;
|
||||
// ncPrintDec(pxBlock->xBlockSize);
|
||||
// ncPrint(" - ");
|
||||
// pxBlock = pxBlock->pxNextFreeBlock;
|
||||
// }
|
||||
|
||||
// /* If we found the end marker then a block of adequate size was not found. */
|
||||
// if( pxBlock != &xEnd )
|
||||
// {
|
||||
// /* Return the memory space - jumping over the BlockLink_t structure
|
||||
// at its start. */
|
||||
// pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE );
|
||||
|
||||
// /* This block is being returned for use so must be taken out of the
|
||||
// list of free blocks. */
|
||||
// pxPreviousBlock->pxNextFreeBlock = pxBlock->pxNextFreeBlock;
|
||||
|
||||
// /* If the block is larger than required it can be split into two. */
|
||||
// if( ( pxBlock->xBlockSize - xWantedSize ) > heapMINIMUM_BLOCK_SIZE )
|
||||
// {
|
||||
// /* This block is to be split into two. Create a new block
|
||||
// following the number of bytes requested. The void cast is
|
||||
// used to prevent byte alignment warnings from the compiler. */
|
||||
// pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );
|
||||
|
||||
// /* Calculate the sizes of two blocks split from the single
|
||||
// block. */
|
||||
// pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
|
||||
// pxBlock->xBlockSize = xWantedSize;
|
||||
|
||||
// /* Insert the new block into the list of free blocks. */
|
||||
// prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );
|
||||
// }
|
||||
|
||||
// }
|
||||
// // tengo 16 de info y de alineamiento 8!
|
||||
// ncPrint("Dentro: ");
|
||||
// ncPrintDec(xFreeBytesRemaining);
|
||||
// ncPrint(" y ");
|
||||
// xFreeBytesRemaining -= pxBlock->xBlockSize;
|
||||
// ncPrintDec(xFreeBytesRemaining);
|
||||
// ncNewline();
|
||||
// }
|
||||
|
||||
// // traceMALLOC( pvReturn, xWantedSize );
|
||||
// }
|
||||
// // ( void ) xTaskResumeAll();
|
||||
|
||||
// // #if( configUSE_MALLOC_FAILED_HOOK == 1 )
|
||||
// // {
|
||||
// // if( pvReturn == NULL )
|
||||
// // {
|
||||
// // extern void vApplicationMallocFailedHook( void );
|
||||
// // vApplicationMallocFailedHook();
|
||||
// // }
|
||||
// // }
|
||||
// // #endif
|
||||
|
||||
// return pvReturn;
|
||||
// }
|
||||
// /*-----------------------------------------------------------*/
|
||||
|
||||
// void vPortFree( void *pv )
|
||||
// {
|
||||
// uint8_t *puc = ( uint8_t * ) pv;
|
||||
// BlockLink_t *pxLink;
|
||||
|
||||
// if( pv != NULL )
|
||||
// {
|
||||
// /* The memory being freed will have an BlockLink_t structure immediately
|
||||
// before it. */
|
||||
// puc -= heapSTRUCT_SIZE;
|
||||
|
||||
// /* This unexpected casting is to keep some compilers from issuing
|
||||
// byte alignment warnings. */
|
||||
// pxLink = ( void * ) puc;
|
||||
|
||||
// // vTaskSuspendAll();
|
||||
// {
|
||||
// /* Add this block to the list of free blocks. */
|
||||
// prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) );
|
||||
// xFreeBytesRemaining += pxLink->xBlockSize;
|
||||
// // traceFREE( pv, pxLink->xBlockSize );
|
||||
// }
|
||||
// // ( void ) xTaskResumeAll();
|
||||
// }
|
||||
// }
|
||||
// /*-----------------------------------------------------------*/
|
||||
|
||||
// size_t xPortGetFreeHeapSize( void )
|
||||
// {
|
||||
// return xFreeBytesRemaining;
|
||||
// }
|
||||
// /*-----------------------------------------------------------*/
|
||||
|
||||
// void vPortInitialiseBlocks( void )
|
||||
// {
|
||||
// /* This just exists to keep the linker quiet. */
|
||||
// }
|
||||
// /*-----------------------------------------------------------*/
|
||||
|
||||
// static void prvHeapInit( void )
|
||||
// {
|
||||
// BlockLink_t *pxFirstFreeBlock;
|
||||
// uint8_t *pucAlignedHeap;
|
||||
|
||||
// /* Ensure the heap starts on a correctly aligned boundary. */
|
||||
// pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ portBYTE_ALIGNMENT ] ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
|
||||
|
||||
// /* xStart is used to hold a pointer to the first item in the list of free
|
||||
// blocks. The void cast is used to prevent compiler warnings. */
|
||||
// xStart.pxNextFreeBlock = ( void * ) pucAlignedHeap;
|
||||
// xStart.xBlockSize = ( size_t ) 0;
|
||||
|
||||
// /* xEnd is used to mark the end of the list of free blocks. */
|
||||
// xEnd.xBlockSize = configADJUSTED_HEAP_SIZE;
|
||||
// xEnd.pxNextFreeBlock = NULL;
|
||||
|
||||
// /* To start with there is a single free block that is sized to take up the
|
||||
// entire heap space. */
|
||||
// pxFirstFreeBlock = ( void * ) pucAlignedHeap;
|
||||
// pxFirstFreeBlock->xBlockSize = configADJUSTED_HEAP_SIZE;
|
||||
// pxFirstFreeBlock->pxNextFreeBlock = &xEnd;
|
||||
// }
|
||||
// /*-----------------------------------------------------------*/
|
||||
|
||||
// // #endif /* #ifdef configHEAP_ALLOCATION_SCHEME */
|
||||
// // #endif /* #if(configHEAP_ALLOCATION_SCHEME == HEAP_ALLOCATION_TYPE1) */
|
||||
|
||||
// // char testOne() {
|
||||
// // void * alloc1 = pvPortMalloc(100);
|
||||
// // void * alloc2 = pvPortMalloc(200);
|
||||
// // void * alloc3 = pvPortMalloc(300);
|
||||
|
||||
// // memset(alloc1, 1, 100);
|
||||
// // memset(alloc2, 2, 200);
|
||||
// // memset(alloc3, 3, 300);
|
||||
|
||||
// // for (int i = 0; i < 600; i++) {
|
||||
// // if (i < 100) {
|
||||
// // assert(*((char *) alloc1+i) == 1);
|
||||
// // } else if (i < 300) {
|
||||
// // assert(*((char *) alloc2+i-100) == 2);
|
||||
// // } else if (i < 600) {
|
||||
// // assert(*((char *) alloc3+i-300) == 3);
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // return EXIT_SUCCESS;
|
||||
// // }
|
||||
|
||||
// // static unsigned long int next = 1;
|
||||
// // int rand(void) // RAND_MAX assumed to be 32767
|
||||
// // {
|
||||
// // next = next * 1103515245 + 12345;
|
||||
// // return (unsigned int)(next/65536) % 32768;
|
||||
// // }
|
||||
|
||||
// /*
|
||||
// char testTwo() {
|
||||
// void * ptr;
|
||||
// while (ptr != NULL){
|
||||
// ptr = memMalloc((rand() % 2000) + 1);
|
||||
// if (!((char *) memoryManager->nextAddress >= memoryManager->initialAddress)) {
|
||||
// printStringLen(13, "allocRand1 -- ERROR", 31);
|
||||
// new_line();
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// if (!((char *) memoryManager->nextAddress <= memoryManager->initialAddress + MANAGED_MEMORY_SIZE)) {
|
||||
// printStringLen(13, "allocRand2 -- ERROR", 31);
|
||||
// new_line();
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// // if (!((char *) memoryManager->lastAddress >= memoryManager->initialAddress)) {
|
||||
// // }
|
||||
// // if (!((char *) memoryManager->lastAddress <= memoryManager->initialAddress + MANAGED_MEMORY_SIZE)) {
|
||||
// // }
|
||||
// }
|
||||
|
||||
// return EXIT_SUCCESS;
|
||||
|
||||
// }
|
||||
// */
|
||||
|
||||
// // char mem[1024];
|
||||
|
||||
// // int main() {
|
||||
// // // initMemoryManager(mem);
|
||||
// // if (testOne() == EXIT_FAILURE)
|
||||
// // return EXIT_FAILURE;
|
||||
// // // if (testTwo() == EXIT_FAILURE)
|
||||
// // // return EXIT_FAILURE;
|
||||
// // }
|
||||
|
||||
// #endif
|
|
@ -1,183 +0,0 @@
|
|||
// #ifndef BUDDY
|
||||
|
||||
// #include <stdio.h>
|
||||
// #include <stdlib.h>
|
||||
// #include <unistd.h>
|
||||
// #include <assert.h>
|
||||
// #include <string.h>
|
||||
|
||||
// typedef long Align; /* for alignment to long boundary */
|
||||
// union header
|
||||
// { /* block header */
|
||||
// struct
|
||||
// {
|
||||
// union header *ptr; /* next block if on free list */
|
||||
// unsigned size; /* size of this block */
|
||||
// } s;
|
||||
// Align x; /* force alignment of blocks */
|
||||
// };
|
||||
// typedef union header Header;
|
||||
|
||||
// // static Header base; /* empty list to get started */
|
||||
// static Header *base; /* empty list to get started */
|
||||
// static Header *freep = NULL; /* start of free list */
|
||||
|
||||
// #define MAX 1024
|
||||
// void initMemoryManager(void * managedMemory) {
|
||||
// // freep = (Header *) managedMemory;
|
||||
// // freep->s.ptr = NULL;
|
||||
// // freep->s.size = ;
|
||||
|
||||
// base = (Header *) managedMemory;
|
||||
// freep = base;
|
||||
// freep->s.ptr = NULL;
|
||||
// freep->s.size = 1024/sizeof(Header);
|
||||
// }
|
||||
|
||||
// /* memMalloc: general-purpose storage allocator */
|
||||
// void *
|
||||
// memMalloc(unsigned nbytes)
|
||||
// {
|
||||
// Header *p, *prevp;
|
||||
// // Header *moreroce(unsigned);
|
||||
// unsigned nunits;
|
||||
// // nunits = (nbytes + sizeof(Header) - 1) / sizeof(header) + 1;
|
||||
// nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1;
|
||||
// // if ((prevp = freep) == NULL)
|
||||
// // { /* no free list yet */
|
||||
// // // base.s.ptr = freeptr = prevptr = &base;
|
||||
// // // base.s.ptr = &base;
|
||||
// // // base.s.size = 0;
|
||||
// // base->s.ptr = base;
|
||||
// // base->s.size = 0;
|
||||
// // }
|
||||
// for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr)
|
||||
// {
|
||||
// if (p->s.size >= nunits)
|
||||
// { /* big enough */
|
||||
// if (p->s.size == nunits) /* exactly */
|
||||
// prevp->s.ptr = p->s.ptr;
|
||||
// else
|
||||
// { /* allocate tail end */
|
||||
// p->s.size -= nunits;
|
||||
// p += p->s.size;
|
||||
// p->s.size = nunits;
|
||||
// }
|
||||
// freep = prevp;
|
||||
// return (void *)(p + 1);
|
||||
// }
|
||||
// // if (p == freep) /* wrapped around free list */
|
||||
// // if ((p = morecore(nunits)) == NULL)
|
||||
// // return NULL; /* none left */
|
||||
// }
|
||||
// }
|
||||
|
||||
// // #define NALLOC 1024 /* minimum #units to request */
|
||||
|
||||
// // /* morecore: ask system for more memory */
|
||||
// // static Header *morecore(unsigned nu)
|
||||
// // {
|
||||
// // char *cp, *sbrk(int);
|
||||
// // Header *up;
|
||||
// // if (nu < NALLOC)
|
||||
// // nu = NALLOC;
|
||||
// // cp = sbrk(nu * sizeof(Header));
|
||||
// // if (cp == (char *)-1) /* no space at all */
|
||||
// // return NULL;
|
||||
// // up = (Header *)cp;
|
||||
// // up->s.size = nu;
|
||||
// // free((void *)(up + 1));
|
||||
// // return freep;
|
||||
// // }
|
||||
|
||||
// /* free: put block ap in free list */
|
||||
// void memFree(void *ap)
|
||||
// {
|
||||
// Header *bp, *p;
|
||||
// bp = (Header *)ap - 1; /* point to block header */
|
||||
// for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
|
||||
// if (p >= p->s.ptr && (bp > p || bp < p->s.ptr))
|
||||
// break; /* freed block at start or end of arena */
|
||||
// if (bp + bp->s.size == p->s.ptr)
|
||||
// { /* join to upper nbr */
|
||||
// bp->s.size += p->s.ptr->s.size;
|
||||
// bp->s.ptr = p->s.ptr->s.ptr;
|
||||
// }
|
||||
// else
|
||||
// bp->s.ptr = p->s.ptr;
|
||||
// if (p + p->s.size == bp)
|
||||
// { /* join to lower nbr */
|
||||
// p->s.size += bp->s.size;
|
||||
// p->s.ptr = bp->s.ptr;
|
||||
// }
|
||||
// else
|
||||
// p->s.ptr = bp;
|
||||
// freep = p;
|
||||
// }
|
||||
|
||||
// // char testOne() {
|
||||
// // void * alloc1 = memMalloc(100);
|
||||
// // void * alloc2 = memMalloc(200);
|
||||
// // void * alloc3 = memMalloc(300);
|
||||
|
||||
// // memset(alloc1, 1, 100);
|
||||
// // memset(alloc2, 2, 200);
|
||||
// // memset(alloc3, 3, 300);
|
||||
|
||||
// // for (int i = 0; i < 600; i++) {
|
||||
// // if (i < 100) {
|
||||
// // assert(*((char *) alloc1+i) == 1);
|
||||
// // } else if (i < 300) {
|
||||
// // assert(*((char *) alloc1+i) == 2);
|
||||
// // } else if (i < 600) {
|
||||
// // assert(*((char *) alloc1+i) == 3);
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // return EXIT_SUCCESS;
|
||||
// // }
|
||||
|
||||
// // static unsigned long int next = 1;
|
||||
// // int rand(void) // RAND_MAX assumed to be 32767
|
||||
// // {
|
||||
// // next = next * 1103515245 + 12345;
|
||||
// // return (unsigned int)(next/65536) % 32768;
|
||||
// // }
|
||||
|
||||
// // /*
|
||||
// // char testTwo() {
|
||||
// // void * ptr;
|
||||
// // while (ptr != NULL){
|
||||
// // ptr = memMalloc((rand() % 2000) + 1);
|
||||
// // if (!((char *) memoryManager->nextAddress >= memoryManager->initialAddress)) {
|
||||
// // printStringLen(13, "allocRand1 -- ERROR", 31);
|
||||
// // new_line();
|
||||
// // return EXIT_FAILURE;
|
||||
// // }
|
||||
// // if (!((char *) memoryManager->nextAddress <= memoryManager->initialAddress + MANAGED_MEMORY_SIZE)) {
|
||||
// // printStringLen(13, "allocRand2 -- ERROR", 31);
|
||||
// // new_line();
|
||||
// // return EXIT_FAILURE;
|
||||
// // }
|
||||
// // // if (!((char *) memoryManager->lastAddress >= memoryManager->initialAddress)) {
|
||||
// // // }
|
||||
// // // if (!((char *) memoryManager->lastAddress <= memoryManager->initialAddress + MANAGED_MEMORY_SIZE)) {
|
||||
// // // }
|
||||
// // }
|
||||
|
||||
// // return EXIT_SUCCESS;
|
||||
|
||||
// // }
|
||||
// // */
|
||||
|
||||
// // char mem[1024];
|
||||
|
||||
// // int main() {
|
||||
// // initMemoryManager(mem);
|
||||
// // if (testOne() == EXIT_FAILURE)
|
||||
// // return EXIT_FAILURE;
|
||||
// // // if (testTwo() == EXIT_FAILURE)
|
||||
// // // return EXIT_FAILURE;
|
||||
// // }
|
||||
|
||||
// #endif
|
|
@ -1,176 +0,0 @@
|
|||
// #ifndef BUDDY
|
||||
|
||||
// #include "memManager.h"
|
||||
// // #include <stdio.h>
|
||||
// #include <string.h>
|
||||
// #include <assert.h>
|
||||
// #include "video.h"
|
||||
|
||||
// #define MANAGED_MEMORY_SIZE 1024 * 1024 * 64
|
||||
|
||||
// // char mem[MANAGED_MEMORY_SIZE];
|
||||
// // char mem2[MANAGED_MEMORY_SIZE];
|
||||
|
||||
// typedef struct MemoryManagerCDT {
|
||||
// char *nextAddress;
|
||||
// // char *lastAddress;
|
||||
// char *initialAddress;
|
||||
// } MemoryManagerCDT;
|
||||
|
||||
// MemoryManagerADT createMemoryManager(void *const restrict memoryForMemoryManager, void *const restrict managedMemory) {
|
||||
// MemoryManagerADT memoryManager = (MemoryManagerADT) memoryForMemoryManager;
|
||||
// memoryManager->nextAddress = managedMemory;
|
||||
// // char * aux = managedMemory;
|
||||
// // memoryManager->lastAddress = aux - 1;
|
||||
// memoryManager->initialAddress = managedMemory;
|
||||
|
||||
// return memoryManager;
|
||||
// }
|
||||
|
||||
// void *allocMemory(MemoryManagerADT const restrict memoryManager, const size_t memoryToAllocate) {
|
||||
// char *allocation = memoryManager->nextAddress;
|
||||
// if (memoryToAllocate + memoryManager->nextAddress > memoryManager->initialAddress + MANAGED_MEMORY_SIZE){
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
// memoryManager->nextAddress += memoryToAllocate;
|
||||
// // if (!(memoryManager->nextAddress -1 == (memoryManager->lastAddress += memoryToAllocate)))
|
||||
// // return NULL;
|
||||
|
||||
// return (void *) allocation;
|
||||
// }
|
||||
|
||||
// // Esto es mejor para independizarnos del puntero a memoryManager! Y poder llamar desde distintos lugares (sin la referencia del memManager) a malloc...
|
||||
|
||||
// static MemoryManagerADT memoryManager;
|
||||
// char initMemoryManager(void *const restrict memoryForMemoryManager, void *const restrict managedMemory) {
|
||||
// return ((memoryManager = createMemoryManager(memoryForMemoryManager, managedMemory)) == NULL) ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
// }
|
||||
|
||||
// void * memMalloc(const size_t memoryToAllocate) {
|
||||
// return allocMemory(memoryManager, memoryToAllocate);
|
||||
// }
|
||||
|
||||
|
||||
// // SACAR DESPUÉS! ES SOLO PARA TESTEO...
|
||||
|
||||
// char testOne() {
|
||||
// void * alloc1 = memMalloc(100);
|
||||
// void * alloc2 = memMalloc(200);
|
||||
// void * alloc3 = memMalloc(300);
|
||||
|
||||
// memset(alloc1, 1, 100);
|
||||
// memset(alloc2, 2, 200);
|
||||
// memset(alloc3, 3, 300);
|
||||
|
||||
// for (int i = 0; i < 600; i++) {
|
||||
// if (i < 100) {
|
||||
// if (!(*((char *) alloc1+i) == 1)) {
|
||||
// printStringLen(13, "alloc1 -- ERROR", 31);
|
||||
// // printStringLen(13, *((char *) alloc1+i), 1);
|
||||
// new_line();
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// } else if (i < 300) {
|
||||
// if (!(*((char *) alloc1+i) == 2)) {
|
||||
// printStringLen(13, "alloc2 -- ERROR", 31);
|
||||
// new_line();
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// } else if (i < 600) {
|
||||
// if (!(*((char *) alloc1+i) == 3)) {
|
||||
// printStringLen(13, "alloc3 -- ERROR", 31);
|
||||
// new_line();
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// return EXIT_SUCCESS;
|
||||
// }
|
||||
|
||||
// static unsigned long int next = 1;
|
||||
// int rand(void) // RAND_MAX assumed to be 32767
|
||||
// {
|
||||
// next = next * 1103515245 + 12345;
|
||||
// return (unsigned int)(next/65536) % 32768;
|
||||
// }
|
||||
|
||||
// char testTwo() {
|
||||
// void * ptr;
|
||||
// while (ptr != NULL){
|
||||
// ptr = memMalloc((rand() % 2000) + 1);
|
||||
// if (!((char *) memoryManager->nextAddress >= memoryManager->initialAddress)) {
|
||||
// printStringLen(13, "allocRand1 -- ERROR", 31);
|
||||
// new_line();
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// if (!((char *) memoryManager->nextAddress <= memoryManager->initialAddress + MANAGED_MEMORY_SIZE)) {
|
||||
// printStringLen(13, "allocRand2 -- ERROR", 31);
|
||||
// new_line();
|
||||
// return EXIT_FAILURE;
|
||||
// }
|
||||
// // if (!((char *) memoryManager->lastAddress >= memoryManager->initialAddress)) {
|
||||
// // }
|
||||
// // if (!((char *) memoryManager->lastAddress <= memoryManager->initialAddress + MANAGED_MEMORY_SIZE)) {
|
||||
// // }
|
||||
// }
|
||||
|
||||
// return EXIT_SUCCESS;
|
||||
|
||||
// }
|
||||
|
||||
// /*
|
||||
// int main() {
|
||||
// static MemoryManagerADT memoryManager;
|
||||
// static MemoryManagerADT memoryManager2;
|
||||
|
||||
// void * memoryForMemoryManager = (void *) 0x700000;
|
||||
// // void * memoryForMemoryManager = malloc(sizeof(void *));
|
||||
// if (memoryForMemoryManager == NULL) {
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
// void *managedMemory = (void *) 0x700016;// malloc(MANAGED_MEMORY_SIZE);
|
||||
// if (managedMemory == NULL) {
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
|
||||
// void * memoryForMemoryManager2 = (void *) 0x700008;
|
||||
// // void * memoryForMemoryManager2 = malloc(sizeof(void *));
|
||||
// memoryManager = createMemoryManager(memoryForMemoryManager, managedMemory);
|
||||
|
||||
// void * alloc1 = allocMemory(memoryManager, 100);
|
||||
// void * alloc2 = allocMemory(memoryManager, 200);
|
||||
// void * alloc3 = allocMemory(memoryManager, 300);
|
||||
|
||||
// memset(alloc1, 1, 100);
|
||||
// memset(alloc2, 2, 200);
|
||||
// memset(alloc3, 3, 300);
|
||||
|
||||
// for (int i = 0; i < 600; i++) {
|
||||
// if (i < 100) {
|
||||
// assert(*((char *) alloc1+i) == 1);
|
||||
// } else if (i < 300) {
|
||||
// assert(*((char *) alloc1+i) == 2);
|
||||
// } else if (i < 600) {
|
||||
// assert(*((char *) alloc1+i) == 3);
|
||||
// }
|
||||
// }
|
||||
|
||||
// managedMemory = (void *) (0x700016 + 600);
|
||||
// memoryManager2 = createMemoryManager(memoryForMemoryManager2, managedMemory);
|
||||
|
||||
// void * ptr;
|
||||
// while (ptr != NULL){
|
||||
// ptr = allocMemory(memoryManager2, (rand() % 2000) + 1);
|
||||
// assert ((char *) memoryManager2->nextAddress >= mem2);
|
||||
// assert ((char *) memoryManager2->nextAddress <= mem2 + MANAGED_MEMORY_SIZE);
|
||||
// assert ((char *) memoryManager2->lastAddress >= mem2);
|
||||
// assert ((char *) memoryManager2->lastAddress <= mem2 + MANAGED_MEMORY_SIZE);
|
||||
// }
|
||||
// }
|
||||
// */
|
||||
|
||||
// #endif
|
|
@ -13,6 +13,9 @@ char openPipe(int fds[2], char * name) {
|
|||
if ((pipe->sem = semOpen(SEM_NAME, 1)) == NULL)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if ((pipe->fullSem = semOpen(FULL_SEM_NAME, 0)) == NULL)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
node_t * node = pvPortMalloc(sizeof(node_t));
|
||||
node->pipe = pipe;
|
||||
node->next = firstPipe;
|
||||
|
@ -85,6 +88,8 @@ void writePipe(int fd, char c) {
|
|||
|
||||
semWait(node->pipe->sem);
|
||||
|
||||
semPost(node->pipe->fullSem);
|
||||
|
||||
node->pipe->buffer[node->pipe->currentW++ % PIPE_MAX_SIZE] = c;
|
||||
|
||||
semPost(node->pipe->sem);
|
||||
|
@ -96,6 +101,8 @@ char readPipe(int fd) {
|
|||
|
||||
semWait(node->pipe->sem);
|
||||
|
||||
semPost(node->pipe->fullSem);
|
||||
|
||||
char c = node->pipe->buffer[node->pipe->currentR++ % PIPE_MAX_SIZE];
|
||||
|
||||
semPost(node->pipe->sem);
|
||||
|
@ -115,6 +122,7 @@ void closePipe(int fd) {
|
|||
else firstPipe = del->next;
|
||||
|
||||
semClose(del->pipe->sem);
|
||||
semClose(del->pipe->fullSem);
|
||||
vPortFree(del->pipe->fd);
|
||||
vPortFree(del->pipe->name);
|
||||
vPortFree(del->pipe->buffer);
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
#include "scheduler.h"
|
||||
#define IDLE_PID 1
|
||||
|
||||
// void _initialize_stack_frame(void *, void *, int, char**, void **, void **);
|
||||
// void _initialize_stack_frame(void *, void *, int, char**, void *, void *);
|
||||
uint64_t _initialize_stack_frame(void *, void *, int, char**);
|
||||
|
||||
enum states {READY = 0, DEAD, BLOCKED, BBCHILDREN, WAITING};
|
||||
enum states {READY = 0, DEAD, BLOCKED, BBCHILDREN, WAITING, BLOCKEDIO};
|
||||
|
||||
typedef struct processCDT {
|
||||
struct processCDT * next;
|
||||
|
@ -41,19 +39,6 @@ static int pids = IDLE_PID;
|
|||
static char update = 1;
|
||||
static char idleFlag = 2;
|
||||
|
||||
// void removeProcessIzElOrishinal(processCDT * del, processCDT * prev, processCDT ** first, processCDT ** last) {
|
||||
// if (prev == NULL) {
|
||||
// *first = del->next;
|
||||
// if (*last == del)
|
||||
// *last = NULL;
|
||||
// }
|
||||
// else {
|
||||
// prev->next = del->next;
|
||||
// if (*last == del)
|
||||
// *last = prev;
|
||||
// }
|
||||
// }
|
||||
|
||||
void removeProcess(processCDT * del, processCDT ** first, processCDT ** last) {
|
||||
processCDT * prev = NULL;
|
||||
del = searchProcess(&prev, del->pid, *first);
|
||||
|
@ -70,24 +55,15 @@ void removeProcess(processCDT * del, processCDT ** first, processCDT ** last) {
|
|||
}
|
||||
}
|
||||
|
||||
void debug1() {
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t nextProcess(uint64_t currentRSP) {
|
||||
if (currentProcess != NULL /*&& currentProcess->state != BLOCKED*/)
|
||||
if (currentProcess != NULL)
|
||||
currentProcess->rsp = currentRSP;
|
||||
processCDT * prev = currentProcess;
|
||||
// if (currentProcess != NULL)
|
||||
// currentProcess = currentProcess->next;
|
||||
if (currentProcess != NULL && currentProcess->state == READY && currentProcess->executions == MAX_PRIORITY - currentProcess->priority + 1) {
|
||||
currentProcess->executions = 0;
|
||||
currentProcess = currentProcess->next;
|
||||
// firstBlockedIteration = NULL;
|
||||
// currentProcess->executions++;
|
||||
// return currentProcess->rsp;
|
||||
}
|
||||
while (currentProcess == NULL || currentProcess->state == BLOCKED || currentProcess->state == DEAD || currentProcess->state == WAITING) {
|
||||
while (currentProcess == NULL || currentProcess->state == BLOCKED || currentProcess->state == DEAD || currentProcess->state == WAITING || currentProcess->state == BLOCKEDIO) {
|
||||
if (currentProcess == NULL) {
|
||||
currentProcess = firstProcess;
|
||||
}
|
||||
|
@ -98,29 +74,22 @@ uint64_t nextProcess(uint64_t currentRSP) {
|
|||
currentProcess = currentProcess->next;
|
||||
}
|
||||
else if (currentProcess->state == DEAD) {
|
||||
debug1();
|
||||
processCDT * del = currentProcess;
|
||||
currentProcess = currentProcess->next;
|
||||
removeProcess(del, &firstProcess, &lastProcess);
|
||||
vPortFree((void *) del);
|
||||
}
|
||||
else if (currentProcess->state == BLOCKED || currentProcess->state == WAITING) {
|
||||
else if (currentProcess->state == BLOCKED || currentProcess->state == WAITING || currentProcess->state == BLOCKEDIO) {
|
||||
if (firstBlockedIteration == NULL)
|
||||
firstBlockedIteration = currentProcess;
|
||||
prev = currentProcess;
|
||||
currentProcess = currentProcess->next;
|
||||
}
|
||||
// else if (currentProcess != NULL && currentProcess->state == READY && currentProcess->executions == MAX_PRIORITY - currentProcess->priority + 1) {
|
||||
// currentProcess->executions = 0;
|
||||
// currentProcess = currentProcess->next;
|
||||
// }
|
||||
}
|
||||
if (currentProcess->pid != IDLE_PID && idleFlag) {
|
||||
idleFlag = 0;
|
||||
block(IDLE_PID);
|
||||
}
|
||||
// if (currentProcess->pid >= 5)
|
||||
// debug1();
|
||||
firstBlockedIteration = NULL;
|
||||
currentProcess->executions++;
|
||||
return currentProcess->rsp;
|
||||
|
@ -159,7 +128,7 @@ int enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *a
|
|||
processADT process = pvPortMalloc(sizeof(processCDT));
|
||||
uint64_t * auxi = pvPortMalloc(STACK_SIZE);
|
||||
uint64_t * rbp = STACK_SIZE + auxi;
|
||||
uint64_t * rsp = rbp - 20; // 20 //22
|
||||
uint64_t * rsp = rbp - 20;
|
||||
|
||||
char priority = (foreground == 1) ? DEF_PRIORITY : MAX_PRIORITY/2;
|
||||
|
||||
|
@ -185,7 +154,6 @@ int enqueueProcess(void (*fn) (int, char **), char foreground, int argc, char *a
|
|||
process->backWait = 0;
|
||||
|
||||
process->rsp = _initialize_stack_frame(fn, rbp, argc, argv);
|
||||
// _initialize_stack_frame(fn, rbp, argc, argv);
|
||||
|
||||
if (firstProcess == NULL)
|
||||
firstProcess = process;
|
||||
|
@ -252,6 +220,36 @@ processADT searchProcess(processADT * previous, int pid, processADT first) {
|
|||
return curr;
|
||||
}
|
||||
|
||||
void unblockIO() {
|
||||
processCDT * aux = firstProcess;
|
||||
while(aux != NULL) {
|
||||
if (aux->state == BLOCKEDIO)
|
||||
aux->state = READY;
|
||||
|
||||
aux = aux->next;
|
||||
}
|
||||
}
|
||||
|
||||
char blockIO() {
|
||||
if (currentProcess == NULL || currentProcess->state == DEAD)
|
||||
return EXIT_FAILURE;
|
||||
else {
|
||||
currentProcess->state = BLOCKEDIO;
|
||||
}
|
||||
|
||||
processCDT * prev = NULL;
|
||||
processADT parent = searchProcess(&prev, currentProcess->ppid, firstProcess);
|
||||
if (currentProcess->foreground) {
|
||||
if (parent->backWait) {
|
||||
parent->backWait = 0;
|
||||
parent->foreground = 1;
|
||||
}
|
||||
}
|
||||
forceTimer();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
char block(int pid) {
|
||||
processADT prev = NULL;
|
||||
processADT del = searchProcess(&prev, pid, firstProcess);
|
||||
|
@ -262,12 +260,12 @@ char block(int pid) {
|
|||
}
|
||||
|
||||
processADT parent = searchProcess(&prev, del->ppid, firstProcess);
|
||||
if (del->foreground)
|
||||
if (del->foreground) {
|
||||
if (parent->backWait) {
|
||||
parent->backWait = 0;
|
||||
parent->foreground = 1;
|
||||
}
|
||||
|
||||
}
|
||||
if (pid == currentProcess->pid) {
|
||||
forceTimer();
|
||||
}
|
||||
|
@ -286,14 +284,12 @@ char unblock(int pid) {
|
|||
}
|
||||
|
||||
processADT parent = searchProcess(&prev, del->ppid, firstProcess);
|
||||
if (del->foreground)
|
||||
if (del->foreground) {
|
||||
if (parent->foreground) {
|
||||
parent->backWait = 1;
|
||||
parent->foreground = 0;
|
||||
}
|
||||
// if (idleFlag && !(--idleFlag))
|
||||
// block(IDLE_PID);
|
||||
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -443,7 +439,6 @@ char * processes(){
|
|||
|
||||
char * info = "name pid prio rsp rbp fore state\n";
|
||||
ans += strcpy(ans, info);
|
||||
// ans += 56;
|
||||
|
||||
processCDT * aux = firstProcess;
|
||||
while (aux != NULL) {
|
||||
|
|
|
@ -7,7 +7,6 @@ typedef struct node_t {
|
|||
struct node_t * next;
|
||||
} node_t;
|
||||
|
||||
// static sem_t semaphores[MAX_SEM];
|
||||
node_t * firstSem = NULL;
|
||||
static char counter = 0;
|
||||
|
||||
|
@ -164,12 +163,11 @@ char * getEntering(sem_t * sem){
|
|||
char * ans = pvPortMalloc(sizeof(pid_t *));
|
||||
pid_t * aux = sem->entering;
|
||||
char buffer[MAX_PID];
|
||||
while(aux != NULL){
|
||||
|
||||
while (aux != NULL) {
|
||||
strcpy(ans, itoa(aux->pid, buffer, 10, 3));
|
||||
aux = aux->next;
|
||||
if (aux != NULL)
|
||||
strcpy(ans, ' ');
|
||||
strcpy(ans, " ");
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
int sys_loadProcess(void (*fn) (int, char **), char foreground, int argc, char *argv[], int * fd);
|
||||
void sys_exit();
|
||||
// void sys_switchContext();
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
winClear();
|
||||
|
@ -14,14 +13,10 @@ int main(int argc, char *argv[]) {
|
|||
char * argv1[] = {"bottler"};
|
||||
sys_loadProcess(bottler, 1, 1, argv1, NULL);
|
||||
sys_wait();
|
||||
// sys_sleep(3);
|
||||
// winClear();
|
||||
|
||||
char * argv2[] = {"shell"};
|
||||
sys_loadProcess(shell, 1, 1, argv2, NULL);
|
||||
// sys_loadProcess(shell);
|
||||
|
||||
// sys_switchContext();
|
||||
sys_exit();
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#define SIZE 1000
|
||||
|
||||
/*
|
||||
void cat(int argc, char ** argv) {
|
||||
char c;
|
||||
int i = 0;
|
||||
|
@ -12,6 +13,28 @@ void cat(int argc, char ** argv) {
|
|||
buffer[i++] = c;
|
||||
}
|
||||
|
||||
printStringLen(buffer, i);
|
||||
sys_exit();
|
||||
}
|
||||
*/
|
||||
|
||||
void cat(int argc, char ** argv) {
|
||||
char c;
|
||||
int i = 0, j = 0, line = 0;
|
||||
char buffer[SIZE] = {0};
|
||||
|
||||
while ((c = getChar()) <= 0) {
|
||||
if (i >= SIZE)
|
||||
break;
|
||||
if (c == '\n') {
|
||||
printStringLen(buffer[line], j);
|
||||
j = 0;
|
||||
line = i;
|
||||
}
|
||||
buffer[i++] = c;
|
||||
j++;
|
||||
}
|
||||
|
||||
printStringLen(buffer, i);
|
||||
sys_exit();
|
||||
}
|
|
@ -2,7 +2,49 @@
|
|||
#define SHELL
|
||||
|
||||
#include "system.h"
|
||||
#include "libc.h"
|
||||
#include "help.h"
|
||||
#include "time.h"
|
||||
#include "shell.h"
|
||||
#include "clear.h"
|
||||
#include "inforeg.h"
|
||||
#include "printmem.h"
|
||||
#include "excDiv.h"
|
||||
#include "excOP.h"
|
||||
#include "quadratic.h"
|
||||
#include "cpu_id.h"
|
||||
#include "ps.h"
|
||||
#include "pipes.h"
|
||||
#include "wc.h"
|
||||
#include "filter.h"
|
||||
#include "cat.h"
|
||||
#include "semCom.h"
|
||||
#include "stddef.h"
|
||||
#include "nice.h"
|
||||
#include "phylo.h"
|
||||
#include "kill.h"
|
||||
#include "block.h"
|
||||
#include "unblock.h"
|
||||
#include "loop.h"
|
||||
|
||||
#define EXIT_FAILURE 1
|
||||
#define EXIT_SUCCESS 0
|
||||
|
||||
#define SIZE 100
|
||||
#define MAX_ARGS 11
|
||||
|
||||
#define COLS 80
|
||||
#define ROWS 25
|
||||
|
||||
typedef struct cmd_t {
|
||||
char * name;
|
||||
void (*func) (int argc, char * argv[]);
|
||||
char isBuiltIn;
|
||||
char isForeground;
|
||||
} cmd_t;
|
||||
|
||||
int scanfNoPrint(char * buffer);
|
||||
void processInput(char * input);
|
||||
void shell(int argc, char *argv[]);
|
||||
void incorrect_comm(char * buffer);
|
||||
void incorrect_arg(char * command);
|
||||
|
|
|
@ -1,158 +0,0 @@
|
|||
/*
|
||||
#include "libc.h"
|
||||
#include "help.h"
|
||||
#include "clear.h"
|
||||
#include "time.h"
|
||||
#include "shell.h"
|
||||
#include "inforeg.h"
|
||||
#include "printmem.h"
|
||||
#include "excDiv.h"
|
||||
#include "excOP.h"
|
||||
#include "quadratic.h"
|
||||
#include "cpu_id.h"
|
||||
#include "change.h"
|
||||
#include "ps.h"
|
||||
#include "semCom.h"
|
||||
|
||||
#define SIZE 100
|
||||
#define MAX_ARGS 5
|
||||
|
||||
#define COLS 80
|
||||
#define ROWS 25
|
||||
|
||||
const int len = 9;
|
||||
char *commands_void[] = {"help", "time", "inforeg", "excdiv", "excop", "clear", "cpufeatures", "ps", "sem"};
|
||||
void (*func []) (char *, int *) = {help, time, inforeg, excdiv, excop, clear, cpufeatures, ps, semCom};
|
||||
|
||||
void substractLine(char * window, int * offset) {
|
||||
for (int i = 0; i < ROWS - 1; i++) {
|
||||
for (int j = 0; j < COLS; j++) {
|
||||
window[i * COLS + j] = window[(i + 1) * COLS + j];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < COLS; i++) {
|
||||
window[(ROWS - 1) * COLS + i - 1] = ' ';
|
||||
window[ROWS * COLS] = 0;
|
||||
}
|
||||
*offset = (ROWS - 1) * COLS;
|
||||
}
|
||||
|
||||
void addText(char * buffer, char * window, int * offset) {
|
||||
while (*buffer != 0) {
|
||||
if (*offset == ROWS * COLS - 1) substractLine(window, offset);
|
||||
if (*buffer == '\n') {
|
||||
buffer++;
|
||||
substractLine(window, offset);
|
||||
}
|
||||
window[(*offset)++] = *buffer++;
|
||||
}
|
||||
}
|
||||
|
||||
void printWindow(char * window) {
|
||||
printStringLen(window, ROWS * COLS);
|
||||
}
|
||||
|
||||
void scanfNoPrint(char * buffer, int maxSize, char * window, int * offset) {
|
||||
char c;
|
||||
int i = 0;
|
||||
while ((c = getChar()) != '\n' && i < maxSize - 1) {
|
||||
if (c != -1) {
|
||||
// if (c == '\v')
|
||||
// sys_switchContext();
|
||||
// else if (c == '\b' && i > 0) {
|
||||
if (c == '\b' && i > 0) {
|
||||
buffer[--i] = ' ';
|
||||
window[--(*offset)] = ' ';
|
||||
printWindow(window);
|
||||
}
|
||||
else if (c != 0 && c != '\b') {
|
||||
buffer[i++] = c;
|
||||
if (*offset == ROWS * COLS - 1) substractLine(window, offset);
|
||||
window[(*offset)++] = c;
|
||||
printWindow(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer[i] = '\0';
|
||||
if (*offset == ROWS * COLS - 1) substractLine(window, offset);
|
||||
window[*offset] = ' ';
|
||||
}
|
||||
|
||||
void clearWindow(char * window, int * offset) {
|
||||
for (int i = 0; i <= ROWS * COLS; i++) {
|
||||
window[i] = ' ';
|
||||
}
|
||||
window[ROWS * COLS] = 0;
|
||||
*offset = (ROWS - 1) * COLS;
|
||||
printWindow(window);
|
||||
}
|
||||
|
||||
// static char window[ROWS * COLS + 1] = {[0 ... ROWS * COLS - 1] = ' ', 0};
|
||||
// static char buffer[SIZE] = {0};
|
||||
// static char *tokens[SIZE] = {0};
|
||||
void shell(int argc, char *argv[]) {
|
||||
char window[ROWS * COLS + 1] = {[0 ... ROWS * COLS - 1] = ' ', 0};
|
||||
int offset = (ROWS - 1) * COLS;
|
||||
|
||||
printWindow(window);
|
||||
while (1) {
|
||||
int comm_flag = 0;
|
||||
addText("$> ", window, &offset);
|
||||
printWindow(window);
|
||||
char buffer[SIZE] = {0};
|
||||
scanfNoPrint(buffer, SIZE, window, &offset);
|
||||
substractLine(window, &offset);
|
||||
char* tokens[SIZE] = {0};
|
||||
tokens[0] = strstrip(buffer, ' ');
|
||||
for (int i = 1; i < MAX_ARGS; i++) {
|
||||
tokens[i] = strtok(tokens[i - 1], ' ');
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (!strcmp(tokens[0], commands_void[i])) {
|
||||
if (*tokens[1] != 0)
|
||||
incorrect_arg(tokens[0], window, &offset);
|
||||
else
|
||||
(*func[i])(window, &offset);
|
||||
comm_flag = 1;
|
||||
}
|
||||
}
|
||||
if (!strcmp(tokens[0], "quadratic")) {
|
||||
if (*tokens[4] != 0 || *tokens[3] == 0)
|
||||
incorrect_arg(tokens[0], window, &offset);
|
||||
else if (!isFloat(tokens[1]) || !isFloat(tokens[2]) || !isFloat(tokens[3]))
|
||||
incorrect_arg(tokens[0], window, &offset);
|
||||
else
|
||||
quadratic(window, &offset, atof(tokens[1]), atof(tokens[2]), atof(tokens[3]));
|
||||
comm_flag = 1;
|
||||
}
|
||||
if (!strcmp(tokens[0], "printmem")) {
|
||||
if (*tokens[2] != 0 || *tokens[1] == 0)
|
||||
incorrect_arg(tokens[0], window, &offset);
|
||||
else {
|
||||
int length = strlen(tokens[1]);
|
||||
printmem(window, &offset, atoi(tokens[1], length));
|
||||
}
|
||||
comm_flag = 1;
|
||||
}
|
||||
|
||||
if (!comm_flag) {
|
||||
if (*tokens[0] != 0)
|
||||
incorrect_comm(tokens[0], window, &offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void incorrect_comm(char * buffer, char* window, int * offset) {
|
||||
addText(buffer, window, offset);
|
||||
addText(" is not a BottlerShell command", window, offset);
|
||||
printWindow(window);
|
||||
substractLine(window, offset);
|
||||
}
|
||||
|
||||
void incorrect_arg(char * command, char* window, int * offset) {
|
||||
addText("Incorrect arguments for command ", window, offset);
|
||||
addText(command, window, offset);
|
||||
printWindow(window);
|
||||
substractLine(window, offset);
|
||||
}
|
||||
*/
|
|
@ -1,42 +1,4 @@
|
|||
#include "libc.h"
|
||||
#include "help.h"
|
||||
#include "time.h"
|
||||
#include "shell.h"
|
||||
#include "clear.h"
|
||||
#include "inforeg.h"
|
||||
#include "printmem.h"
|
||||
#include "excDiv.h"
|
||||
#include "excOP.h"
|
||||
#include "quadratic.h"
|
||||
#include "cpu_id.h"
|
||||
#include "ps.h"
|
||||
#include "pipes.h"
|
||||
#include "wc.h"
|
||||
#include "filter.h"
|
||||
#include "cat.h"
|
||||
#include "semCom.h"
|
||||
#include "stddef.h"
|
||||
#include "nice.h"
|
||||
#include "phylo.h"
|
||||
#include "kill.h"
|
||||
#include "block.h"
|
||||
#include "unblock.h"
|
||||
#include "loop.h"
|
||||
#define EXIT_FAILURE 1
|
||||
#define EXIT_SUCCESS 0
|
||||
|
||||
#define SIZE 100
|
||||
#define MAX_ARGS 11
|
||||
|
||||
#define COLS 80
|
||||
#define ROWS 25
|
||||
|
||||
typedef struct cmd_t {
|
||||
char * name;
|
||||
void (*func) (int argc, char * argv[]);
|
||||
char isBuiltIn;
|
||||
char isForeground;
|
||||
} cmd_t;
|
||||
|
||||
cmd_t commands[] = {
|
||||
{ "help", help, 0, 1},
|
||||
|
@ -103,6 +65,11 @@ void processInput(char * input) {
|
|||
}
|
||||
}
|
||||
|
||||
if (pipe != -1 && ampersand >= 0) {
|
||||
printStringLen("piped processes are not able to run in background\n", 50);
|
||||
return;
|
||||
}
|
||||
|
||||
int * fd, * fd1, * fd2;
|
||||
fd1 = sys_malloc(2 * sizeof(int));
|
||||
fd1[0] = 0;
|
||||
|
@ -162,7 +129,6 @@ void processInput(char * input) {
|
|||
else {
|
||||
if (commands[comm0].isBuiltIn)
|
||||
commands[comm0].func(end, argv0);
|
||||
// sys_loadProcess(commands[comm0].func, 1, end, argv0, fd1);
|
||||
else {
|
||||
if (ampersand >= 0)
|
||||
commands[comm0].isForeground = 0;
|
||||
|
@ -184,21 +150,17 @@ void processInput(char * input) {
|
|||
}
|
||||
}
|
||||
|
||||
// void loader(void (*fn) (int, char **), int argc, char * argv[]) {
|
||||
// fn(argc, argv);
|
||||
// sys_exit();
|
||||
// }
|
||||
|
||||
void shell(int argc, char *argv[]) {
|
||||
printStringLen("$> ", 3);
|
||||
char buffer[SIZE] = {0};
|
||||
|
||||
while (1) {
|
||||
scanfNoPrint(buffer);
|
||||
// while (1) {
|
||||
while (scanfNoPrint(buffer) != 0) {
|
||||
new_line();
|
||||
processInput(buffer);
|
||||
printStringLen("$> ", 3);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
void incorrect_comm(char * buffer) {
|
||||
|
|
Loading…
Reference in New Issue