Initial commit
This commit is contained in:
88
kernel/mem/mem.c
Normal file
88
kernel/mem/mem.c
Normal file
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// Created by rick on 22-04-20.
|
||||
//
|
||||
|
||||
#include <types.h>
|
||||
#include <kprint.h>
|
||||
#include <mem/mem.h>
|
||||
#include <libc/libc.h>
|
||||
|
||||
char *msg_index = "Idx: ";
|
||||
char *msg_addr = "Address: ";
|
||||
char *msg_len = "Length: ";
|
||||
char *msg_type = "Type: ";
|
||||
char *msg_nl = "\n";
|
||||
|
||||
typedef struct {
|
||||
u64 address;
|
||||
u64 length;
|
||||
#define MMAP_TYPE_UNDEFINED 0
|
||||
#define MMAP_TYPE_AVAILABLE 1
|
||||
#define MMAP_TYPE_RESERVED 2
|
||||
#define MMAP_TYPE_ACPI_RECLAIMABLE 3
|
||||
#define MMAP_TYPE_NVS 4
|
||||
#define MMAP_TYPE_BADRAM 5
|
||||
u32 type;
|
||||
} __attribute((packed)) mmap_entry;
|
||||
|
||||
char *msg_lu = "0123456789ABCDEF";
|
||||
|
||||
mmap_entry memmap[16] = {
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
{0, 0, 0},
|
||||
};
|
||||
|
||||
void init_mmap(struct multiboot_mmap_entry *entries, u32 count) {
|
||||
for (u32 i = 0; i < count; ++i) {
|
||||
memmap[i].address = entries[i].addr;
|
||||
memmap[i].length = entries[i].len;
|
||||
memmap[i].type = entries[i].type;
|
||||
}
|
||||
}
|
||||
|
||||
void print_hex_u64(u64 input) {
|
||||
char msg[18] = "0x0000000000000000";
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
int val = input >> (4 * i) & 0xF;
|
||||
msg[17 - i] = msg_lu[val];
|
||||
}
|
||||
kprint(msg);
|
||||
}
|
||||
|
||||
void print_mmap_info() {
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
if (memmap[i].type == 0) {
|
||||
break;
|
||||
}
|
||||
char *tmp_str = " ";
|
||||
kprint(msg_index);
|
||||
itoa(i, tmp_str);
|
||||
kprint(tmp_str);
|
||||
kprint(msg_nl);
|
||||
kprint(msg_addr);
|
||||
print_hex_u64(memmap[i].address);
|
||||
kprint(msg_nl);
|
||||
kprint(msg_len);
|
||||
print_hex_u64(memmap[i].length);
|
||||
kprint(msg_nl);
|
||||
kprint(msg_type);
|
||||
itoa(memmap[i].type, tmp_str);
|
||||
kprint(tmp_str);
|
||||
kprint(msg_nl);
|
||||
kprint(msg_nl);
|
||||
}
|
||||
}
|
||||
14
kernel/mem/mem.h
Normal file
14
kernel/mem/mem.h
Normal file
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by rick on 22-04-20.
|
||||
//
|
||||
|
||||
#ifndef NEW_KERNEL_MEM_H
|
||||
#define NEW_KERNEL_MEM_H
|
||||
|
||||
#include <multiboot.h>
|
||||
|
||||
void init_mmap(struct multiboot_mmap_entry *entries, u32 count);
|
||||
|
||||
void print_mmap_info();
|
||||
|
||||
#endif //NEW_KERNEL_MEM_H
|
||||
Reference in New Issue
Block a user