diff options
Diffstat (limited to 'dynasm/dasm_arm.lua')
-rw-r--r-- | dynasm/dasm_arm.lua | 70 |
1 files changed, 38 insertions, 32 deletions
diff --git a/dynasm/dasm_arm.lua b/dynasm/dasm_arm.lua index 243cfe90..1876078b 100644 --- a/dynasm/dasm_arm.lua +++ b/dynasm/dasm_arm.lua | |||
@@ -586,6 +586,36 @@ local function parse_shift(shift, gprok) | |||
586 | end | 586 | end |
587 | end | 587 | end |
588 | 588 | ||
589 | local function parse_label(label, def) | ||
590 | local prefix = sub(label, 1, 2) | ||
591 | -- =>label (pc label reference) | ||
592 | if prefix == "=>" then | ||
593 | return "PC", 0, sub(label, 3) | ||
594 | end | ||
595 | -- ->name (global label reference) | ||
596 | if prefix == "->" then | ||
597 | return "LG", map_global[sub(label, 3)] | ||
598 | end | ||
599 | if def then | ||
600 | -- [1-9] (local label definition) | ||
601 | if match(label, "^[1-9]$") then | ||
602 | return "LG", 10+tonumber(label) | ||
603 | end | ||
604 | else | ||
605 | -- [<>][1-9] (local label reference) | ||
606 | local dir, lnum = match(label, "^([<>])([1-9])$") | ||
607 | if dir then -- Fwd: 1-9, Bkwd: 11-19. | ||
608 | return "LG", lnum + (dir == ">" and 0 or 10) | ||
609 | end | ||
610 | -- extern label (extern label reference) | ||
611 | local extname = match(label, "^extern%s+(%S+)$") | ||
612 | if extname then | ||
613 | return "EXT", map_extern[extname] | ||
614 | end | ||
615 | end | ||
616 | werror("bad label `"..label.."'") | ||
617 | end | ||
618 | |||
589 | local function parse_load(params, nparams, n, op) | 619 | local function parse_load(params, nparams, n, op) |
590 | local oplo = op % 256 | 620 | local oplo = op % 256 |
591 | local ext, ldrd = (oplo ~= 0), (oplo == 208) | 621 | local ext, ldrd = (oplo ~= 0), (oplo == 208) |
@@ -594,11 +624,17 @@ local function parse_load(params, nparams, n, op) | |||
594 | d = ((op - (op % 4096)) / 4096) % 16 | 624 | d = ((op - (op % 4096)) / 4096) % 16 |
595 | if d % 2 ~= 0 then werror("odd destination register") end | 625 | if d % 2 ~= 0 then werror("odd destination register") end |
596 | end | 626 | end |
597 | local p1, wb = match(params[n], "^%[%s*(.-)%s*%](!?)$") | 627 | local pn = params[n] |
628 | local p1, wb = match(pn, "^%[%s*(.-)%s*%](!?)$") | ||
598 | local p2 = params[n+1] | 629 | local p2 = params[n+1] |
599 | if not p1 then | 630 | if not p1 then |
600 | if not p2 then | 631 | if not p2 then |
601 | local reg, tailr = match(params[n], "^([%w_:]+)%s*(.*)$") | 632 | if match(pn, "^[<>=%-]") or match(pn, "^extern%s+") then |
633 | local mode, n, s = parse_label(pn, false) | ||
634 | waction("REL_"..mode, n + (ext and 0x1800 or 0x0800), s, 1) | ||
635 | return op + 15 * 65536 + 0x01000000 + (ext and 0x00400000 or 0) | ||
636 | end | ||
637 | local reg, tailr = match(pn, "^([%w_:]+)%s*(.*)$") | ||
602 | if reg and tailr ~= "" then | 638 | if reg and tailr ~= "" then |
603 | local d, tp = parse_gpr(reg) | 639 | local d, tp = parse_gpr(reg) |
604 | if tp then | 640 | if tp then |
@@ -653,36 +689,6 @@ local function parse_load(params, nparams, n, op) | |||
653 | return op | 689 | return op |
654 | end | 690 | end |
655 | 691 | ||
656 | local function parse_label(label, def) | ||
657 | local prefix = sub(label, 1, 2) | ||
658 | -- =>label (pc label reference) | ||
659 | if prefix == "=>" then | ||
660 | return "PC", 0, sub(label, 3) | ||
661 | end | ||
662 | -- ->name (global label reference) | ||
663 | if prefix == "->" then | ||
664 | return "LG", map_global[sub(label, 3)] | ||
665 | end | ||
666 | if def then | ||
667 | -- [1-9] (local label definition) | ||
668 | if match(label, "^[1-9]$") then | ||
669 | return "LG", 10+tonumber(label) | ||
670 | end | ||
671 | else | ||
672 | -- [<>][1-9] (local label reference) | ||
673 | local dir, lnum = match(label, "^([<>])([1-9])$") | ||
674 | if dir then -- Fwd: 1-9, Bkwd: 11-19. | ||
675 | return "LG", lnum + (dir == ">" and 0 or 10) | ||
676 | end | ||
677 | -- extern label (extern label reference) | ||
678 | local extname = match(label, "^extern%s+(%S+)$") | ||
679 | if extname then | ||
680 | return "EXT", map_extern[extname] | ||
681 | end | ||
682 | end | ||
683 | werror("bad label `"..label.."'") | ||
684 | end | ||
685 | |||
686 | ------------------------------------------------------------------------------ | 692 | ------------------------------------------------------------------------------ |
687 | 693 | ||
688 | -- Handle opcodes defined with template strings. | 694 | -- Handle opcodes defined with template strings. |