===================================================================
@@ -327,6 +327,7 @@
return ret;
}
+#define RELO 0x0000
static int build_self_segment_list(
struct segment *head,
@@ -355,7 +356,7 @@
segment->type == PAYLOAD_SEGMENT_CODE ? "code" : "data",
ntohl(segment->compression));
new = malloc(sizeof(*new));
- new->s_dstaddr = ntohl((u32) segment->load_addr);
+ new->s_dstaddr = ntohl((u32) segment->load_addr) + RELO;
new->s_memsz = ntohl(segment->mem_len);
new->compression = ntohl(segment->compression);
@@ -376,13 +377,13 @@
ntohl(segment->mem_len));
new = malloc(sizeof(*new));
new->s_filesz = 0;
- new->s_dstaddr = ntohl((u32) segment->load_addr);
+ new->s_dstaddr = ntohl((u32) segment->load_addr) + RELO;
new->s_memsz = ntohl(segment->mem_len);
break;
case PAYLOAD_SEGMENT_ENTRY:
printk_debug(" Entry Point 0x%p\n", (void *) ntohl((u32) segment->load_addr));
- *entry = ntohl((u32) segment->load_addr);
+ *entry = ntohl((u32) segment->load_addr) + RELO;
/* Per definition, a payload always has the entry point
* as last segment. Thus, we use the occurence of the
* entry point as break condition for the loop.
===================================================================
@@ -35,9 +35,9 @@
{
struct cpuid_result result;
asm volatile(
- "cpuid"
+ " pushl %%ebx ; cpuid ; movl %%ebx, %%esi ; pop %%ebx"
: "=a" (result.eax),
- "=b" (result.ebx),
+ "=S" (result.ebx),
"=c" (result.ecx),
"=d" (result.edx)
: "0" (op));
@@ -52,18 +52,18 @@
{
unsigned int eax;
- __asm__("cpuid"
+ __asm__(" pushl %%ebx ; cpuid ; movl %%ebx, %%esi ; pop %%ebx"
: "=a" (eax)
: "0" (op)
- : "ebx", "ecx", "edx");
+ : "ecx", "edx", "esi");
return eax;
}
static inline unsigned int cpuid_ebx(unsigned int op)
{
unsigned int eax, ebx;
- __asm__("cpuid"
- : "=a" (eax), "=b" (ebx)
+ __asm__(" pushl %%ebx ; cpuid ; movl %%ebx, %%esi ; pop %%ebx"
+ : "=a" (eax), "=S" (ebx)
: "0" (op)
: "ecx", "edx" );
return ebx;
@@ -72,20 +72,20 @@
{
unsigned int eax, ecx;
- __asm__("cpuid"
+ __asm__(" pushl %%ebx ; cpuid ; pop %%ebx"
: "=a" (eax), "=c" (ecx)
: "0" (op)
- : "ebx", "edx" );
+ : "edx" );
return ecx;
}
static inline unsigned int cpuid_edx(unsigned int op)
{
unsigned int eax, edx;
- __asm__("cpuid"
+ __asm__(" pushl %%ebx ; cpuid ; pop %%ebx"
: "=a" (eax), "=d" (edx)
: "0" (op)
- : "ebx", "ecx");
+ : "ecx");
return edx;
}
===================================================================
@@ -47,12 +47,12 @@
$(obj)/coreboot_ram: $(obj)/coreboot_ram.o $(src)/arch/i386/coreboot_ram.ld #ldoptions
@printf " CC $(subst $(obj)/,,$(@))\n"
- $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(src)/arch/i386/coreboot_ram.ld $(obj)/coreboot_ram.o
+ $(CC) -nostdlib -nostartfiles -shared -o $@ -L$(obj) -T $(src)/arch/i386/coreboot_ram.ld $(obj)/coreboot_ram.o
$(NM) -n $(obj)/coreboot_ram | sort > $(obj)/coreboot_ram.map
$(obj)/coreboot_ram.o: $(obj)/arch/i386/lib/c_start.o $(drivers) $(obj)/coreboot.a $(LIBGCC_FILE_NAME)
@printf " CC $(subst $(obj)/,,$(@))\n"
- $(CC) -nostdlib -r -o $@ $(obj)/arch/i386/lib/c_start.o $(drivers) -Wl,-\( $(obj)/coreboot.a $(LIBGCC_FILE_NAME) -Wl,-\)
+ $(CC) -nostdlib -fPIC -r -o $@ $(obj)/arch/i386/lib/c_start.o $(drivers) -Wl,-\( $(obj)/coreboot.a $(LIBGCC_FILE_NAME) -Wl,-\)
$(obj)/coreboot.a: $(objs)
@printf " AR $(subst $(obj)/,,$(@))\n"
===================================================================
@@ -1,5 +1,6 @@
+obj-y += cpu.o
+obj-y += reloc.o
obj-y += c_start.o
-obj-y += cpu.o
obj-y += pci_ops_conf1.o
obj-y += pci_ops_conf2.o
obj-y += pci_ops_mmconf.o
===================================================================
@@ -1,13 +1,46 @@
#include <arch/asm.h>
#include <arch/intel.h>
+ /* Reload all of the segment registers
+ leal gdt@GOTOFF(%ebx), %eax
+ movl %eax, 2 + gdt_descr@GOTOFF(%ebx)
+ lgdt gdt_descr@GOTOFF(%ebx)
+ leal flush@GOTOFF(%ebx), %eax
+ pushl $KERNEL_CS
+ pushl %eax
+ lret
+flush: movl $KERNEL_DS, %eax
+ movw %ax, %ds
+*/
+
.section ".text"
.code32
.globl _start
_start:
+
+ /* Load the GOT pointer */
+ call 0f
+0: popl %ebx
+ addl $_GLOBAL_OFFSET_TABLE_+[.-0b], %ebx
+
cli
- lgdt %cs:gdtaddr
+/*
+ lgdt %cs:gdtaddr@GOTOFF(%ebx)
+*/
+ leal gdt@GOTOFF(%ebx), %eax
+ movl %eax, 2 + gdtaddr@GOTOFF(%ebx)
+
+ lgdt gdtaddr@GOTOFF(%ebx)
+
+ leal flush@GOTOFF(%ebx), %eax
+ pushl $0x10
+ pushl %eax
+ lret
+flush:
+
+/*
ljmp $0x10, $1f
+*/
1: movl $0x18, %eax
movl %eax, %ds
movl %eax, %es
@@ -19,8 +52,8 @@
/** clear stack */
cld
- leal _stack, %edi
- movl $_estack, %ecx
+ leal _stack@GOTOFF(%ebx), %edi
+ leal _estack@GOTOFF(%ebx), %ecx
subl %edi, %ecx
shrl $2, %ecx /* it is 32 bit align, right? */
xorl %eax, %eax
@@ -28,8 +61,8 @@
stosl
/** clear bss */
- leal _bss, %edi
- movl $_ebss, %ecx
+ leal _bss@GOTOFF(%ebx), %edi
+ leal _ebss@GOTOFF(%ebx), %ecx
subl %edi, %ecx
jz .Lnobss
shrl $2, %ecx /* it is 32 bit align, right? */
@@ -39,7 +72,7 @@
.Lnobss:
/* set new stack */
- movl $_estack, %esp
+ leal _estack@GOTOFF(%ebx), %esp
/* Push the cpu index and struct cpu */
pushl $0
@@ -49,25 +82,31 @@
pushl %ebp
/* Save the stack location */
- movl %esp, %ebp
+/*
+ movl %esp, %ecx
+*/
+
/* Initialize the Interrupt Descriptor table */
- leal _idt, %edi
- leal vec0, %ebx
+ leal _idt@GOTOFF(%ebx), %edi
+ leal vec0@GOTOFF(%ebx), %ebp
+ leal _idt_end@GOTOFF(%ebx), %ecx
+
+
movl $(0x10 << 16), %eax /* cs selector */
-1: movw %bx, %ax
- movl %ebx, %edx
+1: movw %bp, %ax
+ movl %ebp, %edx
movw $0x8E00, %dx /* Interrupt gate - dpl=0, present */
movl %eax, 0(%edi)
movl %edx, 4(%edi)
- addl $6, %ebx
+ addl $6, %ebp
addl $8, %edi
- cmpl $_idt_end, %edi
+ cmpl %ecx, %edi
jne 1b
/* Load the Interrupt descriptor table */
- lidt idtarg
+ lidt idtarg@GOTOFF(%ebx)
/*
* Now we are finished. Memory is up, data is copied and
@@ -77,7 +116,18 @@
intel_chip_post_macro(0xfe) /* post fe */
/* Restore the stack location */
- movl %ebp, %esp
+/*
+ movl %ecx, %esp
+*/
+
+/*
+ movl %eax,loader_eax@GOTOFF(%ebx)
+ovl %ebx,loader_ebx@GOTOFF(%ebx)
+*/
+
+ leal _dl_start@GOTOFF(%ebx), %eax
+ call *%eax
+
/* The boot_complete flag has already been pushed */
call hardwaremain
@@ -245,9 +295,13 @@
.globl gdt, gdt_end, gdt_limit, idtarg
gdt_limit = gdt_end - gdt - 1 /* compute the table limit */
+
+
gdtaddr:
.word gdt_limit
- .long gdt /* we know the offset */
+ .long 0
+/*
+gdt*/ /* we know the offset */
.data
===================================================================
@@ -39,6 +39,19 @@
. = ALIGN(16);
_etext = .;
}
+
+ .dynsym : { *(.dynsym) }
+ .dynstr : { *(.dynstr) }
+ .hash : { *(.hash) }
+ .gnu.hash : { *(.gnu.hash) }
+ .dynamic : { *(.dynamic) }
+
+ .rel.text : { *(.rel.text .rel.text.*) }
+ .rel.rodata : { *(.rel.rodata .rel.rodata.*) }
+ .rel.data : { *(.rel.data .rel.data.*) }
+ .rel.got : { *(.rel.got .rel.got.*) }
+ .rel.plt : { *(.rel.plt .rel.plt.*) }
+
.rodata : {
_rodata = .;
. = ALIGN(4);
@@ -75,7 +88,14 @@
*(.data)
_edata = .;
}
+ . = ALIGN(4);
+ .got : {
+ *(.got.plt)
+ *(.got)
+ _edata = . ;
+ }
+
.sdata : {
_SDA_BASE_ = .;
*(.sdata)
===================================================================
@@ -144,43 +144,43 @@
$(CPP) -D__ACPI__ -P $(CPPFLAGS) -include $(obj)/config.h -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
iasl -p $$(basename $$@) -tc $$(basename $$@).asl
mv $$(basename $$@).hex $$(basename $$@).c
- $(CC) -m32 $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $$@))), -DAmlCode=AmlCode_$$(basename $$(notdir $$@))) -c -o $$@ $$(basename $$@).c
+ $(CC) -m32 -fPIC $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $$@))), -DAmlCode=AmlCode_$$(basename $$(notdir $$@))) -c -o $$@ $$(basename $$@).c
endef
define objs_c_template
$(obj)/$(1)%.o: src/$(1)%.c $(obj)/config.h
@printf " CC $$(subst $$(obj)/,,$$(@))\n"
- $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
+ $(CC) -m32 -fPIC $$(CFLAGS) -c -o $$@ $$<
endef
define objs_S_template
$(obj)/$(1)%.o: src/$(1)%.S $(obj)/config.h
@printf " CC $$(subst $$(obj)/,,$$(@))\n"
- $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
+ $(CC) -m32 -fPIC -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
endef
define initobjs_c_template
$(obj)/$(1)%.o: src/$(1)%.c $(obj)/config.h
@printf " CC $$(subst $$(obj)/,,$$(@))\n"
- $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
+ $(CC) -m32 -fPIC $$(CFLAGS) -c -o $$@ $$<
endef
define initobjs_S_template
$(obj)/$(1)%.o: src/$(1)%.S $(obj)/config.h
@printf " CC $$(subst $$(obj)/,,$$(@))\n"
- $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
+ $(CC) -m32 -fPIC -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
endef
define drivers_c_template
$(obj)/$(1)%.o: src/$(1)%.c $(obj)/config.h
@printf " CC $$(subst $$(obj)/,,$$(@))\n"
- $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
+ $(CC) -m32 -fPIC $$(CFLAGS) -c -o $$@ $$<
endef
define drivers_S_template
$(obj)/$(1)%.o: src/$(1)%.S
@printf " CC $$(subst $$(obj)/,,$$(@))\n"
- $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
+ $(CC) -m32 -fPIC -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
endef
define smmobjs_c_template