static assert
This commit is contained in:
parent
28514b4efa
commit
6a955679cd
@ -2,23 +2,11 @@
|
|||||||
@include "macros.vc6asm"
|
@include "macros.vc6asm"
|
||||||
|
|
||||||
start:
|
start:
|
||||||
mov r1, 'V'
|
|
||||||
store [VCD_BEGIN], r1
|
|
||||||
mov r1, 'C'
|
|
||||||
store [VCD_BEGIN + 1], r1
|
|
||||||
mov r1, '6'
|
|
||||||
store [VCD_BEGIN + 2], r1
|
|
||||||
|
|
||||||
mov bp, 0x1000
|
mov bp, 0x1000
|
||||||
mov sp, bp
|
mov sp, bp
|
||||||
|
|
||||||
mov r1, text
|
mov r1, .splash
|
||||||
mov r2, VCD_BEGIN + (1 * 40 + 0)
|
mov r2, VCD_BEGIN + (0 * 40 + 0)
|
||||||
call println
|
|
||||||
|
|
||||||
mov r1, prompt
|
|
||||||
mov r2, VCD_BEGIN + (3 * 40 + 0)
|
|
||||||
mov r0, ip
|
|
||||||
call println
|
call println
|
||||||
|
|
||||||
mov r0, 512
|
mov r0, 512
|
||||||
@ -38,37 +26,12 @@ start:
|
|||||||
and fl, FL_LT
|
and fl, FL_LT
|
||||||
cmov ip, r2
|
cmov ip, r2
|
||||||
|
|
||||||
mov r0, 8
|
|
||||||
store [DISK_BLOCK_ID], r0
|
|
||||||
mov r0, 0x0400
|
|
||||||
store [DISK_ADDR], r0
|
|
||||||
mov r0, DISK_CTL_START
|
|
||||||
store [DISK_CTL], r0
|
|
||||||
|
|
||||||
mov r1, 0x0400
|
|
||||||
mov r2, VCD_BEGIN + (2 * 40 + 0)
|
|
||||||
mov r0, ip
|
|
||||||
call println
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mov r0, keydown_handler
|
|
||||||
store [KBD_KEYDOWN_HANDLER], r0
|
|
||||||
mov r1, 0
|
|
||||||
sti
|
|
||||||
.spin:
|
.spin:
|
||||||
hlt
|
hlt
|
||||||
jr .spin
|
jr .spin
|
||||||
|
|
||||||
keydown_handler:
|
.splash:
|
||||||
load r0, [KBD_SCANCODE]
|
dw "VC6 boot loader\0"
|
||||||
add r0, 93
|
|
||||||
mov r2, VCD_BEGIN + 40 * 3 + 2
|
|
||||||
add r2, r1
|
|
||||||
store [r2], r0
|
|
||||||
add r1, 1
|
|
||||||
sti
|
|
||||||
ret
|
|
||||||
|
|
||||||
println:
|
println:
|
||||||
push bp
|
push bp
|
||||||
@ -105,13 +68,7 @@ println:
|
|||||||
pop bp
|
pop bp
|
||||||
ret
|
ret
|
||||||
|
|
||||||
text:
|
|
||||||
dw "boot loader\0"
|
|
||||||
prompt:
|
|
||||||
dw "> \0"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@const BOOT_SIZE $
|
@const BOOT_SIZE $
|
||||||
|
@static_assert 0x800 - BOOT_SIZE & 0x8000 ^ 0x8000 ; BOOT_SIZE <= 0x800
|
||||||
|
|
||||||
|
|||||||
@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
@org 0x0800
|
@org 0x0800
|
||||||
|
|
||||||
dw "haiiiiiiiiiiiiiiiiiii\0"
|
|
||||||
|
|
||||||
main:
|
main:
|
||||||
mov r1, 'V'
|
mov r1, 'V'
|
||||||
store [VCD_BEGIN], r1
|
store [VCD_BEGIN], r1
|
||||||
|
|||||||
18
src/asm.c
18
src/asm.c
@ -300,6 +300,7 @@ char *read_text_file(const char *filename)
|
|||||||
X(Include, ) \
|
X(Include, ) \
|
||||||
X(Guard, ) \
|
X(Guard, ) \
|
||||||
X(Org, ) \
|
X(Org, ) \
|
||||||
|
X(StaticAssert, ) \
|
||||||
X(MacroArg, ) \
|
X(MacroArg, ) \
|
||||||
X(Exclam, = '!') \
|
X(Exclam, = '!') \
|
||||||
X(Dollar, = '$') \
|
X(Dollar, = '$') \
|
||||||
@ -387,6 +388,7 @@ static TokTy l_ident_ty(const char *text, size_t len)
|
|||||||
"include",
|
"include",
|
||||||
"guard",
|
"guard",
|
||||||
"org",
|
"org",
|
||||||
|
"static_assert",
|
||||||
};
|
};
|
||||||
TokTy tys[] = {
|
TokTy tys[] = {
|
||||||
Tok_R0,
|
Tok_R0,
|
||||||
@ -403,6 +405,7 @@ static TokTy l_ident_ty(const char *text, size_t len)
|
|||||||
Tok_Include,
|
Tok_Include,
|
||||||
Tok_Guard,
|
Tok_Guard,
|
||||||
Tok_Org,
|
Tok_Org,
|
||||||
|
Tok_StaticAssert,
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr size_t kws_size = sizeof(kws) / sizeof(kws[0]);
|
constexpr size_t kws_size = sizeof(kws) / sizeof(kws[0]);
|
||||||
@ -1218,6 +1221,19 @@ static void a_parse_directive_org(Assembler *a)
|
|||||||
a->org_offset = (uint16_t)offset;
|
a->org_offset = (uint16_t)offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void a_parse_directive_assert(Assembler *a)
|
||||||
|
{
|
||||||
|
a_step(a);
|
||||||
|
Loc cond_loc = a->tok.loc;
|
||||||
|
int64_t cond = a_parse_expr(a);
|
||||||
|
a_assert_eol(a);
|
||||||
|
|
||||||
|
printf("cond = %ld\n", cond);
|
||||||
|
|
||||||
|
if (!cond && a->second_pass)
|
||||||
|
print_error_exit(cond_loc, "assertion failed");
|
||||||
|
}
|
||||||
|
|
||||||
static void a_parse_directive(Assembler *a)
|
static void a_parse_directive(Assembler *a)
|
||||||
{
|
{
|
||||||
assert(a->tok.ty == '@');
|
assert(a->tok.ty == '@');
|
||||||
@ -1238,6 +1254,8 @@ static void a_parse_directive(Assembler *a)
|
|||||||
a_parse_directive_guard(a);
|
a_parse_directive_guard(a);
|
||||||
} else if (a->tok.ty == Tok_Org) {
|
} else if (a->tok.ty == Tok_Org) {
|
||||||
a_parse_directive_org(a);
|
a_parse_directive_org(a);
|
||||||
|
} else if (a->tok.ty == Tok_StaticAssert) {
|
||||||
|
a_parse_directive_assert(a);
|
||||||
} else {
|
} else {
|
||||||
print_error_exit(a->tok.loc, "malformed directive");
|
print_error_exit(a->tok.loc, "malformed directive");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ syn keyword vcKeyword dw
|
|||||||
syn keyword vcOperator r0 r1 r2 r3 sp bp fl ip
|
syn keyword vcOperator r0 r1 r2 r3 sp bp fl ip
|
||||||
|
|
||||||
syn match vcOperator '|'
|
syn match vcOperator '|'
|
||||||
syn match vcOperator '^'
|
syn match vcOperator '\^'
|
||||||
syn match vcOperator '&'
|
syn match vcOperator '&'
|
||||||
syn match vcOperator '<<'
|
syn match vcOperator '<<'
|
||||||
syn match vcOperator '>>'
|
syn match vcOperator '>>'
|
||||||
@ -34,6 +34,7 @@ syn match vcPreProc '@elif'
|
|||||||
syn match vcPreProc '@else'
|
syn match vcPreProc '@else'
|
||||||
syn match vcPreProc '@guard'
|
syn match vcPreProc '@guard'
|
||||||
syn match vcPreProc '@org'
|
syn match vcPreProc '@org'
|
||||||
|
syn match vcPreProc '@static_assert'
|
||||||
|
|
||||||
syn match vcNumber '0'
|
syn match vcNumber '0'
|
||||||
syn match vcNumber '[1-9][0-9]*'
|
syn match vcNumber '[1-9][0-9]*'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user