Compare commits
2 Commits
2f1eef9e15
...
e8a0a36889
| Author | SHA1 | Date | |
|---|---|---|---|
|
e8a0a36889
|
|||
|
1fc5225fd2
|
@@ -28,5 +28,6 @@ void* kmalloc(size_t size);
|
|||||||
void kfree(void* ptr);
|
void kfree(void* ptr);
|
||||||
void* kalloc_stack(void);
|
void* kalloc_stack(void);
|
||||||
void kheap_map_page(void);
|
void kheap_map_page(void);
|
||||||
|
void kheap_info();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* @author xamidev <xamidev@riseup.net>
|
* @author xamidev <xamidev@riseup.net>
|
||||||
* @brief Spinlock implementation
|
* @brief Spinlock implementation
|
||||||
* @license GPL-3.0-only
|
* @license GPL-3.0-only
|
||||||
|
|||||||
@@ -62,5 +62,4 @@ struct ubsan_overflow_data
|
|||||||
struct ubsan_type_descriptor* type;
|
struct ubsan_type_descriptor* type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
* @license GPL-3.0-only
|
* @license GPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <mem/gdt.h>
|
#include <arch/gdt.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <io/serial/serial.h>
|
#include <io/serial/serial.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
+22
-1
@@ -4,7 +4,7 @@
|
|||||||
* @license GPL-3.0-only
|
* @license GPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <mem/gdt.h>
|
#include <arch/gdt.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <arch/x86.h>
|
#include <arch/x86.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
@@ -29,6 +29,26 @@ static void x86_overwrite_pat()
|
|||||||
wrmsr(0x277, pat);
|
wrmsr(0x277, pat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* x86_enable_fpu - Enable Floating Point Unit
|
||||||
|
*
|
||||||
|
* This function enables the Floating Point Unit,
|
||||||
|
* which allows the CPU to do floating point
|
||||||
|
* operations.
|
||||||
|
*
|
||||||
|
* Here we do not check for FPU support but we
|
||||||
|
* should. However most processors support it.
|
||||||
|
*/
|
||||||
|
static void x86_enable_fpu()
|
||||||
|
{
|
||||||
|
size_t cr4;
|
||||||
|
__asm__ volatile("mov %%cr4, %0" : "=r"(cr4));
|
||||||
|
cr4 |= 0x200;
|
||||||
|
__asm__ volatile("mov %0, %%cr4" :: "r"(cr4));
|
||||||
|
uint16_t cw = 0x37F;
|
||||||
|
asm volatile("fldcw %0" :: "m"(cw));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* x86_arch_init - Initialize x86 CPU structures
|
* x86_arch_init - Initialize x86 CPU structures
|
||||||
*
|
*
|
||||||
@@ -42,6 +62,7 @@ static void x86_overwrite_pat()
|
|||||||
void x86_arch_init()
|
void x86_arch_init()
|
||||||
{
|
{
|
||||||
x86_overwrite_pat();
|
x86_overwrite_pat();
|
||||||
|
x86_enable_fpu();
|
||||||
x86_cpu_identification();
|
x86_cpu_identification();
|
||||||
idt_init();
|
idt_init();
|
||||||
gdt_init();
|
gdt_init();
|
||||||
|
|||||||
+13
-7
@@ -289,15 +289,21 @@ int keyboard_getline(char* output, size_t size)
|
|||||||
|
|
||||||
// Read until Enter is pressed
|
// Read until Enter is pressed
|
||||||
while ((c = keyboard_getchar()) != 0x0A) {
|
while ((c = keyboard_getchar()) != 0x0A) {
|
||||||
if (index == size-1) {
|
if (c == '\b') {
|
||||||
output[index] = c;
|
if (index > 0) {
|
||||||
output[index+1] = '\0';
|
index--;
|
||||||
return index;
|
output[index] = '\0';
|
||||||
|
printf(" \b");
|
||||||
}
|
}
|
||||||
output[index] = c;
|
continue;
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
output[index+1] = '\0';
|
|
||||||
|
if (index >= size-1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
output[index++] = c;
|
||||||
|
}
|
||||||
|
output[index] = '\0';
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -11,6 +11,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <time/date.h>
|
#include <time/date.h>
|
||||||
|
#include <mem/kheap.h>
|
||||||
|
|
||||||
__attribute__((noinline))
|
__attribute__((noinline))
|
||||||
void smash_it()
|
void smash_it()
|
||||||
@@ -49,7 +50,8 @@ void pedicel_main(void* arg)
|
|||||||
"syscall - trigger int 0x80\r\n"
|
"syscall - trigger int 0x80\r\n"
|
||||||
"pf - trigger a page fault\r\n"
|
"pf - trigger a page fault\r\n"
|
||||||
"now - get current date\r\n"
|
"now - get current date\r\n"
|
||||||
"smash - smash the stack\r\n");
|
"smash - smash the stack\r\n"
|
||||||
|
"mem - get used heap info\r\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +91,11 @@ void pedicel_main(void* arg)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strncmp(input_buf, "mem", 3) == 0) {
|
||||||
|
kheap_info();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
printf("%s: command not found\r\n", input_buf);
|
printf("%s: command not found\r\n", input_buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
#include <limine.h>
|
#include <limine.h>
|
||||||
#include <io/term/term.h>
|
#include <io/term/term.h>
|
||||||
#include <io/serial/serial.h>
|
#include <io/serial/serial.h>
|
||||||
#include <mem/gdt.h>
|
#include <arch/gdt.h>
|
||||||
#include <mem/utils.h>
|
#include <mem/utils.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <time/timer.h>
|
#include <time/timer.h>
|
||||||
|
|||||||
@@ -158,3 +158,32 @@ void* kalloc_stack()
|
|||||||
uint8_t* ptr = kmalloc(PROCESS_STACK_SIZE); // As it's out of kmalloc, stack is already mapped into kernel space
|
uint8_t* ptr = kmalloc(PROCESS_STACK_SIZE); // As it's out of kmalloc, stack is already mapped into kernel space
|
||||||
return ptr ? ptr+PROCESS_STACK_SIZE : NULL;
|
return ptr ? ptr+PROCESS_STACK_SIZE : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* kheap_info - Display heap info
|
||||||
|
*
|
||||||
|
* This function writes the size of the heap (total),
|
||||||
|
* the number of allocated bytes, and the number of
|
||||||
|
* free bytes to the standard output.
|
||||||
|
*/
|
||||||
|
void kheap_info()
|
||||||
|
{
|
||||||
|
uint64_t free_bytes = 0;
|
||||||
|
struct heap_block_t* curr = (struct heap_block_t*)kheap_start;
|
||||||
|
|
||||||
|
while (curr) {
|
||||||
|
if (curr->free == true) {
|
||||||
|
free_bytes += curr->size;
|
||||||
|
}
|
||||||
|
curr = curr->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t total = end-kheap_start;
|
||||||
|
|
||||||
|
printf("total=% 8u bytes (%u kB)\r\n"
|
||||||
|
"alloc=% 8u bytes (%u kB)\r\n"
|
||||||
|
" free=% 8u bytes (%u kB)\r\n",
|
||||||
|
total, (total)/1000,
|
||||||
|
total-free_bytes, (total-free_bytes)/1000,
|
||||||
|
free_bytes, free_bytes/1000);
|
||||||
|
}
|
||||||
+2
-2
@@ -9,11 +9,11 @@
|
|||||||
#include <mem/kheap.h>
|
#include <mem/kheap.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <string/string.h>
|
#include <string/string.h>
|
||||||
#include <mem/gdt.h>
|
#include <arch/gdt.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <io/serial/serial.h>
|
#include <io/serial/serial.h>
|
||||||
|
|
||||||
#include <io/term/flanterm.h>
|
#include <io/term/flanterm.h>
|
||||||
|
|
||||||
extern struct flanterm_context* ft_ctx;
|
extern struct flanterm_context* ft_ctx;
|
||||||
|
|
||||||
struct process_t* processes_list;
|
struct process_t* processes_list;
|
||||||
|
|||||||
Reference in New Issue
Block a user