Compare commits
2 Commits
2621399349
...
fb2a19e11d
Author | SHA1 | Date | |
---|---|---|---|
fb2a19e11d | |||
72008b0a7a |
46
src/kernel/drivers/rsdp/rsdp.cpp
Normal file
46
src/kernel/drivers/rsdp/rsdp.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "rsdp.h"
|
||||
|
||||
void printRSD(RSDPTR* rsd){
|
||||
printf("Signature: ");
|
||||
for(int i = 0; i < 8; i++){
|
||||
kterm_put(rsd->signature[i]);
|
||||
}
|
||||
kterm_put('\n');
|
||||
|
||||
printf("OEMID: ");
|
||||
for(int i =0; i < 6 ; i++){
|
||||
kterm_put (rsd->OEMID[i]);
|
||||
}
|
||||
kterm_put('\n');
|
||||
|
||||
printf("Revision: %d\n", rsd->Revision);
|
||||
printf("RSDT Address: 0x%x\n", rsd->RsdtAddress );
|
||||
}
|
||||
|
||||
RSDPTR* FindRSD(){
|
||||
char* memory_byte = (char*) 0x000f2e14;
|
||||
const void* string = "RSD PTR ";
|
||||
|
||||
for( ; (uint32_t) memory_byte < 0x0100000; memory_byte+=10){
|
||||
if( memcmp(memory_byte , string , 8 ) == 0 ) {
|
||||
printf("RSD PTR found at 0x%x !\n", memory_byte);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printRSD((RSDPTR*) memory_byte);
|
||||
return (RSDPTR*) memory_byte;
|
||||
}
|
||||
|
||||
|
||||
RSDT* getRSDT(RSDPTR* rsd){
|
||||
|
||||
RSDT* rsdt = (RSDT*) rsd->RsdtAddress;
|
||||
|
||||
printf("OEMID: ");
|
||||
for(int i = 0; i < 6; i++){
|
||||
kterm_put(rsdt->header.OEMID[i]);
|
||||
}
|
||||
kterm_put('\n');
|
||||
return rsdt;
|
||||
}
|
36
src/kernel/drivers/rsdp/rsdp.h
Normal file
36
src/kernel/drivers/rsdp/rsdp.h
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "./../../tty/kterm.h"
|
||||
#include "../../../libc/include/mem.h"
|
||||
struct RSDPTR {
|
||||
char signature[8];
|
||||
uint8_t Checksum ;
|
||||
char OEMID [6];
|
||||
uint8_t Revision;
|
||||
uint32_t RsdtAddress;
|
||||
}__attribute__((packed));
|
||||
|
||||
struct ACPISDTHeader{
|
||||
char Signature[4];
|
||||
uint32_t Length;
|
||||
uint8_t CheckSum;
|
||||
char OEMID[6];
|
||||
char OEMTableID[8];
|
||||
uint32_t OEMRevision;
|
||||
uint32_t CreatorID;
|
||||
uint32_t CreatorRevision;
|
||||
}__attribute__((packed));
|
||||
|
||||
|
||||
struct RSDT{
|
||||
struct ACPISDTHeader header;
|
||||
uint32_t PointerToSDT[]; // Length of array : (header.Length - sizeof(header))/ 4
|
||||
}__attribute__((packed));
|
||||
|
||||
|
||||
//NOTE: only scans EBDA enough to find RSD PTR in QEMU
|
||||
RSDPTR* FindRSD();
|
||||
|
||||
void printRSD(RSDPTR* rsd);
|
||||
|
||||
RSDT* getRSDT(RSDPTR* rsd);
|
21
src/kernel/filesytems/FAT32/BiosParameterBlock.h
Normal file
21
src/kernel/filesytems/FAT32/BiosParameterBlock.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "./ExtendBootRecord.h"
|
||||
|
||||
struct BiosParameterBlock {
|
||||
uint8_t BootLoaderCodeSection [3];
|
||||
uint8_t OEM_id [8];
|
||||
uint16_t BytesPerSector ; // I suspect would be 512
|
||||
uint8_t SectorsPerCluster ;
|
||||
uint16_t ReservedSectors;
|
||||
uint8_t NumberOfFileAllocationTables; // Probably equals 2
|
||||
uint16_t NumberOfDirectoryEntries; // Root directory must contain entire sectors
|
||||
uint16_t TotalSectorsInLogicalVolume ; // 0 means >65535 sectors in volume , actual count can be found in LargeSectorCount
|
||||
uint8_t MediaDescriptor ; // Indication the media descriptor type
|
||||
uint16_t NumberOfSectorsPerFAT;// only in FAT12 / FAT 16
|
||||
uint16_t NumberOfSectorsPerTrack;
|
||||
uint16_t NumberOfHeadsOnMedia;
|
||||
uint32_t NumberOfHiddenSectors;
|
||||
uint32_t LargeSectorCount;
|
||||
ExtendedBootRecord_FAT16 ebpb;
|
||||
}__attribute__((packed));
|
32
src/kernel/filesytems/FAT32/ExtendBootRecord.h
Normal file
32
src/kernel/filesytems/FAT32/ExtendBootRecord.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
struct ExtendedBootRecord_FAT16{
|
||||
uint8_t DriveNumber;
|
||||
uint8_t Reserved;
|
||||
uint8_t Signature;
|
||||
const uint32_t VOLUME_ID_SERIAL_NUMBER;
|
||||
uint8_t volume_label [11];
|
||||
uint8_t Identifier_string [8];
|
||||
uint8_t bootCode [448];
|
||||
uint16_t partitionSignature;
|
||||
}__attribute__((packed));
|
||||
|
||||
struct ExtendedBootRecord_FAT32{
|
||||
uint32_t SectorsPerFAT;
|
||||
uint16_t Flags;
|
||||
const uint16_t FAT_VERSION_NUMBER;
|
||||
uint32_t rootDirectory_clusterNumber;// Often set to 2;
|
||||
uint16_t FSInfo_SectorNumber;
|
||||
uint16_t backup_bpb_sectorNumber;
|
||||
uint8_t Reserved [12];
|
||||
uint8_t DriveNumber;
|
||||
uint8_t Reserved2;
|
||||
uint8_t Signature; // must be 0x28 or 0x29
|
||||
uint32_t VOLUME_ID_SERIAL;
|
||||
uint8_t volume_label[11];
|
||||
uint8_t SystemIdentifierString [8]; // ALWAYS "FAT32 " but spec says do not trust
|
||||
uint8_t BootCode [420]; // NICE
|
||||
uint16_t PartitionSignature; // 0xAA55
|
||||
|
||||
}__attribute__((packed));
|
@ -44,40 +44,84 @@ extern "C" void kernel_main (void);
|
||||
init_serial();
|
||||
print_serial("Serial port initialized!");
|
||||
|
||||
|
||||
RSDPTR* rsd = FindRSD();
|
||||
RSDT* rsd_table = getRSDT(rsd);
|
||||
|
||||
|
||||
// Enumerate the PCI bus
|
||||
PCI_Enumerate();
|
||||
|
||||
|
||||
|
||||
TestIDEController();
|
||||
TestIDEController();
|
||||
|
||||
int devNumber = 0 ;
|
||||
for ( auto device : ide_devices){
|
||||
if (!device.Reserved)
|
||||
continue;
|
||||
|
||||
|
||||
printf("Device %d\n" , devNumber);
|
||||
printf (" Device on Channel: (0x%x) %s\n" ,device.Channel, device.Channel == 0 ? "Primary" : "Secondary");
|
||||
printf (" Device drive:(0x%x) %s\n" , device.Drive, device.Drive? "Slave" : "Master");
|
||||
printf (" Device Type:(0x%x) %s\n" , device.Type, device.Type ? "ATAPI" : "ATA");
|
||||
devNumber ++;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// ATAPI_DEVICE::isPacketDevice();
|
||||
|
||||
|
||||
enum BUS_PORT {
|
||||
Primary= 0x1f0,
|
||||
Secondary = 0x170
|
||||
};
|
||||
|
||||
|
||||
ATAPI_DEVICE::Identify(ATA_SECONDARY, DEVICE_DRIVE::MASTER);
|
||||
|
||||
ATA_DEVICE::Identify((uint16_t) BUS_PORT::Primary, DEVICE_DRIVE::MASTER);
|
||||
|
||||
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);
|
||||
printf("LBA: %d\n" , LBA);
|
||||
uint16_t buffer [256];
|
||||
|
||||
|
||||
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, LBA, buffer);
|
||||
|
||||
MBR* mbr = (MBR*) buffer;
|
||||
|
||||
printf("BootSector: 0x%x\n", mbr->ValidBootsector );
|
||||
for( int i = 0 ; i < 4 ; i ++){
|
||||
PartitionTableEntry PT = mbr->TableEntries[i];
|
||||
|
||||
printf("Partition %d [ %d sectors, PartitionType: %x, 0x%x, \nLBA Start: 0x%x ]\n" ,
|
||||
i, PT.Number_sectors_inPartition, PT.PartitionType, mbr->uniqueID, PT.LBA_partition_start );
|
||||
}
|
||||
|
||||
// Find the super block
|
||||
uint16_t superBlock[256];
|
||||
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, mbr->TableEntries[0].LBA_partition_start, superBlock);
|
||||
|
||||
BiosParameterBlock* bpb = (BiosParameterBlock*) superBlock;
|
||||
|
||||
|
||||
printf("\nBPB: Bytes per Sector %d\n", bpb->BytesPerSector );
|
||||
printf("OEM ID: %s\n", bpb->OEM_id);
|
||||
printf("Bytes per sector: %d\n", bpb->BytesPerSector);
|
||||
printf("Sectors per cluster: %d\n", bpb->SectorsPerCluster);
|
||||
printf("Reserved sectors: %d\n", bpb->ReservedSectors);
|
||||
printf("Number of FAT: %d\n", bpb->NumberOfFileAllocationTables);
|
||||
printf("Number of Dir entries: %d\n", bpb->NumberOfDirectoryEntries);
|
||||
printf("Total Sectors in volume: %d\n", bpb->TotalSectorsInLogicalVolume);
|
||||
printf("Sectors per FAT: %d\n", bpb->NumberOfSectorsPerFAT);
|
||||
|
||||
uint32_t PartitionAddress = mbr->TableEntries[0].LBA_partition_start *512 ;
|
||||
uint32_t RootDirAddress = PartitionAddress + ((bpb->ReservedSectors + bpb->NumberOfSectorsPerFAT * bpb->NumberOfFileAllocationTables ) * bpb->BytesPerSector);
|
||||
uint32_t RootDirLBA =RootDirAddress/512;
|
||||
|
||||
|
||||
|
||||
uint16_t RootDir [16];
|
||||
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER,RootDirLBA, (uint16_t*) RootDir );
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -20,8 +20,12 @@ extern "C"{
|
||||
#include "serial.h"
|
||||
#include "pci.h"
|
||||
#include "ide/ide.h"
|
||||
#include "drivers/atapi/atapiDevice.h"
|
||||
|
||||
//#include "drivers/atapi/atapiDevice.h"
|
||||
#include "drivers/ata/ataDevice.h"
|
||||
#include "./PartitionTable/MBR/MasterBootRecord.h"
|
||||
#include "./filesytems/FAT32/BiosParameterBlock.h"
|
||||
#include "./filesytems/FAT32/ExtendBootRecord.h"
|
||||
#include "./drivers/rsdp/rsdp.h"
|
||||
|
||||
|
||||
#define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user