forked from PoliEcho-holding-org/kern
Added printing memory map
This commit is contained in:
@@ -9,6 +9,11 @@ char* itoa(uint32_t val, uint8_t base) {
|
|||||||
|
|
||||||
if (base == 0 || base > 16) {
|
if (base == 0 || base > 16) {
|
||||||
// TODO: Add errors!!
|
// TODO: Add errors!!
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val == 0) {
|
||||||
|
buf[0] = '0';
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,18 @@
|
|||||||
|
|
||||||
#define PROMPT "#> "
|
#define PROMPT "#> "
|
||||||
|
|
||||||
|
typedef struct smapEntry_s {
|
||||||
|
uint64_t baseAddress;
|
||||||
|
uint64_t length;
|
||||||
|
uint32_t type;
|
||||||
|
uint32_t acpiAttr;
|
||||||
|
} __attribute__ ((packed)) smapEntry_t;
|
||||||
|
|
||||||
char* filetable = (char*)0x7000; // Pretty sure we don't have to care about the bootloader at 0x7c00
|
char* filetable = (char*)0x7000; // Pretty sure we don't have to care about the bootloader at 0x7c00
|
||||||
|
|
||||||
// Function declarations
|
// Function declarations
|
||||||
void printFiletable(char* ft);
|
void printFiletable(char* ft);
|
||||||
|
void printPhysicalMemmap();
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// Interrupts
|
// Interrupts
|
||||||
@@ -38,6 +46,8 @@ void main() {
|
|||||||
|
|
||||||
diskRead(5, 1, filetable); // Read the filetable and store it in memory
|
diskRead(5, 1, filetable); // Read the filetable and store it in memory
|
||||||
|
|
||||||
|
printPhysicalMemmap();
|
||||||
|
|
||||||
// Run Interactive Shell Program
|
// Run Interactive Shell Program
|
||||||
// TODO: Make it in another file
|
// TODO: Make it in another file
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -282,3 +292,31 @@ void printFiletable(char* ft) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printPhysicalMemmap() {
|
||||||
|
uint32_t entryCount = *(uint32_t*)0x8500;
|
||||||
|
smapEntry_t* smapEntry = (smapEntry_t*)0x8504;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < entryCount; i++) {
|
||||||
|
print("Region ");
|
||||||
|
if (i) print(itoa(i, 10));
|
||||||
|
else print("0");
|
||||||
|
print(": base: 0x");
|
||||||
|
print(itoa(smapEntry->baseAddress, 16));
|
||||||
|
print(" length: 0x");
|
||||||
|
print(itoa(smapEntry->length, 16));
|
||||||
|
print(" type: 0x");
|
||||||
|
print(itoa(smapEntry->type, 16));
|
||||||
|
|
||||||
|
switch (smapEntry->type) {
|
||||||
|
case 1: print(" (Available)"); break;
|
||||||
|
case 2: print(" (Reserved)"); break;
|
||||||
|
case 3: print(" (ACPI Reclaim)"); break;
|
||||||
|
case 4: print(" (ACPI NVS)"); break;
|
||||||
|
default: print(" (Reserved)"); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
putc('\n');
|
||||||
|
smapEntry++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-11
@@ -13,7 +13,7 @@ start:
|
|||||||
|
|
||||||
memMapEntries equ 0x8500
|
memMapEntries equ 0x8500
|
||||||
getMemoryMap:
|
getMemoryMap:
|
||||||
mov di, memMapEntries + 4 ; 4 bytes after memMapEntries
|
mov di, 0x8504 ; 4 bytes after memMapEntries
|
||||||
xor ebx, ebx
|
xor ebx, ebx
|
||||||
xor bp, bp
|
xor bp, bp
|
||||||
mov edx, "PAMS" ; SMAP in little endian
|
mov edx, "PAMS" ; SMAP in little endian
|
||||||
@@ -26,7 +26,13 @@ getMemoryMap:
|
|||||||
cmp eax, "PAMS"
|
cmp eax, "PAMS"
|
||||||
jne .error
|
jne .error
|
||||||
test ebx, ebx
|
test ebx, ebx
|
||||||
jz .error
|
jnz .start
|
||||||
|
|
||||||
|
.error:
|
||||||
|
mov si, acpiFuncErr
|
||||||
|
call print
|
||||||
|
cli
|
||||||
|
hlt
|
||||||
|
|
||||||
.nextEntry:
|
.nextEntry:
|
||||||
mov edx, "PAMS" ; In case BIOS messes with edx
|
mov edx, "PAMS" ; In case BIOS messes with edx
|
||||||
@@ -34,6 +40,7 @@ getMemoryMap:
|
|||||||
mov eax, 0xe820
|
mov eax, 0xe820
|
||||||
int 0x15
|
int 0x15
|
||||||
|
|
||||||
|
.start:
|
||||||
jcxz .skipEntry
|
jcxz .skipEntry
|
||||||
mov ecx, [es:di+8] ; Low 32 bits of length
|
mov ecx, [es:di+8] ; Low 32 bits of length
|
||||||
or ecx, [es:di+12] ; High 32 bits of length
|
or ecx, [es:di+12] ; High 32 bits of length
|
||||||
@@ -48,21 +55,13 @@ getMemoryMap:
|
|||||||
jz .done
|
jz .done
|
||||||
jmp .nextEntry
|
jmp .nextEntry
|
||||||
|
|
||||||
.error:
|
|
||||||
mov si, acpiFuncErr
|
|
||||||
call print
|
|
||||||
cli
|
|
||||||
hlt
|
|
||||||
|
|
||||||
.done:
|
.done:
|
||||||
mov [memMapEntries], bp
|
mov [memMapEntries], bp
|
||||||
clc
|
clc
|
||||||
|
|
||||||
vbeSetup:
|
vbeSetup:
|
||||||
; Setup VBE info
|
; Setup VBE info
|
||||||
xor ax, ax
|
mov ax, 0x4f00
|
||||||
mov es, ax
|
|
||||||
mov ah, 0x4f
|
|
||||||
mov di, vbeInfoBlock
|
mov di, vbeInfoBlock
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user