Added asmc package
This commit is contained in:
41
src/asmc/dllCall.go
Normal file
41
src/asmc/dllCall.go
Normal 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)
|
||||
}
|
Reference in New Issue
Block a user