2019-06-02 00:34:24 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <lib/libc.h>
|
2019-06-02 00:48:33 +03:00
|
|
|
#include <drivers/disk.h>
|
2019-06-02 00:34:24 +03:00
|
|
|
#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:34:24 +03:00
|
|
|
|
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 };
|
2019-06-02 00:34:24 +03:00
|
|
|
|
|
|
|
static int check_results(struct rm_regs *out) {
|
|
|
|
int ah = (out->eax >> 8) & 0xFF;
|
2019-06-02 00:48:33 +03:00
|
|
|
|
|
|
|
if (ah)
|
2019-06-02 00:34:24 +03:00
|
|
|
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;
|
2019-06-02 00:34:24 +03:00
|
|
|
|
|
|
|
while (count--) {
|
2019-06-02 00:48:33 +03:00
|
|
|
dap.lba = lba++;
|
2019-06-02 00:34:24 +03:00
|
|
|
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))
|
2019-06-02 00:34:24 +03:00
|
|
|
return (r.eax >> 8) & 0xFF;
|
|
|
|
|
|
|
|
memcpy(buffer, sector_buf, SECTOR_SIZE);
|
|
|
|
|
|
|
|
buffer += SECTOR_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|