2021-12-23 16:43:25 +00:00
|
|
|
#pragma once
|
2023-02-21 13:36:20 +00:00
|
|
|
#include <stdint-gcc.h>
|
2021-12-23 16:43:25 +00:00
|
|
|
#include "PartitionTableEntry.h"
|
2023-02-21 20:43:14 +00:00
|
|
|
#include "../../../memory/KernelHeap.h"
|
|
|
|
#include "../../ata pio/ATAPIO.h"
|
2021-12-23 16:43:25 +00:00
|
|
|
|
|
|
|
struct MBR {
|
|
|
|
uint8_t code [440];
|
|
|
|
uint32_t uniqueID;
|
|
|
|
uint16_t Reserved;
|
2023-02-21 20:43:14 +00:00
|
|
|
struct PartitionTableEntry TableEntries[4];
|
2021-12-23 16:43:25 +00:00
|
|
|
uint16_t ValidBootsector;
|
2023-02-21 13:36:20 +00:00
|
|
|
}__attribute__((packed));
|
|
|
|
|
|
|
|
|
2023-02-21 20:43:14 +00:00
|
|
|
inline MBR* GetPartitions(bool DEBUG = false){
|
2023-02-21 13:36:20 +00:00
|
|
|
const int C = 0;
|
|
|
|
const int H = 0;
|
|
|
|
const int HPC = 16;
|
|
|
|
const int SPT = 63;
|
|
|
|
|
|
|
|
int S =1;
|
|
|
|
uint32_t LBA = (C*HPC+H) * SPT + (S-1);
|
2023-02-21 20:43:14 +00:00
|
|
|
|
2023-10-27 16:07:11 +00:00
|
|
|
uint16_t* mbr =(uint16_t*) malloc(sizeof (MBR));
|
2023-02-21 13:36:20 +00:00
|
|
|
|
2023-10-27 16:07:11 +00:00
|
|
|
ATAPIO::Read(ATAPIO_PORT::Primary, DEVICE_DRIVE::MASTER, LBA, mbr );
|
|
|
|
auto bootRecord = (MBR*)(mbr);
|
2023-02-21 20:43:14 +00:00
|
|
|
|
2023-10-27 16:07:11 +00:00
|
|
|
printf("MBR (In Memory) Address 0x%x, Size = %d\n", bootRecord, sizeof (MBR));
|
2023-02-21 13:36:20 +00:00
|
|
|
if(DEBUG){
|
2023-10-27 16:07:11 +00:00
|
|
|
printf("BootSector: 0x%x\n", bootRecord->ValidBootsector );
|
2023-02-21 13:36:20 +00:00
|
|
|
for( int i = 0 ; i < 4 ; i ++){
|
2023-10-27 16:07:11 +00:00
|
|
|
PartitionTableEntry PT = bootRecord->TableEntries[i];
|
2023-02-21 13:36:20 +00:00
|
|
|
|
|
|
|
printf("Partition %d [ %d sectors, PartitionType: 0x%x, 0x%x, \nLBA Start: 0x%x ]\n" ,
|
2023-10-27 16:07:11 +00:00
|
|
|
i, PT.Number_sectors_inPartition, PT.PartitionType, bootRecord->uniqueID, PT.LBA_partition_start );
|
2023-02-21 13:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-10-27 16:07:11 +00:00
|
|
|
return bootRecord;
|
2023-02-21 13:36:20 +00:00
|
|
|
}
|