From cc21b3d4bbd8f83e5d54302e4c97424b9204daec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kyle=20J=C2=A0Cardoza?= Date: Sun, 7 Jul 2024 23:35:11 -0400 Subject: [PATCH] Fixed cstartup.s --- config/config.mk | 3 +-- config/kernel.scm | 1 + src/kernel/cstartup.s | 63 +++++++++++++++++++++++++++++++++++++++++-- src/kernel/device.c | 3 ++- 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/config/config.mk b/config/config.mk index 23ad337..ff6caa3 100644 --- a/config/config.mk +++ b/config/config.mk @@ -40,8 +40,7 @@ CFLAGS += --debug \ ASFLAGS += --debug endif -LDFLAGS := --no-data-init-table-section \ - --rtattr cstartup=sentinel65x \ +LDFLAGS := --rtattr cstartup=sentinel65x \ --verbose \ --output-format raw diff --git a/config/kernel.scm b/config/kernel.scm index 448d1a9..bbc6020 100644 --- a/config/kernel.scm +++ b/config/kernel.scm @@ -19,6 +19,7 @@ (section data) (section chuge) (section ihuge) + (section data_init_table) (section (irq_trampolines #xC0F000)) (section (irq_vectors #xC0FF80)) ) diff --git a/src/kernel/cstartup.s b/src/kernel/cstartup.s index ae34b86..5bab4fa 100644 --- a/src/kernel/cstartup.s +++ b/src/kernel/cstartup.s @@ -7,6 +7,7 @@ .section stack .section cstack .section heap + .section data_init_table .extern main, exit .extern _Dp, _Vfp @@ -39,18 +40,61 @@ __program_root_section: txs ; set stack lda ##_DirectPageStart tcd ; set direct page +#ifdef __CALYPSI_DATA_MODEL_SMALL__ + lda ##0 +#else lda ##.word2 _NearBaseAddress +#endif stz dp:.tiny(_Vfp+2) xba ; A upper half = data bank pha plb ; pop 8 dummy plb ; set data bank +#ifdef __CALYPSI_CODE_MODEL_COMPACT__ + jmp long:_Trampoline_program_start + .section compactcode, noreorder +_Trampoline_program_start: +#define CODE compactcode +#else +#define CODE code +#endif + call __low_level_init + +;;; **** Initialize data sections if needed. + .section CODE, noroot, noreorder + .pubweak __data_initialization_needed + .extern __initialize_sections +__data_initialization_needed: + lda ##.word2 (.sectionEnd data_init_table) + sta dp:.tiny(_Dp+6) + lda ##.word0 (.sectionEnd data_init_table) + sta dp:.tiny(_Dp+4) + lda ##.word2 (.sectionStart data_init_table) + sta dp:.tiny(_Dp+2) + lda ##.word0 (.sectionStart data_init_table) + sta dp:.tiny(_Dp+0) + call __initialize_sections + +;;; **** Initialize streams if needed. + .section CODE, noroot, noreorder + .pubweak __call_initialize_global_streams + .extern __initialize_global_streams +__call_initialize_global_streams: + call __initialize_global_streams + ;;; **** Initialize heap if needed. - .section code, noroot, noreorder + .section CODE, noroot, noreorder .pubweak __call_heap_initialize .extern __heap_initialize, __default_heap __call_heap_initialize: +#ifdef __CALYPSI_DATA_MODEL_SMALL__ + lda ##.sectionSize heap + sta dp:.tiny(_Dp+2) + lda ##.sectionStart heap + sta dp:.tiny(_Dp+0) + lda ##__default_heap +#else lda ##.word2 (.sectionStart heap) sta dp:.tiny(_Dp+6) lda ##.word0 (.sectionStart heap) @@ -61,9 +105,24 @@ __call_heap_initialize: sta dp:.tiny(_Dp+0) ldx ##.word2 (.sectionSize heap) lda ##.word0 (.sectionSize heap) +#endif call __heap_initialize - .section code, root, noreorder + .section CODE, root, noreorder lda ##0 ; argc = 0 call main jump exit + +;;; *************************************************************************** +;;; +;;; __low_level_init - custom low level initialization +;;; +;;; This default routine just returns doing nothing. You can provide your own +;;; routine, either in C or assembly for doing custom low leve initialization. +;;; +;;; *************************************************************************** + + .section libcode + .pubweak __low_level_init +__low_level_init: + return diff --git a/src/kernel/device.c b/src/kernel/device.c index 2c2969c..4b58a5c 100644 --- a/src/kernel/device.c +++ b/src/kernel/device.c @@ -11,11 +11,12 @@ #include "kernel/device.h" #include "kernel/file.h" +#include "kernel/device/null.h" static bool device_init_all_run = false; Device *device[DEVICE_MAX] = { - NULL + &NullDevice }; struct device_map *device_map[DEVICE_MAP_MAX] = {0};