How can I replace INT instruction ?
How can I replace INT instruction ?
Hi,
Im developing harddisk driver. Im in usermode and I need execute INT instruction (INT 13h, etc). Whats are the alternatives that can I use?
(int instruction is for rmode).
Im developing harddisk driver. Im in usermode and I need execute INT instruction (INT 13h, etc). Whats are the alternatives that can I use?
(int instruction is for rmode).
Re: How can I replace INT instruction ?
INT 13h is a BIOS call, which as you said is inaccessible from protected mode. You need to write a driver for the kind of disk you want to access. See the wiki for more information.
Re: How can I replace INT instruction ?
yep I read that page.Rusky wrote:INT 13h is a BIOS call, which as you said is inaccessible from protected mode. You need to write a driver for the kind of disk you want to access. See the wiki for more information.
and I read that if I want to execute INT 13h in pmode the alternative is switch to rmode using vm8086 task, execute int, and switch again to pmode...
But i dont have idea how can I use "vm8086" task.
Is this a code developed in ASM? is this any special instruction? how can I use this for switch the mode?!
- thepowersgang
- Member
- Posts: 734
- Joined: Tue Dec 25, 2007 6:03 am
- Libera.chat IRC: thePowersGang
- Location: Perth, Western Australia
- Contact:
Re: How can I replace INT instruction ?
VM8086 is not that difficult to use once you write process management, just set the "VM" bit in EFLAGS for the task, and it will run in a simulated 16-bit mode.
Be sure to have a GPF handler set up for privalaged instructions (or have it be a ring-0 task, if possible)
Be sure to have a GPF handler set up for privalaged instructions (or have it be a ring-0 task, if possible)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Re: How can I replace INT instruction ?
Are you sure you want to write a driver, not a wrapper?raz0r wrote:Im developing harddisk driver. Im in usermode and I need execute INT instruction (INT 13h, etc). Whats are the alternatives that can I use?
(int instruction is for rmode).
Check out the wiki on direct disk access, it can be done without BIOS call, basically you use PIO or DMA access.
And you said you're in usermode, you also need permission on the resources.
How to grant that permission is depends on what environment/OS you're in, which you have not mentioned.
Re: How can I replace INT instruction ?
Yes. Now im trying implement the driver with PIO.
I tested this code: http://forum.osdev.org/viewtopic.php?f=1&t=23194 and I use read_sector() for read one sector of the hdd.
The problem is in the line :
When I execute 0x1f7 my OS dieds.
I read this article to understand the ports http://www.osdever.net/tutorials/view/l ... ss-via-pio and I dont have idea whats the reason because 0x1F7 dont work good in my OS.
Im in pmode, obviusly (32bits). .. helpme:(
I tested this code: http://forum.osdev.org/viewtopic.php?f=1&t=23194 and I use read_sector() for read one sector of the hdd.
The problem is in the line :
Code: Select all
//issue a read sectors command
outb(0x1f7, 0x20);
I read this article to understand the ports http://www.osdever.net/tutorials/view/l ... ss-via-pio and I dont have idea whats the reason because 0x1F7 dont work good in my OS.
Im in pmode, obviusly (32bits). .. helpme:(
Last edited by raz0r on Mon May 16, 2011 5:35 pm, edited 1 time in total.
Re: How can I replace INT instruction ?
Yes, im debugging with GDB and when the OS try to execute 0x1F7 my OS dieds (I view a PANIC Event from device).berkus wrote:provide debug output from bochs first:/raz0r wrote:Im in pmode, obviusly (32bits). .. helpme:(
This is the output of GDB Debugger:
This is the output of internal debugger:(gdb) break read_sector A PANIC has occurred. Do you want to: 1 at 0x106a5: file ide.c, line 1350.
(gdb) c cont - continue execution
Continuando. alwayscont - continue execution, and don't ask again.
This affects only PANIC events from device [PIC ]int 1, read_sector (LBA=24576) at ide.c:1350
(gdb) n die - stop execution now
abort - dump core
debug - hand control to gdb
Choose one of the actions above: [die] WARNING: log_msg returned unexpected value -1
(I have two debuggers configured in bochs)<bochs:1> c
========================================================================
Event type: PANIC
Device: [PIC ]
Message: master: ICW1: single mode not supported
A PANIC has occurred. Do you want to:
cont - continue execution
alwayscont - continue execution, and don't ask again.
This affects only PANIC events from device [PIC ]
die - stop execution now
abort - dump core
debug - continue and return to bochs debugger
Choose one of the actions above: [die]
..maybe I need execute other function for inicializate something before read_sector()....
Ideas?
Last edited by raz0r on Mon May 16, 2011 5:48 pm, edited 1 time in total.
Re: How can I replace INT instruction ?
Code: Select all
outb(0x1f7, 0x20);
If a trainstation is where trains stop, what is a workstation ?
Re: How can I replace INT instruction ?
Because actually the all of the OS are in memory.berkus wrote:How are you going to write an OS if you cannot even read?
Is very beta version...
Re: How can I replace INT instruction ?
hm.... this is outb function:gerryg400 wrote:I just wonder about your outb function. Does it write 0x20 to the port 0x1f7 ? Or does it write 0x1f7 to the port at 0x20 ?Code: Select all
outb(0x1f7, 0x20);
Code: Select all
outb:
push ebp
mov ebp, esp
push edx
mov eax, [ebp+8]
mov edx, [ebp+12]
out dx, al
pop edx
mov esp, ebp
pop ebp
ret
in eax and edx are the arguments that i sent in c code.
im trying to write a byte in the port...
but my doubt is why this function works good in all of the ports exept 0x1f7 ?
I think that the problem is other...
again:
..maybe I need execute other function for inicializate something before read_sector()....
Last edited by raz0r on Mon May 16, 2011 6:03 pm, edited 1 time in total.
Re: How can I replace INT instruction ?
I'm pretty sure that your function arguments are reversed.
If a trainstation is where trains stop, what is a workstation ?
Re: How can I replace INT instruction ?
Yes, that is the problem. thanks.gerryg400 wrote:I'm pretty sure that your function arguments are reversed.
now the problem is I need recover the data that I read.
for example Im trying to read the sector number 6000 :
read_sector(0x6000);
but, how can I recover the information ?
maybe using "in" instruction in asm ?... recover the data in stack?... howto?
Re: How can I replace INT instruction ?
It depends entirely on how you initialise the controller and how your read_sector() work. It's not clear to me what you are trying to do.
If a trainstation is where trains stop, what is a workstation ?
Re: How can I replace INT instruction ?
Im trying to read data from X sector of harddisk. Read byte/word and print that information.gerryg400 wrote:It depends entirely on how you initialise the controller and how your read_sector() work. It's not clear to me what you are trying to do.
For initialise the controller I use all of this functions: http://wiki.osdev.org/ATA
In this case I use:
Code: Select all
//If you only want to support the parallel IDE, you can use these parameters:
ide_initialize(0x1F0, 0x3F4, 0x170, 0x374, 0x000);
About this particular code read_sector():
In the end of the code are the insw function that calls 0x1F0 (According to http://wiki.osdev.org/ATA_PIO_Mode In LBA28 PIO this port is: Transfer 256 words, a word at a time, into your buffer from I/O port 0x1F0. (In assembler, REP INSW works well for this).
So, I execute this code:
Code: Select all
unsigned char data_readBuffer;
print("DATA Before: %s\n", data_readBuffer);
insw(0x1f0, data_readBuffer, 256);
ide_polling(0,0);
print ("DATA After: %s", data_readBuffer);
In that code im trying to check if in the var data_readBuffer are the 256 bytes information of the harddisk.
In the prints I view the same information (trash), so whats the error?
For call the original function I use:
read_sector(0x6000) for example for read the sector 6000. If I send other sector, data_readBuffer should have other information...
ok, nothing of this is happening..
I think im not understanding how insw works (Im trying to recover the information in the second argument)...
Re: How can I replace INT instruction ?
data_readBuffer must be a char [512]. Not a char.
Also my personal opinion is that the code in the ATA/IDE tutorial should not be used if you want a reliable, maintainable driver. The ATA PIO mode article is better. You also need the real ATA specs.
Comments like this make me think that you are not really reading the documentation. There are 256 x 16-bit words to read. Not 256 bytes. Not even 512 bytes.In that code im trying to check if in the var data_readBuffer are the 256 bytes information of the harddisk.
Also my personal opinion is that the code in the ATA/IDE tutorial should not be used if you want a reliable, maintainable driver. The ATA PIO mode article is better. You also need the real ATA specs.
If a trainstation is where trains stop, what is a workstation ?