all: add linux/mipsle support

This adds linux/mipsle (little endian Mips) support to TinyGo.

It also adds experimental linux/mips (big-endian) support. It doesn't
quite work yet, some parts of the standard library (like the reflect
package) currently seem to assume a little-endian system.
This commit is contained in:
Ayke van Laethem
2024-06-24 20:22:16 +02:00
committed by Ron Evans
parent 04d1261f8a
commit 725518f007
23 changed files with 371 additions and 11 deletions
+2
View File
@@ -9,6 +9,8 @@ const deferExtraRegs = 0
const callInstSize = 5 // "call someFunction" is 5 bytes
const linux_MAP_ANONYMOUS = 0x20
// Align on word boundary.
func align(ptr uintptr) uintptr {
return (ptr + 15) &^ 15
+2
View File
@@ -9,6 +9,8 @@ const deferExtraRegs = 0
const callInstSize = 5 // "call someFunction" is 5 bytes
const linux_MAP_ANONYMOUS = 0x20
// Align a pointer.
// Note that some amd64 instructions (like movaps) expect 16-byte aligned
// memory, thus the result must be 16-byte aligned.
+2
View File
@@ -11,6 +11,8 @@ const deferExtraRegs = 0
const callInstSize = 4 // "bl someFunction" is 4 bytes
const linux_MAP_ANONYMOUS = 0x20
// Align on the maximum alignment for this platform (double).
func align(ptr uintptr) uintptr {
return (ptr + 7) &^ 7
+2
View File
@@ -9,6 +9,8 @@ const deferExtraRegs = 0
const callInstSize = 4 // "bl someFunction" is 4 bytes
const linux_MAP_ANONYMOUS = 0x20
// Align on word boundary.
func align(ptr uintptr) uintptr {
return (ptr + 15) &^ 15
+21
View File
@@ -0,0 +1,21 @@
package runtime
const GOARCH = "mips"
// The bitness of the CPU (e.g. 8, 32, 64).
const TargetBits = 32
const deferExtraRegs = 0
const callInstSize = 8 // "jal someFunc" is 4 bytes, plus a MIPS delay slot
const linux_MAP_ANONYMOUS = 0x800
// It appears that MIPS has a maximum alignment of 8 bytes.
func align(ptr uintptr) uintptr {
return (ptr + 7) &^ 7
}
func getCurrentStackPointer() uintptr {
return uintptr(stacksave())
}
+21
View File
@@ -0,0 +1,21 @@
package runtime
const GOARCH = "mipsle"
// The bitness of the CPU (e.g. 8, 32, 64).
const TargetBits = 32
const deferExtraRegs = 0
const callInstSize = 8 // "jal someFunc" is 4 bytes, plus a MIPS delay slot
const linux_MAP_ANONYMOUS = 0x800
// It appears that MIPS has a maximum alignment of 8 bytes.
func align(ptr uintptr) uintptr {
return (ptr + 7) &^ 7
}
func getCurrentStackPointer() uintptr {
return uintptr(stacksave())
}
+40
View File
@@ -0,0 +1,40 @@
.section .text.tinygo_scanCurrentStack
.global tinygo_scanCurrentStack
.type tinygo_scanCurrentStack, %function
tinygo_scanCurrentStack:
// Push callee-saved registers onto the stack.
addiu $sp, $sp, -40
sw $ra, 36($sp)
sw $s8, 32($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, ($sp)
// Scan the stack.
jal tinygo_scanstack
move $a0, $sp // in the branch delay slot
// Restore return address.
lw $ra, 36($sp)
// Restore stack state.
addiu $sp, $sp, 40
// Return to the caller.
jalr $ra
nop
.section .text.tinygo_longjmp
.global tinygo_longjmp
tinygo_longjmp:
// Note: the code we jump to assumes a0 is non-zero, which is already the
// case because that's the defer frame pointer.
lw $sp, 0($a0) // jumpSP
lw $a1, 4($a0) // jumpPC
jr $a1
nop
+1 -1
View File
@@ -14,7 +14,7 @@ const (
flag_PROT_READ = 0x1
flag_PROT_WRITE = 0x2
flag_MAP_PRIVATE = 0x2
flag_MAP_ANONYMOUS = 0x20
flag_MAP_ANONYMOUS = linux_MAP_ANONYMOUS // different on alpha, hppa, mips, xtensa
)
// Source: https://github.com/torvalds/linux/blob/master/include/uapi/linux/time.h
+3
View File
@@ -229,6 +229,9 @@ func preinit() {
// heap size.
// This can happen on 32-bit systems.
heapMaxSize /= 2
if heapMaxSize < 4096 {
runtimePanic("cannot allocate heap memory")
}
continue
}
heapStart = uintptr(addr)