Revision 57a46d05
b/hw/fw_cfg.h | ||
---|---|---|
20 | 20 |
#define FW_CFG_KERNEL_ENTRY 0x10 |
21 | 21 |
#define FW_CFG_KERNEL_DATA 0x11 |
22 | 22 |
#define FW_CFG_INITRD_DATA 0x12 |
23 |
#define FW_CFG_MAX_ENTRY 0x13 |
|
23 |
#define FW_CFG_CMDLINE_ADDR 0x13 |
|
24 |
#define FW_CFG_CMDLINE_SIZE 0x14 |
|
25 |
#define FW_CFG_CMDLINE_DATA 0x15 |
|
26 |
#define FW_CFG_SETUP_ADDR 0x16 |
|
27 |
#define FW_CFG_SETUP_SIZE 0x17 |
|
28 |
#define FW_CFG_SETUP_DATA 0x18 |
|
29 |
#define FW_CFG_MAX_ENTRY 0x19 |
|
24 | 30 |
|
25 | 31 |
#define FW_CFG_WRITE_CHANNEL 0x4000 |
26 | 32 |
#define FW_CFG_ARCH_LOCAL 0x8000 |
b/hw/pc.c | ||
---|---|---|
487 | 487 |
return fw_cfg; |
488 | 488 |
} |
489 | 489 |
|
490 |
/* Generate an initial boot sector which sets state and jump to |
|
491 |
a specified vector */ |
|
492 |
static void generate_bootsect(uint32_t gpr[8], uint16_t segs[6], uint16_t ip) |
|
493 |
{ |
|
494 |
uint8_t rom[512], *p, *reloc; |
|
495 |
uint8_t sum; |
|
496 |
int i; |
|
497 |
|
|
498 |
memset(rom, 0, sizeof(rom)); |
|
499 |
|
|
500 |
p = rom; |
|
501 |
/* Make sure we have an option rom signature */ |
|
502 |
*p++ = 0x55; |
|
503 |
*p++ = 0xaa; |
|
504 |
|
|
505 |
/* ROM size in sectors*/ |
|
506 |
*p++ = 1; |
|
507 |
|
|
508 |
/* Hook int19 */ |
|
509 |
|
|
510 |
*p++ = 0x50; /* push ax */ |
|
511 |
*p++ = 0x1e; /* push ds */ |
|
512 |
*p++ = 0x31; *p++ = 0xc0; /* xor ax, ax */ |
|
513 |
*p++ = 0x8e; *p++ = 0xd8; /* mov ax, ds */ |
|
514 |
|
|
515 |
*p++ = 0xc7; *p++ = 0x06; /* movvw _start,0x64 */ |
|
516 |
*p++ = 0x64; *p++ = 0x00; |
|
517 |
reloc = p; |
|
518 |
*p++ = 0x00; *p++ = 0x00; |
|
519 |
|
|
520 |
*p++ = 0x8c; *p++ = 0x0e; /* mov cs,0x66 */ |
|
521 |
*p++ = 0x66; *p++ = 0x00; |
|
522 |
|
|
523 |
*p++ = 0x1f; /* pop ds */ |
|
524 |
*p++ = 0x58; /* pop ax */ |
|
525 |
*p++ = 0xcb; /* lret */ |
|
526 |
|
|
527 |
/* Actual code */ |
|
528 |
*reloc = (p - rom); |
|
529 |
|
|
530 |
*p++ = 0xfa; /* CLI */ |
|
531 |
*p++ = 0xfc; /* CLD */ |
|
532 |
|
|
533 |
for (i = 0; i < 6; i++) { |
|
534 |
if (i == 1) /* Skip CS */ |
|
535 |
continue; |
|
536 |
|
|
537 |
*p++ = 0xb8; /* MOV AX,imm16 */ |
|
538 |
*p++ = segs[i]; |
|
539 |
*p++ = segs[i] >> 8; |
|
540 |
*p++ = 0x8e; /* MOV <seg>,AX */ |
|
541 |
*p++ = 0xc0 + (i << 3); |
|
542 |
} |
|
543 |
|
|
544 |
for (i = 0; i < 8; i++) { |
|
545 |
*p++ = 0x66; /* 32-bit operand size */ |
|
546 |
*p++ = 0xb8 + i; /* MOV <reg>,imm32 */ |
|
547 |
*p++ = gpr[i]; |
|
548 |
*p++ = gpr[i] >> 8; |
|
549 |
*p++ = gpr[i] >> 16; |
|
550 |
*p++ = gpr[i] >> 24; |
|
551 |
} |
|
552 |
|
|
553 |
*p++ = 0xea; /* JMP FAR */ |
|
554 |
*p++ = ip; /* IP */ |
|
555 |
*p++ = ip >> 8; |
|
556 |
*p++ = segs[1]; /* CS */ |
|
557 |
*p++ = segs[1] >> 8; |
|
558 |
|
|
559 |
/* sign rom */ |
|
560 |
sum = 0; |
|
561 |
for (i = 0; i < (sizeof(rom) - 1); i++) |
|
562 |
sum += rom[i]; |
|
563 |
rom[sizeof(rom) - 1] = -sum; |
|
564 |
|
|
565 |
rom_add_blob("linux-bootsect", rom, sizeof(rom), |
|
566 |
PC_ROM_MIN_OPTION, PC_ROM_MAX, PC_ROM_ALIGN); |
|
567 |
} |
|
568 |
|
|
569 | 490 |
static long get_file_size(FILE *f) |
570 | 491 |
{ |
571 | 492 |
long where, size; |
... | ... | |
812 | 733 |
target_phys_addr_t max_ram_size) |
813 | 734 |
{ |
814 | 735 |
uint16_t protocol; |
815 |
uint32_t gpr[8]; |
|
816 |
uint16_t seg[6]; |
|
817 |
uint16_t real_seg; |
|
818 | 736 |
int setup_size, kernel_size, initrd_size = 0, cmdline_size; |
819 | 737 |
uint32_t initrd_max; |
820 |
uint8_t header[8192], *setup, *kernel; |
|
738 |
uint8_t header[8192], *setup, *kernel, *initrd_data;
|
|
821 | 739 |
target_phys_addr_t real_addr, prot_addr, cmdline_addr, initrd_addr = 0; |
822 | 740 |
FILE *f; |
823 | 741 |
char *vmode; |
... | ... | |
886 | 804 |
if (initrd_max >= max_ram_size-ACPI_DATA_SIZE) |
887 | 805 |
initrd_max = max_ram_size-ACPI_DATA_SIZE-1; |
888 | 806 |
|
889 |
/* kernel command line */ |
|
890 |
rom_add_blob_fixed("cmdline", kernel_cmdline, |
|
891 |
strlen(kernel_cmdline)+1, cmdline_addr); |
|
807 |
fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr); |
|
808 |
fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline)+1); |
|
809 |
fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA, |
|
810 |
(uint8_t*)strdup(kernel_cmdline), |
|
811 |
strlen(kernel_cmdline)+1); |
|
892 | 812 |
|
893 | 813 |
if (protocol >= 0x202) { |
894 | 814 |
stl_p(header+0x228, cmdline_addr); |
... | ... | |
937 | 857 |
|
938 | 858 |
initrd_size = get_image_size(initrd_filename); |
939 | 859 |
initrd_addr = (initrd_max-initrd_size) & ~4095; |
940 |
rom_add_file_fixed(initrd_filename, initrd_addr); |
|
860 |
|
|
861 |
initrd_data = qemu_malloc(initrd_size); |
|
862 |
load_image(initrd_filename, initrd_data); |
|
863 |
|
|
864 |
fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr); |
|
865 |
fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); |
|
866 |
fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, initrd_size); |
|
941 | 867 |
|
942 | 868 |
stl_p(header+0x218, initrd_addr); |
943 | 869 |
stl_p(header+0x21c, initrd_size); |
... | ... | |
957 | 883 |
fread(kernel, 1, kernel_size, f); |
958 | 884 |
fclose(f); |
959 | 885 |
memcpy(setup, header, MIN(sizeof(header), setup_size)); |
960 |
rom_add_blob_fixed("linux-setup", setup, |
|
961 |
setup_size, real_addr); |
|
962 |
rom_add_blob_fixed(kernel_filename, kernel, |
|
963 |
kernel_size, prot_addr); |
|
964 |
qemu_free(setup); |
|
965 |
qemu_free(kernel); |
|
966 |
|
|
967 |
/* generate bootsector to set up the initial register state */ |
|
968 |
real_seg = real_addr >> 4; |
|
969 |
seg[0] = seg[2] = seg[3] = seg[4] = seg[4] = real_seg; |
|
970 |
seg[1] = real_seg+0x20; /* CS */ |
|
971 |
memset(gpr, 0, sizeof gpr); |
|
972 |
gpr[4] = cmdline_addr-real_addr-16; /* SP (-16 is paranoia) */ |
|
973 |
|
|
974 |
generate_bootsect(gpr, seg, 0); |
|
886 |
|
|
887 |
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr); |
|
888 |
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); |
|
889 |
fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size); |
|
890 |
|
|
891 |
fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr); |
|
892 |
fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size); |
|
893 |
fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size); |
|
894 |
|
|
895 |
option_rom[nb_option_roms] = "linuxboot.bin"; |
|
896 |
nb_option_roms++; |
|
975 | 897 |
} |
976 | 898 |
|
977 | 899 |
static const int ide_iobase[2] = { 0x1f0, 0x170 }; |
b/pc-bios/optionrom/Makefile | ||
---|---|---|
13 | 13 |
CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector) |
14 | 14 |
QEMU_CFLAGS = $(CFLAGS) |
15 | 15 |
|
16 |
build-all: multiboot.bin |
|
16 |
build-all: multiboot.bin linuxboot.bin
|
|
17 | 17 |
|
18 | 18 |
%.img: %.o |
19 | 19 |
$(call quiet-command,$(LD) -Ttext 0 -e _start -s -o $@ $<," Building $(TARGET_DIR)$@") |
b/pc-bios/optionrom/linuxboot.S | ||
---|---|---|
1 |
/* |
|
2 |
* Linux Boot Option ROM |
|
3 |
* |
|
4 |
* This program is free software; you can redistribute it and/or modify |
|
5 |
* it under the terms of the GNU General Public License as published by |
|
6 |
* the Free Software Foundation; either version 2 of the License, or |
|
7 |
* (at your option) any later version. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
|
16 |
* |
|
17 |
* Copyright Novell Inc, 2009 |
|
18 |
* Authors: Alexander Graf <agraf@suse.de> |
|
19 |
* |
|
20 |
* Based on code in hw/pc.c. |
|
21 |
*/ |
|
22 |
|
|
23 |
#include "optionrom.h" |
|
24 |
|
|
25 |
BOOT_ROM_START |
|
26 |
|
|
27 |
run_linuxboot: |
|
28 |
|
|
29 |
cli |
|
30 |
cld |
|
31 |
|
|
32 |
jmp copy_kernel |
|
33 |
boot_kernel: |
|
34 |
|
|
35 |
read_fw FW_CFG_SETUP_ADDR |
|
36 |
|
|
37 |
mov %eax, %ebx |
|
38 |
shr $4, %ebx |
|
39 |
|
|
40 |
/* All segments contain real_addr */ |
|
41 |
mov %bx, %ds |
|
42 |
mov %bx, %es |
|
43 |
mov %bx, %fs |
|
44 |
mov %bx, %gs |
|
45 |
mov %bx, %ss |
|
46 |
|
|
47 |
/* CX = CS we want to jump to */ |
|
48 |
add $0x20, %bx |
|
49 |
mov %bx, %cx |
|
50 |
|
|
51 |
/* SP = cmdline_addr-real_addr-16 */ |
|
52 |
read_fw FW_CFG_CMDLINE_ADDR |
|
53 |
mov %eax, %ebx |
|
54 |
read_fw FW_CFG_SETUP_ADDR |
|
55 |
sub %eax, %ebx |
|
56 |
sub $16, %ebx |
|
57 |
mov %ebx, %esp |
|
58 |
|
|
59 |
/* Build indirect lret descriptor */ |
|
60 |
pushw %cx /* CS */ |
|
61 |
xor %ax, %ax |
|
62 |
pushw %ax /* IP = 0 */ |
|
63 |
|
|
64 |
/* Clear registers */ |
|
65 |
xor %eax, %eax |
|
66 |
xor %ebx, %ebx |
|
67 |
xor %ecx, %ecx |
|
68 |
xor %edx, %edx |
|
69 |
xor %edi, %edi |
|
70 |
xor %ebp, %ebp |
|
71 |
|
|
72 |
/* Jump to Linux */ |
|
73 |
lret |
|
74 |
|
|
75 |
|
|
76 |
copy_kernel: |
|
77 |
|
|
78 |
/* We need to load the kernel into memory we can't access in 16 bit |
|
79 |
mode, so let's get into 32 bit mode, write the kernel and jump |
|
80 |
back again. */ |
|
81 |
|
|
82 |
/* Set DS to SS+SP - 0x10, so we can write our GDT descriptor there */ |
|
83 |
mov %ss, %eax |
|
84 |
shl $4, %eax |
|
85 |
add %esp, %eax |
|
86 |
sub $0x10, %eax |
|
87 |
shr $4, %eax |
|
88 |
|
|
89 |
/* Now create the GDT descriptor */ |
|
90 |
mov %cs, %eax |
|
91 |
shl $4, %eax |
|
92 |
movw $((3 * 8) - 1), %bx |
|
93 |
movw %bx, %gs:0 |
|
94 |
movl $gdt, %ebx |
|
95 |
add %eax, %ebx |
|
96 |
movl %ebx, %gs:2 |
|
97 |
|
|
98 |
/* And load the GDT */ |
|
99 |
data32 lgdt %gs:0 |
|
100 |
|
|
101 |
/* Get us to protected mode now */ |
|
102 |
mov $1, %eax |
|
103 |
mov %eax, %cr0 |
|
104 |
|
|
105 |
/* So we can set DS to a 32-bit segment */ |
|
106 |
mov $0x10, %eax |
|
107 |
mov %eax, %ds |
|
108 |
|
|
109 |
/* We're now running in 16-bit CS, but 32-bit DS! */ |
|
110 |
|
|
111 |
/* Load kernel and initrd */ |
|
112 |
read_fw_blob(FW_CFG_KERNEL) |
|
113 |
read_fw_blob(FW_CFG_INITRD) |
|
114 |
read_fw_blob(FW_CFG_CMDLINE) |
|
115 |
read_fw_blob(FW_CFG_SETUP) |
|
116 |
|
|
117 |
/* And now jump into Linux! */ |
|
118 |
mov $0, %eax |
|
119 |
mov %eax, %cr0 |
|
120 |
|
|
121 |
/* DS = CS */ |
|
122 |
mov %cs, %ax |
|
123 |
mov %ax, %ds |
|
124 |
|
|
125 |
jmp boot_kernel |
|
126 |
|
|
127 |
/* Variables */ |
|
128 |
|
|
129 |
.align 4, 0 |
|
130 |
gdt: |
|
131 |
/* 0x00 */ |
|
132 |
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
|
133 |
|
|
134 |
/* 0x08: code segment (base=0, limit=0xfffff, type=32bit code exec/read, DPL=0, 4k) */ |
|
135 |
.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00 |
|
136 |
|
|
137 |
/* 0x10: data segment (base=0, limit=0xfffff, type=32bit data read/write, DPL=0, 4k) */ |
|
138 |
.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00 |
|
139 |
|
|
140 |
BOOT_ROM_END |
Also available in: Unified diff