musage fix & max heap size
This commit is contained in:
parent
2c4dde7529
commit
de2dcafc6c
|
@ -183,14 +183,14 @@ unsigned long strtoul(const char *restrict, char **restrict, int);
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
||||||
void *calloc(size_t, size_t) __attribute__((__malloc__));
|
void *calloc(size_t, size_t) __attribute__((__malloc__));
|
||||||
void *malloc(size_t) __attribute__((__malloc__));
|
void *malloc(size_t) __attribute__((__malloc__));
|
||||||
void free(void *);
|
void free(void *);
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
||||||
int rand(void);
|
int rand(void);
|
||||||
void srand(unsigned int);
|
void srand(unsigned long);
|
||||||
|
|
||||||
//------------------------------------------//
|
//------------------------------------------//
|
||||||
|
|
||||||
|
|
|
@ -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 *, ...);
|
error_t KernLog(const char *, ...);
|
||||||
|
|
||||||
#ifndef _NO_DEBUG
|
#ifndef _NO_DEBUG
|
||||||
|
|
|
@ -31,9 +31,17 @@
|
||||||
|
|
||||||
//----------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
// Absolute heap max
|
||||||
|
#define MM_HEAP_MAX (256 * MB)
|
||||||
|
|
||||||
// Address of the heap
|
// Address of the heap
|
||||||
extern void *_heap_start;
|
extern void *_heap_start;
|
||||||
|
|
||||||
|
// Current end of the heap
|
||||||
extern void *_heap_end;
|
extern void *_heap_end;
|
||||||
|
|
||||||
|
// Maximal size of the heap
|
||||||
|
// (Default: MM_HEAP_MAX)
|
||||||
extern size_t _heap_max;
|
extern size_t _heap_max;
|
||||||
|
|
||||||
void MmInitHeap(void);
|
void MmInitHeap(void);
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include <kernel/boot.h>
|
#include <kernel/boot.h>
|
||||||
|
|
||||||
int KeCPUCount = 1;
|
int KeCPUCount = 1;
|
||||||
CpuCore_t _KeCPUTable[NCPUS] = {0};
|
CpuCore_t _KeCPUTable[NCPUS] = {0};
|
||||||
|
|
||||||
volatile BootInfo_t BtBootTab = {0};
|
volatile BootInfo_t BtBootTab = {0};
|
||||||
volatile bool KeIsPanicking = 0;
|
volatile bool KeIsPanicking = 0;
|
||||||
|
|
|
@ -208,6 +208,40 @@ Time_t* IoGetRtcTime(void)
|
||||||
return &IoRtcTime;
|
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)
|
ulong IoGetRtcTicks(void)
|
||||||
{
|
{
|
||||||
return IoRtcTicks;
|
return IoRtcTicks;
|
||||||
|
@ -251,6 +285,8 @@ void IoEnableRtc(void)
|
||||||
GetTimeFromRtc();
|
GetTimeFromRtc();
|
||||||
KeRestoreIRQs(flags);
|
KeRestoreIRQs(flags);
|
||||||
IoEnableNMI();
|
IoEnableNMI();
|
||||||
|
|
||||||
|
srand(IoGetTimeStamp());
|
||||||
}
|
}
|
||||||
|
|
||||||
void IoRtcWait(uint time) // time in ms
|
void IoRtcWait(uint time) // time in ms
|
||||||
|
|
|
@ -54,7 +54,7 @@ void MmInitHeap(void)
|
||||||
|
|
||||||
// Initialize the heap
|
// Initialize the heap
|
||||||
_heap_end = _heap_start;
|
_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",
|
KernLog("[InitHeap] Start address : %p, Max length : %u Mio\n\n",
|
||||||
_heap_start, _heap_max / MB);
|
_heap_start, _heap_max / MB);
|
||||||
|
|
|
@ -82,6 +82,9 @@ error_t CmdMemMap(int argc, char **argv, char *cmdline)
|
||||||
|
|
||||||
error_t CmdMemUsage(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 stack_cur;
|
||||||
size_t img_diff, stack_diff;
|
size_t img_diff, stack_diff;
|
||||||
size_t heap_start, heap_end;
|
size_t heap_start, heap_end;
|
||||||
|
@ -95,9 +98,15 @@ error_t CmdMemUsage(int argc, char **argv, char *cmdline)
|
||||||
|
|
||||||
KeRestoreIRQs(flags);
|
KeRestoreIRQs(flags);
|
||||||
|
|
||||||
img_diff = (size_t)BtLoaderInfo.kernelEndAddr - (size_t)BtLoaderInfo.kernelAddr;
|
img_diff = (size_t)BtLoaderInfo.kernelEndAddr
|
||||||
stack_diff = (size_t)BtLoaderInfo.stackEndAddr - ((size_t)BtLoaderInfo.kernelEndAddr + 16);
|
- (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;
|
heap_diff = (size_t)heap_end - (size_t)heap_start;
|
||||||
|
|
||||||
|
stack_cur = (size_t)BtLoaderInfo.stackEndAddr - (size_t)&var;
|
||||||
|
|
||||||
KernLog("Kernel image\n");
|
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_MB((size_t)BtLoaderInfo.stackEndAddr),
|
||||||
_ADDR_TO_KB((size_t)BtLoaderInfo.stackEndAddr),
|
_ADDR_TO_KB((size_t)BtLoaderInfo.stackEndAddr),
|
||||||
_ADDR_TO_B((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,
|
(size_t)&var,
|
||||||
_ADDR_TO_MB((size_t)&var),
|
_ADDR_TO_MB((size_t)&var),
|
||||||
_ADDR_TO_KB((size_t)&var),
|
_ADDR_TO_KB((size_t)&var),
|
||||||
_ADDR_TO_B((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,
|
(size_t)BtLoaderInfo.kernelEndAddr+16,
|
||||||
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr+16),
|
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr+16),
|
||||||
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr+16),
|
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr+16),
|
||||||
|
|
|
@ -60,7 +60,7 @@ void KeStartShell(void)
|
||||||
uchar ch;
|
uchar ch;
|
||||||
error_t rc;
|
error_t rc;
|
||||||
|
|
||||||
char cmdbuf[CMDBUFSIZE] = { 0 };
|
char *cmdbuf = malloc(CMDBUFSIZE);
|
||||||
char *bufptr = cmdbuf;
|
char *bufptr = cmdbuf;
|
||||||
|
|
||||||
argv0 = malloc(ARG_MAX);
|
argv0 = malloc(ARG_MAX);
|
||||||
|
@ -78,7 +78,7 @@ void KeStartShell(void)
|
||||||
bufptr = cmdbuf;
|
bufptr = cmdbuf;
|
||||||
ExecuteCommand(cmdbuf);
|
ExecuteCommand(cmdbuf);
|
||||||
|
|
||||||
memzero(cmdbuf, sizeof(cmdbuf));
|
memzero(cmdbuf, CMDBUFSIZE);
|
||||||
BFlushBuf(BStdIn);
|
BFlushBuf(BStdIn);
|
||||||
KernLog("shell> ");
|
KernLog("shell> ");
|
||||||
BFlushBuf(BStdOut);
|
BFlushBuf(BStdOut);
|
||||||
|
@ -130,7 +130,7 @@ void KeStartShell(void)
|
||||||
bufptr = cmdbuf;
|
bufptr = cmdbuf;
|
||||||
ExecuteCommand(cmdbuf);
|
ExecuteCommand(cmdbuf);
|
||||||
|
|
||||||
memzero(cmdbuf, sizeof(cmdbuf));
|
memzero(cmdbuf, CMDBUFSIZE);
|
||||||
KernLog("shell> ");
|
KernLog("shell> ");
|
||||||
BFlushBuf(BStdIn);
|
BFlushBuf(BStdIn);
|
||||||
BFlushBuf(BStdOut);
|
BFlushBuf(BStdOut);
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
//
|
//
|
||||||
// Seed value
|
// Seed value
|
||||||
//
|
//
|
||||||
static ulong next = 7756;
|
static ulong next = 1;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Returns a pseudo-random integer
|
// Returns a pseudo-random integer
|
||||||
|
@ -42,7 +42,7 @@ int rand(void)
|
||||||
//
|
//
|
||||||
// (Re)Set the random seed
|
// (Re)Set the random seed
|
||||||
//
|
//
|
||||||
void srand(uint seed)
|
void srand(ulong seed)
|
||||||
{
|
{
|
||||||
next = (ulong)seed;
|
next = (ulong)seed;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue