Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for GNU Linker Script #3373

Merged
merged 3 commits into from Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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