I'm not sure what's the problem but when I call the function with:
Code: Select all
ide_initialization(0x1F0,0x170,unused_ch,unused_ch);
ide_write((word *)3,1,1,1);
printk("%x\n",ide_read(1,1,1));
Thanks.
Another question: how i can debug my os?
PS: Sorry if my english isn't good, i'm chilean and i learn english yet. Thanks.
All code of the file ata.c:
Code: Select all
//Define los dispositivos maestros y esclavos, suponiendo su uso
//con el metodo de acceso LBA
#define MASTER 0x00
#define SLAVE 0x01
#define READ_SECTORS 0x20
#define WRITE_SECTORS 0x30
#define STATUS 0x0C
#define BSY 0x80
#define unused_ch 0
struct ide_device {
byte Reserved; //0 = Instalado 1 = No Instalado
byte Channel;
byte Drive; //Indica si es maestro o esclavo
} ide_devices[4];
byte ide_polling(byte ch)
{
int i;
for(i = 0; i < 5; i++)
inb(ide_devices[ch].Channel + STATUS - 0x0A);
while (inb(ide_devices[ch].Channel + 0x07) >> 7);
}
//Por defecto, el canal 1 es 0x1F0 y el 2 es 0x170
//Los canales 3 y 4 generalmente no estan presentes, pero cuando estan,
//por lo general el 3 es 0x1E8 y el 4 es 0x168
void ide_initialization(word d1, word d2, word d3, word d4)
{
int device_n = 0;
if(d1!=unused_ch) {
ide_devices[1].Reserved = 1;
ide_devices[1].Channel = d1;
ide_devices[1].Drive = MASTER;
device_n++;
ide_devices[2].Reserved = 1;
ide_devices[2].Channel = d2;
ide_devices[2].Drive = SLAVE;
device_n++;
} else if(d2==unused_ch) {
ide_devices[1].Reserved = 0;
ide_devices[2].Reserved = 0;
}
if(d2!=unused_ch) {
ide_devices[3].Reserved = 1;
ide_devices[3].Channel = d2;
ide_devices[3].Drive = MASTER;
device_n++;
ide_devices[4].Reserved = 1;
ide_devices[4].Channel = d2;
ide_devices[4].Drive = SLAVE;
device_n++;
} else if(d3==unused_ch) {
ide_devices[3].Reserved = 0;
ide_devices[4].Reserved = 0;
}
printk("Se han inicializado %i dispositivos",device_n);
}
//En el argumento 'device' son validos los numeros 1, 2, 3 y 4.
//Cero provocara un error.
//LBA no debe superar 0xFFFFFFF debido a que estamos utilizando LBA 28
//el cual utiliza valores de hasta 28 bits.
word *ide_read(int device, word LBA, byte count)
{
byte slavebit;
word *buffer;
if(device!=0) {
if(ide_devices[device].Reserved!=0) {
if((ide_devices[device].Channel+6)==MASTER) slavebit = 0;
else if((ide_devices[device].Channel+6)==SLAVE) slavebit = 1;
LBA = 0xFFFFFFF & LBA;
outb((0xE0 | slavebit << 4) | ((LBA >> 24) & 0x0F),ide_devices[device].Channel+6);
outb(0x00,ide_devices[device].Channel+1);
outb(count,ide_devices[device].Channel+2);
outb((byte)LBA,ide_devices[device].Channel+3);
outb((byte)(LBA >> 8),ide_devices[device].Channel+4);
outb((byte)(LBA >> 16),ide_devices[device].Channel+5);
outb(READ_SECTORS,ide_devices[device].Channel+7);
ide_polling(ide_devices[device].Channel);
buffer=insw(ide_devices[device].Channel,count);
ide_polling(ide_devices[device].Channel);
return buffer;
} else if(ide_devices[device].Reserved==0) {
printk("Error: El dispositivo %i no ha sido inicializado y es probable que no este conectado\n",device);
}
} else if(device==0) printk("Error: El dispositivo 0 es NULL\n");
}
int ide_write(word *data, int device, word LBA, byte count)
{
byte slavebit;
byte n;
if(device!=0) {
if(ide_devices[device].Reserved!=0) {
if((ide_devices[device].Channel+6)==MASTER) slavebit = 0;
else if((ide_devices[device].Channel+6)==SLAVE) slavebit = 1;
LBA = 0xFFFFFFF & LBA;
outb((0xE0 | slavebit << 4) | ((LBA >> 24) & 0x0F),ide_devices[device].Channel+6);
outb(0x00,ide_devices[device].Channel+1);
outb(count,ide_devices[device].Channel+2);
outb((byte)LBA,ide_devices[device].Channel+3);
outb((byte)(LBA >> 8),ide_devices[device].Channel+4);
outb((byte)(LBA >> 16),ide_devices[device].Channel+5);
outb(WRITE_SECTORS,ide_devices[device].Channel+7);
ide_polling(ide_devices[device].Channel);
while(n!=count) {
outw(*data,ide_devices[device].Channel);
*data++;
n++;
asm(".intel_syntax noprefix");
asm("jmp $+2");
asm(".att_syntax prefix");
}
outb(0xE7,ide_devices[device].Channel+7);
} else if(ide_devices[device].Reserved==0) {
printk("Error: El dispositivo %i no ha sido inicializado y es probable que no este conectado\n",device);
}
} else if(device==0) printk("Error: El dispositivo 0 es NULL\n");
}