Compare commits

..

No commits in common. "qemu_debug" and "master" have entirely different histories.

6 changed files with 52 additions and 96 deletions

View file

@ -1,12 +1,8 @@
NAME = metalsvm
# For 64bit support, you have define BIT as 64
# Note: do not forget to 'make veryclean' after changing BIT!!!
BIT=64
ARCH = x86
SMP=1
TOPDIR = $(shell pwd) TOPDIR = $(shell pwd)
ARCH = x86
# For 64bit support, you have define BIT as 64
BIT=32
NAME = metalsvm
LWIPDIRS = lwip/src/arch lwip/src/api lwip/src/core lwip/src/core/ipv4 lwip/src/netif LWIPDIRS = lwip/src/arch lwip/src/api lwip/src/core lwip/src/core/ipv4 lwip/src/netif
DRIVERDIRS = drivers/net drivers/char DRIVERDIRS = drivers/net drivers/char
KERNDIRS = libkern kernel mm fs apps arch/$(ARCH)/kernel arch/$(ARCH)/mm arch/$(ARCH)/scc $(LWIPDIRS) $(DRIVERDIRS) KERNDIRS = libkern kernel mm fs apps arch/$(ARCH)/kernel arch/$(ARCH)/mm arch/$(ARCH)/scc $(LWIPDIRS) $(DRIVERDIRS)
@ -34,56 +30,35 @@ RANLIB_FOR_TARGET = $(CROSSCOMPREFIX)ranlib
STRIP_FOR_TARGET = $(CROSSCOMPREFIX)strip STRIP_FOR_TARGET = $(CROSSCOMPREFIX)strip
READELF_FOR_TARGET = $(CROSSCOMPREFIX)readelf READELF_FOR_TARGET = $(CROSSCOMPREFIX)readelf
# Tools
MAKE = make MAKE = make
RM = rm -rf RM = rm -rf
NASM = nasm NASM = nasm
# For 64bit code, you have to use qemu-system-x86_64
QEMU = qemu-system-i386
GDB = gdb GDB = gdb
ifeq ($(BIT), 32) # For 64bit support, you have to define -felf64 instead of -felf32
QEMU = qemu-system-i386 NASMFLAGS = -felf32 -g -i$(TOPDIR)/include/metalsvm/
else ifeq ($(BIT), 64) INCLUDE = -I$(TOPDIR)/include -I$(TOPDIR)/arch/$(ARCH)/include -I$(TOPDIR)/lwip/src/include -I$(TOPDIR)/lwip/src/include/ipv4 -I$(TOPDIR)/drivers
QEMU = qemu-system-x86_64 # For 64bit support, you have to define "-m64 -mno-red-zone" instead of "-m32 -march=i586"
endif
INCLUDE = -I$(TOPDIR)/include \
-I$(TOPDIR)/arch/$(ARCH)/include \
-I$(TOPDIR)/lwip/src/include \
-I$(TOPDIR)/lwip/src/include/ipv4 \
-I$(TOPDIR)/drivers
# Compiler options for final code # Compiler options for final code
CFLAGS = -g -O2 -m$(BIT) -Wall -fomit-frame-pointer -ffreestanding -fstrength-reduce -finline-functions $(INCLUDE) $(STACKPROT) CFLAGS = -g -m32 -march=i586 -Wall -O2 -fstrength-reduce -fomit-frame-pointer -finline-functions -ffreestanding $(INCLUDE) $(STACKPROT)
# Compiler options for debuging # Compiler options for debuging
#CFLAGS = -g -O -m$(BIT) -Wall -fomit-frame-pointer -ffreestanding $(INCLUDE) $(STACKPROT) #CFLAGS = -g -O -m32 -march=i586 -Wall -fomit-frame-pointer -ffreestanding $(INCLUDE) $(STACKPROT)
NASMFLAGS = -felf$(BIT) -g -i$(TOPDIR)/include/metalsvm/
ARFLAGS = rsv ARFLAGS = rsv
LDFLAGS = -T link$(BIT).ld -z max-page-size=4096 --defsym __BUILD_DATE=$(shell date +'%Y%m%d') --defsym __BUILD_TIME=$(shell date +'%H%M%S') LDFLAGS = -T link$(BIT).ld -z max-page-size=4096 --defsym __BUILD_DATE=$(shell date +'%Y%m%d') --defsym __BUILD_TIME=$(shell date +'%H%M%S')
STRIP_DEBUG = --strip-debug STRIP_DEBUG = --strip-debug
KEEP_DEBUG = --only-keep-debug KEEP_DEBUG = --only-keep-debug
# Do not change to elf64!
# The Multiboot spec can only boot elf32 binaries
OUTPUT_FORMAT = -O elf32-i386 OUTPUT_FORMAT = -O elf32-i386
# For 64bit support, you have to define -m64 instead of "-m32 -march=i586"
CFLAGS_FOR_NEWLIB = -m$(BIT) -O2 $(STACKPROT) CFLAGS_FOR_NEWLIB = -m32 -march=i586 -O2 $(STACKPROT)
LDFLAGS_FOR_NEWLIB = -m$(BIT) # For 64bit support, you have to define -m64 instead of "-m32 -march=i586"
CFLAGS_FOR_TOOLS = -m$(BIT) -O2 -Wall LDFLAGS_FOR_NEWLIB = -m32 -march=i586
# For 64bit support, you have to define -m64 instead of "-m32"
CFLAGS_FOR_TOOLS = -m32 -O2 -Wall
LDFLAGS_FOR_TOOLS = LDFLAGS_FOR_TOOLS =
NASMFLAGS_FOR_NEWLIB = -felf$(BIT) # For 64bit support, you have to define -felf64 instead of -felf32
NASMFLAGS_FOR_NEWLIB = -felf32
ifeq ($(BIT), 32)
CFLAGS += -march=i586
CFLAGS_FOR_NEWLIB += -march=i586
LDFLAGS_FOR_NEWLIB += -march=i586
else ifeq ($(BIT), 64)
CFLAGS += -mno-red-zone
endif
# Prettify output # Prettify output
V = 0 V = 0
@ -93,15 +68,11 @@ ifeq ($V,0)
endif endif
default: all default: all
all: newlib tools $(NAME).elf all: newlib tools $(NAME).elf
newlib: newlib:
$(MAKE) ARCH=$(ARCH) BIT=$(BIT) \ $(MAKE) ARCH=$(ARCH) BIT=$(BIT) LDFLAGS="$(LDFLAGS_FOR_NEWLIB)" CFLAGS="$(CFLAGS_FOR_NEWLIB)" NASMFLAGS="$(NASMFLAGS_FOR_NEWLIB)" CC_FOR_TARGET=$(CC_FOR_TARGET) \
LDFLAGS="$(LDFLAGS_FOR_NEWLIB)" \
CFLAGS="$(CFLAGS_FOR_NEWLIB)" \
NASMFLAGS="$(NASMFLAGS_FOR_NEWLIB)" \
CC_FOR_TARGET=$(CC_FOR_TARGET) \
CXX_FOR_TARGET=$(CXX_FOR_TARGET) \ CXX_FOR_TARGET=$(CXX_FOR_TARGET) \
GCC_FOR_TARGET=$(GCC_FOR_TARGET) \ GCC_FOR_TARGET=$(GCC_FOR_TARGET) \
AR_FOR_TARGET=$(AR_FOR_TARGET) \ AR_FOR_TARGET=$(AR_FOR_TARGET) \
@ -125,23 +96,14 @@ $(NAME).elf:
$Q$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $(OUTPUT_FORMAT) $(NAME).elf $Q$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $(OUTPUT_FORMAT) $(NAME).elf
qemu: newlib tools $(NAME).elf qemu: newlib tools $(NAME).elf
$(QEMU) -monitor stdio -serial tcp::12346,server,nowait -smp $(SMP) -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -kernel metalsvm.elf -initrd tools/initrd.img $(QEMU) -monitor stdio -smp 2 -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -net dump -kernel metalsvm.elf -initrd tools/initrd.img
qemudbg: newlib tools $(NAME).elf qemudbg: newlib tools $(NAME).elf
$(QEMU) -s -S -nographic -monitor stdio -serial tcp::12346,server -smp $(SMP) -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -kernel metalsvm.elf -initrd tools/initrd.img $(QEMU) -s -S -smp 2 -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -net dump -kernel metalsvm.elf -initrd tools/initrd.img
gdb: $(NAME).elf gdb: $(NAME).elf
$(GDB) -q -x script.gdb make qemudbg > /dev/null &
$(GDB) -x script.gdb
debug: newlib tools $(NAME).elf
killall $(QEMU) || true
killall $(GDB) || true
sleep 1
gnome-terminal --working-directory=$(TOPDIR) \
--tab --title=Shell --command="bash -c 'sleep 1 && telnet localhost 12345'" \
--tab --title=QEmu --command="make qemudbg" \
--tab --title=GDB --command="make gdb" \
--tab --title=Debug --command="bash -c 'sleep 1 && telnet localhost 12346'"
clean: clean:
$Q$(RM) $(NAME).elf $(NAME).sym *~ $Q$(RM) $(NAME).elf $(NAME).sym *~
@ -150,7 +112,7 @@ clean:
veryclean: clean veryclean: clean
$Q$(MAKE) -C newlib veryclean $Q$(MAKE) -C newlib veryclean
@echo Very cleaned. @echo Very cleaned
#depend: #depend:
# for i in $(SUBDIRS); do $(MAKE) -k -C $$i depend; done # for i in $(SUBDIRS); do $(MAKE) -k -C $$i depend; done
@ -172,6 +134,6 @@ include/metalsvm/config.inc: include/metalsvm/config.h
@echo [ASM] $@ @echo [ASM] $@
$Q$(NASM) $(NASMFLAGS) -o $@ $< $Q$(NASM) $(NASMFLAGS) -o $@ $<
.PHONY: default all clean qemu qemudbg gdb debug newlib tools .PHONY: default all clean emu gdb newlib tools
include $(addsuffix /Makefile,$(SUBDIRS)) include $(addsuffix /Makefile,$(SUBDIRS))

View file

@ -102,7 +102,7 @@ inline static void outportl(unsigned short _port, unsigned int _data)
inline static void uart_putchar(unsigned char _data) inline static void uart_putchar(unsigned char _data)
{ {
outportb(UART_PORT, _data); outportb(0x2F8, _data);
} }
/** /**

View file

@ -86,12 +86,11 @@ static ssize_t stdio_write(fildes_t* file, uint8_t* buffer, size_t size)
for (i = 0; i<size; i++, buffer++) { for (i = 0; i<size; i++, buffer++) {
#ifdef CONFIG_VGA #ifdef CONFIG_VGA
vga_putchar(*buffer); vga_putchar(*buffer);
#endif #elif defined(CONFIG_UART)
#ifdef CONFIG_UART
uart_putchar(*buffer); uart_putchar(*buffer);
#endif #else
kputchar(*buffer); kputchar(*buffer);
#endif
} }
file->offset += size; file->offset += size;

View file

@ -34,14 +34,14 @@ extern "C" {
#define PAGE_SHIFT 12 #define PAGE_SHIFT 12
#define CACHE_LINE 64 #define CACHE_LINE 64
#define MAILBOX_SIZE 32 #define MAILBOX_SIZE 32
#define TIMER_FREQ 100 // in HZ #define TIMER_FREQ 100 /* in HZ */
#define CLOCK_TICK_RATE 1193182 // 8254 chip's internal oscillator frequency #define CLOCK_TICK_RATE 1193182 /* 8254 chip's internal oscillator frequency */
#define INT_SYSCALL 0x80 #define INT_SYSCALL 0x80
#define KERNEL_SPACE (1*1024*1024*1024) #define KERNEL_SPACE (1*1024*1024*1024)
#define VIDEO_MEM_ADDR 0xB8000 // the video memory address #define VIDEO_MEM_ADDR 0xB8000 // the video memora address
#define SMP_SETUP_ADDR 0x07000 #define SMP_SETUP_ADDR 0x07000
#define UART_PORT 0x3F8 // 0x2F8 for SCC
#define BYTE_ORDER LITTLE_ENDIAN #define BYTE_ORDER LITTLE_ENDIAN
/* /*
* address space / (page_size * sizeof(uint8_t)) * address space / (page_size * sizeof(uint8_t))
@ -52,7 +52,7 @@ extern "C" {
#define CONFIG_PCI #define CONFIG_PCI
#define CONFIG_LWIP #define CONFIG_LWIP
#define CONFIG_VGA #define CONFIG_VGA
#define CONFIG_UART //#define CONFIG_UART
#define CONFIG_KEYBOARD #define CONFIG_KEYBOARD
#define CONFIG_MULTIBOOT #define CONFIG_MULTIBOOT
//#define CONFIG_ROCKCREEK //#define CONFIG_ROCKCREEK
@ -72,7 +72,7 @@ extern "C" {
//#define SHMADD //#define SHMADD
#define SHMDBG #define SHMDBG
//#define SHMADD_CACHEABLE //#define SHMADD_CACHEABLE
#define SCC_BOOTINFO 0x80000 #define SCC_BOOTINFO 0x80000
#define BUILTIN_EXPECT(exp, b) __builtin_expect((exp), (b)) #define BUILTIN_EXPECT(exp, b) __builtin_expect((exp), (b))
//#define BUILTIN_EXPECT(exp, b) (exp) //#define BUILTIN_EXPECT(exp, b) (exp)

View file

@ -34,7 +34,13 @@
#define VGA_EARLY_PRINT 1 #define VGA_EARLY_PRINT 1
#define UART_EARLY_PRINT 2 #define UART_EARLY_PRINT 2
#ifdef CONFIG_VGA
static uint32_t early_print = VGA_EARLY_PRINT;
#elif defined(CONFIG_UART)
static uint32_t early_print = UART_EARLY_PRINT;
#else
static uint32_t early_print = NO_EARLY_PRINT; static uint32_t early_print = NO_EARLY_PRINT;
#endif
static spinlock_irqsave_t olock = SPINLOCK_IRQSAVE_INIT; static spinlock_irqsave_t olock = SPINLOCK_IRQSAVE_INIT;
static atomic_int32_t kmsg_counter = ATOMIC_INIT(0); static atomic_int32_t kmsg_counter = ATOMIC_INIT(0);
static unsigned char kmessages[KMSG_SIZE] __attribute__ ((section(".kmsg"))) = {[0 ... KMSG_SIZE-1] = 0x00}; static unsigned char kmessages[KMSG_SIZE] __attribute__ ((section(".kmsg"))) = {[0 ... KMSG_SIZE-1] = 0x00};
@ -139,10 +145,6 @@ int koutput_init(void)
{ {
#ifdef CONFIG_VGA #ifdef CONFIG_VGA
vga_init(); vga_init();
early_print |= VGA_EARLY_PRINT;
#endif
#ifdef CONFIG_UART
early_print |= UART_EARLY_PRINT;
#endif #endif
return 0; return 0;
@ -159,11 +161,11 @@ int kputchar(int c)
kmessages[pos % KMSG_SIZE] = (unsigned char) c; kmessages[pos % KMSG_SIZE] = (unsigned char) c;
#ifdef CONFIG_VGA #ifdef CONFIG_VGA
if (early_print & VGA_EARLY_PRINT) if (early_print == VGA_EARLY_PRINT)
vga_putchar(c); vga_putchar(c);
#endif #endif
#ifdef CONFIG_UART #ifdef CONFIG_UART
if (early_print & UART_EARLY_PRINT) if (early_print == UART_EARLY_PRINT)
uart_putchar(c); uart_putchar(c);
#endif #endif
@ -184,11 +186,11 @@ int kputs(const char *str)
pos = atomic_int32_inc(&kmsg_counter); pos = atomic_int32_inc(&kmsg_counter);
kmessages[pos % KMSG_SIZE] = str[i]; kmessages[pos % KMSG_SIZE] = str[i];
#ifdef CONFIG_VGA #ifdef CONFIG_VGA
if (early_print & VGA_EARLY_PRINT) if (early_print == VGA_EARLY_PRINT)
vga_putchar(str[i]); vga_putchar(str[i]);
#endif #endif
#ifdef CONFIG_UART #ifdef CONFIG_UART
if (early_print & UART_EARLY_PRINT) if (early_print == UART_EARLY_PRINT)
uart_putchar(str[i]); uart_putchar(str[i]);
#endif #endif
} }

View file

@ -1,14 +1,7 @@
# Constant part of the script # Constant part of the script
set disassembly-flavor intel
symbol-file metalsvm.sym symbol-file metalsvm.sym
target remote localhost:1234 target remote localhost:1234
# Debugging 32bit code # Configure breakpoints and everything as you wish here.
#set architecture i386 break main
#break stublet
#continue
# Debugging 64bit code
#set architecture i386:x86-64
#break main
continue continue