Skip to content

Commit

Permalink
Booting xam.xex now, first syscall incoming
Browse files Browse the repository at this point in the history
  • Loading branch information
google0101-ryan committed Jan 3, 2024
1 parent 4f21ad7 commit 2d42614
Show file tree
Hide file tree
Showing 18 changed files with 2,662 additions and 14 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.2)

project(DOOM3BFG)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_BUILD_TYPE DEBUG)

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
Expand All @@ -14,6 +15,9 @@ set(SOURCES src/memory/memory.cpp
src/cpu/ops.cpp)

set(AES_SOURCES src/crypto/rijndael-alg-fst.cpp)
set(LZX_SOURCES src/thirdparty/lzxd.cpp
src/thirdparty/system.cpp
src/loader/lzx.cpp)

include_directories(${CMAKE_SOURCE_DIR}/src)
add_executable(xbox360 ${SOURCES} ${AES_SOURCES})
include_directories(${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/thirdparty)
add_executable(xbox360 ${SOURCES} ${AES_SOURCES} ${LZX_SOURCES})
63 changes: 62 additions & 1 deletion src/cpu/CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cassert>
#include "CPU.h"

CPUThread::CPUThread(uint32_t entryPoint, uint32_t stackSize)
{
Expand Down Expand Up @@ -30,22 +32,66 @@ void CPUThread::Run()

printf("0x%08x (0x%08lx): ", instr, state.pc-4);

if (((instr >> 26) & 0x3F) == 18)
if (((instr >> 26) & 0x3F) == 10)
{
cmpli(instr);
}
else if (((instr >> 26) & 0x3F) == 14)
{
addi(instr);
}
else if (((instr >> 26) & 0x3F) == 15)
{
addis(instr);
}
else if (((instr >> 26) & 0x3F) == 16)
{
bc(instr);
}
else if (((instr >> 26) & 0x3F) == 18)
{
branch(instr);
}
else if (((instr >> 26) & 0x3F) == 19 && ((instr >> 1) & 0x3FF) == 16)
{
bclr(instr);
}
else if (((instr >> 26) & 0x3F) == 21)
{
rlwinm(instr);
}
else if (((instr >> 26) & 0x3F) == 24)
{
ori(instr);
}
else if (((instr >> 26) & 0x3F) == 31 && ((instr >> 1) & 0x3FF) == 339)
{
mfspr(instr);
}
else if (((instr >> 26) & 0x3F) == 31 && ((instr >> 1) & 0x3FF) == 444)
{
or_(instr);
}
else if (((instr >> 26) & 0x3F) == 31 && ((instr >> 1) & 0x3FF) == 467)
{
mtspr(instr);
}
else if (((instr >> 26) & 0x3F) == 32)
{
lwz(instr);
}
else if (((instr >> 26) & 0x3F) == 36)
{
stw(instr);
}
else if (((instr >> 26) & 0x3F) == 37)
{
stwu(instr);
}
else if (((instr >> 26) & 0x3F) == 58)
{
ld(instr);
}
else if (((instr >> 26) & 0x3F) == 62)
{
std(instr);
Expand All @@ -57,6 +103,21 @@ void CPUThread::Run()
}
}

void CPUThread::Dump()
{
for (int i = 0; i < 32; i++)
printf("r%d\t->\t0x%08lx\n", i, state.regs[i]);
for (int i = 0; i < 7; i++)
printf("cr%d\t->\t%d\n", i, state.GetCR(i));
}

void CPUThread::SetArg(int num, uint64_t value)
{
printf("Setting arg%d: 0x%08lx\n", num, value);
assert(num < 6);
state.regs[3 + num] = value;
}

uint8_t GetCRBit(const uint32_t bit) { return 1 << (3 - (bit % 4)); }

bool CPUThread::CondPassed(uint8_t bo, uint8_t bi)
Expand Down
42 changes: 41 additions & 1 deletion src/cpu/CPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ typedef struct
exit(1);
}
}

void SetCR(int num, uint32_t val)
{
switch (num)
{
case 0: CR.cr0 = val; break;
case 1: CR.cr1 = val; break;
case 2: CR.cr2 = val; break;
case 3: CR.cr3 = val; break;
case 4: CR.cr4 = val; break;
case 5: CR.cr5 = val; break;
case 6: CR.cr6 = val; break;
case 7: CR.cr7 = val; break;
default:
printf("Write to unknown CR%d\n", num);
exit(1);
}
}

template<typename T>
void UpdateCRn(T x, T y, int num)
{
if (x < y) SetCR(num, 0x8);
else if (x > y) SetCR(num, 0x4);
else SetCR(num, 0x2);
}
} cpuState_t;

/// @brief This will represent one of 6 hardware threads running at a time.
Expand All @@ -56,11 +82,25 @@ class CPUThread
CPUThread(uint32_t entryPoint, uint32_t stackSize);

void Run();
void Dump();

void SetArg(int num, uint64_t value);
private:
void cmpli(uint32_t instruction); // 10
void addi(uint32_t instruction); // 14
void addis(uint32_t instruction); // 15
void bc(uint32_t instruction); // 16
void branch(uint32_t instruction); // 18
void bclr(uint32_t instruction); // 19 16
void mfspr(uint32_t instruction); // 32 339
void rlwinm(uint32_t instruction); // 21
void ori(uint32_t instruction); // 24
void mfspr(uint32_t instruction); // 31 339
void or_(uint32_t instruction); // 31 444
void mtspr(uint32_t instruction); // 31 467
void lwz(uint32_t instruction); // 32
void stw(uint32_t instruction); // 36
void stwu(uint32_t instruction); // 37
void ld(uint32_t instruction); // 58
void std(uint32_t instruction); // 62
private:
bool CondPassed(uint8_t bo, uint8_t bi);
Expand Down
Loading

0 comments on commit 2d42614

Please sign in to comment.