forked from PoliEcho-holding-org/kern
Compare commits
4
Commits
9c386bf447
...
ce75e8c195
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce75e8c195 | ||
|
|
9bdc3c8fc9 | ||
|
|
8909e3c4ca | ||
|
|
70114f6326 |
+4
-4
@@ -79,7 +79,7 @@ AllowShortCaseLabelsOnASingleLine: false
|
|||||||
AllowShortCompoundRequirementOnASingleLine: true
|
AllowShortCompoundRequirementOnASingleLine: true
|
||||||
AllowShortEnumsOnASingleLine: true
|
AllowShortEnumsOnASingleLine: true
|
||||||
AllowShortFunctionsOnASingleLine: All
|
AllowShortFunctionsOnASingleLine: All
|
||||||
AllowShortIfStatementsOnASingleLine: Never
|
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||||
AllowShortLambdasOnASingleLine: All
|
AllowShortLambdasOnASingleLine: All
|
||||||
AllowShortLoopsOnASingleLine: false
|
AllowShortLoopsOnASingleLine: false
|
||||||
AllowShortNamespacesOnASingleLine: false
|
AllowShortNamespacesOnASingleLine: false
|
||||||
@@ -171,7 +171,7 @@ IndentExternBlock: AfterExternBlock
|
|||||||
IndentGotoLabels: true
|
IndentGotoLabels: true
|
||||||
IndentPPDirectives: None
|
IndentPPDirectives: None
|
||||||
IndentRequiresClause: true
|
IndentRequiresClause: true
|
||||||
IndentWidth: 2
|
IndentWidth: 8
|
||||||
IndentWrappedFunctionNames: false
|
IndentWrappedFunctionNames: false
|
||||||
InsertBraces: false
|
InsertBraces: false
|
||||||
InsertNewlineAtEOF: false
|
InsertNewlineAtEOF: false
|
||||||
@@ -216,7 +216,7 @@ PenaltyBreakTemplateDeclaration: 10
|
|||||||
PenaltyExcessCharacter: 1000000
|
PenaltyExcessCharacter: 1000000
|
||||||
PenaltyIndentedWhitespace: 0
|
PenaltyIndentedWhitespace: 0
|
||||||
PenaltyReturnTypeOnItsOwnLine: 60
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
PointerAlignment: Right
|
PointerAlignment: Left
|
||||||
PPIndentWidth: -1
|
PPIndentWidth: -1
|
||||||
QualifierAlignment: Leave
|
QualifierAlignment: Leave
|
||||||
ReferenceAlignment: Pointer
|
ReferenceAlignment: Pointer
|
||||||
@@ -284,7 +284,7 @@ StatementMacros:
|
|||||||
- QT_REQUIRE_VERSION
|
- QT_REQUIRE_VERSION
|
||||||
TableGenBreakInsideDAGArg: DontBreak
|
TableGenBreakInsideDAGArg: DontBreak
|
||||||
TabWidth: 8
|
TabWidth: 8
|
||||||
UseTab: Never
|
UseTab: Always
|
||||||
VerilogBreakBetweenInstancePorts: true
|
VerilogBreakBetweenInstancePorts: true
|
||||||
WhitespaceSensitiveMacros:
|
WhitespaceSensitiveMacros:
|
||||||
- BOOST_PP_STRINGIZE
|
- BOOST_PP_STRINGIZE
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ Low-Level Hardware & Interrupts
|
|||||||
Memory Management
|
Memory Management
|
||||||
[x] Physical memory manager (Bitmap or Buddy)
|
[x] Physical memory manager (Bitmap or Buddy)
|
||||||
[x] Paging (Recursive or Offset mapping)
|
[x] Paging (Recursive or Offset mapping)
|
||||||
[ ] Kernel heap (kmalloc/kfree - Linked list or Slab)
|
[-] Kernel heap (kmalloc/kfree - Linked list or Slab)
|
||||||
[ ] Memory mapped I/O (MMIO) API for drivers
|
[ ] Memory mapped I/O (MMIO) API for drivers
|
||||||
[ ] VMM: Shared memory regions (For IPC/Framebuffers)
|
[ ] VMM: Shared memory regions (For IPC/Framebuffers)
|
||||||
[ ] VMM: Copy-on-Write (COW) support (Optional but good)
|
[ ] VMM: Copy-on-Write (COW) support (Optional but good)
|
||||||
|
|||||||
@@ -48,3 +48,19 @@ A pointer to allocated memory or NULL.
|
|||||||
**Parameters**
|
**Parameters**
|
||||||
* `size_t count` -
|
* `size_t count` -
|
||||||
|
|
||||||
|
**Description**
|
||||||
|
This function allocates memory for `count` elements each of `size` bytes, zeroed-out memory.
|
||||||
|
|
||||||
|
**Returns**
|
||||||
|
A pointer to allocated memory or NULL.
|
||||||
|
|
||||||
|
`void* kfree(void* p)`
|
||||||
|
******************************************
|
||||||
|
**Parameters**
|
||||||
|
* `void* p` -
|
||||||
|
|
||||||
|
**Description**
|
||||||
|
This function frees memory previously allocated using `k[m,z,c]alloc()`
|
||||||
|
|
||||||
|
**Returns**
|
||||||
|
Nothing
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#ifndef _KMALLOC_H
|
||||||
|
#define _KMALLOC_H
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
// This function allocates size bytes of contiguous memory.
|
||||||
|
// Returns a pointer to allocated memory or NULL.
|
||||||
|
void* kmalloc(size_t size);
|
||||||
|
|
||||||
|
// This function allocates size bytes of contiguous, zeroed-out memory.
|
||||||
|
// Returns a pointer to allocated memory or NULL.
|
||||||
|
void* kzalloc(size_t size);
|
||||||
|
|
||||||
|
// This function allocates memory for count elements each of size bytes,
|
||||||
|
// zeroed-out memory. Returns a pointer to allocated memory or NULL.
|
||||||
|
void* kcalloc(size_t count, size_t size);
|
||||||
|
|
||||||
|
// powers of 2
|
||||||
|
#define KMALLOC_MAX_SIZE 17
|
||||||
|
|
||||||
|
union per_cpu_freelist_cache {
|
||||||
|
void* freelists[KMALLOC_MAX_SIZE];
|
||||||
|
struct {
|
||||||
|
void* kmalloc_8;
|
||||||
|
void* kmalloc_16;
|
||||||
|
void* kmalloc_32;
|
||||||
|
void* kmalloc_64;
|
||||||
|
void* kmalloc_128;
|
||||||
|
void* kmalloc_256;
|
||||||
|
void* kmalloc_512;
|
||||||
|
void* kmalloc_1024;
|
||||||
|
void* kmalloc_2048;
|
||||||
|
void* kmalloc_4096;
|
||||||
|
void* kmalloc_8192;
|
||||||
|
void* kmalloc_16384;
|
||||||
|
void* kmalloc_32768;
|
||||||
|
void* kmalloc_65536;
|
||||||
|
void* kmalloc_131072;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#include "types.h"
|
||||||
|
#include <kmalloc.h>
|
||||||
|
#include <string.h>
|
||||||
|
// this file contains SLUB inspired HEAP allocator
|
||||||
|
|
||||||
|
// TODO this will be an allocated array later when we have APIC MADT
|
||||||
|
union per_cpu_freelist_cache freelists_all_cpus[1];
|
||||||
|
|
||||||
|
void* kcalloc(size_t count, size_t size) {
|
||||||
|
size_t size_to_alloc;
|
||||||
|
__asm__ volatile goto(".intel_syntax noprefix\n\t"
|
||||||
|
"mov rax, %1\n\t"
|
||||||
|
"mov rdx, %2\n\t"
|
||||||
|
"mul rdx\n\t"
|
||||||
|
"jo %l[overflow]\n\t"
|
||||||
|
"mov %0, rax\n\t"
|
||||||
|
".att_syntax prefix\n\t"
|
||||||
|
: "=r"(size_to_alloc)
|
||||||
|
: "r"(count), "r"(size)
|
||||||
|
: "rax", "rdx", "cc"
|
||||||
|
: overflow);
|
||||||
|
return kzalloc(size_to_alloc);
|
||||||
|
|
||||||
|
overflow:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* kzalloc(size_t size) {
|
||||||
|
void* allocated = kmalloc(size);
|
||||||
|
if (!allocated) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
memset(allocated, 0, size);
|
||||||
|
return allocated;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* kmalloc(size_t size) {
|
||||||
|
uint32_t core_id;
|
||||||
|
__asm__ volatile(
|
||||||
|
"rdtscp"
|
||||||
|
: "=c"(core_id) // Core ID from IA32_TSC_AUX is placed in ECX
|
||||||
|
:
|
||||||
|
: "eax", "edx");
|
||||||
|
|
||||||
|
// freelists_all_cpus[core_id];
|
||||||
|
// TODO enable when we actualy know how many CPUs we have
|
||||||
|
if () {
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user