Skip to content

Commit

Permalink
finalizing big endian
Browse files Browse the repository at this point in the history
  • Loading branch information
aodinokov committed Aug 17, 2024
1 parent f928b9e commit 11f6601
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 125 deletions.
189 changes: 95 additions & 94 deletions .github/workflows/buildAndTest.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,72 @@
on: [push, pull_request]
name: BuildAndTest
jobs:
# ubuntu:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# include:
# - { go-version: 1.22.x, dwarf-version: 3}
# - { go-version: 1.22.x, dwarf-version: 4}
# - { go-version: 1.22.x, dwarf-version: 5}
ubuntu:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- { go-version: 1.22.x, dwarf-version: 3}
- { go-version: 1.22.x, dwarf-version: 4}
- { go-version: 1.22.x, dwarf-version: 5}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: prerequisites # ubuntu speicific
run: sudo apt-get install check
- name: Checkout code
uses: actions/checkout@v3
- name: Test
env:
GO111MODULE: on
run: go test -cover ./...
- name: Build
run: go build
- name: Examples test
run: make test all DWARF_VER_FORCE=${{matrix.dwarf-version}}

# ubuntu_big_endian:
# # pretty slow since it's running on qemu. we may disable it periodically
# # taken from https://github.com/marketplace/actions/run-on-architecture
# # s390x is big endian with Ubuntu_latest which
# # also has go-lang for linux: https://go.dev/dl/
# # https://go.dev/dl/go1.23.0.linux-s390x.tar.gz
# # GO_TELEMETRY_CHILD=off
# # The host should always be Linux.
# runs-on: ubuntu-22.04
# name: ubuntu (s390x - big endian)
# steps:
# - name: Install Go
# uses: actions/setup-go@v3
# with:
# go-version: ${{ matrix.go-version }}
# - name: prerequisites # ubuntu speicific
# run: sudo apt-get install check
# - name: Checkout code
# uses: actions/checkout@v3
# - name: Test
# env:
# GO111MODULE: on
# run: go test -cover ./...
# - name: Build
# run: go build
# - name: Examples test
# run: make test all DWARF_VER_FORCE=${{matrix.dwarf-version}}
# - uses: actions/checkout@v4
# - name: Download Go
# run: curl -fsSL -o go.tar.gz https://go.dev/dl/go1.22.0.linux-s390x.tar.gz
# - uses: uraimo/run-on-arch-action@v2
# name: Run commands
# id: runcmd
# with:
# arch: s390x
# distro: ubuntu_latest

# # Not required, but speeds up builds by storing container images in
# # a GitHub package registry.
# githubToken: ${{ github.token }}

# # Set an output parameter `uname` for use in subsequent steps
# run: |
# set -x
# uname -a
# apt update && apt-get install -y ca-certificates pkg-config make gcc g++ check # todo: libffi-dev

# tar -C /usr/local -xzf go.tar.gz && rm go.tar.gz
# export PATH=$PATH:/usr/local/go/bin
# go version

# export GO111MODULE=on
# go test -cover ./...
# go build

# make test all

macos:
runs-on: macos-latest
Expand All @@ -50,74 +91,34 @@ jobs:
- name: Examples test
run: make test all

# windows:
# runs-on: windows-latest
# strategy:
# matrix:
# include:
# - { go-version: 1.22.x, sys: mingw64, env: x86_64 }
# defaults:
# run:
# shell: msys2 {0}
# steps:
# - name: Install Go
# uses: actions/setup-go@v3
# with:
# go-version: ${{ matrix.go-version }}
# - name: prerequisites # Windows speicific
# uses: msys2/setup-msys2@v2
# with:
# msystem: ${{matrix.sys}}
# update: true
# install: base-devel git pkg-config mingw-w64-${{matrix.env}}-check mingw-w64-${{matrix.env}}-toolchain
# path-type: inherit # to be able to find go
# - name: Checkout code
# uses: actions/checkout@v3
# - name: Test
# env:
# GO111MODULE: on
# run: go test -cover ./...
# - name: Build
# run: go build
# - name: Examples test
# run: make test all

big_endian_job:
# taken from https://github.com/marketplace/actions/run-on-architecture
# s390x is big endian with Ubuntu_latest which
# also has go-lang for linux: https://go.dev/dl/
# https://go.dev/dl/go1.23.0.linux-s390x.tar.gz
# GO_TELEMETRY_CHILD=off
# The host should always be Linux.
runs-on: ubuntu-22.04
name: ubuntu (s390x - big endian)
windows:
runs-on: windows-latest
strategy:
matrix:
include:
- { go-version: 1.22.x, sys: mingw64, env: x86_64 }
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v4
- name: Downloadin Go
run: curl -fsSL -o go.tar.gz https://go.dev/dl/go1.22.0.linux-s390x.tar.gz
- uses: uraimo/run-on-arch-action@v2
name: Run commands
id: runcmd
with:
arch: s390x
distro: ubuntu_latest

# Not required, but speeds up builds by storing container images in
# a GitHub package registry.
githubToken: ${{ github.token }}

# Set an output parameter `uname` for use in subsequent steps
run: |
set -x
uname -a
apt update && apt-get install -y ca-certificates pkg-config make gcc g++ check # todo: libffi-dev
tar -C /usr/local -xzf go.tar.gz && rm go.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version
export GO111MODULE=on
go test -cover ./...
go build
make test all
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: prerequisites # Windows speicific
uses: msys2/setup-msys2@v2
with:
msystem: ${{matrix.sys}}
update: true
install: base-devel git pkg-config mingw-w64-${{matrix.env}}-check mingw-w64-${{matrix.env}}-toolchain
path-type: inherit # to be able to find go in PATH
- name: Checkout code
uses: actions/checkout@v3
- name: Test
env:
GO111MODULE: on
run: go test -cover ./...
- name: Build
run: go build
- name: Examples test
run: make test all
2 changes: 0 additions & 2 deletions src/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,10 @@ int metac_entry_member_bitfield_offsets(metac_entry_t *p_memb_entry,
*p_bit_offset = _data_bit_offset & 0x7;
} else if (p_memb_entry->member_info.p_data_bit_offset != NULL) { /* dwarf 4 */
// in data

metac_offset_t _data_bit_offset = *p_memb_entry->member_info.p_data_bit_offset;
*p_bit_size = p_memb_entry->member_info.p_bit_size != NULL?(*p_memb_entry->member_info.p_bit_size): 0;

// out

*p_byte_offset = _data_bit_offset >> 3;
*p_bit_offset = _data_bit_offset & 0x7;
}
Expand Down
18 changes: 2 additions & 16 deletions src/value.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,9 @@ static int _entry_bitfield_read(metac_entry_t *p_memb_entry, void * base_addr, v
// TODO: make it without extra copy if possible
// TODO: need to make it for both endians
assert(bit_size != 0);
memcpy(buf, base_addr, (bit_offset + bit_size-1)/8 +1);
memcpy(buf, base_addr, (bit_offset + bit_size - 1)/8 + 1);
base_addr = buf;
} else {
// assert(metac_entry_parent_count(p_memb_entry) == 1);
// metac_entry_t * p_memb_parent = metac_entry_parent_entry(p_memb_entry, 0);
// assert(p_memb_parent != NULL);
// metac_size_t parent_byte_size = 0;
// _check_(metac_entry_byte_size(p_memb_parent, &parent_byte_size) != 0, -(EFAULT));
// assert(parent_byte_size > 0);
// base_addr += parent_byte_size - byte_offset;
base_addr += byte_offset;
bit_offset = 8 * var_size - (bit_offset + bit_size);
}
Expand Down Expand Up @@ -196,16 +189,9 @@ static int _entry_bitfield_write(metac_entry_t *p_memb_entry, void * base_addr,
// TODO: need to make it for both endians
assert(bit_size != 0);
base_addr_orig = base_addr;
memcpy(buf, base_addr, (bit_offset + bit_size-1)/8 +1);
memcpy(buf, base_addr, (bit_offset + bit_size - 1)/8 + 1);
base_addr = buf;
} else {
// assert(metac_entry_parent_count(p_memb_entry) == 1);
// metac_entry_t * p_memb_parent = metac_entry_parent_entry(p_memb_entry, 0);
// assert(p_memb_parent != NULL);
// metac_size_t parent_byte_size = 0;
// _check_(metac_entry_byte_size(p_memb_parent, &parent_byte_size) != 0, -(EFAULT));
// assert(parent_byte_size > 0);
// base_addr += parent_byte_size - byte_offset;
base_addr += byte_offset;
bit_offset = 8 * var_size - (bit_offset + bit_size);
}
Expand Down
26 changes: 13 additions & 13 deletions src/value_bitfields_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#include "value_with_args.c"

// uncomment the next line if the test doesn't work
// #define PRECHECK_DEBUG
#define PRECHECK_DEBUG
struct {
char a:6;
char a:2;
char b:3;
char c:5; // goes beyond the first char (shoud be moved to the next byte by compiler)
char c:3; // goes beyond the first char (shoud be moved to the next byte by compiler)
int x: 10;
long z: 22;
}precheck_struct;
Expand All @@ -27,9 +27,9 @@ METAC_GSYM_LINK(precheck_struct);
int i; \
unsigned char * p = (unsigned char *)_start_; \
for (i=0; i<(_size_); i++) { \
printf("%02x ", (int)*p++); \
fprintf(stderr, "%02x ", (int)*p++); \
} \
printf("\n"); \
fprintf(stderr, "\n"); \
}while(0)

METAC_START_TEST(pre_check) {
Expand All @@ -52,7 +52,7 @@ METAC_START_TEST(pre_check) {
metac_offset_t bit_size;
if (p_mem_entry->member_info.p_bit_offset != NULL) {
#ifdef PRECHECK_DEBUG
printf("DWARF 3, LE %d\n", (int)IS_LITTLE_ENDIAN);
fprintf(stderr, "DWARF 3, LE %d\n", (int)IS_LITTLE_ENDIAN);
#endif
metac_offset_t _bit_size = (p_mem_entry->member_info.p_bit_size?(*p_mem_entry->member_info.p_bit_size):0),
_bit_offset = (p_mem_entry->member_info.p_bit_offset?(*p_mem_entry->member_info.p_bit_offset):0),
Expand All @@ -62,21 +62,21 @@ METAC_START_TEST(pre_check) {
bit_offset = _data_bit_offset & 0x7;
bit_size = _bit_size;
#ifdef PRECHECK_DEBUG
printf("fld %4s, bit_offset %d, bit_size %d, location %d byte_size %d=> byte_offset %d, bit_offset %d bit_size %d\n",
fprintf(stderr, "fld %4s, bit_offset %d, bit_size %d, location %d byte_size %d=> byte_offset %d, bit_offset %d bit_size %d\n",
p_mem_entry->name, (int)(_bit_offset), (int)_bit_size, (int)p_mem_entry->member_info.byte_offset, (int)_byte_size,
(int)byte_offset, (int)bit_offset, (int)bit_size);
#endif
} else if (p_mem_entry->member_info.p_data_bit_offset != NULL) { // test DWARF 4 approach
#ifdef PRECHECK_DEBUG
printf("DWARF 4, LE %d\n", (int)IS_LITTLE_ENDIAN);
fprintf(stderr, "DWARF 4, LE %d\n", (int)IS_LITTLE_ENDIAN);
#endif
metac_offset_t _data_bit_offset = *p_mem_entry->member_info.p_data_bit_offset;
metac_offset_t _bit_size = p_mem_entry->member_info.p_bit_size != NULL?(*p_mem_entry->member_info.p_bit_size): 0;
byte_offset = _data_bit_offset >> 3;
bit_offset = _data_bit_offset & 0x7;
bit_size = _bit_size;
#ifdef PRECHECK_DEBUG
printf("fld %4s, data_bit_offset %d, bit_size %d => byte_offset %d, bit_offset %d bit_size %d\n",
fprintf(stderr, "fld %4s, data_bit_offset %d, bit_size %d => byte_offset %d, bit_offset %d bit_size %d\n",
p_mem_entry->name, (int)(_data_bit_offset), (int)bit_size,
(int)byte_offset, (int)bit_offset, (int)bit_size);
#endif
Expand All @@ -96,13 +96,13 @@ METAC_START_TEST(pre_check) {
}
do {
#ifdef PRECHECK_DEBUG
printf("value %d: ", (int)precheck_struct.a);
fprintf(stderr, "value %d: ", (int)precheck_struct.a);
DUMP_MEM(&precheck_struct, sizeof(precheck_struct));
#endif
fail_unless(base_addr != NULL, "based addr mustn't be NULL");
char data = *((char*)base_addr);
#ifdef PRECHECK_DEBUG
printf("read %x, bit_offset %x, mask %x => %x\n", (int)data, (int)bit_offset,
fprintf(stderr, "read %x, bit_offset %x, mask %x => %x\n", (int)data, (int)bit_offset,
(int)((1 << bit_size) - 1),
(int)(data >> bit_offset) & ((1 << bit_size) - 1));
#endif
Expand All @@ -127,13 +127,13 @@ METAC_START_TEST(pre_check) {
}
do {
#ifdef PRECHECK_DEBUG
printf("value %d: ", (int)precheck_struct.c);
fprintf(stderr, "value %d: ", (int)precheck_struct.c);
DUMP_MEM(&precheck_struct, sizeof(precheck_struct));
#endif
fail_unless(base_addr != NULL, "based addr mustn't be NULL");
char data = *((char*)base_addr);
#ifdef PRECHECK_DEBUG
printf("read %x, bit_offset %x, mask %x => %x\n", (int)data, (int)bit_offset,
fprintf(stderr, "read %x, bit_offset %x, mask %x => %x\n", (int)data, (int)bit_offset,
(int)((1 << bit_size) - 1),
(int)(data >> bit_offset) & ((1 << bit_size) - 1));
#endif
Expand Down

0 comments on commit 11f6601

Please sign in to comment.