[ide] Minor updates

This commit is contained in:
Kevin Lange 2011-12-13 00:48:04 -06:00
parent d7d52555c9
commit 2fdf993af7
4 changed files with 30 additions and 10 deletions

View File

@ -8,7 +8,7 @@
#define BLOCKSIZE 1024
#define SECTORSIZE 512
#define CACHEENTRIES 512
#define CACHEENTRIES 10240
#define DISK_PORT 0x1F0
typedef struct {

View File

@ -28,11 +28,8 @@ void ide_read_sector(uint16_t bus, uint8_t slave, uint32_t lba, uint8_t * buf) {
outportb(bus + ATA_REG_COMMAND, ATA_CMD_READ_PIO);
uint8_t status = 0;
while ((status = inportb(bus + 0x07)) & 0x80);
for (volatile uint32_t i = 0; i < 512; i += 2) {
uint16_t s = inports(bus);
buf[i] = s & 0xFF;
buf[i+1] = (s & 0xFF00) >> 8;
}
int size = 256;
inportsm(bus,buf,size);
IRQ_ON;
}
@ -48,10 +45,8 @@ void ide_write_sector(uint16_t bus, uint8_t slave, uint32_t lba, uint8_t * buf)
outportb(bus + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO);
uint8_t status = 0;
while ((status = inportb(bus + 0x07)) & 0x80);
for (volatile uint32_t i = 0; i < 512; i+=2) {
uint16_t s = (buf[i+1] << 8) + (buf[i]);
outports(bus, s);
}
int size = 256;
outportsm(bus,buf,size);
outportb(bus + 0x07, ATA_CMD_CACHE_FLUSH);
IRQ_ON;
}

View File

@ -232,6 +232,29 @@ outportb(
asm volatile ("outb %1, %0" : : "dN" (_port), "a" (_data));
}
/*
* Output multiple sets of shorts
*/
void outportsm(
unsigned short port,
unsigned char * data,
unsigned long size
) {
asm volatile ("rep outsw" : "+S" (data), "+c" (size) : "d" (port));
}
/*
* Input multiple sets of shorts
*/
void inportsm(
unsigned short port,
unsigned char * data,
unsigned long size
) {
asm volatile ("rep insw" : "+D" (data), "+c" (size) : "d" (port) : "memory");
}
char *
strtok_r(
char * str,

View File

@ -46,6 +46,8 @@ extern unsigned short inports(unsigned short _port);
extern void outports(unsigned short _port, unsigned short _data);
extern unsigned int inportl(unsigned short _port);
extern void outportl(unsigned short _port, unsigned int _data);
extern void outportsm(unsigned short port, unsigned char * data, unsigned long size);
extern void inportsm(unsigned short port, unsigned char * data, unsigned long size);
extern int strcmp(const char *a, const char *b);
extern char * strtok_r(char * str, const char * delim, char ** saveptr);
extern size_t lfind(const char * str, const char accept);