Skip to content
Snippets Groups Projects
Commit ecc6e102 authored by Armin Luntzer's avatar Armin Luntzer
Browse files

ELF: must byte swap more than one header entry, d'oh!

parent b0ade261
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@
#
# kbuild trick to avoid linker error. Can be omitted if a module is built.
obj- := dummy.o
......@@ -25,24 +26,21 @@ HOSTCC := xentium-clang
HOSTLD := xentium-ld
HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -Idsp/xentium
HOSTLDFLAGS += -Tdsp/xentium/sysroot/lib/default.ld
HOSTLDFLAGS += --sysroot=dsp/xentium/sysroot
hostprogs-y := testkernel.xen
hostprogs-y += otherkernel.xen
testkernelkernel.xen :
HOSTLOADLIBES_testkernel.xen :=
testkernel.xen-objs := testkernel.o xen_printf.o
xen_dummy.xen :
HOSTLOADLIBES_xen_dummy.xen :=
xen_dummy.xen-objs := xen_dummy.o xen_printf.o
hostprogs-y := xen_dummy.xen
otherkernel.xen : testkernel.xen
HOSTLOADLIBES_otherkernel.xen := -Ttext $$(readelf -s dsp/xentium/testkernel.xen|grep -w _end |awk '{print $$2}')
otherkernel.xen-objs := testkernel.o xen_printf.o
otherkernel.xen : xen_dummy.xen
HOSTLOADLIBES_otherkernel.xen := -Ttext $$(readelf -s dsp/xentium/xen_dummy.xen|grep -w _end |awk '{print $$2}')
otherkernel.xen-objs := xen_dummy.o xen_printf.o
#hostprogs-y += otherkernel.xen
......
#include <xen_wrapper.h>
#include <xen_printf.h>
const unsigned int _crit_buf_lvl __attribute__((used)) = 1234;
int main(void)
{
int i = 0;
while (i++ < 10) {
x_printf("hello there!\n");
XEN_WAIT_CYCLES(25000000);
}
x_printf("bye\n");
#if 0
/**
* stats
*/
unsigned int elapsed = 0;
unsigned int cycles_used = 0;
unsigned int samples_processed = 0;
unsigned int samples_processed_last = 0;
unsigned int tmp_critical_words;
unsigned int uiTmpBufferCnt = 0;
volatile unsigned int msg = 0;
unsigned int *p_tmp_critical;
unsigned int *p_tmp_buffer;
unsigned int *ptBANK0 = (unsigned int *) p_xen->tcm;
unsigned int *ptBANK2 = (unsigned int *) p_xen->tcm + ((unsigned int) BANK_SIZE >> 1);
/default.ld
struct xen_data *p_xen_data;
enum {NONE, REQUEST_DATA, STORE_OUTPUT, YIELD} last_action = NONE;
XEN_WAIT_INIT(p_xen_data);
p_tmp_buffer = p_xen_data->tmp_buffer_1;
// 50% fill, Size is in words;
// @note: adjust size so this round of processing will always fit
// @note: we have two options here: check the element fill counter or do it by checking the pointer difference
// @note: both ways work, but it depends on how an AlgoLib function is constructed (we really don't want to change them if possible)
tmp_critical_words = p_xen_data->tmp_buffer_1_size >> 1;
p_tmp_critical = p_tmp_buffer + tmp_critical_words;
x_printf("Reducer @Xen %u. Critical tmp buffer state is %u\n", p_xen_data->xen_id, tmp_critical_words);
XEN_RESET_CYCLES_COUNTER();
// lead-in: fetch data
xen_request_data(p_xen_data, ptBANK0, TCM_WORDSIZE);
last_action = REQUEST_DATA;
XEN_MSG_LEON();
while(1)
{
XEN_GET_MSG(msg);
x_printf("msg\n");
elapsed = XEN_GET_CYCLES_ELAPSED();
cycles_used += elapsed;
XEN_RESET_CYCLES_COUNTER();
samples_processed += samples_processed_last;
samples_processed_last = 0;
switch(last_action) {
case YIELD:
if(msg == XEN_GO)
uiTmpBufferCnt = 0; // store was successful, reset
if(msg == XEN_WAIT) { // wait, then try to continue, setup new new data request
XEN_WAIT_CYCLES(XEN_DEFAULT_WAIT);
xen_request_data(p_xen_data, ptBANK0, TCM_WORDSIZE);
last_action = REQUEST_DATA;
break;
}
if(uiTmpBufferCnt > 0) { // try to flush
xen_req_store_data(p_xen_data, p_tmp_buffer, uiTmpBufferCnt);
last_action = YIELD;
break;
} else {
XEN_SET_CYCLES_MSG(cycles_used/samples_processed);
XEN_YIELD();
}
break;
case STORE_OUTPUT:
if(msg == XEN_WAIT) { // retry
XEN_WAIT_CYCLES(XEN_DEFAULT_WAIT);
xen_req_store_data(p_xen_data, p_tmp_buffer, uiTmpBufferCnt);
last_action = STORE_OUTPUT;
break;
}
if(msg == XEN_GO) { // success, continue processing
uiTmpBufferCnt = 0;
xen_request_data(p_xen_data, ptBANK0, TCM_WORDSIZE);
last_action = REQUEST_DATA;
break;
}
break;
case REQUEST_DATA:
if(msg == XEN_GO) { // execute kernel function
uiTmpBufferCnt += execute_this_function(ptBANK0, p_tmp_buffer, TCM_WORDSIZE);
samples_processed_last=TCM_WORDSIZE;
}
if(msg == XEN_WAIT)
XEN_WAIT_CYCLES(XEN_DEFAULT_WAIT);
if(msg == XEN_NODATA) {
XEN_WAIT_CYCLES(XEN_DEFAULT_WAIT);
if(uiTmpBufferCnt > 0) { // try to flush
xen_req_store_data(p_xen_data, p_tmp_buffer, uiTmpBufferCnt);
last_action = STORE_OUTPUT;
break;
} else { // offer to yield
XEN_SET_REQUEST(XEN_I_YIELD);
last_action = YIELD;
}
break;
}
if(uiTmpBufferCnt < tmp_critical_words) { // setup next block request
xen_request_data(p_xen_data, ptBANK0, TCM_WORDSIZE);
last_action = REQUEST_DATA;
} else { // output is critical, flush
xen_req_store_data(p_xen_data, p_tmp_buffer, uiTmpBufferCnt);
last_action = STORE_OUTPUT;
}
break;
default:
break;
}
switch(p_xen_data->ctrl_msg)
{
case XEN_PLEASEYIELD:
p_xen_data->ctrl_msg = 0;
if(uiTmpBufferCnt > 0) { // flush. takes precendence over other requests
xen_req_store_data(p_xen_data, p_tmp_buffer, uiTmpBufferCnt);
last_action = YIELD;
} else {
XEN_SET_CYCLES_MSG(cycles_used/samples_processed);
XEN_YIELD();
}
default:
break;
}
XEN_MSG_LEON();
}
#endif
return 0;
}
......@@ -172,7 +172,6 @@ void elf_hdr_endianess_swap(Elf_Ehdr *ehdr)
ehdr->e_shnum = swab16(ehdr->e_shnum);
ehdr->e_shstrndx = swab16(ehdr->e_shstrndx);
/* everything after is in 32 bit words */
phdr = (Elf_Phdr *) ((char *) ehdr + ehdr->e_phoff);
......@@ -202,13 +201,16 @@ void elf_hdr_endianess_swap(Elf_Ehdr *ehdr)
shdr[i].sh_entsize = swab32(shdr[i].sh_entsize);
}
shdr = elf_find_sec(ehdr, ".symtab");
if (shdr) {
sym = (Elf_Sym *) (((char *) ehdr) + shdr->sh_offset);
for (i = 0; i < shdr->sh_size / shdr->sh_entsize; i++)
sym[i].st_name = swab32(sym[i].st_name);
for (i = 0; i < shdr->sh_size / shdr->sh_entsize; i++) {
sym[i].st_name = swab32(sym[i].st_name);
sym[i].st_value = swab32(sym[i].st_value);
sym[i].st_size = swab32(sym[i].st_size);
sym[i].st_shndx = swab16(sym[i].st_shndx);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment