forked from trhodeos/spicy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry.go
48 lines (43 loc) · 1.02 KB
/
entry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package spicy
import (
"bytes"
"io"
"text/template"
log "github.com/sirupsen/logrus"
)
var compileArgs = []string{"-march=vr4300", "-mtune=vr4300", "-mgp32", "-mfp32", "-non_shared"}
func createEntrySource(bootSegment *Segment) (io.Reader, error) {
t := `
.text
.global _start
_start:
la $8,_{{.Name}}SegmentBssStart
la $9,_{{.Name}}SegmentBssSize
1:
sw $0, 0($8)
sw $0, 4($8)
addi $8, 8
addi $9, 0xfff8
bne $9, $0, 1b
la $10, {{.Entry}} + 0
la $29,{{.StackInfo.Start}} + {{.StackInfo.Offset}}
jr $10
`
tmpl, err := template.New("test").Parse(t)
if err != nil {
return nil, err
}
b := &bytes.Buffer{}
err = tmpl.Execute(b, bootSegment)
log.Debugf("Created entry script:\n%s", b.String())
return b, err
}
func CreateEntryBinary(w *Wave, as Runner) (io.Reader, error) {
name := w.Name
log.Infof("Creating entry for \"%s\".", name)
entrySource, err := createEntrySource(w.GetBootSegment())
if err != nil {
return nil, err
}
return NewOutputFileRunner(as, "a.out").Run(entrySource, append(compileArgs, "-"))
}