Some cleanup, moved PS2 code to drivers folder in the shared sources.
This commit is contained in:
parent
04d25d498d
commit
c097da920d
@ -33,6 +33,10 @@ extern const unsigned {symbol}_SIZE;
|
|||||||
env.Command([f'{res}.s', f'{res}.hpp'.replace('src/', 'include/')], res, action = _generate_s)
|
env.Command([f'{res}.s', f'{res}.hpp'.replace('src/', 'include/')], res, action = _generate_s)
|
||||||
env.AddMethod(_resource, 'Resource')
|
env.AddMethod(_resource, 'Resource')
|
||||||
|
|
||||||
|
irs_sources = Split('''
|
||||||
|
src/drivers/pic.cpp
|
||||||
|
src/drivers/ps2.cpp
|
||||||
|
''')
|
||||||
any_target_sources = Split('''
|
any_target_sources = Split('''
|
||||||
src/app/main.cpp
|
src/app/main.cpp
|
||||||
|
|
||||||
@ -51,5 +55,6 @@ any_target_sources = Split('''
|
|||||||
env.Resource(env.File('src/os/resources/lat9-08.psf').abspath, 'LAT9_08')
|
env.Resource(env.File('src/os/resources/lat9-08.psf').abspath, 'LAT9_08')
|
||||||
|
|
||||||
env.Append(KERNEL_SOURCES = [env.File(f) for f in any_target_sources])
|
env.Append(KERNEL_SOURCES = [env.File(f) for f in any_target_sources])
|
||||||
|
env.Append(KERNEL_ISR_SOURCES = [env.File(f) for f in irs_sources])
|
||||||
|
|
||||||
Return('env')
|
Return('env')
|
@ -25,6 +25,7 @@ void unmaskIRQ(std::uint8_t irq) noexcept;
|
|||||||
return (offset & 7) == 0;
|
return (offset & 7) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__x86_64__)
|
||||||
struct InterruptFrame
|
struct InterruptFrame
|
||||||
{
|
{
|
||||||
std::uint64_t ip;
|
std::uint64_t ip;
|
||||||
@ -33,6 +34,7 @@ struct InterruptFrame
|
|||||||
std::uint64_t sp;
|
std::uint64_t sp;
|
||||||
std::uint64_t ss;
|
std::uint64_t ss;
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
using interrupt_handler_t = __attribute__((interrupt)) void(*)(InterruptFrame*);
|
using interrupt_handler_t = __attribute__((interrupt)) void(*)(InterruptFrame*);
|
||||||
|
|
@ -1,18 +1,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if !defined(BAD_APPLE_OS_KERNEL_KEYBOARD_HPP_INCLUDED)
|
#if !defined(BAD_APPLE_OS_DRIVERS_PS2_HPP_INCLUDED)
|
||||||
#define BAD_APPLE_OS_KERNEL_KEYBOARD_HPP_INCLUDED
|
#define BAD_APPLE_OS_DRIVERS_PS2_HPP_INCLUDED
|
||||||
|
|
||||||
#include "./pic.hpp"
|
#include "drivers/pic.hpp"
|
||||||
|
|
||||||
namespace kbd
|
namespace baos::ps2
|
||||||
{
|
{
|
||||||
[[nodiscard]] bool initialize() noexcept;
|
|
||||||
|
|
||||||
__attribute__((interrupt))
|
|
||||||
void isrKeyboard(InterruptFrame* interruptFrame) noexcept;
|
|
||||||
|
|
||||||
enum class Scancode
|
enum class Scancode
|
||||||
{
|
{
|
||||||
INVALID = 0,
|
INVALID = 0,
|
||||||
@ -152,10 +147,13 @@ struct KeyEvent
|
|||||||
bool repeat : 1 = false;
|
bool repeat : 1 = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] bool readRaw(std::uint8_t& outData) noexcept;
|
[[nodiscard]] bool initialize() noexcept;
|
||||||
[[nodiscard]] bool read(KeyEvent& outEvent) noexcept;
|
|
||||||
|
|
||||||
|
__attribute__((interrupt))
|
||||||
|
void isrKeyboard(InterruptFrame* interruptFrame) noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]] bool readKey(KeyEvent& outEvent) noexcept;
|
||||||
[[nodiscard]] const char* keyName(Scancode scancode) noexcept;
|
[[nodiscard]] const char* keyName(Scancode scancode) noexcept;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !defined(BAD_APPLE_OS_KERNEL_KEYBOARD_HPP_INCLUDED)
|
#endif // !defined(BAD_APPLE_OS_DRIVERS_PS2_HPP_INCLUDED)
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#include "./pic.hpp"
|
#include "drivers/pic.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
@ -1,5 +1,9 @@
|
|||||||
|
|
||||||
#include "./keyboard.hpp"
|
#include "drivers/ps2.hpp"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include "drivers/pic.hpp"
|
||||||
|
#include "os/port.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@ -46,7 +50,7 @@ void pushKey(std::uint8_t data) noexcept
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace kbd
|
namespace baos::ps2
|
||||||
{
|
{
|
||||||
inline bool waitForResponse(unsigned tries = -1) noexcept
|
inline bool waitForResponse(unsigned tries = -1) noexcept
|
||||||
{
|
{
|
||||||
@ -221,7 +225,7 @@ bool gNextIsMoreExtended = false;
|
|||||||
bool gNextIsExtendedest = false;
|
bool gNextIsExtendedest = false;
|
||||||
bool gPrevWasExtendedest = false;
|
bool gPrevWasExtendedest = false;
|
||||||
|
|
||||||
[[nodiscard]] bool read(KeyEvent& outEvent) noexcept
|
bool readKey(KeyEvent& outEvent) noexcept
|
||||||
{
|
{
|
||||||
if (gPrevWasExtendedest)
|
if (gPrevWasExtendedest)
|
||||||
{
|
{
|
||||||
@ -300,7 +304,7 @@ bool gPrevWasExtendedest = false;
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] const char* keyName(Scancode scancode) noexcept
|
const char* keyName(Scancode scancode) noexcept
|
||||||
{
|
{
|
||||||
switch (scancode)
|
switch (scancode)
|
||||||
{
|
{
|
@ -25,18 +25,17 @@ crtbegin_o = get_crt_object('crtbegin.o')
|
|||||||
crtend_o = get_crt_object('crtend.o')
|
crtend_o = get_crt_object('crtend.o')
|
||||||
crti_o = kernel_env.Object('src/crt/crti.s')
|
crti_o = kernel_env.Object('src/crt/crti.s')
|
||||||
crtn_o = kernel_env.Object('src/crt/crtn.s')
|
crtn_o = kernel_env.Object('src/crt/crtn.s')
|
||||||
kernel_env['LINKCOM'] = env['LINKCOM'].replace('$_LIBFLAGS', f'{crti_o[0].abspath} {crtbegin_o} $_LIBFLAGS -lgcc {crtend_o} {crtn_o[0].abspath}')
|
kernel_env['LINKCOM'] = env['LINKCOM'].replace('$_LIBFLAGS', f'{crti_o[0].abspath} {crtbegin_o} -Wl,--start-group $_LIBFLAGS -Wl,--end-group -lgcc {crtend_o} {crtn_o[0].abspath}')
|
||||||
|
|
||||||
|
kernel_isr_sources = env['KERNEL_ISR_SOURCES'] + Split('''
|
||||||
|
|
||||||
kernel_irs_sources = Split('''
|
|
||||||
src/kernel/keyboard.cpp
|
|
||||||
src/kernel/pic.cpp
|
|
||||||
''')
|
''')
|
||||||
kernel_sources = env['KERNEL_SOURCES'] + Split('''
|
kernel_sources = env['KERNEL_SOURCES'] + Split('''
|
||||||
src/cstdlib/memory.s
|
src/cstdlib/memory.s
|
||||||
|
|
||||||
src/kernel/boot.s
|
src/kernel/boot.s
|
||||||
src/kernel/startup.cpp
|
src/kernel/startup.cpp
|
||||||
''') + [kernel_env.Object(f, CCFLAGS = kernel_env['CCFLAGS'] + ['-mgeneral-regs-only']) for f in kernel_irs_sources]
|
''') + [kernel_env.Object(f, CCFLAGS = kernel_env['CCFLAGS'] + ['-mgeneral-regs-only']) for f in kernel_isr_sources]
|
||||||
|
|
||||||
kernel_target = kernel_env.File('#kernel.x86_64.bin')
|
kernel_target = kernel_env.File('#kernel.x86_64.bin')
|
||||||
prog_kernel = kernel_env.Program(
|
prog_kernel = kernel_env.Program(
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
#include "os/draw.hpp"
|
#include "os/draw.hpp"
|
||||||
#include "os/serial.hpp"
|
#include "os/serial.hpp"
|
||||||
#include "os/tty.hpp"
|
#include "os/tty.hpp"
|
||||||
#include "./keyboard.hpp"
|
#include "drivers/pic.hpp"
|
||||||
#include "./pic.hpp"
|
#include "drivers/ps2.hpp"
|
||||||
#include "./x86_64.hpp"
|
#include "./x86_64.hpp"
|
||||||
|
|
||||||
extern "C" int gKernelEnd;
|
extern "C" int gKernelEnd;
|
||||||
@ -143,7 +143,9 @@ extern void __isr21(InterruptFrame*);
|
|||||||
|
|
||||||
void kernel_main()
|
void kernel_main()
|
||||||
{
|
{
|
||||||
setupInterrupt(INTERRUPT_KEYBOARD, &kbd::isrKeyboard, 0);
|
using namespace baos;
|
||||||
|
|
||||||
|
setupInterrupt(INTERRUPT_KEYBOARD, &ps2::isrKeyboard, 0);
|
||||||
|
|
||||||
__setGDT(sizeof(GDT), &GDT);
|
__setGDT(sizeof(GDT), &GDT);
|
||||||
__setIDT(sizeof(IDT), &IDT);
|
__setIDT(sizeof(IDT), &IDT);
|
||||||
@ -153,7 +155,7 @@ void kernel_main()
|
|||||||
unmaskIRQ(1);
|
unmaskIRQ(1);
|
||||||
|
|
||||||
// initialize the hardware
|
// initialize the hardware
|
||||||
const bool kbdInited = kbd::initialize();
|
const bool ps2Inited = ps2::initialize();
|
||||||
|
|
||||||
// done initializing OS stuff, enable interrupts
|
// done initializing OS stuff, enable interrupts
|
||||||
__asm__ __volatile__("sti");
|
__asm__ __volatile__("sti");
|
||||||
@ -187,20 +189,20 @@ void kernel_main()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!kbdInited)
|
if (!ps2Inited)
|
||||||
{
|
{
|
||||||
std::puts("Error initializing the keyboard!\n");
|
std::puts("Error initializing the PS2 controller!!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::puts("This is BadAppleOS and everything is fine!\n");
|
std::puts("This is BadAppleOS and everything is fine!\n");
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
kbd::KeyEvent event;
|
ps2::KeyEvent event;
|
||||||
while (!kbd::read(event));
|
while (!ps2::readKey(event));
|
||||||
std::printf(
|
std::printf(
|
||||||
"Key event: scancode=%s(0x%X), down=%s, repeat=%s\n",
|
"Key event: scancode=%s(0x%X), down=%s, repeat=%s\n",
|
||||||
kbd::keyName(event.scancode),
|
ps2::keyName(event.scancode),
|
||||||
static_cast<unsigned>(event.scancode),
|
static_cast<unsigned>(event.scancode),
|
||||||
event.down ? "true" : "false",
|
event.down ? "true" : "false",
|
||||||
event.repeat ? "true" : "false"
|
event.repeat ? "true" : "false"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user