Add mem dump and update help command (also remove unused variables)

Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar>
Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
Santiago Lo Coco 2021-11-02 20:35:47 -03:00
parent 3c7957ce17
commit 917d377e67
24 changed files with 306 additions and 216 deletions

View File

@ -20,7 +20,6 @@ EXTERN irqDispatcher
EXTERN exceptionDispatcher EXTERN exceptionDispatcher
EXTERN systemCallsDispatcher EXTERN systemCallsDispatcher
EXTERN changeWindow EXTERN changeWindow
EXTERN updateRSP
EXTERN nextProcess EXTERN nextProcess
GLOBAL switchContext GLOBAL switchContext
@ -184,9 +183,6 @@ _irq00Handler:
call checkSleeping call checkSleeping
; mov rdi, rsp
; call updateRSP
mov rdi, 0 mov rdi, 0
call irqDispatcher call irqDispatcher
@ -275,8 +271,6 @@ _initialize_stack_frame:
; System calls (int 80h) ; System calls (int 80h)
_systemCallsHandler: _systemCallsHandler:
pushStateNoRax pushStateNoRax
; fsave [bytesForFPU]
; fxsave [bytesForSSEAligned]
mov [auxRSI], rsi mov [auxRSI], rsi
mov rsi, rsp mov rsi, rsp
@ -291,9 +285,6 @@ _systemCallsHandler:
call systemCallsDispatcher call systemCallsDispatcher
; fxrstor [bytesForSSEAligned]
; frstor [bytesForFPU]
pop rsp pop rsp
mov [auxRAX], rax mov [auxRAX], rax
mov rax, rsp mov rax, rsp

View File

@ -56,6 +56,8 @@ int printStringLen(int color, const char *string, int maxLen) {
} else if (*string == '\b') { } else if (*string == '\b') {
backspace(); backspace();
return i; return i;
} else if (*string == -1) {
return i;
} else if (checkIfEscapeSequence(string)) { } else if (checkIfEscapeSequence(string)) {
return i; return i;
} }

View File

@ -1,8 +1,5 @@
#include "exceptions.h" #include "exceptions.h"
static void * const sampleCodeAddress = (void *) 0x400000;
typedef int (* fn)();
static void zero_division(); static void zero_division();
static void invalid_opcode(); static void invalid_opcode();
@ -54,29 +51,15 @@ void printRegs() {
printStringLen(15, "OLD RSP: ", 10); printStringLen(15, "OLD RSP: ", 10);
printStringLen(15, itoa(*rspValueA, buffer, 16, 20), 20); printStringLen(15, itoa(*rspValueA, buffer, 16, 20), 20);
new_line(); new_line();
*ripValueA = (uint64_t) sampleCodeAddress;
*rspValueA = (uint64_t) getSampleRSP();
} }
void exitProcess();
static void startOver() { static void startOver() {
long initialTime = getTimeOfDay();
while (getTimeOfDay() < initialTime + WAITSECONDS);
clear(); clear();
exitProcess(); exitProcess();
forceTimer();
// TODO : hacer wait con getTimegen
// unsigned char key = 0;
// while (key != '\n') {
// _sti();
// haltcpu();
// key = getKeyFromBuffer();
// }
// clear();
// cleanProcesses();
// moveToWindowVideo(1);
//((fn)sampleCodeAddress)();
} }
static void genericException(char * string, int len) { static void genericException(char * string, int len) {
@ -87,9 +70,9 @@ static void genericException(char * string, int len) {
} }
static void zero_division() { static void zero_division() {
genericException("Exception 0: Zero division. Press enter to reboot", 50); genericException("Exception 0: Zero division. Please wait 5 seconds", 50);
} }
static void invalid_opcode() { static void invalid_opcode() {
genericException("Exception 1: Invalid opcode. Press enter to reboot", 51); genericException("Exception 1: Invalid opcode. Please wait 5 seconds", 51);
} }

View File

@ -4,12 +4,16 @@
#include "lib.h" #include "lib.h"
#include "time.h" #include "time.h"
#include "naiveConsole.h" #include "naiveConsole.h"
#include "pcb.h"
#include "video.h" #include "video.h"
#include "keyboard.h" #include "keyboard.h"
#include "interrupts.h" #include "interrupts.h"
#define ZERO_EXCEPTION_ID 0 #define ZERO_EXCEPTION_ID 0
#define INVALID_OPCODE_ID 6 #define INVALID_OPCODE_ID 6
#define WAITSECONDS 5
void exitProcess();
long getTimeOfDay();
void forceTimer();
#endif #endif

View File

@ -4,7 +4,6 @@
#include "video.h" #include "video.h"
#include "keyboard.h" #include "keyboard.h"
#include "time.h" #include "time.h"
#include "pcb.h"
#include "pipeLib.h" #include "pipeLib.h"
#include "schedulerLib.h" #include "schedulerLib.h"
#include "systemCallsLib.h" #include "systemCallsLib.h"

View File

@ -14,7 +14,7 @@ uint64_t systemCallsDispatcher(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_
exitProcess(); exitProcess();
break; break;
case 5: case 5:
break; return dumpMM();
case 6: case 6:
return (uint64_t) processes(); return (uint64_t) processes();
case 7: case 7:

View File

@ -5,7 +5,6 @@
#include "video.h" #include "video.h"
#include "keyboard.h" #include "keyboard.h"
#include "time.h" #include "time.h"
#include "pcb.h"
#include "memManager.h" #include "memManager.h"
extern uint8_t text; extern uint8_t text;
@ -57,8 +56,6 @@ int main() {
initMemoryManager(memoryModuleAddress); initMemoryManager(memoryModuleAddress);
initScheduler(); initScheduler();
saveSampleRSP(getRSP());
char *argv[] = {"SampleCode"}; char *argv[] = {"SampleCode"};
enqueueProcess(sampleCodeModuleAddress, 1, 1, argv, NULL); enqueueProcess(sampleCodeModuleAddress, 1, 1, argv, NULL);
clear(); clear();

View File

@ -2,13 +2,11 @@
#define MEM_MANAGER_H #define MEM_MANAGER_H
#include <stdlib.h> #include <stdlib.h>
#define DUMP_MAX_SIZE 100
void initMemoryManager(void * managedMemory); void initMemoryManager(void * managedMemory);
void * memMalloc(unsigned nbytes); void *pvPortMalloc(size_t xWantedSize);
void memFree(void *ap);
// void * memMalloc(const size_t memoryToAllocate);
void * pvPortMalloc(size_t xWantedSize);
void vPortFree( void *pv ); void vPortFree( void *pv );
size_t xPortGetFreeHeapSize( void ); char *dumpMM();
#endif #endif

View File

@ -0,0 +1,17 @@
#ifndef MMBUDDY
#define MMBUDDY
#include "memManager.h"
#include <stddef.h>
#include <stdint.h>
#define NODE_UNUSED 0
#define NODE_USED 1
#define NODE_SPLIT 2
#define NODE_FULL 3
#define LEVEL 17
#define SIZE (1<<LEVEL)
#endif

View File

@ -0,0 +1,73 @@
#ifndef MMFRT4_H
#define MMFRT4_H
#include "memManager.h"
#include <stddef.h>
#include <stdint.h>
#include "lib.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
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE 1024 * 1024 * 512
#define configAPPLICATION_ALLOCATED_HEAP 0
#define portBYTE_ALIGNMENT 8
#define portBYTE_ALIGNMENT_MASK ( 0x0007 )
#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 )
#define heapBITS_PER_BYTE ( ( size_t ) 8 )
#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize << 1 ) )
typedef portSTACK_TYPE StackType_t;
typedef long BaseType_t;
typedef unsigned long UBaseType_t;
/* Define the linked list structure. This is used to link free blocks in order
of their memory address. */
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;
/* Definition of the Heap_stats_t structure. */
typedef struct xHeapStats {
size_t xAvailableHeapSpaceInBytes; /* The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated. */
size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */
size_t xMinimumEverFreeBytesRemaining; /* The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted. */
size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */
size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */
} HeapStats_t;
/* Prototype of the vPortGetHeapStats() function. */
void vPortGetHeapStats(HeapStats_t *xHeapStats);
/*
* Inserts a block of memory that is being freed into the correct position in
* the list of free memory blocks. The block being freed will be merged with
* the block in front it and/or the block behind it if the memory blocks are
* adjacent to each other.
*/
static void prvInsertBlockIntoFreeList(BlockLink_t *pxBlockToInsert);
/*
* Called automatically to setup the required heap structures the first time
* pvPortMalloc() is called.
*/
static void prvHeapInit(void);
#endif

View File

@ -1,9 +0,0 @@
#ifndef PCB_H
#define PCB_H
#include <stdint.h>
void saveSampleRSP(uint64_t rsp);
uint64_t getSampleRSP();
#endif

View File

@ -15,7 +15,7 @@ void haltcpu();
#define MAX_PRIORITY 40 #define MAX_PRIORITY 40
#define MIN_PRIORITY 0 #define MIN_PRIORITY 0
#define DEF_PRIORITY 0 #define DEF_PRIORITY 0
#define PROCESS_DATA_MAX_SIZE 100 #define PROCESS_DATA_MAX_SIZE 300
#define MAX_ATTR_SIZE 6 #define MAX_ATTR_SIZE 6
#define MAX_NAME_SIZE 10 #define MAX_NAME_SIZE 10
#define IDLE_PID 1 #define IDLE_PID 1

View File

@ -1,19 +1,7 @@
#ifdef BUDDY #ifdef BUDDY
// Basado en: https://github.com/cloudwu/buddy/blob/master/buddy.c // Basado en: https://github.com/cloudwu/buddy/blob/master/buddy.c
#include "memManagerBuddy.h"
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#define NODE_UNUSED 0
#define NODE_USED 1
#define NODE_SPLIT 2
#define NODE_FULL 3
#define LEVEL 20
#define SIZE (1<<LEVEL)
struct buddy{ struct buddy{
int level; int level;
@ -25,12 +13,13 @@ static struct buddy self;
void * buddy_alloc(int); void * buddy_alloc(int);
int buddy_free(void *); int buddy_free(void *);
void * pvPortMalloc(int size){ void * pvPortMalloc(size_t size){
return buddy_alloc(size); return buddy_alloc(size);
} }
int vPortFree(void * pointer){ void vPortFree(void * pointer){
return buddy_free(pointer); buddy_free(pointer);
// return;
} }
static int heapAddress = 0; static int heapAddress = 0;
@ -53,7 +42,7 @@ uint32_t next_pow_of_2(uint32_t x) {
x |= x>>4; x |= x>>4;
x |= x>>8; x |= x>>8;
x |= x>>16; x |= x>>16;
return x+1; return x + 1;
} }
#define PAGE_SIZE 0x1000 #define PAGE_SIZE 0x1000
@ -63,7 +52,6 @@ int _index_offset(int index, int level, int max_level) {
} }
void _mark_parent(int index) { void _mark_parent(int index) {
while(1) { while(1) {
int buddy = index - 1 + (index & 1) * 2; int buddy = index - 1 + (index & 1) * 2;
if (buddy > 0 && (self.tree[buddy] == NODE_USED || self.tree[buddy] == NODE_FULL)) { if (buddy > 0 && (self.tree[buddy] == NODE_USED || self.tree[buddy] == NODE_FULL)) {
@ -77,13 +65,13 @@ void _mark_parent(int index) {
void * buddy_alloc(int s) { void * buddy_alloc(int s) {
if(s%PAGE_SIZE != 0){ if (s % PAGE_SIZE != 0){
s=(s/PAGE_SIZE)+1; s = (s / PAGE_SIZE) + 1;
}else{ } else{
s/=PAGE_SIZE; s /= PAGE_SIZE;
} }
int size; int size;
if (s==0) { if (s == 0) {
size = 1; size = 1;
} else { } else {
size = (int)next_pow_of_2(s); size = (int)next_pow_of_2(s);
@ -111,8 +99,8 @@ void * buddy_alloc(int s) {
case NODE_FULL: break; case NODE_FULL: break;
case NODE_UNUSED: case NODE_UNUSED:
self.tree[index] = NODE_SPLIT; self.tree[index] = NODE_SPLIT;
self.tree[index*2+1] = NODE_UNUSED; self.tree[index * 2 + 1] = NODE_UNUSED;
self.tree[index*2+2] = NODE_UNUSED; self.tree[index * 2 + 2] = NODE_UNUSED;
default: default:
index = index * 2 + 1; index = index * 2 + 1;
length /= 2; length /= 2;
@ -120,7 +108,7 @@ void * buddy_alloc(int s) {
nextStep = 0; nextStep = 0;
} }
} }
if( nextStep ){ if (nextStep) {
if (index & 1) { if (index & 1) {
++index; ++index;
} else { } else {
@ -128,7 +116,7 @@ void * buddy_alloc(int s) {
while(cont) { while(cont) {
level--; level--;
length *= 2; length *= 2;
index = (index+1)/2 -1; index = (index + 1) / 2 - 1;
if (index < 0) if (index < 0)
return NULL; return NULL;
if (index & 1) { if (index & 1) {
@ -137,10 +125,8 @@ void * buddy_alloc(int s) {
} }
} }
} }
} }
} }
return NULL; return NULL;
} }
@ -195,37 +181,81 @@ int buddy_free(void * pointer) {
} }
} }
static void dumpMM(struct buddy * self, int index , int level) { // char *dumpMM() {
char buffer[100]; // return NULL;
// }
uint64_t getSize(int level, int max_level) {
return (1 << (max_level - level)) * PAGE_SIZE;
}
/*
void buddy_dumpMM(struct buddy * self, int index , int level) {
char buffer[10];
switch (self->tree[index]) { switch (self->tree[index]) {
case NODE_UNUSED: case NODE_UNUSED:
printStringLen("(%d:%d)", _index_offset(index, level, self->level) , 1 << (self->level - level)); printStringLen(15, "(_", 1);
printStringLen(15, itoa(getSize(level, self->level), buffer, 10), 0);
printStringLen(15, ":", 1);
printStringLen(15, itoa(level, buffer, 10), 10);
printStringLen(15, "_)", 1);
break; break;
case NODE_USED: case NODE_USED:
printStringLen("(", 1); printStringLen(15, "(*", 1);
printStringLen(itoa(_index_offset(index, level, self->level), buffer, 10)); printStringLen(15, itoa(getSize(level, self->level), buffer, 10), 10);
printStringLen(":", 1); printStringLen(15, ":", 1);
printStringLen(itoa(1 << (self->level - level), buffer, 10)); printStringLen(15, itoa(level, buffer, 10), 10);
printStringLen(")", 1); printStringLen(15, "*)", 1);
break; break;
case NODE_FULL: case NODE_FULL:
printStringLen("{", 1); printStringLen(15, "[", 1);
_dump(self, index * 2 + 1, level+1); buddy_dumpMM(self, index * 2 + 1, level + 1);
_dump(self, index * 2 + 2, level+1); buddy_dumpMM(self, index * 2 + 2, level + 1);
printStringLen("}", 1); printStringLen(15, "]", 1);
break; break;
default: default:
printStringLen("(", 1); printStringLen(15, "(", 1);
_dump(self, index * 2 + 1, level+1); buddy_dumpMM(self, index * 2 + 1, level + 1);
_dump(self, index * 2 + 2, level+1); buddy_dumpMM(self, index * 2 + 2, level + 1);
printStringLen(")", 1); printStringLen(15, ")", 1);
break;
}
}
*/
#include <stddef.h>
void buddy_dumpMM(int index , int level, uint64_t *size, uint64_t *used) {
char buffer[10];
switch (self.tree[index]) {
case NODE_UNUSED:
*size += getSize(level, self.level);
break;
case NODE_USED:
*size += getSize(level, self.level);
*used += getSize(level, self.level);
break;
case NODE_FULL:
buddy_dumpMM(index * 2 + 1, level+1, size, used);
buddy_dumpMM(index * 2 + 2, level+1, size, used);
break;
default:
buddy_dumpMM(index * 2 + 1, level+1, size, used);
buddy_dumpMM(index * 2 + 2, level+1, size, used);
break; break;
} }
} }
void buddy_dumpMM(struct buddy * self) { char * dumpMM() {
dumpMM(self, 0 , 0); uint64_t size = 0, used = 0;
printStringLen("\n", 1); buddy_dumpMM(0, 0, &size, &used);
char *ans = pvPortMalloc(DUMP_MAX_SIZE);
char *ret = ans;
char buffer[20] = {0};
ans += strcpy(ans, "Free memory: ");
ans += strcpy(ans, itoa(size - used, buffer, 10, 20));
ans += strcpy(ans, "\nTotal memory: ");
ans += strcpy(ans, itoa(size, buffer, 10, 20));
return ret;
} }
#endif #endif

View File

@ -1,48 +1,6 @@
#ifndef BUDDY #ifndef BUDDY
#include <stdlib.h> #include "memManagerFRT4.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 * 1024 * 512
#define configAPPLICATION_ALLOCATED_HEAP 0
#define portBYTE_ALIGNMENT 8
// #define portBYTE_ALIGNMENT 16
#define portBYTE_ALIGNMENT_MASK ( 0x0007 ) // 8
// #define portBYTE_ALIGNMENT_MASK ( 0x000F ) // 16
#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 )
#define heapBITS_PER_BYTE ( ( size_t ) 8 )
#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize << 1 ) )
/* Define the linked list structure. This is used to link free blocks in order
of their memory address. */
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 uint8_t *ucHeap; static uint8_t *ucHeap;
@ -50,42 +8,9 @@ void initMemoryManager(void *managedMemory) {
ucHeap = managedMemory; ucHeap = managedMemory;
} }
/* Definition of the Heap_stats_t structure. */
typedef struct xHeapStats {
size_t xAvailableHeapSpaceInBytes; /* The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated. */
size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */
size_t xMinimumEverFreeBytesRemaining; /* The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted. */
size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */
size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */
} HeapStats_t;
/* Prototype of the vPortGetHeapStats() function. */
void vPortGetHeapStats(HeapStats_t *xHeapStats);
/*-----------------------------------------------------------*/
/*
* Inserts a block of memory that is being freed into the correct position in
* the list of free memory blocks. The block being freed will be merged with
* the block in front it and/or the block behind it if the memory blocks are
* adjacent to each other.
*/
static void prvInsertBlockIntoFreeList(BlockLink_t *pxBlockToInsert);
/*
* Called automatically to setup the required heap structures the first time
* pvPortMalloc() is called.
*/
static void prvHeapInit(void);
/*-----------------------------------------------------------*/
/* The size of the structure placed at the beginning of each allocated memory /* The size of the structure placed at the beginning of each allocated memory
block must by correctly byte aligned. */ block must by correctly byte aligned. */
static const size_t xHeapStructSize = static const size_t xHeapStructSize = (sizeof(BlockLink_t) + ((size_t)(portBYTE_ALIGNMENT - 1))) & ~((size_t)portBYTE_ALIGNMENT_MASK);
(sizeof(BlockLink_t) + ((size_t)(portBYTE_ALIGNMENT - 1))) & ~((size_t)portBYTE_ALIGNMENT_MASK);
/* Create a couple of list links to mark the start and end of the list. */ /* Create a couple of list links to mark the start and end of the list. */
static BlockLink_t xStart, *pxEnd = NULL; static BlockLink_t xStart, *pxEnd = NULL;
@ -130,7 +55,6 @@ void *pvPortMalloc(size_t xWantedSize) {
if ((xWantedSize & portBYTE_ALIGNMENT_MASK) != 0x00) { if ((xWantedSize & portBYTE_ALIGNMENT_MASK) != 0x00) {
/* Byte alignment required. */ /* Byte alignment required. */
xWantedSize += (portBYTE_ALIGNMENT - (xWantedSize & portBYTE_ALIGNMENT_MASK)); xWantedSize += (portBYTE_ALIGNMENT - (xWantedSize & portBYTE_ALIGNMENT_MASK));
// configASSERT( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) == 0 );
} }
} }
@ -163,7 +87,6 @@ void *pvPortMalloc(size_t xWantedSize) {
cast is used to prevent byte alignment warnings from the cast is used to prevent byte alignment warnings from the
compiler. */ compiler. */
pxNewBlockLink = (void *) (((uint8_t *) pxBlock) + xWantedSize); pxNewBlockLink = (void *) (((uint8_t *) pxBlock) + xWantedSize);
// configASSERT( ( ( ( size_t ) pxNewBlockLink ) & portBYTE_ALIGNMENT_MASK ) == 0 );
/* Calculate the sizes of two blocks split from the /* Calculate the sizes of two blocks split from the
single block. */ single block. */
@ -191,7 +114,6 @@ void *pvPortMalloc(size_t xWantedSize) {
} }
} }
// configASSERT( ( ( ( size_t ) pvReturn ) & ( size_t ) portBYTE_ALIGNMENT_MASK ) == 0 );
return pvReturn; return pvReturn;
} }
@ -219,12 +141,10 @@ void vPortFree(void *pv) {
allocated. */ allocated. */
pxLink->xBlockSize &= ~xBlockAllocatedBit; pxLink->xBlockSize &= ~xBlockAllocatedBit;
// {
/* Add this block to the list of free blocks. */ /* Add this block to the list of free blocks. */
xFreeBytesRemaining += pxLink->xBlockSize; xFreeBytesRemaining += pxLink->xBlockSize;
prvInsertBlockIntoFreeList(((BlockLink_t *) pxLink)); prvInsertBlockIntoFreeList(((BlockLink_t *) pxLink));
xNumberOfSuccessfulFrees++; xNumberOfSuccessfulFrees++;
// }
} }
} }
} }
@ -382,5 +302,40 @@ void vPortGetHeapStats(HeapStats_t *pxHeapStats) {
} }
/*
// Definition of the Heap_stats_t structure.
typedef struct xHeapStats {
size_t xAvailableHeapSpaceInBytes; // The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated.
size_t xSizeOfLargestFreeBlockInBytes; // The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called.
size_t xSizeOfSmallestFreeBlockInBytes; // The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called.
size_t xNumberOfFreeBlocks; // The number of free memory blocks within the heap at the time vPortGetHeapStats() is called.
size_t xMinimumEverFreeBytesRemaining; // The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted.
size_t xNumberOfSuccessfulAllocations; // The number of calls to pvPortMalloc() that have returned a valid memory block.
size_t xNumberOfSuccessfulFrees; // The number of calls to vPortFree() that has successfully freed a block of memory.
} HeapStats_t;
*/
char *dumpMM() {
char *ans = pvPortMalloc(DUMP_MAX_SIZE);
char *ret = ans;
HeapStats_t * heapStats = pvPortMalloc(sizeof(HeapStats_t));
vPortGetHeapStats(heapStats);
char buffer[20] = {0};
ans += strcpy(ans, "Free memory: ");
ans += strcpy(ans, itoa(heapStats->xAvailableHeapSpaceInBytes, buffer, 10, 20));
ans += strcpy(ans, "\nTotal memory: ");
ans += strcpy(ans, itoa(configTOTAL_HEAP_SIZE, buffer, 10, 20));
ans += strcpy(ans, "\nmallocs: ");
ans += strcpy(ans, itoa(heapStats->xNumberOfSuccessfulAllocations, buffer, 10, 20));
ans += strcpy(ans, "\nfrees: ");
ans += strcpy(ans, itoa(heapStats->xNumberOfSuccessfulFrees, buffer, 10, 20));
vPortFree(heapStats);
return ret;
}
#endif /* #ifdef configHEAP_ALLOCATION_SCHEME */ #endif /* #ifdef configHEAP_ALLOCATION_SCHEME */
// #endif /* #if(configHEAP_ALLOCATION_SCHEME == HEAP_ALLOCATION_TYPE4) */ // #endif /* #if(configHEAP_ALLOCATION_SCHEME == HEAP_ALLOCATION_TYPE4) */

View File

@ -1,11 +0,0 @@
#include "pcb.h"
static uint64_t sampleRSP;
void saveSampleRSP(uint64_t rsp) {
sampleRSP = rsp;
}
uint64_t getSampleRSP() {
return sampleRSP;
}

View File

@ -16,6 +16,7 @@ node_t * searchSem(char * name, node_t ** prev) {
while (aux != NULL) { while (aux != NULL) {
if (!strcmp(name, aux->sem->name)) if (!strcmp(name, aux->sem->name))
break; break;
aux = aux->next;
} }
return aux; return aux;
} }

View File

@ -5,7 +5,7 @@ GLOBAL _getRegs, sys_switchContext
GLOBAL cpu_id, cpu_id_support GLOBAL cpu_id, cpu_id_support
GLOBAL sys_exit, sys_ps, sys_free, sys_malloc, sys_sem, sys_openPipe, sys_semClose GLOBAL sys_exit, sys_ps, sys_free, sys_malloc, sys_sem, sys_openPipe, sys_semClose
GLOBAL sys_nice, sys_semWait, sys_semPost, sys_semOpen, sys_sleep, sys_kill, sys_getPid, GLOBAL sys_nice, sys_semWait, sys_semPost, sys_semOpen, sys_sleep, sys_kill, sys_getPid,
GLOBAL sys_block, sys_unblock, sys_wait, sys_pipes, sys_quitCPU GLOBAL sys_block, sys_unblock, sys_wait, sys_pipes, sys_quitCPU, sys_dumpMM
section .text section .text
@ -242,6 +242,21 @@ sys_quitCPU:
pop rbp pop rbp
ret ret
sys_dumpMM:
push rbp
mov rbp, rsp
push rdi
mov rdi, 5
int 80h
pop rdi
mov rsp, rbp
pop rbp
ret
sys_wait: sys_wait:
push rbp push rbp
mov rbp, rsp mov rbp, rsp

View File

@ -35,5 +35,6 @@ char sys_block(int pid);
char sys_unblock(int pid); char sys_unblock(int pid);
void sys_quitCPU(); void sys_quitCPU();
void sys_wait(); void sys_wait();
char * sys_dumpMM();
#endif #endif

View File

@ -1,11 +1,40 @@
#include "libc.h" #include "libc.h"
#include "shell.h" #include "shell.h"
static char * info[] = {"clear: Clear the shell window", "cpufeatures: Show the features the cpu supports", "excdiv: Throw exception 0 (zero division)", "excop: Throw exception 6 (opcode error)", "help: Print information about commands", "inforeg: Print values of registers","printmem: Prints 32 bytes of memory, starting at a given direction", "quadratic: Receives 3 floats, quadratic coefficients, prints roots if real", "time: Prints date and time in UTC" }; #define PAGE_SIZE 10
static const int len = 9;
static char * info[] = {"block: Block a process given the pid", "cat: Prints out the text it receives", "clear: Clears the window", "cpufeatures: Show the features the cpu supports", "excdiv: Throw exception 0 (zero division)", "excop: Throw exception 6 (opcode error)", "filter: Prints out the text it receives ignoring vocals", "help: Print information about commands", "inforeg: Print values of registers", "kill: Kills a process given the pid", "loop: Prints it's pid and a given message every given amount of seconds", "nice: Changes the priority of a given process (min: -20, max: 19)", "phylo: Shows a solution for the philosopher problem", "pipes: Prints the dump of the used pipes and their state", "printmem: Prints 32 bytes of memory, starting at a given direction", "ps: Prints information of the running processes", "quadratic: Receives 3 floats, quadratic coefficients, prints roots if real", "sems: Prints the dump of used semaphores", "test_mm: Runs memory manager test", "test_no_sync: Runs synchronization test without semaphores", "test_prio: Runs process priority test", "test_processes: Runs process creation test", "test_sync: Runs synchronization test with semaphores", "time: Prints date and time in UTC", "unblock: Unblocks a process given it's pid", "wc: Prints out amount of lines in the received text", 0 };
int getCurrentPages() {
int i = 0;
for (; info[i] != 0; i++);
return ((i + 1) / PAGE_SIZE) + 1;
}
void help(int argc, char *argv[]) { void help(int argc, char *argv[]) {
for (int i = 0; i < len; i++) { if (argc != 2) {
printStringLen("help receives a number of page between 1 and ", 46);
char buffer[10] = {0};
printString(itoa(getCurrentPages(), buffer, 10));
newline();
sys_exit();
}
int page = atoi(argv[1], 10);
int pages = getCurrentPages();
if (page < 1 || page > pages) {
if (pages > 1) {
printStringLen("page number must be between 1 and ", 34);
char buffer[10] = {0};
printString(itoa(pages, buffer, 10));
}
else
printStringLen("help only has one page (page = 1)\n", 35);
newline();
}
for (int i = (page - 1) * PAGE_SIZE; info[i] != 0 && i < page * PAGE_SIZE; i++) {
printString(info[i]); printString(info[i]);
newline(); newline();
} }

View File

@ -0,0 +1,11 @@
#include "libc.h"
#include "shell.h"
void mem(int argc, char *argv[]) {
char * output = sys_dumpMM();
printString(output);
newline();
sys_free(output);
addEOF();
sys_exit();
}

View File

@ -28,8 +28,6 @@ void test_processes(int argc, char ** argv){
int i = 0; int i = 0;
while (1) { while (1) {
debugPSA();
// Create MAX_PROCESSES processes // Create MAX_PROCESSES processes
for(rq = 0; rq < MAX_PROCESSES; rq++){ for(rq = 0; rq < MAX_PROCESSES; rq++){
char *argv[] = {"endless"}; char *argv[] = {"endless"};
@ -89,15 +87,6 @@ void test_processes(int argc, char ** argv){
printString(itoa(i, buffer, 10)); printString(itoa(i, buffer, 10));
newline(); newline();
} }
// char buffer[6] = {0};
// winClear();
// char buffer[4];
// printString(itoa(i, buffer, 10));
// printStringLen(" procesos creados\n", 19);
// char * output = sys_ps();
// printString(output);
// newline();
} }
sys_exit(); sys_exit();
} }

View File

@ -0,0 +1,9 @@
#ifndef DUMPMEM_LIB
#define DUMPMEM_LIB
#include "libc.h"
#include "system.h"
void mem(int argc, char *argv[]);
#endif

View File

@ -30,6 +30,7 @@
#include "test_sync.h" #include "test_sync.h"
#include "test_processes.h" #include "test_processes.h"
#include "test_mm.h" #include "test_mm.h"
#include "mem.h"
#define EXIT_FAILURE 1 #define EXIT_FAILURE 1
#define EXIT_SUCCESS 0 #define EXIT_SUCCESS 0

View File

@ -7,14 +7,14 @@ cmd_t commands[] = {
{"block", block, 1, 1}, {"block", block, 1, 1},
{"unblock", unblock, 1, 1}, {"unblock", unblock, 1, 1},
{"inforeg", inforeg, 0, 1}, {"inforeg", inforeg, 0, 1},
{"excdiv", excdiv, 1, 1}, {"excdiv", excdiv, 0, 1},
{"excop", excop, 1, 1}, {"excop", excop, 0, 1},
{"filter", filter, 0, 1}, {"filter", filter, 0, 1},
{"clear", clear, 1, 1}, {"clear", clear, 1, 1},
{"cpufeatures", cpufeatures, 0, 1}, {"cpufeatures", cpufeatures, 0, 1},
{"nice", nice, 0, 1}, {"nice", nice, 0, 1},
{"ps", ps, 0, 1}, {"ps", ps, 0, 1},
{"pipe", pipe, 0, 1}, {"pipes", pipe, 0, 1},
{"kill", kill, 1, 1}, {"kill", kill, 1, 1},
{"sem", sem, 0, 1}, {"sem", sem, 0, 1},
{"quadratic", quadratic, 0, 1}, {"quadratic", quadratic, 0, 1},
@ -22,6 +22,7 @@ cmd_t commands[] = {
{"phylo", phylo, 0, 1}, {"phylo", phylo, 0, 1},
{"wc", wc, 0, 1}, {"wc", wc, 0, 1},
{"loop", loop, 0, 1}, {"loop", loop, 0, 1},
{"mem", mem, 0, 1},
{"test_mm", test_mm, 0, 1}, {"test_mm", test_mm, 0, 1},
{"test_prio", test_prio, 0, 1}, {"test_prio", test_prio, 0, 1},
{"test_processes", test_processes, 0, 1}, {"test_processes", test_processes, 0, 1},
@ -130,7 +131,7 @@ void processInput(char *input) {
if (comm_flag0 && (comm_flag1 || pipe == -1)) { if (comm_flag0 && (comm_flag1 || pipe == -1)) {
if (pipe != -1) { if (pipe != -1) {
sys_loadProcess(commands[comm0].func, commands[comm0].isForeground, pipe, argv0, fd1); sys_loadProcess(commands[comm0].func, commands[comm0].isForeground, pipe, argv0, fd1);
sys_loadProcess(commands[comm1].func, commands[comm0].isForeground, end - pipe - 1, argv1, fd2); sys_loadProcess(commands[comm1].func, 0, end - pipe - 1, argv1, fd2);
} else { } else {
if (commands[comm0].isBuiltIn) if (commands[comm0].isBuiltIn)
commands[comm0].func(end, argv0); commands[comm0].func(end, argv0);
@ -141,8 +142,12 @@ void processInput(char *input) {
} }
} }
if (commands[comm0].isForeground) if (commands[comm0].isForeground) {
sys_wait(); sys_wait();
sys_free(argv0);
if (pipe == -1)
sys_free(argv1);
}
} }
if (!comm_flag0) { if (!comm_flag0) {