Skip to content

Commit

Permalink
Split object segments and raw segments.
Browse files Browse the repository at this point in the history
  • Loading branch information
trhodeos committed Feb 26, 2018
1 parent 4bcf95d commit 213b910
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ld.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
func createLdScript(w *Wave) (string, error) {
t := `
MEMORY {
{{range .Segments}}
{{range .ObjectSegments}}
{{.Name}}.RAM (RX) : ORIGIN = {{.Positioning.Address}}, LENGTH = 0x400000
{{.Name}}.bss.RAM (RW) : ORIGIN = {{.Positioning.Address}}, LENGTH = 0x400000
{{end}}
}
SECTIONS {
_RomSize = 0x1050;
_RomStart = _RomSize;
{{range .Segments -}}
{{range .ObjectSegments -}}
_{{.Name}}SegmentRomStart = _RomSize;
..{{.Name}} {{.Positioning.Address}}:
{
Expand Down
15 changes: 10 additions & 5 deletions spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ type Segment struct {

type Wave struct {
Name string
Segments []*Segment
ObjectSegments []*Segment
RawSegments []*Segment
}

type Spec struct {
Expand Down Expand Up @@ -197,7 +198,11 @@ func convertWaveAst(s *WaveAst, segments map[string]*Segment) (*Wave, error) {
break
case "include":
seg := segments[statement.Value.String]
out.Segments = append(out.Segments, seg)
if seg.Flags.Object {
out.ObjectSegments = append(out.ObjectSegments, seg)
} else if seg.Flags.Raw {
out.RawSegments = append(out.RawSegments, seg)
}
break
default:
return nil, errors.New(fmt.Sprintf("Unknown name %s", statement.Name))
Expand All @@ -207,7 +212,7 @@ func convertWaveAst(s *WaveAst, segments map[string]*Segment) (*Wave, error) {
}

func (w *Wave) updateWithConstants() {
for _, seg := range(w.Segments) {
for _, seg := range(w.ObjectSegments) {
if (seg.Flags.Boot) {
seg.Positioning.Address = 0x80000450
}
Expand Down Expand Up @@ -255,7 +260,7 @@ func ParseSpec(r io.Reader) (*Spec, error) {
}

func (w *Wave) checkValidity() error {
for _, seg := range w.Segments {
for _, seg := range w.ObjectSegments {
numSet := 0
if seg.Name == "" {
return errors.New("Name must be non-empty.")
Expand Down Expand Up @@ -288,7 +293,7 @@ func (w *Wave) checkValidity() error {
}

func (w *Wave) GetBootSegment() *Segment {
for _, seg := range w.Segments {
for _, seg := range w.ObjectSegments {
if seg.Flags.Boot {
return seg
}
Expand Down

0 comments on commit 213b910

Please sign in to comment.