limine/drivers/disk.c
2019-06-01 23:48:33 +02:00

49 lines
974 B
C

#include <stdint.h>
#include <stddef.h>
#include <lib/libc.h>
#include <drivers/disk.h>
#include <lib/real.h>
#include <lib/print.h>
#define SECTOR_SIZE 512
static uint8_t sector_buf[512];
static struct {
uint16_t size;
uint16_t count;
uint16_t offset;
uint16_t segment;
uint64_t lba;
} dap = { 16, 1, 0, 0, 0 };
static int check_results(struct rm_regs *out) {
int ah = (out->eax >> 8) & 0xFF;
if (ah)
print("Disk error %x\n", ah);
return ah;
}
int read_sector(int drive, int lba, int count, uint8_t *buffer) {
dap.offset = (uint16_t)(size_t)sector_buf;
while (count--) {
dap.lba = lba++;
struct rm_regs r = {0};
r.eax = 0x4200;
r.edx = drive;
r.esi = (unsigned int)&dap;
rm_int(0x13, &r, &r);
if (check_results(&r))
return (r.eax >> 8) & 0xFF;
memcpy(buffer, sector_buf, SECTOR_SIZE);
buffer += SECTOR_SIZE;
}
return 0;
}