English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 28 October 2019, 12:46   #1
Hedeon
PPC Hacker

 
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,092
VBCC: Restrict usage of registers in C

Hi,

I am busy transferring the WarpOS compatible kernel I did for PCI PPC cards from assembly to C. Of course the kernel is very low level and it is unavoidable to use assembly here and there.

The 603 and e300 PPCs don't have hardware tlb lookup and make use of software exceptions to load the correct values from the page table.

To accomplish this the exceptions use four shadow registers called r0-r3. They are independent from the 'normal' registers which are also called r0-r3 (up to r31).

IF I want to make this in C, I need to restrict the usage of registers to these 4. Is this even possible with VBCC?
Hedeon is offline  
Old 28 October 2019, 14:15   #2
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 626
Quote:
Originally Posted by Hedeon View Post
IF I want to make this in C, I need to restrict the usage of registers to these 4. Is this even possible with VBCC?
I'm not 100% sure this will work, but you would need to modify the backend to mark registers r4 - r31 as allocated in the init_cg function (regsa[n]=1; careful, the register number doesn't map directly to n - see the register names array.) - then modify the t1, t2 and t3 values to restrict the compiler's internal scratch registers to the allowed range. You'll leave just one register free for the compiler's use so expect to see lots of stack operations.
robinsonb5 is offline  
Old 28 October 2019, 14:39   #3
Hedeon
PPC Hacker

 
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,092
Had hoped that some directive would do. Current source does not use stack and only modifies the software page table.

I'd guess this is one of those parts that will stay in assembly.

Excerpt:

Code:
.DLoadTLBMiss:
		mfspr	r2,HASH1				#get first pointer
		li	r1,8   					#load 8 for counter
		mfctr	r0   					#save counter
		mfspr	r3,DCMP   				#get first compare value
		addi	r2,r2,-8  				#pre dec the pointer
dm0:
		mtctr	r1  					#load counter
dm1:
		lwzu	r1,8(r2)				#get next pte
		cmpw	r1,r3 					#see if found pte
		bdnzf	eq,dm1 					#dec count br if cmp ne and if count not zero
		bne	dataSecHash 				#if not found set up second hash or exit
		lwz	r1,4(r2) 				#load tlb entry lower-word
		mtctr	r0   					#restore counter
		mfspr	r0,DMISS  				#get the miss address for the tlbld
		mfsrr1	r3   					#get the saved cr0 bits
		mtcrf	0x80,r3 				#restore CR0
		mtspr	RPA,r1  				#set the pte
		ori	r1,r1,PTE_REFERENCED   			#set reference bit
		srwi	r1,r1,8  				#get byte 7 of pte
		tlbld	r0    					#load the dtlb
		stb	r1,6(r2) 				#update page table
		rfi      					#return to executing program

dataSecHash:
 		andi.	r1,r3,PTE_HASHID 			#see if we have done second hash
		bne	doDSI       				#if so, go to DSI interrupt
		mfspr	r2,HASH2   				#get the second pointer
		ori	r3,r3,PTE_HASHID 			#change the compare value
		li	r1,8   					#load 8 for counter
		addi	r2,r2,-8  				#pre dec for update on load
		b	dm0  					#try second hash
Hedeon is offline  
Old 28 October 2019, 15:47   #4
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,484
No, you cannot restrict the code generator to use certain registers in a function. But to minimize assembler usage you could either use the __saveall attribute, which also saves/restores all (used) volatile registers, or insert inline-assembler to save them: __asm("\tstw\tr4,offset(r1)");
You might also want to use the __interrupt attribute, which makes sure that such a function ends with "rfi" instead of "blr".
phx is offline  
Old 28 October 2019, 16:43   #5
Hedeon
PPC Hacker

 
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,092
Thanks @phx. I learned that from you last time we spoke :-) (regarding __interrupt)

See https://github.com/Sakura-IT/PowerPC...aster/kernel.c

or

https://github.com/Sakura-IT/PowerPCAmiga

Nothing much there yet. I need to use assembly anyway to access the special registers, but want to keep it at minimum.

For these tlb exceptions I'll just use assembly also for speed reasons.
Hedeon is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Preservation of registers guy lateur Coders. Asm / Hardware 51 26 October 2018 15:33
A4000 IDE registers mark_k Coders. Asm / Hardware 6 11 May 2015 18:05
Using FPU registers? oRBIT Coders. General 16 26 April 2010 14:34
Need DA8000-DAFFFF registers documentation BlueAchenar Coders. General 2 13 December 2008 16:39
Gayle Hardware Registers bluea support.Hardware 5 09 July 2006 18:07

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 00:09.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.10602 seconds with 15 queries