From owner-svn-src-user@FreeBSD.ORG Sun Aug 4 18:20:56 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 2A50D287; Sun, 4 Aug 2013 18:20:56 +0000 (UTC) (envelope-from syuu@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 16B9422A1; Sun, 4 Aug 2013 18:20:56 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r74IKuFk048435; Sun, 4 Aug 2013 18:20:56 GMT (envelope-from syuu@svn.freebsd.org) Received: (from syuu@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r74IKrLv048420; Sun, 4 Aug 2013 18:20:53 GMT (envelope-from syuu@svn.freebsd.org) Message-Id: <201308041820.r74IKrLv048420@svn.freebsd.org> From: Takuya ASADA Date: Sun, 4 Aug 2013 18:20:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r253934 - in user/syuu/bhyve_standalone_guest_test1: . kern lib X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Aug 2013 18:20:56 -0000 Author: syuu Date: Sun Aug 4 18:20:53 2013 New Revision: 253934 URL: http://svnweb.freebsd.org/changeset/base/253934 Log: inital import Added: user/syuu/bhyve_standalone_guest_test1/Makefile user/syuu/bhyve_standalone_guest_test1/kern/ user/syuu/bhyve_standalone_guest_test1/kern/boot.S user/syuu/bhyve_standalone_guest_test1/kern/console.c (contents, props changed) user/syuu/bhyve_standalone_guest_test1/kern/console.h user/syuu/bhyve_standalone_guest_test1/kern/multiboot.h user/syuu/bhyve_standalone_guest_test1/kern/test1.c user/syuu/bhyve_standalone_guest_test1/ldscript user/syuu/bhyve_standalone_guest_test1/lib/ user/syuu/bhyve_standalone_guest_test1/lib/console.c user/syuu/bhyve_standalone_guest_test1/lib/console.h user/syuu/bhyve_standalone_guest_test1/lib/string.c user/syuu/bhyve_standalone_guest_test1/lib/string.h user/syuu/bhyve_standalone_guest_test1/lib/types.h Added: user/syuu/bhyve_standalone_guest_test1/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/syuu/bhyve_standalone_guest_test1/Makefile Sun Aug 4 18:20:53 2013 (r253934) @@ -0,0 +1,26 @@ +CFLAGS = -I. -Werror -Wall -Wmissing-prototypes -Wunused -Wshadow -Wpointer-arith -Wundef -fno-builtin -O +CFLAGS += $(shell if $(CC) -fno-stack-protector -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "-fno-stack-protector"; fi) +LDFLAGS = -T ldscript +OBJS = kern/boot.o kern/test1.o kern/console.o lib/console.o lib/string.o + +all: test1.bin + +test1.bin: test1 + objcopy -I elf64-x86-64 -O binary test1 test1.bin + +test1: $(OBJS) + $(LD) -Map test1.map $(LDFLAGS) -o test1 $(OBJS) `$(CC) -print-libgcc-file-name` + +run: + -sudo bhyvectl --vm=test1 --destroy + sudo bhyveload -m 256 -S`pwd`/test1.bin:0x100000 test1 + sudo bhyve -m 256 -e -H -S 31,uart,stdio test1 + +clean: + rm -f $(OBJS) test1 test1.* + +.S.o: + $(CC) -c $(CFLAGS) $< -o $@ + +.c.o: + $(CC) -c $(CFLAGS) $< -o $@ Added: user/syuu/bhyve_standalone_guest_test1/kern/boot.S ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/syuu/bhyve_standalone_guest_test1/kern/boot.S Sun Aug 4 18:20:53 2013 (r253934) @@ -0,0 +1,46 @@ +/* boot.S - bootstrap the kernel */ +/* Copyright (C) 1999, 2001 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#define ASM 1 +#include + + .text + + .globl start, _start +start: +_start: + /* Initialize the stack pointer. */ + movl $(stack + STACK_SIZE), %esp + + /* Reset EFLAGS. */ + pushl $0 + popf + + call EXT_C(main) + + /* Halt. */ + pushl $halt_message + call EXT_C(printf) + +loop: hlt + jmp loop + +halt_message: + .asciz "Halted.\n" + + /* Our stack area. */ + .comm stack, STACK_SIZE Added: user/syuu/bhyve_standalone_guest_test1/kern/console.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/syuu/bhyve_standalone_guest_test1/kern/console.c Sun Aug 4 18:20:53 2013 (r253934) @@ -0,0 +1,32 @@ +#include + +#define COM1_RBR 0x3f8 +#define COM1_THR 0x3f8 +#define COM1_LSR 0x3fd + +static __inline void +outb(unsigned port, unsigned char data) +{ + __asm __volatile("outb %0, %w1" : : "a" (data), "Nd" (port)); +} + +static __inline unsigned char +inb(unsigned port) +{ + unsigned char data; + + __asm __volatile("inb %w1, %0" : "=a" (data) : "Nd" (port)); + return (data); +} + +void putchar(int c) +{ + while ((inb(COM1_LSR) & 0x20) == 0); + outb(COM1_THR, c); +} + +int getchar(void) +{ + while ((inb(COM1_LSR) & 1) == 0); + return inb(COM1_RBR); +} Added: user/syuu/bhyve_standalone_guest_test1/kern/console.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/syuu/bhyve_standalone_guest_test1/kern/console.h Sun Aug 4 18:20:53 2013 (r253934) @@ -0,0 +1,7 @@ +#ifndef KERN_CONSOLE_H_ +#define KERN_CONSOLE_H_ + +void putchar (int c); +int getchar (void); + +#endif Added: user/syuu/bhyve_standalone_guest_test1/kern/multiboot.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/syuu/bhyve_standalone_guest_test1/kern/multiboot.h Sun Aug 4 18:20:53 2013 (r253934) @@ -0,0 +1,124 @@ +/* multiboot.h - the header for Multiboot */ +/* Copyright (C) 1999, 2001 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#ifndef I386_MULTIBOOT_H_ +#define I386_MULTIBOOT_H_ +/* Macros. */ + +/* The magic number for the Multiboot header. */ +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 + +/* The flags for the Multiboot header. */ +#ifdef __ELF__ +# define MULTIBOOT_HEADER_FLAGS 0x00000003 +#else +# define MULTIBOOT_HEADER_FLAGS 0x00010003 +#endif + +/* The magic number passed by a Multiboot-compliant boot loader. */ +#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 + +/* The size of our stack (16KB). */ +#define STACK_SIZE 0x4000 + +/* C symbol format. HAVE_ASM_USCORE is defined by configure. */ +#ifdef HAVE_ASM_USCORE +# define EXT_C(sym) _ ## sym +#else +# define EXT_C(sym) sym +#endif + +#ifndef ASM +/* Do not include here in boot.S. */ + +/* Types. */ + +/* The Multiboot header. */ +typedef struct multiboot_header +{ + unsigned long magic; + unsigned long flags; + unsigned long checksum; + unsigned long header_addr; + unsigned long load_addr; + unsigned long load_end_addr; + unsigned long bss_end_addr; + unsigned long entry_addr; +} multiboot_header_t; + +/* The symbol table for a.out. */ +typedef struct aout_symbol_table +{ + unsigned long tabsize; + unsigned long strsize; + unsigned long addr; + unsigned long reserved; +} aout_symbol_table_t; + +/* The section header table for ELF. */ +typedef struct elf_section_header_table +{ + unsigned long num; + unsigned long size; + unsigned long addr; + unsigned long shndx; +} elf_section_header_table_t; + +/* The Multiboot information. */ +typedef struct multiboot_info +{ + unsigned long flags; + unsigned long mem_lower; + unsigned long mem_upper; + unsigned long boot_device; + unsigned long cmdline; + unsigned long mods_count; + unsigned long mods_addr; + union + { + aout_symbol_table_t aout_sym; + elf_section_header_table_t elf_sec; + } u; + unsigned long mmap_length; + unsigned long mmap_addr; +} multiboot_info_t; + +/* The module structure. */ +typedef struct module +{ + unsigned long mod_start; + unsigned long mod_end; + unsigned long string; + unsigned long reserved; +} module_t; + +/* The memory map. Be careful that the offset 0 is base_addr_low + but no size. */ +typedef struct memory_map +{ + unsigned long size; + unsigned long base_addr_low; + unsigned long base_addr_high; + unsigned long length_low; + unsigned long length_high; + unsigned long type; +} memory_map_t; + +multiboot_info_t *mbi; +#endif /* ! ASM */ +#endif + Added: user/syuu/bhyve_standalone_guest_test1/kern/test1.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/syuu/bhyve_standalone_guest_test1/kern/test1.c Sun Aug 4 18:20:53 2013 (r253934) @@ -0,0 +1,8 @@ +#include + +int main(void) +{ + while(1) + putchar('*'); + return 0; +} Added: user/syuu/bhyve_standalone_guest_test1/ldscript ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/syuu/bhyve_standalone_guest_test1/ldscript Sun Aug 4 18:20:53 2013 (r253934) @@ -0,0 +1,20 @@ +OUTPUT_ARCH(i386:x86-64) +ENTRY(start) +SECTIONS +{ + . = 0x100000; + .text : { *(.text) } + .rodata : { *(.rodata) } + .data : + { + *(.data) + } + _edata = .; + .bss : + { + *(.dynbss) + *(.bss) + *(.COMMON) + } + _end = . ; +} Added: user/syuu/bhyve_standalone_guest_test1/lib/console.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/syuu/bhyve_standalone_guest_test1/lib/console.c Sun Aug 4 18:20:53 2013 (r253934) @@ -0,0 +1,179 @@ + +#include +#include + +#define OUTD_BUF_SIZE 128 +#define OUTU_BUF_SIZE 128 +#define OUTX_BUF_SIZE 128 + +#define UTOC(u) ('0' + u) +#define XTOC(x) "0123456789ABCDEF"[x] + +void +putd(int num) +{ + char buf[OUTD_BUF_SIZE]; + unsigned short is_minus = 0; + + if (num < 0) + { + is_minus = 1; + num = -num; + } + if (num < 10) + putchar(UTOC(num)); + else + { + char *bp; + + bp = buf + OUTU_BUF_SIZE- 1; + *bp-- = '\0'; + while (num && bp >= buf) + { + *bp-- = UTOC(num % 10); + num /= 10; + } + if (is_minus) + putchar('-'); + puts(++bp); + } +} + +void +putu(unsigned num) +{ + char buf[OUTU_BUF_SIZE]; + + if (num < 10) + putchar(UTOC(num)); + else + { + char *bp; + + bp = buf + OUTU_BUF_SIZE- 1; + *bp-- = '\0'; + while (num && bp >= buf) + { + *bp-- = UTOC(num % 10); + num /= 10; + } + puts(++bp); + } +} + +void +putlu(unsigned long long num) +{ + char buf[OUTU_BUF_SIZE]; + + if (num < 10) + putchar(UTOC(num)); + else + { + char *bp; + + bp = buf + OUTU_BUF_SIZE- 1; + *bp-- = '\0'; + while (num && bp >= buf) + { + *bp-- = UTOC(num % 10); + num /= 10; + } + puts(++bp); + } +} + +void +putx(unsigned num) +{ + char buf[OUTX_BUF_SIZE]; + + puts("0x"); + if (num < 16) + putchar(XTOC(num)); + else + { + char *bp; + + bp = buf + OUTX_BUF_SIZE- 1; + *bp-- = '\0'; + while (num && bp >= buf) + { + *bp-- = XTOC(num % 16); + num /= 16; + } + puts(++bp); + } +} + +void +puts(const char *str) +{ + while (*str) + putchar (*str++); +} + +void +putns(const char *str, int n) +{ + while (n--) + putchar (*str++); +} + +int +getns(char *s, int size) +{ + int i; + for (i = 0; i < size; i++) + { + s[i] = getchar(); + if (s[i] == '\r') + break; + } + return i; +} + +int +printf(const char *format, ...) +{ + int i; + va_list ap; + + va_start(ap, format); + for (i = 0; i < strlen(format); i++) + { + if (format[i] == '%') + { + i++; + if (i >= strlen(format)) + { + putchar('%'); + return 0; + } + else if (format[i] == 's') + puts(va_arg(ap, char *)); + else if (format[i] == 'd') + putd(va_arg(ap, int)); + else if (format[i] == 'u') + putu(va_arg(ap, unsigned)); + else if (format[i] == 'U') + putlu(va_arg(ap, unsigned long long)); + else if (format[i] == 'x' || format[i] == 'p') + putx(va_arg(ap, unsigned)); + else if (format[i] == 'c') + putchar(va_arg(ap, int)); + else if (format[i] == 'b') + puts(va_arg(ap, int) ? "true" : "false"); + else + { + putchar('%'); + putchar(format[i]); + } + continue; + } + else + putchar(format[i]); + } + va_end(ap); + return 0; +} Added: user/syuu/bhyve_standalone_guest_test1/lib/console.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/syuu/bhyve_standalone_guest_test1/lib/console.h Sun Aug 4 18:20:53 2013 (r253934) @@ -0,0 +1,16 @@ +#ifndef LIB_CONSOLE_H_ +#define LIB_CONSOLE_H_ +#include +#include + +#define panic(...) {printf("[panic] "); printf(__VA_ARGS__); while(1);} +int printf(const char *format, ...); +void puts(const char *str); +void putns(const char *str, int n); +void putd(const int num); +void putu(const unsigned num); +void putlu(unsigned long long num); +void putx(const unsigned num); +int getns(char *s, int size); + +#endif /* LIB_CONSOLE_H_*/ Added: user/syuu/bhyve_standalone_guest_test1/lib/string.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/syuu/bhyve_standalone_guest_test1/lib/string.c Sun Aug 4 18:20:53 2013 (r253934) @@ -0,0 +1,75 @@ +#include +#include + +//#define DPRINTF (printf("[%s:%s:%d] ", __FILE__, __FUNCTION__, __LINE__), printf) +#define DPRINTF(...) do{}while(0) + +int +strlen(const char *s) +{ + int i = 0; + while (*s++) + i++; + return i; +} + +void * +memset(void *s, int c, int n) +{ + DPRINTF("s:%x c:%d n:%d\n", s, c, n); + int i; + for (i = 0; i < n; i++) + ((char *)s)[i] = c; + return s; +} + +void * +memcpy(void *dest, const void *src, int n) +{ + DPRINTF("dest:%x src:%x n:%d\n", dest, src, n); + int i; + for (i = 0; i < n; i++) + ((char *)dest)[i] = ((char *)src)[i]; + return dest; +} + +char * +strcpy(char *dest, const char *src) +{ + int i; + for (i = 0; src[i]; i++) + dest[i] = ((char *)src)[i]; + return dest; +} + +char * +strncpy(char *dest, const char *src, size_t n) +{ + DPRINTF("dest:%x src:%x n:%d\n", dest, src, n); + int i; + for (i = 0; i < n && src[i] != '\0'; i++) + dest[i] = src[i]; + for (; i < n; i++) + dest[i] = '\0'; + return dest; +} + +int +strcmp(const char *s1, const char *s2) +{ + int i; + for(i = 0; s1[i] == s2[i]; i++) + if(!s1[i]) + return 0; + return s1[i] - s2[i]; +} + +int +strncmp(const char *s1, const char *s2, size_t n) +{ + int i; + for(i = 0; s1[i] == s2[i] && i < n; i++) + if(!s1[i]) + return 0; + return s1[i] - s2[i]; +} Added: user/syuu/bhyve_standalone_guest_test1/lib/string.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/syuu/bhyve_standalone_guest_test1/lib/string.h Sun Aug 4 18:20:53 2013 (r253934) @@ -0,0 +1,13 @@ +#ifndef LIB_STRING_H_ +#define LIB_STRING_H_ +#include + +void *memset(void *s, int c, int n); +void *memcpy(void *dest, const void *src, int n); +int strlen(const char *s); +char *strcpy(char *dest, const char *src); +char *strncpy(char *dest, const char *src, size_t n); +int strcmp(const char *s1, const char *s2); +int strncmp(const char *s1, const char *s2, size_t n); + +#endif /* LIB_STRING_H_*/ Added: user/syuu/bhyve_standalone_guest_test1/lib/types.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/syuu/bhyve_standalone_guest_test1/lib/types.h Sun Aug 4 18:20:53 2013 (r253934) @@ -0,0 +1,28 @@ +#ifndef LIB_TYPES_H +#define LIB_TYPES_H +#include +#include + +typedef unsigned long long uint64_t; +typedef unsigned uint32_t; +typedef unsigned short uint16_t; +typedef unsigned char uint8_t; + +typedef long long int64_t; +typedef int int32_t; +typedef short int16_t; +typedef char int8_t; + +typedef int ssize_t; +typedef unsigned off_t; +typedef unsigned long int ino_t; +typedef uint32_t dev_t; +typedef uint32_t mode_t; +typedef unsigned int nlink_t; +typedef uint32_t uid_t; +typedef uint32_t gid_t; +typedef long int blksize_t; +typedef long int blkcnt_t; +typedef long int time_t; + +#endif