Skip to content

Commit 9a56085

Browse files
committed
feat: add bootsector generation option
1 parent 1a6bce7 commit 9a56085

File tree

22 files changed

+113
-10
lines changed

22 files changed

+113
-10
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Options:
3737
-o, --output <string> Relative path to your output binary
3838
-ps, --print-assembly Print assembly output
3939
-d, --debug Print AST tree and assembly output
40+
-b, --bootsector Generate 512B bootsector output. Remember to have main entrypoint.
4041
-h, --help display help for command
4142
```
4243

apps/cli/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @ts-c-compiler/cli
22

3+
## 1.0.1
4+
5+
### Patch Changes
6+
7+
- Add bootsector output option
8+
39
## 1.0.0
410

511
### Major Changes

apps/cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ts-c-compiler/cli",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"private": false,
55
"license": "MIT",
66
"scripts": {

apps/cli/src/index.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ import fs from 'node:fs';
22
import { program } from '@commander-js/extra-typings';
33

44
import { TableBinaryView, asm } from '@ts-c-compiler/x86-assembler';
5-
import { ccompiler, serializeTypedTreeToString } from '@ts-c-compiler/compiler';
5+
import {
6+
ccompiler,
7+
serializeTypedTreeToString,
8+
wrapWithX86BootsectorAsm,
9+
} from '@ts-c-compiler/compiler';
610

711
program
812
.argument('<source>', 'Relative or absolute path to source file')
913
.option('-o, --output <string>', 'Relative path to your output binary')
1014
.option('-ps, --print-assembly', 'Print assembly output')
1115
.option('-d, --debug', 'Print AST tree and assembly output')
16+
.option(
17+
'-b, --bootsector',
18+
'Generate 512B bootsector output. Remember to have main entrypoint.',
19+
)
1220
.action((source, options) => {
1321
const srcFile = fs.readFileSync(source, { encoding: 'utf8', flag: 'r' });
1422

@@ -18,7 +26,13 @@ program
1826
result.dump();
1927
}
2028

21-
const asmResult = asm(result.codegen.asm, {
29+
let asmRaw = result.codegen.asm;
30+
31+
if (options.bootsector) {
32+
asmRaw = wrapWithX86BootsectorAsm(asmRaw);
33+
}
34+
35+
const asmResult = asm(asmRaw, {
2236
preprocessor: true,
2337
});
2438

packages/compiler-core/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @ts-c-compiler/core
22

3+
## 1.0.1
4+
5+
### Patch Changes
6+
7+
- Add bootsector output option
8+
39
## 1.0.0
410

511
### Major Changes

packages/compiler-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ts-c-compiler/core",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"type": "module",
55
"private": true,
66
"license": "MIT",

packages/compiler-grammar/CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# @ts-c-compiler/grammar
22

3+
## 1.0.1
4+
5+
### Patch Changes
6+
7+
- Add bootsector output option
8+
- Updated dependencies
9+
- @ts-c-compiler/core@1.0.1
10+
- @ts-c-compiler/lexer@1.0.1
11+
312
## 1.0.0
413

514
### Major Changes

packages/compiler-grammar/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ts-c-compiler/grammar",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"type": "module",
55
"private": true,
66
"license": "MIT",

packages/compiler-lexer/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @ts-c-compiler/lexer
22

3+
## 1.0.1
4+
5+
### Patch Changes
6+
7+
- Add bootsector output option
8+
- Updated dependencies
9+
- @ts-c-compiler/core@1.0.1
10+
311
## 1.0.0
412

513
### Major Changes

packages/compiler-lexer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ts-c-compiler/lexer",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"type": "module",
55
"private": true,
66
"license": "MIT",

packages/compiler-pico-c/CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# @ts-c-compiler/compiler
22

3+
## 1.0.1
4+
5+
### Patch Changes
6+
7+
- Add bootsector output option
8+
- Updated dependencies
9+
- @ts-c-compiler/core@1.0.1
10+
- @ts-c-compiler/lexer@1.0.1
11+
- @ts-c-compiler/rpn@1.0.1
12+
- @ts-c-compiler/x86-assembler@1.0.1
13+
314
## 1.0.0
415

516
### Major Changes

packages/compiler-pico-c/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ts-c-compiler/compiler",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"type": "module",
55
"private": false,
66
"license": "MIT",

packages/compiler-pico-c/src/arch/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CCompilerArch } from '../constants';
22
import { CArchDescriptor } from './types';
33

4+
export * from './x86/asm-utils';
45
import * as X86_16 from './x86/modes/16bit/sizeofPrimitiveType';
56

67
const COMPILER_ARCH_DESCRIPTORS: Record<

packages/compiler-pico-c/src/arch/x86/asm-utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './genDefConst';
33
export * from './genInstruction';
44
export * from './genLabel';
55
export * from './genMemAddress';
6+
export * from './wrapWithX86BootsectorAsm';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const wrapWithX86BootsectorAsm = (code: string) => `
2+
[org 0x7c00]
3+
jmp 0x0000:initialize_mbr
4+
5+
initialize_mbr:
6+
xor ax, ax
7+
mov ds, ax
8+
mov es, ax
9+
mov fs, ax
10+
call @@_fn_main
11+
hlt
12+
13+
${code}
14+
15+
times 510 - ($ - $$) db 0
16+
dw 0xaa55
17+
`;
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export * from './asm-utils';
12
export * from './backend/X86ArchBackend';

packages/compiler-rpn/CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# @ts-c-compiler/rpn
22

3+
## 1.0.1
4+
5+
### Patch Changes
6+
7+
- Add bootsector output option
8+
- Updated dependencies
9+
- @ts-c-compiler/core@1.0.1
10+
- @ts-c-compiler/lexer@1.0.1
11+
312
## 1.0.0
413

514
### Major Changes

packages/compiler-rpn/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ts-c-compiler/rpn",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"type": "module",
55
"private": true,
66
"license": "MIT",

packages/x86-assembler/CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# @ts-c-compiler/x86-assembler
22

3+
## 1.0.1
4+
5+
### Patch Changes
6+
7+
- Add bootsector output option
8+
- Updated dependencies
9+
- @ts-c-compiler/core@1.0.1
10+
- @ts-c-compiler/grammar@1.0.1
11+
- @ts-c-compiler/lexer@1.0.1
12+
- @ts-c-compiler/rpn@1.0.1
13+
314
## 1.0.0
415

516
### Major Changes

packages/x86-assembler/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ts-c-compiler/x86-assembler",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"type": "module",
55
"private": false,
66
"license": "MIT",

packages/x86-cpu/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @ts-c-compiler/x86-cpu
22

3+
## 1.0.1
4+
5+
### Patch Changes
6+
7+
- Add bootsector output option
8+
- Updated dependencies
9+
- @ts-c-compiler/x86-assembler@1.0.1
10+
311
## 1.0.0
412

513
### Major Changes

packages/x86-cpu/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ts-c-compiler/x86-cpu",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"type": "module",
55
"private": true,
66
"license": "MIT",

0 commit comments

Comments
 (0)