Adjustments to disk driver

This commit is contained in:
mintsuki 2019-06-01 23:48:33 +02:00
parent fc6c21ec77
commit bbfc5d36af
2 changed files with 20 additions and 44 deletions

View File

@ -1,29 +1,21 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <lib/libc.h> #include <lib/libc.h>
#include <lib/disk.h> #include <drivers/disk.h>
#include <lib/real.h> #include <lib/real.h>
#include <lib/print.h> #include <lib/print.h>
#define DAP_SIZE 16
#define SECTOR_SIZE 512 #define SECTOR_SIZE 512
static uint8_t sector_buf[512];
static struct { static struct {
unsigned short size; uint16_t size;
unsigned short count; uint16_t count;
unsigned short offset; uint16_t offset;
unsigned short segment; uint16_t segment;
unsigned long long lba; uint64_t lba;
} dap = { DAP_SIZE, 0, 0, 0, 0 }; } dap = { 16, 1, 0, 0, 0 };
static unsigned char sector_buf[512];
static inline void setup_dap(int lba, int count, int off, int seg) {
dap.lba = lba;
dap.count = count;
dap.offset = off;
dap.segment = seg;
}
static int check_results(struct rm_regs *out) { static int check_results(struct rm_regs *out) {
int ah = (out->eax >> 8) & 0xFF; int ah = (out->eax >> 8) & 0xFF;
@ -34,9 +26,11 @@ static int check_results(struct rm_regs *out) {
return ah; return ah;
} }
int read_sector(int drive, int lba, int count, unsigned char *buffer) { int read_sector(int drive, int lba, int count, uint8_t *buffer) {
dap.offset = (uint16_t)(size_t)sector_buf;
while (count--) { while (count--) {
setup_dap(lba++, 1, sector_buf, 0); dap.lba = lba++;
struct rm_regs r = {0}; struct rm_regs r = {0};
r.eax = 0x4200; r.eax = 0x4200;
r.edx = drive; r.edx = drive;
@ -52,22 +46,3 @@ int read_sector(int drive, int lba, int count, unsigned char *buffer) {
return 0; return 0;
} }
int write_sector(int drive, int lba, int count, const unsigned char *buffer) {
while (count--) {
memcpy(sector_buf, buffer, SECTOR_SIZE);
setup_dap(lba++, 1, sector_buf, 0);
struct rm_regs r = {0};
r.eax = 0x4300;
r.edx = drive;
r.esi = (unsigned int)&dap;
rm_int(0x13, &r, &r);
if (check_results(&r))
return (r.eax >> 8) & 0xFF;
buffer += SECTOR_SIZE;
}
return 0;
}

View File

@ -1,7 +1,8 @@
#ifndef __DISK_H__ #ifndef __DISK_H__
#define __DISK_H__ #define __DISK_H__
int read_sector(int drive, int lba, int count, unsigned char *buffer); #include <stdint.h>
int write_sector(int drive, int lba, int count, unsigned char *buffer);
int read_sector(int, int, int, uint8_t *);
#endif #endif