Implement DS for linker scripts (#1206)

This commit is contained in:
Rangi
2023-11-03 03:47:22 -04:00
committed by GitHub
parent 477e9812d4
commit 8f3369fe29
4 changed files with 22 additions and 7 deletions

View File

@@ -67,10 +67,11 @@ are only relevant to assembly code and do not apply in section names.
When a new bank statement is found, sections found after it will be placed right from the beginning of that bank. When a new bank statement is found, sections found after it will be placed right from the beginning of that bank.
If the linker script switches to a different bank and then comes back to a previous one, it will continue from the last address that was used. If the linker script switches to a different bank and then comes back to a previous one, it will continue from the last address that was used.
.Pp .Pp
The only two commands are The only three commands are
.Ic ORG .Ic ORG ,
.Ic ALIGN ,
and and
.Ic ALIGN : .Ic DS :
.Bl -bullet .Bl -bullet
.It .It
.Ic ORG .Ic ORG
@@ -83,6 +84,9 @@ will increase the address until it is aligned to the specified boundary
.Ql ALIGN 8 .Ql ALIGN 8
will align to $100 will align to $100
.Pc . .Pc .
.It
.Ic DS
will increase the address by the specified non-negative amount.
.El .El
.Pp .Pp
.Sy Note: .Sy Note:

View File

@@ -154,6 +154,7 @@ char const *tokenTypes[] = {
enum LinkerScriptCommand { enum LinkerScriptCommand {
COMMAND_ORG, COMMAND_ORG,
COMMAND_ALIGN, COMMAND_ALIGN,
COMMAND_DS,
COMMAND_INVALID COMMAND_INVALID
}; };
@@ -170,7 +171,8 @@ struct LinkerScriptToken {
static char const * const commands[] = { static char const * const commands[] = {
[COMMAND_ORG] = "ORG", [COMMAND_ORG] = "ORG",
[COMMAND_ALIGN] = "ALIGN" [COMMAND_ALIGN] = "ALIGN",
[COMMAND_DS] = "DS"
}; };
static int nextChar(void) static int nextChar(void)
@@ -339,10 +341,17 @@ static void processCommand(enum LinkerScriptCommand command, uint16_t arg, uint1
break; break;
case COMMAND_ALIGN: case COMMAND_ALIGN:
if (arg >= 16) if (arg >= 16) {
arg = 0; arg = 0;
else } else {
arg = (*pc + (1 << arg) - 1) & ~((1 << arg) - 1); uint16_t mask = (1 << arg) - 1;
arg = (*pc + mask) & ~mask;
}
break;
case COMMAND_DS:
arg += *pc;
} }
if (arg < *pc) if (arg < *pc)

View File

@@ -1,2 +1,3 @@
SECTION "sec",ROM0,ALIGN[4] SECTION "sec",ROM0,ALIGN[4]
ds 8, $42
SECTION "secfix",ROM0[$20] SECTION "secfix",ROM0[$20]

View File

@@ -1,5 +1,6 @@
ROM0 ROM0
align 4 align 4
"sec" "sec"
ds $18
org $20 org $20
"secfix" "secfix"