提交 2224e0e7 创建 作者: Frans Kaashoek's avatar Frans Kaashoek

Merge branch 'scale-amd64' of ssh://amsterdam.csail.mit.edu/home/am0/6.828/xv6 into scale-amd64

......@@ -21,7 +21,7 @@ OBJCOPY = $(TOOLPREFIX)objcopy
CFLAGS = -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb \
-m64 -Werror -std=c99 -fms-extensions -mno-sse -mcmodel=large -I$(QEMUSRC) \
-fno-omit-frame-pointer -DHW_$(HW) -include param.h
-fno-omit-frame-pointer -DHW_$(HW) -include param.h -include compiler.h
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
ASFLAGS = -m64 -gdwarf-2 -MD
LDFLAGS += -m elf_x86_64
......
#define __padout__ char __padout[0] __attribute__((aligned(CACHELINE)))
#define __mpalign__ __attribute__((aligned(CACHELINE)))
#define __noret__ __attribute__((noreturn))
......@@ -95,6 +95,16 @@ snprintf(char *buf, u32 n, char *fmt, ...)
}
void
__cprintf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vprintfmt(writecons, 0, fmt, ap);
va_end(ap);
}
void
cprintf(const char *fmt, ...)
{
va_list ap;
......@@ -131,7 +141,7 @@ stacktrace(void)
do { \
uptr addr = (uptr) __builtin_return_address(i); \
if ((addr & KBASE) == KBASE) \
cprintf(" %lx\n", addr); \
__cprintf(" %lx\n", addr); \
else \
return; \
} while (0)
......@@ -147,23 +157,55 @@ stacktrace(void)
#undef PRINT_RET
}
void __attribute__((noreturn))
panic(const char *s)
void __noret__
kerneltrap(struct trapframe *tf)
{
extern void sys_halt();
const char *name = "(no name)";
void *kstack = NULL;
int pid = 0;
uptr pc[10];
int i;
cli();
cons.locking = 0;
acquire(&cons.lock);
if (myproc() != NULL) {
if (myproc()->name && myproc()->name[0] != 0)
name = myproc()->name;
pid = myproc()->pid;
kstack = myproc()->kstack;
}
__cprintf("kernel trap %u cpu %u\n"
" tf: rip %p rsp %p cr2 %p\n"
" proc: name %s pid %u kstack %p\n",
tf->trapno, mycpu()->id,
tf->rip, tf->rsp, rcr2(),
name, pid, kstack);
getcallerpcs((void*)tf->rbp, pc);
for (i = 0; i < NELEM(pc) && pc[i] != 0; i++)
__cprintf(" %p\n", pc[i]);
cprintf("cpu%d: panic: ", mycpu()->id);
cprintf(s);
cprintf("\n");
stacktrace();
panicked = 1;
sys_halt();
for(;;)
;
}
void __noret__
panic(const char *s)
{
extern void sys_halt();
cli();
acquire(&cons.lock);
// Never release cons.lock
__cprintf("cpu%d: panic: ", mycpu()->id);
__cprintf(s);
__cprintf("\n");
stacktrace();
panicked = 1;
sys_halt();
for(;;)
;
......
......@@ -9,6 +9,7 @@
#define RX_RING_SIZE 64
int e1000irq;
int e1000init;
static struct {
u32 membase;
......@@ -296,5 +297,6 @@ e1000attach(struct pci_func *pcif)
for (i = 0; i < WMREG_MTA; i+=4)
ewr(WMREG_CORDOVA_MTA+i, 0);
e1000init = 1;
return 0;
}
......@@ -260,7 +260,8 @@ gc_worker(void *x)
{
struct spinlock wl;
cprintf("gc_worker: %d\n", mycpu()->id);
if (VERBOSE)
cprintf("gc_worker: %d\n", mycpu()->id);
initlock(&wl, "rcu_gc_worker dummy"); // dummy lock
for (;;) {
......
......@@ -45,7 +45,8 @@ void cv_tick(void);
// console.c
void cprintf(const char*, ...);
void panic(const char*) __attribute__((noreturn));
void panic(const char*) __noret__;
void kerneltrap(struct trapframe *tf) __noret__;
void snprintf(char *buf, u32 n, char *fmt, ...);
void consoleintr(int(*)(void));
......@@ -76,6 +77,7 @@ void crange_print(struct crange *cr, int);
// e1000.c
extern int e1000irq;
extern int e1000init;
void e1000intr(void);
int e1000tx(void *buf, u32 len);
void e1000hwaddr(u8 *hwaddr);
......@@ -239,7 +241,7 @@ int growproc(int);
int kill(int);
void pinit(void);
void procdumpall(void);
void scheduler(void) __attribute__((noreturn));
void scheduler(void) __noret__;
void sched(void);
void userinit(void);
int wait(void);
......
......@@ -22,3 +22,7 @@
#define subfetch(ptr, val) __sync_sub_and_fetch(ptr, val)
#define fetchadd(ptr, val) __sync_fetch_and_add(ptr, val)
#define __offsetof offsetof
#define __mpalign__ __attribute__((aligned(CACHELINE)))
#define __padout__ char __padout[0] __attribute__((aligned(CACHELINE)))
#define __noret__ __attribute__((noreturn))
# Multiboot header, for multiboot boot loaders like GNU Grub.
# http://www.gnu.org/software/grub/manual/multiboot/multiboot.html
#
# Using GRUB 2, you can boot xv6 from a file stored in a
# Linux file system by copying kernel or kernelmemfs to /boot
# and then adding this menu entry:
#
# menuentry "xv6" {
# insmod ext2
# set root='(hd0,msdos1)'
# set kernel='/boot/kernel'
# echo "Loading ${kernel}..."
# multiboot ${kernel} ${kernel}
# boot
# }
#include "asm.h"
#include "memlayout.h"
#define RELOC(x) ((x) - KERNBASE) // same as V2P, but without casts
#define STACK 4096
#define SEG_KCODE 1 // kernel code
#define SEG_KDATA 2 // kernel data+stack
# Multiboot header. Data to direct multiboot loader.
.p2align 2
.text
.globl multiboot_header
multiboot_header:
#define magic 0x1badb002
#define flags (1<<16 | 1<<0)
.long magic
.long flags
.long (-magic-flags)
.long multiboot_header # beginning of image
.long multiboot_header
.long edata
.long end
.long multiboot_entry
# Multiboot entry point. Machine is mostly set up.
# Configure the GDT to match the environment that our usual
# boot loader - bootasm.S - sets up.
.globl multiboot_entry
multiboot_entry:
lgdt RELOC(gdtdesc)
ljmp $(SEG_KCODE<<3), $mbstart32
mbstart32:
# Set up the protected-mode data segment registers
movw $(SEG_KDATA<<3), %ax # Our data segment selector
movw %ax, %ds # -> DS: Data Segment
movw %ax, %es # -> ES: Extra Segment
movw %ax, %ss # -> SS: Stack Segment
movw $0, %ax # Zero segments not ready for use
movw %ax, %fs # -> FS
movw %ax, %gs # -> GS
# Set up the stack pointer and call into C.
movl $(stack + STACK), %esp
call main
spin:
jmp spin
# Bootstrap GDT
.p2align 2 # force 4 byte alignment
gdt:
SEG_NULLASM # null seg
SEG_ASM(STA_X|STA_R, -KERNBASE, 0xffffffff) # code seg
SEG_ASM(STA_W, -KERNBASE, 0xffffffff) # data seg
gdtdesc:
.word (gdtdesc - gdt - 1) # sizeof(gdt) - 1
.long RELOC(gdt) # address gdt
.comm stack, STACK
......@@ -37,12 +37,16 @@ netalloc(void)
int
nettx(void *va, u16 len)
{
if (e1000init == 0)
return -1;
return e1000tx(va, len);
}
void
nethwaddr(u8 *hwaddr)
{
if (e1000init == 0)
return;
e1000hwaddr(hwaddr);
}
......
#include "types.h"
#include "kernel.h"
#include "spinlock.h"
#include "condvar.h"
#include "fs.h"
#include "file.h"
#include "prof.h"
#include "kernel.h"
#include "bits.h"
#include "amd64.h"
......
......@@ -3,7 +3,6 @@
#include "condvar.h"
#include "fs.h"
#include "file.h"
#include "prof.h"
#include "kernel.h"
#include "bits.h"
#include "amd64.h"
......
......@@ -115,12 +115,8 @@ trap(struct trapframe *tf)
break;
}
if(myproc() == 0 || (tf->cs&3) == 0){
// In kernel, it must be our mistake.
cprintf("unexpected trap %d from cpu %d rip %lx (cr2=0x%lx)\n",
tf->trapno, mycpu()->id, tf->rip, rcr2());
panic("trap");
}
if (myproc() == 0 || (tf->cs&3) == 0)
kerneltrap(tf);
if(tf->trapno == T_PGFLT){
uptr addr = rcr2();
......
......@@ -18,6 +18,3 @@ typedef uptr paddr;
typedef u64 pme_t; // Page Map Entry (refers to any entry in any level)
typedef pme_t pml4e_t;
#define __mpalign__ __attribute__((aligned(CACHELINE)))
#define __padout__ char __padout[0] __attribute__((aligned(CACHELINE)))
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论