Skip to content

Commit

Permalink
Properly forward signals from SDL window to target
Browse files Browse the repository at this point in the history
  • Loading branch information
bane9 committed Jun 19, 2023
1 parent 56e1557 commit abff473
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 85 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ if (USE_EMSCRIPTEN)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(OPTIMIZATION_FLAG "-Og")
set(OPTIMIZATION_FLAG "-O0")
target_compile_options(rv64gc_emu PRIVATE -fsanitize=address)
target_link_options(rv64gc_emu PRIVATE -fsanitize=address)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
Expand Down
11 changes: 0 additions & 11 deletions source/include/cpu_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,3 @@
#ifndef KERNEL_OFFSET
#define KERNEL_OFFSET 0x200000U
#endif

#if USE_TLB && !defined(TLB_COMPLIANT)
// Translation performance is better when disabled.
// When disabled, MMU safety checks will only be performed
// on TLB cache miss, but not if the entry is already in the cache.
#define TLB_COMPLIANT 1
#else
// Chooses the desired code path. When TLB is disabled translation is still compliant regardless of
// the TLB_COMPLIANT value.
#define TLB_COMPLIANT 0
#endif
2 changes: 1 addition & 1 deletion source/include/mmu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct TLBEntry
bool user;
};

constexpr uint64_t tlb_entries = 2;
constexpr uint64_t tlb_entries = 4;

struct Mode
{
Expand Down
65 changes: 1 addition & 64 deletions source/mmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,68 +220,6 @@ bool Mmu::fetch_pte(uint64_t address, AccessType acces_type, cpu::Mode cpu_mode,
entry.phys_base |= ppn[j] << (12ULL + (j * 9ULL));
}
}
#if !TLB_COMPLIANT
bool mxr = cpu.cregs.read_bit_mstatus(csr::Mask::MSTATUSBit::MXR);
bool sum = cpu.cregs.read_bit_mstatus(csr::Mask::MSTATUSBit::SUM);

if ((!entry.read && entry.write && !entry.execute) ||
(!entry.read && entry.write && entry.execute))
{
set_cpu_error(address, acces_type);
return false;
}

if (entry.user &&
((cpu_mode != cpu::Mode::User) && (!sum || acces_type == AccessType::Instruction)))
{
set_cpu_error(address, acces_type);
return false;
}

if (!entry.user && (cpu_mode != cpu::Mode::Supervisor))
{
set_cpu_error(address, acces_type);
return false;
}

switch (acces_type)
{
case Mmu::AccessType::Load:
if (!(entry.read || (entry.execute && mxr)))
{
set_cpu_error(address, acces_type);
return false;
}
break;
case Mmu::AccessType::Store:
if (!entry.write)
{
set_cpu_error(address, acces_type);
return false;
}
break;
case Mmu::AccessType::Instruction:
if (!entry.execute)
{
set_cpu_error(address, acces_type);
return false;
}
}

if (!entry.accessed || (acces_type == AccessType::Store && !entry.dirty))
{
entry.pte |= 1ULL << Pte::Accessed;
entry.accessed = true;

if (acces_type == AccessType::Store)
{
entry.pte |= 1ULL << Pte::Dirty;
entry.dirty = true;
}

cpu.bus.store(cpu, entry.pte_addr, entry.pte, 64);
}
#endif

return true;
}
Expand Down Expand Up @@ -377,7 +315,6 @@ uint64_t Mmu::translate(uint64_t address, AccessType acces_type)
return 0;
}

#if TLB_COMPLIANT
bool mxr = cpu.cregs.read_bit_mstatus(csr::Mask::MSTATUSBit::MXR);
bool sum = cpu.cregs.read_bit_mstatus(csr::Mask::MSTATUSBit::SUM);

Expand Down Expand Up @@ -438,7 +375,7 @@ uint64_t Mmu::translate(uint64_t address, AccessType acces_type)

cpu.bus.store(cpu, entry->pte_addr, entry->pte, 64);
}
#endif

return entry->phys_base | (address & 0xfffULL);
}

Expand Down
54 changes: 46 additions & 8 deletions source/peripherals/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,22 +259,60 @@ void GpuDevice::tick(Cpu& cpu)
last_tick = current_tick;
SDL_Event e;

while (SDL_PollEvent(&e))
if (SDL_PollEvent(&e))
{
switch (e.type)
{
case SDL_QUIT:
exit(0);
break;
case SDL_TEXTINPUT:
uart_putchar(e.text.text[0]);
break;
case SDL_KEYDOWN:
if (e.key.keysym.sym == SDLK_RETURN || e.key.keysym.sym == SDLK_KP_ENTER)
case SDL_KEYDOWN: {
if (SDL_GetModState() & KMOD_CTRL)
{
uart_putchar('\n');
switch (e.key.keysym.sym)
{
case SDLK_c:
uart_putchar(0x3);
break;
case SDLK_d:
uart_putchar(0x4);
break;
}
}
break;
else
{
const Uint8* keystates = SDL_GetKeyboardState(NULL);
SDL_Keycode keycode = e.key.keysym.sym;
bool shiftPressed =
keystates[SDL_SCANCODE_LSHIFT] || keystates[SDL_SCANCODE_RSHIFT];
bool capsLockOn = SDL_GetModState() & KMOD_CAPS;
bool isLetter = (keycode >= SDLK_a && keycode <= SDLK_z);

if (shiftPressed || capsLockOn)
{
if (isLetter)
{
uart_putchar(SDL_toupper((char)keycode));
}
else
{
uart_putchar((char)keycode);
}
}
else
{
if (isLetter)
{
uart_putchar(SDL_tolower((char)keycode));
}
else
{
uart_putchar((char)keycode);
}
}
}
}
break;
case SDL_KEYUP:
val = 0;
break;
Expand Down

0 comments on commit abff473

Please sign in to comment.