How can I replace INT instruction ?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
raz0r
Posts: 19
Joined: Sat Apr 30, 2011 6:02 pm

How can I replace INT instruction ?

Post by raz0r »

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).
User avatar
Rusky
Member
Member
Posts: 792
Joined: Wed Jan 06, 2010 7:07 pm

Re: How can I replace INT instruction ?

Post by Rusky »

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.
raz0r
Posts: 19
Joined: Sat Apr 30, 2011 6:02 pm

Re: How can I replace INT instruction ?

Post by raz0r »

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.
yep I read that page.
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?!
User avatar
thepowersgang
Member
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 ?

Post by thepowersgang »

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)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: How can I replace INT instruction ?

Post by bluemoon »

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).
Are you sure you want to write a driver, not a wrapper?
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.
raz0r
Posts: 19
Joined: Sat Apr 30, 2011 6:02 pm

Re: How can I replace INT instruction ?

Post by raz0r »

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 :

Code: Select all

//issue a read sectors command
   outb(0x1f7, 0x20);
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:(
Last edited by raz0r on Mon May 16, 2011 5:35 pm, edited 1 time in total.
raz0r
Posts: 19
Joined: Sat Apr 30, 2011 6:02 pm

Re: How can I replace INT instruction ?

Post by raz0r »

berkus wrote:
raz0r wrote:Im in pmode, obviusly (32bits). .. helpme:(
provide debug output from bochs first:/
Yes, im debugging with GDB and when the OS try to execute 0x1F7 my OS dieds (I view a PANIC Event from device).

This is the output of GDB 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
This is the output of internal debugger:
<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]
(I have two debuggers configured in bochs)

..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.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: How can I replace INT instruction ?

Post by gerryg400 »

Code: Select all

outb(0x1f7, 0x20);
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 ?
If a trainstation is where trains stop, what is a workstation ?
raz0r
Posts: 19
Joined: Sat Apr 30, 2011 6:02 pm

Re: How can I replace INT instruction ?

Post by raz0r »

berkus wrote:How are you going to write an OS if you cannot even read?
Because actually the all of the OS are in memory.
Is very beta version...
raz0r
Posts: 19
Joined: Sat Apr 30, 2011 6:02 pm

Re: How can I replace INT instruction ?

Post by raz0r »

gerryg400 wrote:

Code: Select all

outb(0x1f7, 0x20);
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 ?
hm.... this is outb function:

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
do you view any error?

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.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: How can I replace INT instruction ?

Post by gerryg400 »

I'm pretty sure that your function arguments are reversed.
If a trainstation is where trains stop, what is a workstation ?
raz0r
Posts: 19
Joined: Sat Apr 30, 2011 6:02 pm

Re: How can I replace INT instruction ?

Post by raz0r »

gerryg400 wrote:I'm pretty sure that your function arguments are reversed.
Yes, that is the problem. thanks.
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?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: How can I replace INT instruction ?

Post by gerryg400 »

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 ?
raz0r
Posts: 19
Joined: Sat Apr 30, 2011 6:02 pm

Re: How can I replace INT instruction ?

Post by raz0r »

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.
Im trying to read data from X sector of harddisk. Read byte/word and print that information.

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);
But I dont have idea if this ports are ok for read/write sectors..

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);
(remember the original code is here: http://forum.osdev.org/viewtopic.php?f=1&t=23194 I edited the last part).

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)...
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: How can I replace INT instruction ?

Post by gerryg400 »

data_readBuffer must be a char [512]. Not a char.
In that code im trying to check if in the var data_readBuffer are the 256 bytes information of the harddisk.
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.

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 ?
Post Reply