diff --git a/test/link/sdcc/good/a.asm b/test/link/sdcc/good/a.asm new file mode 100644 index 000000000..5d2bc2467 --- /dev/null +++ b/test/link/sdcc/good/a.asm @@ -0,0 +1,18 @@ +SECTION "entry", ROM0[$0100] + jp start + +SECTION "header", ROM0[$0104] + ds $150 - $104, 0 + +SECTION "start", ROM0 +start: + ld de, 0 + call _function0 ; bc <- 1 + ld b, b ; breakpoint + + ld d, b :: ld e, c ; de <- bc + + call _function1 ; bc <- 3 + ld b, b ; breakpoint + + stop diff --git a/test/link/sdcc/good/b.c b/test/link/sdcc/good/b.c new file mode 100644 index 000000000..5232d9355 --- /dev/null +++ b/test/link/sdcc/good/b.c @@ -0,0 +1,11 @@ +// sdcc -c -msm83 -o b.rel b.c + +#ifdef __SDCC_sm83 +const int sm83 = 1; +#else +const int sm83 = 0; +#endif + +int function0(int de) { + return de | sm83; +} diff --git a/test/link/sdcc/good/b.rel b/test/link/sdcc/good/b.rel new file mode 100644 index 000000000..0c1b31399 --- /dev/null +++ b/test/link/sdcc/good/b.rel @@ -0,0 +1,24 @@ +XL3 +H 9 areas 3 global symbols +M b +O -msm83 +S .__.ABS. Def000000 +A _CODE size 7 flags 0 addr 0 +S _sm83 Def000005 +S _function0 Def000000 +A _DATA size 0 flags 0 addr 0 +A _INITIALIZED size 0 flags 0 addr 0 +A _DABS size 0 flags 8 addr 0 +A _HOME size 0 flags 0 addr 0 +A _GSINIT size 0 flags 0 addr 0 +A _GSFINAL size 0 flags 0 addr 0 +A _INITIALIZER size 0 flags 0 addr 0 +A _CABS size 0 flags 8 addr 0 +T 00 00 00 +R 00 00 00 00 +T 00 00 00 4B 42 CB C1 C9 +R 00 00 00 00 +T 05 00 00 +R 00 00 00 00 +T 05 00 00 01 00 +R 00 00 00 00 diff --git a/test/link/sdcc/good/c.c b/test/link/sdcc/good/c.c new file mode 100644 index 000000000..4308f563c --- /dev/null +++ b/test/link/sdcc/good/c.c @@ -0,0 +1,5 @@ +// sdcc -c -msm83 -o c.rel c.c + +int function1(int de) { + return de | 0b10; +} diff --git a/test/link/sdcc/good/c.rel b/test/link/sdcc/good/c.rel new file mode 100644 index 000000000..ce7165daf --- /dev/null +++ b/test/link/sdcc/good/c.rel @@ -0,0 +1,19 @@ +XL3 +H 9 areas 2 global symbols +M c +O -msm83 +S .__.ABS. Def000000 +A _CODE size 5 flags 0 addr 0 +S _function1 Def000000 +A _DATA size 0 flags 0 addr 0 +A _INITIALIZED size 0 flags 0 addr 0 +A _DABS size 0 flags 8 addr 0 +A _HOME size 0 flags 0 addr 0 +A _GSINIT size 0 flags 0 addr 0 +A _GSFINAL size 0 flags 0 addr 0 +A _INITIALIZER size 0 flags 0 addr 0 +A _CABS size 0 flags 8 addr 0 +T 00 00 00 +R 00 00 00 00 +T 00 00 00 4B 42 CB C9 C9 +R 00 00 00 00 diff --git a/test/link/sdcc/good/out.err b/test/link/sdcc/good/out.err new file mode 100644 index 000000000..e69de29bb diff --git a/test/link/sdcc/good/ref.out.bin b/test/link/sdcc/good/ref.out.bin new file mode 100644 index 000000000..17aab6c8d Binary files /dev/null and b/test/link/sdcc/good/ref.out.bin differ diff --git a/test/link/sdcc/good/ref.out.sym b/test/link/sdcc/good/ref.out.sym new file mode 100644 index 000000000..6381494ef --- /dev/null +++ b/test/link/sdcc/good/ref.out.sym @@ -0,0 +1,6 @@ +; File generated by rgblink +00:0000 start +01:4000 _function0 +01:4005 _sm83 +01:4007 _function1 +00 .__.ABS. diff --git a/test/link/sdcc/good/script.link b/test/link/sdcc/good/script.link new file mode 100644 index 000000000..9f157ebbc --- /dev/null +++ b/test/link/sdcc/good/script.link @@ -0,0 +1,21 @@ +ROM0 + FLOATING + "_HOME" OPTIONAL + "_BASE" OPTIONAL + "_CODE_0" OPTIONAL + "_LIT_0" OPTIONAL + "_INITIALIZER" OPTIONAL ; Initializer of `_INITIALIZED` + "_GSINIT" OPTIONAL ; Reportedly internal to the crt0; TODO: investigate this + "_GSFINAL" OPTIONAL + +ROMX FLOATING + FLOATING + "_CODE" OPTIONAL + "_LIT" OPTIONAL + +WRAM0 + FLOATING + "_DATA" OPTIONAL ; Uninitialized RAM + "_BSS" OPTIONAL ; Zero-initialized RAM + "_INITIALIZED" OPTIONAL ; Initialised by `_INITIALIZER` + "_DABS (ABS)" OPTIONAL ; TODO: what is this? diff --git a/test/link/sdcc/no-script/a.asm b/test/link/sdcc/no-script/a.asm new file mode 100644 index 000000000..bb8486567 --- /dev/null +++ b/test/link/sdcc/no-script/a.asm @@ -0,0 +1,12 @@ +SECTION "entry", ROM0[$0100] + jp start + +SECTION "header", ROM0[$0104] + ds $150 - $104, 0 + +SECTION "start", ROM0 +start: + ld de, 1234 + call _function ; de <- 1234 * 2 + ld b, b ; breakpoint + stop diff --git a/test/link/sdcc/no-script/b.c b/test/link/sdcc/no-script/b.c new file mode 100644 index 000000000..380db7321 --- /dev/null +++ b/test/link/sdcc/no-script/b.c @@ -0,0 +1,5 @@ +// sdcc -c -msm83 -o b.rel b.c + +int function(int de) { + return de * 2; +} diff --git a/test/link/sdcc/no-script/b.rel b/test/link/sdcc/no-script/b.rel new file mode 100644 index 000000000..e373c299c --- /dev/null +++ b/test/link/sdcc/no-script/b.rel @@ -0,0 +1,19 @@ +XL3 +H 9 areas 2 global symbols +M b +O -msm83 +S .__.ABS. Def000000 +A _CODE size 6 flags 0 addr 0 +S _function Def000000 +A _DATA size 0 flags 0 addr 0 +A _INITIALIZED size 0 flags 0 addr 0 +A _DABS size 0 flags 8 addr 0 +A _HOME size 0 flags 0 addr 0 +A _GSINIT size 0 flags 0 addr 0 +A _GSFINAL size 0 flags 0 addr 0 +A _INITIALIZER size 0 flags 0 addr 0 +A _CABS size 0 flags 8 addr 0 +T 00 00 00 +R 00 00 00 00 +T 00 00 00 6B 62 29 4D 44 C9 +R 00 00 00 00 diff --git a/test/link/sdcc/no-script/out.err b/test/link/sdcc/no-script/out.err new file mode 100644 index 000000000..f0ca0821d --- /dev/null +++ b/test/link/sdcc/no-script/out.err @@ -0,0 +1,8 @@ +error: Section "_INITIALIZER" has not been assigned a type by a linker script +error: Section "_GSFINAL" has not been assigned a type by a linker script +error: Section "_GSINIT" has not been assigned a type by a linker script +error: Section "_HOME" has not been assigned a type by a linker script +error: Section "_INITIALIZED" has not been assigned a type by a linker script +error: Section "_DATA" has not been assigned a type by a linker script +error: Section "_CODE" has not been assigned a type by a linker script +Linking failed with 7 errors diff --git a/test/link/test.sh b/test/link/test.sh index fa9d8f1de..c66343f46 100755 --- a/test/link/test.sh +++ b/test/link/test.sh @@ -232,6 +232,24 @@ tryDiff "$test"/out.err "$outtemp" tryCmpRomSize "$gbtemp" 65536 evaluateTest +test="sdcc/good" +startTest +"$RGBASM" -o "$otemp" "$test"/a.asm +continueTest +rgblinkQuiet -o "$gbtemp" -n "$outtemp2" -l "$test"/script.link "$otemp" "$test"/b.rel "$test"/c.rel 2>"$outtemp" +tryDiff "$test"/out.err "$outtemp" +tryDiff "$test"/ref.out.sym "$outtemp2" +tryCmpRom "$test"/ref.out.bin +evaluateTest + +test="sdcc/no-script" +startTest +"$RGBASM" -o "$otemp" "$test"/a.asm +continueTest +rgblinkQuiet "$otemp" "$test"/b.rel 2>"$outtemp" +tryDiff "$test"/out.err "$outtemp" +evaluateTest + test="section-fragment/good" startTest "$RGBASM" -o "$otemp" "$test"/a.asm