Skip to content

Commit

Permalink
add mips-build job, remove dead coe in elf_loader
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Dec 26, 2024
1 parent 5fc0c95 commit 9485af0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/mips-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: MIPS Build and Package

on:
workflow_dispatch:
push:
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
with:
path: |
/var/cache/apt/archives/*.deb
key: ${{ runner.os }}-apt-${{ hashFiles('.github/workflows/mips-build.yml') }}

- name: Install MIPS tools
run: |
sudo apt-get update
sudo apt-get install -y binutils-mips-linux-gnu
- 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
tar -czf mips-binaries.tar.gz bin/
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: mips-binaries
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 9485af0

Please sign in to comment.