linux下如何使用nasm访问声卡

发布于 2024-07-20 06:23:56 字数 256 浏览 3 评论 0原文

你好,我想知道如何使用 int 0x80 从 nasm 汇编程序访问声卡。 以及当访问声卡时我应该在寄存器中放入什么值。

是否有任何手册或内容详细介绍了我们必须传递给内核以访问声卡或其他硬件设备的参数,如果有人知道请告诉我。

我做了很多搜索,还有很多 C 库、ALSA 和 OSS 之类的东西,但我想要的是,如果有人知道一些从基础知识开始学习汇编程序与硬件接口的资源。

如果有人能给我一份关于如何进行访问的小代码清单,我将非常感激。

hello i want to know how i can access sound card from nasm assembly program using int 0x80.
and also what values should i put in the registers when to access the sound card.

is there any manual or something that has details about the arguments that we have to pass to the kernel to access the sound card or other hardware devices, please if anyone know please tell me.

i had done alot of searching and well there alot of c libraries and ALSA and OSS and stuff like that, but what i would like is that if any one know of some resources about learning from the basics up about assembly program interfacing with the hardware.

and if any one could give me a small code listing as to how the access is done i would be very thankful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小…红帽 2024-07-27 06:23:56

正如您所观察到的,Linux 中用户空间和内核空间之间的接口是 INT 0x80。

在 Unix 中,从哲学上来说,(几乎)一切都是文件,因此声卡被视为“字符文件”。 内核系统调用符合 POSIX 规范 - 所以“open”、“close”、“ioctl”、“read”、“write”。

对声卡的访问是通过驱动程序接口完成的,作为“/dev/”下的文件。 一些示例文档位于 OSS 文档,但我不确定它是否是最新的。

要观察此通信,您可以使用“strace”来查看任何现有应用程序正在使用哪些系统调用。

您可能会看到如下序列:

     open("/dev/dsp", ... ) 
     ioctl() 
     write() 
     ... 
     write()
     close()

通常您会通过 C 库“打开”,但由于您想跳过它,因此您可以通过几种方式找到系统调用 - 一种方法是

      objdump -d /usr/lib/libc.a

例如,您可以找到通过查找 <__libc_open> 打开是系统调用 0x5:
您会注意到 eax 为 5,其余参数位于 ebx、ecx 和 edx 中。
(用法和参数也列在 Linux Syscalls)

As you've observed, the interface between user-space and kernel space in Linux is INT 0x80.

In Unix, as a matter of philosophy, (almost) everything is a file, thus sound cards are treated as "Character Files." The kernel syscalls are as per the POSIX specification - so "open","close","ioctl","read","write".

Access to the soundcard is done through the driver interface, as a file under "/dev/". Some sample documentation is at OSS documentation, but I'm not sure if its current.

To observe this communication, you can use 'strace' to see what system calls are being used by any existing application.

You will likely see a sequence like:

     open("/dev/dsp", ... ) 
     ioctl() 
     write() 
     ... 
     write()
     close()

Usually you'd get to "open" through the C library, but since you want to skip that, you can find the syscalls a few ways - one way would be

      objdump -d /usr/lib/libc.a

For example, you can find that open is syscall 0x5 by looking for <__libc_open>:
You'll notice that eax is 5, and the rest of the parameters are in ebx, ecx and edx.
(The usage and parameters are also listed on Linux Syscalls )

初心 2024-07-27 06:23:56

这就是声卡驱动程序的作用。 它们必须为每个声卡定制编写,以便实现可供操作系统或应用程序使用的通用 API。 其他硬件设备也是如此。 硬件制造商往往不太公开如何在这个级别访问他们的东西(一方面)。

我并不是 Linux 专家,但这对于所有操作系统来说都是一个相当基本的问题。

This is what sound card drivers do. They have to be custom written for each sound card, in order to implement a common API which can be used by the O/S or applications. The same goes for other hardware devices. Hardware manufacturers tend to be less than open about how to access their stuff at this level (for one thing).

Not that I'm a Linux expert, but this is a fairly fundamental issue with all O/S's.

自演自醉 2024-07-27 06:23:56

在用户模式下,这将不起作用 - 您将无法直接访问声音硬件。

如果你创建一个内核模式驱动程序,你就可以直接戳声卡硬件,但在这一点上我认为大多数供应商都有不同的实现,并且不遵循一致的标准。 较新的声卡可能仍然是 Adlib 和 Adlib。 SoundBlaster 16 兼容 - 这是早在游戏针对 DOS 并直接使用硬件时的硬件标准,但如果它不再有效,我也不会感到惊讶。 快速搜索应该会找到直接访问这些旧卡界面的方法。 或者,您可以在虚拟机内运行 DOS 并访问硬件 - 大多数虚拟机模拟此级别的声卡。

From user mode, this won't work - you won't have direct access to the sound hardware.

If you create a kernel-mode driver, you'd be able to directly poke the sound card hardware, but at this point I think most vendors have different implementations and don't follow a consistent standard. Newer sound cards might still be Adlib & SoundBlaster 16 compatible - this was the hardware standard WAY back when games were targetting DOS and directly used the hardware, but I wouldn't be surprised if this is no longer valid. A quick search should yield ways to directly access the interface for these legacy cards. Alternatively, you could run DOS inside of a virtual machine and access the hardware - most virtual machines emulate this level of sound card.

方觉久 2024-07-27 06:23:56

根据你想要做什么,你可能最好使用现有的库来处理声卡的接口,除非你的目标是编写一个声卡驱动程序,我对此表示怀疑,并且最好用 C 语言完成在Linux上。

Portaudio 是一款相对易于使用的(免费)软件。 一个使用带有 C 接口的 portaudio 的示例库(我是 wwviaudio 的作者)

FMOD 似乎对游戏编程人员很重要,尽管它不是免费的。

sdl mix 是另一个深受 Linux 游戏开发者欢迎的工具。

JACK 在 Linux 专业音频领域很重要。 (想想 ardor —— Linux 对 Protools 的回答。)

尝试直接从用户空间与音频硬件对话是没有意义的。

Depending what you're trying to do, you're probably better off using an existing library to handle the interface to the sound card, unless you aim to write a sound card driver, which I doubt, and that would be best done in C on linux.

Portaudio is one (free) one that's relatively easy to use. one example lib using portaudio with a C interface (I'm the author of wwviaudio).

FMOD seems to be big with the game programming guys, though it's not free.

sdl mixer is another one that's big with the linux game developers.

JACK is big in the linux pro-audio world. (think ardour -- the linux answer to Protools.)

There's no sense in trying to talk to the audio hardware directly from user space.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文