Added asmc package

This commit is contained in:
2025-02-06 23:26:10 +01:00
parent cae3092df7
commit 78aee7999b
14 changed files with 464 additions and 386 deletions

41
src/asmc/dllCall.go Normal file
View File

@ -0,0 +1,41 @@
package asmc
import (
"strings"
"git.akyoto.dev/cli/q/src/asm"
"git.akyoto.dev/cli/q/src/x86"
)
func (c *compiler) dllCall(x asm.Instruction) {
size := 4
// TODO: R15 could be in use.
c.code = x86.MoveRegisterRegister(c.code, x86.R15, x86.RSP)
c.code = x86.AlignStack(c.code)
c.code = x86.SubRegisterNumber(c.code, x86.RSP, 32)
c.code = x86.CallAtAddress(c.code, 0x00_00_00_00)
position := len(c.code) - size
c.code = x86.MoveRegisterRegister(c.code, x86.RSP, x86.R15)
label := x.Data.(*asm.Label)
pointer := &pointer{
Position: Address(position),
OpSize: 2,
Size: uint8(size),
}
pointer.Resolve = func() Address {
dot := strings.Index(label.Name, ".")
library := label.Name[:dot]
funcName := label.Name[dot+1:]
index := c.dlls.Index(library, funcName)
if index == -1 {
panic("unknown DLL function " + label.Name)
}
return Address(index * 8)
}
c.dllPointers = append(c.dllPointers, pointer)
}