From bdff7484617f2aae8b436d6e4d53eef5e58c89e2 Mon Sep 17 00:00:00 2001 From: sfja Date: Wed, 2 Apr 2025 16:32:51 +0200 Subject: [PATCH] don't use rsp in indirection --- asm/main.c | 37 ++++++++++++++++++++++++++++++------- kern/main.asm | 12 +++--------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/asm/main.c b/asm/main.c index 0c305c8..04165aa 100644 --- a/asm/main.c +++ b/asm/main.c @@ -492,10 +492,32 @@ typedef enum { PStmtTy_Line, PStmtTy_Global, PStmtTy_Extern, - PStmtTy_Include, PStmtTy_Define, } PStmtTy; +typedef struct { + PStmtTy ty; + union { + PLine* line; + char* ident; + }; +} PStmt; + +void pstmt_free(PStmt* stmt) +{ + switch (stmt->ty) { + case PStmtTy_Line: + pline_free(stmt->line); + break; + case PStmtTy_Global: + case PStmtTy_Extern: + case PStmtTy_Define: + free(stmt->ident); + break; + } + free(stmt); +} + typedef struct { Lexer lexer; Tok tok; @@ -1063,7 +1085,7 @@ typedef struct { typedef struct { IdentResolver* re; Reporter* rep; - bool unresolve_is_error; + bool second_pass; } OperandEvaluator; static inline uint16_t eval_poperandty_unary(POperandTy ty, uint16_t operand) @@ -1131,7 +1153,7 @@ EvaledOperand eval_operand_to_imm( const IdentResol* re = ident_resolver_resolve(evaluator->re, operand->str); if (re == NULL) { - if (!evaluator->unresolve_is_error) { + if (!evaluator->second_pass) { return (EvaledOperand) { .ty = EoTy_Imm, .imm = 0 }; } REPORTF_ERROR("undefined identifier '%s'", operand->str); @@ -2109,7 +2131,7 @@ int main(int argc, char** argv) OperandEvaluator evaluator = { .re = &resolver, .rep = &rep, - .unresolve_is_error = false, + .second_pass = false, }; size_t chunk_capacity = 64; @@ -2120,9 +2142,10 @@ int main(int argc, char** argv) int res = define_labels(&resolver, lines[i]->labels, ip, &rep); if (res != 0) errors_occured = true; - ip += pline_assemble(&evaluator, chunk, lines[i], &rep); - if (ip == 0) + uint16_t size = pline_assemble(&evaluator, chunk, lines[i], &rep); + if (size == 0) errors_occured = true; + ip += size; } if (errors_occured) { @@ -2131,7 +2154,7 @@ int main(int argc, char** argv) goto leave_free_chunk; } - evaluator.unresolve_is_error = true; + evaluator.second_pass = true; FILE* output_fp = fopen(args.output_file, "wb"); if (!output_fp) { diff --git a/kern/main.asm b/kern/main.asm index 311d4e9..21f1b1f 100644 --- a/kern/main.asm +++ b/kern/main.asm @@ -96,16 +96,10 @@ keyboard_interrupt: iret put_char: - ; push rbp - add rsp, rsp, 2 - mov u16 [rsp], rbp + push rbp mov rbp, rsp - ; push r1 - add rsp, rsp, 2 - mov u16 [rsp], r1 - ; push r2 - add rsp, rsp, 2 - mov u16 [rsp], r2 + push r1 + push r2 mov r2, u16 [screen_y] mul r2, r2, 40 ; vcd_width_in_ch