--- Gnu-Mach/i386/i386at/boothdr.S 2020/09/02 04:36:58 1.1 +++ Gnu-Mach/i386/i386at/boothdr.S 2020/09/02 04:55:39 1.1.1.3 @@ -1,10 +1,13 @@ #include -#include "i386asm.h" - - .text +#include + /* + * This section will be put first into .text. See also i386/ldscript. + */ + .section .text.start,"ax" + /* We should never be entered this way. */ .globl start,_start start: @@ -14,9 +17,9 @@ _start: /* MultiBoot header - see multiboot.h. */ #define MULTIBOOT_MAGIC 0x1BADB002 #ifdef __ELF__ -#define MULTIBOOT_FLAGS 0x00000002 +#define MULTIBOOT_FLAGS 0x00000003 #else /* __ELF__ */ -#define MULTIBOOT_FLAGS 0x00010002 +#define MULTIBOOT_FLAGS 0x00010003 #endif /* __ELF__ */ P2ALIGN(2) boot_hdr: @@ -36,6 +39,19 @@ boot_hdr: #endif /* __ELF__ */ boot_entry: + /* use segmentation to offset ourself. */ + lgdt boot_gdt_descr - KERNELBASE + ljmp $8,$0f +0: + movw $0,%ax + movw %ax,%ds + movw %ax,%es + movw %ax,%fs + movw %ax,%gs + movw $16,%ax + movw %ax,%ds + movw %ax,%es + movw %ax,%ss /* Switch to our own interrupt stack. */ movl $_intstack+INTSTACK_SIZE,%esp @@ -55,8 +71,49 @@ boot_entry: /* Push the boot_info pointer to be the second argument. */ pushl %ebx + /* Fix ifunc entries */ + movl $__rel_iplt_start,%esi + movl $__rel_iplt_end,%edi +iplt_cont: + cmpl %edi,%esi + jae iplt_done + movl (%esi),%ebx /* r_offset */ + movb 4(%esi),%al /* info */ + cmpb $42,%al /* IRELATIVE */ + jnz iplt_next + call *(%ebx) /* call ifunc */ + movl %eax,(%ebx) /* fixed address */ +iplt_next: + addl $8,%esi + jmp iplt_cont +iplt_done: + /* Jump into C code. */ call EXT(c_boot_entry) .comm _intstack,INTSTACK_SIZE +.align 16 + .word 0 +boot_gdt_descr: + .word 3*8+7 + .long boot_gdt - KERNELBASE +.align 16 +boot_gdt: + /* 0 */ + .quad 0 + /* boot CS = 8 */ + .word 0xffff + .word (-KERNELBASE) & 0xffff + .byte ((-KERNELBASE) >> 16) & 0xff + .byte 0x9a + .byte 0xcf + .byte ((-KERNELBASE) >> 24) & 0xff + /* boot DS = 8 */ + .word 0xffff + .word (-KERNELBASE) & 0xffff + .byte ((-KERNELBASE) >> 16) & 0xff + .byte 0x92 + .byte 0xcf + .byte ((-KERNELBASE) >> 24) & 0xff +