os-k/kaleid/kernel/sh/musage.c

263 lines
9.2 KiB
C
Raw Normal View History

2019-05-18 23:03:41 +02:00
//----------------------------------------------------------------------------//
// 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/>. //
//----------------------------------------------------------------------------//
2019-05-29 14:34:37 +02:00
#include <io/vga.h>
#include <mm/heap.h>
#include <sh/shell.h>
#include <init/boot.h>
2019-05-18 23:03:41 +02:00
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;
2019-11-28 13:02:47 +01:00
2019-05-18 23:03:41 +02:00
KeRestoreIRQs(flags);
2019-11-28 13:02:47 +01:00
2019-05-18 23:03:41 +02:00
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;
2019-11-28 13:02:47 +01:00
2019-05-18 23:03:41 +02:00
stack_cur = (size_t)BtLoaderInfo.stackEndAddr - (size_t)&var;
KernLog("Kernel image\n");
2019-05-22 23:32:44 +02:00
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,
2019-05-18 23:03:41 +02:00
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelAddr),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelAddr),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B((size_t)BtLoaderInfo.kernelAddr),
VGA_COLOR_DARK_GREY,
shcol
);
2019-05-18 23:03:41 +02:00
2019-05-22 23:32:44 +02:00
KernLog("\t%Cends at:\t\t%C%p (%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C)\n",
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
(size_t)BtLoaderInfo.kernelEndAddr,
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B((size_t)BtLoaderInfo.kernelEndAddr),
VGA_COLOR_DARK_GREY,
shcol
);
2019-05-18 23:03:41 +02:00
2019-05-22 23:32:44 +02:00
KernLog("\t%Csize:\t\t\t%C%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C (%p)\n",
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_MB(img_diff),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_KB(img_diff),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_B(img_diff),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
img_diff
);
2019-05-18 23:03:41 +02:00
KernLog("Kernel stack\n");
2019-05-22 23:32:44 +02:00
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,
2019-05-18 23:03:41 +02:00
_ADDR_TO_MB((size_t)BtLoaderInfo.stackEndAddr),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_KB((size_t)BtLoaderInfo.stackEndAddr),
2019-05-22 23:32:44 +02:00
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,
2019-05-18 23:03:41 +02:00
(size_t)&var,
_ADDR_TO_MB((size_t)&var),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_KB((size_t)&var),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B((size_t)&var),
VGA_COLOR_DARK_GREY,
shcol
);
2019-05-18 23:03:41 +02:00
2019-05-22 23:32:44 +02:00
KernLog("\t%Cmin address:\t%C%p (%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C)\n",
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
(size_t)BtLoaderInfo.kernelEndAddr+16,
_ADDR_TO_MB((size_t)BtLoaderInfo.kernelEndAddr+16),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_KB((size_t)BtLoaderInfo.kernelEndAddr+16),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B((size_t)BtLoaderInfo.kernelEndAddr+16),
VGA_COLOR_DARK_GREY,
shcol
);
2019-05-18 23:03:41 +02:00
2019-05-22 23:32:44 +02:00
KernLog("\t%Csize (cur):\t%C%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C (%p)\n",
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_MB(stack_cur),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_KB(stack_cur),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_B(stack_cur),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
stack_cur
);
2019-05-18 23:03:41 +02:00
2019-05-22 23:32:44 +02:00
KernLog("\t%Csize (max):\t%C%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C (%p)\n",
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_MB(stack_diff),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_KB(stack_diff),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_B(stack_diff),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
stack_diff
);
2019-05-18 23:03:41 +02:00
KernLog("Kernel heap\n");
2019-05-22 23:32:44 +02:00
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,
2019-05-18 23:03:41 +02:00
_ADDR_TO_KB(heap_start),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B(heap_start),
VGA_COLOR_DARK_GREY,
shcol
);
2019-05-18 23:03:41 +02:00
2019-05-22 23:32:44 +02:00
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,
2019-05-18 23:03:41 +02:00
_ADDR_TO_KB(heap_end),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B(heap_end),
VGA_COLOR_DARK_GREY,
shcol
);
2019-05-18 23:03:41 +02:00
2019-05-22 23:32:44 +02:00
KernLog("\t%Cmax addr:\t\t%C%p (%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C)\n",
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
heap_start + heap_max,
_ADDR_TO_MB(heap_start + heap_max),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_KB(heap_start + heap_max),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
_ADDR_TO_B(heap_start + heap_max),
VGA_COLOR_DARK_GREY,
shcol
);
2019-05-18 23:03:41 +02:00
2019-05-22 23:32:44 +02:00
KernLog("\t%Csize (cur):\t%C%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C (%p)\n",
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_MB(heap_diff),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_KB(heap_diff),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_B(heap_diff),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
heap_diff
);
2019-05-18 23:03:41 +02:00
2019-05-23 10:40:50 +02:00
KernLog("\t%Csize (max):\t%C%4lu%CMB%C + %4lu%CKB%C + %4lu%CB%C (%p)\n\n",
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_MB(heap_max),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_KB(heap_max),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
2019-05-18 23:03:41 +02:00
_ADDR_TO_B(heap_max),
2019-05-22 23:32:44 +02:00
VGA_COLOR_DARK_GREY,
shcol,
heap_max
);
2019-05-18 23:03:41 +02:00
return EOK;
}