Skip to content

Commit

Permalink
more misc
Browse files Browse the repository at this point in the history
  • Loading branch information
neuschaefer committed Dec 18, 2023
1 parent e3ef81c commit e204aa5
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 37 deletions.
9 changes: 9 additions & 0 deletions .forgejo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Forgejo/Gitea Actions CI setup

- run `docker build . -t jzvm` in the repository root directory
- Install [forgejo-runner] on a machine, and follow the [setup guide]
- Add the runner to your Codeberg/Forgejo/Gitea repo (Settings -> Actions -> Runners)

[forgejo-runner]: https://code.forgejo.org/forgejo/runner/
[setup guide]: https://forgejo.org/docs/next/admin/actions/#forgejo-runner

17 changes: 0 additions & 17 deletions .forgejo/workflows/arm926.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .forgejo/workflows/forgejo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
on: [push]
jobs:
arm926:
runs-on:
# Specifying multiple entries under "runs-on" doesn't seem to work at the moment.
- linux-arm926
container:
# To speed things up, we use a custom base image. See .forgejo/Dockerfile
image: jzvm
steps:
# Unfortunately, actions are written in Node.js, which doesn't run on ARMv5[1],
# so we can't use actions.
# [1]: https://packages.debian.org/bookworm/nodejs "dep: armv6k-support"
#- uses: actions/checkout@v3

- run: |
git clone "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" -b "$GITHUB_REF_NAME" jzvm
cd jzvm
git reset --hard "$GITHUB_SHA"
cp -r /jzvm/target .
- run: cd jzvm && cargo run
- run: cd jzvm && cargo test
- run: cd jzvm && cargo test --release

arm1176:
runs-on:
- linux-arm1176
container:
image: jzvm
steps:
- run: |
git clone "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" -b "$GITHUB_REF_NAME" jzvm
cd jzvm
git reset --hard "$GITHUB_SHA"
cp -r /jzvm/target .
- run: cd jzvm && cargo run
- run: cd jzvm && cargo test
- run: cd jzvm && cargo test --release
16 changes: 16 additions & 0 deletions .github/workflows/github.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on: [push]
jobs:
debug:
runs-on: ubuntu-latest
steps:
- run: sudo apt-get update && sudo apt-get install -y git cargo
- uses: actions/checkout@v3
- run: cargo run
- run: cargo test
release:
runs-on: ubuntu-latest
steps:
- run: sudo apt-get update && sudo apt-get install -y git cargo
- uses: actions/checkout@v3
- run: cargo run --release
- run: cargo test --release
9 changes: 0 additions & 9 deletions .github/workflows/x86.yml

This file was deleted.

9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# See .forgejo/README.md
FROM debian:trixie

RUN apt-get -o APT::Sandbox::User=root update && apt-get -o APT::Sandbox::User=root install -y rustc cargo git

ADD . /jzvm
WORKDIR /jzvm

RUN cargo build --all-targets && cargo build --all-targets --release
4 changes: 4 additions & 0 deletions src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ pub enum Implementation {

/// ARM926EJ-S, my beloved
ARM926,

/// ARM1176, as found in early Raspberry Pis
ARM1176,
}

impl From<u32> for Implementation {
fn from(id: u32) -> Implementation {
match id {
0x64100004 => Implementation::ARM926,
0x74100064 => Implementation::ARM1176,
0x00000000 => Implementation::Trivial,
_ => Implementation::Unknown,
}
Expand Down
10 changes: 2 additions & 8 deletions src/exec/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,11 @@ impl ARMExecutor {
}

impl Executor for ARMExecutor {
// TODO: change to Ctx API
//fn execute(&self, state: &mut State) -> ExitCondition {
#[allow(named_asm_labels)]
unsafe fn execute(&mut self, ctx: &mut Context, state: &mut State) -> Result<(), ExitCondition> {
self.check();

// TODO: build handler table here
println!("[execute] handlers @ {:?}", self.handler_table.0.as_ptr());
println!("[execute] stack @ {:?}", ctx.stack.as_ptr());
println!("[execute] stackptr @ {:?}", state.sp);

for i in 0..self.handler_table.0.len() {
// TODO: implement a proper handler exit path
self.handler_table.0[i] = 0x0dead000 | (i as u32) << 4;
}

Expand Down Expand Up @@ -161,6 +154,7 @@ impl Executor for ARMExecutor {

"bxj r12",

"fooo:",
"100:", // Opcode handler
"mov r1, #0x100",
"ldrb r0, [lr]",
Expand Down
6 changes: 5 additions & 1 deletion src/exec/emu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ fn fetch_u8(ctx: &Context, pc: usize) -> Result<u8, ExitCondition> {
Ok(*ptr)
}

fn i2us(i: i32) -> usize {
i as u32 as usize
}

impl Executor for EmulationExecutor {
unsafe fn execute(&mut self, ctx: &mut Context, state: &mut State) -> Result<(), ExitCondition> {
loop {
Expand All @@ -27,7 +31,7 @@ impl Executor for EmulationExecutor {
state.sp += 1;
},
op::iconst_m1 => {
ctx.stack[state.sp] = -1i32 as usize; //JReference::null().into(),
ctx.stack[state.sp] = i2us(-1);
state.sp += 1;
},
op::iconst_2 => {
Expand Down
163 changes: 163 additions & 0 deletions src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,170 @@ pub const fload_0: u8 = 0x22;
pub const fload_1: u8 = 0x23;
pub const fload_2: u8 = 0x24;
pub const fload_3: u8 = 0x25;
pub const dload_0: u8 = 0x26;
pub const dload_1: u8 = 0x27;
pub const dload_2: u8 = 0x28;
pub const dload_3: u8 = 0x29;
pub const aload_0: u8 = 0x2a;
pub const aload_1: u8 = 0x2b;
pub const aload_2: u8 = 0x2c;
pub const aload_3: u8 = 0x2d;
pub const iaload: u8 = 0x2e;
pub const laload: u8 = 0x2f;
pub const faload: u8 = 0x30;
pub const daload: u8 = 0x31;
pub const aaload: u8 = 0x32;
pub const baload: u8 = 0x33;
pub const caload: u8 = 0x34;
pub const saload: u8 = 0x35;
pub const istore: u8 = 0x36;
pub const lstore: u8 = 0x37;
pub const fstore: u8 = 0x38;
pub const dstore: u8 = 0x39;
pub const astore: u8 = 0x3a;
pub const istore_0: u8 = 0x3b;
pub const istore_1: u8 = 0x3c;
pub const istore_2: u8 = 0x3d;
pub const istore_3: u8 = 0x3e;
pub const lstore_0: u8 = 0x3f;
pub const lstore_1: u8 = 0x40;
pub const lstore_2: u8 = 0x41;
pub const lstore_3: u8 = 0x42;
pub const fstore_0: u8 = 0x43;
pub const fstore_1: u8 = 0x44;
pub const fstore_2: u8 = 0x45;
pub const fstore_3: u8 = 0x46;
pub const dstore_0: u8 = 0x47;
pub const dstore_1: u8 = 0x48;
pub const dstore_2: u8 = 0x49;
pub const dstore_3: u8 = 0x4a;
pub const astore_0: u8 = 0x4b;
pub const astore_1: u8 = 0x4c;
pub const astore_2: u8 = 0x4d;
pub const astore_3: u8 = 0x4e;
pub const iastore: u8 = 0x4f;
pub const lastore: u8 = 0x50;
pub const fastore: u8 = 0x51;
pub const dastore: u8 = 0x52;
pub const aastore: u8 = 0x53;
pub const bastore: u8 = 0x54;
pub const castore: u8 = 0x55;
pub const sastore: u8 = 0x56;
pub const pop: u8 = 0x57;
pub const pop2: u8 = 0x58;
pub const dup: u8 = 0x59;
pub const dup_x1: u8 = 0x5a;
pub const dup_x2: u8 = 0x5b;
pub const dup2: u8 = 0x5c;
pub const dup2_x1: u8 = 0x5d;
pub const dup2_x2: u8 = 0x5e;
pub const swap: u8 = 0x5f;
pub const iadd: u8 = 0x60;
pub const ladd: u8 = 0x61;
pub const fadd: u8 = 0x62;
pub const dadd: u8 = 0x63;
pub const isub: u8 = 0x64;
pub const lsub: u8 = 0x65;
pub const fsub: u8 = 0x66;
pub const dsub: u8 = 0x67;
pub const imul: u8 = 0x68;
pub const lmul: u8 = 0x69;
pub const fmul: u8 = 0x6a;
pub const dmul: u8 = 0x6b;
pub const idiv: u8 = 0x6c;
pub const ldiv: u8 = 0x6d;
pub const fdiv: u8 = 0x6e;
pub const ddiv: u8 = 0x6f;
pub const irem: u8 = 0x70;
pub const lrem: u8 = 0x71;
pub const frem: u8 = 0x72;
pub const drem: u8 = 0x73;
pub const ineg: u8 = 0x74;
pub const lneg: u8 = 0x75;
pub const fneg: u8 = 0x76;
pub const dneg: u8 = 0x77;
pub const ishl: u8 = 0x78;
pub const lshl: u8 = 0x79;
pub const ishr: u8 = 0x7a;
pub const lshr: u8 = 0x7b;
pub const iushr: u8 = 0x7c;
pub const lushr: u8 = 0x7d;
pub const iand: u8 = 0x7e;
pub const land: u8 = 0x7f;
pub const ior: u8 = 0x80;
pub const lor: u8 = 0x81;
pub const ixor: u8 = 0x82;
pub const lxor: u8 = 0x83;
pub const iinc: u8 = 0x84;
pub const i2l: u8 = 0x85;
pub const i2f: u8 = 0x86;
pub const i2d: u8 = 0x87;
pub const l2i: u8 = 0x88;
pub const l2f: u8 = 0x89;
pub const l2d: u8 = 0x8a;
pub const f2i: u8 = 0x8b;
pub const f2l: u8 = 0x8c;
pub const f2d: u8 = 0x8d;
pub const d2i: u8 = 0x8e;
pub const d2l: u8 = 0x8f;
pub const d2f: u8 = 0x90;
pub const i2b: u8 = 0x91;
pub const i2c: u8 = 0x92;
pub const i2s: u8 = 0x93;
pub const lcmp: u8 = 0x94;
pub const fcmpl: u8 = 0x95;
pub const fcmpg: u8 = 0x96;
pub const dcmpl: u8 = 0x97;
pub const dcmpg: u8 = 0x98;
pub const ifeq: u8 = 0x99;
pub const ifne: u8 = 0x9a;
pub const iflt: u8 = 0x9b;
pub const ifge: u8 = 0x9c;
pub const ifgt: u8 = 0x9d;
pub const ifle: u8 = 0x9e;
pub const if_icmpeq: u8 = 0x9f;
pub const if_icmpne: u8 = 0xa0;
pub const if_icmplt: u8 = 0xa1;
pub const if_icmpge: u8 = 0xa2;
pub const if_icmpgt: u8 = 0xa3;
pub const if_icmple: u8 = 0xa4;
pub const if_acmpeq: u8 = 0xa5;
pub const if_acmpne: u8 = 0xa6;
pub const goto: u8 = 0xa7;
pub const jsr: u8 = 0xa8;
pub const ret: u8 = 0xa9;
pub const tableswitch: u8 = 0xaa;
pub const lookupswitch: u8 = 0xab;
pub const ireturn: u8 = 0xac;
pub const lreturn: u8 = 0xad;
pub const freturn: u8 = 0xae;
pub const dreturn: u8 = 0xaf;
pub const areturn: u8 = 0xb0;
pub const return_: u8 = 0xb1;
pub const getstatic: u8 = 0xb2;
pub const putstatic: u8 = 0xb3;
pub const getfield: u8 = 0xb4;
pub const putfield: u8 = 0xb5;
pub const invokevirtual: u8 = 0xb6;
pub const invokespecial: u8 = 0xb7;
pub const invokestatic: u8 = 0xb8;
pub const invokeinterface: u8 = 0xb9;
pub const invokedynamic: u8 = 0xba;
pub const new: u8 = 0xbb;
pub const newarray: u8 = 0xbc;
pub const anewarray: u8 = 0xbd;
pub const arraylength: u8 = 0xbe;
pub const athrow: u8 = 0xbf;
pub const checkcast: u8 = 0xc0;
pub const instanceof: u8 = 0xc1;
pub const monitorenter: u8 = 0xc2;
pub const monitorexit: u8 = 0xc3;
pub const wide: u8 = 0xc4;
pub const multianewarray: u8 = 0xc5;
pub const ifnull: u8 = 0xc6;
pub const ifnotnull: u8 = 0xc7;
pub const goto_w: u8 = 0xc8;
pub const jsr_w: u8 = 0xc9;
pub const breakpoint: u8 = 0xca;
pub const impdep1: u8 = 0xfe;
pub const impdep2: u8 = 0xff;
1 change: 1 addition & 0 deletions tests/exec/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//use jzvm::exec;

#[test]
#[ignore]
fn demand_paging() {
// allocate a page but don't populate it (mmap(anon))
// use this page as stack
Expand Down
2 changes: 0 additions & 2 deletions tests/exec/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ impl TestVM {
}

#[test]
#[ignore]
fn test_00_nop() {
let mut exec = exec::new().unwrap();
let pre = TestVM::from_code(vec![op::nop, op::breakpoint]);
Expand All @@ -54,7 +53,6 @@ fn test_00_nop() {
}

#[test]
#[ignore]
fn test_01_aconst_null() {
let mut exec = exec::new().unwrap();
let pre = TestVM::from_code(vec![op::aconst_null, op::breakpoint]);
Expand Down

0 comments on commit e204aa5

Please sign in to comment.