hotfix: make 'nim doc nimhcr' work on all platforms

This commit is contained in:
Araq 2020-03-23 13:05:29 +01:00
commit e05fd1d00f

View file

@ -228,39 +228,39 @@ when defined(createNimHcr):
{.pragma: nimhcr, compilerProc, exportc, dynlib.} {.pragma: nimhcr, compilerProc, exportc, dynlib.}
when hostCPU in ["i386", "amd64"]: # XXX these types are CPU specific and need ARM etc support
type type
ShortJumpInstruction {.packed.} = object ShortJumpInstruction {.packed.} = object
opcode: byte opcode: byte
offset: int32 offset: int32
LongJumpInstruction {.packed.} = object LongJumpInstruction {.packed.} = object
opcode1: byte opcode1: byte
opcode2: byte opcode2: byte
offset: int32 offset: int32
absoluteAddr: pointer absoluteAddr: pointer
proc writeJump(jumpTableEntry: ptr LongJumpInstruction, targetFn: pointer) = proc writeJump(jumpTableEntry: ptr LongJumpInstruction, targetFn: pointer) =
let let
jumpFrom = jumpTableEntry.shift(sizeof(ShortJumpInstruction)) jumpFrom = jumpTableEntry.shift(sizeof(ShortJumpInstruction))
jumpDistance = distance(jumpFrom, targetFn) jumpDistance = distance(jumpFrom, targetFn)
if abs(jumpDistance) < 0x7fff0000: if abs(jumpDistance) < 0x7fff0000:
let shortJump = cast[ptr ShortJumpInstruction](jumpTableEntry) let shortJump = cast[ptr ShortJumpInstruction](jumpTableEntry)
shortJump.opcode = 0xE9 # relative jump shortJump.opcode = 0xE9 # relative jump
shortJump.offset = int32(jumpDistance) shortJump.offset = int32(jumpDistance)
else:
jumpTableEntry.opcode1 = 0xff # indirect absolute jump
jumpTableEntry.opcode2 = 0x25
when hostCPU == "i386":
# on x86 we write the absolute address of the following pointer
jumpTableEntry.offset = cast[int32](addr jumpTableEntry.absoluteAddr)
else: else:
jumpTableEntry.opcode1 = 0xff # indirect absolute jump # on x64, we use a relative address for the same location
jumpTableEntry.opcode2 = 0x25 jumpTableEntry.offset = 0
when hostCPU == "i386": jumpTableEntry.absoluteAddr = targetFn
# on x86 we write the absolute address of the following pointer
jumpTableEntry.offset = cast[int32](addr jumpTableEntry.absoluteAddr)
else:
# on x64, we use a relative address for the same location
jumpTableEntry.offset = 0
jumpTableEntry.absoluteAddr = targetFn
elif hostCPU == "arm": if hostCPU == "arm":
const jumpSize = 8 const jumpSize = 8
elif hostCPU == "arm64": elif hostCPU == "arm64":
const jumpSize = 16 const jumpSize = 16
@ -556,7 +556,7 @@ when defined(createNimHcr):
inc(generation) inc(generation)
trace "HCR RELOADING: ", generation trace "HCR RELOADING: ", generation
var traversedHandlerModules = initSet[string]() var traversedHandlerModules = initHashSet[string]()
proc recursiveExecuteHandlers(isBefore: bool, module: string) = proc recursiveExecuteHandlers(isBefore: bool, module: string) =
# do not process an already traversed module # do not process an already traversed module