]> xenbits.xensource.com Git - people/liuw/rumprun.git/commitdiff
Shuffle bits so that multiboot isn't *the* way to boot.
authorAntti Kantee <pooka@iki.fi>
Thu, 30 Apr 2015 10:17:20 +0000 (10:17 +0000)
committerAntti Kantee <pooka@iki.fi>
Thu, 30 Apr 2015 10:21:17 +0000 (10:21 +0000)
platform/baremetal/Makefile
platform/baremetal/arch/i386/Makefile.inc
platform/baremetal/arch/i386/locore32.S
platform/baremetal/arch/i386/machdep.c
platform/baremetal/include/arch/i386/md.h
platform/baremetal/include/bmk/kernel.h
platform/baremetal/include/bmk/multiboot.h
platform/baremetal/kernel.c
platform/baremetal/multiboot.c [new file with mode: 0644]

index 4b82b40625ad90f698d068c6fea0924671ec0ace..7155432d9238cea9449ca4f524593a1847643211 100644 (file)
@@ -36,7 +36,7 @@ endif
 
 all: app-tools include/bmk/machine rumprun.o commonlibs buildtest
 
-OBJS_BMK-y+=           intr.o clock.o kernel.o undefs.o
+OBJS_BMK-y+=           intr.o clock.o kernel.o multiboot.o undefs.o
 OBJS_BMK-y+=           rumpuser.o rumpconfig.o
 OBJS_BMK-${HASPCI}+=   rumppci.o
 
index 9cee7b02484a7e61e99c2601b122c7c12faf8ba6..7f44935e53fc20644701f8bed533bf95a158c906 100644 (file)
@@ -1,4 +1,4 @@
-OBJS_BMK+=     arch/i386/locore32.o arch/i386/machdep.o
+OBJS_BMK+=     arch/i386/locore32.o arch/i386/machdep.o arch/i386/boot.o
 LDSCRIPT=      arch/i386/kern.ldscript
 
 CFLAGS+=       -mno-sse -mno-mmx -march=i686
index 4551eaf88b839d496d640371ae6f793a8c50b247..175d43699bb2ec834ace49e1eba43c537ec13c9b 100644 (file)
@@ -52,7 +52,7 @@ ENTRY(_start32)
        cmpl $MULTIBOOT_BOOTLOADER_MAGIC, %eax
        jne nomultiboot
 
-       call bmk_main
+       call bmk_cpu_boot
        jmp haltme
 
 nomultiboot:
index de9d7c60b811729590c227b7ed6b12a4c1a696fb..e8948643d1485ab930d759c613b1b44c09c3fcf3 100644 (file)
@@ -214,9 +214,6 @@ bmk_cpu_init(void)
        outb(TIMER_MODE, TIMER_RATEGEN | TIMER_16BIT);
        outb(TIMER_CNTR, (TIMER_HZ/HZ) & 0xff);
        outb(TIMER_CNTR, (TIMER_HZ/HZ) >> 8);
-
-       /* aaand we're good to interrupt */
-       spl0();
 }
 
 int
index c721f3b79bba5517eec5ab6dca105f5472cd5070..35c3acb170da85149b1382e0aac918636b5c163d 100644 (file)
@@ -73,6 +73,9 @@ hlt(void)
 
        __asm__ __volatile__("hlt");
 }
+
+struct multiboot_info;
+void bmk_cpu_boot(struct multiboot_info *);
 #endif /* !_LOCORE */
 
 #endif /* _BMK..._H_ */
index ccc3fa6e70a2a44b62103cb0299b88174125ba68..760d1de1cc7b92fe0cda5fb5f740729075094af0 100644 (file)
@@ -4,7 +4,8 @@
 
 #include <bmk/types.h>
 
-#define MEMSTART 0x100000
+extern unsigned long bmk_memsize, bmk_membase;
+
 #define PAGE_SHIFT 12
 #define PAGE_SIZE (1<<PAGE_SHIFT)
 #define STACK_SIZE 0x2000
 
 void *bmk_allocpg(size_t);
 
-struct multiboot_info;
-void bmk_init(void);
 void bmk_halt(const char *) __attribute__((noreturn));
-void bmk_main(struct multiboot_info *);
 
+void bmk_init(void);
+
+struct multiboot_info;
+void bmk_multiboot(struct multiboot_info *);
+
+void bmk_run(char *);
+
+void bmk_cons_clear(void);
 void bmk_cons_putc(int);
 
 void bmk_cpu_init(void);
index cdd7043a0b73b9ad80fa183c9c5886c2d03ada65..5aa2ca39fcf0d2cfd5051af045e3c34ee690b4ca 100644 (file)
@@ -1,3 +1,11 @@
+#ifndef MULTIBOOT_HEADER
+#define MULTIBOOT_HEADER 1
+
+#define BMK_MULTIBOOT_CMDLINE_SIZE 4096
+#ifndef _LOCORE
+extern char bmk_multiboot_cmdline[];
+#endif
+
 /*
  * from multiboot.h, source:
  * https://www.gnu.org/software/grub/manual/multiboot/multiboot.html
@@ -23,9 +31,6 @@
  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
-
-#ifndef MULTIBOOT_HEADER
-#define MULTIBOOT_HEADER 1
      
 /* How many bytes from the start of the file we search for the header. */
 #define MULTIBOOT_SEARCH               8192
index 7d86bda4253604634ce3a71dace68508817ca6aa..301e75b2fb075a8d75b25234887fda0e312224c1 100644 (file)
@@ -36,8 +36,8 @@
 #include <bmk-core/printf.h>
 #include <bmk-core/queue.h>
 
-static unsigned long bmk_membase;
-static unsigned long bmk_memsize;
+unsigned long bmk_membase;
+unsigned long bmk_memsize;
 
 LIST_HEAD(, stackcache) cacheofstacks = LIST_HEAD_INITIALIZER(cacheofstacks);
 struct stackcache {
@@ -156,67 +156,6 @@ bmk_platform_splx(unsigned long x)
        return; /* XXX */
 }
 
-static int
-parsemem(uint32_t addr, uint32_t len)
-{
-       struct multiboot_mmap_entry *mbm;
-       unsigned long memsize;
-       unsigned long ossize, osbegin, osend;
-       extern char _end[], _begin[];
-       uint32_t off;
-
-       /*
-        * Look for our memory.  We assume it's just in one chunk
-        * starting at MEMSTART.
-        */
-       for (off = 0; off < len; off += mbm->size + sizeof(mbm->size)) {
-               mbm = (void *)(addr + off);
-               if (mbm->addr == MEMSTART
-                   && mbm->type == MULTIBOOT_MEMORY_AVAILABLE) {
-                       break;
-               }
-       }
-       bmk_assert(off < len);
-
-       memsize = mbm->len;
-       osbegin = (unsigned long)_begin;
-       osend = round_page((unsigned long)_end);
-       ossize = osend - osbegin;
-
-       bmk_membase = mbm->addr + ossize;
-       bmk_memsize = memsize - ossize;
-
-       bmk_assert((bmk_membase & (PAGE_SIZE-1)) == 0);
-
-       return 0;
-}
-
-void
-bmk_main(struct multiboot_info *mbi)
-{
-       static char cmdline[2048];
-
-       bmk_printf_init(bmk_cons_putc, NULL);
-       bmk_core_init(BMK_THREAD_STACK_PAGE_ORDER, PAGE_SIZE);
-
-       if (bmk_strlen((char *)mbi->cmdline) > sizeof(cmdline)-1)
-               bmk_platform_halt("command line too long"); /* XXX */
-       bmk_memcpy(cmdline, (char *)mbi->cmdline, sizeof(cmdline));
-
-       bmk_printf("rump kernel bare metal bootstrap\n\n");
-       if ((mbi->flags & MULTIBOOT_MEMORY_INFO) == 0) {
-               bmk_printf("multiboot memory info not available\n");
-               return;
-       }
-       if (parsemem(mbi->mmap_addr, mbi->mmap_length))
-               return;
-       bmk_cpu_init();
-       bmk_isr_init();
-
-       /* enough bootstrap already, jump to main thread */
-       bmk_sched_init(bmk_mainthread, cmdline);
-}
-
 /*
  * console.  quick, cheap, dirty, etc.
  * Should eventually keep an in-memory log.  printf-debugging is currently
@@ -285,6 +224,14 @@ bmk_init(void)
                cons_putat(' ', x % CONS_WIDTH, x / CONS_WIDTH);
 }
 
+void
+bmk_run(char *cmdline)
+{
+
+       /* initialize scheduler and jump to main thread */
+       bmk_sched_init(bmk_mainthread, cmdline);
+}
+
 void __attribute__((noreturn))
 bmk_platform_halt(const char *panicstring)
 {
diff --git a/platform/baremetal/multiboot.c b/platform/baremetal/multiboot.c
new file mode 100644 (file)
index 0000000..8cb8cee
--- /dev/null
@@ -0,0 +1,99 @@
+/*-
+ * Copyright (c) 2014 Antti Kantee.  All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <bmk/types.h>
+#include <bmk/multiboot.h>
+#include <bmk/kernel.h>
+#include <bmk/sched.h>
+
+#include <bmk-core/core.h>
+#include <bmk-core/printf.h>
+#include <bmk-core/string.h>
+
+#define MEMSTART 0x100000
+
+static int
+parsemem(uint32_t addr, uint32_t len)
+{
+       struct multiboot_mmap_entry *mbm;
+       unsigned long memsize;
+       unsigned long ossize, osbegin, osend;
+       extern char _end[], _begin[];
+       uint32_t off;
+
+       /*
+        * Look for our memory.  We assume it's just in one chunk
+        * starting at MEMSTART.
+        */
+       for (off = 0; off < len; off += mbm->size + sizeof(mbm->size)) {
+               mbm = (void *)(addr + off);
+               if (mbm->addr == MEMSTART
+                   && mbm->type == MULTIBOOT_MEMORY_AVAILABLE) {
+                       break;
+               }
+       }
+       bmk_assert(off < len);
+
+       memsize = mbm->len;
+       osbegin = (unsigned long)_begin;
+       osend = round_page((unsigned long)_end);
+       ossize = osend - osbegin;
+
+       bmk_membase = mbm->addr + ossize;
+       bmk_memsize = memsize - ossize;
+
+       bmk_assert((bmk_membase & (PAGE_SIZE-1)) == 0);
+
+       return 0;
+}
+
+char bmk_multiboot_cmdline[BMK_MULTIBOOT_CMDLINE_SIZE];
+
+void
+bmk_multiboot(struct multiboot_info *mbi)
+{
+       unsigned long cmdlinelen;
+
+       bmk_init(); /* XXX: convert to cons_clear */
+       bmk_printf_init(bmk_cons_putc, NULL);
+       bmk_core_init(BMK_THREAD_STACK_PAGE_ORDER, PAGE_SIZE);
+
+       bmk_printf("rump kernel bare metal multibootstrap\n\n");
+
+       /* save the command line before something overwrites it */
+       cmdlinelen = bmk_strlen((char *)mbi->cmdline);
+       if (cmdlinelen >= BMK_MULTIBOOT_CMDLINE_SIZE)
+               bmk_platform_halt("command line too long, "
+                   "increase BMK_MULTIBOOT_CMDLINE_SIZE");
+       bmk_strcpy(bmk_multiboot_cmdline, (char *)mbi->cmdline);
+
+       if ((mbi->flags & MULTIBOOT_MEMORY_INFO) == 0)
+               bmk_platform_halt("multiboot memory info not available\n");
+
+       if (parsemem(mbi->mmap_addr, mbi->mmap_length) != 0)
+               bmk_platform_halt("multiboot memory parse failed");
+
+       bmk_isr_init();
+}