Terminal program for MailStation devices
at master 68 lines 2.3 kB view raw
1#/usr/bin/env ruby 2# 3# link, figure out header/code/data sizes, then relink with them packed tightly 4# msTERM 5# 6# Copyright (c) 2021 joshua stein <jcs@jcs.org> 7# 8# Permission to use, copy, modify, and distribute this software for any 9# purpose with or without fee is hereby granted, provided that the above 10# copyright notice and this permission notice appear in all copies. 11# 12# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19# 20 21def get_size(area) 22 File.open("msterm.map", "r") do |f| 23 while f && !f.eof? 24 line = f.gets 25 # _HEADER0 00000000 000000F9 = 249. bytes (ABS,CON) 26 if m = line.match(/^#{area} .* (\d+)\. *bytes/) 27 return m[1].to_i 28 end 29 end 30 end 31 32 raise "can't find #{area} in msterm.map" 33end 34 35def sdcc(code_start, data_start) 36 s = "#{ENV["SDCC"]} --code-loc #{sprintf("0x%04x", code_start)} " + 37 "--data-loc #{sprintf("0x%04x", data_start)} -o #{ENV["TARGET"]} " + 38 "#{ARGV.join(" ")}" 39 puts s 40 system(s) 41end 42 43base_addr = ENV["BASE_ADDR"].to_i(16) 44header_size = 0x1000 45code_start = base_addr + header_size 46data_start = base_addr + 0x4000 47 48# link once at a large offset data-loc 49sdcc(code_start, data_start) 50 51header_size = get_size("_HEADER0") 52printf "header: %d bytes (0x%04x)\n", header_size, header_size 53 54code_size = get_size("_CODE") 55printf "code: %d bytes (0x%04x)\n", code_size, code_size 56 57data_size = get_size("_DATA") 58printf "data: %d bytes (0x%04x)\n", data_size, data_size 59 60printf "total: %d bytes (0x%04x)\n", header_size + code_size + data_size, 61 header_size + code_size + data_size 62 63code_start = base_addr + header_size 64data_start = code_start + code_size 65printf "relinking with base: 0x%04x code: 0x%04x data:0x%04x\n", 66 base_addr, code_start, data_start 67 68sdcc(code_start, data_start)