From 54bd33f64923b67e5dd1d954d3b2c974aff99e1f Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Wed, 23 Jan 2019 14:17:01 +0000 Subject: [PATCH] 68000: dynamic udata, use actual available memory space for allocs --- Kernel/flat.c | 7 +++---- Kernel/include/kernel.h | 2 +- Kernel/platform-tiny68k/README | 7 +++++-- Kernel/platform-tiny68k/main.c | 31 +++++++++++++++++++++---------- Kernel/platform-tiny68k/p68000.S | 7 ++----- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Kernel/flat.c b/Kernel/flat.c index 8a189abc..7d4feaf1 100644 --- a/Kernel/flat.c +++ b/Kernel/flat.c @@ -54,7 +54,7 @@ static struct mem *mem[PTABSIZE]; /* The map we use */ static struct mem *store[PTABSIZE]; /* Where our memory currently lives */ static struct mem memblock[PTABSIZE]; -extern struct u_data *udata_shadow; /* FIXME HACK */ +extern struct u_data *udata_shadow; static void mem_free(struct mem *m) { @@ -204,8 +204,6 @@ usize_t valaddr(const char *pp, usize_t l) p is the process we are going to create maps for, udata.u_ptab is our own process. init is a special case! - FIXME: where do we need to call pagemap_alloc from to get it early - and make the valaddr and init data special cases go away ? */ int pagemap_alloc(ptptr p) @@ -217,7 +215,8 @@ int pagemap_alloc(ptptr p) kprintf("%d: pagemap_alloc %p\n", proc, p); #endif p->p_page = nproc; - platform_udata_set(p); + if (platform_udata_set(p)) + return ENOMEM; /* Init is special */ if (p->p_pid == 1) { struct memblk *mb; diff --git a/Kernel/include/kernel.h b/Kernel/include/kernel.h index e5b526c4..c848941d 100644 --- a/Kernel/include/kernel.h +++ b/Kernel/include/kernel.h @@ -1055,7 +1055,7 @@ extern uint8_t platform_param(char *p); extern void platform_switchout(void); extern void platform_interrupt(void); extern uint8_t platform_suspend(void); -extern void platform_udata_set(ptptr p); +extern uint8_t platform_udata_set(ptptr p); extern void platform_swap_found(uint8_t part, uint8_t letter); diff --git a/Kernel/platform-tiny68k/README b/Kernel/platform-tiny68k/README index 839fadbe..2840af09 100644 --- a/Kernel/platform-tiny68k/README +++ b/Kernel/platform-tiny68k/README @@ -58,8 +58,6 @@ To Do Propogate synchronous trap changes to Z80+MMU and Z180 illegal and maybe generically jp 0 and 0 corruptor ? -Dynamic udata allocation -Do we need the extra irqstack any more ? Move lots of p68000.S code into lowlevel-68000.S Need some kind of CPU specific C file (or a general one with ifdefs ?) and then move lots of platform/main.c into it. @@ -70,6 +68,9 @@ Better binary format. Look into posix spawn functions or vfork and if /bin/sh can use them +Longer term split into multiple segments (code R/O uncopied, data/stack etc +copied) + DONE Add a 'user touches kernel' catcher on the debug/sim DONE ps user/kernel include mismatch error DONE (libc bug) calendar does not put a : before 'cannot open file' @@ -106,3 +107,5 @@ DONE Pick a final trap number that is clear of any interesting emulations DONE Switch from one process in memory model to flat model with parent first and child custom stack build DONE All I/O going via buffers +DONE Dynamic udata allocation +DONE Do we need the extra irqstack any more ? diff --git a/Kernel/platform-tiny68k/main.c b/Kernel/platform-tiny68k/main.c index f341d56b..b705bbec 100644 --- a/Kernel/platform-tiny68k/main.c +++ b/Kernel/platform-tiny68k/main.c @@ -43,17 +43,19 @@ void memzero(void *p, usize_t len) void pagemap_init(void) { - /* FIXME: base should be from _end of binary aligned - and size we want to probe early and deal with shifted monitor - etc */ - kmemaddblk((void *)0x40000, 0xFF8000 - 0x40000); + /* Linker provided end of kernel */ + extern uint8_t _end; + uint32_t e = (uint32_t)&_end; + kprintf("Kernel end %p\n", e); + /* Allocate the rest of memory to the userspace */ + kmemaddblk((void *)e, 0xFF8000 - e); } /* Udata and kernel stacks */ -/* FIXME: dynamic allocation needed */ -u_block udata_block[PTABSIZE]; -/* FIXME: irqstack can go now I think */ -uint16_t irqstack[128]; /* Used for swapping only */ +/* We need an initial kernel stack and udata so the slot for init is + set up at compile time */ +u_block udata_block0; +static u_block *udata_block[PTABSIZE] = {&udata_block0,}; /* This will belong in the core 68K code once finalized */ @@ -64,9 +66,18 @@ void install_vdso(void) memcpy((void *)udata.u_codebase, &vdso, 0x40); } -void platform_udata_set(ptptr p) +uint8_t platform_udata_set(ptptr p) { - p->p_udata = &udata_block[p - ptab].u_d; + u_block **up = &udata_block[p - ptab]; + if (*up == NULL) { + *up = kmalloc(sizeof(struct u_block)); + if (*up == NULL) + return ENOMEM; + kputs("alloc udata"); + } + p->p_udata = &(*up)->u_d; + kprintf("udata %p\n", p->p_udata); + return 0; } extern void *get_usp(void); diff --git a/Kernel/platform-tiny68k/p68000.S b/Kernel/platform-tiny68k/p68000.S index 9704faad..edcee32b 100644 --- a/Kernel/platform-tiny68k/p68000.S +++ b/Kernel/platform-tiny68k/p68000.S @@ -1,8 +1,5 @@ #include "../kernel-68000.def" -/* - * Lots left to fill in - */ .globl platform_reboot .globl init_early @@ -10,7 +7,7 @@ .globl program_vectors .globl outchar .globl platform_monitor - .globl udata_block + .globl udata_block0 .globl devide_read_data .globl devide_write_data .globl vdso @@ -30,7 +27,7 @@ platform_reboot: bra platform_monitor init_early: - lea.l udata_block,a5 ; udata ptr + lea.l udata_block0,a5 ; udata ptr move.l a5,udata_shadow ; shadow copy for entry/exit rts -- 2.34.1