On Thu, Jul 06, 2017 at 06:55:17PM +0300, Artturi Alm wrote:
> Hi,
> 
> is/has anyone been working on a diff that would collect&move these
> into a structure, so that those could easier get gotten rid of once
> bootstrap is done? Or have i missed something about this new bootstrap
> split-up to locore/0.S, i mean, is the gap alone good enough to leave
> these around, or is this still WIP on arm, or considered cleanup hence
> not to be done, or?
> 
> -Artturi

Hi,

lack of answers, and i came up w/this as a start for what i was
asking for above.
Certainly not minimal, maybe optimal, but should be clear&obvious
enough, in any case, i only
did a few variables for this diff, but one has to start somewhere,
and this does zero out the stack used by initarm() before main(),
where all the moved variables now are at, except for the unused
variables i just removed. this one does avoid returning to locore.S
from initarm() also.

the comment i removed and the function proto i changed was because
there is no need for the pretending, arm==armv7, right?

btw. is SORTR in the Makefile the knob i'm supposed to use if i want
to diff whole bsd for binary changes instead of looking at single .o's?

tested for happy booting w/wandboard.
-Artturi


diff --git a/sys/arch/arm/arm/arm32_machdep.c b/sys/arch/arm/arm/arm32_machdep.c
index 44ae69fa7f9..0ed1d7efb30 100644
--- a/sys/arch/arm/arm/arm32_machdep.c
+++ b/sys/arch/arm/arm/arm32_machdep.c
@@ -80,8 +80,6 @@ struct uvm_constraint_range *uvm_md_constraints[] = { NULL };
 
 int cold = 1;
 
-pv_addr_t kernelstack;
-
 /* the following is used externally (sysctl_hw) */
 char   machine[] = MACHINE;            /* from <machine/param.h> */
 
diff --git a/sys/arch/arm/arm/locore.S b/sys/arch/arm/arm/locore.S
index 9e393bc3e36..18bb91c0394 100644
--- a/sys/arch/arm/arm/locore.S
+++ b/sys/arch/arm/arm/locore.S
@@ -40,9 +40,6 @@
 #include <machine/cpu.h>
 #include <machine/frame.h>
 
-/* What size should this really be ? It is only used by init_arm() */
-#define INIT_ARM_STACK_SIZE    2048
-
 /*
  * This is for kvm_mkdb, and should be the address of the beginning
  * of the kernel text segment (not necessarily the same as kernbase).
@@ -64,7 +61,6 @@ ASENTRY_NP(start)
 
        sub     r2, r2, r1              /* get zero init data */
        mov     r3, #0
-
 .L1:
        str     r3, [r1], #0x0004       /* Zero the bss */
        subs    r2, r2, #4
@@ -74,35 +70,22 @@ ASENTRY_NP(start)
        mov     r1, r5
        mov     r2, r6
        mov     r3, r7
-       bl      _C_LABEL(initarm)       /* Off we go */
-
-       /* init arm will return the new stack pointer. */
-       mov     sp, r0
-
-       mov     fp, #0x00000000         /* trace back starts here */
-       mov     ip, sp
-       stmfd   sp!, {fp, ip, lr, pc}
-       sub     fp, ip, #4
-
-       bl      _C_LABEL(main)          /* call main()! */
-
-       adr     r0, .Lmainreturned
-       b       _C_LABEL(panic)
-       /* NOTREACHED */
+       bl      initarm                 /* __dead void initarm(...); */
 
 .Lstart:
        .word   _edata
        .word   _end
        .word   _C_LABEL(cpu_info_primary)
-       .word   svcstk + INIT_ARM_STACK_SIZE
+       .word   _bs_stk + PAGE_SIZE
 
 .Lmainreturned:
        .asciz  "main() returned"
        .align  2
 
        .bss
-svcstk:
-       .space  INIT_ARM_STACK_SIZE
+       .global _bs_stk
+_bs_stk:       /* XXX reuse as msgbuf or something, will be less code. */
+       .space  PAGE_SIZE
 
        .text
        .align  2
diff --git a/sys/arch/arm/arm/pmap7.c b/sys/arch/arm/arm/pmap7.c
index f99ee582e00..c13b8ff97db 100644
--- a/sys/arch/arm/arm/pmap7.c
+++ b/sys/arch/arm/arm/pmap7.c
@@ -421,8 +421,6 @@ vaddr_t virtual_avail;
 vaddr_t virtual_end;
 vaddr_t pmap_curmaxkvaddr;
 
-extern pv_addr_t systempage;
-
 static __inline boolean_t
 pmap_is_current(pmap_t pm)
 {
diff --git a/sys/arch/arm/arm/vm_machdep.c b/sys/arch/arm/arm/vm_machdep.c
index 9b2a00a92f5..44f7c9e36c5 100644
--- a/sys/arch/arm/arm/vm_machdep.c
+++ b/sys/arch/arm/arm/vm_machdep.c
@@ -62,8 +62,6 @@
 #include <machine/reg.h>
 #include <machine/vmparam.h>
 
-extern pv_addr_t systempage;
-
 int process_read_regs  (struct proc *p, struct reg *regs);
 int process_read_fpregs        (struct proc *p, struct fpreg *regs);
 
diff --git a/sys/arch/arm/include/machdep.h b/sys/arch/arm/include/machdep.h
index d5f06623e05..b71b49c0ea3 100644
--- a/sys/arch/arm/include/machdep.h
+++ b/sys/arch/arm/include/machdep.h
@@ -12,11 +12,7 @@ void prefetch_abort_handler (trapframe_t *);
 void undefinedinstruction_bounce (trapframe_t *);
 void dumpsys   (void);
 
-/* 
- * note that we use void * as all the platforms have different ideas on what
- * the structure is
- */
-u_int initarm (void *, void *, void *, paddr_t);
+__dead void initarm(u_int, u_int, void *, paddr_t);
 
 /* from arm/arm/intr.c */
 void dosoftints (void);
diff --git a/sys/arch/armv7/armv7/armv7_machdep.c 
b/sys/arch/armv7/armv7/armv7_machdep.c
index aa1c549b29b..d4d76f108fa 100644
--- a/sys/arch/armv7/armv7/armv7_machdep.c
+++ b/sys/arch/armv7/armv7/armv7_machdep.c
@@ -151,25 +151,8 @@ char *boot_args = NULL;
 char *boot_file = "";
 u_int cpu_reset_address = 0;
 
-vaddr_t physical_start;
-vaddr_t physical_freestart;
-vaddr_t physical_freeend;
-vaddr_t physical_end;
-u_int free_pages;
 int physmem = 0;
 
-/*int debug_flags;*/
-#ifndef PMAP_STATIC_L1S
-int max_processes = 64;                        /* Default number */
-#endif /* !PMAP_STATIC_L1S */
-
-/* Physical and virtual addresses for some global pages */
-pv_addr_t systempage;
-pv_addr_t irqstack;
-pv_addr_t undstack;
-pv_addr_t abtstack;
-extern pv_addr_t kernelstack;
-
 vaddr_t msgbufphys;
 
 extern u_int data_abort_handler_address;
@@ -368,8 +351,8 @@ copy_io_area_map(pd_entry_t *new_pd)
  *   Initialising the physical console so characters can be printed.
  *   Setting up page tables for the kernel.
  */
-u_int
-initarm(void *arg0, void *arg1, void *arg2, paddr_t loadaddr)
+__dead void
+initarm(u_int _esym_fixup, u_int _board_id, void *_fdt, paddr_t loadaddr)
 {
        int loop, loop1, i, physsegs = VM_PHYSSEG_MAX;
        u_int l1pagetable;
@@ -383,16 +366,28 @@ initarm(void *arg0, void *arg1, void *arg2, paddr_t 
loadaddr)
        size_t size;
        void *node;
        extern uint32_t esym; /* &_end if no symbols are loaded */
+       extern u_int _bs_stk;
+       /* Physical and virtual addresses for some global pages */
+       pv_addr_t systempage;
+       pv_addr_t irqstack;
+       pv_addr_t undstack;
+       pv_addr_t abtstack;
+       pv_addr_t kernelstack;
+       vaddr_t physical_start;
+       vaddr_t physical_freestart;
+       vaddr_t physical_freeend;
+       vaddr_t physical_end;
+       u_int free_pages;
+
 
        /* early bus_space_map support */
-       struct bus_space tmp_bs_tag;
        int     (*map_func_save)(void *, uint64_t, bus_size_t, int,
            bus_space_handle_t *);
 
-       if (arg0)
-               esym = (uint32_t)arg0;
+       if (_esym_fixup)
+               esym = _esym_fixup;
 
-       board_id = (uint32_t)arg1;
+       board_id = _board_id;
        /*
         * u-boot has decided the top four bits are
         * 'compatibility revision' for sunxi
@@ -413,11 +408,9 @@ initarm(void *arg0, void *arg1, void *arg2, paddr_t 
loadaddr)
         * Note that this relies upon the fact that both regular
         * and a4x bus_space tags use the same map function.
         */
-       tmp_bs_tag = armv7_bs_tag;
        map_func_save = armv7_bs_tag.bs_map;
        armv7_bs_tag.bs_map = bootstrap_bs_map;
        armv7_a4x_bs_tag.bs_map = bootstrap_bs_map;
-       tmp_bs_tag.bs_map = bootstrap_bs_map;
 
        /*
         * Now, map the FDT area.
@@ -429,7 +422,7 @@ initarm(void *arg0, void *arg1, void *arg2, paddr_t 
loadaddr)
         * XXX: There's (currently) no way to unmap a bootstrap mapping, so
         * we might lose a bit of the bootstrap address space.
         */
-       bootstrap_bs_map(NULL, (bus_addr_t)arg2, L1_S_SIZE, 0,
+       bootstrap_bs_map(NULL, (bus_addr_t)_fdt, L1_S_SIZE, 0,
            (bus_space_handle_t *)&config);
 
        if (!fdt_init(config) || fdt_get_size(config) == 0)
@@ -466,7 +459,8 @@ initarm(void *arg0, void *arg1, void *arg2, paddr_t 
loadaddr)
        /* Talk to the user */
        printf("\nOpenBSD/armv7 booting ...\n");
 
-       printf("arg0 %p arg1 %p arg2 %p\n", arg0, arg1, arg2);
+       printf("arg0 %#x arg1 %#x arg2 %p arg3 %#lx\n",
+           _esym_fixup, _board_id, _fdt, loadaddr);
 
 #ifdef RAMDISK_HOOKS
        boothowto |= RB_DFLTROOT;
@@ -791,8 +785,35 @@ initarm(void *arg0, void *arg1, void *arg2, paddr_t 
loadaddr)
 
        cpu_setup();
 
-       /* We return the new stack pointer address */
-       return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
+       /*
+        * setup stack&frame pointers for main(),
+        * and clean/zero the bootstrap stack used by initarm().
+        */
+       asm volatile(
+               "mov    r0, %0\n"
+               "mov    sp, r0\n"
+               "mov    fp, #0x00000000\n"
+               "mov    ip, sp\n"
+               "push   {fp, ip, lr, pc}\n"
+               "sub    fp, ip, #4\n"
+               "mov    r1, %1\n"               /* r1:zp = &_bs_stk */
+               "mov    r2, %2\n"
+               "add    r2, r1, r2\n"           /* r2:zpe = zp + PAGE_SIZE */
+               "mov    r3, #0x00000000\n"
+       "1:     str     r3, [r1], #4\n"         /* do { *zp++ = 0x00; */
+               "cmp    r1, r2\n"               /* } while (zp != zpe); */
+               "bne    1b\n"
+               "mov    r1, #0x00000000\n"
+               "mov    r2, #0x00000000\n"
+               "dsb    sy\n"
+               "isb    sy\n"
+               "bl     main\n"                 /* branch to MI */
+           :: "r"(kernelstack.pv_va + USPACE_SVC_STACK_TOP),
+           "r"(&_bs_stk), "I"(PAGE_SIZE) : "memory");
+
+       panic("main() returned");
+       for (;;)
+               asm volatile("");
 }
 
 

Reply via email to