Просмотр исходного кода

Merged revisions 8200,8203,8206-8207,8212-8213,8215,8225,8227,8233-8239,8262,8302,8307,8309,8316,8318-8319,8336,8338-8340,8404,8410-8411,8430,8438-8442,8445-8446,8448,8450-8454,8456-8457,8459,8462,8469-8470,8472-8483,8486-8488,8490,8493,8496,8506,8535-8537,8539-8546,8554,8560,8575-8576,8581-8587,8590,8593-8594,8596,8600,8605,8607,8625,8630-8638,8640-8641,8659,8665,8667,8681-8682,8686-8687,8702,8705,8710-8714,8719,8721-8723,8727,8730-8731,8743,8747-8751,8766-8769,8797,8822,8831,8848-8849,8851,8879,8885-8889,8891-8893,8895,8897,8912,8917,8942,8950,8998,9000-9006,9021,9025,9033,9035,9059,9074,9076-9082,9084,9086,9088-9090,9096,9108,9114,9132-9133,9185,9211,9236-9238,9260,9262,9266,9269-9272,9276-9278,9295,9307-9308,9310,9322,9337,9340,9343-9344,9359,9373-9375,9387,9396,9399,9401-9402,9424,9434,9450-9456,9459-9463,9466,9468-9469,9472-9473,9476-9477,9480,9491-9492,9529,9536,9550,9566-9568,9571,9573,9576-9577,9579,9583,9587,9632-9637,9655-9656,9658,9672 via svnmerge from
http://svn.freepascal.org/svn/fpc/trunk

........
r8200 | Legolas | 2007-07-30 17:37:19 +0200 (Mon, 30 Jul 2007) | 1 line

* gba and nds work with new heap manager now (no need for a custom heap manager that allocates a single big block anymore)
........
r9424 | Legolas | 2007-12-10 18:06:14 +0100 (Mon, 10 Dec 2007) | 4 lines

* Resized stack value for NDS
* Changes to prt0:
+ Added argv support
* New function calls
........
r9672 | Legolas | 2008-01-07 20:31:32 +0100 (Mon, 07 Jan 2008) | 1 line

* Some cleaning on nds linker; new extension for intermediate files
........

git-svn-id: branches/fixes_2_2@10278 -

peter 17 лет назад
Родитель
Сommit
ae7f3ed2b1
7 измененных файлов с 177 добавлено и 72 удалено
  1. 2 0
      .gitignore
  2. 1 1
      compiler/systems/i_nds.pas
  3. 11 24
      compiler/systems/t_nds.pas
  4. 3 29
      rtl/gba/system.pp
  5. 0 2
      rtl/inc/heap.inc
  6. 78 6
      rtl/nds/cprt09.as
  7. 82 10
      rtl/nds/prt09.as

+ 2 - 0
.gitignore

@@ -774,6 +774,7 @@ rtl/freebsd/x86_64/*.ppu
 rtl/freebsd/x86_64/*.s
 rtl/freebsd/x86_64/fpcmade.*
 rtl/freebsd/x86_64/units
+rtl/gba/Copia[!!-~]di[!!-~]system.pp
 rtl/gba/backup
 rtl/gba/build_rtl.bat
 rtl/gba/build_rtl_EABI.bat
@@ -868,6 +869,7 @@ rtl/morphos/*.ppu
 rtl/morphos/*.s
 rtl/morphos/fpcmade.*
 rtl/morphos/units
+rtl/nds/backup
 rtl/nds/parcheggio
 rtl/netbsd/*.bak
 rtl/netbsd/*.exe

+ 1 - 1
compiler/systems/i_nds.pas

@@ -83,7 +83,7 @@ unit i_nds;
                 maxCrecordalign : 4
               );
             first_parm_offset : 8;
-            stacksize    : 262144;
+            stacksize    : 16384;
             abi : abi_default
           );
 

+ 11 - 24
compiler/systems/t_nds.pas

@@ -127,20 +127,17 @@ begin
 
   LinkRes.Add('INPUT (');
   { add objectfiles, start with prt0 always }
-  //s:=FindObjectFile('prt0','',false);
   if prtobj<>'' then
    s:=FindObjectFile(prtobj,'',false);
   LinkRes.AddFileName(s);
   { try to add crti and crtbegin if linking to C }
   if linklibc then
    begin
-   //QUA C'E' LA GUFECCHIA!!!!
      if librarysearchpath.FindFile('crti.o',false,s) then
       LinkRes.AddFileName(s);
    end;
   if linklibgcc then
    begin
-   //QUA C'E' LA GUFECCHIA!!!!
      if librarysearchpath.FindFile('crtbegin.o',false,s) then
        LinkRes.AddFileName(s);
    end;
@@ -708,8 +705,8 @@ begin
   StripStr:='';
   DynLinkStr:='';
   case apptype of
-   app_arm9: preName:='.arm9';
-   app_arm7: preName:='.arm7';
+   app_arm9: preName:='.nef';
+   app_arm7: preName:='.nlf';
   end;
 
   GCSectionsStr:='--gc-sections';
@@ -722,24 +719,14 @@ begin
 { Call linker }
   SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
   Replace(cmdstr,'$OPT',Info.ExtraOptions);
-  if not(cs_link_on_target in current_settings.globalswitches) then
-   begin
-    Replace(cmdstr,'$EXE',(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename^,preName+'.nef')))));
-    Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
-    Replace(cmdstr,'$STATIC',StaticStr);
-    Replace(cmdstr,'$STRIP',StripStr);
-    Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
-    Replace(cmdstr,'$DYNLINK',DynLinkStr);
-   end
-  else
-   begin
-    Replace(cmdstr,'$EXE',maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename^,preName+'.nef'))));
-    Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
-    Replace(cmdstr,'$STATIC',StaticStr);
-    Replace(cmdstr,'$STRIP',StripStr);
-    Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
-    Replace(cmdstr,'$DYNLINK',DynLinkStr);
-   end;
+
+  Replace(cmdstr,'$EXE',(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename^,preName)))));
+  Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
+  Replace(cmdstr,'$STATIC',StaticStr);
+  Replace(cmdstr,'$STRIP',StripStr);
+  Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
+  Replace(cmdstr,'$DYNLINK',DynLinkStr);
+  
   success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
 
 { Remove ReponseFile }
@@ -750,7 +737,7 @@ begin
   if success then
     begin
       success:=DoExec(FindUtil(utilsprefix + 'objcopy'), '-O binary '+ 
-        ChangeFileExt(current_module.exefilename^, preName+'.nef') + ' ' + 
+        ChangeFileExt(current_module.exefilename^, preName) + ' ' + 
         ChangeFileExt(current_module.exefilename^, preName+target_info.exeext),
         true,false);
     end;

+ 3 - 29
rtl/gba/system.pp

@@ -19,11 +19,10 @@ interface
 
 {$define __ARM__} (* For future usage! *)
 {$define FPC_IS_SYSTEM}
-{$define USE_NOTHREADMANAGER}
 
 {$i gbabiosh.inc}
 
-{$I systemh.inc}
+{$i systemh.inc}
 
 {$define fpc_softfpu_interface}
 {$i softfpu.pp}
@@ -61,8 +60,7 @@ var
   argv: PPChar;
   envp: PPChar;
   errno: integer;
-  fake_heap_start: pchar; cvar;
-  fake_heap_end: pchar; cvar;
+
 
 implementation
 
@@ -82,7 +80,7 @@ implementation
 {$define FPC_SYSTEM_HAS_extractFloat32Exp}
 {$define FPC_SYSTEM_HAS_extractFloat32Sign}
 
-{$I system.inc}
+{$i system.inc}
 
 {$i gbabios.inc}
 
@@ -139,34 +137,11 @@ begin
 end;
 
 
-procedure InitHeap;
-begin
-  FillChar(freelists_fixed,sizeof(tfreelists),0);
-  FillChar(freelists_free_chunk,sizeof(freelists_free_chunk),0);
-
-  freelist_var:=nil;
-  {The GBA has no operating system from which we ask memory, so we
-   initialize the heap with a single block of memory.}
-  freeoslistcount:=1;
-  freeoslist:=pointer($2040000);
-  fillchar(freeoslist^,sizeof(freeoslist^),0);
-  freeoslist^.size:=$40000; {GBA heap is $40000 bytes.}
-  fillchar(internal_status,sizeof(internal_status),0);
-end;
-
-
-
-
 begin
   StackLength := CheckInitialStkLen(InitialStkLen);
-  ///StackBottom := Sptr - StackLength;
   StackBottom := StackTop - StackLength;
 { OS specific startup }
-  fake_heap_start := pchar(0);
-  fake_heap_end := pchar(0);
-{ Set up signals handlers }
 
-  fpc_cpucodeinit;
 { Setup heap }
   InitHeap;
   SysInitExceptions;
@@ -175,7 +150,6 @@ begin
 { Reset IO Error }
   InOutRes:=0;
 { Arguments }
-
   InitSystemThreads;
   initvariantmanager;
 end.

+ 0 - 2
rtl/inc/heap.inc

@@ -1432,7 +1432,6 @@ end;
                                  InitHeap
 *****************************************************************************}
 
-{$if not(defined(gba)) and not(defined(nds))}
 { This function will initialize the Heap manager and need to be called from
   the initialization of the system unit }
 procedure InitHeap;
@@ -1447,7 +1446,6 @@ begin
   fillchar(maxsizeusage,sizeof(sizeusage),0);
 {$endif}
 end;
-{$endif}
 
 procedure FinalizeHeap;
 var

+ 78 - 6
rtl/nds/cprt09.as

@@ -1,3 +1,12 @@
+@---------------------------------------------------------------------------------
+@ DS processor selection
+@---------------------------------------------------------------------------------
+	.arch	armv5te
+	.cpu	arm946e-s
+@---------------------------------------------------------------------------------
+
+	.equ	_libnds_argv,	0x027FFF70
+
 @---------------------------------------------------------------------------------
 	.section ".init"
 	.global _start
@@ -95,7 +104,7 @@ _start:
 	@-------------------------------------------------------------------------
 	@ Write buffer enable
 	@-------------------------------------------------------------------------
-	ldr	r0,=0b00000110
+	ldr	r0,=0b00000010
 	mcr	p15, 0, r0, c3, c0, 0
 
 	@-------------------------------------------------------------------------
@@ -148,6 +157,8 @@ _start:
 	ldr	r4, =__dtcm_end
 	bl	CopyMemCheck
 
+	bl	checkARGV					@	check and process argv trickery
+
 	ldr	r0, =__bss_start	@ Clear BSS section
 	ldr	r1, =__bss_end
 	sub	r1, r1, r0
@@ -163,14 +174,25 @@ _start:
 	str	r0, [r1]
 	
 	ldr	r3, =__libc_init_array	@ global constructors
-	bl	_call_via_r3
+	blx	r3
+
+	ldr	r3,	=initSystem
+	blx	r3	@	jump to user code
+
+	ldr	r0,	=_libnds_argv
+
+	@ reset heap base
+	ldr	r2, [r0,#20]            @ newheap base
+	ldr	r1,=fake_heap_start
+	str	r2,[r1]
+
+	ldr	r1, [r0,#16]            @ argv
+	ldr	r0, [r0,#12]            @ argc
 
-	mov	r0, #0			@ int argc
-	mov	r1, #0			@ char *argv[]
 	ldr	r3, =main
-	bl	_call_via_r3		@ jump to user code
+	blx	r3		@ jump to user code
 		
-	@ If the user ever returns, go to an infinte loop
+	@ If the user ever returns, go back to passme loop
 	ldr	r0, =ILoop
 	ldr	r0, [r0]
 	ldr	r1, =0x027FFE78
@@ -179,6 +201,56 @@ _start:
 ILoop:
 	b	ILoop
 
+@---------------------------------------------------------------------------------
+@ check for a commandline
+@---------------------------------------------------------------------------------
+checkARGV:
+@---------------------------------------------------------------------------------
+	ldr	r0, =_libnds_argv       @ argv structure
+	mov	r1, #0
+	str	r1, [r0,#12]            @ clear argc
+	str	r1, [r0,#16]            @ clear argv
+ 	  	 
+	ldr	r1, [r0]                @ argv magic number
+	ldr	r2, =0x5f617267         @ '_arg'
+	cmp	r1, r2
+	bxne	lr                      @ bail out if no magic
+
+	ldr	r1, [r0, #4]            @ command line address
+	ldr	r2, [r0, #8]            @ length of command line
+
+	@ copy to heap
+	ldr	r3, =__end__            @ initial heap base
+	str	r3, [r0, #4]            @ set command line address
+ 	  	 
+	cmp	r2, #0
+	subnes	r4, r3, r1              @ dst-src
+	bxeq	lr                      @ dst == src || len==0 : nothing to do.
+
+	cmphi	r2, r4                  @ len > (dst-src)
+	bhi	.copybackward
+
+.copyforward:
+	ldrb	r4, [r1], #1
+	strb	r4, [r3], #1
+	subs	r2, r2, #1
+	bne	.copyforward
+	b	.copydone
+
+.copybackward:
+	subs	r2, r2, #1
+	ldrb	r4, [r1, r2]
+	strb	r4, [r3, r2]
+	bne	.copybackward
+
+.copydone:
+	push	{lr}
+	ldr	r3, =build_argv
+	blx	r3
+	pop	{lr}
+	bx	lr
+
+
 @---------------------------------------------------------------------------------
 @ Clear memory to 0x00 if length != 0
 @  r0 = Start Address

+ 82 - 10
rtl/nds/prt09.as

@@ -1,3 +1,12 @@
+@---------------------------------------------------------------------------------
+@ DS processor selection
+@---------------------------------------------------------------------------------
+	.arch	armv5te
+	.cpu	arm946e-s
+@---------------------------------------------------------------------------------
+
+	.equ	_libnds_argv,	0x027FFF70
+
 @---------------------------------------------------------------------------------
 	.section ".init"
 	.global _start
@@ -95,14 +104,14 @@ _start:
 	@-------------------------------------------------------------------------
 	@ Write buffer enable
 	@-------------------------------------------------------------------------
-	ldr	r0,=0b00000110
+	ldr	r0,=0b00000010
 	mcr	p15, 0, r0, c3, c0, 0
 
 	@-------------------------------------------------------------------------
 	@ DCache & ICache enable
 	@-------------------------------------------------------------------------
-	ldr	r0,=0b01000010
-
+	ldr	r0,=0b01000110
+	ldr	r0,=0x42
 	mcr	p15, 0, r0, c2, c0, 0
 	mcr	p15, 0, r0, c2, c0, 1
 
@@ -148,6 +157,8 @@ _start:
 	ldr	r4, =__dtcm_end
 	bl	CopyMemCheck
 
+	bl	checkARGV					@	check and process argv trickery
+
 	ldr	r0, =__bss_start	@ Clear BSS section
 	ldr	r1, =__bss_end
 	sub	r1, r1, r0
@@ -162,13 +173,26 @@ _start:
 	ldr	r0, =__eheap_end
 	str	r0, [r1]
 
-	mov	r0, #0			@ int argc
-	mov	r1, #0			@ char *argv[]
-	ldr	r3, =main
-  bx	r3
-  nop
+@	ldr	r3, =__libc_init_array	@ global constructors
+@	blx	r3
+
+	ldr	r3,	=initSystem
+	blx	r3	@	jump to user code
+
+	ldr	r0,	=_libnds_argv
 
-	@ If the user ever returns, go to an infinte loop
+	@ reset heap base
+	ldr	r2, [r0,#20]            @ newheap base
+	ldr	r1,=fake_heap_start
+	str	r2,[r1]
+
+	ldr	r1, [r0,#16]            @ argv
+	ldr	r0, [r0,#12]            @ argc
+
+	ldr	r3, =main
+	blx	r3		@ jump to user code
+		
+	@ If the user ever returns, go back to passme loop
 	ldr	r0, =ILoop
 	ldr	r0, [r0]
 	ldr	r1, =0x027FFE78
@@ -177,8 +201,56 @@ _start:
 ILoop:
 	b	ILoop
 
-
 @---------------------------------------------------------------------------------
+@ check for a commandline
+@---------------------------------------------------------------------------------
+checkARGV:
+@---------------------------------------------------------------------------------
+	ldr	r0, =_libnds_argv       @ argv structure
+	mov	r1, #0
+	str	r1, [r0,#12]            @ clear argc
+	str	r1, [r0,#16]            @ clear argv
+ 	  	 
+	ldr	r1, [r0]                @ argv magic number
+	ldr	r2, =0x5f617267         @ '_arg'
+	cmp	r1, r2
+	bxne	lr                      @ bail out if no magic
+
+	ldr	r1, [r0, #4]            @ command line address
+	ldr	r2, [r0, #8]            @ length of command line
+
+	@ copy to heap
+	ldr	r3, =__end__            @ initial heap base
+	str	r3, [r0, #4]            @ set command line address
+ 	  	 
+	cmp	r2, #0
+	subnes	r4, r3, r1              @ dst-src
+	bxeq	lr                      @ dst == src || len==0 : nothing to do.
+
+	cmphi	r2, r4                  @ len > (dst-src)
+	bhi	.copybackward
+
+.copyforward:
+	ldrb	r4, [r1], #1
+	strb	r4, [r3], #1
+	subs	r2, r2, #1
+	bne	.copyforward
+	b	.copydone
+
+.copybackward:
+	subs	r2, r2, #1
+	ldrb	r4, [r1, r2]
+	strb	r4, [r3, r2]
+	bne	.copybackward
+
+.copydone:
+	push	{lr}
+	ldr	r3, =build_argv
+	blx	r3
+	pop	{lr}
+	bx	lr
+
+
 @---------------------------------------------------------------------------------
 @ Clear memory to 0x00 if length != 0
 @  r0 = Start Address