Compare commits
4 commits
master
...
qemu_debug
Author | SHA1 | Date | |
---|---|---|---|
acc6e2124e | |||
5ab075df9b | |||
db21f7cf05 | |||
![]() |
e731d60256 |
6 changed files with 97 additions and 53 deletions
|
@ -1,8 +1,12 @@
|
|||
TOPDIR = $(shell pwd)
|
||||
ARCH = x86
|
||||
# For 64bit support, you have define BIT as 64
|
||||
BIT=32
|
||||
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)
|
||||
LWIPDIRS = lwip/src/arch lwip/src/api lwip/src/core lwip/src/core/ipv4 lwip/src/netif
|
||||
DRIVERDIRS = drivers/net drivers/char
|
||||
KERNDIRS = libkern kernel mm fs apps arch/$(ARCH)/kernel arch/$(ARCH)/mm arch/$(ARCH)/scc $(LWIPDIRS) $(DRIVERDIRS)
|
||||
|
@ -30,35 +34,56 @@ RANLIB_FOR_TARGET = $(CROSSCOMPREFIX)ranlib
|
|||
STRIP_FOR_TARGET = $(CROSSCOMPREFIX)strip
|
||||
READELF_FOR_TARGET = $(CROSSCOMPREFIX)readelf
|
||||
|
||||
# Tools
|
||||
MAKE = make
|
||||
RM = rm -rf
|
||||
NASM = nasm
|
||||
# For 64bit code, you have to use qemu-system-x86_64
|
||||
QEMU = qemu-system-i386
|
||||
GDB = gdb
|
||||
|
||||
# For 64bit support, you have to define -felf64 instead of -felf32
|
||||
NASMFLAGS = -felf32 -g -i$(TOPDIR)/include/metalsvm/
|
||||
INCLUDE = -I$(TOPDIR)/include -I$(TOPDIR)/arch/$(ARCH)/include -I$(TOPDIR)/lwip/src/include -I$(TOPDIR)/lwip/src/include/ipv4 -I$(TOPDIR)/drivers
|
||||
# For 64bit support, you have to define "-m64 -mno-red-zone" instead of "-m32 -march=i586"
|
||||
ifeq ($(BIT), 32)
|
||||
QEMU = qemu-system-i386
|
||||
else ifeq ($(BIT), 64)
|
||||
QEMU = qemu-system-x86_64
|
||||
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
|
||||
CFLAGS = -g -m32 -march=i586 -Wall -O2 -fstrength-reduce -fomit-frame-pointer -finline-functions -ffreestanding $(INCLUDE) $(STACKPROT)
|
||||
CFLAGS = -g -O2 -m$(BIT) -Wall -fomit-frame-pointer -ffreestanding -fstrength-reduce -finline-functions $(INCLUDE) $(STACKPROT)
|
||||
|
||||
# Compiler options for debuging
|
||||
#CFLAGS = -g -O -m32 -march=i586 -Wall -fomit-frame-pointer -ffreestanding $(INCLUDE) $(STACKPROT)
|
||||
#CFLAGS = -g -O -m$(BIT) -Wall -fomit-frame-pointer -ffreestanding $(INCLUDE) $(STACKPROT)
|
||||
|
||||
NASMFLAGS = -felf$(BIT) -g -i$(TOPDIR)/include/metalsvm/
|
||||
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')
|
||||
|
||||
STRIP_DEBUG = --strip-debug
|
||||
KEEP_DEBUG = --only-keep-debug
|
||||
|
||||
# Do not change to elf64!
|
||||
# The Multiboot spec can only boot elf32 binaries
|
||||
OUTPUT_FORMAT = -O elf32-i386
|
||||
# For 64bit support, you have to define -m64 instead of "-m32 -march=i586"
|
||||
CFLAGS_FOR_NEWLIB = -m32 -march=i586 -O2 $(STACKPROT)
|
||||
# For 64bit support, you have to define -m64 instead of "-m32 -march=i586"
|
||||
LDFLAGS_FOR_NEWLIB = -m32 -march=i586
|
||||
# For 64bit support, you have to define -m64 instead of "-m32"
|
||||
CFLAGS_FOR_TOOLS = -m32 -O2 -Wall
|
||||
|
||||
CFLAGS_FOR_NEWLIB = -m$(BIT) -O2 $(STACKPROT)
|
||||
LDFLAGS_FOR_NEWLIB = -m$(BIT)
|
||||
CFLAGS_FOR_TOOLS = -m$(BIT) -O2 -Wall
|
||||
LDFLAGS_FOR_TOOLS =
|
||||
# For 64bit support, you have to define -felf64 instead of -felf32
|
||||
NASMFLAGS_FOR_NEWLIB = -felf32
|
||||
NASMFLAGS_FOR_NEWLIB = -felf$(BIT)
|
||||
|
||||
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
|
||||
V = 0
|
||||
|
@ -68,11 +93,15 @@ ifeq ($V,0)
|
|||
endif
|
||||
|
||||
default: all
|
||||
|
||||
|
||||
all: newlib tools $(NAME).elf
|
||||
|
||||
|
||||
newlib:
|
||||
$(MAKE) ARCH=$(ARCH) BIT=$(BIT) LDFLAGS="$(LDFLAGS_FOR_NEWLIB)" CFLAGS="$(CFLAGS_FOR_NEWLIB)" NASMFLAGS="$(NASMFLAGS_FOR_NEWLIB)" CC_FOR_TARGET=$(CC_FOR_TARGET) \
|
||||
$(MAKE) ARCH=$(ARCH) BIT=$(BIT) \
|
||||
LDFLAGS="$(LDFLAGS_FOR_NEWLIB)" \
|
||||
CFLAGS="$(CFLAGS_FOR_NEWLIB)" \
|
||||
NASMFLAGS="$(NASMFLAGS_FOR_NEWLIB)" \
|
||||
CC_FOR_TARGET=$(CC_FOR_TARGET) \
|
||||
CXX_FOR_TARGET=$(CXX_FOR_TARGET) \
|
||||
GCC_FOR_TARGET=$(GCC_FOR_TARGET) \
|
||||
AR_FOR_TARGET=$(AR_FOR_TARGET) \
|
||||
|
@ -96,14 +125,23 @@ $(NAME).elf:
|
|||
$Q$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $(OUTPUT_FORMAT) $(NAME).elf
|
||||
|
||||
qemu: newlib tools $(NAME).elf
|
||||
$(QEMU) -monitor stdio -smp 2 -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -net dump -kernel metalsvm.elf -initrd tools/initrd.img
|
||||
$(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
|
||||
|
||||
qemudbg: newlib tools $(NAME).elf
|
||||
$(QEMU) -s -S -smp 2 -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -net dump -kernel metalsvm.elf -initrd tools/initrd.img
|
||||
$(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
|
||||
|
||||
gdb: $(NAME).elf
|
||||
make qemudbg > /dev/null &
|
||||
$(GDB) -x script.gdb
|
||||
$(GDB) -q -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:
|
||||
$Q$(RM) $(NAME).elf $(NAME).sym *~
|
||||
|
@ -112,7 +150,7 @@ clean:
|
|||
|
||||
veryclean: clean
|
||||
$Q$(MAKE) -C newlib veryclean
|
||||
@echo Very cleaned
|
||||
@echo Very cleaned.
|
||||
|
||||
#depend:
|
||||
# for i in $(SUBDIRS); do $(MAKE) -k -C $$i depend; done
|
||||
|
@ -134,6 +172,6 @@ include/metalsvm/config.inc: include/metalsvm/config.h
|
|||
@echo [ASM] $@
|
||||
$Q$(NASM) $(NASMFLAGS) -o $@ $<
|
||||
|
||||
.PHONY: default all clean emu gdb newlib tools
|
||||
.PHONY: default all clean qemu qemudbg gdb debug newlib tools
|
||||
|
||||
include $(addsuffix /Makefile,$(SUBDIRS))
|
||||
|
|
|
@ -102,7 +102,7 @@ inline static void outportl(unsigned short _port, unsigned int _data)
|
|||
|
||||
inline static void uart_putchar(unsigned char _data)
|
||||
{
|
||||
outportb(0x2F8, _data);
|
||||
outportb(UART_PORT, _data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -86,11 +86,12 @@ static ssize_t stdio_write(fildes_t* file, uint8_t* buffer, size_t size)
|
|||
for (i = 0; i<size; i++, buffer++) {
|
||||
#ifdef CONFIG_VGA
|
||||
vga_putchar(*buffer);
|
||||
#elif defined(CONFIG_UART)
|
||||
uart_putchar(*buffer);
|
||||
#else
|
||||
kputchar(*buffer);
|
||||
#endif
|
||||
#ifdef CONFIG_UART
|
||||
uart_putchar(*buffer);
|
||||
#endif
|
||||
|
||||
kputchar(*buffer);
|
||||
}
|
||||
|
||||
file->offset += size;
|
||||
|
|
|
@ -34,14 +34,14 @@ extern "C" {
|
|||
#define PAGE_SHIFT 12
|
||||
#define CACHE_LINE 64
|
||||
#define MAILBOX_SIZE 32
|
||||
#define TIMER_FREQ 100 /* in HZ */
|
||||
#define CLOCK_TICK_RATE 1193182 /* 8254 chip's internal oscillator frequency */
|
||||
#define TIMER_FREQ 100 // in HZ
|
||||
#define CLOCK_TICK_RATE 1193182 // 8254 chip's internal oscillator frequency
|
||||
#define INT_SYSCALL 0x80
|
||||
#define KERNEL_SPACE (1*1024*1024*1024)
|
||||
#define VIDEO_MEM_ADDR 0xB8000 // the video memora address
|
||||
#define VIDEO_MEM_ADDR 0xB8000 // the video memory address
|
||||
#define SMP_SETUP_ADDR 0x07000
|
||||
|
||||
#define BYTE_ORDER LITTLE_ENDIAN
|
||||
#define UART_PORT 0x3F8 // 0x2F8 for SCC
|
||||
#define BYTE_ORDER LITTLE_ENDIAN
|
||||
|
||||
/*
|
||||
* address space / (page_size * sizeof(uint8_t))
|
||||
|
@ -52,7 +52,7 @@ extern "C" {
|
|||
#define CONFIG_PCI
|
||||
#define CONFIG_LWIP
|
||||
#define CONFIG_VGA
|
||||
//#define CONFIG_UART
|
||||
#define CONFIG_UART
|
||||
#define CONFIG_KEYBOARD
|
||||
#define CONFIG_MULTIBOOT
|
||||
//#define CONFIG_ROCKCREEK
|
||||
|
@ -72,7 +72,7 @@ extern "C" {
|
|||
//#define SHMADD
|
||||
#define SHMDBG
|
||||
//#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) (exp)
|
||||
|
|
|
@ -34,13 +34,7 @@
|
|||
#define VGA_EARLY_PRINT 1
|
||||
#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;
|
||||
#endif
|
||||
static spinlock_irqsave_t olock = SPINLOCK_IRQSAVE_INIT;
|
||||
static atomic_int32_t kmsg_counter = ATOMIC_INIT(0);
|
||||
static unsigned char kmessages[KMSG_SIZE] __attribute__ ((section(".kmsg"))) = {[0 ... KMSG_SIZE-1] = 0x00};
|
||||
|
@ -145,6 +139,10 @@ int koutput_init(void)
|
|||
{
|
||||
#ifdef CONFIG_VGA
|
||||
vga_init();
|
||||
early_print |= VGA_EARLY_PRINT;
|
||||
#endif
|
||||
#ifdef CONFIG_UART
|
||||
early_print |= UART_EARLY_PRINT;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
@ -161,11 +159,11 @@ int kputchar(int c)
|
|||
kmessages[pos % KMSG_SIZE] = (unsigned char) c;
|
||||
|
||||
#ifdef CONFIG_VGA
|
||||
if (early_print == VGA_EARLY_PRINT)
|
||||
if (early_print & VGA_EARLY_PRINT)
|
||||
vga_putchar(c);
|
||||
#endif
|
||||
#ifdef CONFIG_UART
|
||||
if (early_print == UART_EARLY_PRINT)
|
||||
if (early_print & UART_EARLY_PRINT)
|
||||
uart_putchar(c);
|
||||
#endif
|
||||
|
||||
|
@ -186,11 +184,11 @@ int kputs(const char *str)
|
|||
pos = atomic_int32_inc(&kmsg_counter);
|
||||
kmessages[pos % KMSG_SIZE] = str[i];
|
||||
#ifdef CONFIG_VGA
|
||||
if (early_print == VGA_EARLY_PRINT)
|
||||
if (early_print & VGA_EARLY_PRINT)
|
||||
vga_putchar(str[i]);
|
||||
#endif
|
||||
#ifdef CONFIG_UART
|
||||
if (early_print == UART_EARLY_PRINT)
|
||||
if (early_print & UART_EARLY_PRINT)
|
||||
uart_putchar(str[i]);
|
||||
#endif
|
||||
}
|
||||
|
|
11
script.gdb
11
script.gdb
|
@ -1,7 +1,14 @@
|
|||
# Constant part of the script
|
||||
set disassembly-flavor intel
|
||||
symbol-file metalsvm.sym
|
||||
target remote localhost:1234
|
||||
|
||||
# Configure breakpoints and everything as you wish here.
|
||||
break main
|
||||
# Debugging 32bit code
|
||||
#set architecture i386
|
||||
#break stublet
|
||||
#continue
|
||||
|
||||
# Debugging 64bit code
|
||||
#set architecture i386:x86-64
|
||||
#break main
|
||||
continue
|
||||
|
|
Loading…
Add table
Reference in a new issue