67 Commits

Author SHA1 Message Date
Ronald Caesar
9dafe44839 memory: change bal_memory_destroy_flat function signature
Function returns a bal_error_t instead of void to provide better
error handling.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-03-09 04:48:44 +00:00
Ronald Caesar
8cf79d8afe memory: update outdated doc
bal_memory_destroy_flat() frees heap allocated memory AND resets
`interface` to 0, which the docs do not specify.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-03-09 04:48:38 +00:00
Ronald Caesar
78573737d8 engine: extract BAL_LOG code to bal_log_message
Code coverage tools cannot fully cover BAL_LOG_* statements because of
the numerous if statements in BAL_LOG(). We extract the code in
BAL_LOG() to bal_log_message() to fix this issue.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-03-09 04:47:41 +00:00
Ronald Caesar
41678fad72 engine: add option to disable logging.
Adds BAL_LOG_LEVEL_NONE to to the bal_log_level_t enum. This gives users
the option to disable logging completely if BAL_LOG_LEVEL_NONE is set as
the mininum log level.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-03-09 04:47:35 +00:00
Ronald Caesar
402a303902 Merge branch 'engine-support-add' 2026-03-04 07:13:31 +00:00
Ronald Caesar
c12b8f22b3 engine: move register index enum to bal_types.h
This enum is very useful for the translation loop and including the
entirety of bal_assembler.h just to get it is not a good idea. This enum
has been moved to bal_types.h.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-03-04 07:12:49 +00:00
Ronald Caesar
7881220883 tools: remove -Werror from doctest
I truly dont if markdown code examples peoduce warnings, but those
warnings cannot make the build fail to compile.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-03-04 07:12:46 +00:00
Ronald Caesar
ef4181a25c decoder: support option bitfield for add instructions
In the ADD Extended Register encoding, bitfield "option" Bit[13:15] was
not being detected by the python script. This commit parses this
bitfield correctly. Consequently, the size of the operands array has to
be raised from 4 to 5 to support this new operand.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-03-04 07:12:38 +00:00
Ronald Caesar
6f37f21e4b engine: add imcorrect register type header
Introduces BAL_ERROR_INCORRECT_REGISTER_TYPE for incorrectly decoded
registers.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-03-04 07:10:13 +00:00
Ronald Caesar
f27d77b056 assembler: emit add immediate instructions
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-03-04 07:09:04 +00:00
Ronald Caesar
60c2f868f7 engine: fix clion warnings
I recently got a new PC with Jetbrain's Clion IDE and this commit fixes
warnings generated by Clion.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-03-02 18:02:07 +00:00
Ronald Caesar
0457321d1c engine: fix gcc errors
1. Fixes GCC warnings that do not deserve me writing an indepth
explanation on what needed to be changed.

2. The original mask calculation for OPCODE_MOV makes zero sense because
the bit width for operands[0] is always > 31. I don't know what I was
thinking when I wrote this. The mask is now set to cover 32 and 64-bit
immediate values.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-03-02 16:30:54 +00:00
Ronald Caesar
0f72fc4305 engine: add OPCODE_GET_REGISTER to opcode enum
This opcode represents a volotile load of a guest register. This is
needed to handle instructions reading register before it has been
written to within the current basic block.

For example, if `MOVK X0` is the first instruction in the basic block,
we have no IR variable representing X0 yet. So we emit
OPCODE_GET_REGISTER before MOVK. OPCODE_GET_REGISTER tells
the backend "load X0 from guest memory"

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-02-20 16:37:18 -04:00
Ronald Caesar
8d4edce80f engine: convert source size to source masks
The definition BAL_SOURCE_SIZE isnt really usefull for Ballistic. Its
mainly use to create a mask for the IR source bitfield. SoI created two
definitions to replace this: BAL_SOURCE_MASK and
BAL_SOURCE_MASK_WITH_FLAG.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-02-20 16:37:18 -04:00
Ronald Caesar
d9d6c2a630 engine: upgrade constant pool to uint64_t
The engine is built for 32-bit constants which is wrong since Ballistic
is an ARM64 recompiler. Instructions like MOVZ with LSR #32 or LSR #48
would fail.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-02-17 14:13:22 -04:00
Ronald Caesar
31fc60ecca engine: fix logging example not writing to file
The log file `jit.log` created in the bal_logging.h example was empty.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-02-17 01:51:28 -04:00
Ronald Caesar
851c78c3be assembler: remove redundant doc clause
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-02-15 19:34:47 -04:00
Ronald Caesar
fd592ea245 assembler: fix doc links
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-02-15 19:28:44 -04:00
Ronald Caesar
9ce5081561 assembler: add file level docs to bal_assembler.h
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-02-15 19:20:53 -04:00
Ronald Caesar
1a1116f7a8 build: fix all compiler warnings.
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-02-15 18:39:14 -04:00
Ronald Caesar
c5f52b1db5 assembler: wrap BAL_REGISTER_X* defines in an enum.
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-02-15 18:18:25 -04:00
Ronald Caesar
4c25091d7e assembler: add documentation to bal_assembler.h
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-02-15 18:06:02 -04:00
Ronald Caesar
6e660c21f0 assembler: add logging
Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-02-15 13:17:35 -04:00
Ronald Caesar
32f799695f assembler: add lightweight assembler
This was created to make creating instructions easier to test
Ballistic's translation loop. Documentation will be added in the
future.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-02-15 04:05:02 -04:00
Ronald Caesar
dc53cc31a1 github: impove actions build system
Add clang-format checking plus some other small things.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2026-02-14 20:56:36 -04:00