1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00
os-k/kaleid/kernel/sh/musage.c
2019-05-23 10:40:50 +02:00

260 lines
9.2 KiB
C

//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: Kernel shell //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#include "shell.h"
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;
size_t heap_diff, heap_max;
ulong flags = KePauseIRQs();
heap_start = (size_t)_heap_start;
heap_end = (size_t)_heap_end;
heap_max = _heap_max;
KeRestoreIRQs(flags);
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");
KernLog("\t%Cstarts at:\t\t%C%p (%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C)\n",
VGA_COLOR_DARK_GREY,
shcol,
(size_t)BtLoaderInfo.kernelAddr,
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelAddr),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelAddr),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B((size_t)BtLoaderInfo.kernelAddr),
VGA_COLOR_DARK_GREY,
shcol
);
KernLog("\t%Cends at:\t\t%C%p (%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C)\n",
VGA_COLOR_DARK_GREY,
shcol,
(size_t)BtLoaderInfo.kernelEndAddr,
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B((size_t)BtLoaderInfo.kernelEndAddr),
VGA_COLOR_DARK_GREY,
shcol
);
KernLog("\t%Csize:\t\t\t%C%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C (%p)\n",
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_MB(img_diff),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB(img_diff),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B(img_diff),
VGA_COLOR_DARK_GREY,
shcol,
img_diff
);
KernLog("Kernel stack\n");
KernLog("\t%Cstarts at:\t\t%C%p (%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C)\n",
VGA_COLOR_DARK_GREY,
shcol,
(size_t)BtLoaderInfo.stackEndAddr,
_ADDR_TO_MB((size_t)BtLoaderInfo.stackEndAddr),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB((size_t)BtLoaderInfo.stackEndAddr),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B((size_t)BtLoaderInfo.stackEndAddr),
VGA_COLOR_DARK_GREY,
shcol
);
KernLog("\t%Ccurrently at:\t%C%p (%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C)\n",
VGA_COLOR_DARK_GREY,
shcol,
(size_t)&var,
_ADDR_TO_MB((size_t)&var),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB((size_t)&var),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B((size_t)&var),
VGA_COLOR_DARK_GREY,
shcol
);
KernLog("\t%Cmin address:\t%C%p (%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C)\n",
VGA_COLOR_DARK_GREY,
shcol,
(size_t)BtLoaderInfo.kernelEndAddr+16,
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr+16),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr+16),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B((size_t)BtLoaderInfo.kernelEndAddr+16),
VGA_COLOR_DARK_GREY,
shcol
);
KernLog("\t%Csize (cur):\t%C%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C (%p)\n",
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_MB(stack_cur),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB(stack_cur),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B(stack_cur),
VGA_COLOR_DARK_GREY,
shcol,
stack_cur
);
KernLog("\t%Csize (max):\t%C%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C (%p)\n",
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_MB(stack_diff),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB(stack_diff),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B(stack_diff),
VGA_COLOR_DARK_GREY,
shcol,
stack_diff
);
KernLog("Kernel heap\n");
KernLog("\t%Cstarts at:\t\t%C%p (%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C)\n",
VGA_COLOR_DARK_GREY,
shcol,
heap_start,
_ADDR_TO_MB(heap_start),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB(heap_start),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B(heap_start),
VGA_COLOR_DARK_GREY,
shcol
);
KernLog("\t%Cends at:\t\t%C%p (%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C)\n",
VGA_COLOR_DARK_GREY,
shcol,
heap_end,
_ADDR_TO_MB(heap_end),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB(heap_end),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B(heap_end),
VGA_COLOR_DARK_GREY,
shcol
);
KernLog("\t%Cmax addr:\t\t%C%p (%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C)\n",
VGA_COLOR_DARK_GREY,
shcol,
heap_start + heap_max,
_ADDR_TO_MB(heap_start + heap_max),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB(heap_start + heap_max),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B(heap_start + heap_max),
VGA_COLOR_DARK_GREY,
shcol
);
KernLog("\t%Csize (cur):\t%C%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C (%p)\n",
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_MB(heap_diff),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB(heap_diff),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B(heap_diff),
VGA_COLOR_DARK_GREY,
shcol,
heap_diff
);
KernLog("\t%Csize (max):\t%C%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C (%p)\n\n",
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_MB(heap_max),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_KB(heap_max),
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B(heap_max),
VGA_COLOR_DARK_GREY,
shcol,
heap_max
);
return EOK;
}