limine/drivers/disk.c

49 lines
974 B
C
Raw Normal View History

#include <stdint.h>
#include <stddef.h>
#include <lib/libc.h>
2019-06-02 00:48:33 +03:00
#include <drivers/disk.h>
#include <lib/real.h>
#include <lib/print.h>
#define SECTOR_SIZE 512
2019-06-02 00:48:33 +03:00
static uint8_t sector_buf[512];
2019-06-02 00:48:33 +03:00
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;
2019-06-02 00:48:33 +03:00
if (ah)
print("Disk error %x\n", ah);
return ah;
2019-06-02 00:48:33 +03:00
}
int read_sector(int drive, int lba, int count, uint8_t *buffer) {
dap.offset = (uint16_t)(size_t)sector_buf;
while (count--) {
2019-06-02 00:48:33 +03:00
dap.lba = lba++;
struct rm_regs r = {0};
r.eax = 0x4200;
r.edx = drive;
r.esi = (unsigned int)&dap;
rm_int(0x13, &r, &r);
2019-06-02 00:48:33 +03:00
if (check_results(&r))
return (r.eax >> 8) & 0xFF;
memcpy(buffer, sector_buf, SECTOR_SIZE);
buffer += SECTOR_SIZE;
}
return 0;
}