summaryrefslogtreecommitdiffstats
path: root/arch/x86/lib
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/lib')
-rw-r--r--arch/x86/lib/.gitignore1
-rw-r--r--arch/x86/lib/Makefile10
-rw-r--r--arch/x86/lib/asm-offsets.c7
-rw-r--r--arch/x86/lib/barebox.lds.S161
-rw-r--r--arch/x86/lib/gdt.c38
-rw-r--r--arch/x86/lib/linux_start.S55
-rw-r--r--arch/x86/lib/memory.c49
-rw-r--r--arch/x86/lib/setjmp_32.S63
-rw-r--r--arch/x86/lib/setjmp_64.S63
9 files changed, 130 insertions, 317 deletions
diff --git a/arch/x86/lib/.gitignore b/arch/x86/lib/.gitignore
deleted file mode 100644
index d1165788c9..0000000000
--- a/arch/x86/lib/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-barebox.lds
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index 05e43f0f2b..d713065fd3 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -1,8 +1,4 @@
-extra-$(CONFIG_GENERIC_LINKER_SCRIPT) += barebox.lds
-ifneq ($(CONFIG_X86_EFI),y)
-obj-y += memory.o
-obj-y += gdt.o
-endif
+# SPDX-License-Identifier: GPL-2.0-only
-# needed, when running via a 16 bit BIOS
-obj-$(CONFIG_CMD_LINUX16) += linux_start.o
+obj-$(CONFIG_X86_32) += setjmp_32.o
+obj-$(CONFIG_X86_64) += setjmp_64.o
diff --git a/arch/x86/lib/asm-offsets.c b/arch/x86/lib/asm-offsets.c
index 0f9c47eaa9..caa4a289d8 100644
--- a/arch/x86/lib/asm-offsets.c
+++ b/arch/x86/lib/asm-offsets.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
/*
* Generate definitions needed by assembly language modules.
* This code generates raw asm output which is post-processed to extract
@@ -6,13 +7,7 @@
#include <linux/kbuild.h>
-#ifdef CONFIG_EFI_BOOTUP
int main(void)
{
return 0;
}
-#else
-void common(void)
-{
-}
-#endif
diff --git a/arch/x86/lib/barebox.lds.S b/arch/x86/lib/barebox.lds.S
deleted file mode 100644
index b24c4807b5..0000000000
--- a/arch/x86/lib/barebox.lds.S
+++ /dev/null
@@ -1,161 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-#undef i386
-#include <asm-generic/barebox.lds.h>
-
-OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
-OUTPUT_ARCH(i386)
-ENTRY(_start)
-
-MEMORY
-{
- mbr(rwx): ORIGIN = TEXT_BASE, LENGTH = 2 * SECTOR_SIZE
- barebox (rwx) : ORIGIN = TEXT_BASE + SECTOR_SIZE, LENGTH = (256 * 1024 * 1024)
-}
-
-SECTIONS
-{
-#ifdef CONFIG_X86_HDBOOT
-
- .ramlayout : {
- boot_stack = INDIRECT_AREA;
- indirect_area = INDIRECT_AREA;
- }
- /* describing the main boot sector */
- .bootsector : AT (0) {
- *(.boot_start)
-
- . = 0x00b;
- /*
- * Maybe later on occupied by a "BIOS parameter block". So,
- * keep it free from code.
- * - BytesPerSector dw@0x000B
- * - SectorsPerCluster db@0x000D
- * - ReservedSectors dw@0x000E
- * - FatCopies db@0x0010
- * - RootDirEntries dw@0x0011
- * - NumSectors dw@0x0013
- * - MediaType db@0x0015
- * - SectorsPerFAT dw@0x0016
- * - SectorsPerTrack dw@0x0018
- * - NumberOfHeads dw@0x001A
- * - HiddenSectors dd@0x001C
- * - SectorsBig dd@0x0020
- */
- LONG(0);
-
- . = 0x024;
- *(.boot_code)
- *(.boot_data)
-
- /*
- * embed one "Disk Address Packet Structure" into the boot sector
- * This DAPS points to the 'indirect' sector to give the boot code
- * an idea what and where to load. Its content must be adapted
- * to the system it should run on, so, this structure must be
- * located at a well known offset.
- */
- . = PATCH_AREA;
- indirect_sector_lba = .;
- SHORT(0x0010); /* size of this structure */
- SHORT(0x0001); /* one sector */
- SHORT(indirect_area); /* where to store: offset */
- SHORT(0x0000); /* where to store: segment */
- /* the following values are filled by the installer */
- LONG(0x00000000); /* LBA start lower */
- LONG(0x00000000); /* LBA start upper */
-
- /* boot disk number used by upper layers */
- . = PATCH_AREA + PATCH_AREA_BOOT_DEV;
- boot_disk = .;
- BYTE(0x00); /* boot disk number (provided by the BIOS)
-
- /* information about the persistent environment storage */
- . = PATCH_AREA + PATCH_AREA_PERS_START;
- pers_env_storage = .;
- LONG(0x00000000); /* LBA start lower */
- LONG(0x00000000); /* LBA start upper */
-
- . = PATCH_AREA + PATCH_AREA_PERS_SIZE;
- pers_env_size = .;
- SHORT(PATCH_AREA_PERS_SIZE_UNUSED); /* size of this area in sectors */
-
- . = PATCH_AREA + PATCH_AREA_PERS_DRIVE;
- pers_env_drive = .;
- BYTE(0x00); /* used drive */
-
- /* partition table area (fixed location) */
- . = OFFSET_OF_PARTITION_TABLE;
- /* create an empty one */
- LONG(0x00000000); LONG(0x00000000); LONG(0x00000000); LONG(0x00000000);
- LONG(0x00000000); LONG(0x00000000); LONG(0x00000000); LONG(0x00000000);
- LONG(0x00000000); LONG(0x00000000); LONG(0x00000000); LONG(0x00000000);
- LONG(0x00000000); LONG(0x00000000); LONG(0x00000000); LONG(0x00000000);
-
- /* boot sector signature */
- . = OFFSET_OF_SIGNATURE;
- BYTE(0x55);
- BYTE(0xAA);
- /* end of the first sector */
-
- /*
- * The indirect sector starts here
- */
- . = SECTOR_SIZE;
- BYTE(MARK_DAPS_INVALID); /* mark the first entry invalid */
- BYTE(0x00);
- . = SECTOR_SIZE + 496;
- BYTE(MARK_DAPS_INVALID); /* mark the last entry invalid */
- BYTE(0x00);
- . = SECTOR_SIZE + 508;
- LONG(0x00000000); /* LBA start upper */
- } > mbr
-
- /* some real mode bootstrapping */
- .bootstrapping : AT ( LOADADDR(.bootsector) + SIZEOF(.bootsector) ) {
- *(.boot.head)
- *(.boot.text*)
- *(.boot.rodata*)
- *(.boot.data*)
- . = ALIGN(4);
- RO_DATA_SECTION
- } > barebox
-#endif
-
- /* the main barebox part (32 bit) */
- .text : AT ( LOADADDR(.bootstrapping) + SIZEOF(.bootstrapping) ) {
- /* do not align here! It may fails with the LOADADDR! */
- _stext = .;
- _text = .;
- *(.text_entry*)
- __bare_init_start = .;
- *(.text_bare_init*)
- __bare_init_end = .;
- *(.text*)
- . = ALIGN(4);
- *(.rodata*)
- . = ALIGN(4);
- _etext = .; /* End of text and rodata section */
- } > barebox
- BAREBOX_BARE_INIT_SIZE
-
- _sdata = .;
- .data : AT ( LOADADDR(.text) + SIZEOF(.text) ) {
- *(.data*)
- . = ALIGN(4);
- } > barebox
-
- .got : AT ( LOADADDR(.data) + SIZEOF (.data) ) {
- *(.got*)
- . = ALIGN(4);
- } > barebox
-
- _edata = .;
- .bss : {
- __bss_start = .;
- *(.bss*);
- *( COMMON )
- __bss_stop = .;
- _end = .;
- } > barebox
-}
diff --git a/arch/x86/lib/gdt.c b/arch/x86/lib/gdt.c
deleted file mode 100644
index 4cd1622b6b..0000000000
--- a/arch/x86/lib/gdt.c
+++ /dev/null
@@ -1,38 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-// SPDX-FileCopyrightText: 2009 Juergen Beisert, Pengutronix
-
-/**
- * @file
- * @brief Definition of the Global Descriptor Table
- */
-
-#include <types.h>
-#include <asm/modes.h>
-#include <asm/segment.h>
-
-/**
- * The 'Global Descriptor Table' used in barebox
- *
- * Note: This table must reachable by real and flat mode code
- */
-uint64_t gdt[] __attribute__((aligned(16))) __bootdata = {
- /* CS: code, read/execute, 4 GB, base 0 */
- [GDT_ENTRY_BOOT_CS] = GDT_ENTRY(0xc09b, 0, 0xfffff),
- /* DS: data, read/write, 4 GB, base 0 */
- [GDT_ENTRY_BOOT_DS] = GDT_ENTRY(0xc093, 0, 0xfffff),
- /* CS: for real mode calls */
- [GDT_ENTRY_REAL_CS] = GDT_ENTRY(0x009E, 0, 0x0ffff),
- /* DS: for real mode calls */
- [GDT_ENTRY_REAL_DS] = GDT_ENTRY(0x0092, 0, 0x0ffff),
- /* TSS: 32-bit tss, 104 bytes, base 4096 */
- /* We only have a TSS here to keep Intel VT happy;
- we don't actually use it for anything. */
- [GDT_ENTRY_BOOT_TSS] = GDT_ENTRY(0x0089, 4096, 103),
-};
-
-/**
- * Size of the GDT must be known to load it
- *
- * Note: This varibale must reachable by real and flat mode code
- */
-unsigned gdt_size __bootdata = sizeof(gdt);
diff --git a/arch/x86/lib/linux_start.S b/arch/x86/lib/linux_start.S
deleted file mode 100644
index 07be37fed4..0000000000
--- a/arch/x86/lib/linux_start.S
+++ /dev/null
@@ -1,55 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/* SPDX-FileCopyrightText: 2009 Juergen Beisert, Pengutronix */
-/* SPDX-FileCopyrightText: 1999-2008 Free Software Foundation, Inc. */
-
-/* Mostly stolen from the GRUB2 project */
-
-/**
- * @file
- * @brief Start the Linux real mode setup code
- *
- * Note: These functions are running in flat and real mode. Due to some
- * other restrictions these routines must running from an address
- * space below 0x10000
- */
-
-/*
- * void bios_start_linux(unsigned segment)
- *
- */
-
- .section .boot.text.bios_start_linux, "ax"
- .code32
- .globl bios_start_linux
- .type bios_start_linux, @function
-
- .extern prot_to_real
-
-bios_start_linux:
- /* 'prot_to_real' eats our eax content */
- movl %eax, %ebx
- addl $0x20, %eax
- movw %ax, setup_seg
-
- call prot_to_real
-
- .code16
-
- cli
- /* all segment registers are using the same segment */
- movw %bx, %ss
- movw %bx, %ds
- movw %bx, %es
- movw %bx, %fs
- movw %bx, %gs
-
- /* stack for the setup code (end of heap) */
- movw $0x9000, %sp
-
- /* do an 'ljmp' and never return */
- .byte 0xea
- .word 0
-setup_seg:
- .word 0
-
- .code32
diff --git a/arch/x86/lib/memory.c b/arch/x86/lib/memory.c
deleted file mode 100644
index 64fbbb9300..0000000000
--- a/arch/x86/lib/memory.c
+++ /dev/null
@@ -1,49 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-// SPDX-FileCopyrightText: 2009 Juergen Beisert, Pengutronix
-
-/* This code was inspired by the GRUB2 project. */
-
-/**
- * @file
- * @brief Memory management
- */
-
-#include <common.h>
-#include <init.h>
-#include <stdio.h>
-#include <memory.h>
-#include <asm/syslib.h>
-#include <asm-generic/memory_layout.h>
-
-/**
- * Handling of free memory
- *
- * Topics:
- * - areas used by BIOS code
- * - The 0xa0000... 0xfffff hole
- * - memory above 0x100000
- */
-
-int x86_start_barebox(void)
-{
-#ifdef CONFIG_MEMORY_LAYOUT_DEFAULT
- unsigned long memory_size;
-
- memory_size = bios_get_memsize();
- memory_size <<= 10; /* BIOS reports in kiB */
-
- /*
- * We do not want to conflict with the kernel. So, we keep the
- * area from 0x100000 ... 0xFFFFFF free from usage
- */
- if (memory_size >= (15 * 1024 * 1024 + MALLOC_SIZE))
- mem_malloc_init((void*)(16 * 1024 * 1024),
- (void*)(16 * 1024 * 1024 + MALLOC_SIZE - 1));
- else
- return -1;
-#else
- mem_malloc_init((void *)MALLOC_BASE,
- (void *)(MALLOC_BASE + MALLOC_SIZE - 1));
-#endif
- start_barebox();
-}
diff --git a/arch/x86/lib/setjmp_32.S b/arch/x86/lib/setjmp_32.S
new file mode 100644
index 0000000000..5814623f94
--- /dev/null
+++ b/arch/x86/lib/setjmp_32.S
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Written by H. Peter Anvin <hpa@zytor.com>
+ * Brought in from Linux v4.4 and modified for U-Boot
+ * From Linux arch/um/sys-i386/setjmp.S
+ */
+
+#define _REGPARM
+
+#include <linux/linkage.h>
+#include <asm-generic/pointer.h>
+
+.text
+.align 8
+
+/*
+ * The jmp_buf is assumed to contain the following, in order:
+ * %ebx
+ * %esp
+ * %ebp
+ * %esi
+ * %edi
+ * <return address>
+ */
+
+ENTRY(setjmp)
+
+ movl %eax, %edx
+ popl %ecx /* Return address, and adjust the stack */
+ xorl %eax, %eax /* Return value */
+ movl %ebx, (%edx)
+ movl %esp, 4(%edx) /* Post-return %esp! */
+ pushl %ecx /* Make the call/return stack happy */
+ movl %ebp, 8(%edx)
+ movl %esi, 12(%edx)
+ movl %edi, 16(%edx)
+ movl %ecx, 20(%edx) /* Return address */
+ ret
+
+ENDPROC(setjmp)
+
+ENTRY(longjmp)
+
+ xchgl %eax, %edx
+ movl (%edx), %ebx
+ movl 4(%edx), %esp
+ movl 8(%edx), %ebp
+ movl 12(%edx), %esi
+ movl 16(%edx), %edi
+ jmp *20(%edx)
+
+ENDPROC(longjmp)
+
+ENTRY(initjmp)
+
+ movl %edx, 20(%eax) /* Return address */
+ movl $0, 8(%edx) /* Base pointer */
+ sub $ASM_SZPTR, %ecx /* ESP - 4 has to be 16-byte aligned on entry */
+ movl %ecx, 4(%eax) /* Stack top */
+ xorl %eax, %eax /* Return value */
+ ret
+
+ENDPROC(initjmp)
diff --git a/arch/x86/lib/setjmp_64.S b/arch/x86/lib/setjmp_64.S
new file mode 100644
index 0000000000..bfa1521499
--- /dev/null
+++ b/arch/x86/lib/setjmp_64.S
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2018 Intel Corporation
+ *
+ * See arch/x86/include/asm/setjmp.h for jmp_buf format
+ */
+
+#include <linux/linkage.h>
+#include <asm-generic/pointer.h>
+
+.text
+.align 8
+
+ENTRY(setjmp)
+
+ pop %rcx
+ movq %rcx, (%rdi) /* Return address */
+ movq %rsp, 8(%rdi)
+ movq %rbp, 16(%rdi)
+ movq %rbx, 24(%rdi)
+ movq %r12, 32(%rdi)
+ movq %r13, 40(%rdi)
+ movq %r14, 48(%rdi)
+ movq %r15, 56(%rdi)
+ xorq %rax, %rax /* Direct invocation returns 0 */
+ jmpq *%rcx
+
+ENDPROC(setjmp)
+
+.align 8
+
+ENTRY(longjmp)
+
+ movq (%rdi), %rcx /* Return address */
+ movq 8(%rdi), %rsp
+ movq 16(%rdi), %rbp
+ movq 24(%rdi), %rbx
+ movq 32(%rdi), %r12
+ movq 40(%rdi), %r13
+ movq 48(%rdi), %r14
+ movq 56(%rdi), %r15
+
+ movq %rsi, %rax /* Value to be returned by setjmp() */
+ testq %rax, %rax /* cannot be 0 in this case */
+ jnz 1f
+ incq %rax /* Return 1 instead */
+1:
+ jmpq *%rcx
+
+ENDPROC(longjmp)
+
+.align 8
+
+ENTRY(initjmp)
+
+ movq %rsi, (%rdi) /* Return address */
+ movq $0, 16(%rdi) /* Base pointer */
+ sub $ASM_SZPTR, %rdx /* RSP - 8 has to be 16-byte aligned on entry */
+ movq %rdx, 8(%rdi) /* Stack top */
+ xorq %rax, %rax
+ ret
+
+ENDPROC(initjmp)