199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This file and its contents are supplied under the terms of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Common Development and Distribution License ("CDDL"), version 1.0.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * You may only use this file in accordance with the terms of version
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1.0 of the CDDL.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * A full copy of the text of the CDDL should have accompanied this
199767f8919635c4928607450d9e0abb932109ceToomas Soome * source. A copy of the CDDL is also available via the Internet at
199767f8919635c4928607450d9e0abb932109ceToomas Soome * http://www.illumos.org/license/CDDL.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright 2016 Toomas Soome <tsoome@me.com>
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Relocate is needed to support loading code which has to be located
199767f8919635c4928607450d9e0abb932109ceToomas Soome * below 1MB, as both BTX and loader are using low memory area.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Relocate and start loaded code. Since loaded code may need to be
199767f8919635c4928607450d9e0abb932109ceToomas Soome * placed in an already occupied memory area, the code is moved to a safe
199767f8919635c4928607450d9e0abb932109ceToomas Soome * memory area and then btx __exec will be called with physical pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to this area. __exec will set the pointer to %eax and call *%eax,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * so that on entry, we have the new "base" address in %eax.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Relocate will first set up and load new safe GDT to shut down BTX,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * then loaded code will be relocated to final memory location,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * then machine will be switched from 32-bit protected mode to 16-bit
199767f8919635c4928607450d9e0abb932109ceToomas Soome * protected mode following by switch to real mode with A20 enabled or
199767f8919635c4928607450d9e0abb932109ceToomas Soome * disabled. Finally the loaded code will be started and it will take
199767f8919635c4928607450d9e0abb932109ceToomas Soome * over the whole system.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * For now, the known "safe" memory area for relocate is 0x600,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the actual "free" memory is supposed to start from 0x500, leaving
199767f8919635c4928607450d9e0abb932109ceToomas Soome * first 0x100 bytes in reserve. As relocate code+data is very small,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * it will leave enough space to set up boot blocks to 0:7c00 or load
199767f8919635c4928607450d9e0abb932109ceToomas Soome * linux kernel below 1MB space.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * segment selectors
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_SCODE,0x8
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_SDATA,0x10
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_RCODE,0x18
199767f8919635c4928607450d9e0abb932109ceToomas Soome .set SEL_RDATA,0x20
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome .p2align 4
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocater
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocater:
199767f8919635c4928607450d9e0abb932109ceToomas Soome cli
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * set up GDT from new location
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax, %esi /* our base address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome add $(relocater.1-relocater), %eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp *%eax
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocater.1:
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* set up jump */
199767f8919635c4928607450d9e0abb932109ceToomas Soome lea (relocater.2-relocater)(%esi), %eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax, (jump_vector-relocater) (%esi)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* set up gdt */
199767f8919635c4928607450d9e0abb932109ceToomas Soome lea (gdt-relocater) (%esi), %eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax, (gdtaddr-relocater) (%esi)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* load gdt */
199767f8919635c4928607450d9e0abb932109ceToomas Soome lgdt (gdtdesc - relocater) (%esi)
199767f8919635c4928607450d9e0abb932109ceToomas Soome lidt (idt-relocater) (%esi)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* update cs */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ljmp *(jump_vector-relocater) (%esi)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome .code32
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocater.2:
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorl %eax, %eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $SEL_SDATA, %al
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %ss
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %ds
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %es
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %fs
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %gs
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %cr0, %eax /* disable paging */
199767f8919635c4928607450d9e0abb932109ceToomas Soome andl $~0x80000000,%eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax, %cr0
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorl %ecx, %ecx /* flush TLB */
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ecx, %cr3
199767f8919635c4928607450d9e0abb932109ceToomas Soome cld
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * relocate data loop. load source, dest and size from
199767f8919635c4928607450d9e0abb932109ceToomas Soome * relocater_data[i], 0 value will stop the loop.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * registers used for move: %esi, %edi, %ecx.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * %ebx to keep base
199767f8919635c4928607450d9e0abb932109ceToomas Soome * %edx for relocater_data offset
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %esi, %ebx /* base address */
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorl %edx, %edx
199767f8919635c4928607450d9e0abb932109ceToomas Soomeloop.1:
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl (relocater_data-relocater)(%ebx, %edx, 4), %eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome testl %eax, %eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz loop.2
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl (relocater_data-relocater)(%ebx, %edx, 4), %esi
199767f8919635c4928607450d9e0abb932109ceToomas Soome inc %edx
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl (relocater_data-relocater)(%ebx, %edx, 4), %edi
199767f8919635c4928607450d9e0abb932109ceToomas Soome inc %edx
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl (relocater_data-relocater)(%ebx, %edx, 4), %ecx
199767f8919635c4928607450d9e0abb932109ceToomas Soome inc %edx
199767f8919635c4928607450d9e0abb932109ceToomas Soome rep
199767f8919635c4928607450d9e0abb932109ceToomas Soome movsb
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp loop.1
199767f8919635c4928607450d9e0abb932109ceToomas Soomeloop.2:
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %ebx, %esi /* restore esi */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * data is relocated, switch to 16-bit mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome lea (relocater.3-relocater)(%esi), %eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax, (jump_vector-relocater) (%esi)
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl $SEL_RCODE, %eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax, (jump_vector-relocater+4) (%esi)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome ljmp *(jump_vector-relocater) (%esi)
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocater.3:
199767f8919635c4928607450d9e0abb932109ceToomas Soome .code16
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw $SEL_RDATA, %ax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %ds
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %es
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %fs
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %gs
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %ss
199767f8919635c4928607450d9e0abb932109ceToomas Soome lidt (idt-relocater) (%esi)
199767f8919635c4928607450d9e0abb932109ceToomas Soome lea (relocater.4-relocater)(%esi), %eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax, (jump_vector-relocater) (%esi)
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorl %eax, %eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax, (jump_vector-relocater+4) (%esi)
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* clear PE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %cr0, %eax
199767f8919635c4928607450d9e0abb932109ceToomas Soome dec %al
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax, %cr0
199767f8919635c4928607450d9e0abb932109ceToomas Soome ljmp *(jump_vector-relocater) (%esi)
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocater.4:
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorw %ax, %ax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %ds
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %es
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %fs
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %gs
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %ss
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * set real mode irq offsets
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw $0x7008,%bx
199767f8919635c4928607450d9e0abb932109ceToomas Soome in $0x21,%al # Save master
199767f8919635c4928607450d9e0abb932109ceToomas Soome push %ax # IMR
199767f8919635c4928607450d9e0abb932109ceToomas Soome in $0xa1,%al # Save slave
199767f8919635c4928607450d9e0abb932109ceToomas Soome push %ax # IMR
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x11,%al # ICW1 to
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0x20 # master,
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0xa0 # slave
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb %bl,%al # ICW2 to
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0x21 # master
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb %bh,%al # ICW2 to
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0xa1 # slave
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x4,%al # ICW3 to
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0x21 # master
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x2,%al # ICW3 to
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0xa1 # slave
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb $0x1,%al # ICW4 to
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0x21 # master,
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0xa1 # slave
199767f8919635c4928607450d9e0abb932109ceToomas Soome pop %ax # Restore slave
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0xa1 # IMR
199767f8919635c4928607450d9e0abb932109ceToomas Soome pop %ax # Restore master
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al,$0x21 # IMR
199767f8919635c4928607450d9e0abb932109ceToomas Soome # done
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Should A20 be left enabled?
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* movw imm16, %ax */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0xb8
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_a20_enabled
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_a20_enabled:
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome test %ax, %ax
199767f8919635c4928607450d9e0abb932109ceToomas Soome jnz a20_done
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw $0xa00, %ax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %sp
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %bp
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Disable A20 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw $0x2400, %ax
199767f8919635c4928607450d9e0abb932109ceToomas Soome int $0x15
199767f8919635c4928607450d9e0abb932109ceToomas Soome# jnc a20_done
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome call a20_check_state
199767f8919635c4928607450d9e0abb932109ceToomas Soome testb %al, %al
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz a20_done
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome inb $0x92
199767f8919635c4928607450d9e0abb932109ceToomas Soome andb $(~0x03), %al
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb $0x92
199767f8919635c4928607450d9e0abb932109ceToomas Soome jmp a20_done
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomea20_check_state:
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw $100, %cx
199767f8919635c4928607450d9e0abb932109ceToomas Soome1:
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorw %ax, %ax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %ds
199767f8919635c4928607450d9e0abb932109ceToomas Soome decw %ax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %es
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorw %ax, %ax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw $0x8000, %ax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %si
199767f8919635c4928607450d9e0abb932109ceToomas Soome addw $0x10, %ax
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %di
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb %ds:(%si), %dl
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb %es:(%di), %al
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb %al, %dh
199767f8919635c4928607450d9e0abb932109ceToomas Soome decb %dh
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb %dh, %ds:(%si)
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al, $0x80
199767f8919635c4928607450d9e0abb932109ceToomas Soome outb %al, $0x80
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb %es:(%di), %dh
199767f8919635c4928607450d9e0abb932109ceToomas Soome subb %dh, %al
199767f8919635c4928607450d9e0abb932109ceToomas Soome xorb $1, %al
199767f8919635c4928607450d9e0abb932109ceToomas Soome movb %dl, %ds:(%si)
199767f8919635c4928607450d9e0abb932109ceToomas Soome testb %al, %al
199767f8919635c4928607450d9e0abb932109ceToomas Soome jz a20_done
199767f8919635c4928607450d9e0abb932109ceToomas Soome loop 1b
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret
199767f8919635c4928607450d9e0abb932109ceToomas Soomea20_done:
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * set up registers
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* movw imm16, %ax. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0xb8
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_ds
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_ds: .word 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %ds
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* movw imm16, %ax. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0xb8
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_es
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_es: .word 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %es
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* movw imm16, %ax. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0xb8
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_fs
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_fs: .word 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %fs
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* movw imm16, %ax. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0xb8
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_gs
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_gs: .word 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %gs
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* movw imm16, %ax. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0xb8
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_ss
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_ss: .word 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome movw %ax, %ss
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* movw imm16, %ax. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0xb8
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_sp
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_sp: .word 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome movzwl %ax, %esp
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* movw imm32, %eax. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x66, 0xb8
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_esi
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_esi: .long 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome movl %eax, %esi
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* movw imm32, %edx. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x66, 0xba
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_edx
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_edx: .long 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* movw imm32, %ebx. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x66, 0xbb
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_ebx
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_ebx: .long 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* movw imm32, %eax. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x66, 0xb8
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_eax
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_eax: .long 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* movw imm32, %ebp. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x66, 0xbd
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_ebp
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_ebp: .long 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome sti
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0xea /* ljmp */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_ip
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_ip:
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocator_cs
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocator_cs:
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* GDT to reset BTX */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .code32
199767f8919635c4928607450d9e0abb932109ceToomas Soome .p2align 4
199767f8919635c4928607450d9e0abb932109ceToomas Soomejump_vector: .long 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long SEL_SCODE
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomegdt: .word 0x0, 0x0 /* null entry */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x0, 0x0, 0x0, 0x0
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff, 0x0 /* SEL_SCODE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x0, 0x9a, 0xcf, 0x0
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff, 0x0 /* SEL_SDATA */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x0, 0x92, 0xcf, 0x0
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff, 0x0 /* SEL_RCODE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x0, 0x9a, 0x0f, 0x0
199767f8919635c4928607450d9e0abb932109ceToomas Soome .word 0xffff, 0x0 /* SEL_RDATA */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .byte 0x0, 0x92, 0x0f, 0x0
199767f8919635c4928607450d9e0abb932109ceToomas Soomegdt.1:
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomegdtdesc: .word gdt.1 - gdt - 1 /* limit */
199767f8919635c4928607450d9e0abb932109ceToomas Soomegdtaddr: .long 0 /* base */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeidt: .word 0x3ff
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocater_data
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* reserve space for 3 entries */
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocater_data:
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long 0 /* src */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long 0 /* dest */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long 0 /* size */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long 0 /* src */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long 0 /* dest */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long 0 /* size */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long 0 /* src */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long 0 /* dest */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long 0 /* size */
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome .globl relocater_size
199767f8919635c4928607450d9e0abb932109ceToomas Soomerelocater_size:
199767f8919635c4928607450d9e0abb932109ceToomas Soome .long relocater_size-relocater