Assembly 使用程序集中的端口时发生磁盘读/写故障
我的O/S现在处于保护模式,因此我现在无法使用中断访问磁盘。我不知道如何切换到v86模式。我需要使用端口访问磁盘 我决定试试我在forum.osdev.org上找到的代码。在模拟器中,它显示磁盘读写成功。但当我检查硬盘时,它是空的,或者当我测试读取时,缓冲区都是空的 此代码或我的O/S有什么问题? (可能是堆栈问题导致的?) 代码:Assembly 使用程序集中的端口时发生磁盘读/写故障,assembly,x86,operating-system,disk,protected-mode,Assembly,X86,Operating System,Disk,Protected Mode,我的O/S现在处于保护模式,因此我现在无法使用中断访问磁盘。我不知道如何切换到v86模式。我需要使用端口访问磁盘 我决定试试我在forum.osdev.org上找到的代码。在模拟器中,它显示磁盘读写成功。但当我检查硬盘时,它是空的,或者当我测试读取时,缓冲区都是空的 此代码或我的O/S有什么问题? (可能是堆栈问题导致的?) 代码: mov si,[buffer]似乎是错误的,因为它移动的是缓冲区的内容,而不是缓冲区的地址 我想应该是mov-si,buffer或lea-si,[buffer]。我
mov si,[buffer]
似乎是错误的,因为它移动的是缓冲区的内容,而不是缓冲区的地址
我想应该是
mov-si,buffer
或lea-si,[buffer]
。我发现了问题,问题出在rep outsw
,所以我写了一个循环代码,在没有该命令的情况下将字发送到数据寄存器。
这是我用pascal编写的代码:
uses ...;
var
RawData:array[0..255] of Word;
ATA_INDEX:Integer;
implementation
//...
function DiskReadSector(Drive,Head,Cylinder,SecNum:integer):Integer;stdcall;
var
xstat:Word;
i:integer;
BaseAdress:Word;
begin
if ATA_INDEX=0 then
BaseAdress:=$1f0 else
BaseAdress:=$170;
outb(BaseAdress+6,$0a0 or (Drive shl 4) or head);
outb(BaseAdress+2,1);//Count
outb(BaseAdress+3,SecNum);// Sector Number
outb(BaseAdress+4,Cylinder and $00FF);//LOW Cylinder
outb(BaseAdress+5,Cylinder shr 8);//HIGH Cylinder
outb(BaseAdress+7,$20);//READ COMMAND $30 for WRITE
asm //CHECK FOR DATA READY
mov dx,1f7h
@still_going:
in al,dx
test al,8
jz @still_going
end;
for i:=0 to 255 do begin //COPY DATA TO WORD ARRAY
xstat:=inw(BaseAdress);
RawData[i]:=xstat;
end;
DiskReadSector:=inb(BaseAdress+7);//DEBUG
end
用法:
procedure kmain;stdcall;[public,alias:'kmain'];
begin
//...
ATA_INDEX:=0;//Zero for Primary Others for Secondary
DiskReadSector(0,0,0,1);//Drive 0 for Master 1 for Slave Example:
//ATA_INDEX=0 and Drive=0 it means Primary Master
//This Code Will Read Master Boot Record of IDE Primary Master
//a simple check for boot signature of first sector at primary master:
if RawData[255]=$AA55 then
WriteLn('Boot Signature Detected!');
end;
不要把你的代码链接起来,内联发布,这样人们就可以帮助你了。怎么会有人告诉你你的操作系统出了什么问题呢。您还没有向我们展示任何信息。@SepRoland经验丰富的O/S开发人员可以猜测itI的一些信息。我知道IDE主控主机使用1fxh。我正在尝试IDE主控主机。我可以使用PCI检测IDE@seprolandi如果您处于32位保护模式,加载16位地址是非常可疑的。还有,post,我们无法调试。你应该在这里发布更新的代码。@CodyGray你现在满意了吗?
procedure kmain;stdcall;[public,alias:'kmain'];
begin
//...
ATA_INDEX:=0;//Zero for Primary Others for Secondary
DiskReadSector(0,0,0,1);//Drive 0 for Master 1 for Slave Example:
//ATA_INDEX=0 and Drive=0 it means Primary Master
//This Code Will Read Master Boot Record of IDE Primary Master
//a simple check for boot signature of first sector at primary master:
if RawData[255]=$AA55 then
WriteLn('Boot Signature Detected!');
end;