Page 1 of 1

Calling API's

Posted: Fri Jul 30, 2010 11:12 pm
by me239
With my newfound success with my OS, I think I'm ready to expand my kernel a bit. I'm going to add FAT file system support by myself, but one other function I want to add is the ability to call my API's. I've searched through the forums and on google and have found close to no documentation on the calling of API's. If anyone could help me in writing this code it would be very helpful.
xOS info:
real mode
made in FASM

Re: Calling API's

Posted: Fri Jul 30, 2010 11:41 pm
by roboman
me239 wrote:no documentation on the calling of API's.
xOS info:
real mode
made in FASM
In the real mode dos world they tended to be called tsr's Terminate and Stay Resident programs. A program would be loaded to a high spot in memory, the high mem would be adjusted, An int would be redirected to that program..... If you didn't like the way bios or dos did something you could redirect one of their int's or you could hunt down one not in use. Haven't done any in probably 15 years now, but there is a ton of info about them around.

Re: Calling API's

Posted: Fri Jul 30, 2010 11:52 pm
by me239
roboman wrote:
me239 wrote:no documentation on the calling of API's.
xOS info:
real mode
made in FASM
In the real mode dos world they tended to be called tsr's Terminate and Stay Resident programs. A program would be loaded to a high spot in memory, the high mem would be adjusted, An int would be redirected to that program..... If you didn't like the way bios or dos did something you could redirect one of their int's or you could hunt down one not in use. Haven't done any in probably 15 years now, but there is a ton of info about them around.
Could you give me any advice on how to set the IRV and handler? BTW I've also heard about Call Gates. Can you give me any examples of making call gates?
Thanks :)

Re: Calling API's

Posted: Sat Jul 31, 2010 2:56 am
by bitshifter
I used a far-call API in this small OS demo.
http://forum.osdev.org/viewtopic.php?f=2&t=21464
Also see how i remapped int 20h to my own routine...

Re: Calling API's

Posted: Sat Jul 31, 2010 3:23 am
by me239
bitshifter wrote:I used a far-call API in this small OS demo.
http://forum.osdev.org/viewtopic.php?f=2&t=21464
Also see how i remapped int 20h to my own routine...
I looked at your OS and I didn't see anything about interrupts. All I saw was I boot loader capable of booting a com or exe file.

Re: Calling API's

Posted: Sat Jul 31, 2010 9:06 am
by roboman
me239 wrote:Could you give me any advice on how to set the IRV and handler? BTW I've also heard about Call Gates. Can you give me any examples of making call gates?
Thanks :)
Call Gates, as in playing with privilege level, Sorry no, if my programs can't access the entire system and touch any piece of hardware they want, well then where is the fun in that. So I never played with that stuff and leave the entire system open. That's why I'm doing this and not writing Droid programs or Windows games. IRV? as in Reference Version stuff for large group projects? No history with that.

Re: Calling API's

Posted: Sat Jul 31, 2010 9:42 am
by nikito
Basically, you set an IDT in protected mode or IVT in real mode, and basically both are the some thing.
When you code "int 10", the CPU is interrupting all what it does, and go to the code who pointed in the entry in the IDT/IVT number 10 in the case. Then execute the code of you API.When your API should terminate and return the instruction pointer to the previously executed program, you code "iret".
This is the normal way to implement an API. Its just like serving an interrupt from the keyboard, but this time is an interrupt originated inside you code.
Call Gates, as in playing with privilege level, Sorry no, if my programs can't access the entire system and touch any piece of hardware they want, well then where is the fun in that. So I never played with that stuff and leave the entire system open. That's why I'm doing this and not writing Droid programs or Windows games. IRV? as in Reference Version stuff for large group projects? No history with that.
This is what I am doing right now. All SO work in level 0. This is done this way, because this will be an OS not for the common user thus there will never be mall ware. Wrong code? - no, once debuged.

cheers!

niki

Re: Calling API's

Posted: Sat Jul 31, 2010 12:03 pm
by bitshifter
If you look in SYSTEM.ASM you will find that i remapped int 20h
so it uses my own routine (so programs can ask to be terminated)
Its quite easy, just write CS:IP into desired table entry.
Also they can be chained as to just monitor its activity.
Just be sure to disable interrupts before changing them...

Re: Calling API's

Posted: Sat Jul 31, 2010 2:27 pm
by me239
bitshifter wrote:If you look in SYSTEM.ASM you will find that i remapped int 20h
so it uses my own routine (so programs can ask to be terminated)
Its quite easy, just write CS:IP into desired table entry.
Also they can be chained as to just monitor its activity.
Just be sure to disable interrupts before changing them...
I didn't see any files named system.asm just fat12.asm and fat16.asm. If somebody give me code here in the forum that can directly change the ivt.

Re: Calling API's

Posted: Sun Aug 01, 2010 11:31 am
by egos

Code: Select all

  xor ax,ax
  mov ds,ax
  cli
  mov [20h*4],_offset
  mov [20h*4+2],_segment
  sti

Re: Calling API's

Posted: Sun Aug 01, 2010 7:05 pm
by bitshifter
I have uploaded attachment of that OS demo for you to try...
It sounds like you have the BOOTPROG tools but not the OS code...

Re: Calling API's

Posted: Mon Aug 02, 2010 1:07 am
by me239
bitshifter wrote:I have uploaded attachment of that OS demo for you to try...
It sounds like you have the BOOTPROG tools but not the OS code...
Thanks man. It's not an interrupt, but it's actually what I was orginally looking for :)