Jump to content

Photo

GCC for the TI


304 replies to this topic

#301 Tursi OFFLINE  

Tursi

    River Patroller

  • 4,715 posts
  • Location:BUR

Posted Thu May 11, 2017 1:11 AM

Just as a note, I was able to use the install script to build this under the Linux Subsystem for Windows, except for the install step failed to find libc++. I didn't need that right now, so I just changed it not to build the c++ compiler, and it seemed to work. It was /really/ noisy, tons of pedantic warnings (all over the place, not just in the patches), but I didn't have to do anything special. Just wanted to try it and see if it worked better than Cygwin. ;)



#302 insomnia OFFLINE  

insomnia

    Star Raider

  • Topic Starter
  • 67 posts
  • Location:Pittsburgh, PA

Posted Mon May 29, 2017 7:52 PM

Hey everyone,

 

I've got a new set of patches for the compiler to send out. It's pretty thin, but that's a good thing.

 

Here's what's new:

 

Fixed a multiplication bug reported by Chue, In come cases, the input arguments were clobbered leading to a wrong result.

Fixed incorrect instruction sizes. This will result in better optimized code.

Added .size directive to calculate function sizes. This is helpful during development.

Reduced size of the patch file. This makes it easier to understand which changes were made to the baseline.

 

I've updated the GCC installer to use this latest patch, and added an updated "hello world" program. This program no longer needs the elf2cart tool, makes improvements to the crt0 as well as fixing some bugs in the vdp_copy_from_sys function.

 

Honestly, there's not much else to say here. The compiler is pretty mature and stable at this point, but I'm always interested to hear of any problems or opportunities for improvement.



#303 chue OFFLINE  

chue

    Chopper Commander

  • 120 posts

Posted Mon May 29, 2017 8:44 PM

Awesome, looking forward to trying out the new patch!



#304 TheMole OFFLINE  

TheMole

    Dragonstomper

  • 729 posts
  • Location:Belgium

Posted Thu Jul 13, 2017 6:54 AM

This is as much for future reference for myself as it is for anyone compiling on a macOS, but I needed to do three things in order to build the latest patch on my machine:

 

  1. Edit the install script to invoke curl correctly by adding double quotes around the WGET variable assigned, and changing the curl option from -C to -O

  2. Install gmp and mpfr libraries via Homebrew (brew install gmp mpfr)

  3. remove the c++ build target. Unfortunately, c++ doesn't build with clang due to duplicate symbols. I don't need c++ for my use, so not a big problem, but something worth noting nonetheless. Perhaps this is related to the problem Tursi was seeing when building with the Linux Subsystem for Windows back in May?



#305 TheMole OFFLINE  

TheMole

    Dragonstomper

  • 729 posts
  • Location:Belgium

Posted Tue Aug 15, 2017 3:41 AM

Played with the latest version a little bit, and I've discovered what I think might be a bug. I'm comparing patch 12 vs patch 15 here, and the assembler it outputs for this piece of C code:

 

bankswitch.h

#ifndef BANKSWITCH_H
#define BANKSWITCH_H

#define BANKSIZE	0x2000
#define BANKADDRESS 0x6000

// Variable to store our current bank, used by all trampoline functions
extern volatile unsigned int currentbank;

// Where to write to, to switch banks
// You can switch banks by addressing this as an array, and writing
// any value to it.
// 		e.g.	bankbase[2] = 1;
// This will switch to bank 2
extern volatile unsigned int *bankbase;

#endif

resource_copy.c:

#include "bankswitch.h"

#define _binary_start_bank	5

// Copy from cartridge ROM to a section in RAM
void rom_to_ram(unsigned long start, unsigned long end, unsigned char *dst)
{
	unsigned int srcoffset 	= (unsigned int)start % BANKSIZE;
	unsigned int length		= (unsigned int)(end - start);
	unsigned int srcbank	= _binary_start_bank + ((start - srcoffset) / BANKSIZE);

	// Do we need to read across different banks?
	while ( (srcoffset + length) > BANKSIZE )
	{
		unsigned int templength = BANKSIZE - srcoffset;

		// activate source bank
		bankbase[srcbank] = 1;

		// copy contents until end of bank
		memcpy(dst, (unsigned char*)(BANKADDRESS + srcoffset), templength);

		// update bank, offset and remaining length
		length -= templength;
		srcbank++;				// prime for next bank
		srcoffset = 0;			// start at start of bank
		dst += templength;		// Move destination pointer
	}

	// Copy contents of one (last) bank
	bankbase[srcbank] = 1;
	memcpy(dst, (void*)(BANKADDRESS + srcoffset), length);

	// Restore bank
	bankbase[currentbank] = 1;
}

When compiled with patch 12, the code works perfectly fine (it is, as I'm sure is obvious to most, code to copy binary blobs from paged cartridge ROM to RAM). When compiled with patch 15, it copies garbage (haven't been able to identify where it goes wrong). So as a first step to debug this, I figured I'd look at the assembly code generated by the two compilers.

 

For patch 12:

000000ba <rom_to_ram>:
  ba:	02 2a ff f2 	ai r10, >FFF2
  be:	c0 0a       	mov r10, r0
  c0:	cc 0b       	mov r11, *r0+
  c2:	cc 09       	mov r9, *r0+
  c4:	cc 0d       	mov r13, *r0+
  c6:	cc 0e       	mov r14, *r0+
  c8:	c4 0f       	mov r15, *r0
  ca:	c1 81       	mov r1, r6
  cc:	c1 c2       	mov r2, r7
  ce:	c3 85       	mov r5, r14
  d0:	c2 02       	mov r2, r8
  d2:	02 48 1f ff 	andi r8, >1FFF
  d6:	c3 44       	mov r4, r13
  d8:	63 42       	s r2, r13
  da:	c0 88       	mov r8, r2
  dc:	04 c1       	clr r1
  de:	61 81       	s r1, r6
  e0:	61 c2       	s r2, r7
  e2:	18 00       	joc 0
  e4:	06 06       	dec r6
  e6:	c2 46       	mov r6, r9
  e8:	0a 39       	sla r9, 3
  ea:	c0 47       	mov r7, r1
  ec:	09 d1       	srl r1, 13
  ee:	e2 41       	soc r1, r9
  f0:	02 29 00 05 	ai r9, >0005
  f4:	c3 c9       	mov r9, r15
  f6:	a3 c9       	a r9, r15
  f8:	02 04 00 00 	li r4, >0000
  fc:	10 00       	jmp 0

000000fe <L8>:
  fe:	02 28 e0 00 	ai r8, >E000
 102:	05 08       	neg r8
 104:	c0 60 00 00 	mov @>0000, r1
 108:	a0 4f       	a r15, r1
 10a:	02 03 00 01 	li r3, >0001
 10e:	c4 43       	mov r3, *r1
 110:	c0 4e       	mov r14, r1
 112:	c0 c8       	mov r8, r3
 114:	ca 84 00 0c 	mov r4, @>000C(r10)
 118:	ca 88 00 0a 	mov r8, @>000A(r10)
 11c:	06 94       	bl *r4
 11e:	c2 2a 00 0a 	mov @>000A(r10), r8
 122:	63 48       	s r8, r13
 124:	05 89       	inc r9
 126:	a3 88       	a r8, r14
 128:	05 cf       	inct r15
 12a:	04 c8       	clr r8
 12c:	c1 2a 00 0c 	mov @>000C(r10), r4

00000130 <L7>:
 130:	c0 4d       	mov r13, r1
 132:	a0 48       	a r8, r1
 134:	c0 88       	mov r8, r2
 136:	02 22 60 00 	ai r2, >6000
 13a:	02 81 20 00 	ci r1, >2000
 13e:	1b 00       	jh 0
 140:	a2 49       	a r9, r9
 142:	a2 60 00 00 	a @>0000, r9
 146:	02 01 00 01 	li r1, >0001
 14a:	c6 41       	mov r1, *r9
 14c:	c0 4e       	mov r14, r1
 14e:	c0 cd       	mov r13, r3
 150:	06 a0 00 00 	bl @>0000
 154:	c0 60 00 00 	mov @>0000, r1
 158:	a0 41       	a r1, r1
 15a:	a0 60 00 00 	a @>0000, r1
 15e:	02 02 00 01 	li r2, >0001
 162:	c4 42       	mov r2, *r1
 164:	c2 fa       	mov *r10+, r11
 166:	c2 7a       	mov *r10+, r9
 168:	c3 7a       	mov *r10+, r13
 16a:	c3 ba       	mov *r10+, r14
 16c:	c3 da       	mov *r10, r15
 16e:	02 2a 00 06 	ai r10, >0006
 172:	04 5b       	b *r11

For patch 15:

000000bc <rom_to_ram>:
  bc:	02 2a ff f2 	ai r10, >FFF2
  c0:	c0 0a       	mov r10, r0
  c2:	cc 0b       	mov r11, *r0+
  c4:	cc 09       	mov r9, *r0+
  c6:	cc 0d       	mov r13, *r0+
  c8:	cc 0e       	mov r14, *r0+
  ca:	c4 0f       	mov r15, *r0
  cc:	c1 81       	mov r1, r6
  ce:	c1 c2       	mov r2, r7
  d0:	c3 85       	mov r5, r14
  d2:	c2 02       	mov r2, r8
  d4:	02 48 1f ff 	andi r8, >1FFF
  d8:	c3 44       	mov r4, r13
  da:	63 42       	s r2, r13
  dc:	c0 88       	mov r8, r2
  de:	04 c1       	clr r1
  e0:	61 81       	s r1, r6
  e2:	61 c2       	s r2, r7
  e4:	18 00       	joc 0
  e6:	06 06       	dec r6
  e8:	c0 87       	mov r7, r2
  ea:	08 d6       	sra r6, 13
  ec:	09 d7       	srl r7, 13
  ee:	0a 32       	sla r2, 3
  f0:	e1 c2       	soc r2, r7
  f2:	c2 47       	mov r7, r9
  f4:	02 29 00 05 	ai r9, >0005
  f8:	c3 c9       	mov r9, r15
  fa:	a3 c9       	a r9, r15
  fc:	02 04 00 00 	li r4, >0000
 100:	10 00       	jmp 0

00000102 <L8>:
 102:	02 28 e0 00 	ai r8, >E000
 106:	05 08       	neg r8
 108:	c0 60 00 00 	mov @>0000, r1
 10c:	a0 4f       	a r15, r1
 10e:	02 03 00 01 	li r3, >0001
 112:	c4 43       	mov r3, *r1
 114:	c0 4e       	mov r14, r1
 116:	c0 c8       	mov r8, r3
 118:	ca 84 00 0c 	mov r4, @>000C(r10)
 11c:	ca 88 00 0a 	mov r8, @>000A(r10)
 120:	06 94       	bl *r4
 122:	c2 2a 00 0a 	mov @>000A(r10), r8
 126:	63 48       	s r8, r13
 128:	05 89       	inc r9
 12a:	a3 88       	a r8, r14
 12c:	05 cf       	inct r15
 12e:	04 c8       	clr r8
 130:	c1 2a 00 0c 	mov @>000C(r10), r4

00000134 <L7>:
 134:	c0 4d       	mov r13, r1
 136:	a0 48       	a r8, r1
 138:	c0 88       	mov r8, r2
 13a:	02 22 60 00 	ai r2, >6000
 13e:	02 81 20 00 	ci r1, >2000
 142:	1b 00       	jh 0
 144:	a2 49       	a r9, r9
 146:	a2 60 00 00 	a @>0000, r9
 14a:	02 01 00 01 	li r1, >0001
 14e:	c6 41       	mov r1, *r9
 150:	c0 4e       	mov r14, r1
 152:	c0 cd       	mov r13, r3
 154:	06 a0 00 00 	bl @>0000
 158:	c0 60 00 00 	mov @>0000, r1
 15c:	a0 41       	a r1, r1
 15e:	a0 60 00 00 	a @>0000, r1
 162:	02 02 00 01 	li r2, >0001
 166:	c4 42       	mov r2, *r1
 168:	c2 fa       	mov *r10+, r11
 16a:	c2 7a       	mov *r10+, r9
 16c:	c3 7a       	mov *r10+, r13
 16e:	c3 ba       	mov *r10+, r14
 170:	c3 da       	mov *r10, r15
 172:	02 2a 00 06 	ai r10, >0006
 176:	04 5b       	b *r11

That's as far as I got. You'll notice the code is largely the same, except for right after line 20 (adress 0x0bc and 0x0ba in the respective disassemblies), where there's a small difference in generated code (patch 15 is slightly longer).






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users