diff --git a/kernel/hal/x86/blk/BlockDevice.cpp b/kernel/hal/x86/blk/BlockDevice.cpp index cef07da..303891e 100644 --- a/kernel/hal/x86/blk/BlockDevice.cpp +++ b/kernel/hal/x86/blk/BlockDevice.cpp @@ -71,4 +71,22 @@ namespace MTGosHAL { return drivenum; } BlockDevice::~BlockDevice() {}; + auto BlockDevice::readSector(uint8_t drv, uint64_t sectorNum, uint8_t *buf) -> void { + if(!(existent&(1<>1]+DRV, 0x40 | (drv&1)<<4); + outb(ataports[drv>>1]+SECTOR_CNT, 0); + outb(ataports[drv>>1]+LBAlo, (uint8_t)(sectorNum>>24)); + outb(ataports[drv>>1]+LBAmid, (uint8_t)(sectorNum>>32)); + outb(ataports[drv>>1]+LBAhi, (uint8_t)(sectorNum>>40)); + outb(ataports[drv>>1]+SECTOR_CNT, 1); + outb(ataports[drv>>1]+LBAlo, (uint8_t)(sectorNum)); + outb(ataports[drv>>1]+LBAmid, (uint8_t)(sectorNum>>8)); + outb(ataports[drv>>1]+LBAhi, (uint8_t)(sectorNum>>16)); + outb(ataports[drv>>1]+CMD, 0x24); + while(inb(ataports[drv>>1]+CMD)&0x80); + uint16_t *bufw=(uint16_t *)buf; + for(int i=0;i<256;i++) + bufw[i]=inb(ataports[drv>>1]); + } } diff --git a/kernel/hal/x86/include/blockdev.hpp b/kernel/hal/x86/include/blockdev.hpp index 635e0e1..9a2f240 100644 --- a/kernel/hal/x86/include/blockdev.hpp +++ b/kernel/hal/x86/include/blockdev.hpp @@ -11,8 +11,8 @@ namespace MTGosHAL { ~BlockDevice(); auto getDriveCnt() -> uint8_t; auto getDriveNumByName(const char *) -> uint8_t; //Returns -1 if device is not existent - auto readSector(uint32_t drv, uint64_t sectorNum, uint8_t *buf); //Has to be at least 512 bytes big! - auto readSectors(uint32_t drv, uint64_t sectorNum, uint32_t num, uint8_t *buf); //Has to be at least num*512 bytes big! + auto readSector(uint8_t drv, uint64_t sectorNum, uint8_t *buf) -> void; //Has to be at least 512 bytes big! + auto readSectors(uint8_t drv, uint64_t sectorNum, uint32_t num, uint8_t *buf) -> void; //Has to be at least num*512 bytes big! }; }