mirror of
https://github.com/g012/l65.git
synced 2025-08-11 06:28:10 +00:00
Added rorg option to locations for relocatable origin.
This commit is contained in:
49
6502.lua
49
6502.lua
@@ -14,7 +14,7 @@ M.link = function()
|
|||||||
stats.unused = 0
|
stats.unused = 0
|
||||||
stats.cycles = 0
|
stats.cycles = 0
|
||||||
for _,location in ipairs(locations) do
|
for _,location in ipairs(locations) do
|
||||||
local sections = location.sections
|
local sections,rorg = location.sections,location.rorg
|
||||||
|
|
||||||
local chunk_reserve = function(chunk_ix, chunk, start, size)
|
local chunk_reserve = function(chunk_ix, chunk, start, size)
|
||||||
if start == chunk.start then
|
if start == chunk.start then
|
||||||
@@ -53,7 +53,7 @@ M.link = function()
|
|||||||
for chunk_ix,chunk in ipairs(location.chunks) do
|
for chunk_ix,chunk in ipairs(location.chunks) do
|
||||||
if chunk.start <= section.org and chunk.size - (section.org - chunk.start) >= section.size then
|
if chunk.start <= section.org and chunk.size - (section.org - chunk.start) >= section.size then
|
||||||
chunk_reserve(chunk_ix, chunk, section.org, section.size)
|
chunk_reserve(chunk_ix, chunk, section.org, section.size)
|
||||||
symbols[section.label] = section.org
|
symbols[section.label] = rorg(section.org)
|
||||||
goto chunk_located
|
goto chunk_located
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -121,7 +121,7 @@ M.link = function()
|
|||||||
if position then
|
if position then
|
||||||
chunk_reserve(chunk_ix, chunk, position, section.size)
|
chunk_reserve(chunk_ix, chunk, position, section.size)
|
||||||
section.org = position
|
section.org = position
|
||||||
symbols[section.label] = position
|
symbols[section.label] = rorg(position)
|
||||||
--print(section.label, string.format("%04X\t%d", position, section.size))
|
--print(section.label, string.format("%04X\t%d", position, section.size))
|
||||||
--for k,v in ipairs(location.chunks) do print(string.format(" %04X %04X %d", v.start, v.size+v.start-1, v.size)) end
|
--for k,v in ipairs(location.chunks) do print(string.format(" %04X %04X %d", v.start, v.size+v.start-1, v.size)) end
|
||||||
goto chunk_located
|
goto chunk_located
|
||||||
@@ -145,14 +145,14 @@ M.resolve = function()
|
|||||||
M.link()
|
M.link()
|
||||||
|
|
||||||
stats.resolved_count = 0
|
stats.resolved_count = 0
|
||||||
local count = 0
|
repeat local count = 0
|
||||||
for k,v in pairs(symbols) do if k ~= '__index' then
|
for k,v in pairs(symbols) do if k ~= '__index' then
|
||||||
local t = type(v)
|
local t = type(v)
|
||||||
if t == 'function' then v=v() t=type(v) symbols[k]=v count=count+1 end
|
if t == 'function' then v=v() t=type(v) symbols[k]=v count=count+1 end
|
||||||
if t == 'table' and type(v.resolve) == 'function' then symbols[k]=v.resolve() count=count+1
|
if t == 'table' and type(v.resolve) == 'function' then symbols[k]=v.resolve() count=count+1 end
|
||||||
elseif t == 'string' then symbols[k]=symbols[v] count=count+1 end
|
if t == 'string' and symbols[v] then symbols[k]=symbols[v] count=count+1 end
|
||||||
end end
|
stats.resolved_count = stats.resolved_count + count
|
||||||
stats.resolved_count = count
|
end end until count == 0
|
||||||
|
|
||||||
-- set local label references resolver
|
-- set local label references resolver
|
||||||
local llresolver = { __index = function(tab,key)
|
local llresolver = { __index = function(tab,key)
|
||||||
@@ -224,15 +224,26 @@ M.getstats = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
M.location = function(start, finish)
|
M.location = function(start, finish)
|
||||||
|
local location = { type='location', start=start, finish=finish, sections={} }
|
||||||
if type(start) == 'table' then
|
if type(start) == 'table' then
|
||||||
for _,v in ipairs(locations) do if v == start then
|
if start.type == 'location' then
|
||||||
M.location_current = start
|
for _,v in ipairs(locations) do if v == start then
|
||||||
return start
|
M.location_current = start
|
||||||
end end
|
return start
|
||||||
error("unable to find reference to location [" .. (start.start or '?') .. ", " .. (start.finish or '?') .. "]")
|
end end
|
||||||
|
error("unable to find reference to location [" .. (start.start or '?') .. ", " .. (start.finish or '?') .. "]")
|
||||||
|
end
|
||||||
|
location.start = start[1]
|
||||||
|
location.finish = start[2]
|
||||||
|
location.rorg = start.rorg
|
||||||
|
if type(location.rorg) == 'number' then
|
||||||
|
local offset = location.rorg - location.start
|
||||||
|
location.rorg = function(x) return x+offset end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
local size = (finish or math.huge) - start + 1
|
if not location.rorg then location.rorg = function(x) return x end end
|
||||||
local location = { start=start, finish=finish, sections={}, chunks={ { start=start, size=size } } }
|
local size = (location.finish or math.huge) - location.start + 1
|
||||||
|
location.chunks={ { start=location.start, size=size } }
|
||||||
locations[#locations+1] = location
|
locations[#locations+1] = location
|
||||||
M.location_current = location
|
M.location_current = location
|
||||||
return location
|
return location
|
||||||
@@ -281,7 +292,7 @@ end
|
|||||||
|
|
||||||
M.label = function(name)
|
M.label = function(name)
|
||||||
local label,offset
|
local label,offset
|
||||||
local section = M.section_current
|
local section,rorg = M.section_current,M.location_current.rorg
|
||||||
label = { type='label' }
|
label = { type='label' }
|
||||||
if name:sub(1,1) == '_' then -- local label
|
if name:sub(1,1) == '_' then -- local label
|
||||||
name = M.label_current .. name
|
name = M.label_current .. name
|
||||||
@@ -296,7 +307,7 @@ M.label = function(name)
|
|||||||
label.size = 0
|
label.size = 0
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
label.resolve = function() return section.org + offset end
|
label.resolve = function() return rorg(section.org + offset) end
|
||||||
table.insert(section.instructions, label)
|
table.insert(section.instructions, label)
|
||||||
return label
|
return label
|
||||||
end
|
end
|
||||||
@@ -667,7 +678,7 @@ cycles_def=2 xcross_def=0 local oprel={
|
|||||||
for k,v in pairs(oprel) do
|
for k,v in pairs(oprel) do
|
||||||
M[k .. 'rel'] = function(label)
|
M[k .. 'rel'] = function(label)
|
||||||
local parent,offset = M.label_current
|
local parent,offset = M.label_current
|
||||||
local section = M.section_current
|
local section,rorg = M.section_current,M.location_current.rorg
|
||||||
local op = { cycles=2 }
|
local op = { cycles=2 }
|
||||||
op.size = function()
|
op.size = function()
|
||||||
offset = section.size
|
offset = section.size
|
||||||
@@ -682,7 +693,7 @@ for k,v in pairs(oprel) do
|
|||||||
x = symbols[x]
|
x = symbols[x]
|
||||||
end
|
end
|
||||||
if type(x) ~= 'number' then error("unresolved branch target: " .. tostring(x)) end
|
if type(x) ~= 'number' then error("unresolved branch target: " .. tostring(x)) end
|
||||||
x = x - offset - section.org
|
x = x - offset - rorg(section.org)
|
||||||
if x < -128 or x > 127 then error("branch target out of range for " .. l .. ": " .. x) end
|
if x < -128 or x > 127 then error("branch target out of range for " .. l .. ": " .. x) end
|
||||||
b[#b+1]=v.opc b[#b+1]=x&0xff
|
b[#b+1]=v.opc b[#b+1]=x&0xff
|
||||||
end
|
end
|
||||||
|
7
asm.l65
7
asm.l65
@@ -8,10 +8,10 @@ function switchbank(i) bit 0x1ff4+i end
|
|||||||
-- create bank stubs
|
-- create bank stubs
|
||||||
for bi=0,7,1 do
|
for bi=0,7,1 do
|
||||||
local o=(bi<<12)
|
local o=(bi<<12)
|
||||||
_ENV['bank' .. bi] = location(0x8000+o, 0x8fff+o)
|
_ENV['bank' .. bi] = location{0x8000+o, 0x8fff+o, rorg=0xf000}
|
||||||
section{"entry"..bi, org=0x8fee+o} switchbank(0) jmp main
|
local start=section{"entry"..bi, org=0x8fee+o} switchbank(0) if bi==0 then jmp main end
|
||||||
section{"switchtab"..bi, org=0x8ff4+o} byte(0,0,0,0,0,0,0,0)
|
section{"switchtab"..bi, org=0x8ff4+o} byte(0,0,0,0,0,0,0,0)
|
||||||
section{"vectors"..bi, org=0x8ffc+o} word(0xffee,0xffee)
|
section{"vectors"..bi, org=0x8ffc+o} word(start,start)
|
||||||
end
|
end
|
||||||
|
|
||||||
location(bank0)
|
location(bank0)
|
||||||
@@ -129,6 +129,7 @@ ptr_table("ptrs", message, data, 0)
|
|||||||
|
|
||||||
writebin()
|
writebin()
|
||||||
writesym()
|
writesym()
|
||||||
|
print(getstats())
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
section "doOverscan"
|
section "doOverscan"
|
||||||
|
7
asm.lua
7
asm.lua
@@ -8,10 +8,10 @@ function switchbank(i) bitzab(function(_o) return _o+( 0x1ff4+i) end) end
|
|||||||
-- create bank stubs
|
-- create bank stubs
|
||||||
for bi=0,7,1 do
|
for bi=0,7,1 do
|
||||||
local o=(bi<<12)
|
local o=(bi<<12)
|
||||||
_ENV['bank' .. bi] = location(0x8000+o, 0x8fff+o)
|
_ENV['bank' .. bi] = location{0x8000+o, 0x8fff+o, rorg=0xf000}
|
||||||
section{"entry"..bi, org=0x8fee+o} switchbank(0) jmpabs(function(_o) return _o+( main) end)
|
local start=section{"entry"..bi, org=0x8fee+o} switchbank(0) if bi==0 then jmpabs(function(_o) return _o+( main) end) end
|
||||||
section{"switchtab"..bi, org=0x8ff4+o} byte(0,0,0,0,0,0,0,0)
|
section{"switchtab"..bi, org=0x8ff4+o} byte(0,0,0,0,0,0,0,0)
|
||||||
section{"vectors"..bi, org=0x8ffc+o} word(0xffee,0xffee)
|
section{"vectors"..bi, org=0x8ffc+o} word(start,start)
|
||||||
end
|
end
|
||||||
|
|
||||||
location(bank0)
|
location(bank0)
|
||||||
@@ -127,6 +127,7 @@ label("_toto")
|
|||||||
|
|
||||||
writebin()
|
writebin()
|
||||||
writesym()
|
writesym()
|
||||||
|
print(getstats())
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
section "doOverscan"
|
section "doOverscan"
|
||||||
|
Reference in New Issue
Block a user