Added exe package to manage sections
This commit is contained in:
@ -3,7 +3,7 @@ package asmc
|
||||
import (
|
||||
"git.urbach.dev/cli/q/src/config"
|
||||
"git.urbach.dev/cli/q/src/elf"
|
||||
"git.urbach.dev/cli/q/src/fs"
|
||||
"git.urbach.dev/cli/q/src/exe"
|
||||
"git.urbach.dev/cli/q/src/macho"
|
||||
"git.urbach.dev/cli/q/src/pe"
|
||||
)
|
||||
@ -21,6 +21,5 @@ func codeOffset() Address {
|
||||
headerEnd = pe.HeaderEnd
|
||||
}
|
||||
|
||||
offset, _ := fs.Align(headerEnd, config.Align)
|
||||
return offset
|
||||
return exe.Align(headerEnd, config.FileAlign)
|
||||
}
|
||||
|
@ -13,4 +13,5 @@ type compiler struct {
|
||||
dlls dll.List
|
||||
codeStart Address
|
||||
dataStart Address
|
||||
importsStart Address
|
||||
}
|
||||
|
@ -8,15 +8,15 @@ import (
|
||||
)
|
||||
|
||||
func (c *compiler) dllCall(x asm.Instruction) {
|
||||
size := 4
|
||||
c.code = x86.CallAt(c.code, 0x00_00_00_00)
|
||||
position := len(c.code) - size
|
||||
next := Address(len(c.code))
|
||||
position := next - 4
|
||||
label := x.Data.(*asm.Label)
|
||||
|
||||
pointer := &pointer{
|
||||
Position: Address(position),
|
||||
OpSize: 2,
|
||||
Size: uint8(size),
|
||||
Size: 4,
|
||||
}
|
||||
|
||||
pointer.Resolve = func() Address {
|
||||
@ -29,7 +29,9 @@ func (c *compiler) dllCall(x asm.Instruction) {
|
||||
panic("unknown DLL function " + label.Name)
|
||||
}
|
||||
|
||||
return Address(index * 8)
|
||||
destination := c.importsStart + Address(index*8)
|
||||
from := c.codeStart + next
|
||||
return destination - from
|
||||
}
|
||||
|
||||
c.dllPointers = append(c.dllPointers, pointer)
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"slices"
|
||||
|
||||
"git.urbach.dev/cli/q/src/config"
|
||||
"git.urbach.dev/cli/q/src/fs"
|
||||
"git.urbach.dev/cli/q/src/exe"
|
||||
"git.urbach.dev/cli/q/src/sizeof"
|
||||
)
|
||||
|
||||
@ -77,7 +77,9 @@ restart:
|
||||
}
|
||||
}
|
||||
|
||||
c.dataStart, _ = fs.Align(c.codeStart+Address(len(c.code)), config.Align)
|
||||
sections := exe.MakeSections(int(codeOffset()), c.code, c.data, nil)
|
||||
data := sections[1]
|
||||
c.dataStart = Address(data.MemoryOffset)
|
||||
|
||||
for _, pointer := range c.dataPointers {
|
||||
address := pointer.Resolve()
|
||||
@ -86,14 +88,13 @@ restart:
|
||||
}
|
||||
|
||||
if config.TargetOS == config.Windows {
|
||||
importsStart, _ := fs.Align(c.dataStart+Address(len(c.data)), config.Align)
|
||||
imports := sections[2]
|
||||
c.importsStart = Address(imports.MemoryOffset)
|
||||
|
||||
for _, pointer := range c.dllPointers {
|
||||
destination := importsStart + pointer.Resolve()
|
||||
from := c.codeStart + pointer.Position + Address(pointer.Size)
|
||||
offset := destination - from
|
||||
slice := c.code[pointer.Position : pointer.Position+4]
|
||||
binary.LittleEndian.PutUint32(slice, uint32(offset))
|
||||
address := pointer.Resolve()
|
||||
slice := c.code[pointer.Position : pointer.Position+Address(pointer.Size)]
|
||||
binary.LittleEndian.PutUint32(slice, uint32(address))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user