From: Minep Date: Sat, 2 Mar 2024 15:56:19 +0000 (+0000) Subject: * Make the ksym table built-in with kernel image, thus remove the need X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/commitdiff_plain/9209afa5f69cffa48a04c4a9066357d5cba75926 * Make the ksym table built-in with kernel image, thus remove the need of grub side-loaded module. This include a two-stage linking: first pass is used to generate relocated symbol address and populate the ksymtable; second pass is to link the ksymtable into the kernel. * Fix an issue within terminal signal delivery, which always deliver SIGINT due to a typo * Fix the issue where pwait is waken by SIGINT, the next pwait call will fail the invariant assertion check --- diff --git a/lunaix-os/.gitignore b/lunaix-os/.gitignore index a7f6eaf..438c74f 100644 --- a/lunaix-os/.gitignore +++ b/lunaix-os/.gitignore @@ -17,3 +17,5 @@ __pycache__/ **.d *.log + +.lunaix_ksymtable.S \ No newline at end of file diff --git a/lunaix-os/GRUB_TEMPLATE b/lunaix-os/GRUB_TEMPLATE index db98366..c05136f 100644 --- a/lunaix-os/GRUB_TEMPLATE +++ b/lunaix-os/GRUB_TEMPLATE @@ -3,5 +3,4 @@ timeout=0 menuentry "$_OS_NAME" { multiboot /boot/kernel.bin $KCMD - module --nounzip /boot/modksyms modksyms } \ No newline at end of file diff --git a/lunaix-os/arch/i386/mm/pmm.c b/lunaix-os/arch/i386/mm/pmm.c index 7a6ef29..45b7e4e 100644 --- a/lunaix-os/arch/i386/mm/pmm.c +++ b/lunaix-os/arch/i386/mm/pmm.c @@ -31,13 +31,6 @@ found:; ptr_t kexec_end = to_kphysical(__kexec_end); ptr_t aligned_pplist = MAX(ent->start, kexec_end); - // FIXME this is a temporary hack, we need a better way to convey - // the mem-map for us to settle the pplist safely - - for (i = 0; i mods.mods_num; i++) { - aligned_pplist = MAX(aligned_pplist, bctx->mods.entries[i].end); - } - aligned_pplist = napot_upaligned(aligned_pplist, L0T_SIZE); if (aligned_pplist + pool_size > ent->start + ent->size) { diff --git a/lunaix-os/bochs.cfg b/lunaix-os/bochs.cfg deleted file mode 100644 index 0011df5..0000000 --- a/lunaix-os/bochs.cfg +++ /dev/null @@ -1,9 +0,0 @@ -ata0-master: type=cdrom, path="build/lunaix.iso", status=inserted - -memory: guest=1024, host=1024 - -clock: sync=realtime, time0=utc, rtc_sync=1 - -display_library: x, options="gui_debug" - -boot: cdrom \ No newline at end of file diff --git a/lunaix-os/hal/term/lcntls/lcntl.c b/lunaix-os/hal/term/lcntls/lcntl.c index de3334c..db146e1 100644 --- a/lunaix-os/hal/term/lcntls/lcntl.c +++ b/lunaix-os/hal/term/lcntls/lcntl.c @@ -17,7 +17,7 @@ static inline void raise_sig(struct term* at_term, struct linebuffer* lbuf, int sig) { - term_sendsig(at_term, SIGINT); + term_sendsig(at_term, sig); lbuf->sflags |= LSTATE_SIGRAISE; } diff --git a/lunaix-os/includes/lunaix/trace.h b/lunaix-os/includes/lunaix/trace.h index c0208bd..9409c36 100644 --- a/lunaix-os/includes/lunaix/trace.h +++ b/lunaix-os/includes/lunaix/trace.h @@ -7,8 +7,8 @@ struct ksym_entry { ptr_t pc; - u32_t label_off; -}; + char* label; +} align(8); struct trace_record { @@ -19,8 +19,7 @@ struct trace_record struct ksyms { - u32_t ksym_count; - u32_t ksym_label_off; + unsigned long ksym_count; struct ksym_entry syms[0]; }; diff --git a/lunaix-os/kernel.mk b/lunaix-os/kernel.mk index 9d6ca02..189e970 100644 --- a/lunaix-os/kernel.mk +++ b/lunaix-os/kernel.mk @@ -27,6 +27,8 @@ ksrc_deps := $(addsuffix .d,$(ksrc_files)) kinc_opts := $(addprefix -I,$(kinc_dirs)) +tmp_kbin := $(BUILD_DIR)/tmpk.bin +ksymtable := lunaix_ksyms.o CFLAGS += -include flags.h CFLAGS += -include config.h @@ -39,18 +41,25 @@ CFLAGS += -include config.h $(call status_,CC,$<) @$(CC) $(CFLAGS) $(kinc_opts) -c $< -o $@ -$(kbin_dir)/modksyms: $(kbin) - $(call status_,MOD,$@) - @$(PY) scripts/syms_export.py --bits=32 --order=little -o "$@" "$<" +$(tmp_kbin): $(ksrc_objs) + $(call status_,LD,$@) + @$(CC) -T link/linker.ld $(LDFLAGS) -o $@ $^ + +$(ksymtable): $(tmp_kbin) + $(call status_,KSYM,$@) + @scripts/gen_ksymtable.sh DdRrTtAGg $< > .lunaix_ksymtable.S + @$(CC) $(CFLAGS) -c .lunaix_ksymtable.S -o $@ .PHONY: __do_relink -__do_relink: $(ksrc_objs) +__do_relink: $(ksrc_objs) $(ksymtable) $(call status_,LD,$(kbin)) - @$(CC) -T link/linker.ld -o $(kbin) $(ksrc_objs) $(LDFLAGS) + @$(CC) -T link/linker.ld $(LDFLAGS) -o $(kbin) $^ + @rm $(tmp_kbin) .PHONY: all -all: __do_relink $(kbin_dir)/modksyms +all: __do_relink clean: @rm -f $(ksrc_objs) - @rm -f $(ksrc_deps) \ No newline at end of file + @rm -f $(ksrc_deps) + @rm -f .lunaix_ksymtable.S $(ksymtable) \ No newline at end of file diff --git a/lunaix-os/kernel/debug/trace.c b/lunaix-os/kernel/debug/trace.c index 173b1cd..0a70de3 100644 --- a/lunaix-os/kernel/debug/trace.c +++ b/lunaix-os/kernel/debug/trace.c @@ -14,32 +14,21 @@ LOG_MODULE("TRACE") +weak struct ksyms __lunaix_ksymtable[] = { }; +extern struct ksyms __lunaix_ksymtable[]; + static struct trace_context trace_ctx; void trace_modksyms_init(struct boot_handoff* bhctx) { - struct boot_modent* modents = bhctx->mods.entries; - for (size_t i = 0; i < bhctx->mods.mods_num; i++) { - struct boot_modent* mod = &bhctx->mods.entries[i]; - if (streq(mod->str, "modksyms")) { - assert(!va_offset(mod->start)); - - pte_t pte = mkpte(mod->start, KERNEL_DATA); - size_t n = pfn(mod->end) - pfn(mod->start); - - ptr_t ksym_va = vmap_leaf_ptes(pte, n); - - assert(ksym_va); - trace_ctx.ksym_table = (struct ksyms*)ksym_va; - } - } + trace_ctx.ksym_table = __lunaix_ksymtable; } struct ksym_entry* trace_sym_lookup(ptr_t addr) { - int c = trace_ctx.ksym_table->ksym_count; + unsigned long c = trace_ctx.ksym_table->ksym_count; struct ksym_entry* ksent = trace_ctx.ksym_table->syms; int i = c - 1, j = 0, m = 0; @@ -74,8 +63,7 @@ ksym_getstr(struct ksym_entry* sym) return "???"; } - return (char*)((ptr_t)trace_ctx.ksym_table + - trace_ctx.ksym_table->ksym_label_off + sym->label_off); + return sym->label; } static inline bool valid_fp(ptr_t ptr) { @@ -123,9 +111,9 @@ static inline void trace_print_code_entry(ptr_t sym_pc, ptr_t inst_pc, char* sym) { if (sym_pc) { - DEBUG("%p+%p: %s", sym_pc, inst_pc - sym_pc, sym); + DEBUG("%s+%p", sym, inst_pc - sym_pc); } else { - DEBUG("%p+%p: %s", inst_pc, sym_pc, sym); + DEBUG("%s [%p]", sym, sym_pc); } } diff --git a/lunaix-os/kernel/ds/waitq.c b/lunaix-os/kernel/ds/waitq.c index c9fb88f..522974f 100644 --- a/lunaix-os/kernel/ds/waitq.c +++ b/lunaix-os/kernel/ds/waitq.c @@ -18,6 +18,8 @@ pwait(waitq_t* queue) block_current_thread(); sched_pass(); + // In case of SIGINT-forced awaken + llist_delete(¤t_wq->waiters); cpu_enable_interrupt(); } diff --git a/lunaix-os/link/linker.ld b/lunaix-os/link/linker.ld index 93c9693..c3d57da 100644 --- a/lunaix-os/link/linker.ld +++ b/lunaix-os/link/linker.ld @@ -180,6 +180,11 @@ SECTIONS { } + .ksymtable BLOCK(4K) : AT ( ADDR(.ksymtable) - 0xC0000000 ) + { + *(.ksymtable) + } + .bss BLOCK(4K) : AT ( ADDR(.bss) - 0xC0000000 ) { *(.bss) diff --git a/lunaix-os/makeinc/toolchain.mkinc b/lunaix-os/makeinc/toolchain.mkinc index 7421f45..c9d085f 100644 --- a/lunaix-os/makeinc/toolchain.mkinc +++ b/lunaix-os/makeinc/toolchain.mkinc @@ -2,7 +2,6 @@ CC := $(CX_PREFIX)gcc CC := $(CX_PREFIX)gcc AS := $(CX_PREFIX)as AR := $(CX_PREFIX)ar -PY := python3 STRIP_OSDEP_CC := -ffreestanding -fno-pie STRIP_OSDEP_LD := -nostdlib -nolibc -z noexecstack -no-pie -Wl,--build-id=none diff --git a/lunaix-os/scripts/gen_ksymtable.sh b/lunaix-os/scripts/gen_ksymtable.sh new file mode 100755 index 0000000..6b59e4d --- /dev/null +++ b/lunaix-os/scripts/gen_ksymtable.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +sym_types=$1 +bin=$2 + +nm_out=$(nm -nfbsd "$bin") +allsyms=($nm_out) +allsyms_len=${#allsyms[@]} + +syms_idx=() + +for (( i=0; i[0-9a-f]+)\s[a-z]\s+F\s+\.[a-z._]+\s+[0-9a-f]+(?P