From 0ba991750314310a5e53b0d8135aef5b1352b261 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 20 Nov 2019 22:17:48 +0100 Subject: Began two-stage hdd bootloader and os installer --- src/kernel/fs/atapi_pio.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/kernel/fs/atapi_pio.c (limited to 'src/kernel/fs/atapi_pio.c') diff --git a/src/kernel/fs/atapi_pio.c b/src/kernel/fs/atapi_pio.c new file mode 100644 index 0000000..4f986d9 --- /dev/null +++ b/src/kernel/fs/atapi_pio.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +void ATAPI_read(uint16_t nblocks, uint32_t lba) { + struct dapack *d = (struct dapack *) ATAPI_PIO_DAPACK; + d->size = 0x10; + d->null = 0x00; + d->blkcount = nblocks; + d->boffset = ATAPI_PIO_BUFFER; + d->bsegment = 0x0000; + d->start = lba; + d->upper_lba_bits = 0x00000000; + + regs16_t regs; + regs.ax = 0x4200; + regs.dx = ATAPI_PIO_DRIVE; + regs.ds = 0; + regs.si = ATAPI_PIO_DAPACK; + + paging_disable(); + int32(LBA_READ_INT, ®s); + paging_enable(); +} + +void ATAPI_granular_read(uint32_t nblocks, uint32_t lba, uint8_t *output) { + for (uint32_t i = 0; i < nblocks; i++) { + ATAPI_read(1, lba + i); + for (uint16_t j = 0; j < ATAPI_SECTOR_SIZE; j++) output[j + (2048 * i)] = ((uint8_t *) ATAPI_PIO_BUFFER)[j]; + } +} \ No newline at end of file -- cgit v1.2.3