I need to ask - even if I`m the idiot afterwards

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
TheStupidOne

I need to ask - even if I`m the idiot afterwards

Post by TheStupidOne »

Hello Guys,

I`m planning as you guessed an OS, what surprise....
Anyway, besides trying to learn assembler I came up with a question:

How do I make the functions that I implement in the Kernel (printf, etc.) available to other programs (yeah, that is if I get so far...)?
Tim

Re:I need to ask - even if I`m the idiot afterwards

Post by Tim »

Set up an interrupt handler in your kernel. Programs can use the INT instruction to invoke that handler.
TheStupidOne

Re:I need to ask - even if I`m the idiot afterwards

Post by TheStupidOne »

Bear with me.
I know it may sound stupid again, but I can`t imagine how to do this in C++/C. I mean I normally don`t use/see any assembler routines that call an INT. All C/C++.


P.S: Does someone know good tutorials on Interrupt Handlers or do I have to finally buy the book from Tanenbaum?
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:I need to ask - even if I`m the idiot afterwards

Post by Candy »

TheStupidOne wrote: Bear with me.
I know it may sound stupid again, but I can`t imagine how to do this in C++/C. I mean I normally don`t use/see any assembler routines that call an INT. All C/C++.


P.S: Does someone know good tutorials on Interrupt Handlers or do I have to finally buy the book from Tanenbaum?
Hidden part of the OS.

There is a library you ALWAYS link along (when using normal compilation) but you never actually use. It's called libc, linked with (usually) -lc and contains a lot of wrapper functions for C users to use, that clean up the arguments and call the interrupt (or use syscall or sysenter or something like that). The handler (which is again assembly) then passes those arguments to the handler, which ends up calling the function you intended to call. In the end, aside from this bit, all you see from the mechanism is that the CPU goes to kernel mode.

You will need to use assembly.
Post Reply