resw
This commit is contained in:
parent
251d214f25
commit
6a4a678e5d
@ -1,39 +1,67 @@
|
||||
@include "arch.vc6asm"
|
||||
@include "macros.vc6asm"
|
||||
|
||||
@const STACK_BASE 0xfff
|
||||
@const HEAP_BASE 0x1000
|
||||
@const stack_base 0xfff
|
||||
@const heap_base 0x1000
|
||||
|
||||
@const block_size 0x200
|
||||
|
||||
|
||||
start:
|
||||
mov bp, STACK_BASE
|
||||
mov bp, stack_base
|
||||
mov sp, bp
|
||||
|
||||
mov r1, .splash
|
||||
mov r1, .splash_str
|
||||
call println
|
||||
|
||||
mov r1, .loading_bootloader_str
|
||||
call println
|
||||
|
||||
mov r0, 512
|
||||
mov r1, 1
|
||||
mov r2, 512
|
||||
jmp .l0_cond
|
||||
.l0_body:
|
||||
store [DISK_BLOCK_ID], r1
|
||||
store [DISK_ADDR], r0
|
||||
mov r2, DISK_CTL_START
|
||||
store [DISK_CTL], r2
|
||||
add r0, 512
|
||||
call read_block
|
||||
|
||||
add r1, 1
|
||||
add r2, 512
|
||||
.l0_cond:
|
||||
cmp r1, BOOT_SIZE / 512 + 2
|
||||
cmp r1, (BOOT_SIZE + 511) / 512
|
||||
jlt .l0_body
|
||||
|
||||
mov r1, .ok_str
|
||||
call println
|
||||
|
||||
.spin:
|
||||
hlt
|
||||
jmp .spin
|
||||
|
||||
.splash:
|
||||
dw "VC6 boot loader\n\0"
|
||||
.splash_str:
|
||||
dw "VC6 BOOT LOADER\0"
|
||||
.ok_str:
|
||||
dw "OK\0"
|
||||
.loading_bootloader_str:
|
||||
dw "Loading bootloader...\0"
|
||||
|
||||
display:
|
||||
read_block:
|
||||
store [DISK_BLOCK_ID], r1
|
||||
store [DISK_ADDR], r2
|
||||
mov r0, DISK_CTL_START
|
||||
store [DISK_CTL], r0
|
||||
ret
|
||||
|
||||
@const fs_superblock heap_base
|
||||
@const fs_block_bitmap fs_superblock + block_size
|
||||
|
||||
@const fs_block_offset 4
|
||||
|
||||
fs_load:
|
||||
mov r1, 4
|
||||
mov r2, fs_superblock
|
||||
call read_block
|
||||
|
||||
|
||||
Display:
|
||||
.x: dw 0
|
||||
.y: dw 0
|
||||
|
||||
@ -50,8 +78,8 @@ println:
|
||||
cmp r2, '\n'
|
||||
jeq .newline
|
||||
|
||||
load r1, [display.x]
|
||||
load r3, [display.y]
|
||||
load r1, [Display.x]
|
||||
load r3, [Display.y]
|
||||
|
||||
add r3, r1
|
||||
add r3, VCD_BEGIN
|
||||
@ -65,12 +93,12 @@ println:
|
||||
.newline:
|
||||
mov r1, 0
|
||||
|
||||
load r3, [display.y]
|
||||
load r3, [Display.y]
|
||||
add r3, 40
|
||||
store [display.y], r3
|
||||
store [Display.y], r3
|
||||
.no_newline:
|
||||
|
||||
store [display.x], r1
|
||||
store [Display.x], r1
|
||||
|
||||
add r0, 1
|
||||
.l0_cond:
|
||||
@ -78,19 +106,18 @@ println:
|
||||
cmp r1, '\0'
|
||||
jgt .l0_body
|
||||
|
||||
load r3, [display.y]
|
||||
load r3, [Display.y]
|
||||
add r3, 40
|
||||
store [display.y], r3
|
||||
store [Display.y], r3
|
||||
|
||||
mov r1, 0
|
||||
store [display.x], r1
|
||||
store [Display.x], r1
|
||||
|
||||
.leave:
|
||||
mov sp, bp
|
||||
pop bp
|
||||
ret
|
||||
|
||||
|
||||
@const BOOT_SIZE $
|
||||
@static_assert 0x800 - BOOT_SIZE & 0x8000 ^ 0x8000 ; BOOT_SIZE <= 0x800
|
||||
|
||||
|
||||
38
src/asm.c
38
src/asm.c
@ -1407,6 +1407,38 @@ static void a_parse_dw(Assembler *a, Loc loc)
|
||||
a->ip = ip;
|
||||
}
|
||||
|
||||
static void a_parse_resw(Assembler *a, Loc loc)
|
||||
{
|
||||
(void)loc;
|
||||
|
||||
int64_t count = a_parse_expr(a);
|
||||
bool fill_with_nop = false;
|
||||
uint16_t val = 0;
|
||||
if (a->tok.ty == ',') {
|
||||
a_step(a);
|
||||
if (a->tok.ty == Tok_Ident && a->tok.len == 3
|
||||
&& strncmp(a->tok.text, "nop", a->tok.len) == 0) {
|
||||
a_step(a);
|
||||
fill_with_nop = true;
|
||||
} else {
|
||||
val = a_parse_expr(a);
|
||||
}
|
||||
}
|
||||
a_assert_eol(a);
|
||||
|
||||
for (int64_t i = 0; i < count; ++i) {
|
||||
assert(a->ip < a->output_size);
|
||||
|
||||
if (fill_with_nop) {
|
||||
a->ip += op_encode(
|
||||
a->output, a->output_size, a->ip, &(Op) { .ty = Op_Nop });
|
||||
} else {
|
||||
a->output[a->ip] = val;
|
||||
a->ip += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void a_parse_macro_expan(Assembler *a, size_t macro_idx, Loc loc)
|
||||
{
|
||||
MacroExpansion expan = {
|
||||
@ -1539,6 +1571,12 @@ static void a_parse_ins(Assembler *a, Tok ident_tok)
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(ident, "resw") == 0) {
|
||||
free(ident);
|
||||
a_parse_resw(a, ident_tok.loc);
|
||||
return;
|
||||
}
|
||||
|
||||
size_t *macro_idx = map_get(&a->macro_map, ident);
|
||||
if (macro_idx) {
|
||||
free(ident);
|
||||
|
||||
@ -9,7 +9,7 @@ endif
|
||||
|
||||
syn keyword vcKeyword nop hlt mov load store cmp cmov
|
||||
syn keyword vcKeyword or xor and not shr shl rshr rshl add sub
|
||||
syn keyword vcKeyword dw
|
||||
syn keyword vcKeyword dw resw
|
||||
syn keyword vcOperator r0 r1 r2 r3 sp bp fl ip
|
||||
|
||||
syn match vcOperator '|'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user