sigh And this why I never liked the term 'software interrupt' for
System Calls. Feel free to skip the rant coming up; my reply about the specific problems you are looking at will follow that.
/me pulls out soapbox and hopes it won't break under my weight if I stand on it
While the mechanism used for calling system services in real mode x86 (and several other CPU architectures, including ARM and MIPS) is
sort of the same as that for interrupts (e.g., they both use the same or similar lookup table mechanisms), the
purpose of them is quite different.
Unfortunately, this is another one of the instances where no one seems to agree on their terminology, and each ISA has it's own name for the service call instruction (if it has one). On x86, it's called
INT; if memory serves, on 68K it's
TRAP; going from memory again, on the old IBM mainframes it was
SVC ('SerVice Call'); on MIPS, it's
SYSCALL; and on ARM, it was originally
SWI ('SoftWare Interrupt'), but this was later deprecated in favor of the alias
SVC, with both being accepted by most ARM assemblers today.
And that's not even getting into the three other mechanisms for implementing system calls which were later introduced for x86 protected mode: Traps (which are completely unrelated to the 68K instruction mentioned above, how nice); Call Gates (which are a bit hairy to get into right now); and the
SYSENTER instruction (which for maximum confusion, gets renamed in long mode to
SYSCALL). Or the various software-based approaches which different x86 OSes have relied on over the years, some of which have been brain-breakingly weird.
steps off of soapbox
OK, back to the matter at hand.
First off, what both Brendan and iansjack said already is pretty much the heart of the issue, at least on the surface: it sounds as if this just isn't something you are ready to address in your system, for a few different reasons.
Part of the reason we are having trouble answering this is because you don't mention whether you are in real mode or not. This is a crucial question with the given code, since - as has already been stated - all of the standard BIOS calls are written for 16-bit real mode, and won't run in any form of protected or long mode without heroic efforts (e.g., setting up Virtual 8086 support, which would only work if you
already have p-mode interrupt handling set up). Furthermore, interrupt handling in protected mode is radically different from interrupt handling in real mode, meaning that the interrupt vectors to the BIOS calls found in the real mode Interrupt Vector Table won't even exist in your p-mode Interrupt Descriptor Table unless you put them there (and there's no sane reason to do so in most cases).
As an aside, according to the
RBIL entry discussing that interrupt vector, the interrupt only gives a timing resolution of 997 microseconds, or just a little better than a tenth of a second. This probably is fast enough for your intended use here, but not even remotely fast enough for a general
sleep() routine, and certainly not fast enough for the function usually indicated by the name
usleep() (where the 'u' is an ASCII-ism for the Greek letter mu (μ), short for micro - in other words, a sleep with a microsecond resolution). I mean, call it what you want, you do you, but be aware that you'll have trouble getting help from others if you use common function names in unexpected ways.
But all of that may be irrelevant, for one simple reason: as far as I know, most motherboards don't even have a
PC Speaker of that type any more, and modern
Sound systems (most current ones being based on the
Intel High Definition Audio spec) work in a completely different manner from the old PC speaker subsystem of the original IBM PC. While my understanding is that most implementations of
AC97 and later sound standards will still emulate the PC speaker, AFAIK it isn't required by those standards, so there's no guarantee that your hardware does or not. If anyone can correct or clarify this point, please do so.
Maybe we need to start over, as this is getting into '
XY Problem' territory. Can you tell us what you want to use the speaker for?