Преглед изворни кода

Merged revisions 8002,8004-8006,8008-8012,8016,8026 via svnmerge from
http://svn.freepascal.org/svn/fpc/trunk

........
r8002 | Legolas | 2007-07-10 00:17:36 +0200 (Tue, 10 Jul 2007) | 4 lines

* Changed .elf extension to .nef (Not Executable File) for intermediate file builds in the NDS compiler (used on no$gba debugger for symbol table)
* Added nds target to ppudump.pp
* Fixed rtl compilation for nds target
* Changes in prt09.as
........
r8026 | Legolas | 2007-07-12 13:29:49 +0200 (Thu, 12 Jul 2007) | 1 line

* Added NDS CPU detection routine (ARM7 can't handle dsp extensions)
........

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

peter пре 18 година
родитељ
комит
84d5681738
8 измењених фајлова са 118 додато и 97 уклоњено
  1. 3 3
      compiler/systems/t_nds.pas
  2. 4 2
      compiler/utils/ppudump.pp
  3. 15 3
      rtl/nds/Makefile
  4. 2 2
      rtl/nds/Makefile.fpc
  5. 3 0
      rtl/nds/classes.pp
  6. 2 5
      rtl/nds/prt09.as
  7. 36 34
      rtl/nds/sysheap.inc
  8. 53 48
      rtl/nds/system.pp

+ 3 - 3
compiler/systems/t_nds.pas

@@ -724,7 +724,7 @@ begin
   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+'.elf')))));
+    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);
@@ -733,7 +733,7 @@ begin
    end
   else
    begin
-    Replace(cmdstr,'$EXE',maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename^,preName+'.elf'))));
+    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);
@@ -750,7 +750,7 @@ begin
   if success then
     begin
       success:=DoExec(FindUtil(utilsprefix + 'objcopy'), '-O binary '+ 
-        ChangeFileExt(current_module.exefilename^, preName+'.elf') + ' ' + 
+        ChangeFileExt(current_module.exefilename^, preName+'.nef') + ' ' + 
         ChangeFileExt(current_module.exefilename^, preName+target_info.exeext),
         true,false);
     end;

+ 4 - 2
compiler/utils/ppudump.pp

@@ -149,7 +149,8 @@ type
              system_ia64_win64,         { 39 }
              system_i386_wince,         { 40 }
              system_x86_6432_linux,     { 41 }
-             system_arm_gba             { 42 }
+             system_arm_gba,            { 42 }
+             system_arm_nds             { 43 }
        );
 const
   Targets : array[ttarget] of string[17]=(
@@ -195,7 +196,8 @@ const
   { 39 }  'Win64-iA64',
   { 40 }  'WinCE-i386',
   { 41 }  'Linux-x64',
-  { 42 }  'GBA-ARM'
+  { 42 }  'GBA-arm',
+  { 43 }  'NDS-arm'
   );
 begin
   if w<=ord(high(ttarget)) then

+ 15 - 3
rtl/nds/Makefile

@@ -1,8 +1,8 @@
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2007/08/29]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2007/08/22]
 #
 default: all
-MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-embedded
+MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded
 BSDs = freebsd netbsd openbsd darwin
 UNIXs = linux $(BSDs) solaris qnx
 LIMIT83fs = go32v2 os2 emx watcom
@@ -395,6 +395,9 @@ endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
 override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil fgl
 endif
+ifeq ($(FULL_TARGET),powerpc64-darwin)
+override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil fgl
+endif
 ifeq ($(FULL_TARGET),powerpc64-embedded)
 override TARGET_UNITS+=$(SYSTEMUNIT) objpas macpas strings sysutils classes math typinfo varutils fmtbcd ctypes charset ucomplex getopts matrix variants types rtlconsts sysconst dateutil fgl
 endif
@@ -548,6 +551,9 @@ endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
 override TARGET_LOADERS+=prt07 prt09 cprt07 cprt09
 endif
+ifeq ($(FULL_TARGET),powerpc64-darwin)
+override TARGET_LOADERS+=prt07 prt09 cprt07 cprt09
+endif
 ifeq ($(FULL_TARGET),powerpc64-embedded)
 override TARGET_LOADERS+=prt07 prt09 cprt07 cprt09
 endif
@@ -702,6 +708,9 @@ endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
 endif
+ifeq ($(FULL_TARGET),powerpc64-darwin)
+override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
+endif
 ifeq ($(FULL_TARGET),powerpc64-embedded)
 override COMPILER_INCLUDEDIR+=$(INC) $(PROCINC)
 endif
@@ -855,6 +864,9 @@ endif
 ifeq ($(FULL_TARGET),powerpc64-linux)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
 endif
+ifeq ($(FULL_TARGET),powerpc64-darwin)
+override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
+endif
 ifeq ($(FULL_TARGET),powerpc64-embedded)
 override COMPILER_SOURCEDIR+=$(INC) $(PROCINC) $(COMMON)
 endif
@@ -2149,7 +2161,7 @@ cprt07$(OEXT) : cprt07.as
 	$(AS) $(ASTARGET) -o $(UNITTARGETDIRPREFIX)cprt07$(OEXT) cprt07.as
 cprt09$(OEXT) : cprt09.as
 	$(AS) $(ASTARGET) -o $(UNITTARGETDIRPREFIX)cprt09$(OEXT) cprt09.as
-$(SYSTEMUNIT)$(PPUEXT) : $(SYSTEMUNIT).pp $(SYSDEPS)
+$(SYSTEMUNIT)$(PPUEXT) : $(SYSTEMUNIT).pp $(SYSDEPS) $(INC)/softfpu.pp
 	$(COMPILER) -Us -Sg $(SYSTEMUNIT).pp $(REDIR)
 objpas$(PPUEXT): $(OBJPASDIR)/objpas.pp $(INC)/except.inc $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) -I$(OBJPASDIR) $(OBJPASDIR)/objpas.pp $(REDIR)

+ 2 - 2
rtl/nds/Makefile.fpc

@@ -53,7 +53,7 @@ endif
 OBJPASDIR=$(RTL)/objpas
 GRAPHDIR=$(INC)/graph
 
-[rules]
+[rules]
 .NOTPARALLEL:
 # Get the system independent include file names.
 # This will set the following variables :
@@ -91,7 +91,7 @@ cprt09$(OEXT) : cprt09.as
 # Base Units (System, strings, os-dependent-base-unit)
 #
 
-$(SYSTEMUNIT)$(PPUEXT) : $(SYSTEMUNIT).pp $(SYSDEPS)
+$(SYSTEMUNIT)$(PPUEXT) : $(SYSTEMUNIT).pp $(SYSDEPS) $(INC)/softfpu.pp
         $(COMPILER) -Us -Sg $(SYSTEMUNIT).pp $(REDIR)
 
 objpas$(PPUEXT): $(OBJPASDIR)/objpas.pp $(INC)/except.inc $(SYSTEMUNIT)$(PPUEXT)

+ 3 - 0
rtl/nds/classes.pp

@@ -24,6 +24,9 @@ uses
   sysutils,
   rtlconsts,
   types,
+{$ifdef FPC_TESTGENERICS}
+  fgl,
+{$endif}
   typinfo;
 
 {$i classesh.inc}

+ 2 - 5
rtl/nds/prt09.as

@@ -101,8 +101,8 @@ _start:
 	@-------------------------------------------------------------------------
 	@ DCache & ICache enable
 	@-------------------------------------------------------------------------
-	ldr	r0,=0b01000110
-	ldr	r0,=0x42
+	ldr	r0,=0b01000010
+
 	mcr	p15, 0, r0, c2, c0, 0
 	mcr	p15, 0, r0, c2, c0, 1
 
@@ -162,9 +162,6 @@ _start:
 	ldr	r0, =__eheap_end
 	str	r0, [r1]
 
-
-
-
 	mov	r0, #0			@ int argc
 	mov	r1, #0			@ char *argv[]
 	ldr	r3, =main

+ 36 - 34
rtl/nds/sysheap.inc

@@ -1,34 +1,36 @@
-{
-    This file is part of the Free Pascal run time library.
-    Copyright (c) 2005 by Free Pascal development team
-
-    Low level memory functions
-
-    Heap functions unit for Nintendo DS
-    Copyright (c) 2006 by Francesco Lombardi
-
-    See the file COPYING.FPC, included in this distribution,
-    for details about the copyright.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
- **********************************************************************}
-
-{*****************************************************************************
-      OS Memory allocation / deallocation
- ****************************************************************************}
-
-
-function SysOSAlloc(size: ptrint): pointer;
-begin
-  result := nil;//pointer($02000000);
-end;
-
-{ $define HAS_SYSOSFREE}
-
-procedure SysOSFree(p: pointer; size: ptrint);
-begin
-  
-end;
+{
+    This file is part of the Free Pascal run time library.
+    Copyright (c) 2005 by Free Pascal development team
+
+    Low level memory functions
+
+    Heap functions unit for Nintendo DS
+    Copyright (c) 2006 by Francesco Lombardi
+
+    See the file COPYING.FPC, included in this distribution,
+    for details about the copyright.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ **********************************************************************}
+
+{*****************************************************************************
+      OS Memory allocation / deallocation
+ ****************************************************************************}
+
+var
+  heap_start: longint; external name '_end';
+  
+function SysOSAlloc(size: ptruint): pointer;
+begin
+  result := @heap_start;
+end;
+
+{ $define HAS_SYSOSFREE}
+
+procedure SysOSFree(p: pointer; size: ptruint);
+begin
+  
+end;

+ 53 - 48
rtl/nds/system.pp

@@ -20,31 +20,29 @@ interface
 {$define FPC_IS_SYSTEM}
 
 {$i ndsbiosh.inc}
-
-{$I systemh.inc}
+{$i systemh.inc}
 
 {$define fpc_softfpu_interface}
 {$i softfpu.pp}
 {$undef fpc_softfpu_interface}
 
+function IsARM9(): boolean; 
 
 const
- LineEnding = #10;
- LFNSupport = true;
- CtrlZMarksEOF: boolean = false;
- DirectorySeparator = '/';
- DriveSeparator = ':';
- PathSeparator = ';';
- FileNameCaseSensitive = false;
- maxExitCode = 255;
- MaxPathLen = 255;
+  LineEnding = #10;
+  LFNSupport = true;
+  CtrlZMarksEOF: boolean = false;
+  DirectorySeparator = '/';
+  DriveSeparator = ':';
+  PathSeparator = ';';
+  FileNameCaseSensitive = false;
+  maxExitCode = 255;
+  MaxPathLen = 255;
   AllFilesMask = '*';
 
+  sLineBreak: string[1] = LineEnding;
+  DefaultTextLineBreakStyle: TTextLineBreakStyle = tlbsCRLF;
 
- sLineBreak : string[1] = LineEnding;
- DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
-
-const
   UnusedHandle    = $ffff;
   StdInputHandle  = 0;
   StdOutputHandle = 1;
@@ -56,8 +54,7 @@ var
   argv: PPChar;
   envp: PPChar;
   errno: integer;
-  fake_heap_start: pchar; cvar;
-  fake_heap_end: pchar; cvar;
+  fake_heap_end: ^byte; cvar; 
 
 implementation
 
@@ -77,13 +74,37 @@ implementation
 {$define FPC_SYSTEM_HAS_extractFloat32Exp}
 {$define FPC_SYSTEM_HAS_extractFloat32Sign}
 
-{$I system.inc}
-
+{$i system.inc}
 {$i ndsbios.inc}
 
+
+{ 
+  NDS CPU detecting function (thanks to 21o6): 
+  --------------------------------------------
+   "You see, the ARM7 can't write to bank A of VRAM, but it doesn't give any 
+    error ... it just doesn't write there... so it's easily determinable what 
+    CPU is running the code"
+   
+   ARM946E-S processor can handle dsp extensions extensions, but ARM7TDMI does 
+   not. FPC can't retrieve the CPU target at compiling time, so this small
+   function takes care to check if the code is running on an ARM9 or on an ARM7
+   CPU. It works on Nintendo DS only, I guess :)
+}
+function IsARM9(): boolean; 
+var
+  Dummy : pword absolute $06800000;
+  tmp: word;
+begin
+  tmp := Dummy^;
+  Dummy^ := $C0DE;
+  IsARM9 := Dummy^ = $C0DE;
+  Dummy^ := tmp;
+end;
+
 {$ifdef FPC_HAS_FEATURE_PROCESSES}
 function GetProcessID: SizeUInt;
 begin
+  GetProcessID := 0;
 end;
 {$endif}
 
@@ -93,6 +114,7 @@ end;
 *****************************************************************************}
 procedure System_exit;
 begin
+  // Boo!
 end;
 
 
@@ -104,18 +126,19 @@ end;
 { number of args }
 function paramcount : longint;
 begin
-  paramcount:=0;
+  paramcount := 0;
 end;
 
 { argument number l }
 function paramstr(l : longint) : string;
 begin
-  paramstr:='';
+  paramstr := '';
 end;
 
 { set randseed to a new pseudo random value }
 procedure randomize;
 begin
+  // Boo!
 end;
 
 {$ifdef FPC_HAS_FEATURE_TEXTIO}
@@ -134,41 +157,23 @@ begin
 end;
 
 
-procedure InitHeap;
-begin
-{
-  FillChar(freelists_fixed,sizeof(tfreelists),0);
-  FillChar(freelists_free_chunk,sizeof(freelists_free_chunk),0);
-
-  freelist_var:=nil;
-  freeoslistcount:=1;
-  freeoslist:=pointer($2040000);
-  fillchar(freeoslist^,sizeof(freeoslist^),0);
-  freeoslist^.size:=$40000;
-  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 }
 
+{ Set up signals handlers }
+  if IsARM9 then 
+    fpc_cpucodeinit;
+    
 { Setup heap }
   InitHeap;
-  //SysInitExceptions;
+  SysInitExceptions;
 { Setup stdin, stdout and stderr }
-  //SysInitStdIO;
+  SysInitStdIO;
 { Reset IO Error }
-  InOutRes := 0;
+  InOutRes:=0;
 { Arguments }
-
-  //InitSystemThreads;
-  //initvariantmanager;
-  //initwidestringmanager;
+  InitSystemThreads;
+  initvariantmanager;
 end.