Calling API's

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.
Post Reply
me239
Member
Member
Posts: 25
Joined: Thu Jul 29, 2010 10:36 pm
Contact:

Calling API's

Post 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
roboman
Posts: 24
Joined: Fri Feb 27, 2009 9:41 am
Location: USA
Contact:

Re: Calling API's

Post 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.
me239
Member
Member
Posts: 25
Joined: Thu Jul 29, 2010 10:36 pm
Contact:

Re: Calling API's

Post 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 :)
bitshifter
Member
Member
Posts: 50
Joined: Sun Sep 20, 2009 4:03 pm

Re: Calling API's

Post 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...
me239
Member
Member
Posts: 25
Joined: Thu Jul 29, 2010 10:36 pm
Contact:

Re: Calling API's

Post 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.
roboman
Posts: 24
Joined: Fri Feb 27, 2009 9:41 am
Location: USA
Contact:

Re: Calling API's

Post 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.
nikito
Member
Member
Posts: 42
Joined: Thu Jul 15, 2010 7:16 pm

Re: Calling API's

Post 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
bitshifter
Member
Member
Posts: 50
Joined: Sun Sep 20, 2009 4:03 pm

Re: Calling API's

Post 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...
me239
Member
Member
Posts: 25
Joined: Thu Jul 29, 2010 10:36 pm
Contact:

Re: Calling API's

Post 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.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Calling API's

Post by egos »

Code: Select all

  xor ax,ax
  mov ds,ax
  cli
  mov [20h*4],_offset
  mov [20h*4+2],_segment
  sti
If you have seen bad English in my words, tell me what's wrong, please.
bitshifter
Member
Member
Posts: 50
Joined: Sun Sep 20, 2009 4:03 pm

Re: Calling API's

Post 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...
Attachments
x3dos.zip
(18.75 KiB) Downloaded 49 times
me239
Member
Member
Posts: 25
Joined: Thu Jul 29, 2010 10:36 pm
Contact:

Re: Calling API's

Post 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 :)
Post Reply