summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls/beep.cpp
blob: 1e5b2fe192a9614778a1f454e1fa97dd0760a1ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <Kernel/CommandLine.h>
#if ARCH(I386) || ARCH(X86_64)
#    include <Kernel/Arch/x86/common/PCSpeaker.h>
#endif
#include <Kernel/Process.h>

namespace Kernel {

ErrorOr<FlatPtr> Process::sys$beep()
{
    VERIFY_NO_PROCESS_BIG_LOCK(this);
    if (!kernel_command_line().is_pc_speaker_enabled())
        return ENODEV;
#if ARCH(I386) || ARCH(X86_64)
    PCSpeaker::tone_on(440);
    auto result = Thread::current()->sleep(Time::from_nanoseconds(200'000'000));
    PCSpeaker::tone_off();
    if (result.was_interrupted())
        return EINTR;
    return 0;
#else
    return ENOTIMPL;
#endif
}

}