Another Zico logging variant, using sprintf. The following code does not add timestamps.
sprintf can be found by looking up the reference to this string:
LOG(%5d):%5u.%02usec(0x%04x)
# xtensa-elf-as try1.s -o try1.o
# xtensa-elf-objcopy -O binary try1.o try1.bin
# to check generated code: xtensa-elf-objdump -d try1.o
.text
.begin
.align 4
j myhack
.align 4
.literal_position
_sprintf: # stub address
.word 0x80A28918
mybuf: # buffer somewhere in memory - there will be issues with xtensa side caches though
.word 0x1feb2400
bufsize: # size of buffer (0x200 is the safety margin)
.word 0x5ff02600 - 0x5feb2400 - 0x200
ptr: # buffer pointer is kept at this address, Xtensa data memory
.word 0xbff07ffc
myhack:
entry a1, 64 # note: usable area seems 32 bytes less than this due to space reserved for saved registers, when using call8 (caller or callee?)
# call12 (caller or callee?) further reduces the usable amount (-16 bytes)
l32r a8, ptr
l32i a15, a8, 0
l32r a9, bufsize
sub a9, a9, a15
bgez a9, lab1
movi a15, 0
lab1:
l32r a10, mybuf
add a10, a10, a15
l32r a8, _sprintf
mov a11, a2
mov a12, a3
mov a3, a15 # backup pointer val
mov a13, a4
mov a14, a5
mov a15, a6
s32i a7, a1, 0
l32i a2, a1, 64
s32i a2, a1, 4
l32i a2, a1, 68
s32i a2, a1, 8
l32i a2, a1, 72
s32i a2, a1, 12
l32i a2, a1, 76
s32i a2, a1, 16
callx8 a8
mov a11, a3 # restore pointer
add a11, a11, a10
l32r a12, ptr
s32i a11, a12, 0
mov a2, a10
retw
.end
unsigned char rawData[98] = {
0x06, 0x04, 0x00, 0x00, 0x18, 0x89, 0xA2, 0x80, 0x00, 0x24, 0xEB, 0x1F,
0x00, 0x00, 0x05, 0x00, 0xFC, 0x7F, 0xF0, 0xBF, 0x36, 0x81, 0x00, 0x81,
0xFE, 0xFF, 0xF8, 0x08, 0x91, 0xFC, 0xFF, 0xF0, 0x99, 0xC0, 0xD6, 0x29,
0x00, 0xF2, 0xA0, 0x00, 0xA1, 0xF8, 0xFF, 0xFA, 0xAA, 0x81, 0xF5, 0xFF,
0xBD, 0x02, 0xCD, 0x03, 0x3D, 0x0F, 0xDD, 0x04, 0xED, 0x05, 0xFD, 0x06,
0x79, 0x01, 0x22, 0x21, 0x10, 0x29, 0x11, 0x22, 0x21, 0x11, 0x29, 0x21,
0x22, 0x21, 0x12, 0x29, 0x31, 0x22, 0x21, 0x13, 0x29, 0x41, 0xE0, 0x08,
0x00, 0xBD, 0x03, 0xAA, 0xBB, 0xC1, 0xED, 0xFF, 0xB9, 0x0C, 0x2D, 0x0A,
0x1D, 0xF0
};
zico_mem=0xbff27940 -- free space in zico code memory
zico_dbg_ptr=0x40c13538 -- 0xc13538 in xtensa
call_event_proc("System.Create")
buf=call_event_proc("AllocateMemory",1024)
imgfile=call_event_proc("Fopen_Fut","A/demo.bin","rb")
call_event_proc("Fread_Fut",buf,1024,1,imgfile)
call_event_proc("Fclose_Fut",imgfile)
call_event_proc("memcpy",zico_mem,buf,1024)
call_event_proc("FreeMemory",buf)
poke(0xbff07ffc,0) -- clear our debug counter (used by our xtensa binary)
poke(zico_dbg_ptr,zico_mem) -- this might crash zico in case of caching issues
edit:
Binary fixed to correspond to source. The 4 constants of code (which are model specific) can be found in binary at offset 4.
edit2:
fix the entry instruction (80 -> 64, stack arguments were not picked up correctly due to that)