Kodewerx

Our culture has advanced beyond all that you could possibly comprehend with one hundred percent of your brain.
It is currently Thu Mar 28, 2024 7:24 am

All times are UTC - 8 hours [ DST ]


Forum rules


Discussion of illegal hacking/cracking is prohibited. (No virus/trojans/cracks/warez/etc allowed.)



Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sun Nov 22, 2009 11:30 pm 
Offline
Komrade
Komrade
User avatar

Joined: Tue Mar 27, 2007 6:23 pm
Posts: 1354
Location: Mario Raceway, 1509.831, 217.198, -564.429
Title: Mario Kart 64 Hacker
I've compiled binutils for MIPS and I can assemble just fine, but using objcopy to dump the raw binary is not working.
Input file:
Code:
.ascii "ohai thar"
.align 2
ADDIU $zero, $zero, 0x1234
Run through:
Code:
mips-unknown-linux-gnu-as -EB -march=vr4300 -mtune=vr4300 --warn test.asm -o test.elf
test.elf is:
Code:
00000000  7f 45 4c 46 01 02 01 00  00 00 00 00 00 00 00 00  |.ELF............|
00000010  00 01 00 08 00 00 00 01  00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 a4 20 00 11 00  00 34 00 00 00 00 00 28  |.... ....4.....(|
00000030  00 09 00 06 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000040  6f 68 61 69 20 74 68 61  72 00 00 00 24 00 12 34  |ohai thar...$..4|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000060  00 00 00 00 00 00 00 00  00 2e 73 79 6d 74 61 62  |..........symtab|
00000070  00 2e 73 74 72 74 61 62  00 2e 73 68 73 74 72 74  |..strtab..shstrt|
00000080  61 62 00 2e 74 65 78 74  00 2e 64 61 74 61 00 2e  |ab..text..data..|
00000090  62 73 73 00 2e 72 65 67  69 6e 66 6f 00 2e 70 64  |bss..reginfo..pd|
000000a0  72 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |r...............|
000000b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 1b  |................|
000000d0  00 00 00 01 00 00 00 06  00 00 00 00 00 00 00 40  |...............@|
000000e0  00 00 00 10 00 00 00 00  00 00 00 00 00 00 00 10  |................|
000000f0  00 00 00 00 00 00 00 21  00 00 00 01 00 00 00 03  |.......!........|
00000100  00 00 00 00 00 00 00 50  00 00 00 00 00 00 00 00  |.......P........|
00000110  00 00 00 00 00 00 00 10  00 00 00 00 00 00 00 27  |...............'|
00000120  00 00 00 08 00 00 00 03  00 00 00 00 00 00 00 50  |...............P|
00000130  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 10  |................|
00000140  00 00 00 00 00 00 00 2c  70 00 00 06 00 00 00 02  |.......,p.......|
00000150  00 00 00 00 00 00 00 50  00 00 00 18 00 00 00 00  |.......P........|
00000160  00 00 00 00 00 00 00 04  00 00 00 18 00 00 00 35  |...............5|
00000170  00 00 00 01 00 00 00 00  00 00 00 00 00 00 00 68  |...............h|
00000180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 04  |................|
00000190  00 00 00 00 00 00 00 11  00 00 00 03 00 00 00 00  |................|
000001a0  00 00 00 00 00 00 00 68  00 00 00 3a 00 00 00 00  |.......h...:....|
000001b0  00 00 00 00 00 00 00 01  00 00 00 00 00 00 00 01  |................|
000001c0  00 00 00 02 00 00 00 00  00 00 00 00 00 00 02 0c  |................|
000001d0  00 00 00 60 00 00 00 08  00 00 00 06 00 00 00 04  |...`............|
000001e0  00 00 00 10 00 00 00 09  00 00 00 03 00 00 00 00  |................|
000001f0  00 00 00 00 00 00 02 6c  00 00 00 01 00 00 00 00  |.......l........|
00000200  00 00 00 00 00 00 00 01  00 00 00 00 00 00 00 00  |................|
00000210  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000220  00 00 00 00 00 00 00 00  03 00 00 01 00 00 00 00  |................|
00000230  00 00 00 00 00 00 00 00  03 00 00 02 00 00 00 00  |................|
00000240  00 00 00 00 00 00 00 00  03 00 00 03 00 00 00 00  |................|
00000250  00 00 00 00 00 00 00 00  03 00 00 04 00 00 00 00  |................|
00000260  00 00 00 00 00 00 00 00  03 00 00 05 00           |.............|
0000026d
I can clearly see my code at 0x40. However, I then use this to strip out just the actual instructions:
Code:
mips-unknown-linux-gnu-objcopy test.elf -O binary test.dmp
And test.dmp now contains 24 zero bytes. :?

The only other thing I've got it to do is if I stick a ".section foobar" at the top of my source, and add "-j foobar" to the objcopy flags, then test.dmp contains nothing at all.

_________________
Image 143
HyperNova Software is now live (but may take a few tries to load) currently down; check out my PSP/DS/Game Boy/Windows/Linux homebrew, ROM hacks, and Gameshark codes!


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 23, 2009 5:21 pm 
Offline
Krew (Admin)
Krew (Admin)
User avatar

Joined: Sun Oct 01, 2006 9:26 pm
Posts: 3768
Title: All in a day's work.
You might want to put the code into the .text section. That's a good place to start. Also try objdump, see if you can get any info out of the ELF at all.

And remember that ELF format is not limited to any single architecture; you should be able to run the local binutils from your distribution on any ELFs generated by your MIPS build.

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 23, 2009 5:45 pm 
Offline
Komrade
Komrade
User avatar

Joined: Tue Mar 27, 2007 6:23 pm
Posts: 1354
Location: Mario Raceway, 1509.831, 217.198, -564.429
Title: Mario Kart 64 Hacker
I tried putting it in all different sections. objdump can disassemble it but objcopy can't copy it.

The assembler apparently is horribly broken anyway. It mangles my instructions. e.g.:
LUI $k1, 0x8034
LB $t1, 0xB218($k1)
becomes something along the lines of:
LUI $k1, 0x8033
LUI $t1, 0x0001
ADDIU $t1, $t1, 0xB218
ADD $t1, $t1, $k1
LB $t1, 0x0000($t1)

Worse, it inserts NOPs in my branch delays, which just breaks the code:
BEQ $s2, $s1, end
NOP
ADDIU $t2, $t2, 0x0001
BNEL $s2, $t0, for
NOP
ADDIU $s0, $s0, 0x0004

Then there's the completely meaningless error messages with random control characters in them. IIRC it was saying something about "invalid section for operation on L0[some control characters here]" for an instruction like ADDIU $t1, $t1, 0xFFFC. (Anything where the immediate value is more than 0x7FFF.)

_________________
Image 143
HyperNova Software is now live (but may take a few tries to load) currently down; check out my PSP/DS/Game Boy/Windows/Linux homebrew, ROM hacks, and Gameshark codes!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Nov 23, 2009 6:48 pm 
Offline
Komrade
Komrade

Joined: Tue Mar 27, 2007 10:18 am
Posts: 1328
I already told you about the latter issue. Like I said, some immediate or meta variable of yours has a width that is larger than the context you're using it in. Now, I won't argue whether the error message is meaningful, but apparently your assembler thinks that 0x8000 and above uses too many bits.

It PROBABLY thinks that ADDIU works the way it's supposed to and therefore can't use negative values (I guess it thinks 0x8000 is negative?). If I had to guess.

_________________
Image


Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 24, 2009 6:26 pm 
Offline
Krew (Admin)
Krew (Admin)
User avatar

Joined: Sun Oct 01, 2006 9:26 pm
Posts: 3768
Title: All in a day's work.
Regardless, it should not be rewriting the input. It's an assembler; not an optimizing compiler. Now I'm curious, is the MIPS port still alive? I know GNU likes to remove inactive ports from their source tree... This is the reason. (New features in the suite break old code that isn't getting updated to match the rest of the core.) That's my current theory on the matter.

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 24, 2009 11:47 pm 
Offline
Komrade
Komrade

Joined: Tue Mar 27, 2007 10:18 am
Posts: 1328
My mips-elf-as doesn't work either, now that I've actually tried it.

Shit happens.

My mips-elf-gcc compiles and assembles fine, though.

_________________
Image


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 25, 2009 1:06 am 
Offline
Komrade
Komrade
User avatar

Joined: Tue Mar 27, 2007 6:23 pm
Posts: 1354
Location: Mario Raceway, 1509.831, 217.198, -564.429
Title: Mario Kart 64 Hacker
Wait, it works from GCC? It doesn't just generate code and pass it on to 'as'?

(I hate how 'as' is also a word... makes it confusing <.<)

_________________
Image 143
HyperNova Software is now live (but may take a few tries to load) currently down; check out my PSP/DS/Game Boy/Windows/Linux homebrew, ROM hacks, and Gameshark codes!


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 25, 2009 12:58 pm 
Offline
Krew (Admin)
Krew (Admin)
User avatar

Joined: Sun Oct 01, 2006 9:26 pm
Posts: 3768
Title: All in a day's work.
I used to prefix my Google searches on the subject with "gas" ... but that's also a word. "GNU as" is unique enough to be useful though.

_________________
I have to return some video tapes.

Feed me a stray cat.


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 25, 2009 1:10 pm 
Offline
Komrade
Komrade

Joined: Tue Mar 27, 2007 10:18 am
Posts: 1328
HyperHacker wrote:
Wait, it works from GCC? It doesn't just generate code and pass it on to 'as'?

(I hate how 'as' is also a word... makes it confusing <.<)

I didn't try it with inline assembly, mind you, but it might actually work. When I did -S to get the compiler's assembly output, the instructions looked much more like what we're used to.

Note that it actually makes an executable for a real MIPS arch, so you're going to be trimming lots of excess binary if you compile C code.

_________________
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 119 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group