diff options
| author | wuyangyong <[email protected]> | 2012-02-16 15:49:18 +0000 |
|---|---|---|
| committer | wuyangyong <[email protected]> | 2012-02-16 15:49:18 +0000 |
| commit | 4f6f15601dad6f72dca278afe2af1451cdae29c2 (patch) | |
| tree | 3b4ae8efb8762a973d9791e1d573e99312940465 /bsp/x86 | |
| parent | 68bee363ff8c2077454bc39ac054abbb8aecb2a2 (diff) | |
rename qemu(ia32) to x86.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1949 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'bsp/x86')
| -rw-r--r-- | bsp/x86/application.c | 28 | ||||
| -rw-r--r-- | bsp/x86/board.c | 69 | ||||
| -rw-r--r-- | bsp/x86/board.h | 24 | ||||
| -rw-r--r-- | bsp/x86/build/Makefile | 59 | ||||
| -rw-r--r-- | bsp/x86/build/bsp/Makefile | 9 | ||||
| -rw-r--r-- | bsp/x86/build/bsp/qemu/Makefile | 39 | ||||
| -rwxr-xr-x | bsp/x86/build/clean-link | 18 | ||||
| -rw-r--r-- | bsp/x86/build/config.local | 38 | ||||
| -rw-r--r-- | bsp/x86/build/config.mk | 140 | ||||
| -rw-r--r-- | bsp/x86/build/config.target | 59 | ||||
| -rwxr-xr-x | bsp/x86/build/create-link | 24 | ||||
| -rw-r--r-- | bsp/x86/build/finsh/Makefile | 29 | ||||
| -rw-r--r-- | bsp/x86/build/libcpu/Makefile | 9 | ||||
| -rw-r--r-- | bsp/x86/build/libcpu/ia32/Makefile | 33 | ||||
| -rw-r--r-- | bsp/x86/build/readme | 9 | ||||
| -rw-r--r-- | bsp/x86/build/src/Makefile | 25 | ||||
| -rw-r--r-- | bsp/x86/console.c | 210 | ||||
| -rw-r--r-- | bsp/x86/keyboard.c | 138 | ||||
| -rw-r--r-- | bsp/x86/qemu_ram.lds | 41 | ||||
| -rw-r--r-- | bsp/x86/serial.c | 75 | ||||
| -rw-r--r-- | bsp/x86/startup.c | 108 |
21 files changed, 1184 insertions, 0 deletions
diff --git a/bsp/x86/application.c b/bsp/x86/application.c new file mode 100644 index 0000000000..cad1e64d97 --- /dev/null +++ b/bsp/x86/application.c @@ -0,0 +1,28 @@ +/* + * File : application.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006, RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://openlab.rt-thread.com/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2006-09-15 QiuYi the first version + */ + +/** + * @addtogroup QEMU + */ +/*@{*/ + +/** + * This function will be invoked to initalize user application when system startup. + */ +int rt_application_init() +{ + return 0; /* empty */ +} + +/*@}*/ diff --git a/bsp/x86/board.c b/bsp/x86/board.c new file mode 100644 index 0000000000..c537b507be --- /dev/null +++ b/bsp/x86/board.c @@ -0,0 +1,69 @@ +/* + * File : board.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.fayfayspace.org/license/LICENSE. + * + * Change Logs: + * Date Author Notes + * 2006-09-15 QiuYi the first version + * 2006-10-10 Bernard add hardware related of finsh + */ + +#include <rtthread.h> +#include <rthw.h> + +#include <bsp.h> + +/** + * @addtogroup QEMU + */ +/*@{*/ + +static void rt_timer_handler(int vector) +{ + rt_tick_increase(); +} + +/** + * This function will init QEMU + * + */ +void rt_hw_board_init(void) +{ + /* initialize 8253 clock to interrupt 100 times/sec */ + outb(TIMER_MODE, TIMER_SEL0|TIMER_RATEGEN|TIMER_16BIT); + outb(IO_TIMER1, TIMER_DIV(100) % 256); + outb(IO_TIMER1, TIMER_DIV(100) / 256); + + /* install interrupt handler */ + rt_hw_interrupt_install(INTTIMER0, rt_timer_handler, RT_NULL); + rt_hw_interrupt_umask(INTTIMER0); +} + +#ifdef RT_USING_FINSH +extern void finsh_notify(void); +static void rt_serial_isr(int vector) +{ + finsh_notify(); +} + +/** + * This function will init hardware related in finsh shell + */ +void rt_hw_finsh_init() +{ + /* install UART isr */ + rt_hw_interrupt_install(INTUART0_RX, rt_serial_isr, RT_NULL); + rt_hw_interrupt_umask(INTUART0_RX); + + /* install keyboard isr */ + rt_hw_interrupt_install(INTKEYBOARD, rt_serial_isr, RT_NULL); + rt_hw_interrupt_umask(INTKEYBOARD); +} +#endif + +/*@}*/ diff --git a/bsp/x86/board.h b/bsp/x86/board.h new file mode 100644 index 0000000000..c7f4583157 --- /dev/null +++ b/bsp/x86/board.h @@ -0,0 +1,24 @@ +/* + * File : board.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006, RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://openlab.rt-thread.com/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2006-10-09 Bernard first version + */
+ +#ifndef __BOARD_H__
+#define __BOARD_H__
+
+void rt_hw_board_init(void); + +#ifdef RT_USING_FINSH +void rt_hw_finsh_init(void); +#endif + +#endif
diff --git a/bsp/x86/build/Makefile b/bsp/x86/build/Makefile new file mode 100644 index 0000000000..a5cc611799 --- /dev/null +++ b/bsp/x86/build/Makefile @@ -0,0 +1,59 @@ +KERNEL_ROOT=. + +include $(KERNEL_ROOT)/config.mk + +SRC_DIR = src libcpu +MAKE_CMD= + +ifeq ($(RT_USING_FINSH), 1) +SRC_DIR += finsh +MAKE_CMD+= RT_USING_FINSH=1 +endif + +ifeq ($(RT_USING_LWIP), 1) +SRC_DIR += net +MAKE_CMD+= RT_USING_LWIP=1 +endif + +ifeq ($(RT_USING_EFSL), 1) +SRC_DIR += filesystem +MAKE_CMD+= RT_USING_EFSL=1 +endif + +ifeq ($(RT_USING_RTGUI), 1) +SRC_DIR += rtgui +MAKE_CMD+= RT_USING_RTGUI=1 +endif + +ifeq ($(RT_USING_CPLUSPLUS), 1) +SRC_DIR += cplusplus +endif + +ifeq ($(RT_USING_NEWLIB), 1) +SRC_DIR += libc +else +ifeq ($(RT_USING_MINILIBC), 1) +SRC_DIR += libc +endif +endif + +SRC_DIR += bsp + +all: + for dir in $(SRC_DIR); do \ + make -C $$dir $(MAKE_CMD); \ + done + +clean : + for dir in $(SRC_DIR); do \ + make -C $$dir clean $(MAKE_CMD); \ + done + +test: + make -C testsuite + +docs: + $(DOXYGEN) Doxyfile + +dist-clean: clean + make -C testsuite clean diff --git a/bsp/x86/build/bsp/Makefile b/bsp/x86/build/bsp/Makefile new file mode 100644 index 0000000000..20099682bc --- /dev/null +++ b/bsp/x86/build/bsp/Makefile @@ -0,0 +1,9 @@ +KERNEL_ROOT=.. + +include $(KERNEL_ROOT)/config.mk + +all: + make -C $(BOARD) + +clean: + make -C $(BOARD) clean
\ No newline at end of file diff --git a/bsp/x86/build/bsp/qemu/Makefile b/bsp/x86/build/bsp/qemu/Makefile new file mode 100644 index 0000000000..346c319157 --- /dev/null +++ b/bsp/x86/build/bsp/qemu/Makefile @@ -0,0 +1,39 @@ +KERNEL_ROOT=../.. + +include $(KERNEL_ROOT)/config.mk + +SRC = board.c startup.c keyboard.c console.c serial.c +APP = application.o +OBJ = $(SRC:.c=.o) +BIN = rtthread-$(BOARD) +IMG = $(KERNEL_ROOT)/lib/$(BIN).img + +#LFALGS = -nostdlib -Bstatic -T $(LDSCRIPT) -Ttext $(TEXTBASE) +LFALGS = -nostdlib -Bstatic -T $(LDSCRIPT) +CFLAGS += -I$(KERNEL_ROOT)/libcpu/$(ARCH)/include + +all: $(BIN) $(LIBBSP) + +$(IMG): $(BIN) $(KERNEL_ROOT)/lib/boot + dd if=/dev/zero of=$(IMG)~ count=1000 2>/dev/null + dd if=$(KERNEL_ROOT)/lib/boot of=$(IMG)~ conv=notrunc 2>/dev/null + dd if=$(BIN) of=$(IMG)~ seek=1 conv=notrunc 2>/dev/null + +$(LIBBSP): $(OBJ) + $(AR) r $@ $? + $(RANLIB) $@ + +$(BIN): $(OBJ) $(APP) $(LIBFINSH) $(LIBCPU) $(KERNEL) + $(LD) $(LFALGS) $(STARTOBJ) $(OBJ) $(APP) $(LIBFINSH) $(KERNEL) $(LIBCPU) -o $(BIN).elf + $(SIZE) $(BIN).elf + +clean : + $(RM) $(BIN).elf *.o *~ *.bak *.bin $(LIBBSP) + $(RM) .depend + +dep : .depend + +include .depend + +.depend: $(SRC) + $(CC) $(CFLAGS) -M $^ > $@ diff --git a/bsp/x86/build/clean-link b/bsp/x86/build/clean-link new file mode 100755 index 0000000000..33d5058788 --- /dev/null +++ b/bsp/x86/build/clean-link @@ -0,0 +1,18 @@ +#!/bin/bash +rm lib -rf +rm include -f +rm src/*.c -f +rm src/*.h -f +rm src/*.o -f +rm bsp/qemu/*.c -f +rm bsp/qemu/*.h -f +rm bsp/qemu/*.S -f +rm bsp/qemu/*.o -f +rm bsp/qemu/*.lds -f +rm libcpu/ia32/*.c -f +rm libcpu/ia32/*.S -f +rm libcpu/ia32/*.o -f +rm libcpu/ia32/include -f +rm finsh/*.c -f +rm finsh/*.h -f +rm finsh/*.o -f diff --git a/bsp/x86/build/config.local b/bsp/x86/build/config.local new file mode 100644 index 0000000000..74004109c1 --- /dev/null +++ b/bsp/x86/build/config.local @@ -0,0 +1,38 @@ +# RT-Thread build config file +# Platform +PLATFORM=qemu + +# Platform Prefix +PREFIX= + +# C flags +CFLAGS=-Wall + +# Linker flags +LDFLAGS=-nostdlib + +# ASM Flags +ASFLAGS= + +# Build Type +BUILDTYPE=RAM + +# Release Type +RELEASETYPE=Release + +# Text Base +TEXTBASE=0x108000 + +# SECTION: RT-Thread Component +# finsh, shell of RT-Thread +RT_USING_FINSH=1 + +# a mini libc +#RT_USING_MINILIBC=1 + +# Using C++ support +# RT_USING_CPLUSPLUS=1 + +# LwIP, light weight TCP/IP stack for RT-Thread +# RT_USING_LWIP=1 + diff --git a/bsp/x86/build/config.mk b/bsp/x86/build/config.mk new file mode 100644 index 0000000000..6a3adc5d93 --- /dev/null +++ b/bsp/x86/build/config.mk @@ -0,0 +1,140 @@ +# +# RT-Thread Makefile +# CFLAGS for C compiler flags +# CPPFLAGS for C++ compiler flags +# LDFLAGS for ld link flags +# LDLIBS for libraries should be linked +# AFLAGS for assemble flags +# + +include $(KERNEL_ROOT)/config.local +include $(KERNEL_ROOT)/config.target + +# +# toolchain variables +# +CC = $(PREFIX)gcc +CXX = $(PREFIX)g++ +LD = $(PREFIX)ld +AR = $(PREFIX)ar +AS = $(PREFIX)as +RANLIB = $(PREFIX)ranlib +NM = $(PREFIX)nm +OBJCOPY = $(PREFIX)objcopy +OBJDUMP = $(PREFIX)objdump +STRIP = $(PREFIX)strip +SIZE = $(PREFIX)size +RM = rm -rf +MKDIR = mkdir -p + +# +# start object and library +# +STARTOBJ = $(KERNEL_ROOT)/lib/start_$(CPU).o +LIBCPU = $(KERNEL_ROOT)/lib/libcpu_$(CPU).a +KERNEL = $(KERNEL_ROOT)/lib/libkernel_$(ARCH).a +LIBBSP = $(KERNEL_ROOT)/lib/libbsp_$(BOARD).a +LIBFINSH = $(KERNEL_ROOT)/lib/libfinsh_$(ARCH).a +LIBEFSL = $(KERNEL_ROOT)/lib/libefsl-fs-vfat.a \ + $(KERNEL_ROOT)/lib/libefsl-base.a +LIBRTGUI = $(KERNEL_ROOT)/lib/librtgui_widgets.a \ + $(KERNEL_ROOT)/lib/librtgui_server.a \ + $(KERNEL_ROOT)/lib/librtgui_common.a \ + $(KERNEL_ROOT)/lib/librtgui_app.a +LIBLWIP = $(KERNEL_ROOT)/lib/liblwip_$(ARCH).a +LIBCPP = $(KERNEL_ROOT)/lib/librtt++_$(ARCH).a +LIBMINIC = $(KERNEL_ROOT)/lib/libminilibc_$(ARCH).a + +LDLIBS = -lcpu_$(CPU) -lkernel_$(ARCH) -lbsp_$(BOARD) + +# +# ld script, according to build type, RAM or ROM +# +ifeq ($(BUILDTYPE), RAM) +LDSCRIPT= $(KERNEL_ROOT)/bsp/$(BOARD)/$(BOARD)_ram.lds +else +LDSCRIPT= $(KERNEL_ROOT)/bsp/$(BOARD)/$(BOARD)_rom.lds +endif + +# +# RT-Thread component +# +ifeq ($(RT_USING_FINSH), 1) +CFLAGS += -I$(KERNEL_ROOT)/finsh +LDLIBS += -lfinsh_$(ARCH) +endif + +ifeq ($(RT_USING_RTGUI), 1) +CFLAGS += -I$(KERNEL_ROOT)/rtgui/include +LDLIBS += -lrtgui_server -lrtgui_common -lrtgui_widgets -lrtgui_app +endif + +ifeq ($(RT_USING_LWIP), 1) +CFLAGS += -I$(KERNEL_ROOT)/net/lwip/src \ + -I$(KERNEL_ROOT)/net/lwip/src/include \ + -I$(KERNEL_ROOT)/net/lwip/src/include/ipv4 \ + -I$(KERNEL_ROOT)/net/lwip/src/arch/include +LDLIBS += -llwip_$(ARCH) +endif + +ifeq ($(RT_USING_EFSL), 1) +CFLAGS += -I$(KERNEL_ROOT)/filesystem/efsl/src/fs/vfat/include \ + -I$(KERNEL_ROOT)/filesystem/efsl/src/base/include \ + -I$(KERNEL_ROOT)/filesystem/efsl/src/include \ + -I$(KERNEL_ROOT)/filesystem/efsl/conf +LDLIBS += -lefsl-base -lefsl-fs-vfat +endif + +ifeq ($(RT_USING_CPLUSPLUS), 1) +CFLAGS += +LDLIBS += -lrtt++_$(ARCH) +endif + +ifeq ($(RT_USING_NEWLIB), 1) +CFLAGS += -I$(KERNEL_ROOT)/newlib/libc/include +LDLIBS += -lnewlib_$(ARCH) +else +ifeq ($(RT_USING_MINILIBC), 1) +CFLAGS += -I$(KERNEL_ROOT)/libc/minilibc +LDLIBS += -lminilibc_$(ARCH) +endif +endif + +# +# compiler, assemble and ld link flag +# +CFLAGS += -I$(KERNEL_ROOT)/include -I$(KERNEL_ROOT)/bsp/$(BOARD) -Wall -nostdinc -fno-builtin + +ifeq ($(RELEASETYPE), DEBUG) +CFLAGS += -ggdb +AFLAGS += -ggdb +else +CFLAGS += -O2 +CFLAGS += +AFLAGS += +endif + +ifeq ($(BUILDTYPE), RAM) +#AFLAGS += +#AFLAGS += -x assembler-with-cpp -DTEXT_BASE=$(TEXTBASE) +#AFLAGS += -x assembler-with-cpp +else +#AFLAGS += +#AFLAGS += -x assembler-with-cpp -DTEXT_BASE=$(TEXTBASE) -D__FLASH_BUILD__ +endif + +LDFLAGS += -L$(KERNEL_ROOT)/lib --start-group $(LDLIBS) --end-group + +CPPFLAGS = $(CFLAGS) -fno-rtti + +# +# Common rules +# +.c.o: + $(CC) -c $(CFLAGS) -o $@ $< + +.cpp.o: + $(CXX) -c $(CPPFLAGS) -o $@ $< + +.S.o: + $(CC) -c $(AFLAGS) -o $@ $< diff --git a/bsp/x86/build/config.target b/bsp/x86/build/config.target new file mode 100644 index 0000000000..872a4a9c1e --- /dev/null +++ b/bsp/x86/build/config.target @@ -0,0 +1,59 @@ +ifeq ($(PLATFORM), lumit4510) +ARCH = arm +CPU = s3c4510 +BOARD = lumit4510 +endif + +ifeq ($(PLATFORM), wh44b0) +ARCH = arm +CPU = s3c44b0 +BOARD = wh44b0 +endif + +ifeq ($(PLATFORM), s3ceb2410) +ARCH = arm +CPU = s3c2410 +BOARD = s3ceb2410 +endif + +ifeq ($(PLATFORM), sam7s) +ARCH = arm +CPU = AT91SAM7S +BOARD = sam7s +endif + +ifeq ($(PLATFORM), sam7x) +ARCH = arm +CPU = AT91SAM7X +BOARD = sam7x +endif + +ifeq ($(PLATFORM), zaurusc1k) +ARCH = arm +CPU = pxa270 +BOARD = zaurusc1k +endif + +ifeq ($(PLATFORM), qemu_akita) +ARCH = arm +CPU = pxa270 +BOARD = qemu_akita +endif + +ifeq ($(PLATFORM), nds) +ARCH = arm +CPU = nds +BOARD = nds +endif + +ifeq ($(PLATFORM), qemu) +ARCH = ia32 +CPU = ia32 +BOARD = qemu +endif + +ifeq ($(PLATFORM), at9200) +ARCH = arm +CPU = AT9200 +BOARD = AT9200 +endif diff --git a/bsp/x86/build/create-link b/bsp/x86/build/create-link new file mode 100755 index 0000000000..6131198931 --- /dev/null +++ b/bsp/x86/build/create-link @@ -0,0 +1,24 @@ +#!/bin/bash +mkdir lib +ln -s ../../../include include + +for m_file in `ls ../../../src` +do + ln -s ../../../../src/$m_file src/$m_file +done + +for m_file in `ls ../` +do + ln -s ../../../$m_file bsp/qemu/$m_file +done +rm bsp/qemu/build -f + +for m_file in `ls ../../../libcpu/ia32` +do + ln -s ../../../../../libcpu/ia32/$m_file libcpu/ia32/$m_file +done + +for m_file in `ls ../../../finsh` +do + ln -s ../../../../finsh/$m_file finsh/$m_file +done diff --git a/bsp/x86/build/finsh/Makefile b/bsp/x86/build/finsh/Makefile new file mode 100644 index 0000000000..5b56504fae --- /dev/null +++ b/bsp/x86/build/finsh/Makefile @@ -0,0 +1,29 @@ +KERNEL_ROOT=.. + +include $(KERNEL_ROOT)/config.mk + +SRC = cmd.c shell.c symbol.c finsh_error.c finsh_node.c finsh_token.c \ + finsh_heap.c finsh_ops.c finsh_var.c finsh_compiler.c finsh_init.c\ + finsh_parser.c finsh_vm.c +OBJ = $(SRC:.c=.o) + +CFLAGS += -I. + + +all: $(LIBFINSH) + +$(LIBFINSH): $(OBJ) + $(AR) -r $@ $? + $(RANLIB) $@ + +clean : + $(RM) *.o *~ *.bak + $(RM) $(LIBFINSH) + $(RM) .depend + +dep : .depend + +include .depend + +.depend: $(SRC) + $(CC) $(CFLAGS) -M $^ > $@ diff --git a/bsp/x86/build/libcpu/Makefile b/bsp/x86/build/libcpu/Makefile new file mode 100644 index 0000000000..a3a541ce74 --- /dev/null +++ b/bsp/x86/build/libcpu/Makefile @@ -0,0 +1,9 @@ +KERNEL_ROOT=.. + +include $(KERNEL_ROOT)/config.mk + +all: + make -C $(ARCH) + +clean: + make -C $(ARCH) clean diff --git a/bsp/x86/build/libcpu/ia32/Makefile b/bsp/x86/build/libcpu/ia32/Makefile new file mode 100644 index 0000000000..90becda7d5 --- /dev/null +++ b/bsp/x86/build/libcpu/ia32/Makefile @@ -0,0 +1,33 @@ +KERNEL_ROOT=../.. + +include $(KERNEL_ROOT)/config.mk + +SRC = interrupt.c trap.c stack.c backtrace.c showmem.c __udivsi3.c __umodsi3.c +CPU_OBJ = $(SRC:.c=.o) context.o trapisr.o hdisr.o + +#AFLAGS += -DTEXT_BASE=$(TEXTBASE) -I$(KERNEL_ROOT)/libcpu/$(ARCH)/include +AFLAGS += -I$(KERNEL_ROOT)/libcpu/$(ARCH)/include +CFLAGS += -I$(KERNEL_ROOT)/libcpu/$(ARCH)/include + +all: $(LIBCPU) $(STARTOBJ) + +$(STARTOBJ): start.S +# $(CC) $(AFLAGS) -c start.S -ggdb -o $(STARTOBJ) + $(CC) $(AFLAGS) -c start.S -o $(STARTOBJ) + +$(LIBCPU): $(CPU_OBJ) + $(AR) r $(LIBCPU) $? + $(RANLIB) $(LIBCPU) + +clean : + $(RM) *.o *~ *.bak + $(RM) $(LIBCPU) + $(RM) $(STARTOBJ) + $(RM) .depend + +dep : .depend + +include .depend + +.depend: $(SRC) + $(CC) $(CFLAGS) -M $^ > $@ diff --git a/bsp/x86/build/readme b/bsp/x86/build/readme new file mode 100644 index 0000000000..b42b885f2e --- /dev/null +++ b/bsp/x86/build/readme @@ -0,0 +1,9 @@ +./create-link +make +cp bsp/qemu/rtthread-qemu.elf $dest + + + +test OK ON: + Fedora 10 + Fedora 11 diff --git a/bsp/x86/build/src/Makefile b/bsp/x86/build/src/Makefile new file mode 100644 index 0000000000..ad51ea4608 --- /dev/null +++ b/bsp/x86/build/src/Makefile @@ -0,0 +1,25 @@ +KERNEL_ROOT=.. + +include $(KERNEL_ROOT)/config.mk + +SRC = kservice.c clock.c object.c ipc.c timer.c irq.c scheduler.c \ + thread.c idle.c mempool.c mem.c slab.c device.c +OBJ = $(SRC:.c=.o) + +all: $(KERNEL) + +$(KERNEL): $(OBJ) + $(AR) r $@ $? + $(RANLIB) $@ + +clean : + $(RM) *.o *~ *.bak + $(RM) $(KERNEL) + $(RM) .depend + +dep : .depend + +include .depend + +.depend: $(SRC) + $(CC) $(CFLAGS) -M $^ > $@ diff --git a/bsp/x86/console.c b/bsp/x86/console.c new file mode 100644 index 0000000000..75418acd9d --- /dev/null +++ b/bsp/x86/console.c @@ -0,0 +1,210 @@ +/* + * File : console.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://openlab.rt-thread.com/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2006-09-15 QiuYi the first version + */ + +#include <rtthread.h> +#include <rthw.h> + +#include <bsp.h> + + +#include "serial.h" + +static unsigned addr_6845; +static rt_uint16_t *crt_buf; +static rt_int16_t crt_pos; + +extern void rt_serial_init(void); +extern char rt_keyboard_getc(void); + +static void rt_console_putc(int c); + +/** + * @addtogroup QEMU + */ +/*@{*/ + +/** + * This function initializes cga + * + */ +void rt_cga_init(void) +{ + rt_uint16_t volatile *cp; + rt_uint16_t was; + rt_uint32_t pos; + + cp = (rt_uint16_t *) (CGA_BUF); + was = *cp; + *cp = (rt_uint16_t) 0xA55A; + if (*cp != 0xA55A) + { + cp = (rt_uint16_t *) (MONO_BUF); + addr_6845 = MONO_BASE; + } + else + { + *cp = was; + addr_6845 = CGA_BASE; + } + + /* Extract cursor location */ + outb(addr_6845, 14); + pos = inb(addr_6845+1) << 8; + outb(addr_6845, 15); + pos |= inb(addr_6845+1); + + crt_buf = (rt_uint16_t *)cp; + crt_pos = pos; +} + +/** + * This function will write a character to cga + * + * @param c the char to write + */ +static void rt_cga_putc(int c) +{ + /* if no attribute given, then use black on white */ + if (!(c & ~0xff)) c |= 0x0700; + + switch (c & 0xff) + { + case '\b': + if (crt_pos > 0) + { + crt_pos--; + crt_buf[crt_pos] = (c&~0xff) | ' '; + } + break; + case '\n': + crt_pos += CRT_COLS; + /* cascade */ + case '\r': + crt_pos -= (crt_pos % CRT_COLS); + break; + case '\t': + rt_console_putc(' '); + rt_console_putc(' '); + rt_console_putc(' '); + rt_console_putc(' '); + rt_console_putc(' '); + break; + default: + crt_buf[crt_pos++] = c; /* write the character */ + break; + } + + if (crt_pos >= CRT_SIZE) + { + rt_int32_t i; + rt_memcpy(crt_buf, crt_buf + CRT_COLS, (CRT_SIZE - CRT_COLS) << 1); + for (i = CRT_SIZE - CRT_COLS; i < CRT_SIZE; i++) + crt_buf[i] = 0x0700 | ' '; + crt_pos -= CRT_COLS; + } + + outb(addr_6845, 14); + outb(addr_6845+1, crt_pos >> 8); + outb(addr_6845, 15); + outb(addr_6845+1, crt_pos); +} + +/** + * This function will write a character to serial an cga + * + * @param c the char to write + */ +static void rt_console_putc(int c) +{ + rt_cga_putc(c); + rt_serial_putc(c); +} + +/** + * This function initializes console + * + */ +void rt_console_init(void) +{ + rt_cga_init(); + rt_serial_init(); +} + +/** + * This function is used to display a string on console, normally, it's + * invoked by rt_kprintf + * + * @param str the displayed string + * + * Modified: + * caoxl 2009-10-14 + * the name is change to rt_hw_console_output in the v0.3.0 + * + */ + +//void rt_console_puts(const char* str) +void rt_hw_console_output(const char* str) +{ + while (*str) + { + rt_console_putc (*str++); + } +} + +#define BY2CONS 512 + +static struct +{ + rt_uint8_t buf[BY2CONS]; + rt_uint32_t rpos; + rt_uint32_t wpos; +}cons; + +static void rt_console_intr(char (*proc)(void)) +{ + int c; + + while ((c = (*proc)()) != -1) + { + if (c == 0) + continue; + cons.buf[cons.wpos++] = c; + if (cons.wpos == BY2CONS) + cons.wpos = 0; + } +} + +/** + * return the next input character from the console,either from serial, + * or keyboard + * + */ +int rt_console_getc(void) +{ + int c; + + rt_console_intr(rt_serial_getc); + rt_console_intr(rt_keyboard_getc); + + if (cons.rpos != cons.wpos) + { + c = cons.buf[cons.rpos++]; + if (cons.rpos == BY2CONS) + cons.rpos = 0; + return c; + } + return 0; +} + +/*@}*/ diff --git a/bsp/x86/keyboard.c b/bsp/x86/keyboard.c new file mode 100644 index 0000000000..5bf3de3906 --- /dev/null +++ b/bsp/x86/keyboard.c @@ -0,0 +1,138 @@ +/*
+ * File : keyboard.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://openlab.rt-thread.com/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2006-09-15 QiuYi the first version + */
+
+#include <rtthread.h>
+#include <rthw.h>
+
+#include <bsp.h>
+
+#define NO 0
+
+#define SHIFT (1 << 0)
+#define CTL (1 << 1)
+#define ALT (1 << 2)
+
+#define CAPSLOCK (1<<3)
+#define NUMLOCK (1<<4)
+#define SCROLLOCK (1<<5)
+
+static int shiftcode[256] =
+{
+ [29] CTL,
+ [42] SHIFT,
+ [54] SHIFT,
+ [56] ALT,
+};
+
+static int togglecode[256] =
+{
+ [58] CAPSLOCK,
+ [69] NUMLOCK,
+ [70] SCROLLOCK,
+};
+
+static char normalmap[256] =
+{
+ NO, 033, '1', '2', '3', '4', '5', '6',
+ '7', '8', '9', '0', '-', '=', '\b', '\t',
+ 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
+ 'o', 'p', '[', ']', '\n', NO, 'a', 's',
+ 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
+ '\'', '`', NO, '\\', 'z', 'x', 'c', 'v',
+ 'b', 'n', 'm', ',', '.', '/', NO, '*',
+ NO, ' ', NO, NO, NO, NO, NO, NO,
+ NO, NO, NO, NO, NO, NO, NO, '7',
+ '8', '9', '-', '4', '5', '6', '+', '1',
+ '2', '3', '0', '.',
+};
+
+static char shiftmap[256] =
+{
+ NO, 033, '!', '@', '#', '$', '%', '^',
+ '&', '*', '(', ')', '_', '+', '\b', '\t',
+ 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
+ 'O', 'P', '{', '}', '\n', NO, 'A', 'S',
+ 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';',
+ '"', '~', NO, '|', 'Z', 'X', 'C', 'V',
+ 'B', 'N', 'M', '<', '>', '?', NO, '*',
+ NO, ' ', NO, NO, NO, NO, NO, NO,
+ NO, NO, NO, NO, NO, NO, NO, '7',
+ '8', '9', '-', '4', '5', '6', '+', '1',
+ '2', '3', '0', '.',
+};
+
+#define C(x) (x-'@')
+
+static char ctlmap[256] =
+{
+ NO, NO, NO, NO, NO, NO, NO, NO,
+ NO, NO, NO, NO, NO, NO, NO, NO,
+ C('Q'), C('W'), C('E'), C('R'), C('T'), C('Y'), C('U'), C('I'),
+ C('O'), C('P'), NO, NO, '\r', NO, C('A'), C('S'),
+ C('D'), C('F'), C('G'), C('H'), C('J'), C('K'), C('L'), NO,
+ NO, NO, NO, C('\\'), C('Z'), C('X'), C('C'), C('V'),
+ C('B'), C('N'), C('M'), NO, NO, C('/'), NO, NO,
+};
+
+static char *charcode[4] =
+{
+ normalmap,
+ shiftmap,
+ ctlmap,
+ ctlmap,
+};
+
+/**
+ * @addtogroup QEMU
+ */
+/*@{*/
+
+/**
+ * This function get a char from the keyboard
+ */
+char rt_keyboard_getc(void)
+{
+ int c;
+ rt_uint8_t data;
+ static rt_uint32_t shift;
+
+ if ((inb(KBSTATP) & KBS_DIB) == 0)
+ return -1;
+
+ data = inb(KBDATAP);
+
+ if (data & 0x80)
+ {
+ /* key up */
+ shift &= ~shiftcode[data&~0x80];
+ return 0;
+ }
+
+ /* key down */
+ shift |= shiftcode[data];
+ shift ^= togglecode[data];
+ c = charcode[shift&(CTL|SHIFT)][data];
+
+ if (shift&CAPSLOCK)
+ {
+ if ('a' <= c && c <= 'z')
+ c += 'A' - 'a';
+ else if ('A' <= c && c <= 'Z')
+ c += 'a' - 'A';
+ }
+
+ return c;
+}
+
+/*@}*/
diff --git a/bsp/x86/qemu_ram.lds b/bsp/x86/qemu_ram.lds new file mode 100644 index 0000000000..8964405875 --- /dev/null +++ b/bsp/x86/qemu_ram.lds @@ -0,0 +1,41 @@ +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") +OUTPUT_ARCH(i386) +ENTRY(_start) +SECTIONS +{ + . = 0x00100000; + + . = ALIGN(4); + .text : + { + *(.init) + *(.text) + } + + . = ALIGN(4); + .rodata : { *(.rodata) } + + . = ALIGN(4); + .data : { *(.data) } + + . = ALIGN(4); + __bss_start = .; + .bss : { *(.bss) } + __bss_end = .; + + /* stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_info 0 : { *(.debug_info) } + .debug_line 0 : { *(.debug_line) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_aranges 0 : { *(.debug_aranges) } + + _end = .; +} diff --git a/bsp/x86/serial.c b/bsp/x86/serial.c new file mode 100644 index 0000000000..f2484417e2 --- /dev/null +++ b/bsp/x86/serial.c @@ -0,0 +1,75 @@ +/*
+ * File : serial.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2006, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://openlab.rt-thread.com/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2006-09-15 QiuYi the first version
+ * 2006-10-10 Bernard use keyboard instead of serial + */
+
+#include <rtthread.h>
+#include <rthw.h>
+
+#include <bsp.h>
+extern char rt_keyboard_getc(void); +
+/**
+ * @addtogroup QEMU
+ */
+/*@{*/
+
+/**
+ * This function initializes serial
+ */
+void rt_serial_init(void)
+{
+ outb(COM1+3,0x80); /* set DLAB of line control reg */
+ outb(COM1,0x0c); /* LS of divisor (48 -> 2400 bps */
+ outb(COM1+1,0x00); /* MS of divisor */
+ outb(COM1+3,0x03); /* reset DLAB */
+ outb(COM1+4,0x0b); /* set DTR,RTS, OUT_2 */
+ outb(COM1+1,0x0d); /* enable all intrs but writes */
+ inb(COM1); /* read data port to reset things (?) */
+}
+
+/**
+ * This function read a character from serial without interrupt enable mode
+ *
+ * @return the read char
+ */
+char rt_serial_getc(void)
+{
+ return rt_keyboard_getc();
+
+#if 0
+ while(!(inb(COM1+COMSTATUS) & COMDATA));
+
+ return inb(COM1+COMREAD);
+#endif
+}
+
+/**
+ * This function will write a character to serial without interrupt enable mode
+ *
+ * @param c the char to write
+ */
+void rt_serial_putc(const char c)
+{
+ int val;
+
+ while(1)
+ {
+ if ((val = inb(COM1+COMSTATUS)) & THRE)
+ break;
+ }
+
+ outb(COM1+COMWRITE, c&0xff);
+}
+
+/*@}*/
diff --git a/bsp/x86/startup.c b/bsp/x86/startup.c new file mode 100644 index 0000000000..4841da83f1 --- /dev/null +++ b/bsp/x86/startup.c @@ -0,0 +1,108 @@ +/* + * File : startup.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006, RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.fayfayspace.org/license/LICENSE. + * + * Change Logs: + * Date Author Notes + * 2006-09-15 QiuYi the first version + * 2006-10-10 Bernard update to 0.2.2 version + */ + +#include <rtthread.h> +#include <rthw.h> + +#include "board.h" + +extern void rt_console_init(void); +extern void rt_hw_interrupt_init(void); +extern void rt_hw_board_init(void); +extern void rt_system_timer_init(void); +extern void rt_system_scheduler_init(void); +extern void rt_thread_idle_init(void); + +extern unsigned char __bss_start[]; +extern unsigned char __bss_end[]; + +/** + * @addtogroup QEMU + */ + /*@{*/ + +/* clear .bss */ +void rt_hw_clear_bss() +{ + unsigned char *dst; + dst = __bss_start; + while(dst < __bss_end) *dst++ = 0; +} + +extern void finsh_system_init(void); +extern int rt_application_init(void); + +/** + * This function will startup RT-Thread RTOS + */ +void rtthread_startup() +{ + /* clear .bss */ + rt_hw_clear_bss(); + + /* init hardware interrupt */ + rt_hw_interrupt_init(); + + /* init the console */ + rt_console_init(); + + /* init board */ + rt_hw_board_init(); + + rt_show_version(); + + /* init tick */ + rt_system_tick_init(); + + /* init kernel object */ + rt_system_object_init(); + + /* init timer system */ + rt_system_timer_init(); + + /* init memory system */ +#ifdef RT_USING_HEAP + //rt_system_heap_init(); +#endif + + /* init scheduler system */ + rt_system_scheduler_init(); + + /* init application */ + rt_application_init(); + + /* init the finsh input */ + rt_hw_finsh_init(); + + /* init finsh */ + finsh_system_init(); + +#ifdef RT_USING_HOOK + /* set idle thread hook */ + rt_thread_idle_sethook(RT_NULL); +#endif + + /* init idle thread */ + rt_thread_idle_init(); + + /* start scheduler */ + rt_system_scheduler_start(); + + /* never reach here */ + return ; + +} + +/*@}*/ |
