Skip to content

Commit

Permalink
Added support for GNU Linker Script (#3373)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Mar 21, 2022
1 parent 1b1d673 commit 33f2cf9
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Expand Up @@ -507,6 +507,11 @@
"alias": "gni",
"owner": "RunDevelopment"
},
"linker-script": {
"title": "GNU Linker Script",
"alias": "ld",
"owner": "RunDevelopment"
},
"go": {
"title": "Go",
"require": "clike",
Expand Down
30 changes: 30 additions & 0 deletions components/prism-linker-script.js
@@ -0,0 +1,30 @@
Prism.languages['linker-script'] = {
'comment': {
pattern: /(^|\s)\/\*[\s\S]*?(?:$|\*\/)/,
lookbehind: true,
greedy: true
},
'identifier': {
pattern: /"[^"\r\n]*"/,
greedy: true
},

'location-counter': {
pattern: /\B\.\B/,
alias: 'important'
},

'section': {
pattern: /(^|[^\w*])\.\w+\b/,
lookbehind: true,
alias: 'keyword'
},
'function': /\b[A-Z][A-Z_]*(?=\s*\()/,

'number': /\b(?:0[xX][a-fA-F0-9]+|\d+)[KM]?\b/,

'operator': />>=?|<<=?|->|\+\+|--|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?/,
'punctuation': /[(){},;]/
};

Prism.languages['ld'] = Prism.languages['linker-script'];
1 change: 1 addition & 0 deletions components/prism-linker-script.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions examples/prism-linker-script.html
@@ -0,0 +1,53 @@
<h2>Full example</h2>
<pre><code>/* Source: https://github.com/stivale/stivale2-barebones/blob/master/kernel/linker.ld */

/* We want the symbol _start to be our entry point */
ENTRY(_start)

/* Define the program headers we want so the bootloader gives us the right */
/* MMU permissions */
PHDRS
{
null PT_NULL FLAGS(0) ; /* Null segment */
text PT_LOAD FLAGS((1 &lt;&lt; 0) | (1 &lt;&lt; 2)) ; /* Execute + Read */
rodata PT_LOAD FLAGS((1 &lt;&lt; 2)) ; /* Read only */
data PT_LOAD FLAGS((1 &lt;&lt; 1) | (1 &lt;&lt; 2)) ; /* Write + Read */
}

SECTIONS
{
/* We wanna be placed in the topmost 2GiB of the address space, for optimisations */
/* and because that is what the stivale2 spec mandates. */
/* Any address in this region will do, but often 0xffffffff80000000 is chosen as */
/* that is the beginning of the region. */
. = 0xffffffff80000000;

.text : {
*(.text .text.*)
} :text

/* Move to the next memory page for .rodata */
. += CONSTANT(MAXPAGESIZE);

/* We place the .stivale2hdr section containing the header in its own section, */
/* and we use the KEEP directive on it to make sure it doesn't get discarded. */
.stivale2hdr : {
KEEP(*(.stivale2hdr))
} :rodata

.rodata : {
*(.rodata .rodata.*)
} :rodata

/* Move to the next memory page for .data */
. += CONSTANT(MAXPAGESIZE);

.data : {
*(.data .data.*)
} :data

.bss : {
*(COMMON)
*(.bss .bss.*)
} :data
}</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Expand Up @@ -199,6 +199,7 @@
"gamemakerlanguage": "gml",
"po": "gettext",
"gni": "gn",
"ld": "linker-script",
"go-mod": "go-module",
"hbs": "handlebars",
"hs": "haskell",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/show-language/prism-show-language.js
Expand Up @@ -102,6 +102,8 @@
"glsl": "GLSL",
"gn": "GN",
"gni": "GN",
"linker-script": "GNU Linker Script",
"ld": "GNU Linker Script",
"go-module": "Go module",
"go-mod": "Go module",
"graphql": "GraphQL",
Expand Down

0 comments on commit 33f2cf9

Please sign in to comment.