diff options
author | Ayke van Laethem <[email protected]> | 2020-03-09 16:26:20 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2020-03-17 14:46:56 +0100 |
commit | 5bace979ea6cee3fc64675d7ad6212547c38e7ce (patch) | |
tree | ccdf270a81ea3394b559031c3c045e012b447ca1 /tools/gen-device-avr | |
parent | 63cfb09e9efd2bab72d31efca1f06cc5cd0c220b (diff) | |
download | tinygo-5bace979ea6cee3fc64675d7ad6212547c38e7ce.tar.gz tinygo-5bace979ea6cee3fc64675d7ad6212547c38e7ce.zip |
avr: use the correct RAM start address
Previously, the RAM was set to start at address 0. This is incorrect: on
AVR, the first few addresses are taken up by memory-mapped I/O. The
reason this didn't lead to problems (yet) was because the stack was
usually big enough to avoid real problems.
Diffstat (limited to 'tools/gen-device-avr')
-rwxr-xr-x | tools/gen-device-avr/gen-device-avr.go | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/tools/gen-device-avr/gen-device-avr.go b/tools/gen-device-avr/gen-device-avr.go index 8f9298a21..9b9c627ae 100755 --- a/tools/gen-device-avr/gen-device-avr.go +++ b/tools/gen-device-avr/gen-device-avr.go @@ -24,8 +24,9 @@ type AVRToolsDeviceFile struct { Name string `xml:"name,attr"` Size string `xml:"size,attr"` MemorySegments []struct { - Name string `xml:"name,attr"` - Size string `xml:"size,attr"` + Name string `xml:"name,attr"` + Start string `xml:"start,attr"` + Size string `xml:"size,attr"` } `xml:"memory-segment"` } `xml:"address-spaces>address-space"` Interrupts []Interrupt `xml:"interrupts>interrupt"` @@ -57,9 +58,26 @@ type Device struct { peripherals []*Peripheral } +// AddressSpace is the Go version of an XML element like the following: +// +// <address-space endianness="little" name="data" id="data" start="0x0000" size="0x0900"> +// +// It describes one address space in an AVR microcontroller. One address space +// may have multiple memory segments. type AddressSpace struct { Size string - Segments map[string]int + Segments map[string]MemorySegment +} + +// MemorySegment is the Go version of an XML element like the following: +// +// <memory-segment name="IRAM" start="0x0100" size="0x0800" type="ram" external="false"/> +// +// It describes a single contiguous area of memory in a particular address space +// (see AddressSpace). +type MemorySegment struct { + start int64 + size int64 } type Interrupt struct { @@ -115,14 +133,21 @@ func readATDF(path string) (*Device, error) { for _, el := range device.AddressSpaces { memorySizes[el.Name] = &AddressSpace{ Size: el.Size, - Segments: make(map[string]int), + Segments: make(map[string]MemorySegment), } for _, segmentEl := range el.MemorySegments { + start, err := strconv.ParseInt(segmentEl.Start, 0, 32) + if err != nil { + return nil, err + } size, err := strconv.ParseInt(segmentEl.Size, 0, 32) if err != nil { return nil, err } - memorySizes[el.Name].Segments[segmentEl.Name] = int(size) + memorySizes[el.Name].Segments[segmentEl.Name] = MemorySegment{ + start: start, + size: size, + } } } @@ -205,10 +230,12 @@ func readATDF(path string) (*Device, error) { } } - ramSize := 0 // for devices with no RAM + ramStart := int64(0) + ramSize := int64(0) // for devices with no RAM for _, ramSegmentName := range []string{"IRAM", "INTERNAL_SRAM", "SRAM"} { if segment, ok := memorySizes["data"].Segments[ramSegmentName]; ok { - ramSize = segment + ramStart = segment.start + ramSize = segment.size } } @@ -227,6 +254,7 @@ func readATDF(path string) (*Device, error) { "arch": device.Architecture, "family": device.Family, "flashSize": int(flashSize), + "ramStart": ramStart, "ramSize": ramSize, "numInterrupts": len(device.Interrupts), }, @@ -429,6 +457,7 @@ func writeLD(outdir string, device *Device) error { /* Generated by gen-device-avr.go from {{.file}}, see {{.descriptorSource}} */ __flash_size = 0x{{printf "%x" .flashSize}}; +__ram_start = 0x{{printf "%x" .ramStart}}; __ram_size = 0x{{printf "%x" .ramSize}}; __num_isrs = {{.numInterrupts}}; `)) |