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 b0d4ae0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 12 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
18 changes: 6 additions & 12 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 All @@ -124,7 +118,7 @@ pub fn make_state<T: EndianParse>(file: ElfBytes<T>) -> Result<State, String> {

// Entry point of the program
let pc: u32 = file.ehdr.e_entry as u32;
assert!(pc != 0, "Entry point is 0. The documentation of the ELF library says that it means the ELF doesn't have an entry point. This is not supported.");
assert!(pc != 0, "Entry point is 0. The documentation of the ELF library says that it means the ELF doesn't have an entry point. This is not supported. This can happen if the binary given is an object file and not an executable file. You might need to call the linker (ld) before running the binary.");
let next_pc: u32 = pc + 4u32;

let state = State {
Expand Down

0 comments on commit b0d4ae0

Please sign in to comment.