Skip to content

Commit

Permalink
test elf loader in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Dec 26, 2024
1 parent 0d2c910 commit 240ad63
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/mips-build.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
name: MIPS Build and Package

on:
workflow_dispatch:
workflow_dispatch:
pull_request:
push:
paths:
paths:
- 'o1vm/resources/programs/mips/**'
- 'Makefile'

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
rust_toolchain_version: ["1.74"]

steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Cache apt packages
id: apt-cache
uses: actions/cache@v4
Expand All @@ -24,7 +28,7 @@ jobs:
/var/lib/apt/lists
/var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('.github/workflows/mips-build.yml') }}

- name: Install MIPS tools
run: |
sudo apt-get update
Expand All @@ -33,6 +37,14 @@ jobs:
- name: Build MIPS programs
run: make build-mips-programs

- name: Use shared Rust toolchain setting up steps
uses: ./.github/actions/toolchain-shared
with:
rust_toolchain_version: ${{ matrix.rust_toolchain_version }}

- name: Test elf_loader against mips programs
run: ./o1vm/test-gen-state-json.sh

- name: Create tar archive
run: |
cd o1vm/resources/programs/mips
Expand All @@ -42,4 +54,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: mips-binaries
path: o1vm/resources/programs/mips/mips-binaries.tar.gz
path: o1vm/resources/programs/mips/mips-binaries.tar.gz
16 changes: 5 additions & 11 deletions o1vm/src/elf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,16 @@ pub fn make_state<T: EndianParse>(file: ElfBytes<T>) -> Result<State, String> {
.copy_from_slice(&text_section_data[0..data_length]);
data_offset += data_length;
} else {
let data_length = if page_index == last_page_index {
code_section_end_address - end_page_address
} else {
page_size_usize
};
let page_offset = if page_index == first_page_index {
code_section_starting_address - start_page_address
} else {
0
};
let data_length = if page_index == last_page_index {
let data_length = code_section_end_address - end_page_address;
// for the last page, we might need to pad with zeros if the text_section_data is not
// a multiple of the page size.
if page_size_usize > data_length {
data[page_offset + data_length..page_offset + page_size_usize].fill(0);
}
data_length
} else {
page_size_usize
};
data[page_offset..page_offset + data_length]
.copy_from_slice(&text_section_data[data_offset..data_offset + data_length]);

Expand Down

0 comments on commit 240ad63

Please sign in to comment.