feature (GPT): implemented basic GPT decoding
This commit is contained in:
parent
b8cafaf24d
commit
c9d57639c1
|
@ -231,6 +231,8 @@ ahci_controller_T* ahci_controller_alloc (pci_device_T* pci_device);
|
||||||
void ahci_controller_destruct (ahci_controller_T* controller);
|
void ahci_controller_destruct (ahci_controller_T* controller);
|
||||||
|
|
||||||
void ahci_port_init (ahci_port_T* port);
|
void ahci_port_init (ahci_port_T* port);
|
||||||
|
void ahci_port_init_partitions_mbr (ahci_port_T* port);
|
||||||
|
void ahci_port_init_partitions_gpt (ahci_port_T* port);
|
||||||
void ahci_port_destruct (ahci_port_T* port);
|
void ahci_port_destruct (ahci_port_T* port);
|
||||||
ahci_device_type_E ahci_port_get_type (ahci_hba_port_T* port);
|
ahci_device_type_E ahci_port_get_type (ahci_hba_port_T* port);
|
||||||
void ahci_port_command_stop (ahci_port_T* port);
|
void ahci_port_command_stop (ahci_port_T* port);
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
// This file is part of noxos and licensed under the MIT open source license
|
||||||
|
|
||||||
|
#ifndef NOXOS_GPT_H
|
||||||
|
#define NOXOS_GPT_H
|
||||||
|
|
||||||
|
#include "utils/stdtypes.h"
|
||||||
|
|
||||||
|
#define GPT_PARTITION_TYPE_GUID_MATCH(g, t) ((g[0] == g_gpt_partition_type_guides[t][0]) && (g[1] == g_gpt_partition_type_guides[t][1]))
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
GPT_PARTITION_GUID_UNUSED,
|
||||||
|
GPT_PARTITION_GUID_BASIC_DATA,
|
||||||
|
GPT_PARTITION_GUID_EFI_SYSTEM,
|
||||||
|
|
||||||
|
GPT_PARTITION_GUID_ENUM_END
|
||||||
|
} gpt_partition_type_guids_E;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t signature [8];
|
||||||
|
uint32_t revision;
|
||||||
|
uint32_t header_size;
|
||||||
|
uint32_t checksum_crc32;
|
||||||
|
uint32_t reserved;
|
||||||
|
uint64_t current_lba;
|
||||||
|
uint64_t backup_lba;
|
||||||
|
uint64_t first_usable_lba;
|
||||||
|
uint64_t last_usable_lba;
|
||||||
|
uint64_t disk_guid [2];
|
||||||
|
uint64_t starting_lba;
|
||||||
|
uint32_t num_partitions;
|
||||||
|
uint32_t partition_entry_size;
|
||||||
|
uint32_t partition_entry_crc32;
|
||||||
|
uint8_t reserved2 [0x1A4];
|
||||||
|
}__attribute__((packed)) gpt_table_header_T;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint64_t partition_type_guid [2];
|
||||||
|
uint64_t partition_guid [2];
|
||||||
|
uint64_t starting_lba;
|
||||||
|
uint64_t ending_lba;
|
||||||
|
uint64_t attributes;
|
||||||
|
uint8_t name [72];
|
||||||
|
}__attribute__((packed)) gpt_partition_entry_T;
|
||||||
|
|
||||||
|
extern uint64_t g_gpt_partition_type_guides[GPT_PARTITION_GUID_ENUM_END][2];
|
||||||
|
|
||||||
|
#endif //NOXOS_GPT_H
|
|
@ -1,7 +1,7 @@
|
||||||
// This file is part of noxos and licensed under the MIT open source license
|
// This file is part of noxos and licensed under the MIT open source license
|
||||||
|
|
||||||
#ifndef KERNEL_MBR_H
|
#ifndef NOXOS_MBR_H
|
||||||
#define KERNEL_MBR_H
|
#define NOXOS_MBR_H
|
||||||
|
|
||||||
#include "utils/stdtypes.h"
|
#include "utils/stdtypes.h"
|
||||||
#include "utils/string.h"
|
#include "utils/string.h"
|
||||||
|
@ -37,4 +37,4 @@ typedef struct {
|
||||||
|
|
||||||
string_t mbr_partition_type_to_string(mbr_partition_types_E type);
|
string_t mbr_partition_type_to_string(mbr_partition_types_E type);
|
||||||
|
|
||||||
#endif //KERNEL_MBR_H
|
#endif //NOXOS_MBR_H
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "drivers/ahci.h"
|
#include "drivers/ahci.h"
|
||||||
#include "drivers/fs/mbr.h"
|
#include "drivers/fs/mbr.h"
|
||||||
|
#include "drivers/fs/gpt.h"
|
||||||
#include "utils/memory.h"
|
#include "utils/memory.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include "mm/page_map.h"
|
#include "mm/page_map.h"
|
||||||
|
@ -51,22 +52,6 @@ ahci_controller_T* ahci_controller_alloc(pci_device_T* pci_device) {
|
||||||
for (int i = 0; i < controller->num_ports; i++) {
|
for (int i = 0; i < controller->num_ports; i++) {
|
||||||
log(LOG_INFO, " %s", g_ahci_device_type_strings[controller->ports[i].type]);
|
log(LOG_INFO, " %s", g_ahci_device_type_strings[controller->ports[i].type]);
|
||||||
ahci_port_init(&controller->ports[i]);
|
ahci_port_init(&controller->ports[i]);
|
||||||
|
|
||||||
uint8_t* addr = memory_allocate(512 + PFRAME_SIZE);
|
|
||||||
void* buffer = (void*)CEIL_TO((uint64_t)addr, PFRAME_SIZE);
|
|
||||||
|
|
||||||
if (ahci_port_read(&controller->ports[i], 0, 1, buffer)) {
|
|
||||||
mbr_header_T* mbr = (mbr_header_T*)buffer;
|
|
||||||
|
|
||||||
log(LOG_INFO, " MBR:");
|
|
||||||
for (int j = 0; j < 4; j++) {
|
|
||||||
mbr_partition_types_E type = mbr->partitions[j].partition_type;
|
|
||||||
if (type == MBR_PARTITION_TYPE_UNUSED) continue;
|
|
||||||
log(LOG_INFO, " p%d: 0x%xb - %s", j, type, mbr_partition_type_to_string(type));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
memory_free(addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return controller;
|
return controller;
|
||||||
|
@ -108,6 +93,61 @@ void ahci_port_init(ahci_port_T* port) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ahci_port_command_start(port);
|
ahci_port_command_start(port);
|
||||||
|
|
||||||
|
ahci_port_init_partitions_mbr(port);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ahci_port_init_partitions_mbr(ahci_port_T* port) {
|
||||||
|
uint8_t* addr = memory_allocate(512 + PFRAME_SIZE);
|
||||||
|
void* buffer = (void*)CEIL_TO((uint64_t)addr, PFRAME_SIZE);
|
||||||
|
|
||||||
|
if (ahci_port_read(port, 0, 1, buffer)) {
|
||||||
|
mbr_header_T* mbr = (mbr_header_T*)buffer;
|
||||||
|
|
||||||
|
log(LOG_INFO, " MBR:");
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
mbr_partition_types_E type = mbr->partitions[i].partition_type;
|
||||||
|
if (type == MBR_PARTITION_TYPE_UNUSED) continue;
|
||||||
|
|
||||||
|
log(LOG_INFO, " p%d: 0x%xb - %d - %s", i, type, mbr->partitions[i].start_lba, mbr_partition_type_to_string(type));
|
||||||
|
|
||||||
|
if (type == MBR_PARTITION_TYPE_GPT) {
|
||||||
|
ahci_port_init_partitions_gpt(port);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memory_free(addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ahci_port_init_partitions_gpt(ahci_port_T* port) {
|
||||||
|
uint8_t* addr_header = memory_allocate(512 + PFRAME_SIZE);
|
||||||
|
void* buffer_header = (void*)CEIL_TO((uint64_t)addr_header, PFRAME_SIZE);
|
||||||
|
|
||||||
|
if (ahci_port_read(port, 1, 1, buffer_header)) {
|
||||||
|
gpt_table_header_T* gpt = (gpt_table_header_T*)buffer_header;
|
||||||
|
|
||||||
|
uint32_t num_sectors = CEIL_TO(gpt->num_partitions, 4) / 4;
|
||||||
|
|
||||||
|
uint8_t* addr_entries = memory_allocate((512 * num_sectors) + PFRAME_SIZE);
|
||||||
|
void* buffer_entries = (void*)CEIL_TO((uint64_t)addr_entries, PFRAME_SIZE);
|
||||||
|
|
||||||
|
if (ahci_port_read(port, 2, num_sectors, buffer_entries)) {
|
||||||
|
gpt_partition_entry_T* entries = (gpt_partition_entry_T*)buffer_entries;
|
||||||
|
|
||||||
|
log(LOG_INFO, " GPT:");
|
||||||
|
for (int i = 0; i < gpt->num_partitions; i++) {
|
||||||
|
gpt_partition_entry_T* entry = &entries[i];
|
||||||
|
if (GPT_PARTITION_TYPE_GUID_MATCH(entry->partition_type_guid, GPT_PARTITION_GUID_UNUSED)) continue;
|
||||||
|
log(LOG_INFO, " p%d: %x%x", i, entry->partition_type_guid[0], entry->partition_type_guid[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memory_free(addr_entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
memory_free(addr_header);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ahci_port_destruct(ahci_port_T* port) {
|
void ahci_port_destruct(ahci_port_T* port) {
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
// This file is part of noxos and licensed under the MIT open source license
|
||||||
|
|
||||||
|
#include "drivers/fs/gpt.h"
|
||||||
|
|
||||||
|
uint64_t g_gpt_partition_type_guides[GPT_PARTITION_GUID_ENUM_END][2] = {
|
||||||
|
{0x0000000000000000, 0x0000000000000000},
|
||||||
|
{0x11D2F81FC12A7328, 0x3BC93EC9A0004BBA},
|
||||||
|
{0x28732AC11FF8D211, 0xBA4B00A0C93EC93B}
|
||||||
|
};
|
Loading…
Reference in New Issue