123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- {
- This file is part of the Free Pascal run time library.
- Copyright (c) 2023 by Karoly Balogh
- System unit for the Human 68k (Sharp X68000)
- 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.
- **********************************************************************}
- unit System;
- interface
- {$define FPC_IS_SYSTEM}
- {$define FPC_STDOUT_TRUE_ALIAS}
- {$define FPC_ANSI_TEXTFILEREC}
- {$define FPC_SYSTEM_EXIT_NO_RETURN}
- {$define FPC_SYSTEM_NO_VERBOSE_UNICODEERROR}
- {$.define FPC_HUMAN68K_USE_TINYHEAP}
- {$ifdef FPC_HUMAN68K_USE_TINYHEAP}
- {$define HAS_MEMORYMANAGER}
- {$endif FPC_HUMAN68K_USE_TINYHEAP}
- {$i systemh.inc}
- {$ifdef FPC_HUMAN68K_USE_TINYHEAP}
- {$i tnyheaph.inc}
- {$endif FPC_HUMAN68K_USE_TINYHEAP}
- {Platform specific information}
- const
- LineEnding = #13#10;
- LFNSupport = false;
- CtrlZMarksEOF: boolean = false; (* #26 not considered as end of file *)
- DirectorySeparator = '\';
- DriveSeparator = ':';
- ExtensionSeparator = '.';
- PathSeparator = ';';
- AllowDirectorySeparators : set of char = ['\','/'];
- AllowDriveSeparators : set of char = [':'];
- FileNameCaseSensitive = false;
- FileNameCasePreserving = false;
- maxExitCode = 255;
- MaxPathLen = 255;
- AllFilesMask = '*.*';
- sLineBreak = LineEnding;
- DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
- const
- UnusedHandle = -1;
- StdInputHandle: longint = 0;
- StdOutputHandle: longint = 1;
- StdErrorHandle: longint = 2;
- var
- args: PChar;
- argc: LongInt;
- argv: PPChar;
- envp: PPChar;
- human68k_vernum: word;
- {$if defined(FPUSOFT)}
- {$define fpc_softfpu_interface}
- {$i softfpu.pp}
- {$undef fpc_softfpu_interface}
- {$endif defined(FPUSOFT)}
- implementation
- {$if defined(FPUSOFT)}
- {$define fpc_softfpu_implementation}
- {$define softfpu_compiler_mul32to64}
- {$define softfpu_inline}
- {$i softfpu.pp}
- {$undef fpc_softfpu_implementation}
- { we get these functions and types from the softfpu code }
- {$define FPC_SYSTEM_HAS_float64}
- {$define FPC_SYSTEM_HAS_float32}
- {$define FPC_SYSTEM_HAS_flag}
- {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
- {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
- {$define FPC_SYSTEM_HAS_extractFloat64Exp}
- {$define FPC_SYSTEM_HAS_extractFloat64Sign}
- {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
- {$define FPC_SYSTEM_HAS_extractFloat32Exp}
- {$define FPC_SYSTEM_HAS_extractFloat32Sign}
- {$endif defined(FPUSOFT)}
- {$i system.inc}
- {$ifdef FPC_HUMAN68K_USE_TINYHEAP}
- {$i tinyheap.inc}
- {$endif FPC_HUMAN68K_USE_TINYHEAP}
- function GetProcessID:SizeUInt;
- begin
- GetProcessID := 1;
- end;
- var
- h68k_startup: Th68kdos_startup; external name '_h68k_startup';
- h68k_psp: Ph68kdos_psp; external name '_h68k_psp';
- {$ifdef FPC_HUMAN68K_USE_TINYHEAP}
- initial_heap_start: pointer; public name '__initial_heap_start';
- initial_heap_end: pointer; public name '__initial_heap_end';
- {$endif FPC_HUMAN68K_USE_TINYHEAP}
- {*****************************************************************************
- Platform Specific Helpers
- *****************************************************************************}
- function h68kdos_exec0(const fil: pchar; p1: pointer; p2: pointer): longint; assembler; public name '_fpc_h68kdos_exec0';
- asm
- movem.l d2-d7/a2-a6,-(sp)
- move.l p2,-(sp)
- move.l p1,-(sp)
- move.l fil,-(sp)
- move.w #0,-(sp)
- dc.w $ff4b
- lea.l 14(sp),sp
- movem.l (sp)+,d2-d7/a2-a6
- end;
- {*****************************************************************************
- ParamStr
- *****************************************************************************}
- { number of args }
- function ParamCount: LongInt;
- begin
- ParamCount:=argc;
- end;
- { argument number l }
- function ParamStr(l: LongInt): shortstring;
- begin
- if assigned(argv) and (l >= 0) and (l <= argc) then
- ParamStr:=argv[l]
- else
- ParamStr:='';
- end;
- procedure GenerateArgs;
- var
- argcc: longint;
- argl,pathlen,namelen: longint;
- p: pchar;
- argsp: pchar;
- inquotes: boolean;
- inarg: boolean;
- i: longint;
- begin
- inquotes:=false;
- inarg:=false;
- if not assigned(h68k_startup.comm) then
- exit;
- p:=@h68k_startup.comm^.buffer;
- argl:=h68k_startup.comm^.len;
- args:=GetMem(argl+1);
- if not assigned(args) then
- exit;
- fillchar(args^,argl+1,#0);
- argsp:=args;
- for i:=0 to argl-1 do
- begin
- case p[i] of
- ' ':
- begin
- if not inquotes then
- begin
- if inarg then
- begin
- inc(argc);
- inarg:=false;
- end;
- argsp^:=#0;
- end
- else
- argsp^:=p[i];
- inc(argsp);
- end;
- '"':
- begin
- inquotes:=not inquotes;
- end;
- else
- begin
- inarg:=true;
- argsp^:=p[i];
- inc(argsp);
- end;
- end;
- end;
- if inarg then
- inc(argc);
- argv:=GetMem(argc+1);
- if not assigned(argv) then
- exit;
- argsp:=args;
- argcc:=0;
- inarg:=false;
- while (argsp < (args + argl)) and (argcc < argc) do
- begin
- if argsp^ = #0 then
- inarg:=false
- else
- if not inarg then
- begin
- inarg:=true;
- argv[argcc+1]:=argsp;
- inc(argcc);
- end;
- inc(argsp);
- end;
- pathlen:=strlen(h68k_psp^.exe_path);
- namelen:=strlen(h68k_psp^.exe_name);
- argl:=pathlen+namelen;
- argv[0]:=GetMem(argl+1);
- if not assigned(argv[0]) then
- exit;
- Move(h68k_psp^.exe_path[0],argv[0][0],pathlen);
- Move(h68k_psp^.exe_name[0],argv[0][pathlen],namelen);
- argv[0][argl]:=#0;
- end;
- procedure SysInitParamsAndEnv;
- begin
- GenerateArgs;
- end;
- procedure randomize;
- begin
- {$WARNING: randseed is uninitialized}
- randseed:=0;
- end;
- {*****************************************************************************
- System Dependent Exit code
- *****************************************************************************}
- procedure haltproc(e:longint); noreturn; external name '_haltproc';
- Procedure system_exit; noreturn;
- begin
- haltproc(ExitCode);
- end;
- {*****************************************************************************
- System Unit Initialization
- *****************************************************************************}
- {$ifdef FPC_HUMAN68K_USE_TINYHEAP}
- procedure InitHeap;
- var
- aligned_heap_start: pointer;
- begin
- aligned_heap_start:=align(initial_heap_start,sizeof(ttinyheapblock));
- RegisterTinyHeapBlock_Simple_Prealigned(aligned_heap_start, ptruint(initial_heap_end - aligned_heap_start));
- end;
- {$endif FPC_HUMAN68K_USE_TINYHEAP}
- procedure SysInitStdIO;
- begin
- OpenStdIO(Input,fmInput,StdInputHandle);
- OpenStdIO(Output,fmOutput,StdOutputHandle);
- OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
- {$ifndef FPC_STDOUT_TRUE_ALIAS}
- OpenStdIO(StdOut,fmOutput,StdOutputHandle);
- OpenStdIO(StdErr,fmOutput,StdErrorHandle);
- {$endif FPC_STDOUT_TRUE_ALIAS}
- end;
- function CheckInitialStkLen (StkLen: SizeUInt): SizeUInt;
- begin
- CheckInitialStkLen := StkLen;
- end;
- begin
- human68k_vernum:=word(h68kdos_vernum);
- StackLength := CheckInitialStkLen (InitialStkLen);
- { Initialize ExitProc }
- ExitProc:=Nil;
- { Setup heap }
- InitHeap;
- SysInitExceptions;
- {$ifdef FPC_HAS_FEATURE_UNICODESTRINGS}
- InitUnicodeStringManager;
- {$endif FPC_HAS_FEATURE_UNICODESTRINGS}
- { Setup stdin, stdout and stderr }
- SysInitStdIO;
- { Reset IO Error }
- InOutRes:=0;
- { Setup command line arguments }
- SysInitParamsAndEnv;
- {$ifdef FPC_HAS_FEATURE_THREADING}
- InitSystemThreads;
- {$endif FPC_HAS_FEATURE_THREADING}
- end.
|