implemented support for the AVR CPU and standalone OS
This commit is contained in:
parent
97743faa83
commit
142e849b91
7 changed files with 122 additions and 32 deletions
|
|
@ -778,6 +778,9 @@ proc genMainProc(m: BModule) =
|
||||||
PosixCMain = "int main(int argc, char** args, char** env) {$n" &
|
PosixCMain = "int main(int argc, char** args, char** env) {$n" &
|
||||||
" cmdLine = args;$n" & " cmdCount = argc;$n" & " gEnv = env;$n" &
|
" cmdLine = args;$n" & " cmdCount = argc;$n" & " gEnv = env;$n" &
|
||||||
" NimMain();$n" & " return nim_program_result;$n" & "}$n"
|
" NimMain();$n" & " return nim_program_result;$n" & "}$n"
|
||||||
|
StandaloneCMain = "int main(void) {$n" &
|
||||||
|
" NimMain();$n" &
|
||||||
|
" return 0;$n" & "}$n"
|
||||||
WinNimMain = "N_CDECL(void, NimMain)(void) {$n" &
|
WinNimMain = "N_CDECL(void, NimMain)(void) {$n" &
|
||||||
CommonMainBody & "}$n"
|
CommonMainBody & "}$n"
|
||||||
WinCMain = "N_STDCALL(int, WinMain)(HINSTANCE hCurInstance, $n" &
|
WinCMain = "N_STDCALL(int, WinMain)(HINSTANCE hCurInstance, $n" &
|
||||||
|
|
@ -807,6 +810,9 @@ proc genMainProc(m: BModule) =
|
||||||
elif optGenDynLib in gGlobalOptions:
|
elif optGenDynLib in gGlobalOptions:
|
||||||
nimMain = posixNimDllMain
|
nimMain = posixNimDllMain
|
||||||
otherMain = posixCDllMain
|
otherMain = posixCDllMain
|
||||||
|
elif platform.targetOS == osStandalone:
|
||||||
|
nimMain = PosixNimMain
|
||||||
|
otherMain = StandaloneCMain
|
||||||
else:
|
else:
|
||||||
nimMain = PosixNimMain
|
nimMain = PosixNimMain
|
||||||
otherMain = PosixCMain
|
otherMain = PosixCMain
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ type
|
||||||
# conditionals to condsyms (end of module).
|
# conditionals to condsyms (end of module).
|
||||||
osNone, osDos, osWindows, osOs2, osLinux, osMorphos, osSkyos, osSolaris,
|
osNone, osDos, osWindows, osOs2, osLinux, osMorphos, osSkyos, osSolaris,
|
||||||
osIrix, osNetbsd, osFreebsd, osOpenbsd, osAix, osPalmos, osQnx, osAmiga,
|
osIrix, osNetbsd, osFreebsd, osOpenbsd, osAix, osPalmos, osQnx, osAmiga,
|
||||||
osAtari, osNetware, osMacos, osMacosx, osEcmaScript, osNimrodVM
|
osAtari, osNetware, osMacos, osMacosx, osEcmaScript, osNimrodVM,
|
||||||
|
osStandalone
|
||||||
|
|
||||||
type
|
type
|
||||||
TInfoOSProp* = enum
|
TInfoOSProp* = enum
|
||||||
|
|
@ -139,14 +140,18 @@ const
|
||||||
exeExt: "", extSep: ".", props: {}),
|
exeExt: "", extSep: ".", props: {}),
|
||||||
(name: "NimrodVM", parDir: "..", dllFrmt: "lib$1.so", altDirSep: "/",
|
(name: "NimrodVM", parDir: "..", dllFrmt: "lib$1.so", altDirSep: "/",
|
||||||
objExt: ".o", newLine: "\x0A", pathSep: ":", dirSep: "/",
|
objExt: ".o", newLine: "\x0A", pathSep: ":", dirSep: "/",
|
||||||
scriptExt: ".sh", curDir: ".", exeExt: "", extSep: ".", props: {})]
|
scriptExt: ".sh", curDir: ".", exeExt: "", extSep: ".", props: {}),
|
||||||
|
(name: "Standalone", parDir: "..", dllFrmt: "lib$1.so", altDirSep: "/",
|
||||||
|
objExt: ".o", newLine: "\x0A", pathSep: ":", dirSep: "/",
|
||||||
|
scriptExt: ".sh", curDir: ".", exeExt: ".elf", extSep: ".",
|
||||||
|
props: {})]
|
||||||
|
|
||||||
type
|
type
|
||||||
TSystemCPU* = enum # Also add CPU for in initialization section and
|
TSystemCPU* = enum # Also add CPU for in initialization section and
|
||||||
# alias conditionals to condsyms (end of module).
|
# alias conditionals to condsyms (end of module).
|
||||||
cpuNone, cpuI386, cpuM68k, cpuAlpha, cpuPowerpc, cpuPowerpc64,
|
cpuNone, cpuI386, cpuM68k, cpuAlpha, cpuPowerpc, cpuPowerpc64,
|
||||||
cpuSparc, cpuVm, cpuIa64, cpuAmd64, cpuMips, cpuArm,
|
cpuSparc, cpuVm, cpuIa64, cpuAmd64, cpuMips, cpuArm,
|
||||||
cpuEcmaScript, cpuNimrodVM
|
cpuEcmaScript, cpuNimrodVM, cpuAVR
|
||||||
|
|
||||||
type
|
type
|
||||||
TEndian* = enum
|
TEndian* = enum
|
||||||
|
|
@ -169,7 +174,8 @@ const
|
||||||
(name: "mips", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
(name: "mips", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
||||||
(name: "arm", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32),
|
(name: "arm", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32),
|
||||||
(name: "ecmascript", intSize: 32, endian: bigEndian,floatSize: 64,bit: 32),
|
(name: "ecmascript", intSize: 32, endian: bigEndian,floatSize: 64,bit: 32),
|
||||||
(name: "nimrodvm", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32)]
|
(name: "nimrodvm", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
||||||
|
(name: "avr", intSize: 16, endian: littleEndian, floatSize: 32, bit: 16)]
|
||||||
|
|
||||||
var
|
var
|
||||||
targetCPU*, hostCPU*: TSystemCPU
|
targetCPU*, hostCPU*: TSystemCPU
|
||||||
|
|
|
||||||
2
koch.nim
2
koch.nim
|
|
@ -141,7 +141,7 @@ proc boot(args: string) =
|
||||||
return
|
return
|
||||||
copyExe(output, (i+1).thVersion)
|
copyExe(output, (i+1).thVersion)
|
||||||
copyExe(output, finalDest)
|
copyExe(output, finalDest)
|
||||||
echo "[Warning] executables are still not equal"
|
when not defined(windows): echo "[Warning] executables are still not equal"
|
||||||
|
|
||||||
# -------------- clean --------------------------------------------------------
|
# -------------- clean --------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -851,7 +851,7 @@ template sysAssert(cond: bool, msg: string) =
|
||||||
|
|
||||||
include "system/inclrtl"
|
include "system/inclrtl"
|
||||||
|
|
||||||
when not defined(ecmascript) and not defined(nimrodVm):
|
when not defined(ecmascript) and not defined(nimrodVm) and not defined(avr):
|
||||||
include "system/cgprocs"
|
include "system/cgprocs"
|
||||||
|
|
||||||
proc add *[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.}
|
proc add *[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.}
|
||||||
|
|
@ -1604,9 +1604,10 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
||||||
{.push stack_trace: off.}
|
{.push stack_trace: off.}
|
||||||
|
|
||||||
proc initGC()
|
proc initGC()
|
||||||
when not defined(boehmgc):
|
when not defined(boehmgc) and not defined(useMalloc):
|
||||||
proc initAllocator() {.inline.}
|
proc initAllocator() {.inline.}
|
||||||
|
|
||||||
|
when not defined(nogc):
|
||||||
proc initStackBottom() {.inline.} =
|
proc initStackBottom() {.inline.} =
|
||||||
# WARNING: This is very fragile! An array size of 8 does not work on my
|
# WARNING: This is very fragile! An array size of 8 does not work on my
|
||||||
# Linux 64bit system. Very strange, but we are at the will of GCC's
|
# Linux 64bit system. Very strange, but we are at the will of GCC's
|
||||||
|
|
@ -1868,7 +1869,7 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
||||||
when hasThreadSupport:
|
when hasThreadSupport:
|
||||||
include "system/syslocks"
|
include "system/syslocks"
|
||||||
include "system/threads"
|
include "system/threads"
|
||||||
else:
|
elif not defined(nogc):
|
||||||
initStackBottom()
|
initStackBottom()
|
||||||
initGC()
|
initGC()
|
||||||
|
|
||||||
|
|
@ -1881,21 +1882,23 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
||||||
## for debug builds.
|
## for debug builds.
|
||||||
|
|
||||||
{.push stack_trace: off.}
|
{.push stack_trace: off.}
|
||||||
|
when hostCPU == "avr":
|
||||||
|
include "system/embedded"
|
||||||
|
else:
|
||||||
include "system/excpt"
|
include "system/excpt"
|
||||||
|
|
||||||
# we cannot compile this with stack tracing on
|
# we cannot compile this with stack tracing on
|
||||||
# as it would recurse endlessly!
|
# as it would recurse endlessly!
|
||||||
include "system/arithm"
|
include "system/arithm"
|
||||||
{.pop.} # stack trace
|
{.pop.} # stack trace
|
||||||
{.pop.} # stack trace
|
{.pop.} # stack trace
|
||||||
|
|
||||||
include "system/dyncalls"
|
when hostOS != "standalone": include "system/dyncalls"
|
||||||
include "system/sets"
|
include "system/sets"
|
||||||
|
|
||||||
const
|
const
|
||||||
GenericSeqSize = (2 * sizeof(int))
|
GenericSeqSize = (2 * sizeof(int))
|
||||||
|
|
||||||
proc reprAny(p: pointer, typ: PNimType): string {.compilerRtl.}
|
|
||||||
|
|
||||||
proc getDiscriminant(aa: Pointer, n: ptr TNimNode): int =
|
proc getDiscriminant(aa: Pointer, n: ptr TNimNode): int =
|
||||||
sysAssert(n.kind == nkCase, "getDiscriminant: node != nkCase")
|
sysAssert(n.kind == nkCase, "getDiscriminant: node != nkCase")
|
||||||
var d: int
|
var d: int
|
||||||
|
|
@ -1918,7 +1921,7 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
||||||
|
|
||||||
include "system/mmdisp"
|
include "system/mmdisp"
|
||||||
{.push stack_trace: off.}
|
{.push stack_trace: off.}
|
||||||
include "system/sysstr"
|
when hostCPU != "avr": include "system/sysstr"
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
include "system/sysio"
|
include "system/sysio"
|
||||||
|
|
@ -1938,6 +1941,7 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
||||||
var res = TaintedString(newStringOfCap(80))
|
var res = TaintedString(newStringOfCap(80))
|
||||||
while f.readLine(res): yield TaintedString(res)
|
while f.readLine(res): yield TaintedString(res)
|
||||||
|
|
||||||
|
when hostCPU != "avr":
|
||||||
include "system/assign"
|
include "system/assign"
|
||||||
include "system/repr"
|
include "system/repr"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ else:
|
||||||
proc writeToStdErr(msg: CString) =
|
proc writeToStdErr(msg: CString) =
|
||||||
discard MessageBoxA(0, msg, nil, 0)
|
discard MessageBoxA(0, msg, nil, 0)
|
||||||
|
|
||||||
proc registerSignalHandler() {.compilerproc.}
|
proc registerSignalHandler()
|
||||||
|
|
||||||
proc chckIndx(i, a, b: int): int {.inline, compilerproc.}
|
proc chckIndx(i, a, b: int): int {.inline, compilerproc.}
|
||||||
proc chckRange(i, a, b: int): int {.inline, compilerproc.}
|
proc chckRange(i, a, b: int): int {.inline, compilerproc.}
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,78 @@ when defined(boehmgc):
|
||||||
proc deallocOsPages() {.inline.} = nil
|
proc deallocOsPages() {.inline.} = nil
|
||||||
|
|
||||||
include "system/cellsets"
|
include "system/cellsets"
|
||||||
|
elif defined(nogc) and defined(useMalloc):
|
||||||
|
|
||||||
|
when not defined(useNimRtl):
|
||||||
|
proc alloc(size: int): pointer =
|
||||||
|
result = cmalloc(size)
|
||||||
|
if result == nil: raiseOutOfMem()
|
||||||
|
proc alloc0(size: int): pointer =
|
||||||
|
result = alloc(size)
|
||||||
|
zeroMem(result, size)
|
||||||
|
proc realloc(p: Pointer, newsize: int): pointer =
|
||||||
|
result = crealloc(p, newsize)
|
||||||
|
if result == nil: raiseOutOfMem()
|
||||||
|
proc dealloc(p: Pointer) = cfree(p)
|
||||||
|
|
||||||
|
proc allocShared(size: int): pointer =
|
||||||
|
result = cmalloc(size)
|
||||||
|
if result == nil: raiseOutOfMem()
|
||||||
|
proc allocShared0(size: int): pointer =
|
||||||
|
result = alloc(size)
|
||||||
|
zeroMem(result, size)
|
||||||
|
proc reallocShared(p: Pointer, newsize: int): pointer =
|
||||||
|
result = crealloc(p, newsize)
|
||||||
|
if result == nil: raiseOutOfMem()
|
||||||
|
proc deallocShared(p: Pointer) = cfree(p)
|
||||||
|
|
||||||
|
proc GC_disable() = nil
|
||||||
|
proc GC_enable() = nil
|
||||||
|
proc GC_fullCollect() = nil
|
||||||
|
proc GC_setStrategy(strategy: TGC_Strategy) = nil
|
||||||
|
proc GC_enableMarkAndSweep() = nil
|
||||||
|
proc GC_disableMarkAndSweep() = nil
|
||||||
|
proc GC_getStatistics(): string = return ""
|
||||||
|
|
||||||
|
proc getOccupiedMem(): int = nil
|
||||||
|
proc getFreeMem(): int = nil
|
||||||
|
proc getTotalMem(): int = nil
|
||||||
|
|
||||||
|
proc setStackBottom(theStackBottom: pointer) = nil
|
||||||
|
|
||||||
|
proc initGC() = nil
|
||||||
|
|
||||||
|
proc newObj(typ: PNimType, size: int): pointer {.compilerproc.} =
|
||||||
|
result = alloc(size)
|
||||||
|
proc newSeq(typ: PNimType, len: int): pointer {.compilerproc.} =
|
||||||
|
result = newObj(typ, addInt(mulInt(len, typ.base.size), GenericSeqSize))
|
||||||
|
cast[PGenericSeq](result).len = len
|
||||||
|
cast[PGenericSeq](result).reserved = len
|
||||||
|
|
||||||
|
proc growObj(old: pointer, newsize: int): pointer =
|
||||||
|
result = realloc(old, newsize)
|
||||||
|
|
||||||
|
proc nimGCref(p: pointer) {.compilerproc, inline.} = nil
|
||||||
|
proc nimGCunref(p: pointer) {.compilerproc, inline.} = nil
|
||||||
|
|
||||||
|
proc unsureAsgnRef(dest: ppointer, src: pointer) {.compilerproc, inline.} =
|
||||||
|
dest[] = src
|
||||||
|
proc asgnRef(dest: ppointer, src: pointer) {.compilerproc, inline.} =
|
||||||
|
dest[] = src
|
||||||
|
proc asgnRefNoCycle(dest: ppointer, src: pointer) {.compilerproc, inline.} =
|
||||||
|
dest[] = src
|
||||||
|
|
||||||
|
type
|
||||||
|
TMemRegion = object {.final, pure.}
|
||||||
|
|
||||||
|
proc Alloc(r: var TMemRegion, size: int): pointer =
|
||||||
|
result = alloc(size)
|
||||||
|
proc Alloc0(r: var TMemRegion, size: int): pointer =
|
||||||
|
result = alloc0(size)
|
||||||
|
proc Dealloc(r: var TMemRegion, p: Pointer) = Dealloc(p)
|
||||||
|
proc deallocOsPages(r: var TMemRegion) {.inline.} = nil
|
||||||
|
proc deallocOsPages() {.inline.} = nil
|
||||||
|
|
||||||
elif defined(nogc):
|
elif defined(nogc):
|
||||||
# Even though we don't want the GC, we cannot simply use C's memory manager
|
# Even though we don't want the GC, we cannot simply use C's memory manager
|
||||||
# because Nimrod's runtime wants ``realloc`` to zero out the additional
|
# because Nimrod's runtime wants ``realloc`` to zero out the additional
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
# The generic ``repr`` procedure. It is an invaluable debugging tool.
|
# The generic ``repr`` procedure. It is an invaluable debugging tool.
|
||||||
|
|
||||||
|
proc reprAny(p: pointer, typ: PNimType): string {.compilerRtl.}
|
||||||
|
|
||||||
proc reprInt(x: int64): string {.compilerproc.} = return $x
|
proc reprInt(x: int64): string {.compilerproc.} = return $x
|
||||||
proc reprFloat(x: float): string {.compilerproc.} = return $x
|
proc reprFloat(x: float): string {.compilerproc.} = return $x
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue