- Aug 12, 2014
- 522
- 3
- 81
Hello,
I recently asked a question about talking to A/D converter chips in the sound sub-system on the motherboard. Here's the link:http://forums.anandtech.com/showthread.php?t=2463388
Ken closed the thread as it went astray at some point, so I can't ask this question there.
Anyway, at some point I asked the following:
But, at the hardware level, what you're actually doing is making the 'int'
hardware call with a direct integer argument and setting parameters in
certain registers.
This is what I want to do.
What's the proper 'int' argument for fopen()?
To which Merad responded:
Like many of your recent questions, the answers is: you can't do that.
A modern OS like Linux/Unix or Windows is a managed playground.
Teacher is watching you to make sure you don't do something you aren't
supposed to. And AFAIK, directly interacting with hardware resources from
a user mode program is very high on "not allowed" list.
If you want to tinker with things at that level, you need to either start
writing your own OS, or start playing around with microcontrollers.
Now, this has me questioning what I've learned up to this point about OS. It was my understanding that you could interact with hardware from user space if you asked the OS to intervene. This is called a system call, kernel trap, or software generated interrupt. This is a big part of what an OS does; it provides an interface for user space code to talk to hardware.
OK. So, in Linux assemblers, if you call the 'int' instruction and give the instruction an integer argument, that tells the processor to dive into kernel space and check the integer value's offset in the vector interrupt table that usually lies at the very bottom of physical RAM. This is a table of pointers that point to code somewhere else in kernel space.
A lot of these pointers are for when the hardware fails or the CPU throws a fault like divide by zero. But, there should be a number that codes for software interrupts. That pointer points to another table of pointers that point to the functions that you want to ultimately call. By setting parameters in certain registers in the CPU, you tell the computer which of those software interrupt functions you wish to use.
OK. That was my understanding. But, when Merad said what he said, I began questioning my understanding.
Is there something special about the fopen() function in C?
Is it not just a simple wrapper for some OS API function?
I thought that high level I/O functions in languages like C were just wrappers for OS I/O functions.
Perhaps, the fopen() function wraps many OS API I/O functions into one bundle?
Still, though, shouldn't you be able to call the required low-level OS API functions from assembly language using the 'int' hardware instruction and get the same result as if you had called fopen()?
Thanks.
I recently asked a question about talking to A/D converter chips in the sound sub-system on the motherboard. Here's the link:http://forums.anandtech.com/showthread.php?t=2463388
Ken closed the thread as it went astray at some point, so I can't ask this question there.
Anyway, at some point I asked the following:
But, at the hardware level, what you're actually doing is making the 'int'
hardware call with a direct integer argument and setting parameters in
certain registers.
This is what I want to do.
What's the proper 'int' argument for fopen()?
To which Merad responded:
Like many of your recent questions, the answers is: you can't do that.
A modern OS like Linux/Unix or Windows is a managed playground.
Teacher is watching you to make sure you don't do something you aren't
supposed to. And AFAIK, directly interacting with hardware resources from
a user mode program is very high on "not allowed" list.
If you want to tinker with things at that level, you need to either start
writing your own OS, or start playing around with microcontrollers.
Now, this has me questioning what I've learned up to this point about OS. It was my understanding that you could interact with hardware from user space if you asked the OS to intervene. This is called a system call, kernel trap, or software generated interrupt. This is a big part of what an OS does; it provides an interface for user space code to talk to hardware.
OK. So, in Linux assemblers, if you call the 'int' instruction and give the instruction an integer argument, that tells the processor to dive into kernel space and check the integer value's offset in the vector interrupt table that usually lies at the very bottom of physical RAM. This is a table of pointers that point to code somewhere else in kernel space.
A lot of these pointers are for when the hardware fails or the CPU throws a fault like divide by zero. But, there should be a number that codes for software interrupts. That pointer points to another table of pointers that point to the functions that you want to ultimately call. By setting parameters in certain registers in the CPU, you tell the computer which of those software interrupt functions you wish to use.
OK. That was my understanding. But, when Merad said what he said, I began questioning my understanding.
Is there something special about the fopen() function in C?
Is it not just a simple wrapper for some OS API function?
I thought that high level I/O functions in languages like C were just wrappers for OS I/O functions.
Perhaps, the fopen() function wraps many OS API I/O functions into one bundle?
Still, though, shouldn't you be able to call the required low-level OS API functions from assembly language using the 'int' hardware instruction and get the same result as if you had called fopen()?
Thanks.
Last edited: