2009-06-29 13:37:39 +00:00
|
|
|
/*
|
|
|
|
* Multiboot Option ROM
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-07-16 20:47:01 +00:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2009-06-29 13:37:39 +00:00
|
|
|
*
|
|
|
|
* Copyright Novell Inc, 2009
|
|
|
|
* Authors: Alexander Graf <agraf@suse.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NO_QEMU_PROTOS
|
|
|
|
#include "../../hw/fw_cfg.h"
|
|
|
|
|
|
|
|
#define BIOS_CFG_IOPORT_CFG 0x510
|
|
|
|
#define BIOS_CFG_IOPORT_DATA 0x511
|
|
|
|
|
|
|
|
#define MULTIBOOT_MAGIC 0x2badb002
|
|
|
|
|
2009-11-12 20:53:12 +00:00
|
|
|
#define GS_PROT_JUMP 0
|
|
|
|
#define GS_GDT_DESC 6
|
|
|
|
|
|
|
|
/* Break the translation block flow so -d cpu shows us values */
|
|
|
|
#define DEBUG_HERE \
|
|
|
|
jmp 1f; \
|
|
|
|
1:
|
|
|
|
|
2009-06-29 13:37:39 +00:00
|
|
|
/* Read a variable from the fw_cfg device.
|
|
|
|
Clobbers: %edx
|
|
|
|
Out: %eax */
|
|
|
|
.macro read_fw VAR
|
|
|
|
mov $\VAR, %ax
|
|
|
|
mov $BIOS_CFG_IOPORT_CFG, %dx
|
|
|
|
outw %ax, (%dx)
|
|
|
|
mov $BIOS_CFG_IOPORT_DATA, %dx
|
|
|
|
inb (%dx), %al
|
|
|
|
shl $8, %eax
|
|
|
|
inb (%dx), %al
|
|
|
|
shl $8, %eax
|
|
|
|
inb (%dx), %al
|
|
|
|
shl $8, %eax
|
|
|
|
inb (%dx), %al
|
|
|
|
bswap %eax
|
|
|
|
.endm
|
|
|
|
|
2009-11-12 20:53:12 +00:00
|
|
|
/*
|
|
|
|
* Read a blob from the fw_cfg device.
|
|
|
|
* Requires _ADDR, _SIZE and _DATA values for the parameter.
|
|
|
|
*
|
|
|
|
* Clobbers: %eax, %edx, %es, %ecx, %edi
|
|
|
|
*/
|
|
|
|
#define read_fw_blob(var) \
|
|
|
|
read_fw var ## _ADDR; \
|
|
|
|
mov %eax, %edi; \
|
|
|
|
read_fw var ## _SIZE; \
|
|
|
|
mov %eax, %ecx; \
|
|
|
|
mov $var ## _DATA, %ax; \
|
|
|
|
mov $BIOS_CFG_IOPORT_CFG, %edx; \
|
|
|
|
outw %ax, (%dx); \
|
|
|
|
mov $BIOS_CFG_IOPORT_DATA, %dx; \
|
|
|
|
cld; \
|
|
|
|
DEBUG_HERE \
|
|
|
|
rep insb (%dx), %es:(%edi);
|
|
|
|
|
2009-06-29 13:37:39 +00:00
|
|
|
.code16
|
|
|
|
.text
|
|
|
|
.global _start
|
|
|
|
_start:
|
|
|
|
.short 0xaa55
|
2009-11-12 20:53:12 +00:00
|
|
|
.byte (_end - _start) / 512
|
2009-06-29 13:37:39 +00:00
|
|
|
push %eax
|
|
|
|
push %ds
|
|
|
|
|
|
|
|
/* setup ds so we can access the IVT */
|
|
|
|
xor %ax, %ax
|
|
|
|
mov %ax, %ds
|
|
|
|
|
|
|
|
/* install our int 19 handler */
|
|
|
|
movw $int19_handler, (0x19*4)
|
|
|
|
mov %cs, (0x19*4+2)
|
|
|
|
|
|
|
|
pop %ds
|
|
|
|
pop %eax
|
|
|
|
lret
|
|
|
|
|
|
|
|
int19_handler:
|
|
|
|
/* DS = CS */
|
|
|
|
movw %cs, %ax
|
|
|
|
movw %ax, %ds
|
|
|
|
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
run_multiboot:
|
|
|
|
|
|
|
|
cli
|
|
|
|
cld
|
|
|
|
|
|
|
|
mov %cs, %eax
|
|
|
|
shl $0x4, %eax
|
|
|
|
|
2009-11-12 20:53:12 +00:00
|
|
|
/* set up a long jump descriptor that is PC relative */
|
2009-06-29 13:37:39 +00:00
|
|
|
|
2009-11-12 20:53:12 +00:00
|
|
|
/* move stack memory to %gs */
|
|
|
|
mov %ss, %ecx
|
|
|
|
shl $0x4, %ecx
|
|
|
|
mov %esp, %ebx
|
|
|
|
add %ebx, %ecx
|
|
|
|
sub $0x20, %ecx
|
|
|
|
sub $0x30, %esp
|
|
|
|
shr $0x4, %ecx
|
|
|
|
mov %cx, %gs
|
|
|
|
|
|
|
|
/* now push the indirect jump decriptor there */
|
2009-06-29 13:37:39 +00:00
|
|
|
mov (prot_jump), %ebx
|
|
|
|
add %eax, %ebx
|
2009-11-12 20:53:12 +00:00
|
|
|
movl %ebx, %gs:GS_PROT_JUMP
|
|
|
|
mov $8, %bx
|
|
|
|
movw %bx, %gs:GS_PROT_JUMP + 4
|
|
|
|
|
|
|
|
/* fix the gdt descriptor to be PC relative */
|
|
|
|
movw (gdt_desc), %bx
|
|
|
|
movw %bx, %gs:GS_GDT_DESC
|
|
|
|
movl (gdt_desc+2), %ebx
|
|
|
|
add %eax, %ebx
|
|
|
|
movl %ebx, %gs:GS_GDT_DESC + 2
|
|
|
|
|
|
|
|
/* Read the bootinfo struct into RAM */
|
|
|
|
read_fw_blob(FW_CFG_INITRD)
|
2009-06-29 13:37:39 +00:00
|
|
|
|
|
|
|
/* FS = bootinfo_struct */
|
|
|
|
read_fw FW_CFG_INITRD_ADDR
|
|
|
|
shr $4, %eax
|
|
|
|
mov %ax, %fs
|
|
|
|
|
|
|
|
/* ES = mmap_addr */
|
2009-11-12 20:53:12 +00:00
|
|
|
mov %eax, %fs:0x48
|
2009-06-29 13:37:39 +00:00
|
|
|
shr $4, %eax
|
|
|
|
mov %ax, %es
|
|
|
|
|
|
|
|
/* Initialize multiboot mmap structs using int 0x15(e820) */
|
|
|
|
xor %ebx, %ebx
|
|
|
|
/* mmap start after first size */
|
|
|
|
movl $4, %edi
|
|
|
|
|
|
|
|
mmap_loop:
|
|
|
|
/* entry size (mmap struct) & max buffer size (int15) */
|
|
|
|
movl $20, %ecx
|
|
|
|
/* store entry size */
|
multiboot.S patch for old as(1) (was: Re: [Qemu-devel] Some OpenBSD/amd64 build fixes)
On Wed, Sep 23, 2009 at 10:55:02PM +0200, Juergen Lock wrote:
> On Wed, Sep 23, 2009 at 09:31:16PM +0100, Laurence Tratt wrote:
>[...]
> > then the above error doesn't occur, but
> > pc-bios/optionrom/multiboot.S dies as follows:
> >
> > $
> > AS optionrom/multiboot.o
> > multiboot.S: Assembler messages:
> > multiboot.S:116: Error: `%es:-4(%edi)' is not a valid 16 bit base/index
> > expression
> > $
> >
> > What little Intel assembler I ever knew has long since departed from my
> > brain, so I don't know why that error occurs, nor what a fix might be.
> >
> It occurs because of too old binutils (as(1) in this case), on FreeBSD
> we now have a port for newer ones,
> http://www.freshports.org/devel/binutils
> so I depend on that and have the optionrom Makefile use the new as
> like this: (the first change wrt CFLAGS is unrelated and has probably
> been fixed in the meantime; it caused gmake to complain about
> recursive use of CFLAGS.)
>
> Index: qemu/pc-bios/optionrom/Makefile
> @@ -9,10 +9,13 @@
>
> CFLAGS = -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin
> CFLAGS += -I$(SRC_PATH)
> -CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector,"")
> +CFLAGS := $(CFLAGS) $(call cc-option, $(CFLAGS), -fno-stack-protector,"")
>
> build-all: multiboot.bin
>
> +%.o: %.S
> + $(CC) -E $(CFLAGS) -o - -c $< |${LOCALBASE}/bin/as -V -Qy -o $@
> +
> %.img: %.o
> $(call quiet-command,$(LD) -Ttext 0 -e _start -s -o $@ $<," Building $(TARGET_DIR)$@")
>
That patch didn't seem to help on OpenBSD so I now finally got around
making another one that just emits the bytes of the offending insn
instead so people can keep using old assemblers:
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-13 21:29:12 +00:00
|
|
|
/* old as(1) doesn't like this insn so emit the bytes instead:
|
2009-06-29 13:37:39 +00:00
|
|
|
movl %ecx, %es:-4(%edi)
|
multiboot.S patch for old as(1) (was: Re: [Qemu-devel] Some OpenBSD/amd64 build fixes)
On Wed, Sep 23, 2009 at 10:55:02PM +0200, Juergen Lock wrote:
> On Wed, Sep 23, 2009 at 09:31:16PM +0100, Laurence Tratt wrote:
>[...]
> > then the above error doesn't occur, but
> > pc-bios/optionrom/multiboot.S dies as follows:
> >
> > $
> > AS optionrom/multiboot.o
> > multiboot.S: Assembler messages:
> > multiboot.S:116: Error: `%es:-4(%edi)' is not a valid 16 bit base/index
> > expression
> > $
> >
> > What little Intel assembler I ever knew has long since departed from my
> > brain, so I don't know why that error occurs, nor what a fix might be.
> >
> It occurs because of too old binutils (as(1) in this case), on FreeBSD
> we now have a port for newer ones,
> http://www.freshports.org/devel/binutils
> so I depend on that and have the optionrom Makefile use the new as
> like this: (the first change wrt CFLAGS is unrelated and has probably
> been fixed in the meantime; it caused gmake to complain about
> recursive use of CFLAGS.)
>
> Index: qemu/pc-bios/optionrom/Makefile
> @@ -9,10 +9,13 @@
>
> CFLAGS = -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin
> CFLAGS += -I$(SRC_PATH)
> -CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector,"")
> +CFLAGS := $(CFLAGS) $(call cc-option, $(CFLAGS), -fno-stack-protector,"")
>
> build-all: multiboot.bin
>
> +%.o: %.S
> + $(CC) -E $(CFLAGS) -o - -c $< |${LOCALBASE}/bin/as -V -Qy -o $@
> +
> %.img: %.o
> $(call quiet-command,$(LD) -Ttext 0 -e _start -s -o $@ $<," Building $(TARGET_DIR)$@")
>
That patch didn't seem to help on OpenBSD so I now finally got around
making another one that just emits the bytes of the offending insn
instead so people can keep using old assemblers:
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-13 21:29:12 +00:00
|
|
|
*/
|
|
|
|
.dc.b 0x26,0x67,0x66,0x89,0x4f,0xfc
|
2009-06-29 13:37:39 +00:00
|
|
|
/* e820 */
|
|
|
|
movl $0x0000e820, %eax
|
|
|
|
/* 'SMAP' magic */
|
|
|
|
movl $0x534d4150, %edx
|
|
|
|
int $0x15
|
|
|
|
|
|
|
|
mmap_check_entry:
|
|
|
|
/* last entry? then we're done */
|
|
|
|
jb mmap_done
|
|
|
|
and %bx, %bx
|
|
|
|
jz mmap_done
|
|
|
|
/* valid entry, so let's loop on */
|
|
|
|
|
|
|
|
mmap_store_entry:
|
|
|
|
/* %ax = entry_number * 24 */
|
|
|
|
mov $24, %ax
|
|
|
|
mul %bx
|
|
|
|
mov %ax, %di
|
|
|
|
movw %di, %fs:0x2c
|
|
|
|
/* %di = 4 + (entry_number * 24) */
|
|
|
|
add $4, %di
|
|
|
|
jmp mmap_loop
|
|
|
|
|
|
|
|
mmap_done:
|
|
|
|
real_to_prot:
|
|
|
|
/* Load the GDT before going into protected mode */
|
|
|
|
lgdt:
|
2009-11-12 20:53:12 +00:00
|
|
|
data32 lgdt %gs:GS_GDT_DESC
|
2009-06-29 13:37:39 +00:00
|
|
|
|
|
|
|
/* get us to protected mode now */
|
|
|
|
movl $1, %eax
|
|
|
|
movl %eax, %cr0
|
|
|
|
|
|
|
|
/* the LJMP sets CS for us and gets us to 32-bit */
|
|
|
|
ljmp:
|
2009-11-12 20:53:12 +00:00
|
|
|
data32 ljmp *%gs:GS_PROT_JUMP
|
2009-06-29 13:37:39 +00:00
|
|
|
|
|
|
|
prot_mode:
|
|
|
|
.code32
|
|
|
|
|
|
|
|
/* initialize all other segments */
|
|
|
|
movl $0x10, %eax
|
|
|
|
movl %eax, %ss
|
|
|
|
movl %eax, %ds
|
|
|
|
movl %eax, %es
|
|
|
|
movl %eax, %fs
|
|
|
|
movl %eax, %gs
|
|
|
|
|
2009-11-12 20:53:12 +00:00
|
|
|
/* Read the kernel and modules into RAM */
|
|
|
|
read_fw_blob(FW_CFG_KERNEL)
|
|
|
|
|
2009-06-29 13:37:39 +00:00
|
|
|
/* Jump off to the kernel */
|
2009-11-12 20:53:12 +00:00
|
|
|
read_fw FW_CFG_KERNEL_ENTRY
|
2009-06-29 13:37:39 +00:00
|
|
|
mov %eax, %ecx
|
|
|
|
|
|
|
|
/* EBX contains a pointer to the bootinfo struct */
|
|
|
|
read_fw FW_CFG_INITRD_ADDR
|
|
|
|
movl %eax, %ebx
|
|
|
|
|
|
|
|
/* EAX has to contain the magic */
|
|
|
|
movl $MULTIBOOT_MAGIC, %eax
|
|
|
|
ljmp2:
|
|
|
|
jmp *%ecx
|
|
|
|
|
|
|
|
/* Variables */
|
|
|
|
.align 4, 0
|
|
|
|
prot_jump: .long prot_mode
|
|
|
|
.short 8
|
|
|
|
|
|
|
|
.align 4, 0
|
|
|
|
gdt:
|
|
|
|
/* 0x00 */
|
|
|
|
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
|
|
|
|
|
|
|
/* 0x08: code segment (base=0, limit=0xfffff, type=32bit code exec/read, DPL=0, 4k) */
|
|
|
|
.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00
|
|
|
|
|
|
|
|
/* 0x10: data segment (base=0, limit=0xfffff, type=32bit data read/write, DPL=0, 4k) */
|
|
|
|
.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00
|
|
|
|
|
|
|
|
/* 0x18: code segment (base=0, limit=0x0ffff, type=16bit code exec/read/conf, DPL=0, 1b) */
|
|
|
|
.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00
|
|
|
|
|
|
|
|
/* 0x20: data segment (base=0, limit=0x0ffff, type=16bit data read/write, DPL=0, 1b) */
|
|
|
|
.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00
|
|
|
|
|
|
|
|
gdt_desc:
|
|
|
|
.short (5 * 8) - 1
|
|
|
|
.long gdt
|
|
|
|
|
|
|
|
.align 512, 0
|
|
|
|
_end:
|
|
|
|
|