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.
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
The only two commands are
.Ic ORG
The only three commands are
.Ic ORG ,
.Ic ALIGN ,
and
.Ic ALIGN :
.Ic DS :
.Bl -bullet
.It
.Ic ORG
@@ -83,6 +84,9 @@ will increase the address until it is aligned to the specified boundary
.Ql ALIGN 8
will align to $100
.Pc .
.It
.Ic DS
will increase the address by the specified non-negative amount.
.El
.Pp
.Sy Note:

View File

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

View File

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

View File

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