68000: dynamic udata, use actual available memory space for allocs
authorAlan Cox <alan@linux.intel.com>
Wed, 23 Jan 2019 14:17:01 +0000 (14:17 +0000)
committerAlan Cox <alan@linux.intel.com>
Wed, 23 Jan 2019 14:17:01 +0000 (14:17 +0000)
Kernel/flat.c
Kernel/include/kernel.h
Kernel/platform-tiny68k/README
Kernel/platform-tiny68k/main.c
Kernel/platform-tiny68k/p68000.S

index 8a189ab..7d4feaf 100644 (file)
@@ -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;
index e5b526c..c848941 100644 (file)
@@ -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);
 
index 839fadb..2840af0 100644 (file)
@@ -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 ?
index f341d56..b705bbe 100644 (file)
@@ -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);
index 9704faa..edcee32 100644 (file)
@@ -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