Skip to content

Commit 4e4f908

Browse files
committed
Initial import of the x86 port
Currently this works only in qemu.
1 parent 2b95e7b commit 4e4f908

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+7915
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ cachegrind.out*
1111
.project
1212
.cproject
1313
.settings
14+
/toolchain

boards/qemu-i386/Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
MODULE = qemu-i386_base
2+
3+
DIRS = $(RIOTBOARD)/x86-multiboot-common
4+
5+
all: $(BINDIR)$(MODULE).a
6+
@for i in $(DIRS) ; do "$(MAKE)" -C $$i ; done ;
7+
8+
include $(RIOTBASE)/Makefile.base
9+
10+
clean::
11+
@for i in $(DIRS) ; do "$(MAKE)" -C $$i clean ; done ;

boards/qemu-i386/Makefile.include

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include $(RIOTBOARD)/x86-multiboot-common/Makefile.include
2+
3+
CFLAGS += -march=i686 -mtune=i686
4+
CFLAGS += -I$(RIOTBOARD)/qemu-i386/include
5+
6+
TERMPROG = qemu-system-i386 -m 512m -serial stdio -nographic -monitor /dev/null -kernel $(BINDIR)/$(PROJECT).hex
7+
FLASHER = true

boards/qemu-i386/include/board.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2014 René Kijewski <rene.kijewski@fu-berlin.de>
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
/**
20+
* @ingroup x86
21+
* @{
22+
*
23+
* @file
24+
* @brief Board specific defines for qemu-i386.
25+
*
26+
* @author René Kijewski <rene.kijewski@fu-berlin.de>
27+
*/
28+
29+
#ifndef __RIOT__BOARDS__QEMU_I386__BOARD__H
30+
#define __RIOT__BOARDS__QEMU_I386__BOARD__H
31+
32+
#define UART_PORT (COM1_PORT) /* IO port to use for UART */
33+
#define UART_IRQ (COM1_IRQ) /* IRQ line to use for UART */
34+
35+
#define LED_RED_ON /* not available */
36+
#define LED_RED_OFF /* not available */
37+
#define LED_RED_TOGGLE /* not available */
38+
39+
#endif
40+
41+
/**
42+
* @}
43+
*/

boards/qemu-i386/include/cpu-conf.h

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (C) 2014 René Kijewski <rene.kijewski@fu-berlin.de>
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
/**
20+
* CPU-specific defines for qemu-i386.
21+
*
22+
* @ingroup x86
23+
* @{
24+
* @file
25+
* @author René Kijewski <rene.kijewski@fu-berlin.de>
26+
*/
27+
28+
#ifndef __RIOT__BOARDS__QEMU_I386__CPU_CONF__H
29+
#define __RIOT__BOARDS__QEMU_I386__CPU_CONF__H
30+
31+
/* FIXME: This file is just a filler. The numbers are entirely random ... */
32+
33+
#define KERNEL_CONF_STACKSIZE_DEFAULT (8192)
34+
#define KERNEL_CONF_STACKSIZE_IDLE (8192)
35+
#define KERNEL_CONF_STACKSIZE_PRINTF (8192)
36+
#define KERNEL_CONF_STACKSIZE_PRINTF_FLOAT (8192)
37+
38+
#define MINIMUM_STACK_SIZE (8192)
39+
40+
#define UART0_BUFSIZE (16)
41+
42+
#define F_CPU (1000000) /* This value is unused in x86 */
43+
44+
#endif
45+
46+
/** @} */

boards/qemu-i386/x86_board_init.c

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (C) 2014 René Kijewski <rene.kijewski@fu-berlin.de>
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
/**
20+
* @ingroup x86
21+
* @{
22+
*
23+
* @file
24+
* @brief Initialization code for the qemu-i386 board
25+
*
26+
* @author René Kijewski <rene.kijewski@fu-berlin.de>
27+
*
28+
* @}
29+
*/
30+
31+
#include "cpu.h"
32+
#include "x86_ports.h"
33+
#include "x86_reboot.h"
34+
35+
#define ENABLE_DEBUG (0)
36+
#include "debug.h"
37+
38+
static bool qemu_shutdown(void)
39+
{
40+
unsigned old_state = disableIRQ();
41+
42+
DEBUG("SHUTTING DOWN.\n");
43+
44+
/* (phony) ACPI shutdown (http://forum.osdev.org/viewtopic.php?t=16990) */
45+
/* Works for qemu and bochs. */
46+
outw(0xB004, 0x2000);
47+
48+
restoreIRQ(old_state);
49+
return false;
50+
}
51+
52+
void x86_init_board(void)
53+
{
54+
x86_set_shutdown_fun(qemu_shutdown);
55+
}

boards/qemu-i386/x86_board_lpm.c

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2014 René Kijewski <rene.kijewski@fu-berlin.de>
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
/**
20+
* @ingroup x86
21+
* @{
22+
*
23+
* @file
24+
* @brief Placeholder if someone uses x86-multiboot as a board.
25+
*
26+
* @author René Kijewski <rene.kijewski@fu-berlin.de>
27+
*
28+
* @}
29+
*/
30+
31+
#include <lpm.h>
32+
33+
void lpm_init(void)
34+
{
35+
// void
36+
}
37+
38+
enum lpm_mode lpm_set(enum lpm_mode target)
39+
{
40+
if (target != LPM_ON) {
41+
asm volatile ("hlt");
42+
}
43+
return LPM_UNKNOWN;
44+
}
45+
46+
void lpm_awake(void)
47+
{
48+
// void
49+
}
50+
51+
void lpm_begin_awake(void)
52+
{
53+
// void
54+
}
55+
56+
void lpm_end_awake(void)
57+
{
58+
// void
59+
}

boards/x86-multiboot-common/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
MODULE = x86-multiboot-common_base
2+
3+
include $(RIOTBASE)/Makefile.base
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
ifeq (, $(NEWLIB_BASE))
2+
NEWLIB_BASE := $(RIOTBASE)/toolchain/x86/i586-none-elf
3+
4+
ifneq (0, $(shell test -e "$(NEWLIB_BASE)/lib/libc.a" && echo $$?))
5+
NEWLIB_PRECOMPILED_NAME := i586-newlib_2.1.0_tlsf.txz
6+
NEWLIB_PRECOMPILED := http://download.riot-os.org/$(NEWLIB_PRECOMPILED_NAME)
7+
8+
$(warning "Precompiled newlib is missing in $(NEWLIB_BASE)")
9+
$(warning "Downloading from $(NEWLIB_PRECOMPILED)")
10+
11+
$(shell cd $(RIOTBASE) && wget -qO- "$(NEWLIB_PRECOMPILED)" | tar xJ)
12+
endif
13+
endif
14+
15+
ifeq (,$(BUILD_INCLUDE_BASE))
16+
GCC_BUILD_TRIPLET ?= $(shell gcc -dumpmachine)
17+
GCC_BUILD_VERSION ?= $(shell gcc -dumpversion)
18+
BUILD_INCLUDE_BASE = /usr/lib/gcc/$(GCC_BUILD_TRIPLET)/$(GCC_BUILD_VERSION)
19+
20+
ifeq (,$(shell echo $(GCC_BUILD_TRIPLET) | sed -e 's,-.*,,' | grep -e '\(x\|i[3-7]\)86'))
21+
$(warning Your build machine is a(n) $(GCC_BUILD_TRIPLET).)
22+
$(warning Since this is not IA32 compatible, you must set BUILD_INCLUDE_BASE explicitly!)
23+
endif
24+
endif
25+
26+
export INCLUDES += -isystem $(BUILD_INCLUDE_BASE)/include \
27+
-isystem $(NEWLIB_BASE)/include \
28+
-isystem $(NEWLIB_BASE)/sys-include \
29+
-isystem $(BUILD_INCLUDE_BASE)/include-fixed \
30+
-I$(RIOTBOARD)/x86-multiboot-common/include
31+
export CPU = x86
32+
33+
# toolchain config
34+
export CC ?= $(PREFIX)gcc
35+
export AR ?= $(PREFIX)ar
36+
export AS ?= $(PREFIX)as
37+
export RANLIB ?= $(PREFIX)ranlib
38+
export LINK ?= $(RIOTBASE)/boards/x86-multiboot-common/dist/link $(PREFIX)gcc
39+
export SIZE ?= $(PREFIX)size
40+
export OBJCOPY ?= $(PREFIX)objcopy
41+
42+
export CFLAGS += -m32 -mfpmath=387 -ffreestanding -nostdlib -nostdinc -fno-builtin
43+
export OFLAGS = -O binary
44+
45+
LINKFLAGS += -m32 -nostdlib -nostdinc -nostartfiles -nodefaultlibs \
46+
--prefix=$(NEWLIB_BASE) \
47+
-Wl,-rpath,$(NEWLIB_BASE)/lib \
48+
-T $(RIOTBASE)/boards/x86-multiboot-common/linker.ld
49+
UNDEF += $(BINDIR)x86-multiboot-common_base/startup.o
50+
51+
#CFLAGS += -ffunction-sections -fdata-sections
52+
#LINKFLAGS += -Wl,--gc-sections
53+
#CFLAGS += -Wall -Wextra -Werror -pedantic -pedantic-errors \
54+
55+
BASELIBS += $(NEWLIB_BASE)/lib/libc.a \
56+
$(NEWLIB_BASE)/lib/libm.a

boards/x86-multiboot-common/dist/link

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
args=($@)
4+
5+
for ((i = 0; i < ${#args[@]}; ++i))
6+
do
7+
if [[ "${args[i]}" == '-lm' ]]
8+
then
9+
unset args[i]
10+
break
11+
fi
12+
done
13+
14+
exec "${args[@]}"

0 commit comments

Comments
 (0)