diff --git a/programs/boot.vc5asm b/programs/boot.vc5asm index ed74de5..338e7b8 100644 --- a/programs/boot.vc5asm +++ b/programs/boot.vc5asm @@ -1,13 +1,20 @@ -const KBD_STATUS 0x1ffc -const KBD_CODE 0x1ffe -const VCD 0x2000 +const fl_zero 0x1 +const fl_eq 0x2 +const fl_be 0x4 +const fl_lt 0x8 +const fl_err 0xa -const FL_EQ 0x2 +const vcd_base 0x2000 -const KBD_FLAG_IS_RELEASE 0x1 +const kbd_status 0x1ffc +const kbd_code 0x1ffe +const kbd_flag_is_release 0x1 +const counter 0x600 + +_start: mov rsp, 0x1000 mov rbp, rsp @@ -18,7 +25,7 @@ const KBD_FLAG_IS_RELEASE 0x1 ; setup video character display (VCD) ; descriptor table structure: ; [addr + 0] memory map base - mov r0, VCD + mov r0, vcd_base mov [0x700], r0 lvcd 0x700 @@ -27,9 +34,9 @@ const KBD_FLAG_IS_RELEASE 0x1 ; [addr + 0] status address ; [addr + 2] keycode address ; [addr + 4] keyboard interrupt handler - mov r0, KBD_STATUS + mov r0, kbd_status mov [0x702], r0 - mov r0, KBD_CODE + mov r0, kbd_code mov [0x704], r0 mov r0, key_press_int mov [0x706], r0 @@ -37,33 +44,91 @@ const KBD_FLAG_IS_RELEASE 0x1 ; character counter mov r0, 0 - mov [0x600], r0 + mov [counter], r0 main_loop: hlt jmp main_loop key_press_int: - mov r0, [KBD_STATUS] - and r0, r0, KBD_FLAG_IS_RELEASE + mov r0, [kbd_status] + and r0, kbd_flag_is_release jnz r0, .leave - mov r0, [0x600] - add r0, r0, VCD - mov r1, [KBD_CODE] + mov r0, [counter] + add r0, vcd_base + mov r1, [kbd_code] cmp r1, 44 ; spacebar mov r2, rfl - and r2, r2, FL_EQ - jnz r2, .incr - add r1, r1, 61 - mov byte [r0], r1 -.incr: - mov r0, [0x600] - add r0, r0, 1 - mov [0x600], r0 + and r2, fl_eq +; jnz r2, .incr +; add r1, 61 +; mov byte [r0], r1 +;.incr: +; mov r0, [counter] +; add r0, 1 +; mov [counter], r0 + + jnz r2, .print_space + add r1, 61 ; scancode letter -> ascii + mov [rsp], r0 + add rsp, 2 + call print_char + jmp .leave +.print_space: + mov r0, ' ' + mov [rsp], r0 + add rsp, 2 + call print_char .leave: reti +print_char: + mov [rsp], rbp + mov rbp, rsp + add rsp, 2 + + mov r1, [rbp-6] + + add r0, vcd_base + mov r1, [kbd_code] + cmp r1, ' ' + mov r2, rfl + and r2, fl_eq + jnz r2, .incr + add r1, 61 + mov byte [r0], r1 +.incr: + mov r0, [counter] + add r0, 1 + mov [counter], r0 +.leave: + sub rsp, 2 + mov rbp, [rsp] + ret + +;print_int: +; mov [rsp], rbp +; add rsp, 2 +; mov rbp, rsp +; add rsp, rsp, 2 +; +; mov r1, [rbp-2] +; +; mov r2, 10000 +; mov r3, 0 +; jmp .c_10000 +;.b_10000: +; add r3, 1 +; sub r1, r2 +;.c_10000: +; cmp r2, r1 +; mov r0, rfl +; and r0, fl_eq | fl_lt +; jnz r0, .b_10000 +; add r3, 48 + + ;scancode_to_char: ; cmp r1, 61 ; diff --git a/src/assembler.cpp b/src/assembler.cpp index 36c2341..7a61e5a 100644 --- a/src/assembler.cpp +++ b/src/assembler.cpp @@ -101,7 +101,11 @@ auto Assembler::assemble_file() } assert(value->ty == EOT::Imm); - m_syms[std::string(stmt->ident)] = value->as_imm(); + if (auto result + = define_sym(std::string(stmt->ident), value->as_imm()); + not result) { + error(stmt->loc, result.error()); + } } else if (parser.next_is_align()) { auto stmt = parser.parse_align(); @@ -172,9 +176,20 @@ auto Assembler::assemble_file() m_second_pass = true; for (const auto& line : lines) { + if (line->labels) { + for (const auto& label : *line->labels) { + if (not label.is_local) { + m_superlabel = label.ident; + } + } + } + assemble_line(*line); } + if (m_failed) + return std::unexpected("assembling failed"); + return std::move(m_program); } @@ -182,10 +197,17 @@ void Assembler::define_labels(const std::vector