1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00

musage fix & max heap size

This commit is contained in:
Julian Barathieu 2019-05-13 20:34:41 +02:00
parent 2c4dde7529
commit de2dcafc6c
9 changed files with 76 additions and 21 deletions

View File

@ -183,14 +183,14 @@ unsigned long strtoul(const char *restrict, char **restrict, int);
//------------------------------------------//
void *calloc(size_t, size_t) __attribute__((__malloc__));
void *malloc(size_t) __attribute__((__malloc__));
void free(void *);
void *calloc(size_t, size_t) __attribute__((__malloc__));
void *malloc(size_t) __attribute__((__malloc__));
void free(void *);
//------------------------------------------//
int rand(void);
void srand(unsigned int);
void srand(unsigned long);
//------------------------------------------//

View File

@ -153,6 +153,14 @@ extern CpuCore_t _KeCPUTable[NCPUS];
//----------------------------------------------------------------------------//
#ifdef NDEBUG
#define DEBUG if(0)
#else
#define DEBUG if(1)
#endif
//----------------------------------------------------------------------------//
error_t KernLog(const char *, ...);
#ifndef _NO_DEBUG

View File

@ -31,9 +31,17 @@
//----------------------------------------------------------------------------//
// Absolute heap max
#define MM_HEAP_MAX (256 * MB)
// Address of the heap
extern void *_heap_start;
// Current end of the heap
extern void *_heap_end;
// Maximal size of the heap
// (Default: MM_HEAP_MAX)
extern size_t _heap_max;
void MmInitHeap(void);

View File

@ -25,7 +25,7 @@
#include <kernel/boot.h>
int KeCPUCount = 1;
CpuCore_t _KeCPUTable[NCPUS] = {0};
CpuCore_t _KeCPUTable[NCPUS] = {0};
volatile BootInfo_t BtBootTab = {0};
volatile bool KeIsPanicking = 0;

View File

@ -208,6 +208,40 @@ Time_t* IoGetRtcTime(void)
return &IoRtcTime;
}
static uint IsLeapYear(uint year)
{
if (!(year % 4)) {
return 0;
}
return year % 100 == 0
? (year % 400 == 0)
: 1;
}
static uint DaysInMonth(uint month, uint year)
{
return (month == 2)
? (28 + IsLeapYear(year))
: 31 - (month - 1) % 7 % 2;
}
ulong IoGetTimeStamp(void)
{
Time_t *time = IoGetRtcTime();
uint dpy = 365 + IsLeapYear(time->year);
uint dim = DaysInMonth(time->month, time->year + time->century * 100);
return time->sec
+ time->min * 60
+ time->hour * 60 * 60
+ time->day * 24 * 60 * 60
+ time->month * dim * 24 * 60 * 60
+ (time->year + time->century * 100)
* dpy * 24 * 60 * 60;
}
ulong IoGetRtcTicks(void)
{
return IoRtcTicks;
@ -251,6 +285,8 @@ void IoEnableRtc(void)
GetTimeFromRtc();
KeRestoreIRQs(flags);
IoEnableNMI();
srand(IoGetTimeStamp());
}
void IoRtcWait(uint time) // time in ms

View File

@ -54,7 +54,7 @@ void MmInitHeap(void)
// Initialize the heap
_heap_end = _heap_start;
_heap_max = MmGetAvailZoneSize(_heap_end);
_heap_max = lmin(MM_HEAP_MAX, MmGetAvailZoneSize(_heap_end));
KernLog("[InitHeap] Start address : %p, Max length : %u Mio\n\n",
_heap_start, _heap_max / MB);

View File

@ -82,6 +82,9 @@ error_t CmdMemMap(int argc, char **argv, char *cmdline)
error_t CmdMemUsage(int argc, char **argv, char *cmdline)
{
char var;
(void)var;
size_t stack_cur;
size_t img_diff, stack_diff;
size_t heap_start, heap_end;
@ -95,9 +98,15 @@ error_t CmdMemUsage(int argc, char **argv, char *cmdline)
KeRestoreIRQs(flags);
img_diff = (size_t)BtLoaderInfo.kernelEndAddr - (size_t)BtLoaderInfo.kernelAddr;
stack_diff = (size_t)BtLoaderInfo.stackEndAddr - ((size_t)BtLoaderInfo.kernelEndAddr + 16);
img_diff = (size_t)BtLoaderInfo.kernelEndAddr
- (size_t)BtLoaderInfo.kernelAddr;
stack_diff = (size_t)BtLoaderInfo.stackEndAddr
- ((size_t)BtLoaderInfo.kernelEndAddr + 16);
heap_diff = (size_t)heap_end - (size_t)heap_start;
stack_cur = (size_t)BtLoaderInfo.stackEndAddr - (size_t)&var;
KernLog("Kernel image\n");
@ -126,20 +135,14 @@ error_t CmdMemUsage(int argc, char **argv, char *cmdline)
_ADDR_TO_MB((size_t)BtLoaderInfo.stackEndAddr),
_ADDR_TO_KB((size_t)BtLoaderInfo.stackEndAddr),
_ADDR_TO_B((size_t)BtLoaderInfo.stackEndAddr));
BARRIER();
char var;
(void)var;
stack_cur = (size_t)BtLoaderInfo.stackEndAddr - (size_t)&var;
KernLog("\tends at:\t\t%p (%4luMB + %4luKB + %4luB)\n",
KernLog("\tcurrently at:\t%p (%4luMB + %4luKB + %4luB)\n",
(size_t)&var,
_ADDR_TO_MB((size_t)&var),
_ADDR_TO_KB((size_t)&var),
_ADDR_TO_B((size_t)&var));
KernLog("\tmin addr:\t\t%p (%4luMB + %4luKB + %4luB)\n",
KernLog("\tmin address:\t%p (%4luMB + %4luKB + %4luB)\n",
(size_t)BtLoaderInfo.kernelEndAddr+16,
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr+16),
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr+16),

View File

@ -60,7 +60,7 @@ void KeStartShell(void)
uchar ch;
error_t rc;
char cmdbuf[CMDBUFSIZE] = { 0 };
char *cmdbuf = malloc(CMDBUFSIZE);
char *bufptr = cmdbuf;
argv0 = malloc(ARG_MAX);
@ -78,7 +78,7 @@ void KeStartShell(void)
bufptr = cmdbuf;
ExecuteCommand(cmdbuf);
memzero(cmdbuf, sizeof(cmdbuf));
memzero(cmdbuf, CMDBUFSIZE);
BFlushBuf(BStdIn);
KernLog("shell> ");
BFlushBuf(BStdOut);
@ -130,7 +130,7 @@ void KeStartShell(void)
bufptr = cmdbuf;
ExecuteCommand(cmdbuf);
memzero(cmdbuf, sizeof(cmdbuf));
memzero(cmdbuf, CMDBUFSIZE);
KernLog("shell> ");
BFlushBuf(BStdIn);
BFlushBuf(BStdOut);

View File

@ -27,7 +27,7 @@
//
// Seed value
//
static ulong next = 7756;
static ulong next = 1;
//
// Returns a pseudo-random integer
@ -42,7 +42,7 @@ int rand(void)
//
// (Re)Set the random seed
//
void srand(uint seed)
void srand(ulong seed)
{
next = (ulong)seed;
}