mirror of
https://github.com/qemu/qemu.git
synced 2024-11-23 10:53:37 +08:00
find -type f | xargs sed -i 's/[\t ]$//g' # on most files
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3173 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
parent
bd494f4cbd
commit
5fafdf24ef
16
Changelog
16
Changelog
@ -86,7 +86,7 @@ version 0.8.0:
|
||||
(Johannes Schindelin)
|
||||
|
||||
version 0.7.2:
|
||||
|
||||
|
||||
- x86_64 fixes (Win2000 and Linux 2.6 boot in 32 bit)
|
||||
- merge self modifying code handling in dirty ram page mecanism.
|
||||
- MIPS fixes (Ralf Baechle)
|
||||
@ -135,7 +135,7 @@ version 0.6.1:
|
||||
- Mac OS X port (Pierre d'Herbemont)
|
||||
- Virtual console support
|
||||
- Better monitor line edition
|
||||
- New block device layer
|
||||
- New block device layer
|
||||
- New 'qcow' growable disk image support with AES encryption and
|
||||
transparent decompression
|
||||
- VMware 3 and 4 read-only disk image support (untested)
|
||||
@ -201,7 +201,7 @@ version 0.5.5:
|
||||
- FDC fixes for Win98
|
||||
|
||||
version 0.5.4:
|
||||
|
||||
|
||||
- qemu-fast fixes
|
||||
- BIOS area protection fix (aka EMM386.EXE fix) (Mike Nordell)
|
||||
- keyboard/mouse fix (Mike Nordell)
|
||||
@ -228,7 +228,7 @@ version 0.5.3:
|
||||
- added accurate CR0.MP/ME/TS emulation
|
||||
- fixed DMA memory write access (Win95 boot floppy fix)
|
||||
- graphical x86 linux loader
|
||||
- command line monitor
|
||||
- command line monitor
|
||||
- generic removable device support
|
||||
- support of CD-ROM change
|
||||
- multiple network interface support
|
||||
@ -266,7 +266,7 @@ version 0.5.2:
|
||||
- eflags optimisation fix for string operations
|
||||
|
||||
version 0.5.1:
|
||||
|
||||
|
||||
- float access fixes when using soft mmu
|
||||
- PC emulation support on PowerPC
|
||||
- A20 support
|
||||
@ -281,7 +281,7 @@ version 0.5.1:
|
||||
- Major SPARC target fixes (dynamically linked programs begin to work)
|
||||
|
||||
version 0.5.0:
|
||||
|
||||
|
||||
- full hardware level VGA emulation
|
||||
- graphical display with SDL
|
||||
- added PS/2 mouse and keyboard emulation
|
||||
@ -319,7 +319,7 @@ version 0.4.2:
|
||||
- SMP kernels can at least be booted
|
||||
|
||||
version 0.4.1:
|
||||
|
||||
|
||||
- more accurate timer support in vl.
|
||||
- more reliable NE2000 probe in vl.
|
||||
- added 2.5.66 kernel in vl-test.
|
||||
@ -405,7 +405,7 @@ version 0.1.3:
|
||||
- added bound, cmpxchg8b, cpuid instructions
|
||||
- added 16 bit addressing support/override for string operations
|
||||
- poll() fix
|
||||
|
||||
|
||||
version 0.1.2:
|
||||
|
||||
- compile fixes
|
||||
|
4
Makefile
4
Makefile
@ -40,7 +40,7 @@ dyngen$(EXESUF): dyngen.c
|
||||
|
||||
clean:
|
||||
# avoid old build problems by removing potentially incorrect old files
|
||||
rm -f config.mak config.h op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
|
||||
rm -f config.mak config.h op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
|
||||
rm -f *.o *.a $(TOOLS) dyngen$(EXESUF) TAGS cscope.* *.pod *~ */*~
|
||||
$(MAKE) -C tests clean
|
||||
for d in $(TARGET_DIRS); do \
|
||||
@ -89,7 +89,7 @@ endif
|
||||
test speed test2: all
|
||||
$(MAKE) -C tests $@
|
||||
|
||||
TAGS:
|
||||
TAGS:
|
||||
etags *.[ch] tests/*.[ch]
|
||||
|
||||
cscope:
|
||||
|
@ -269,7 +269,7 @@ OBJS+= libqemu.a
|
||||
|
||||
# cpu emulator library
|
||||
LIBOBJS=exec.o kqemu.o translate-op.o translate-all.o cpu-exec.o\
|
||||
translate.o op.o
|
||||
translate.o op.o
|
||||
ifdef CONFIG_SOFTFLOAT
|
||||
LIBOBJS+=fpu/softfloat.o
|
||||
else
|
||||
@ -317,7 +317,7 @@ LIBOBJS+= op_helper.o helper.o alpha_palcode.o
|
||||
endif
|
||||
|
||||
# NOTE: the disassembler code is only needed for debugging
|
||||
LIBOBJS+=disas.o
|
||||
LIBOBJS+=disas.o
|
||||
ifeq ($(findstring i386, $(TARGET_ARCH) $(ARCH)),i386)
|
||||
USE_I386_DIS=y
|
||||
endif
|
||||
@ -483,7 +483,7 @@ VL_OBJS+= an5206.o mcf5206.o ptimer.o mcf_uart.o mcf_intc.o mcf5208.o mcf_fec.o
|
||||
VL_OBJS+= m68k-semi.o
|
||||
endif
|
||||
ifdef CONFIG_GDBSTUB
|
||||
VL_OBJS+=gdbstub.o
|
||||
VL_OBJS+=gdbstub.o
|
||||
endif
|
||||
ifdef CONFIG_SDL
|
||||
VL_OBJS+=sdl.o x_keymap.o
|
||||
@ -511,7 +511,7 @@ ifdef CONFIG_STATIC
|
||||
VL_LDFLAGS+=-static
|
||||
endif
|
||||
ifndef CONFIG_SOFTMMU
|
||||
VL_LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386-vl.ld
|
||||
VL_LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386-vl.ld
|
||||
endif
|
||||
ifndef CONFIG_DARWIN
|
||||
ifndef CONFIG_WIN32
|
||||
@ -561,7 +561,7 @@ depend: $(SRCS)
|
||||
vldepend: $(VL_OBJS:.o=.c)
|
||||
$(CC) -MM $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $^ 1>.depend
|
||||
|
||||
# libqemu
|
||||
# libqemu
|
||||
|
||||
libqemu.a: $(LIBOBJS)
|
||||
rm -f $@
|
||||
@ -665,7 +665,7 @@ $(OBJS) $(LIBOBJS) $(VL_OBJS): config.h ../config-host.h
|
||||
clean:
|
||||
rm -f *.o *.a *~ $(PROGS) gen-op.h opc.h op.h nwfpe/*.o slirp/*.o fpu/*.o
|
||||
|
||||
install: all
|
||||
install: all
|
||||
ifneq ($(PROGS),)
|
||||
$(INSTALL) -m 755 -s $(PROGS) "$(DESTDIR)$(bindir)"
|
||||
endif
|
||||
|
2
TODO
2
TODO
@ -16,7 +16,7 @@ short term:
|
||||
- do not resize vga if invalid size.
|
||||
- avoid looping if only exceptions
|
||||
- TLB code protection support for PPC
|
||||
- see openMosix Doc
|
||||
- see openMosix Doc
|
||||
- disable SMC handling for ARM/SPARC/PPC (not finished)
|
||||
- see undefined flags for BTx insn
|
||||
- user/kernel PUSHL/POPL in helper.c
|
||||
|
8
aes.c
8
aes.c
@ -1,5 +1,5 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
* aes.c - integrated in QEMU by Fabrice Bellard from the OpenSSL project.
|
||||
*/
|
||||
/*
|
||||
@ -1267,7 +1267,7 @@ void AES_decrypt(const unsigned char *in, unsigned char *out,
|
||||
|
||||
void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
const unsigned long length, const AES_KEY *key,
|
||||
unsigned char *ivec, const int enc)
|
||||
unsigned char *ivec, const int enc)
|
||||
{
|
||||
|
||||
unsigned long n;
|
||||
@ -1294,7 +1294,7 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
AES_encrypt(tmp, tmp, key);
|
||||
memcpy(out, tmp, AES_BLOCK_SIZE);
|
||||
memcpy(ivec, tmp, AES_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (len >= AES_BLOCK_SIZE) {
|
||||
memcpy(tmp, in, AES_BLOCK_SIZE);
|
||||
@ -1312,6 +1312,6 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
for(n=0; n < len; ++n)
|
||||
out[n] = tmp[n] ^ ivec[n];
|
||||
memcpy(ivec, tmp, AES_BLOCK_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ const struct alpha_operand alpha_operands[] =
|
||||
|
||||
/* The signed "23-bit" aligned displacement of Branch format insns */
|
||||
#define BDISP (MDISP + 1)
|
||||
{ 21, 0, BFD_RELOC_23_PCREL_S2,
|
||||
{ 21, 0, BFD_RELOC_23_PCREL_S2,
|
||||
AXP_OPERAND_RELATIVE, insert_bdisp, extract_bdisp },
|
||||
|
||||
/* The 26-bit PALcode function */
|
||||
|
160
arm-dis.c
160
arm-dis.c
@ -4,17 +4,17 @@
|
||||
Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
|
||||
Modification by James G. Smith (jsmith@cygnus.co.uk)
|
||||
|
||||
This file is part of libopcodes.
|
||||
This file is part of libopcodes.
|
||||
|
||||
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.
|
||||
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.
|
||||
more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
@ -34,7 +34,7 @@ struct thumb_opcode
|
||||
};
|
||||
|
||||
/* format of the assembler string :
|
||||
|
||||
|
||||
%% %
|
||||
%<bitfield>d print the bitfield in decimal
|
||||
%<bitfield>x print the bitfield in hex
|
||||
@ -104,7 +104,7 @@ static struct arm_opcode arm_opcodes[] =
|
||||
{0x0c400000, 0x0ff00fff, "mar%c\tacc0, %12-15r, %16-19r"},
|
||||
{0x0c500000, 0x0ff00fff, "mra%c\t%12-15r, %16-19r, acc0"},
|
||||
{0xf450f000, 0xfc70f000, "pld\t%a"},
|
||||
|
||||
|
||||
/* V5 Instructions. */
|
||||
{0xe1200070, 0xfff000f0, "bkpt\t0x%16-19X%12-15X%8-11X%0-3X"},
|
||||
{0xfa000000, 0xfe000000, "blx\t%B"},
|
||||
@ -116,7 +116,7 @@ static struct arm_opcode arm_opcodes[] =
|
||||
{0xfe000010, 0xff100010, "mcr2\t%8-11d, %21-23d, %12-15r, cr%16-19d, cr%0-3d, {%5-7d}"},
|
||||
{0xfe100010, 0xff100010, "mrc2\t%8-11d, %21-23d, %12-15r, cr%16-19d, cr%0-3d, {%5-7d}"},
|
||||
|
||||
/* V5E "El Segundo" Instructions. */
|
||||
/* V5E "El Segundo" Instructions. */
|
||||
{0x000000d0, 0x0e1000f0, "ldr%cd\t%12-15r, %s"},
|
||||
{0x000000f0, 0x0e1000f0, "str%cd\t%12-15r, %s"},
|
||||
{0x01000080, 0x0ff000f0, "smlabb%c\t%16-19r, %0-3r, %8-11r, %12-15r"},
|
||||
@ -303,7 +303,7 @@ static struct arm_opcode arm_opcodes[] =
|
||||
{0x0d100400, 0x0f500f00, "cfldrs%c\tmvf%12-15d, %A"},
|
||||
{0x0c100400, 0x0f500f00, "cfldrs%c\tmvf%12-15d, %A"},
|
||||
{0x0d500400, 0x0f500f00, "cfldrd%c\tmvd%12-15d, %A"},
|
||||
{0x0c500400, 0x0f500f00, "cfldrd%c\tmvd%12-15d, %A"},
|
||||
{0x0c500400, 0x0f500f00, "cfldrd%c\tmvd%12-15d, %A"},
|
||||
{0x0d100500, 0x0f500f00, "cfldr32%c\tmvfx%12-15d, %A"},
|
||||
{0x0c100500, 0x0f500f00, "cfldr32%c\tmvfx%12-15d, %A"},
|
||||
{0x0d500500, 0x0f500f00, "cfldr64%c\tmvdx%12-15d, %A"},
|
||||
@ -571,7 +571,7 @@ static boolean force_thumb = false;
|
||||
static char * arm_fp_const[] =
|
||||
{"0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0"};
|
||||
|
||||
static char * arm_shift[] =
|
||||
static char * arm_shift[] =
|
||||
{"lsl", "lsr", "asr", "ror"};
|
||||
|
||||
/* Forward declarations. */
|
||||
@ -621,14 +621,14 @@ arm_decode_shift (given, func, stream)
|
||||
void * stream;
|
||||
{
|
||||
func (stream, "%s", arm_regnames[given & 0xf]);
|
||||
|
||||
|
||||
if ((given & 0xff0) != 0)
|
||||
{
|
||||
if ((given & 0x10) == 0)
|
||||
{
|
||||
int amount = (given & 0xf80) >> 7;
|
||||
int shift = (given & 0x60) >> 5;
|
||||
|
||||
|
||||
if (amount == 0)
|
||||
{
|
||||
if (shift == 3)
|
||||
@ -636,10 +636,10 @@ arm_decode_shift (given, func, stream)
|
||||
func (stream, ", rrx");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
amount = 32;
|
||||
}
|
||||
|
||||
|
||||
func (stream, ", %s #%d", arm_shift[shift], amount);
|
||||
}
|
||||
else
|
||||
@ -666,7 +666,7 @@ print_insn_arm1 (pc, info, given)
|
||||
if ((given & insn->mask) == insn->value)
|
||||
{
|
||||
char * c;
|
||||
|
||||
|
||||
for (c = insn->assembler; *c; c++)
|
||||
{
|
||||
if (*c == '%')
|
||||
@ -682,14 +682,14 @@ print_insn_arm1 (pc, info, given)
|
||||
&& ((given & 0x02000000) == 0))
|
||||
{
|
||||
int offset = given & 0xfff;
|
||||
|
||||
|
||||
func (stream, "[pc");
|
||||
|
||||
|
||||
if (given & 0x01000000)
|
||||
{
|
||||
if ((given & 0x00800000) == 0)
|
||||
offset = - offset;
|
||||
|
||||
|
||||
/* Pre-indexed. */
|
||||
func (stream, ", #%d]", offset);
|
||||
|
||||
@ -710,13 +710,13 @@ print_insn_arm1 (pc, info, given)
|
||||
/* ie ignore the offset. */
|
||||
offset = pc + 8;
|
||||
}
|
||||
|
||||
|
||||
func (stream, "\t; ");
|
||||
info->print_address_func (offset, info);
|
||||
}
|
||||
else
|
||||
{
|
||||
func (stream, "[%s",
|
||||
func (stream, "[%s",
|
||||
arm_regnames[(given >> 16) & 0xf]);
|
||||
if ((given & 0x01000000) != 0)
|
||||
{
|
||||
@ -736,7 +736,7 @@ print_insn_arm1 (pc, info, given)
|
||||
arm_decode_shift (given, func, stream);
|
||||
}
|
||||
|
||||
func (stream, "]%s",
|
||||
func (stream, "]%s",
|
||||
((given & 0x00200000) != 0) ? "!" : "");
|
||||
}
|
||||
else
|
||||
@ -748,13 +748,13 @@ print_insn_arm1 (pc, info, given)
|
||||
func (stream, "], %s#%d",
|
||||
(((given & 0x00800000) == 0)
|
||||
? "-" : ""), offset);
|
||||
else
|
||||
else
|
||||
func (stream, "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
func (stream, "], %s",
|
||||
(((given & 0x00800000) == 0)
|
||||
(((given & 0x00800000) == 0)
|
||||
? "-" : ""));
|
||||
arm_decode_shift (given, func, stream);
|
||||
}
|
||||
@ -767,18 +767,18 @@ print_insn_arm1 (pc, info, given)
|
||||
{
|
||||
/* PC relative with immediate offset. */
|
||||
int offset = ((given & 0xf00) >> 4) | (given & 0xf);
|
||||
|
||||
|
||||
if ((given & 0x00800000) == 0)
|
||||
offset = -offset;
|
||||
|
||||
|
||||
func (stream, "[pc, #%d]\t; ", offset);
|
||||
|
||||
|
||||
(*info->print_address_func)
|
||||
(offset + pc + 8, info);
|
||||
}
|
||||
else
|
||||
{
|
||||
func (stream, "[%s",
|
||||
func (stream, "[%s",
|
||||
arm_regnames[(given >> 16) & 0xf]);
|
||||
if ((given & 0x01000000) != 0)
|
||||
{
|
||||
@ -801,7 +801,7 @@ print_insn_arm1 (pc, info, given)
|
||||
arm_regnames[given & 0xf]);
|
||||
}
|
||||
|
||||
func (stream, "]%s",
|
||||
func (stream, "]%s",
|
||||
((given & 0x00200000) != 0) ? "!" : "");
|
||||
}
|
||||
else
|
||||
@ -815,7 +815,7 @@ print_insn_arm1 (pc, info, given)
|
||||
func (stream, "], %s#%d",
|
||||
(((given & 0x00800000) == 0)
|
||||
? "-" : ""), offset);
|
||||
else
|
||||
else
|
||||
func (stream, "]");
|
||||
}
|
||||
else
|
||||
@ -829,7 +829,7 @@ print_insn_arm1 (pc, info, given)
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'b':
|
||||
(*info->print_address_func)
|
||||
(BDISP (given) * 4 + pc + 8, info);
|
||||
@ -911,7 +911,7 @@ print_insn_arm1 (pc, info, given)
|
||||
{
|
||||
bfd_vma address;
|
||||
bfd_vma offset = 0;
|
||||
|
||||
|
||||
if (given & 0x00800000)
|
||||
/* Is signed, hi bits should be ones. */
|
||||
offset = (-1) ^ 0x00ffffff;
|
||||
@ -920,7 +920,7 @@ print_insn_arm1 (pc, info, given)
|
||||
offset += given & 0x00ffffff;
|
||||
offset <<= 2;
|
||||
address = offset + pc + 8;
|
||||
|
||||
|
||||
if (given & 0x01000000)
|
||||
/* H bit allows addressing to 2-byte boundaries. */
|
||||
address += 2;
|
||||
@ -976,7 +976,7 @@ print_insn_arm1 (pc, info, given)
|
||||
func (stream, "3");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'P':
|
||||
switch (given & 0x00080080)
|
||||
{
|
||||
@ -1028,7 +1028,7 @@ print_insn_arm1 (pc, info, given)
|
||||
}
|
||||
break;
|
||||
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
{
|
||||
int bitstart = *c++ - '0';
|
||||
@ -1040,44 +1040,44 @@ print_insn_arm1 (pc, info, given)
|
||||
{
|
||||
case '-':
|
||||
c++;
|
||||
|
||||
|
||||
while (*c >= '0' && *c <= '9')
|
||||
bitend = (bitend * 10) + *c++ - '0';
|
||||
|
||||
|
||||
if (!bitend)
|
||||
abort ();
|
||||
|
||||
|
||||
switch (*c)
|
||||
{
|
||||
case 'r':
|
||||
{
|
||||
long reg;
|
||||
|
||||
|
||||
reg = given >> bitstart;
|
||||
reg &= (2 << (bitend - bitstart)) - 1;
|
||||
|
||||
|
||||
func (stream, "%s", arm_regnames[reg]);
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
{
|
||||
long reg;
|
||||
|
||||
|
||||
reg = given >> bitstart;
|
||||
reg &= (2 << (bitend - bitstart)) - 1;
|
||||
|
||||
|
||||
func (stream, "%d", reg);
|
||||
}
|
||||
break;
|
||||
case 'x':
|
||||
{
|
||||
long reg;
|
||||
|
||||
|
||||
reg = given >> bitstart;
|
||||
reg &= (2 << (bitend - bitstart)) - 1;
|
||||
|
||||
|
||||
func (stream, "0x%08x", reg);
|
||||
|
||||
|
||||
/* Some SWI instructions have special
|
||||
meanings. */
|
||||
if ((given & 0x0fffffff) == 0x0FF00000)
|
||||
@ -1089,20 +1089,20 @@ print_insn_arm1 (pc, info, given)
|
||||
case 'X':
|
||||
{
|
||||
long reg;
|
||||
|
||||
|
||||
reg = given >> bitstart;
|
||||
reg &= (2 << (bitend - bitstart)) - 1;
|
||||
|
||||
|
||||
func (stream, "%01x", reg & 0xf);
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
{
|
||||
long reg;
|
||||
|
||||
|
||||
reg = given >> bitstart;
|
||||
reg &= (2 << (bitend - bitstart)) - 1;
|
||||
|
||||
|
||||
if (reg > 7)
|
||||
func (stream, "#%s",
|
||||
arm_fp_const[reg & 7]);
|
||||
@ -1163,7 +1163,7 @@ print_insn_arm1 (pc, info, given)
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
@ -1252,7 +1252,7 @@ print_insn_thumb (pc, info, given)
|
||||
if (!*c) /* Check for empty (not NULL) assembler string. */
|
||||
{
|
||||
long offset;
|
||||
|
||||
|
||||
info->bytes_per_chunk = 4;
|
||||
info->bytes_per_line = 4;
|
||||
|
||||
@ -1274,16 +1274,16 @@ print_insn_thumb (pc, info, given)
|
||||
{
|
||||
info->bytes_per_chunk = 2;
|
||||
info->bytes_per_line = 4;
|
||||
|
||||
|
||||
given &= 0xffff;
|
||||
|
||||
|
||||
for (; *c; c++)
|
||||
{
|
||||
if (*c == '%')
|
||||
{
|
||||
int domaskpc = 0;
|
||||
int domasklr = 0;
|
||||
|
||||
|
||||
switch (*++c)
|
||||
{
|
||||
case '%':
|
||||
@ -1293,11 +1293,11 @@ print_insn_thumb (pc, info, given)
|
||||
case 'S':
|
||||
{
|
||||
long reg;
|
||||
|
||||
|
||||
reg = (given >> 3) & 0x7;
|
||||
if (given & (1 << 6))
|
||||
reg += 8;
|
||||
|
||||
|
||||
func (stream, "%s", arm_regnames[reg]);
|
||||
}
|
||||
break;
|
||||
@ -1305,11 +1305,11 @@ print_insn_thumb (pc, info, given)
|
||||
case 'D':
|
||||
{
|
||||
long reg;
|
||||
|
||||
|
||||
reg = given & 0x7;
|
||||
if (given & (1 << 7))
|
||||
reg += 8;
|
||||
|
||||
|
||||
func (stream, "%s", arm_regnames[reg]);
|
||||
}
|
||||
break;
|
||||
@ -1331,9 +1331,9 @@ print_insn_thumb (pc, info, given)
|
||||
{
|
||||
int started = 0;
|
||||
int reg;
|
||||
|
||||
|
||||
func (stream, "{");
|
||||
|
||||
|
||||
/* It would be nice if we could spot
|
||||
ranges, and generate the rS-rE format: */
|
||||
for (reg = 0; (reg < 8); reg++)
|
||||
@ -1365,12 +1365,12 @@ print_insn_thumb (pc, info, given)
|
||||
break;
|
||||
|
||||
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
{
|
||||
int bitstart = *c++ - '0';
|
||||
int bitend = 0;
|
||||
|
||||
|
||||
while (*c >= '0' && *c <= '9')
|
||||
bitstart = (bitstart * 10) + *c++ - '0';
|
||||
|
||||
@ -1379,7 +1379,7 @@ print_insn_thumb (pc, info, given)
|
||||
case '-':
|
||||
{
|
||||
long reg;
|
||||
|
||||
|
||||
c++;
|
||||
while (*c >= '0' && *c <= '9')
|
||||
bitend = (bitend * 10) + *c++ - '0';
|
||||
@ -1478,11 +1478,11 @@ parse_arm_disassembler_option (option)
|
||||
{
|
||||
if (option == NULL)
|
||||
return;
|
||||
|
||||
|
||||
if (strneq (option, "reg-names-", 10))
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
option += 10;
|
||||
|
||||
for (i = NUM_ARM_REGNAMES; i--;)
|
||||
@ -1491,7 +1491,7 @@ parse_arm_disassembler_option (option)
|
||||
regname_selected = i;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (i < 0)
|
||||
fprintf (stderr, _("Unrecognised register name set: %s\n"), option);
|
||||
}
|
||||
@ -1501,7 +1501,7 @@ parse_arm_disassembler_option (option)
|
||||
force_thumb = 0;
|
||||
else
|
||||
fprintf (stderr, _("Unrecognised disassembler option: %s\n"), option);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1512,7 +1512,7 @@ parse_disassembler_options (options)
|
||||
char * options;
|
||||
{
|
||||
char * space;
|
||||
|
||||
|
||||
if (options == NULL)
|
||||
return;
|
||||
|
||||
@ -1550,25 +1550,25 @@ print_insn_arm (pc, info)
|
||||
if (info->disassembler_options)
|
||||
{
|
||||
parse_disassembler_options (info->disassembler_options);
|
||||
|
||||
|
||||
/* To avoid repeated parsing of these options, we remove them here. */
|
||||
info->disassembler_options = NULL;
|
||||
}
|
||||
|
||||
|
||||
is_thumb = force_thumb;
|
||||
if (pc & 1)
|
||||
{
|
||||
is_thumb = 1;
|
||||
pc &= ~(bfd_vma) 1;
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
if (!is_thumb && info->symbols != NULL)
|
||||
{
|
||||
if (bfd_asymbol_flavour (*info->symbols) == bfd_target_coff_flavour)
|
||||
{
|
||||
coff_symbol_type * cs;
|
||||
|
||||
|
||||
cs = coffsymbol (*info->symbols);
|
||||
is_thumb = ( cs->native->u.syment.n_sclass == C_THUMBEXT
|
||||
|| cs->native->u.syment.n_sclass == C_THUMBSTAT
|
||||
@ -1580,15 +1580,15 @@ print_insn_arm (pc, info)
|
||||
{
|
||||
elf_symbol_type * es;
|
||||
unsigned int type;
|
||||
|
||||
|
||||
es = *(elf_symbol_type **)(info->symbols);
|
||||
type = ELF_ST_TYPE (es->internal_elf_sym.st_info);
|
||||
|
||||
|
||||
is_thumb = (type == STT_ARM_TFUNC) || (type == STT_ARM_16BIT);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
little = (info->endian == BFD_ENDIAN_LITTLE);
|
||||
info->bytes_per_chunk = 4;
|
||||
info->display_endian = little ? BFD_ENDIAN_LITTLE : BFD_ENDIAN_BIG;
|
||||
@ -1599,17 +1599,17 @@ print_insn_arm (pc, info)
|
||||
if (status != 0 && is_thumb)
|
||||
{
|
||||
info->bytes_per_chunk = 2;
|
||||
|
||||
|
||||
status = info->read_memory_func (pc, (bfd_byte *) b, 2, info);
|
||||
b[3] = b[2] = 0;
|
||||
}
|
||||
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
info->memory_error_func (status, pc, info);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
given = (b[0]) | (b[1] << 8) | (b[2] << 16) | (b[3] << 24);
|
||||
}
|
||||
else
|
||||
@ -1621,13 +1621,13 @@ print_insn_arm (pc, info)
|
||||
info->memory_error_func (status, pc, info);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (is_thumb)
|
||||
{
|
||||
if (pc & 0x2)
|
||||
{
|
||||
given = (b[2] << 8) | b[3];
|
||||
|
||||
|
||||
status = info->read_memory_func
|
||||
((pc + 4) & ~ 0x3, (bfd_byte *) b, 4, info);
|
||||
if (status != 0)
|
||||
@ -1635,7 +1635,7 @@ print_insn_arm (pc, info)
|
||||
info->memory_error_func (status, pc + 4, info);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
given |= (b[0] << 24) | (b[1] << 16);
|
||||
}
|
||||
else
|
||||
@ -1644,7 +1644,7 @@ print_insn_arm (pc, info)
|
||||
else
|
||||
given = (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | (b[3]);
|
||||
}
|
||||
|
||||
|
||||
if (info->flags & INSN_HAS_RELOC)
|
||||
/* If the instruction has a reloc associated with it, then
|
||||
the offset field in the instruction will actually be the
|
||||
@ -1668,7 +1668,7 @@ print_arm_disassembler_options (FILE * stream)
|
||||
fprintf (stream, _("\n\
|
||||
The following ARM specific disassembler options are supported for use with\n\
|
||||
the -M switch:\n"));
|
||||
|
||||
|
||||
for (i = NUM_ARM_REGNAMES; i--;)
|
||||
fprintf (stream, " reg-names-%s %*c%s\n",
|
||||
regnames[i].name,
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Arm "Angel" semihosting syscalls
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2005, 2007 CodeSourcery.
|
||||
* Written by Paul Brook.
|
||||
*
|
||||
@ -194,7 +194,7 @@ uint32_t do_arm_semihosting(CPUState *env)
|
||||
return STDOUT_FILENO;
|
||||
}
|
||||
if (use_gdb_syscalls()) {
|
||||
gdb_do_syscall(arm_semi_cb, "open,%s,%x,1a4", ARG(0),
|
||||
gdb_do_syscall(arm_semi_cb, "open,%s,%x,1a4", ARG(0),
|
||||
(int)ARG(2)+1, gdb_open_modeflags[ARG(1)]);
|
||||
return env->regs[0];
|
||||
} else {
|
||||
@ -283,7 +283,7 @@ uint32_t do_arm_semihosting(CPUState *env)
|
||||
}
|
||||
case SYS_FLEN:
|
||||
if (use_gdb_syscalls()) {
|
||||
gdb_do_syscall(arm_semi_flen_cb, "fstat,%x,%x",
|
||||
gdb_do_syscall(arm_semi_flen_cb, "fstat,%x,%x",
|
||||
ARG(0), env->regs[13]-64);
|
||||
return env->regs[0];
|
||||
} else {
|
||||
@ -401,7 +401,7 @@ uint32_t do_arm_semihosting(CPUState *env)
|
||||
}
|
||||
ts->heap_limit = limit;
|
||||
}
|
||||
|
||||
|
||||
ptr = lock_user(ARG(0), 16, 0);
|
||||
ptr[0] = tswap32(ts->heap_base);
|
||||
ptr[1] = tswap32(ts->heap_limit);
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Block driver for the various disk image formats used by Bochs
|
||||
* Currently only for "growing" type in read-only mode
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2005 Alex Beregszaszi
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -44,7 +44,7 @@ struct bochs_header_v1 {
|
||||
char subtype[16]; // "Undoable" / "Volatile" / "Growing"
|
||||
uint32_t version;
|
||||
uint32_t header; // size of header
|
||||
|
||||
|
||||
union {
|
||||
struct {
|
||||
uint32_t catalog; // num of entries
|
||||
@ -64,7 +64,7 @@ struct bochs_header {
|
||||
char subtype[16]; // "Undoable" / "Volatile" / "Growing"
|
||||
uint32_t version;
|
||||
uint32_t header; // size of header
|
||||
|
||||
|
||||
union {
|
||||
struct {
|
||||
uint32_t catalog; // num of entries
|
||||
@ -83,9 +83,9 @@ typedef struct BDRVBochsState {
|
||||
|
||||
uint32_t *catalog_bitmap;
|
||||
int catalog_size;
|
||||
|
||||
|
||||
int data_offset;
|
||||
|
||||
|
||||
int bitmap_blocks;
|
||||
int extent_blocks;
|
||||
int extent_size;
|
||||
@ -94,7 +94,7 @@ typedef struct BDRVBochsState {
|
||||
static int bochs_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||
{
|
||||
const struct bochs_header *bochs = (const void *)buf;
|
||||
|
||||
|
||||
if (buf_size < HEADER_SIZE)
|
||||
return 0;
|
||||
|
||||
@ -121,9 +121,9 @@ static int bochs_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
bs->read_only = 1; // no write support yet
|
||||
|
||||
|
||||
s->fd = fd;
|
||||
|
||||
if (read(fd, &bochs, sizeof(bochs)) != sizeof(bochs)) {
|
||||
@ -161,7 +161,7 @@ static int bochs_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
|
||||
s->bitmap_blocks = 1 + (le32_to_cpu(bochs.extra.redolog.bitmap) - 1) / 512;
|
||||
s->extent_blocks = 1 + (le32_to_cpu(bochs.extra.redolog.extent) - 1) / 512;
|
||||
|
||||
|
||||
s->extent_size = le32_to_cpu(bochs.extra.redolog.extent);
|
||||
|
||||
return 0;
|
||||
@ -180,7 +180,7 @@ static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
|
||||
// seek to sector
|
||||
extent_index = offset / s->extent_size;
|
||||
extent_offset = (offset % s->extent_size) / 512;
|
||||
|
||||
|
||||
if (s->catalog_bitmap[extent_index] == 0xffffffff)
|
||||
{
|
||||
// fprintf(stderr, "page not allocated [%x - %x:%x]\n",
|
||||
@ -191,17 +191,17 @@ static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
|
||||
bitmap_offset = s->data_offset + (512 * s->catalog_bitmap[extent_index] *
|
||||
(s->extent_blocks + s->bitmap_blocks));
|
||||
block_offset = bitmap_offset + (512 * (s->bitmap_blocks + extent_offset));
|
||||
|
||||
|
||||
// fprintf(stderr, "sect: %x [ext i: %x o: %x] -> %x bitmap: %x block: %x\n",
|
||||
// sector_num, extent_index, extent_offset,
|
||||
// le32_to_cpu(s->catalog_bitmap[extent_index]),
|
||||
// bitmap_offset, block_offset);
|
||||
|
||||
|
||||
// read in bitmap for current extent
|
||||
lseek(s->fd, bitmap_offset + (extent_offset / 8), SEEK_SET);
|
||||
|
||||
|
||||
read(s->fd, &bitmap_entry, 1);
|
||||
|
||||
|
||||
if (!((bitmap_entry >> (extent_offset % 8)) & 1))
|
||||
{
|
||||
// fprintf(stderr, "sector (%x) in bitmap not allocated\n",
|
||||
@ -210,11 +210,11 @@ static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
|
||||
}
|
||||
|
||||
lseek(s->fd, block_offset, SEEK_SET);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bochs_read(BlockDriverState *bs, int64_t sector_num,
|
||||
static int bochs_read(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVBochsState *s = bs->opaque;
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU Block driver for CLOOP images
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004 Johannes E. Schindelin
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -96,7 +96,7 @@ cloop_close:
|
||||
if(inflateInit(&s->zstream) != Z_OK)
|
||||
goto cloop_close;
|
||||
s->current_block=s->n_blocks;
|
||||
|
||||
|
||||
s->sectors_per_block = s->block_size/512;
|
||||
bs->total_sectors = s->n_blocks*s->sectors_per_block;
|
||||
return 0;
|
||||
@ -107,12 +107,12 @@ static inline int cloop_read_block(BDRVCloopState *s,int block_num)
|
||||
if(s->current_block != block_num) {
|
||||
int ret;
|
||||
uint32_t bytes = s->offsets[block_num+1]-s->offsets[block_num];
|
||||
|
||||
|
||||
lseek(s->fd, s->offsets[block_num], SEEK_SET);
|
||||
ret = read(s->fd, s->compressed_block, bytes);
|
||||
if (ret != bytes)
|
||||
if (ret != bytes)
|
||||
return -1;
|
||||
|
||||
|
||||
s->zstream.next_in = s->compressed_block;
|
||||
s->zstream.avail_in = bytes;
|
||||
s->zstream.next_out = s->uncompressed_block;
|
||||
@ -123,13 +123,13 @@ static inline int cloop_read_block(BDRVCloopState *s,int block_num)
|
||||
ret = inflate(&s->zstream, Z_FINISH);
|
||||
if(ret != Z_STREAM_END || s->zstream.total_out != s->block_size)
|
||||
return -1;
|
||||
|
||||
|
||||
s->current_block = block_num;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cloop_read(BlockDriverState *bs, int64_t sector_num,
|
||||
static int cloop_read(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVCloopState *s = bs->opaque;
|
||||
|
32
block-cow.c
32
block-cow.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Block driver for the COW format
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -56,7 +56,7 @@ static int cow_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||
|
||||
if (buf_size >= sizeof(struct cow_header_v2) &&
|
||||
be32_to_cpu(cow_header->magic) == COW_MAGIC &&
|
||||
be32_to_cpu(cow_header->version) == COW_VERSION)
|
||||
be32_to_cpu(cow_header->version) == COW_VERSION)
|
||||
return 100;
|
||||
else
|
||||
return 0;
|
||||
@ -85,18 +85,18 @@ static int cow_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
be32_to_cpu(cow_header.version) != COW_VERSION) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
/* cow image found */
|
||||
size = be64_to_cpu(cow_header.size);
|
||||
bs->total_sectors = size / 512;
|
||||
|
||||
pstrcpy(bs->backing_file, sizeof(bs->backing_file),
|
||||
pstrcpy(bs->backing_file, sizeof(bs->backing_file),
|
||||
cow_header.backing_file);
|
||||
|
||||
|
||||
/* mmap the bitmap */
|
||||
s->cow_bitmap_size = ((bs->total_sectors + 7) >> 3) + sizeof(cow_header);
|
||||
s->cow_bitmap_addr = mmap(get_mmap_addr(s->cow_bitmap_size),
|
||||
s->cow_bitmap_size,
|
||||
s->cow_bitmap_addr = mmap(get_mmap_addr(s->cow_bitmap_size),
|
||||
s->cow_bitmap_size,
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED, s->fd, 0);
|
||||
if (s->cow_bitmap_addr == MAP_FAILED)
|
||||
@ -143,24 +143,24 @@ static inline int is_changed(uint8_t *bitmap,
|
||||
return changed;
|
||||
}
|
||||
|
||||
static int cow_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
||||
static int cow_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, int *pnum)
|
||||
{
|
||||
BDRVCowState *s = bs->opaque;
|
||||
return is_changed(s->cow_bitmap, sector_num, nb_sectors, pnum);
|
||||
}
|
||||
|
||||
static int cow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
static int cow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVCowState *s = bs->opaque;
|
||||
int ret, n;
|
||||
|
||||
|
||||
while (nb_sectors > 0) {
|
||||
if (is_changed(s->cow_bitmap, sector_num, nb_sectors, &n)) {
|
||||
lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET);
|
||||
ret = read(s->fd, buf, n * 512);
|
||||
if (ret != n * 512)
|
||||
if (ret != n * 512)
|
||||
return -1;
|
||||
} else {
|
||||
if (bs->backing_hd) {
|
||||
@ -179,15 +179,15 @@ static int cow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cow_write(BlockDriverState *bs, int64_t sector_num,
|
||||
static int cow_write(BlockDriverState *bs, int64_t sector_num,
|
||||
const uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVCowState *s = bs->opaque;
|
||||
int ret, i;
|
||||
|
||||
|
||||
lseek(s->fd, s->cow_sectors_offset + sector_num * 512, SEEK_SET);
|
||||
ret = write(s->fd, buf, nb_sectors * 512);
|
||||
if (ret != nb_sectors * 512)
|
||||
if (ret != nb_sectors * 512)
|
||||
return -1;
|
||||
for (i = 0; i < nb_sectors; i++)
|
||||
cow_set_bit(s->cow_bitmap, sector_num + i);
|
||||
@ -211,7 +211,7 @@ static int cow_create(const char *filename, int64_t image_sectors,
|
||||
if (flags)
|
||||
return -ENOTSUP;
|
||||
|
||||
cow_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
|
||||
cow_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
|
||||
0644);
|
||||
if (cow_fd < 0)
|
||||
return -1;
|
||||
|
14
block-dmg.c
14
block-dmg.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU Block driver for DMG images
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004 Johannes E. Schindelin
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
typedef struct BDRVDMGState {
|
||||
int fd;
|
||||
|
||||
|
||||
/* each chunk contains a certain number of sectors,
|
||||
* offsets[i] is the offset in the .dmg file,
|
||||
* lengths[i] is the length of the compressed chunk,
|
||||
@ -86,7 +86,7 @@ static int dmg_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
bs->read_only = 1;
|
||||
s->n_chunks = 0;
|
||||
s->offsets = s->lengths = s->sectors = s->sectorcounts = 0;
|
||||
|
||||
|
||||
/* read offset of info blocks */
|
||||
if(lseek(s->fd,-0x1d8,SEEK_END)<0) {
|
||||
dmg_close:
|
||||
@ -167,7 +167,7 @@ dmg_close:
|
||||
goto dmg_close;
|
||||
|
||||
s->current_chunk = s->n_chunks;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -227,7 +227,7 @@ static inline int dmg_read_chunk(BDRVDMGState *s,int sector_num)
|
||||
|
||||
if (ret != s->lengths[chunk])
|
||||
return -1;
|
||||
|
||||
|
||||
s->zstream.next_in = s->compressed_chunk;
|
||||
s->zstream.avail_in = s->lengths[chunk];
|
||||
s->zstream.next_out = s->uncompressed_chunk;
|
||||
@ -253,7 +253,7 @@ static inline int dmg_read_chunk(BDRVDMGState *s,int sector_num)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dmg_read(BlockDriverState *bs, int64_t sector_num,
|
||||
static int dmg_read(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVDMGState *s = bs->opaque;
|
||||
|
114
block-qcow.c
114
block-qcow.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Block driver for the QCOW format
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004-2006 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -80,10 +80,10 @@ static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset);
|
||||
static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||
{
|
||||
const QCowHeader *cow_header = (const void *)buf;
|
||||
|
||||
|
||||
if (buf_size >= sizeof(QCowHeader) &&
|
||||
be32_to_cpu(cow_header->magic) == QCOW_MAGIC &&
|
||||
be32_to_cpu(cow_header->version) == QCOW_VERSION)
|
||||
be32_to_cpu(cow_header->version) == QCOW_VERSION)
|
||||
return 100;
|
||||
else
|
||||
return 0;
|
||||
@ -108,7 +108,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
be64_to_cpus(&header.size);
|
||||
be32_to_cpus(&header.crypt_method);
|
||||
be64_to_cpus(&header.l1_table_offset);
|
||||
|
||||
|
||||
if (header.magic != QCOW_MAGIC || header.version != QCOW_VERSION)
|
||||
goto fail;
|
||||
if (header.size <= 1 || header.cluster_bits < 9)
|
||||
@ -134,7 +134,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
s->l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t));
|
||||
if (!s->l1_table)
|
||||
goto fail;
|
||||
if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
|
||||
if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
|
||||
s->l1_size * sizeof(uint64_t))
|
||||
goto fail;
|
||||
for(i = 0;i < s->l1_size; i++) {
|
||||
@ -151,7 +151,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
if (!s->cluster_data)
|
||||
goto fail;
|
||||
s->cluster_cache_offset = -1;
|
||||
|
||||
|
||||
/* read the backing file name */
|
||||
if (header.backing_file_offset != 0) {
|
||||
len = header.backing_file_size;
|
||||
@ -177,7 +177,7 @@ static int qcow_set_key(BlockDriverState *bs, const char *key)
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
uint8_t keybuf[16];
|
||||
int len, i;
|
||||
|
||||
|
||||
memset(keybuf, 0, 16);
|
||||
len = strlen(key);
|
||||
if (len > 16)
|
||||
@ -231,7 +231,7 @@ static void encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
|
||||
for(i = 0; i < nb_sectors; i++) {
|
||||
ivec.ll[0] = cpu_to_le64(sector_num);
|
||||
ivec.ll[1] = 0;
|
||||
AES_cbc_encrypt(in_buf, out_buf, 512, key,
|
||||
AES_cbc_encrypt(in_buf, out_buf, 512, key,
|
||||
ivec.b, enc);
|
||||
sector_num++;
|
||||
in_buf += 512;
|
||||
@ -248,7 +248,7 @@ static void encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
|
||||
*
|
||||
* 2 to allocate a compressed cluster of size
|
||||
* 'compressed_size'. 'compressed_size' must be > 0 and <
|
||||
* cluster_size
|
||||
* cluster_size
|
||||
*
|
||||
* return 0 if not allocated.
|
||||
*/
|
||||
@ -262,7 +262,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||
uint64_t l2_offset, *l2_table, cluster_offset, tmp;
|
||||
uint32_t min_count;
|
||||
int new_l2_table;
|
||||
|
||||
|
||||
l1_index = offset >> (s->l2_bits + s->cluster_bits);
|
||||
l2_offset = s->l1_table[l1_index];
|
||||
new_l2_table = 0;
|
||||
@ -276,7 +276,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||
/* update the L1 entry */
|
||||
s->l1_table[l1_index] = l2_offset;
|
||||
tmp = cpu_to_be64(l2_offset);
|
||||
if (bdrv_pwrite(s->hd, s->l1_table_offset + l1_index * sizeof(tmp),
|
||||
if (bdrv_pwrite(s->hd, s->l1_table_offset + l1_index * sizeof(tmp),
|
||||
&tmp, sizeof(tmp)) != sizeof(tmp))
|
||||
return 0;
|
||||
new_l2_table = 1;
|
||||
@ -309,7 +309,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||
s->l2_size * sizeof(uint64_t))
|
||||
return 0;
|
||||
} else {
|
||||
if (bdrv_pread(s->hd, l2_offset, l2_table, s->l2_size * sizeof(uint64_t)) !=
|
||||
if (bdrv_pread(s->hd, l2_offset, l2_table, s->l2_size * sizeof(uint64_t)) !=
|
||||
s->l2_size * sizeof(uint64_t))
|
||||
return 0;
|
||||
}
|
||||
@ -318,7 +318,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||
found:
|
||||
l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1);
|
||||
cluster_offset = be64_to_cpu(l2_table[l2_index]);
|
||||
if (!cluster_offset ||
|
||||
if (!cluster_offset ||
|
||||
((cluster_offset & QCOW_OFLAG_COMPRESSED) && allocate == 1)) {
|
||||
if (!allocate)
|
||||
return 0;
|
||||
@ -331,54 +331,54 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||
if (decompress_cluster(s, cluster_offset) < 0)
|
||||
return 0;
|
||||
cluster_offset = bdrv_getlength(s->hd);
|
||||
cluster_offset = (cluster_offset + s->cluster_size - 1) &
|
||||
cluster_offset = (cluster_offset + s->cluster_size - 1) &
|
||||
~(s->cluster_size - 1);
|
||||
/* write the cluster content */
|
||||
if (bdrv_pwrite(s->hd, cluster_offset, s->cluster_cache, s->cluster_size) !=
|
||||
if (bdrv_pwrite(s->hd, cluster_offset, s->cluster_cache, s->cluster_size) !=
|
||||
s->cluster_size)
|
||||
return -1;
|
||||
} else {
|
||||
cluster_offset = bdrv_getlength(s->hd);
|
||||
if (allocate == 1) {
|
||||
/* round to cluster size */
|
||||
cluster_offset = (cluster_offset + s->cluster_size - 1) &
|
||||
cluster_offset = (cluster_offset + s->cluster_size - 1) &
|
||||
~(s->cluster_size - 1);
|
||||
bdrv_truncate(s->hd, cluster_offset + s->cluster_size);
|
||||
/* if encrypted, we must initialize the cluster
|
||||
content which won't be written */
|
||||
if (s->crypt_method &&
|
||||
if (s->crypt_method &&
|
||||
(n_end - n_start) < s->cluster_sectors) {
|
||||
uint64_t start_sect;
|
||||
start_sect = (offset & ~(s->cluster_size - 1)) >> 9;
|
||||
memset(s->cluster_data + 512, 0x00, 512);
|
||||
for(i = 0; i < s->cluster_sectors; i++) {
|
||||
if (i < n_start || i >= n_end) {
|
||||
encrypt_sectors(s, start_sect + i,
|
||||
s->cluster_data,
|
||||
encrypt_sectors(s, start_sect + i,
|
||||
s->cluster_data,
|
||||
s->cluster_data + 512, 1, 1,
|
||||
&s->aes_encrypt_key);
|
||||
if (bdrv_pwrite(s->hd, cluster_offset + i * 512,
|
||||
if (bdrv_pwrite(s->hd, cluster_offset + i * 512,
|
||||
s->cluster_data, 512) != 512)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cluster_offset |= QCOW_OFLAG_COMPRESSED |
|
||||
cluster_offset |= QCOW_OFLAG_COMPRESSED |
|
||||
(uint64_t)compressed_size << (63 - s->cluster_bits);
|
||||
}
|
||||
}
|
||||
/* update L2 table */
|
||||
tmp = cpu_to_be64(cluster_offset);
|
||||
l2_table[l2_index] = tmp;
|
||||
if (bdrv_pwrite(s->hd,
|
||||
if (bdrv_pwrite(s->hd,
|
||||
l2_offset + l2_index * sizeof(tmp), &tmp, sizeof(tmp)) != sizeof(tmp))
|
||||
return 0;
|
||||
}
|
||||
return cluster_offset;
|
||||
}
|
||||
|
||||
static int qcow_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
||||
static int qcow_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, int *pnum)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
@ -420,7 +420,7 @@ static int decompress_buffer(uint8_t *out_buf, int out_buf_size,
|
||||
inflateEnd(strm);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)
|
||||
{
|
||||
int ret, csize;
|
||||
@ -431,7 +431,7 @@ static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)
|
||||
csize = cluster_offset >> (63 - s->cluster_bits);
|
||||
csize &= (s->cluster_size - 1);
|
||||
ret = bdrv_pread(s->hd, coffset, s->cluster_data, csize);
|
||||
if (ret != csize)
|
||||
if (ret != csize)
|
||||
return -1;
|
||||
if (decompress_buffer(s->cluster_cache, s->cluster_size,
|
||||
s->cluster_data, csize) < 0) {
|
||||
@ -444,13 +444,13 @@ static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)
|
||||
|
||||
#if 0
|
||||
|
||||
static int qcow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
static int qcow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
int ret, index_in_cluster, n;
|
||||
uint64_t cluster_offset;
|
||||
|
||||
|
||||
while (nb_sectors > 0) {
|
||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0);
|
||||
index_in_cluster = sector_num & (s->cluster_sectors - 1);
|
||||
@ -472,10 +472,10 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
memcpy(buf, s->cluster_cache + index_in_cluster * 512, 512 * n);
|
||||
} else {
|
||||
ret = bdrv_pread(s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512);
|
||||
if (ret != n * 512)
|
||||
if (ret != n * 512)
|
||||
return -1;
|
||||
if (s->crypt_method) {
|
||||
encrypt_sectors(s, sector_num, buf, buf, n, 0,
|
||||
encrypt_sectors(s, sector_num, buf, buf, n, 0,
|
||||
&s->aes_decrypt_key);
|
||||
}
|
||||
}
|
||||
@ -487,32 +487,32 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
}
|
||||
#endif
|
||||
|
||||
static int qcow_write(BlockDriverState *bs, int64_t sector_num,
|
||||
static int qcow_write(BlockDriverState *bs, int64_t sector_num,
|
||||
const uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
int ret, index_in_cluster, n;
|
||||
uint64_t cluster_offset;
|
||||
|
||||
|
||||
while (nb_sectors > 0) {
|
||||
index_in_cluster = sector_num & (s->cluster_sectors - 1);
|
||||
n = s->cluster_sectors - index_in_cluster;
|
||||
if (n > nb_sectors)
|
||||
n = nb_sectors;
|
||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 1, 0,
|
||||
index_in_cluster,
|
||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 1, 0,
|
||||
index_in_cluster,
|
||||
index_in_cluster + n);
|
||||
if (!cluster_offset)
|
||||
return -1;
|
||||
if (s->crypt_method) {
|
||||
encrypt_sectors(s, sector_num, s->cluster_data, buf, n, 1,
|
||||
&s->aes_encrypt_key);
|
||||
ret = bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512,
|
||||
ret = bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512,
|
||||
s->cluster_data, n * 512);
|
||||
} else {
|
||||
ret = bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512);
|
||||
}
|
||||
if (ret != n * 512)
|
||||
if (ret != n * 512)
|
||||
return -1;
|
||||
nb_sectors -= n;
|
||||
sector_num += n;
|
||||
@ -529,7 +529,7 @@ typedef struct QCowAIOCB {
|
||||
int nb_sectors;
|
||||
int n;
|
||||
uint64_t cluster_offset;
|
||||
uint8_t *cluster_data;
|
||||
uint8_t *cluster_data;
|
||||
BlockDriverAIOCB *hd_aiocb;
|
||||
} QCowAIOCB;
|
||||
|
||||
@ -556,8 +556,8 @@ static void qcow_aio_read_cb(void *opaque, int ret)
|
||||
/* nothing to do */
|
||||
} else {
|
||||
if (s->crypt_method) {
|
||||
encrypt_sectors(s, acb->sector_num, acb->buf, acb->buf,
|
||||
acb->n, 0,
|
||||
encrypt_sectors(s, acb->sector_num, acb->buf, acb->buf,
|
||||
acb->n, 0,
|
||||
&s->aes_decrypt_key);
|
||||
}
|
||||
}
|
||||
@ -572,9 +572,9 @@ static void qcow_aio_read_cb(void *opaque, int ret)
|
||||
qemu_aio_release(acb);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* prepare next AIO request */
|
||||
acb->cluster_offset = get_cluster_offset(bs, acb->sector_num << 9,
|
||||
acb->cluster_offset = get_cluster_offset(bs, acb->sector_num << 9,
|
||||
0, 0, 0, 0);
|
||||
index_in_cluster = acb->sector_num & (s->cluster_sectors - 1);
|
||||
acb->n = s->cluster_sectors - index_in_cluster;
|
||||
@ -597,7 +597,7 @@ static void qcow_aio_read_cb(void *opaque, int ret)
|
||||
/* add AIO support for compressed blocks ? */
|
||||
if (decompress_cluster(s, acb->cluster_offset) < 0)
|
||||
goto fail;
|
||||
memcpy(acb->buf,
|
||||
memcpy(acb->buf,
|
||||
s->cluster_cache + index_in_cluster * 512, 512 * acb->n);
|
||||
goto redo;
|
||||
} else {
|
||||
@ -606,7 +606,7 @@ static void qcow_aio_read_cb(void *opaque, int ret)
|
||||
goto fail;
|
||||
}
|
||||
acb->hd_aiocb = bdrv_aio_read(s->hd,
|
||||
(acb->cluster_offset >> 9) + index_in_cluster,
|
||||
(acb->cluster_offset >> 9) + index_in_cluster,
|
||||
acb->buf, acb->n, qcow_aio_read_cb, acb);
|
||||
if (acb->hd_aiocb == NULL)
|
||||
goto fail;
|
||||
@ -627,7 +627,7 @@ static BlockDriverAIOCB *qcow_aio_read(BlockDriverState *bs,
|
||||
acb->buf = buf;
|
||||
acb->nb_sectors = nb_sectors;
|
||||
acb->n = 0;
|
||||
acb->cluster_offset = 0;
|
||||
acb->cluster_offset = 0;
|
||||
|
||||
qcow_aio_read_cb(acb, 0);
|
||||
return &acb->common;
|
||||
@ -661,13 +661,13 @@ static void qcow_aio_write_cb(void *opaque, int ret)
|
||||
qemu_aio_release(acb);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
index_in_cluster = acb->sector_num & (s->cluster_sectors - 1);
|
||||
acb->n = s->cluster_sectors - index_in_cluster;
|
||||
if (acb->n > acb->nb_sectors)
|
||||
acb->n = acb->nb_sectors;
|
||||
cluster_offset = get_cluster_offset(bs, acb->sector_num << 9, 1, 0,
|
||||
index_in_cluster,
|
||||
cluster_offset = get_cluster_offset(bs, acb->sector_num << 9, 1, 0,
|
||||
index_in_cluster,
|
||||
index_in_cluster + acb->n);
|
||||
if (!cluster_offset || (cluster_offset & 511) != 0) {
|
||||
ret = -EIO;
|
||||
@ -681,15 +681,15 @@ static void qcow_aio_write_cb(void *opaque, int ret)
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf,
|
||||
encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf,
|
||||
acb->n, 1, &s->aes_encrypt_key);
|
||||
src_buf = acb->cluster_data;
|
||||
} else {
|
||||
src_buf = acb->buf;
|
||||
}
|
||||
acb->hd_aiocb = bdrv_aio_write(s->hd,
|
||||
(cluster_offset >> 9) + index_in_cluster,
|
||||
src_buf, acb->n,
|
||||
(cluster_offset >> 9) + index_in_cluster,
|
||||
src_buf, acb->n,
|
||||
qcow_aio_write_cb, acb);
|
||||
if (acb->hd_aiocb == NULL)
|
||||
goto fail;
|
||||
@ -701,7 +701,7 @@ static BlockDriverAIOCB *qcow_aio_write(BlockDriverState *bs,
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
QCowAIOCB *acb;
|
||||
|
||||
|
||||
s->cluster_cache_offset = -1; /* disable compressed cache */
|
||||
|
||||
acb = qemu_aio_get(bs, cb, opaque);
|
||||
@ -712,7 +712,7 @@ static BlockDriverAIOCB *qcow_aio_write(BlockDriverState *bs,
|
||||
acb->buf = (uint8_t *)buf;
|
||||
acb->nb_sectors = nb_sectors;
|
||||
acb->n = 0;
|
||||
|
||||
|
||||
qcow_aio_write_cb(acb, 0);
|
||||
return &acb->common;
|
||||
}
|
||||
@ -774,7 +774,7 @@ static int qcow_create(const char *filename, int64_t total_size,
|
||||
} else {
|
||||
header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE);
|
||||
}
|
||||
|
||||
|
||||
/* write all the data */
|
||||
write(fd, &header, sizeof(header));
|
||||
if (backing_file) {
|
||||
@ -811,7 +811,7 @@ static int qcow_make_empty(BlockDriverState *bs)
|
||||
|
||||
/* XXX: put compressed sectors first, then all the cluster aligned
|
||||
tables to avoid losing bytes in alignment */
|
||||
static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
const uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
@ -830,7 +830,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
/* best compression, small window, no zlib header */
|
||||
memset(&strm, 0, sizeof(strm));
|
||||
ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION,
|
||||
Z_DEFLATED, -12,
|
||||
Z_DEFLATED, -12,
|
||||
9, Z_DEFAULT_STRATEGY);
|
||||
if (ret != 0) {
|
||||
qemu_free(out_buf);
|
||||
@ -856,7 +856,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
/* could not compress: write normal cluster */
|
||||
qcow_write(bs, sector_num, buf, s->cluster_sectors);
|
||||
} else {
|
||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 2,
|
||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 2,
|
||||
out_len, 0, 0);
|
||||
cluster_offset &= s->cluster_offset_mask;
|
||||
if (bdrv_pwrite(s->hd, cluster_offset, out_buf, out_len) != out_len) {
|
||||
@ -864,7 +864,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
qemu_free(out_buf);
|
||||
return 0;
|
||||
}
|
||||
|
258
block-qcow2.c
258
block-qcow2.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Block driver for the QCOW version 2 format
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004-2006 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -34,10 +34,10 @@
|
||||
- Memory management by reference counts.
|
||||
- Clusters which have a reference count of one have the bit
|
||||
QCOW_OFLAG_COPIED to optimize write performance.
|
||||
- Size of compressed clusters is stored in sectors to reduce bit usage
|
||||
- Size of compressed clusters is stored in sectors to reduce bit usage
|
||||
in the cluster offsets.
|
||||
- Support for storing additional data (such as the VM state) in the
|
||||
snapshots.
|
||||
snapshots.
|
||||
- If a backing store is used, the cluster size is not constrained
|
||||
(could be backported to QCOW).
|
||||
- L2 tables have always a size of one cluster.
|
||||
@ -45,7 +45,7 @@
|
||||
|
||||
//#define DEBUG_ALLOC
|
||||
//#define DEBUG_ALLOC2
|
||||
|
||||
|
||||
#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb)
|
||||
#define QCOW_VERSION 2
|
||||
|
||||
@ -152,22 +152,22 @@ typedef struct BDRVQcowState {
|
||||
} BDRVQcowState;
|
||||
|
||||
static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset);
|
||||
static int qcow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
static int qcow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors);
|
||||
static int qcow_read_snapshots(BlockDriverState *bs);
|
||||
static void qcow_free_snapshots(BlockDriverState *bs);
|
||||
static int refcount_init(BlockDriverState *bs);
|
||||
static void refcount_close(BlockDriverState *bs);
|
||||
static int get_refcount(BlockDriverState *bs, int64_t cluster_index);
|
||||
static int update_cluster_refcount(BlockDriverState *bs,
|
||||
static int update_cluster_refcount(BlockDriverState *bs,
|
||||
int64_t cluster_index,
|
||||
int addend);
|
||||
static void update_refcount(BlockDriverState *bs,
|
||||
int64_t offset, int64_t length,
|
||||
static void update_refcount(BlockDriverState *bs,
|
||||
int64_t offset, int64_t length,
|
||||
int addend);
|
||||
static int64_t alloc_clusters(BlockDriverState *bs, int64_t size);
|
||||
static int64_t alloc_bytes(BlockDriverState *bs, int size);
|
||||
static void free_clusters(BlockDriverState *bs,
|
||||
static void free_clusters(BlockDriverState *bs,
|
||||
int64_t offset, int64_t size);
|
||||
#ifdef DEBUG_ALLOC
|
||||
static void check_refcounts(BlockDriverState *bs);
|
||||
@ -176,10 +176,10 @@ static void check_refcounts(BlockDriverState *bs);
|
||||
static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||
{
|
||||
const QCowHeader *cow_header = (const void *)buf;
|
||||
|
||||
|
||||
if (buf_size >= sizeof(QCowHeader) &&
|
||||
be32_to_cpu(cow_header->magic) == QCOW_MAGIC &&
|
||||
be32_to_cpu(cow_header->version) == QCOW_VERSION)
|
||||
be32_to_cpu(cow_header->version) == QCOW_VERSION)
|
||||
return 100;
|
||||
else
|
||||
return 0;
|
||||
@ -209,11 +209,11 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
be32_to_cpus(&header.refcount_table_clusters);
|
||||
be64_to_cpus(&header.snapshots_offset);
|
||||
be32_to_cpus(&header.nb_snapshots);
|
||||
|
||||
|
||||
if (header.magic != QCOW_MAGIC || header.version != QCOW_VERSION)
|
||||
goto fail;
|
||||
if (header.size <= 1 ||
|
||||
header.cluster_bits < 9 ||
|
||||
if (header.size <= 1 ||
|
||||
header.cluster_bits < 9 ||
|
||||
header.cluster_bits > 16)
|
||||
goto fail;
|
||||
if (header.crypt_method > QCOW_CRYPT_AES)
|
||||
@ -231,7 +231,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
s->csize_mask = (1 << (s->cluster_bits - 8)) - 1;
|
||||
s->cluster_offset_mask = (1LL << s->csize_shift) - 1;
|
||||
s->refcount_table_offset = header.refcount_table_offset;
|
||||
s->refcount_table_size =
|
||||
s->refcount_table_size =
|
||||
header.refcount_table_clusters << (s->cluster_bits - 3);
|
||||
|
||||
s->snapshots_offset = header.snapshots_offset;
|
||||
@ -249,7 +249,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
s->l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t));
|
||||
if (!s->l1_table)
|
||||
goto fail;
|
||||
if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
|
||||
if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
|
||||
s->l1_size * sizeof(uint64_t))
|
||||
goto fail;
|
||||
for(i = 0;i < s->l1_size; i++) {
|
||||
@ -267,7 +267,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
if (!s->cluster_data)
|
||||
goto fail;
|
||||
s->cluster_cache_offset = -1;
|
||||
|
||||
|
||||
if (refcount_init(bs) < 0)
|
||||
goto fail;
|
||||
|
||||
@ -304,7 +304,7 @@ static int qcow_set_key(BlockDriverState *bs, const char *key)
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
uint8_t keybuf[16];
|
||||
int len, i;
|
||||
|
||||
|
||||
memset(keybuf, 0, 16);
|
||||
len = strlen(key);
|
||||
if (len > 16)
|
||||
@ -358,7 +358,7 @@ static void encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
|
||||
for(i = 0; i < nb_sectors; i++) {
|
||||
ivec.ll[0] = cpu_to_le64(sector_num);
|
||||
ivec.ll[1] = 0;
|
||||
AES_cbc_encrypt(in_buf, out_buf, 512, key,
|
||||
AES_cbc_encrypt(in_buf, out_buf, 512, key,
|
||||
ivec.b, enc);
|
||||
sector_num++;
|
||||
in_buf += 512;
|
||||
@ -379,12 +379,12 @@ static int copy_sectors(BlockDriverState *bs, uint64_t start_sect,
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (s->crypt_method) {
|
||||
encrypt_sectors(s, start_sect + n_start,
|
||||
s->cluster_data,
|
||||
encrypt_sectors(s, start_sect + n_start,
|
||||
s->cluster_data,
|
||||
s->cluster_data, n, 1,
|
||||
&s->aes_encrypt_key);
|
||||
}
|
||||
ret = bdrv_write(s->hd, (cluster_offset >> 9) + n_start,
|
||||
ret = bdrv_write(s->hd, (cluster_offset >> 9) + n_start,
|
||||
s->cluster_data, n);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@ -451,7 +451,7 @@ static int grow_l1_table(BlockDriverState *bs, int min_size)
|
||||
|
||||
/* write new table (align to cluster) */
|
||||
new_l1_table_offset = alloc_clusters(bs, new_l1_size2);
|
||||
|
||||
|
||||
for(i = 0; i < s->l1_size; i++)
|
||||
new_l1_table[i] = cpu_to_be64(new_l1_table[i]);
|
||||
ret = bdrv_pwrite(s->hd, new_l1_table_offset, new_l1_table, new_l1_size2);
|
||||
@ -459,7 +459,7 @@ static int grow_l1_table(BlockDriverState *bs, int min_size)
|
||||
goto fail;
|
||||
for(i = 0; i < s->l1_size; i++)
|
||||
new_l1_table[i] = be64_to_cpu(new_l1_table[i]);
|
||||
|
||||
|
||||
/* set new table */
|
||||
data64 = cpu_to_be64(new_l1_table_offset);
|
||||
if (bdrv_pwrite(s->hd, offsetof(QCowHeader, l1_table_offset),
|
||||
@ -489,7 +489,7 @@ static int grow_l1_table(BlockDriverState *bs, int min_size)
|
||||
*
|
||||
* 2 to allocate a compressed cluster of size
|
||||
* 'compressed_size'. 'compressed_size' must be > 0 and <
|
||||
* cluster_size
|
||||
* cluster_size
|
||||
*
|
||||
* return 0 if not allocated.
|
||||
*/
|
||||
@ -501,7 +501,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
int min_index, i, j, l1_index, l2_index, ret;
|
||||
uint64_t l2_offset, *l2_table, cluster_offset, tmp, old_l2_offset;
|
||||
|
||||
|
||||
l1_index = offset >> (s->l2_bits + s->cluster_bits);
|
||||
if (l1_index >= s->l1_size) {
|
||||
/* outside l1 table is allowed: we grow the table if needed */
|
||||
@ -521,7 +521,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||
/* update the L1 entry */
|
||||
s->l1_table[l1_index] = l2_offset | QCOW_OFLAG_COPIED;
|
||||
tmp = cpu_to_be64(l2_offset | QCOW_OFLAG_COPIED);
|
||||
if (bdrv_pwrite(s->hd, s->l1_table_offset + l1_index * sizeof(tmp),
|
||||
if (bdrv_pwrite(s->hd, s->l1_table_offset + l1_index * sizeof(tmp),
|
||||
&tmp, sizeof(tmp)) != sizeof(tmp))
|
||||
return 0;
|
||||
min_index = l2_cache_new_entry(bs);
|
||||
@ -530,12 +530,12 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||
if (old_l2_offset == 0) {
|
||||
memset(l2_table, 0, s->l2_size * sizeof(uint64_t));
|
||||
} else {
|
||||
if (bdrv_pread(s->hd, old_l2_offset,
|
||||
if (bdrv_pread(s->hd, old_l2_offset,
|
||||
l2_table, s->l2_size * sizeof(uint64_t)) !=
|
||||
s->l2_size * sizeof(uint64_t))
|
||||
return 0;
|
||||
}
|
||||
if (bdrv_pwrite(s->hd, l2_offset,
|
||||
if (bdrv_pwrite(s->hd, l2_offset,
|
||||
l2_table, s->l2_size * sizeof(uint64_t)) !=
|
||||
s->l2_size * sizeof(uint64_t))
|
||||
return 0;
|
||||
@ -563,7 +563,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||
/* not found: load a new entry in the least used one */
|
||||
min_index = l2_cache_new_entry(bs);
|
||||
l2_table = s->l2_cache + (min_index << s->l2_bits);
|
||||
if (bdrv_pread(s->hd, l2_offset, l2_table, s->l2_size * sizeof(uint64_t)) !=
|
||||
if (bdrv_pread(s->hd, l2_offset, l2_table, s->l2_size * sizeof(uint64_t)) !=
|
||||
s->l2_size * sizeof(uint64_t))
|
||||
return 0;
|
||||
}
|
||||
@ -581,7 +581,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||
/* free the cluster */
|
||||
if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
|
||||
int nb_csectors;
|
||||
nb_csectors = ((cluster_offset >> s->csize_shift) &
|
||||
nb_csectors = ((cluster_offset >> s->csize_shift) &
|
||||
s->csize_mask) + 1;
|
||||
free_clusters(bs, (cluster_offset & s->cluster_offset_mask) & ~511,
|
||||
nb_csectors * 512);
|
||||
@ -600,7 +600,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||
written */
|
||||
if ((n_end - n_start) < s->cluster_sectors) {
|
||||
uint64_t start_sect;
|
||||
|
||||
|
||||
start_sect = (offset & ~(s->cluster_size - 1)) >> 9;
|
||||
ret = copy_sectors(bs, start_sect,
|
||||
cluster_offset, 0, n_start);
|
||||
@ -615,22 +615,22 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||
} else {
|
||||
int nb_csectors;
|
||||
cluster_offset = alloc_bytes(bs, compressed_size);
|
||||
nb_csectors = ((cluster_offset + compressed_size - 1) >> 9) -
|
||||
nb_csectors = ((cluster_offset + compressed_size - 1) >> 9) -
|
||||
(cluster_offset >> 9);
|
||||
cluster_offset |= QCOW_OFLAG_COMPRESSED |
|
||||
cluster_offset |= QCOW_OFLAG_COMPRESSED |
|
||||
((uint64_t)nb_csectors << s->csize_shift);
|
||||
/* compressed clusters never have the copied flag */
|
||||
tmp = cpu_to_be64(cluster_offset);
|
||||
}
|
||||
/* update L2 table */
|
||||
l2_table[l2_index] = tmp;
|
||||
if (bdrv_pwrite(s->hd,
|
||||
if (bdrv_pwrite(s->hd,
|
||||
l2_offset + l2_index * sizeof(tmp), &tmp, sizeof(tmp)) != sizeof(tmp))
|
||||
return 0;
|
||||
return cluster_offset;
|
||||
}
|
||||
|
||||
static int qcow_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
||||
static int qcow_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, int *pnum)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
@ -672,7 +672,7 @@ static int decompress_buffer(uint8_t *out_buf, int out_buf_size,
|
||||
inflateEnd(strm);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)
|
||||
{
|
||||
int ret, csize, nb_csectors, sector_offset;
|
||||
@ -697,7 +697,7 @@ static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)
|
||||
}
|
||||
|
||||
/* handle reading after the end of the backing file */
|
||||
static int backing_read1(BlockDriverState *bs,
|
||||
static int backing_read1(BlockDriverState *bs,
|
||||
int64_t sector_num, uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
int n1;
|
||||
@ -711,13 +711,13 @@ static int backing_read1(BlockDriverState *bs,
|
||||
return n1;
|
||||
}
|
||||
|
||||
static int qcow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
static int qcow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
int ret, index_in_cluster, n, n1;
|
||||
uint64_t cluster_offset;
|
||||
|
||||
|
||||
while (nb_sectors > 0) {
|
||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0);
|
||||
index_in_cluster = sector_num & (s->cluster_sectors - 1);
|
||||
@ -742,10 +742,10 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
memcpy(buf, s->cluster_cache + index_in_cluster * 512, 512 * n);
|
||||
} else {
|
||||
ret = bdrv_pread(s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512);
|
||||
if (ret != n * 512)
|
||||
if (ret != n * 512)
|
||||
return -1;
|
||||
if (s->crypt_method) {
|
||||
encrypt_sectors(s, sector_num, buf, buf, n, 0,
|
||||
encrypt_sectors(s, sector_num, buf, buf, n, 0,
|
||||
&s->aes_decrypt_key);
|
||||
}
|
||||
}
|
||||
@ -756,32 +756,32 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qcow_write(BlockDriverState *bs, int64_t sector_num,
|
||||
static int qcow_write(BlockDriverState *bs, int64_t sector_num,
|
||||
const uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
int ret, index_in_cluster, n;
|
||||
uint64_t cluster_offset;
|
||||
|
||||
|
||||
while (nb_sectors > 0) {
|
||||
index_in_cluster = sector_num & (s->cluster_sectors - 1);
|
||||
n = s->cluster_sectors - index_in_cluster;
|
||||
if (n > nb_sectors)
|
||||
n = nb_sectors;
|
||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 1, 0,
|
||||
index_in_cluster,
|
||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 1, 0,
|
||||
index_in_cluster,
|
||||
index_in_cluster + n);
|
||||
if (!cluster_offset)
|
||||
return -1;
|
||||
if (s->crypt_method) {
|
||||
encrypt_sectors(s, sector_num, s->cluster_data, buf, n, 1,
|
||||
&s->aes_encrypt_key);
|
||||
ret = bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512,
|
||||
ret = bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512,
|
||||
s->cluster_data, n * 512);
|
||||
} else {
|
||||
ret = bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512);
|
||||
}
|
||||
if (ret != n * 512)
|
||||
if (ret != n * 512)
|
||||
return -1;
|
||||
nb_sectors -= n;
|
||||
sector_num += n;
|
||||
@ -798,7 +798,7 @@ typedef struct QCowAIOCB {
|
||||
int nb_sectors;
|
||||
int n;
|
||||
uint64_t cluster_offset;
|
||||
uint8_t *cluster_data;
|
||||
uint8_t *cluster_data;
|
||||
BlockDriverAIOCB *hd_aiocb;
|
||||
} QCowAIOCB;
|
||||
|
||||
@ -825,8 +825,8 @@ static void qcow_aio_read_cb(void *opaque, int ret)
|
||||
/* nothing to do */
|
||||
} else {
|
||||
if (s->crypt_method) {
|
||||
encrypt_sectors(s, acb->sector_num, acb->buf, acb->buf,
|
||||
acb->n, 0,
|
||||
encrypt_sectors(s, acb->sector_num, acb->buf, acb->buf,
|
||||
acb->n, 0,
|
||||
&s->aes_decrypt_key);
|
||||
}
|
||||
}
|
||||
@ -841,9 +841,9 @@ static void qcow_aio_read_cb(void *opaque, int ret)
|
||||
qemu_aio_release(acb);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* prepare next AIO request */
|
||||
acb->cluster_offset = get_cluster_offset(bs, acb->sector_num << 9,
|
||||
acb->cluster_offset = get_cluster_offset(bs, acb->sector_num << 9,
|
||||
0, 0, 0, 0);
|
||||
index_in_cluster = acb->sector_num & (s->cluster_sectors - 1);
|
||||
acb->n = s->cluster_sectors - index_in_cluster;
|
||||
@ -853,10 +853,10 @@ static void qcow_aio_read_cb(void *opaque, int ret)
|
||||
if (!acb->cluster_offset) {
|
||||
if (bs->backing_hd) {
|
||||
/* read from the base image */
|
||||
n1 = backing_read1(bs->backing_hd, acb->sector_num,
|
||||
n1 = backing_read1(bs->backing_hd, acb->sector_num,
|
||||
acb->buf, acb->n);
|
||||
if (n1 > 0) {
|
||||
acb->hd_aiocb = bdrv_aio_read(bs->backing_hd, acb->sector_num,
|
||||
acb->hd_aiocb = bdrv_aio_read(bs->backing_hd, acb->sector_num,
|
||||
acb->buf, acb->n, qcow_aio_read_cb, acb);
|
||||
if (acb->hd_aiocb == NULL)
|
||||
goto fail;
|
||||
@ -872,7 +872,7 @@ static void qcow_aio_read_cb(void *opaque, int ret)
|
||||
/* add AIO support for compressed blocks ? */
|
||||
if (decompress_cluster(s, acb->cluster_offset) < 0)
|
||||
goto fail;
|
||||
memcpy(acb->buf,
|
||||
memcpy(acb->buf,
|
||||
s->cluster_cache + index_in_cluster * 512, 512 * acb->n);
|
||||
goto redo;
|
||||
} else {
|
||||
@ -881,7 +881,7 @@ static void qcow_aio_read_cb(void *opaque, int ret)
|
||||
goto fail;
|
||||
}
|
||||
acb->hd_aiocb = bdrv_aio_read(s->hd,
|
||||
(acb->cluster_offset >> 9) + index_in_cluster,
|
||||
(acb->cluster_offset >> 9) + index_in_cluster,
|
||||
acb->buf, acb->n, qcow_aio_read_cb, acb);
|
||||
if (acb->hd_aiocb == NULL)
|
||||
goto fail;
|
||||
@ -948,13 +948,13 @@ static void qcow_aio_write_cb(void *opaque, int ret)
|
||||
qemu_aio_release(acb);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
index_in_cluster = acb->sector_num & (s->cluster_sectors - 1);
|
||||
acb->n = s->cluster_sectors - index_in_cluster;
|
||||
if (acb->n > acb->nb_sectors)
|
||||
acb->n = acb->nb_sectors;
|
||||
cluster_offset = get_cluster_offset(bs, acb->sector_num << 9, 1, 0,
|
||||
index_in_cluster,
|
||||
cluster_offset = get_cluster_offset(bs, acb->sector_num << 9, 1, 0,
|
||||
index_in_cluster,
|
||||
index_in_cluster + acb->n);
|
||||
if (!cluster_offset || (cluster_offset & 511) != 0) {
|
||||
ret = -EIO;
|
||||
@ -968,15 +968,15 @@ static void qcow_aio_write_cb(void *opaque, int ret)
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf,
|
||||
encrypt_sectors(s, acb->sector_num, acb->cluster_data, acb->buf,
|
||||
acb->n, 1, &s->aes_encrypt_key);
|
||||
src_buf = acb->cluster_data;
|
||||
} else {
|
||||
src_buf = acb->buf;
|
||||
}
|
||||
acb->hd_aiocb = bdrv_aio_write(s->hd,
|
||||
(cluster_offset >> 9) + index_in_cluster,
|
||||
src_buf, acb->n,
|
||||
(cluster_offset >> 9) + index_in_cluster,
|
||||
src_buf, acb->n,
|
||||
qcow_aio_write_cb, acb);
|
||||
if (acb->hd_aiocb == NULL)
|
||||
goto fail;
|
||||
@ -988,13 +988,13 @@ static BlockDriverAIOCB *qcow_aio_write(BlockDriverState *bs,
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
QCowAIOCB *acb;
|
||||
|
||||
|
||||
s->cluster_cache_offset = -1; /* disable compressed cache */
|
||||
|
||||
acb = qcow_aio_setup(bs, sector_num, (uint8_t*)buf, nb_sectors, cb, opaque);
|
||||
if (!acb)
|
||||
return NULL;
|
||||
|
||||
|
||||
qcow_aio_write_cb(acb, 0);
|
||||
return &acb->common;
|
||||
}
|
||||
@ -1038,7 +1038,7 @@ static void create_refcount_update(QCowCreateState *s,
|
||||
|
||||
start = offset & ~(s->cluster_size - 1);
|
||||
last = (offset + size - 1) & ~(s->cluster_size - 1);
|
||||
for(cluster_offset = start; cluster_offset <= last;
|
||||
for(cluster_offset = start; cluster_offset <= last;
|
||||
cluster_offset += s->cluster_size) {
|
||||
p = &s->refcount_block[cluster_offset >> s->cluster_bits];
|
||||
refcount = be16_to_cpu(*p);
|
||||
@ -1054,7 +1054,7 @@ static int qcow_create(const char *filename, int64_t total_size,
|
||||
QCowHeader header;
|
||||
uint64_t tmp, offset;
|
||||
QCowCreateState s1, *s = &s1;
|
||||
|
||||
|
||||
memset(s, 0, sizeof(*s));
|
||||
|
||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
|
||||
@ -1096,7 +1096,7 @@ static int qcow_create(const char *filename, int64_t total_size,
|
||||
s->refcount_block = qemu_mallocz(s->cluster_size);
|
||||
if (!s->refcount_block)
|
||||
goto fail;
|
||||
|
||||
|
||||
s->refcount_table_offset = offset;
|
||||
header.refcount_table_offset = cpu_to_be64(offset);
|
||||
header.refcount_table_clusters = cpu_to_be32(1);
|
||||
@ -1111,7 +1111,7 @@ static int qcow_create(const char *filename, int64_t total_size,
|
||||
create_refcount_update(s, s->l1_table_offset, l1_size * sizeof(uint64_t));
|
||||
create_refcount_update(s, s->refcount_table_offset, s->cluster_size);
|
||||
create_refcount_update(s, s->refcount_block_offset, s->cluster_size);
|
||||
|
||||
|
||||
/* write all the data */
|
||||
write(fd, &header, sizeof(header));
|
||||
if (backing_file) {
|
||||
@ -1124,7 +1124,7 @@ static int qcow_create(const char *filename, int64_t total_size,
|
||||
}
|
||||
lseek(fd, s->refcount_table_offset, SEEK_SET);
|
||||
write(fd, s->refcount_table, s->cluster_size);
|
||||
|
||||
|
||||
lseek(fd, s->refcount_block_offset, SEEK_SET);
|
||||
write(fd, s->refcount_block, s->cluster_size);
|
||||
|
||||
@ -1153,7 +1153,7 @@ static int qcow_make_empty(BlockDriverState *bs)
|
||||
ret = bdrv_truncate(s->hd, s->l1_table_offset + l1_length);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
|
||||
l2_cache_reset(bs);
|
||||
#endif
|
||||
return 0;
|
||||
@ -1161,7 +1161,7 @@ static int qcow_make_empty(BlockDriverState *bs)
|
||||
|
||||
/* XXX: put compressed sectors first, then all the cluster aligned
|
||||
tables to avoid losing bytes in alignment */
|
||||
static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
const uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
@ -1189,7 +1189,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
/* best compression, small window, no zlib header */
|
||||
memset(&strm, 0, sizeof(strm));
|
||||
ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION,
|
||||
Z_DEFLATED, -12,
|
||||
Z_DEFLATED, -12,
|
||||
9, Z_DEFAULT_STRATEGY);
|
||||
if (ret != 0) {
|
||||
qemu_free(out_buf);
|
||||
@ -1215,7 +1215,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
/* could not compress: write normal cluster */
|
||||
qcow_write(bs, sector_num, buf, s->cluster_sectors);
|
||||
} else {
|
||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 2,
|
||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 2,
|
||||
out_len, 0, 0);
|
||||
cluster_offset &= s->cluster_offset_mask;
|
||||
if (bdrv_pwrite(s->hd, cluster_offset, out_buf, out_len) != out_len) {
|
||||
@ -1223,7 +1223,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
qemu_free(out_buf);
|
||||
return 0;
|
||||
}
|
||||
@ -1238,7 +1238,7 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
bdi->cluster_size = s->cluster_size;
|
||||
bdi->vm_state_offset = (int64_t)s->l1_vm_state_index <<
|
||||
bdi->vm_state_offset = (int64_t)s->l1_vm_state_index <<
|
||||
(s->cluster_bits + s->l2_bits);
|
||||
return 0;
|
||||
}
|
||||
@ -1247,7 +1247,7 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
|
||||
/* snapshot support */
|
||||
|
||||
/* update the refcounts of snapshots and the copied flag */
|
||||
static int update_snapshot_refcount(BlockDriverState *bs,
|
||||
static int update_snapshot_refcount(BlockDriverState *bs,
|
||||
int64_t l1_table_offset,
|
||||
int l1_size,
|
||||
int addend)
|
||||
@ -1256,7 +1256,7 @@ static int update_snapshot_refcount(BlockDriverState *bs,
|
||||
uint64_t *l1_table, *l2_table, l2_offset, offset, l1_size2, l1_allocated;
|
||||
int64_t old_offset, old_l2_offset;
|
||||
int l2_size, i, j, l1_modified, l2_modified, nb_csectors, refcount;
|
||||
|
||||
|
||||
l2_cache_reset(bs);
|
||||
|
||||
l2_table = NULL;
|
||||
@ -1268,7 +1268,7 @@ static int update_snapshot_refcount(BlockDriverState *bs,
|
||||
if (!l1_table)
|
||||
goto fail;
|
||||
l1_allocated = 1;
|
||||
if (bdrv_pread(s->hd, l1_table_offset,
|
||||
if (bdrv_pread(s->hd, l1_table_offset,
|
||||
l1_table, l1_size2) != l1_size2)
|
||||
goto fail;
|
||||
for(i = 0;i < l1_size; i++)
|
||||
@ -1278,7 +1278,7 @@ static int update_snapshot_refcount(BlockDriverState *bs,
|
||||
l1_table = s->l1_table;
|
||||
l1_allocated = 0;
|
||||
}
|
||||
|
||||
|
||||
l2_size = s->l2_size * sizeof(uint64_t);
|
||||
l2_table = qemu_malloc(l2_size);
|
||||
if (!l2_table)
|
||||
@ -1298,13 +1298,13 @@ static int update_snapshot_refcount(BlockDriverState *bs,
|
||||
old_offset = offset;
|
||||
offset &= ~QCOW_OFLAG_COPIED;
|
||||
if (offset & QCOW_OFLAG_COMPRESSED) {
|
||||
nb_csectors = ((offset >> s->csize_shift) &
|
||||
nb_csectors = ((offset >> s->csize_shift) &
|
||||
s->csize_mask) + 1;
|
||||
if (addend != 0)
|
||||
update_refcount(bs, (offset & s->cluster_offset_mask) & ~511,
|
||||
nb_csectors * 512, addend);
|
||||
/* compressed clusters are never modified */
|
||||
refcount = 2;
|
||||
refcount = 2;
|
||||
} else {
|
||||
if (addend != 0) {
|
||||
refcount = update_cluster_refcount(bs, offset >> s->cluster_bits, addend);
|
||||
@ -1323,7 +1323,7 @@ static int update_snapshot_refcount(BlockDriverState *bs,
|
||||
}
|
||||
}
|
||||
if (l2_modified) {
|
||||
if (bdrv_pwrite(s->hd,
|
||||
if (bdrv_pwrite(s->hd,
|
||||
l2_offset, l2_table, l2_size) != l2_size)
|
||||
goto fail;
|
||||
}
|
||||
@ -1345,7 +1345,7 @@ static int update_snapshot_refcount(BlockDriverState *bs,
|
||||
if (l1_modified) {
|
||||
for(i = 0; i < l1_size; i++)
|
||||
cpu_to_be64s(&l1_table[i]);
|
||||
if (bdrv_pwrite(s->hd, l1_table_offset, l1_table,
|
||||
if (bdrv_pwrite(s->hd, l1_table_offset, l1_table,
|
||||
l1_size2) != l1_size2)
|
||||
goto fail;
|
||||
for(i = 0; i < l1_size; i++)
|
||||
@ -1455,7 +1455,7 @@ static int qcow_write_snapshots(BlockDriverState *bs)
|
||||
|
||||
snapshots_offset = alloc_clusters(bs, snapshots_size);
|
||||
offset = snapshots_offset;
|
||||
|
||||
|
||||
for(i = 0; i < s->nb_snapshots; i++) {
|
||||
sn = s->snapshots + i;
|
||||
memset(&h, 0, sizeof(h));
|
||||
@ -1465,7 +1465,7 @@ static int qcow_write_snapshots(BlockDriverState *bs)
|
||||
h.date_sec = cpu_to_be32(sn->date_sec);
|
||||
h.date_nsec = cpu_to_be32(sn->date_nsec);
|
||||
h.vm_clock_nsec = cpu_to_be64(sn->vm_clock_nsec);
|
||||
|
||||
|
||||
id_str_size = strlen(sn->id_str);
|
||||
name_size = strlen(sn->name);
|
||||
h.id_str_size = cpu_to_be16(id_str_size);
|
||||
@ -1533,7 +1533,7 @@ static int find_snapshot_by_id_or_name(BlockDriverState *bs, const char *name)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
int i, ret;
|
||||
|
||||
|
||||
ret = find_snapshot_by_id(bs, name);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
@ -1545,14 +1545,14 @@ static int find_snapshot_by_id_or_name(BlockDriverState *bs, const char *name)
|
||||
}
|
||||
|
||||
/* if no id is provided, a new one is constructed */
|
||||
static int qcow_snapshot_create(BlockDriverState *bs,
|
||||
static int qcow_snapshot_create(BlockDriverState *bs,
|
||||
QEMUSnapshotInfo *sn_info)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
QCowSnapshot *snapshots1, sn1, *sn = &sn1;
|
||||
int i, ret;
|
||||
uint64_t *l1_table = NULL;
|
||||
|
||||
|
||||
memset(sn, 0, sizeof(*sn));
|
||||
|
||||
if (sn_info->id_str[0] == '\0') {
|
||||
@ -1590,7 +1590,7 @@ static int qcow_snapshot_create(BlockDriverState *bs,
|
||||
l1_table[i] = cpu_to_be64(s->l1_table[i]);
|
||||
}
|
||||
if (bdrv_pwrite(s->hd, sn->l1_table_offset,
|
||||
l1_table, s->l1_size * sizeof(uint64_t)) !=
|
||||
l1_table, s->l1_size * sizeof(uint64_t)) !=
|
||||
(s->l1_size * sizeof(uint64_t)))
|
||||
goto fail;
|
||||
qemu_free(l1_table);
|
||||
@ -1616,7 +1616,7 @@ static int qcow_snapshot_create(BlockDriverState *bs,
|
||||
}
|
||||
|
||||
/* copy the snapshot 'snapshot_name' into the current disk image */
|
||||
static int qcow_snapshot_goto(BlockDriverState *bs,
|
||||
static int qcow_snapshot_goto(BlockDriverState *bs,
|
||||
const char *snapshot_id)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
@ -1637,7 +1637,7 @@ static int qcow_snapshot_goto(BlockDriverState *bs,
|
||||
s->l1_size = sn->l1_size;
|
||||
l1_size2 = s->l1_size * sizeof(uint64_t);
|
||||
/* copy the snapshot l1 table to the current l1 table */
|
||||
if (bdrv_pread(s->hd, sn->l1_table_offset,
|
||||
if (bdrv_pread(s->hd, sn->l1_table_offset,
|
||||
s->l1_table, l1_size2) != l1_size2)
|
||||
goto fail;
|
||||
if (bdrv_pwrite(s->hd, s->l1_table_offset,
|
||||
@ -1663,7 +1663,7 @@ static int qcow_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
QCowSnapshot *sn;
|
||||
int snapshot_index, ret;
|
||||
|
||||
|
||||
snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_id);
|
||||
if (snapshot_index < 0)
|
||||
return -ENOENT;
|
||||
@ -1693,7 +1693,7 @@ static int qcow_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qcow_snapshot_list(BlockDriverState *bs,
|
||||
static int qcow_snapshot_list(BlockDriverState *bs,
|
||||
QEMUSnapshotInfo **psn_tab)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
@ -1731,7 +1731,7 @@ static int refcount_init(BlockDriverState *bs)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
int ret, refcount_table_size2, i;
|
||||
|
||||
|
||||
s->refcount_block_cache = qemu_malloc(s->cluster_size);
|
||||
if (!s->refcount_block_cache)
|
||||
goto fail;
|
||||
@ -1760,12 +1760,12 @@ static void refcount_close(BlockDriverState *bs)
|
||||
}
|
||||
|
||||
|
||||
static int load_refcount_block(BlockDriverState *bs,
|
||||
static int load_refcount_block(BlockDriverState *bs,
|
||||
int64_t refcount_block_offset)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
int ret;
|
||||
ret = bdrv_pread(s->hd, refcount_block_offset, s->refcount_block_cache,
|
||||
ret = bdrv_pread(s->hd, refcount_block_offset, s->refcount_block_cache,
|
||||
s->cluster_size);
|
||||
if (ret != s->cluster_size)
|
||||
return -EIO;
|
||||
@ -1790,7 +1790,7 @@ static int get_refcount(BlockDriverState *bs, int64_t cluster_index)
|
||||
if (load_refcount_block(bs, refcount_block_offset) < 0)
|
||||
return 1;
|
||||
}
|
||||
block_index = cluster_index &
|
||||
block_index = cluster_index &
|
||||
((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1);
|
||||
return be16_to_cpu(s->refcount_block_cache[block_index]);
|
||||
}
|
||||
@ -1812,7 +1812,7 @@ static int64_t alloc_clusters_noref(BlockDriverState *bs, int64_t size)
|
||||
}
|
||||
#ifdef DEBUG_ALLOC2
|
||||
printf("alloc_clusters: size=%lld -> %lld\n",
|
||||
size,
|
||||
size,
|
||||
(s->free_cluster_index - nb_clusters) << s->cluster_bits);
|
||||
#endif
|
||||
return (s->free_cluster_index - nb_clusters) << s->cluster_bits;
|
||||
@ -1839,13 +1839,13 @@ static int64_t alloc_bytes(BlockDriverState *bs, int size)
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
int64_t offset, cluster_offset;
|
||||
int free_in_cluster;
|
||||
|
||||
|
||||
assert(size > 0 && size <= s->cluster_size);
|
||||
if (s->free_byte_offset == 0) {
|
||||
s->free_byte_offset = alloc_clusters(bs, s->cluster_size);
|
||||
}
|
||||
redo:
|
||||
free_in_cluster = s->cluster_size -
|
||||
free_in_cluster = s->cluster_size -
|
||||
(s->free_byte_offset & (s->cluster_size - 1));
|
||||
if (size <= free_in_cluster) {
|
||||
/* enough space in current cluster */
|
||||
@ -1872,7 +1872,7 @@ static int64_t alloc_bytes(BlockDriverState *bs, int size)
|
||||
return offset;
|
||||
}
|
||||
|
||||
static void free_clusters(BlockDriverState *bs,
|
||||
static void free_clusters(BlockDriverState *bs,
|
||||
int64_t offset, int64_t size)
|
||||
{
|
||||
update_refcount(bs, offset, size, -1);
|
||||
@ -1912,14 +1912,14 @@ static int grow_refcount_table(BlockDriverState *bs, int min_size)
|
||||
new_table = qemu_mallocz(new_table_size2);
|
||||
if (!new_table)
|
||||
return -ENOMEM;
|
||||
memcpy(new_table, s->refcount_table,
|
||||
memcpy(new_table, s->refcount_table,
|
||||
s->refcount_table_size * sizeof(uint64_t));
|
||||
for(i = 0; i < s->refcount_table_size; i++)
|
||||
cpu_to_be64s(&new_table[i]);
|
||||
/* Note: we cannot update the refcount now to avoid recursion */
|
||||
table_offset = alloc_clusters_noref(bs, new_table_size2);
|
||||
ret = bdrv_pwrite(s->hd, table_offset, new_table, new_table_size2);
|
||||
if (ret != new_table_size2)
|
||||
if (ret != new_table_size2)
|
||||
goto fail;
|
||||
for(i = 0; i < s->refcount_table_size; i++)
|
||||
be64_to_cpus(&new_table[i]);
|
||||
@ -1950,7 +1950,7 @@ static int grow_refcount_table(BlockDriverState *bs, int min_size)
|
||||
|
||||
/* addend must be 1 or -1 */
|
||||
/* XXX: cache several refcount block clusters ? */
|
||||
static int update_cluster_refcount(BlockDriverState *bs,
|
||||
static int update_cluster_refcount(BlockDriverState *bs,
|
||||
int64_t cluster_index,
|
||||
int addend)
|
||||
{
|
||||
@ -1980,8 +1980,8 @@ static int update_cluster_refcount(BlockDriverState *bs,
|
||||
return -EINVAL;
|
||||
s->refcount_table[refcount_table_index] = offset;
|
||||
data64 = cpu_to_be64(offset);
|
||||
ret = bdrv_pwrite(s->hd, s->refcount_table_offset +
|
||||
refcount_table_index * sizeof(uint64_t),
|
||||
ret = bdrv_pwrite(s->hd, s->refcount_table_offset +
|
||||
refcount_table_index * sizeof(uint64_t),
|
||||
&data64, sizeof(data64));
|
||||
if (ret != sizeof(data64))
|
||||
return -EINVAL;
|
||||
@ -1996,7 +1996,7 @@ static int update_cluster_refcount(BlockDriverState *bs,
|
||||
}
|
||||
}
|
||||
/* we can update the count and save it */
|
||||
block_index = cluster_index &
|
||||
block_index = cluster_index &
|
||||
((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1);
|
||||
refcount = be16_to_cpu(s->refcount_block_cache[block_index]);
|
||||
refcount += addend;
|
||||
@ -2006,50 +2006,50 @@ static int update_cluster_refcount(BlockDriverState *bs,
|
||||
s->free_cluster_index = cluster_index;
|
||||
}
|
||||
s->refcount_block_cache[block_index] = cpu_to_be16(refcount);
|
||||
if (bdrv_pwrite(s->hd,
|
||||
refcount_block_offset + (block_index << REFCOUNT_SHIFT),
|
||||
if (bdrv_pwrite(s->hd,
|
||||
refcount_block_offset + (block_index << REFCOUNT_SHIFT),
|
||||
&s->refcount_block_cache[block_index], 2) != 2)
|
||||
return -EIO;
|
||||
return refcount;
|
||||
}
|
||||
|
||||
static void update_refcount(BlockDriverState *bs,
|
||||
int64_t offset, int64_t length,
|
||||
static void update_refcount(BlockDriverState *bs,
|
||||
int64_t offset, int64_t length,
|
||||
int addend)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
int64_t start, last, cluster_offset;
|
||||
|
||||
#ifdef DEBUG_ALLOC2
|
||||
printf("update_refcount: offset=%lld size=%lld addend=%d\n",
|
||||
printf("update_refcount: offset=%lld size=%lld addend=%d\n",
|
||||
offset, length, addend);
|
||||
#endif
|
||||
if (length <= 0)
|
||||
return;
|
||||
start = offset & ~(s->cluster_size - 1);
|
||||
last = (offset + length - 1) & ~(s->cluster_size - 1);
|
||||
for(cluster_offset = start; cluster_offset <= last;
|
||||
for(cluster_offset = start; cluster_offset <= last;
|
||||
cluster_offset += s->cluster_size) {
|
||||
update_cluster_refcount(bs, cluster_offset >> s->cluster_bits, addend);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ALLOC
|
||||
static void inc_refcounts(BlockDriverState *bs,
|
||||
uint16_t *refcount_table,
|
||||
static void inc_refcounts(BlockDriverState *bs,
|
||||
uint16_t *refcount_table,
|
||||
int refcount_table_size,
|
||||
int64_t offset, int64_t size)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
int64_t start, last, cluster_offset;
|
||||
int k;
|
||||
|
||||
|
||||
if (size <= 0)
|
||||
return;
|
||||
|
||||
start = offset & ~(s->cluster_size - 1);
|
||||
last = (offset + size - 1) & ~(s->cluster_size - 1);
|
||||
for(cluster_offset = start; cluster_offset <= last;
|
||||
for(cluster_offset = start; cluster_offset <= last;
|
||||
cluster_offset += s->cluster_size) {
|
||||
k = cluster_offset >> s->cluster_bits;
|
||||
if (k < 0 || k >= refcount_table_size) {
|
||||
@ -2062,8 +2062,8 @@ static void inc_refcounts(BlockDriverState *bs,
|
||||
}
|
||||
}
|
||||
|
||||
static int check_refcounts_l1(BlockDriverState *bs,
|
||||
uint16_t *refcount_table,
|
||||
static int check_refcounts_l1(BlockDriverState *bs,
|
||||
uint16_t *refcount_table,
|
||||
int refcount_table_size,
|
||||
int64_t l1_table_offset, int l1_size,
|
||||
int check_copied)
|
||||
@ -2081,12 +2081,12 @@ static int check_refcounts_l1(BlockDriverState *bs,
|
||||
l1_table = qemu_malloc(l1_size2);
|
||||
if (!l1_table)
|
||||
goto fail;
|
||||
if (bdrv_pread(s->hd, l1_table_offset,
|
||||
if (bdrv_pread(s->hd, l1_table_offset,
|
||||
l1_table, l1_size2) != l1_size2)
|
||||
goto fail;
|
||||
for(i = 0;i < l1_size; i++)
|
||||
be64_to_cpus(&l1_table[i]);
|
||||
|
||||
|
||||
l2_size = s->l2_size * sizeof(uint64_t);
|
||||
l2_table = qemu_malloc(l2_size);
|
||||
if (!l2_table)
|
||||
@ -2113,10 +2113,10 @@ static int check_refcounts_l1(BlockDriverState *bs,
|
||||
offset >> s->cluster_bits);
|
||||
offset &= ~QCOW_OFLAG_COPIED;
|
||||
}
|
||||
nb_csectors = ((offset >> s->csize_shift) &
|
||||
nb_csectors = ((offset >> s->csize_shift) &
|
||||
s->csize_mask) + 1;
|
||||
offset &= s->cluster_offset_mask;
|
||||
inc_refcounts(bs, refcount_table,
|
||||
inc_refcounts(bs, refcount_table,
|
||||
refcount_table_size,
|
||||
offset & ~511, nb_csectors * 512);
|
||||
} else {
|
||||
@ -2128,13 +2128,13 @@ static int check_refcounts_l1(BlockDriverState *bs,
|
||||
}
|
||||
}
|
||||
offset &= ~QCOW_OFLAG_COPIED;
|
||||
inc_refcounts(bs, refcount_table,
|
||||
inc_refcounts(bs, refcount_table,
|
||||
refcount_table_size,
|
||||
offset, s->cluster_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
inc_refcounts(bs, refcount_table,
|
||||
inc_refcounts(bs, refcount_table,
|
||||
refcount_table_size,
|
||||
l2_offset,
|
||||
s->cluster_size);
|
||||
@ -2165,7 +2165,7 @@ static void check_refcounts(BlockDriverState *bs)
|
||||
/* header */
|
||||
inc_refcounts(bs, refcount_table, nb_clusters,
|
||||
0, s->cluster_size);
|
||||
|
||||
|
||||
check_refcounts_l1(bs, refcount_table, nb_clusters,
|
||||
s->l1_table_offset, s->l1_size, 1);
|
||||
|
||||
@ -2180,7 +2180,7 @@ static void check_refcounts(BlockDriverState *bs)
|
||||
|
||||
/* refcount data */
|
||||
inc_refcounts(bs, refcount_table, nb_clusters,
|
||||
s->refcount_table_offset,
|
||||
s->refcount_table_offset,
|
||||
s->refcount_table_size * sizeof(uint64_t));
|
||||
for(i = 0; i < s->refcount_table_size; i++) {
|
||||
int64_t offset;
|
||||
|
70
block-raw.c
70
block-raw.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Block driver for RAW files
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2006 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -137,12 +137,12 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
#endif
|
||||
*/
|
||||
|
||||
static int raw_pread(BlockDriverState *bs, int64_t offset,
|
||||
static int raw_pread(BlockDriverState *bs, int64_t offset,
|
||||
uint8_t *buf, int count)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
int ret;
|
||||
|
||||
|
||||
ret = fd_open(bs);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@ -189,12 +189,12 @@ label__raw_read__success:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int raw_pwrite(BlockDriverState *bs, int64_t offset,
|
||||
static int raw_pwrite(BlockDriverState *bs, int64_t offset,
|
||||
const uint8_t *buf, int count)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
int ret;
|
||||
|
||||
|
||||
ret = fd_open(bs);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
@ -259,7 +259,7 @@ void qemu_aio_init(void)
|
||||
struct sigaction act;
|
||||
|
||||
aio_initialized = 1;
|
||||
|
||||
|
||||
sigfillset(&act.sa_mask);
|
||||
act.sa_flags = 0; /* do not restart syscalls to interrupt select() */
|
||||
act.sa_handler = aio_signal_handler;
|
||||
@ -401,7 +401,7 @@ static BlockDriverAIOCB *raw_aio_read(BlockDriverState *bs,
|
||||
if (aio_read(&acb->aiocb) < 0) {
|
||||
qemu_aio_release(acb);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return &acb->common;
|
||||
}
|
||||
|
||||
@ -417,7 +417,7 @@ static BlockDriverAIOCB *raw_aio_write(BlockDriverState *bs,
|
||||
if (aio_write(&acb->aiocb) < 0) {
|
||||
qemu_aio_release(acb);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return &acb->common;
|
||||
}
|
||||
|
||||
@ -522,7 +522,7 @@ static int raw_create(const char *filename, int64_t total_size,
|
||||
if (flags || backing_file)
|
||||
return -ENOTSUP;
|
||||
|
||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
|
||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
|
||||
0644);
|
||||
if (fd < 0)
|
||||
return -EIO;
|
||||
@ -547,7 +547,7 @@ BlockDriver bdrv_raw = {
|
||||
raw_close,
|
||||
raw_create,
|
||||
raw_flush,
|
||||
|
||||
|
||||
.bdrv_aio_read = raw_aio_read,
|
||||
.bdrv_aio_write = raw_aio_write,
|
||||
.bdrv_aio_cancel = raw_aio_cancel,
|
||||
@ -568,7 +568,7 @@ static kern_return_t GetBSDPath( io_iterator_t mediaIterator, char *bsdPath, CFI
|
||||
|
||||
kern_return_t FindEjectableCDMedia( io_iterator_t *mediaIterator )
|
||||
{
|
||||
kern_return_t kernResult;
|
||||
kern_return_t kernResult;
|
||||
mach_port_t masterPort;
|
||||
CFMutableDictionaryRef classesToMatch;
|
||||
|
||||
@ -576,8 +576,8 @@ kern_return_t FindEjectableCDMedia( io_iterator_t *mediaIterator )
|
||||
if ( KERN_SUCCESS != kernResult ) {
|
||||
printf( "IOMasterPort returned %d\n", kernResult );
|
||||
}
|
||||
|
||||
classesToMatch = IOServiceMatching( kIOCDMediaClass );
|
||||
|
||||
classesToMatch = IOServiceMatching( kIOCDMediaClass );
|
||||
if ( classesToMatch == NULL ) {
|
||||
printf( "IOServiceMatching returned a NULL dictionary.\n" );
|
||||
} else {
|
||||
@ -588,7 +588,7 @@ kern_return_t FindEjectableCDMedia( io_iterator_t *mediaIterator )
|
||||
{
|
||||
printf( "IOServiceGetMatchingServices returned %d\n", kernResult );
|
||||
}
|
||||
|
||||
|
||||
return kernResult;
|
||||
}
|
||||
|
||||
@ -614,7 +614,7 @@ kern_return_t GetBSDPath( io_iterator_t mediaIterator, char *bsdPath, CFIndex ma
|
||||
}
|
||||
IOObjectRelease( nextMedia );
|
||||
}
|
||||
|
||||
|
||||
return kernResult;
|
||||
}
|
||||
|
||||
@ -631,10 +631,10 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
io_iterator_t mediaIterator;
|
||||
char bsdPath[ MAXPATHLEN ];
|
||||
int fd;
|
||||
|
||||
|
||||
kernResult = FindEjectableCDMedia( &mediaIterator );
|
||||
kernResult = GetBSDPath( mediaIterator, bsdPath, sizeof( bsdPath ) );
|
||||
|
||||
|
||||
if ( bsdPath[ 0 ] != '\0' ) {
|
||||
strcat(bsdPath,"s0");
|
||||
/* some CDs don't have a partition 0 */
|
||||
@ -646,7 +646,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
}
|
||||
filename = bsdPath;
|
||||
}
|
||||
|
||||
|
||||
if ( mediaIterator )
|
||||
IOObjectRelease( mediaIterator );
|
||||
}
|
||||
@ -704,7 +704,7 @@ static int fd_open(BlockDriverState *bs)
|
||||
if (s->type != FTYPE_FD)
|
||||
return 0;
|
||||
last_media_present = (s->fd >= 0);
|
||||
if (s->fd >= 0 &&
|
||||
if (s->fd >= 0 &&
|
||||
(qemu_get_clock(rt_clock) - s->fd_open_time) >= FD_OPEN_TIMEOUT) {
|
||||
close(s->fd);
|
||||
s->fd = -1;
|
||||
@ -713,7 +713,7 @@ static int fd_open(BlockDriverState *bs)
|
||||
#endif
|
||||
}
|
||||
if (s->fd < 0) {
|
||||
if (s->fd_got_error &&
|
||||
if (s->fd_got_error &&
|
||||
(qemu_get_clock(rt_clock) - s->fd_error_time) < FD_OPEN_TIMEOUT) {
|
||||
#ifdef DEBUG_FLOPPY
|
||||
printf("No floppy (open delayed)\n");
|
||||
@ -883,7 +883,7 @@ BlockDriver bdrv_host_device = {
|
||||
raw_close,
|
||||
NULL,
|
||||
raw_flush,
|
||||
|
||||
|
||||
.bdrv_aio_read = raw_aio_read,
|
||||
.bdrv_aio_write = raw_aio_write,
|
||||
.bdrv_aio_cancel = raw_aio_cancel,
|
||||
@ -979,7 +979,7 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
#else
|
||||
overlapped = FILE_FLAG_OVERLAPPED;
|
||||
#endif
|
||||
s->hfile = CreateFile(filename, access_flags,
|
||||
s->hfile = CreateFile(filename, access_flags,
|
||||
FILE_SHARE_READ, NULL,
|
||||
create_flags, overlapped, NULL);
|
||||
if (s->hfile == INVALID_HANDLE_VALUE) {
|
||||
@ -992,14 +992,14 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int raw_pread(BlockDriverState *bs, int64_t offset,
|
||||
static int raw_pread(BlockDriverState *bs, int64_t offset,
|
||||
uint8_t *buf, int count)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
OVERLAPPED ov;
|
||||
DWORD ret_count;
|
||||
int ret;
|
||||
|
||||
|
||||
memset(&ov, 0, sizeof(ov));
|
||||
ov.Offset = offset;
|
||||
ov.OffsetHigh = offset >> 32;
|
||||
@ -1014,14 +1014,14 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
|
||||
return ret_count;
|
||||
}
|
||||
|
||||
static int raw_pwrite(BlockDriverState *bs, int64_t offset,
|
||||
static int raw_pwrite(BlockDriverState *bs, int64_t offset,
|
||||
const uint8_t *buf, int count)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
OVERLAPPED ov;
|
||||
DWORD ret_count;
|
||||
int ret;
|
||||
|
||||
|
||||
memset(&ov, 0, sizeof(ov));
|
||||
ov.Offset = offset;
|
||||
ov.OffsetHigh = offset >> 32;
|
||||
@ -1171,7 +1171,7 @@ static int64_t raw_getlength(BlockDriverState *bs)
|
||||
{
|
||||
BDRVRawState *s = bs->opaque;
|
||||
LARGE_INTEGER l;
|
||||
ULARGE_INTEGER available, total, total_free;
|
||||
ULARGE_INTEGER available, total, total_free;
|
||||
DISK_GEOMETRY dg;
|
||||
DWORD count;
|
||||
BOOL status;
|
||||
@ -1209,7 +1209,7 @@ static int raw_create(const char *filename, int64_t total_size,
|
||||
if (flags || backing_file)
|
||||
return -ENOTSUP;
|
||||
|
||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
|
||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
|
||||
0644);
|
||||
if (fd < 0)
|
||||
return -EIO;
|
||||
@ -1256,7 +1256,7 @@ BlockDriver bdrv_raw = {
|
||||
raw_close,
|
||||
raw_create,
|
||||
raw_flush,
|
||||
|
||||
|
||||
#if 0
|
||||
.bdrv_aio_read = raw_aio_read,
|
||||
.bdrv_aio_write = raw_aio_write,
|
||||
@ -1335,7 +1335,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
}
|
||||
}
|
||||
s->type = find_device_type(bs, filename);
|
||||
|
||||
|
||||
if ((flags & BDRV_O_ACCESS) == O_RDWR) {
|
||||
access_flags = GENERIC_READ | GENERIC_WRITE;
|
||||
} else {
|
||||
@ -1348,7 +1348,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
#else
|
||||
overlapped = FILE_FLAG_OVERLAPPED;
|
||||
#endif
|
||||
s->hfile = CreateFile(filename, access_flags,
|
||||
s->hfile = CreateFile(filename, access_flags,
|
||||
FILE_SHARE_READ, NULL,
|
||||
create_flags, overlapped, NULL);
|
||||
if (s->hfile == INVALID_HANDLE_VALUE) {
|
||||
@ -1382,10 +1382,10 @@ static int raw_eject(BlockDriverState *bs, int eject_flag)
|
||||
if (s->type == FTYPE_FILE)
|
||||
return -ENOTSUP;
|
||||
if (eject_flag) {
|
||||
DeviceIoControl(s->hfile, IOCTL_STORAGE_EJECT_MEDIA,
|
||||
DeviceIoControl(s->hfile, IOCTL_STORAGE_EJECT_MEDIA,
|
||||
NULL, 0, NULL, 0, &lpBytesReturned, NULL);
|
||||
} else {
|
||||
DeviceIoControl(s->hfile, IOCTL_STORAGE_LOAD_MEDIA,
|
||||
DeviceIoControl(s->hfile, IOCTL_STORAGE_LOAD_MEDIA,
|
||||
NULL, 0, NULL, 0, &lpBytesReturned, NULL);
|
||||
}
|
||||
}
|
||||
@ -1406,7 +1406,7 @@ BlockDriver bdrv_host_device = {
|
||||
raw_close,
|
||||
NULL,
|
||||
raw_flush,
|
||||
|
||||
|
||||
#if 0
|
||||
.bdrv_aio_read = raw_aio_read,
|
||||
.bdrv_aio_write = raw_aio_write,
|
||||
|
36
block-vmdk.c
36
block-vmdk.c
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Block driver for the VMDK format
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004 Fabrice Bellard
|
||||
* Copyright (c) 2005 Filip Navara
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -110,16 +110,16 @@ static int vmdk_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||
|
||||
#define CHECK_CID 1
|
||||
|
||||
#define SECTOR_SIZE 512
|
||||
#define SECTOR_SIZE 512
|
||||
#define DESC_SIZE 20*SECTOR_SIZE // 20 sectors of 512 bytes each
|
||||
#define HEADER_SIZE 512 // first sector of 512 bytes
|
||||
#define HEADER_SIZE 512 // first sector of 512 bytes
|
||||
|
||||
static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
|
||||
{
|
||||
BDRVVmdkState *s = bs->opaque;
|
||||
char desc[DESC_SIZE];
|
||||
uint32_t cid;
|
||||
char *p_name, *cid_str;
|
||||
char *p_name, *cid_str;
|
||||
size_t cid_str_size;
|
||||
|
||||
/* the descriptor offset = 0x200 */
|
||||
@ -187,7 +187,7 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file)
|
||||
{
|
||||
int snp_fd, p_fd;
|
||||
uint32_t p_cid;
|
||||
char *p_name, *gd_buf, *rgd_buf;
|
||||
char *p_name, *gd_buf, *rgd_buf;
|
||||
const char *real_filename, *temp_str;
|
||||
VMDK4Header header;
|
||||
uint32_t gde_entries, gd_size;
|
||||
@ -271,7 +271,7 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file)
|
||||
gt_size = (int64_t)header.num_gtes_per_gte * header.granularity * SECTOR_SIZE;
|
||||
if (!gt_size)
|
||||
goto fail;
|
||||
gde_entries = (uint32_t)(capacity / gt_size); // number of gde/rgde
|
||||
gde_entries = (uint32_t)(capacity / gt_size); // number of gde/rgde
|
||||
gd_size = gde_entries * sizeof(uint32_t);
|
||||
|
||||
/* write RGD */
|
||||
@ -308,7 +308,7 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file)
|
||||
|
||||
fail_gd:
|
||||
qemu_free(gd_buf);
|
||||
fail_rgd:
|
||||
fail_rgd:
|
||||
qemu_free(rgd_buf);
|
||||
fail:
|
||||
close(p_fd);
|
||||
@ -326,7 +326,7 @@ int parent_open = 0;
|
||||
static int vmdk_parent_open(BlockDriverState *bs, const char * filename)
|
||||
{
|
||||
BDRVVmdkState *s = bs->opaque;
|
||||
char *p_name;
|
||||
char *p_name;
|
||||
char desc[DESC_SIZE];
|
||||
char parent_img_name[1024];
|
||||
|
||||
@ -341,7 +341,7 @@ static int vmdk_parent_open(BlockDriverState *bs, const char * filename)
|
||||
p_name += sizeof("parentFileNameHint") + 1;
|
||||
if ((end_name = strchr(p_name,'\"')) == 0)
|
||||
return -1;
|
||||
|
||||
|
||||
strncpy(s->hd->backing_file, p_name, end_name - p_name);
|
||||
if (stat(s->hd->backing_file, &file_buf) != 0) {
|
||||
path_combine(parent_img_name, sizeof(parent_img_name),
|
||||
@ -406,7 +406,7 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
s->l1_entry_sectors = s->l2_size * s->cluster_sectors;
|
||||
if (s->l1_entry_sectors <= 0)
|
||||
goto fail;
|
||||
s->l1_size = (bs->total_sectors + s->l1_entry_sectors - 1)
|
||||
s->l1_size = (bs->total_sectors + s->l1_entry_sectors - 1)
|
||||
/ s->l1_entry_sectors;
|
||||
s->l1_table_offset = le64_to_cpu(header.rgd_offset) << 9;
|
||||
s->l1_backup_table_offset = le64_to_cpu(header.gd_offset) << 9;
|
||||
@ -552,7 +552,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, VmdkMetaData *m_data,
|
||||
}
|
||||
}
|
||||
l2_table = s->l2_cache + (min_index * s->l2_size);
|
||||
if (bdrv_pread(s->hd, (int64_t)l2_offset * 512, l2_table, s->l2_size * sizeof(uint32_t)) !=
|
||||
if (bdrv_pread(s->hd, (int64_t)l2_offset * 512, l2_table, s->l2_size * sizeof(uint32_t)) !=
|
||||
s->l2_size * sizeof(uint32_t))
|
||||
return 0;
|
||||
|
||||
@ -597,7 +597,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, VmdkMetaData *m_data,
|
||||
return cluster_offset;
|
||||
}
|
||||
|
||||
static int vmdk_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
||||
static int vmdk_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, int *pnum)
|
||||
{
|
||||
BDRVVmdkState *s = bs->opaque;
|
||||
@ -613,7 +613,7 @@ static int vmdk_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
||||
return (cluster_offset != 0);
|
||||
}
|
||||
|
||||
static int vmdk_read(BlockDriverState *bs, int64_t sector_num,
|
||||
static int vmdk_read(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVVmdkState *s = bs->opaque;
|
||||
@ -648,7 +648,7 @@ static int vmdk_read(BlockDriverState *bs, int64_t sector_num,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
|
||||
static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
|
||||
const uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVVmdkState *s = bs->opaque;
|
||||
@ -761,8 +761,8 @@ static int vmdk_create(const char *filename, int64_t total_size,
|
||||
header.check_bytes[1] = 0x20;
|
||||
header.check_bytes[2] = 0xd;
|
||||
header.check_bytes[3] = 0xa;
|
||||
|
||||
/* write all the data */
|
||||
|
||||
/* write all the data */
|
||||
write(fd, &magic, sizeof(magic));
|
||||
write(fd, &header, sizeof(header));
|
||||
|
||||
@ -773,7 +773,7 @@ static int vmdk_create(const char *filename, int64_t total_size,
|
||||
for (i = 0, tmp = header.rgd_offset + gd_size;
|
||||
i < gt_count; i++, tmp += gt_size)
|
||||
write(fd, &tmp, sizeof(tmp));
|
||||
|
||||
|
||||
/* write backup grain directory */
|
||||
lseek(fd, le64_to_cpu(header.gd_offset) << 9, SEEK_SET);
|
||||
for (i = 0, tmp = header.gd_offset + gd_size;
|
||||
|
20
block-vpc.c
20
block-vpc.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Block driver for Conectix/Microsoft Virtual PC images
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2005 Alex Beregszaszi
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -65,7 +65,7 @@ struct vpc_subheader {
|
||||
|
||||
typedef struct BDRVVPCState {
|
||||
int fd;
|
||||
|
||||
|
||||
int pagetable_entries;
|
||||
uint32_t *pagetable;
|
||||
|
||||
@ -74,7 +74,7 @@ typedef struct BDRVVPCState {
|
||||
uint8_t *pageentry_u8;
|
||||
uint32_t *pageentry_u32;
|
||||
uint16_t *pageentry_u16;
|
||||
|
||||
|
||||
uint64_t last_bitmap;
|
||||
#endif
|
||||
} BDRVVPCState;
|
||||
@ -97,7 +97,7 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags)
|
||||
return -1;
|
||||
|
||||
bs->read_only = 1; // no write support yet
|
||||
|
||||
|
||||
s->fd = fd;
|
||||
|
||||
if (read(fd, &header, HEADER_SIZE) != HEADER_SIZE)
|
||||
@ -153,13 +153,13 @@ static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
|
||||
|
||||
pagetable_index = offset / s->pageentry_size;
|
||||
pageentry_index = (offset % s->pageentry_size) / 512;
|
||||
|
||||
|
||||
if (pagetable_index > s->pagetable_entries || s->pagetable[pagetable_index] == 0xffffffff)
|
||||
return -1; // not allocated
|
||||
|
||||
bitmap_offset = 512 * s->pagetable[pagetable_index];
|
||||
block_offset = bitmap_offset + 512 + (512 * pageentry_index);
|
||||
|
||||
|
||||
// printf("sector: %" PRIx64 ", index: %x, offset: %x, bioff: %" PRIx64 ", bloff: %" PRIx64 "\n",
|
||||
// sector_num, pagetable_index, pageentry_index,
|
||||
// bitmap_offset, block_offset);
|
||||
@ -172,7 +172,7 @@ static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
|
||||
lseek(s->fd, bitmap_offset, SEEK_SET);
|
||||
|
||||
s->last_bitmap = bitmap_offset;
|
||||
|
||||
|
||||
// Scary! Bitmap is stored as big endian 32bit entries,
|
||||
// while we used to look it up byte by byte
|
||||
read(s->fd, s->pageentry_u8, 512);
|
||||
@ -184,7 +184,7 @@ static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
|
||||
return -1;
|
||||
#else
|
||||
lseek(s->fd, bitmap_offset + (pageentry_index / 8), SEEK_SET);
|
||||
|
||||
|
||||
read(s->fd, &bitmap_entry, 1);
|
||||
|
||||
if ((bitmap_entry >> (pageentry_index % 8)) & 1)
|
||||
@ -196,7 +196,7 @@ static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vpc_read(BlockDriverState *bs, int64_t sector_num,
|
||||
static int vpc_read(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVVPCState *s = bs->opaque;
|
||||
|
@ -1,9 +1,9 @@
|
||||
/* vim:set shiftwidth=4 ts=8: */
|
||||
/*
|
||||
* QEMU Block driver for virtual VFAT (shadows a local directory)
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004,2005 Johannes E. Schindelin
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -38,7 +38,7 @@
|
||||
/* TODO: add ":bootsector=blabla.img:" */
|
||||
/* LATER TODO: add automatic boot sector generation from
|
||||
BOOTEASY.ASM and Ranish Partition Manager
|
||||
Note that DOS assumes the system files to be the first files in the
|
||||
Note that DOS assumes the system files to be the first files in the
|
||||
file system (test if the boot sector still relies on that fact)! */
|
||||
/* MAYBE TODO: write block-visofs.c */
|
||||
/* TODO: call try_commit() only after a timeout */
|
||||
@ -153,7 +153,7 @@ static inline int array_roll(array_t* array,int index_to,int index_from,int coun
|
||||
index_to<0 || index_to>=array->next ||
|
||||
index_from<0 || index_from>=array->next)
|
||||
return -1;
|
||||
|
||||
|
||||
if(index_to==index_from)
|
||||
return 0;
|
||||
|
||||
@ -167,7 +167,7 @@ static inline int array_roll(array_t* array,int index_to,int index_from,int coun
|
||||
memmove(to+is*count,to,from-to);
|
||||
else
|
||||
memmove(from,from+is*count,to-from);
|
||||
|
||||
|
||||
memcpy(to,buf,is*count);
|
||||
|
||||
free(buf);
|
||||
@ -319,10 +319,10 @@ typedef struct BDRVVVFATState {
|
||||
BlockDriverState* bs; /* pointer to parent */
|
||||
unsigned int first_sectors_number; /* 1 for a single partition, 0x40 for a disk with partition table */
|
||||
unsigned char first_sectors[0x40*0x200];
|
||||
|
||||
|
||||
int fat_type; /* 16 or 32 */
|
||||
array_t fat,directory,mapping;
|
||||
|
||||
|
||||
unsigned int cluster_size;
|
||||
unsigned int sectors_per_cluster;
|
||||
unsigned int sectors_per_fat;
|
||||
@ -332,7 +332,7 @@ typedef struct BDRVVVFATState {
|
||||
uint32_t sector_count; /* total number of sectors of the partition */
|
||||
uint32_t cluster_count; /* total number of clusters of this partition */
|
||||
uint32_t max_fat_value;
|
||||
|
||||
|
||||
int current_fd;
|
||||
mapping_t* current_mapping;
|
||||
unsigned char* cluster; /* points to current cluster */
|
||||
@ -358,7 +358,7 @@ static void init_mbr(BDRVVVFATState* s)
|
||||
partition_t* partition=&(real_mbr->partition[0]);
|
||||
|
||||
memset(s->first_sectors,0,512);
|
||||
|
||||
|
||||
partition->attributes=0x80; /* bootable */
|
||||
partition->start_head=1;
|
||||
partition->start_sector=1;
|
||||
@ -478,7 +478,7 @@ static inline uint8_t fat_chksum(const direntry_t* entry)
|
||||
for(i=0;i<11;i++)
|
||||
chksum=(((chksum&0xfe)>>1)|((chksum&0x01)?0x80:0))
|
||||
+(unsigned char)entry->name[i];
|
||||
|
||||
|
||||
return chksum;
|
||||
}
|
||||
|
||||
@ -554,7 +554,7 @@ static inline void init_fat(BDRVVVFATState* s)
|
||||
s->sectors_per_fat * 0x200 / s->fat.item_size - 1);
|
||||
}
|
||||
memset(s->fat.pointer,0,s->fat.size);
|
||||
|
||||
|
||||
switch(s->fat_type) {
|
||||
case 12: s->max_fat_value=0xfff; break;
|
||||
case 16: s->max_fat_value=0xffff; break;
|
||||
@ -579,10 +579,10 @@ static inline direntry_t* create_short_and_long_name(BDRVVVFATState* s,
|
||||
memcpy(entry->name,filename,strlen(filename));
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
entry_long=create_long_filename(s,filename);
|
||||
|
||||
i = strlen(filename);
|
||||
|
||||
i = strlen(filename);
|
||||
for(j = i - 1; j>0 && filename[j]!='.';j--);
|
||||
if (j > 0)
|
||||
i = (j > 8 ? 8 : j);
|
||||
@ -592,7 +592,7 @@ static inline direntry_t* create_short_and_long_name(BDRVVVFATState* s,
|
||||
entry=array_get_next(&(s->directory));
|
||||
memset(entry->name,0x20,11);
|
||||
strncpy(entry->name,filename,i);
|
||||
|
||||
|
||||
if(j > 0)
|
||||
for (i = 0; i < 3 && filename[j+1+i]; i++)
|
||||
entry->extension[i] = filename[j+1+i];
|
||||
@ -618,7 +618,7 @@ static inline direntry_t* create_short_and_long_name(BDRVVVFATState* s,
|
||||
if(entry1==entry) /* no dupe found */
|
||||
break;
|
||||
|
||||
/* use all 8 characters of name */
|
||||
/* use all 8 characters of name */
|
||||
if(entry->name[7]==' ') {
|
||||
int j;
|
||||
for(j=6;j>0 && entry->name[j]==' ';j--)
|
||||
@ -675,11 +675,11 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
|
||||
mapping->end = mapping->begin;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
i = mapping->info.dir.first_dir_index =
|
||||
first_cluster == 0 ? 0 : s->directory.next;
|
||||
|
||||
/* actually read the directory, and allocate the mappings */
|
||||
/* actually read the directory, and allocate the mappings */
|
||||
while((entry=readdir(dir))) {
|
||||
unsigned int length=strlen(dirname)+2+strlen(entry->d_name);
|
||||
char* buffer;
|
||||
@ -690,7 +690,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
|
||||
|
||||
if(first_cluster == 0 && (is_dotdot || is_dot))
|
||||
continue;
|
||||
|
||||
|
||||
buffer=(char*)malloc(length);
|
||||
assert(buffer);
|
||||
snprintf(buffer,length,"%s/%s",dirname,entry->d_name);
|
||||
@ -765,7 +765,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
|
||||
memset(array_get(&(s->directory), cur), 0,
|
||||
(ROOT_ENTRIES - cur) * sizeof(direntry_t));
|
||||
}
|
||||
|
||||
|
||||
/* reget the mapping, since s->mapping was possibly realloc()ed */
|
||||
mapping = (mapping_t*)array_get(&(s->mapping), mapping_index);
|
||||
first_cluster += (s->directory.next - mapping->info.dir.first_dir_index)
|
||||
@ -774,7 +774,7 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
|
||||
|
||||
direntry = (direntry_t*)array_get(&(s->directory), mapping->dir_index);
|
||||
set_begin_of_direntry(direntry, mapping->begin);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -825,7 +825,7 @@ static int init_directories(BDRVVVFATState* s,
|
||||
*/
|
||||
i = 1+s->sectors_per_cluster*0x200*8/s->fat_type;
|
||||
s->sectors_per_fat=(s->sector_count+i)/i; /* round up */
|
||||
|
||||
|
||||
array_init(&(s->mapping),sizeof(mapping_t));
|
||||
array_init(&(s->directory),sizeof(direntry_t));
|
||||
|
||||
@ -857,7 +857,7 @@ static int init_directories(BDRVVVFATState* s,
|
||||
|
||||
for (i = 0, cluster = 0; i < s->mapping.next; i++) {
|
||||
int j;
|
||||
/* MS-DOS expects the FAT to be 0 for the root directory
|
||||
/* MS-DOS expects the FAT to be 0 for the root directory
|
||||
* (except for the media byte). */
|
||||
/* LATER TODO: still true for FAT32? */
|
||||
int fix_fat = (i != 0);
|
||||
@ -987,7 +987,7 @@ DLOG(if (stderr == NULL) {
|
||||
s->qcow_filename = NULL;
|
||||
s->fat2 = NULL;
|
||||
s->downcase_short_names = 1;
|
||||
|
||||
|
||||
if (!strstart(dirname, "fat:", NULL))
|
||||
return -1;
|
||||
|
||||
@ -1076,7 +1076,7 @@ static inline int find_mapping_for_cluster_aux(BDRVVVFATState* s,int cluster_num
|
||||
assert(index1<=index2);
|
||||
DLOG(mapping=array_get(&(s->mapping),index1);
|
||||
assert(mapping->begin<=cluster_num);
|
||||
assert(index2 >= s->mapping.next ||
|
||||
assert(index2 >= s->mapping.next ||
|
||||
((mapping = array_get(&(s->mapping),index2)) &&
|
||||
mapping->end>cluster_num)));
|
||||
}
|
||||
@ -1239,7 +1239,7 @@ static void print_mapping(const mapping_t* mapping)
|
||||
}
|
||||
#endif
|
||||
|
||||
static int vvfat_read(BlockDriverState *bs, int64_t sector_num,
|
||||
static int vvfat_read(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVVVFATState *s = bs->opaque;
|
||||
@ -1674,7 +1674,7 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s,
|
||||
}
|
||||
|
||||
/*
|
||||
* This function looks at the modified data (qcow).
|
||||
* This function looks at the modified data (qcow).
|
||||
* It returns 0 upon inconsistency or error, and the number of clusters
|
||||
* used by the directory, its subdirectories and their files.
|
||||
*/
|
||||
@ -1709,7 +1709,7 @@ static int check_directory_consistency(BDRVVVFATState *s,
|
||||
} else
|
||||
/* new directory */
|
||||
schedule_mkdir(s, cluster_num, strdup(path));
|
||||
|
||||
|
||||
lfn_init(&lfn);
|
||||
do {
|
||||
int i;
|
||||
@ -2049,7 +2049,7 @@ static int commit_mappings(BDRVVVFATState* s,
|
||||
}
|
||||
|
||||
next_mapping->dir_index = mapping->dir_index;
|
||||
next_mapping->first_mapping_index =
|
||||
next_mapping->first_mapping_index =
|
||||
mapping->first_mapping_index < 0 ?
|
||||
array_index(&(s->mapping), mapping) :
|
||||
mapping->first_mapping_index;
|
||||
@ -2069,7 +2069,7 @@ static int commit_mappings(BDRVVVFATState* s,
|
||||
|
||||
mapping = next_mapping;
|
||||
}
|
||||
|
||||
|
||||
cluster = c1;
|
||||
}
|
||||
|
||||
@ -2555,7 +2555,7 @@ static int do_commit(BDRVVVFATState* s)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* copy FAT (with bdrv_read) */
|
||||
/* copy FAT (with bdrv_read) */
|
||||
memcpy(s->fat.pointer, s->fat2, 0x200 * s->sectors_per_fat);
|
||||
|
||||
/* recurse direntries from root (using bs->bdrv_read) */
|
||||
@ -2597,10 +2597,10 @@ DLOG(checkpoint());
|
||||
return do_commit(s);
|
||||
}
|
||||
|
||||
static int vvfat_write(BlockDriverState *bs, int64_t sector_num,
|
||||
static int vvfat_write(BlockDriverState *bs, int64_t sector_num,
|
||||
const uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BDRVVVFATState *s = bs->opaque;
|
||||
BDRVVVFATState *s = bs->opaque;
|
||||
int i, ret;
|
||||
|
||||
DLOG(checkpoint());
|
||||
@ -2639,7 +2639,7 @@ DLOG(checkpoint());
|
||||
begin = sector_num;
|
||||
if (end > sector_num + nb_sectors)
|
||||
end = sector_num + nb_sectors;
|
||||
dir_index = mapping->dir_index +
|
||||
dir_index = mapping->dir_index +
|
||||
0x10 * (begin - mapping->begin * s->sectors_per_cluster);
|
||||
direntries = (direntry_t*)(buf + 0x200 * (begin - sector_num));
|
||||
|
||||
@ -2698,7 +2698,7 @@ static int vvfat_is_allocated(BlockDriverState *bs,
|
||||
*n = nb_sectors;
|
||||
else if (*n < 0)
|
||||
return 0;
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int write_target_commit(BlockDriverState *bs, int64_t sector_num,
|
||||
|
96
block.c
96
block.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU System Emulator block driver
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -48,7 +48,7 @@ static BlockDriverAIOCB *bdrv_aio_write_em(BlockDriverState *bs,
|
||||
int64_t sector_num, const uint8_t *buf, int nb_sectors,
|
||||
BlockDriverCompletionFunc *cb, void *opaque);
|
||||
static void bdrv_aio_cancel_em(BlockDriverAIOCB *acb);
|
||||
static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,
|
||||
static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors);
|
||||
static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,
|
||||
const uint8_t *buf, int nb_sectors);
|
||||
@ -167,7 +167,7 @@ BlockDriver *bdrv_find_format(const char *format_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int bdrv_create(BlockDriver *drv,
|
||||
int bdrv_create(BlockDriver *drv,
|
||||
const char *filename, int64_t size_in_sectors,
|
||||
const char *backing_file, int flags)
|
||||
{
|
||||
@ -180,7 +180,7 @@ int bdrv_create(BlockDriver *drv,
|
||||
void get_tmp_filename(char *filename, int size)
|
||||
{
|
||||
char temp_dir[MAX_PATH];
|
||||
|
||||
|
||||
GetTempPath(MAX_PATH, temp_dir);
|
||||
GetTempFileName(temp_dir, "qem", 0, filename);
|
||||
}
|
||||
@ -202,10 +202,10 @@ static int is_windows_drive_prefix(const char *filename)
|
||||
(filename[0] >= 'A' && filename[0] <= 'Z')) &&
|
||||
filename[1] == ':');
|
||||
}
|
||||
|
||||
|
||||
static int is_windows_drive(const char *filename)
|
||||
{
|
||||
if (is_windows_drive_prefix(filename) &&
|
||||
if (is_windows_drive_prefix(filename) &&
|
||||
filename[2] == '\0')
|
||||
return 1;
|
||||
if (strstart(filename, "\\\\.\\", NULL) ||
|
||||
@ -236,7 +236,7 @@ static BlockDriver *find_protocol(const char *filename)
|
||||
memcpy(protocol, filename, len);
|
||||
protocol[len] = '\0';
|
||||
for(drv1 = first_drv; drv1 != NULL; drv1 = drv1->next) {
|
||||
if (drv1->protocol_name &&
|
||||
if (drv1->protocol_name &&
|
||||
!strcmp(drv1->protocol_name, protocol))
|
||||
return drv1;
|
||||
}
|
||||
@ -251,7 +251,7 @@ static BlockDriver *find_image_format(const char *filename)
|
||||
BlockDriver *drv1, *drv;
|
||||
uint8_t buf[2048];
|
||||
BlockDriverState *bs;
|
||||
|
||||
|
||||
/* detect host devices. By convention, /dev/cdrom[N] is always
|
||||
recognized as a host CDROM */
|
||||
if (strstart(filename, "/dev/cdrom", NULL))
|
||||
@ -262,13 +262,13 @@ static BlockDriver *find_image_format(const char *filename)
|
||||
#else
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(filename, &st) >= 0 &&
|
||||
if (stat(filename, &st) >= 0 &&
|
||||
(S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) {
|
||||
return &bdrv_host_device;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
drv = find_protocol(filename);
|
||||
/* no need to test disk image formats for vvfat */
|
||||
if (drv == &bdrv_vvfat)
|
||||
@ -324,7 +324,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
|
||||
int ret, open_flags;
|
||||
char tmp_filename[PATH_MAX];
|
||||
char backing_filename[PATH_MAX];
|
||||
|
||||
|
||||
bs->read_only = 0;
|
||||
bs->is_temporary = 0;
|
||||
bs->encrypted = 0;
|
||||
@ -332,7 +332,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
|
||||
if (flags & BDRV_O_SNAPSHOT) {
|
||||
BlockDriverState *bs1;
|
||||
int64_t total_size;
|
||||
|
||||
|
||||
/* if snapshot, we create a temporary backing file and open it
|
||||
instead of opening 'filename' directly */
|
||||
|
||||
@ -347,10 +347,10 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
|
||||
}
|
||||
total_size = bdrv_getlength(bs1) >> SECTOR_BITS;
|
||||
bdrv_delete(bs1);
|
||||
|
||||
|
||||
get_tmp_filename(tmp_filename, sizeof(tmp_filename));
|
||||
realpath(filename, backing_filename);
|
||||
if (bdrv_create(&bdrv_qcow2, tmp_filename,
|
||||
if (bdrv_create(&bdrv_qcow2, tmp_filename,
|
||||
total_size, backing_filename, 0) < 0) {
|
||||
return -1;
|
||||
}
|
||||
@ -494,7 +494,7 @@ int bdrv_commit(BlockDriverState *bs)
|
||||
}
|
||||
|
||||
/* return < 0 if error. See bdrv_write() for the return codes */
|
||||
int bdrv_read(BlockDriverState *bs, int64_t sector_num,
|
||||
int bdrv_read(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BlockDriver *drv = bs->drv;
|
||||
@ -525,13 +525,13 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num,
|
||||
}
|
||||
}
|
||||
|
||||
/* Return < 0 if error. Important errors are:
|
||||
/* Return < 0 if error. Important errors are:
|
||||
-EIO generic I/O error (may happen for all errors)
|
||||
-ENOMEDIUM No media inserted.
|
||||
-EINVAL Invalid sector number or nb_sectors
|
||||
-EACCES Trying to write a read-only device
|
||||
*/
|
||||
int bdrv_write(BlockDriverState *bs, int64_t sector_num,
|
||||
int bdrv_write(BlockDriverState *bs, int64_t sector_num,
|
||||
const uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BlockDriver *drv = bs->drv;
|
||||
@ -540,7 +540,7 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
|
||||
if (bs->read_only)
|
||||
return -EACCES;
|
||||
if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {
|
||||
memcpy(bs->boot_sector_data, buf, 512);
|
||||
memcpy(bs->boot_sector_data, buf, 512);
|
||||
}
|
||||
if (drv->bdrv_pwrite) {
|
||||
int ret, len;
|
||||
@ -557,7 +557,7 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
|
||||
}
|
||||
}
|
||||
|
||||
static int bdrv_pread_em(BlockDriverState *bs, int64_t offset,
|
||||
static int bdrv_pread_em(BlockDriverState *bs, int64_t offset,
|
||||
uint8_t *buf, int count1)
|
||||
{
|
||||
uint8_t tmp_buf[SECTOR_SIZE];
|
||||
@ -601,7 +601,7 @@ static int bdrv_pread_em(BlockDriverState *bs, int64_t offset,
|
||||
return count1;
|
||||
}
|
||||
|
||||
static int bdrv_pwrite_em(BlockDriverState *bs, int64_t offset,
|
||||
static int bdrv_pwrite_em(BlockDriverState *bs, int64_t offset,
|
||||
const uint8_t *buf, int count1)
|
||||
{
|
||||
uint8_t tmp_buf[SECTOR_SIZE];
|
||||
@ -650,9 +650,9 @@ static int bdrv_pwrite_em(BlockDriverState *bs, int64_t offset,
|
||||
}
|
||||
|
||||
/**
|
||||
* Read with byte offsets (needed only for file protocols)
|
||||
* Read with byte offsets (needed only for file protocols)
|
||||
*/
|
||||
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||
void *buf1, int count1)
|
||||
{
|
||||
BlockDriver *drv = bs->drv;
|
||||
@ -664,10 +664,10 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||
return drv->bdrv_pread(bs, offset, buf1, count1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write with byte offsets (needed only for file protocols)
|
||||
/**
|
||||
* Write with byte offsets (needed only for file protocols)
|
||||
*/
|
||||
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
||||
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
||||
const void *buf1, int count1)
|
||||
{
|
||||
BlockDriver *drv = bs->drv;
|
||||
@ -729,7 +729,7 @@ void bdrv_set_boot_sector(BlockDriverState *bs, const uint8_t *data, int size)
|
||||
memset(bs->boot_sector_data + size, 0, 512 - size);
|
||||
}
|
||||
|
||||
void bdrv_set_geometry_hint(BlockDriverState *bs,
|
||||
void bdrv_set_geometry_hint(BlockDriverState *bs,
|
||||
int cyls, int heads, int secs)
|
||||
{
|
||||
bs->cyls = cyls;
|
||||
@ -749,7 +749,7 @@ void bdrv_set_translation_hint(BlockDriverState *bs, int translation)
|
||||
bs->translation = translation;
|
||||
}
|
||||
|
||||
void bdrv_get_geometry_hint(BlockDriverState *bs,
|
||||
void bdrv_get_geometry_hint(BlockDriverState *bs,
|
||||
int *pcyls, int *pheads, int *psecs)
|
||||
{
|
||||
*pcyls = bs->cyls;
|
||||
@ -778,7 +778,7 @@ int bdrv_is_read_only(BlockDriverState *bs)
|
||||
}
|
||||
|
||||
/* XXX: no longer used */
|
||||
void bdrv_set_change_cb(BlockDriverState *bs,
|
||||
void bdrv_set_change_cb(BlockDriverState *bs,
|
||||
void (*change_cb)(void *opaque), void *opaque)
|
||||
{
|
||||
bs->change_cb = change_cb;
|
||||
@ -816,7 +816,7 @@ void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size)
|
||||
}
|
||||
}
|
||||
|
||||
void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
|
||||
void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
|
||||
void *opaque)
|
||||
{
|
||||
BlockDriver *drv;
|
||||
@ -899,7 +899,7 @@ void bdrv_info(void)
|
||||
}
|
||||
}
|
||||
|
||||
void bdrv_get_backing_filename(BlockDriverState *bs,
|
||||
void bdrv_get_backing_filename(BlockDriverState *bs,
|
||||
char *filename, int filename_size)
|
||||
{
|
||||
if (!bs->backing_hd) {
|
||||
@ -909,7 +909,7 @@ void bdrv_get_backing_filename(BlockDriverState *bs,
|
||||
}
|
||||
}
|
||||
|
||||
int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
const uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
BlockDriver *drv = bs->drv;
|
||||
@ -919,7 +919,7 @@ int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||
return -ENOTSUP;
|
||||
return drv->bdrv_write_compressed(bs, sector_num, buf, nb_sectors);
|
||||
}
|
||||
|
||||
|
||||
int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
|
||||
{
|
||||
BlockDriver *drv = bs->drv;
|
||||
@ -934,7 +934,7 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
|
||||
/**************************************************************/
|
||||
/* handling of snapshots */
|
||||
|
||||
int bdrv_snapshot_create(BlockDriverState *bs,
|
||||
int bdrv_snapshot_create(BlockDriverState *bs,
|
||||
QEMUSnapshotInfo *sn_info)
|
||||
{
|
||||
BlockDriver *drv = bs->drv;
|
||||
@ -945,7 +945,7 @@ int bdrv_snapshot_create(BlockDriverState *bs,
|
||||
return drv->bdrv_snapshot_create(bs, sn_info);
|
||||
}
|
||||
|
||||
int bdrv_snapshot_goto(BlockDriverState *bs,
|
||||
int bdrv_snapshot_goto(BlockDriverState *bs,
|
||||
const char *snapshot_id)
|
||||
{
|
||||
BlockDriver *drv = bs->drv;
|
||||
@ -966,7 +966,7 @@ int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id)
|
||||
return drv->bdrv_snapshot_delete(bs, snapshot_id);
|
||||
}
|
||||
|
||||
int bdrv_snapshot_list(BlockDriverState *bs,
|
||||
int bdrv_snapshot_list(BlockDriverState *bs,
|
||||
QEMUSnapshotInfo **psn_info)
|
||||
{
|
||||
BlockDriver *drv = bs->drv;
|
||||
@ -991,12 +991,12 @@ char *get_human_readable_size(char *buf, int buf_size, int64_t size)
|
||||
base = 1024;
|
||||
for(i = 0; i < NB_SUFFIXES; i++) {
|
||||
if (size < (10 * base)) {
|
||||
snprintf(buf, buf_size, "%0.1f%c",
|
||||
snprintf(buf, buf_size, "%0.1f%c",
|
||||
(double)size / base,
|
||||
suffixes[i]);
|
||||
break;
|
||||
} else if (size < (1000 * base) || i == (NB_SUFFIXES - 1)) {
|
||||
snprintf(buf, buf_size, "%" PRId64 "%c",
|
||||
snprintf(buf, buf_size, "%" PRId64 "%c",
|
||||
((size + (base >> 1)) / base),
|
||||
suffixes[i]);
|
||||
break;
|
||||
@ -1019,8 +1019,8 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
|
||||
int64_t secs;
|
||||
|
||||
if (!sn) {
|
||||
snprintf(buf, buf_size,
|
||||
"%-10s%-20s%7s%20s%15s",
|
||||
snprintf(buf, buf_size,
|
||||
"%-10s%-20s%7s%20s%15s",
|
||||
"ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
|
||||
} else {
|
||||
ti = sn->date_sec;
|
||||
@ -1038,10 +1038,10 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
|
||||
"%02d:%02d:%02d.%03d",
|
||||
(int)(secs / 3600),
|
||||
(int)((secs / 60) % 60),
|
||||
(int)(secs % 60),
|
||||
(int)(secs % 60),
|
||||
(int)((sn->vm_clock_nsec / 1000000) % 1000));
|
||||
snprintf(buf, buf_size,
|
||||
"%-10s%-20s%7s%20s%15s",
|
||||
"%-10s%-20s%7s%20s%15s",
|
||||
sn->id_str, sn->name,
|
||||
get_human_readable_size(buf1, sizeof(buf1), sn->vm_state_size),
|
||||
date_buf,
|
||||
@ -1062,7 +1062,7 @@ BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num,
|
||||
|
||||
if (!drv)
|
||||
return NULL;
|
||||
|
||||
|
||||
/* XXX: we assume that nb_sectors == 0 is suppored by the async read */
|
||||
if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {
|
||||
memcpy(buf, bs->boot_sector_data, 512);
|
||||
@ -1085,7 +1085,7 @@ BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
|
||||
if (bs->read_only)
|
||||
return NULL;
|
||||
if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {
|
||||
memcpy(bs->boot_sector_data, buf, 512);
|
||||
memcpy(bs->boot_sector_data, buf, 512);
|
||||
}
|
||||
|
||||
return drv->bdrv_aio_write(bs, sector_num, buf, nb_sectors, cb, opaque);
|
||||
@ -1184,7 +1184,7 @@ static void bdrv_rw_em_cb(void *opaque, int ret)
|
||||
|
||||
#define NOT_DONE 0x7fffffff
|
||||
|
||||
static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,
|
||||
static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors)
|
||||
{
|
||||
int async_ret;
|
||||
@ -1192,7 +1192,7 @@ static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,
|
||||
|
||||
async_ret = NOT_DONE;
|
||||
qemu_aio_wait_start();
|
||||
acb = bdrv_aio_read(bs, sector_num, buf, nb_sectors,
|
||||
acb = bdrv_aio_read(bs, sector_num, buf, nb_sectors,
|
||||
bdrv_rw_em_cb, &async_ret);
|
||||
if (acb == NULL) {
|
||||
qemu_aio_wait_end();
|
||||
@ -1213,7 +1213,7 @@ static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,
|
||||
|
||||
async_ret = NOT_DONE;
|
||||
qemu_aio_wait_start();
|
||||
acb = bdrv_aio_write(bs, sector_num, buf, nb_sectors,
|
||||
acb = bdrv_aio_write(bs, sector_num, buf, nb_sectors,
|
||||
bdrv_rw_em_cb, &async_ret);
|
||||
if (acb == NULL) {
|
||||
qemu_aio_wait_end();
|
||||
@ -1293,7 +1293,7 @@ int bdrv_is_inserted(BlockDriverState *bs)
|
||||
|
||||
/**
|
||||
* Return TRUE if the media changed since the last call to this
|
||||
* function. It is currently only used for floppy disks
|
||||
* function. It is currently only used for floppy disks
|
||||
*/
|
||||
int bdrv_media_changed(BlockDriverState *bs)
|
||||
{
|
||||
|
26
block_int.h
26
block_int.h
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU System Emulator block driver
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -29,12 +29,12 @@ struct BlockDriver {
|
||||
int instance_size;
|
||||
int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename);
|
||||
int (*bdrv_open)(BlockDriverState *bs, const char *filename, int flags);
|
||||
int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
|
||||
int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
|
||||
uint8_t *buf, int nb_sectors);
|
||||
int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
|
||||
int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
|
||||
const uint8_t *buf, int nb_sectors);
|
||||
void (*bdrv_close)(BlockDriverState *bs);
|
||||
int (*bdrv_create)(const char *filename, int64_t total_sectors,
|
||||
int (*bdrv_create)(const char *filename, int64_t total_sectors,
|
||||
const char *backing_file, int flags);
|
||||
void (*bdrv_flush)(BlockDriverState *bs);
|
||||
int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
|
||||
@ -52,21 +52,21 @@ struct BlockDriver {
|
||||
int aiocb_size;
|
||||
|
||||
const char *protocol_name;
|
||||
int (*bdrv_pread)(BlockDriverState *bs, int64_t offset,
|
||||
int (*bdrv_pread)(BlockDriverState *bs, int64_t offset,
|
||||
uint8_t *buf, int count);
|
||||
int (*bdrv_pwrite)(BlockDriverState *bs, int64_t offset,
|
||||
int (*bdrv_pwrite)(BlockDriverState *bs, int64_t offset,
|
||||
const uint8_t *buf, int count);
|
||||
int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
|
||||
int64_t (*bdrv_getlength)(BlockDriverState *bs);
|
||||
int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
|
||||
int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
|
||||
const uint8_t *buf, int nb_sectors);
|
||||
|
||||
int (*bdrv_snapshot_create)(BlockDriverState *bs,
|
||||
int (*bdrv_snapshot_create)(BlockDriverState *bs,
|
||||
QEMUSnapshotInfo *sn_info);
|
||||
int (*bdrv_snapshot_goto)(BlockDriverState *bs,
|
||||
int (*bdrv_snapshot_goto)(BlockDriverState *bs,
|
||||
const char *snapshot_id);
|
||||
int (*bdrv_snapshot_delete)(BlockDriverState *bs, const char *snapshot_id);
|
||||
int (*bdrv_snapshot_list)(BlockDriverState *bs,
|
||||
int (*bdrv_snapshot_list)(BlockDriverState *bs,
|
||||
QEMUSnapshotInfo **psn_info);
|
||||
int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
|
||||
|
||||
@ -75,7 +75,7 @@ struct BlockDriver {
|
||||
int (*bdrv_media_changed)(BlockDriverState *bs);
|
||||
int (*bdrv_eject)(BlockDriverState *bs, int eject_flag);
|
||||
int (*bdrv_set_locked)(BlockDriverState *bs, int locked);
|
||||
|
||||
|
||||
BlockDriverAIOCB *free_aiocb;
|
||||
struct BlockDriver *next;
|
||||
};
|
||||
@ -107,7 +107,7 @@ struct BlockDriverState {
|
||||
/* async read/write emulation */
|
||||
|
||||
void *sync_aiocb;
|
||||
|
||||
|
||||
/* NOTE: the following infos are only hints for real hardware
|
||||
drivers. They are not used by the block driver */
|
||||
int cyls, heads, secs, translation;
|
||||
|
4
bswap.h
4
bswap.h
@ -48,12 +48,12 @@ static inline uint16_t bswap16(uint16_t x)
|
||||
return bswap_16(x);
|
||||
}
|
||||
|
||||
static inline uint32_t bswap32(uint32_t x)
|
||||
static inline uint32_t bswap32(uint32_t x)
|
||||
{
|
||||
return bswap_32(x);
|
||||
}
|
||||
|
||||
static inline uint64_t bswap64(uint64_t x)
|
||||
static inline uint64_t bswap64(uint64_t x)
|
||||
{
|
||||
return bswap_64(x);
|
||||
}
|
||||
|
214
cocoa.m
214
cocoa.m
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* QEMU Cocoa display driver
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2005 Pierre d'Herbemont
|
||||
* many code/inspiration from SDL 1.2 code (LGPL)
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -23,7 +23,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
/*
|
||||
Todo : x miniaturize window
|
||||
Todo : x miniaturize window
|
||||
x center the window
|
||||
- save window position
|
||||
- handle keyboard event
|
||||
@ -84,7 +84,7 @@ static void cocoa_update(DisplayState *ds, int x, int y, int w, int h)
|
||||
MacSetRectRgn (temp, x, y,
|
||||
x + w, y + h);
|
||||
MacUnionRgn (dirty, temp, dirty);
|
||||
|
||||
|
||||
/* Flush the dirty region */
|
||||
QDFlushPortBuffer ( [ qd_view qdPort ], dirty );
|
||||
DisposeRgn (dirty);
|
||||
@ -102,9 +102,9 @@ static void cocoa_resize(DisplayState *ds, int w, int h)
|
||||
static void *screen_pixels;
|
||||
static int screen_pitch;
|
||||
NSRect contentRect;
|
||||
|
||||
|
||||
//printf("resizing to %d %d\n", w, h);
|
||||
|
||||
|
||||
contentRect = NSMakeRect (0, 0, w, h);
|
||||
if(window)
|
||||
{
|
||||
@ -119,44 +119,44 @@ static void cocoa_resize(DisplayState *ds, int w, int h)
|
||||
fprintf(stderr, "(cocoa) can't create window\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
if(qd_view)
|
||||
[qd_view release];
|
||||
|
||||
|
||||
qd_view = [ [ NSQuickDrawView alloc ] initWithFrame:contentRect ];
|
||||
|
||||
|
||||
if(!qd_view)
|
||||
{
|
||||
fprintf(stderr, "(cocoa) can't create qd_view\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
[ window setAcceptsMouseMovedEvents:YES ];
|
||||
[ window setTitle:@"Qemu" ];
|
||||
[ window setReleasedWhenClosed:NO ];
|
||||
|
||||
|
||||
/* Set screen to black */
|
||||
[ window setBackgroundColor: [NSColor blackColor] ];
|
||||
|
||||
|
||||
/* set window position */
|
||||
[ window center ];
|
||||
|
||||
|
||||
[ qd_view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable ];
|
||||
[ [ window contentView ] addSubview:qd_view ];
|
||||
[ qd_view release ];
|
||||
[ window makeKeyAndOrderFront:nil ];
|
||||
|
||||
|
||||
/* Careful here, the window seems to have to be onscreen to do that */
|
||||
LockPortBits ( [ qd_view qdPort ] );
|
||||
screen_pixels = GetPixBaseAddr ( GetPortPixMap ( [ qd_view qdPort ] ) );
|
||||
screen_pitch = GetPixRowBytes ( GetPortPixMap ( [ qd_view qdPort ] ) );
|
||||
UnlockPortBits ( [ qd_view qdPort ] );
|
||||
{
|
||||
int vOffset = [ window frame ].size.height -
|
||||
{
|
||||
int vOffset = [ window frame ].size.height -
|
||||
[ qd_view frame ].size.height - [ qd_view frame ].origin.y;
|
||||
|
||||
|
||||
int hOffset = [ qd_view frame ].origin.x;
|
||||
|
||||
|
||||
screen_pixels += (vOffset * screen_pitch) + hOffset * (device_bpp/8);
|
||||
}
|
||||
ds->data = screen_pixels;
|
||||
@ -310,38 +310,38 @@ int keymap[] =
|
||||
208,// 125 0x7D 0xd0 E0,50 D ARROW QZ_DOWN
|
||||
200,// 126 0x7E 0xc8 E0,48 U ARROW QZ_UP
|
||||
/* completed according to http://www.libsdl.org/cgi/cvsweb.cgi/SDL12/src/video/quartz/SDL_QuartzKeys.h?rev=1.6&content-type=text/x-cvsweb-markup */
|
||||
|
||||
|
||||
/* Aditional 104 Key XP-Keyboard Scancodes from http://www.computer-engineering.org/ps2keyboard/scancodes1.html */
|
||||
/*
|
||||
219 // 0xdb e0,5b L GUI
|
||||
220 // 0xdc e0,5c R GUI
|
||||
221 // 0xdd e0,5d APPS
|
||||
// E0,2A,E0,37 PRNT SCRN
|
||||
// E1,1D,45,E1,9D,C5 PAUSE
|
||||
83 // 0x53 0x53 KP .
|
||||
// ACPI Scan Codes
|
||||
222 // 0xde E0, 5E Power
|
||||
223 // 0xdf E0, 5F Sleep
|
||||
227 // 0xe3 E0, 63 Wake
|
||||
// Windows Multimedia Scan Codes
|
||||
153 // 0x99 E0, 19 Next Track
|
||||
144 // 0x90 E0, 10 Previous Track
|
||||
164 // 0xa4 E0, 24 Stop
|
||||
162 // 0xa2 E0, 22 Play/Pause
|
||||
160 // 0xa0 E0, 20 Mute
|
||||
176 // 0xb0 E0, 30 Volume Up
|
||||
174 // 0xae E0, 2E Volume Down
|
||||
237 // 0xed E0, 6D Media Select
|
||||
236 // 0xec E0, 6C E-Mail
|
||||
161 // 0xa1 E0, 21 Calculator
|
||||
235 // 0xeb E0, 6B My Computer
|
||||
229 // 0xe5 E0, 65 WWW Search
|
||||
178 // 0xb2 E0, 32 WWW Home
|
||||
234 // 0xea E0, 6A WWW Back
|
||||
233 // 0xe9 E0, 69 WWW Forward
|
||||
232 // 0xe8 E0, 68 WWW Stop
|
||||
231 // 0xe7 E0, 67 WWW Refresh
|
||||
230 // 0xe6 E0, 66 WWW Favorites
|
||||
219 // 0xdb e0,5b L GUI
|
||||
220 // 0xdc e0,5c R GUI
|
||||
221 // 0xdd e0,5d APPS
|
||||
// E0,2A,E0,37 PRNT SCRN
|
||||
// E1,1D,45,E1,9D,C5 PAUSE
|
||||
83 // 0x53 0x53 KP .
|
||||
// ACPI Scan Codes
|
||||
222 // 0xde E0, 5E Power
|
||||
223 // 0xdf E0, 5F Sleep
|
||||
227 // 0xe3 E0, 63 Wake
|
||||
// Windows Multimedia Scan Codes
|
||||
153 // 0x99 E0, 19 Next Track
|
||||
144 // 0x90 E0, 10 Previous Track
|
||||
164 // 0xa4 E0, 24 Stop
|
||||
162 // 0xa2 E0, 22 Play/Pause
|
||||
160 // 0xa0 E0, 20 Mute
|
||||
176 // 0xb0 E0, 30 Volume Up
|
||||
174 // 0xae E0, 2E Volume Down
|
||||
237 // 0xed E0, 6D Media Select
|
||||
236 // 0xec E0, 6C E-Mail
|
||||
161 // 0xa1 E0, 21 Calculator
|
||||
235 // 0xeb E0, 6B My Computer
|
||||
229 // 0xe5 E0, 65 WWW Search
|
||||
178 // 0xb2 E0, 32 WWW Home
|
||||
234 // 0xea E0, 6A WWW Back
|
||||
233 // 0xe9 E0, 69 WWW Forward
|
||||
232 // 0xe8 E0, 68 WWW Stop
|
||||
231 // 0xe7 E0, 67 WWW Refresh
|
||||
230 // 0xe6 E0, 66 WWW Favorites
|
||||
*/
|
||||
};
|
||||
|
||||
@ -366,10 +366,10 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
NSDate *distantPast;
|
||||
NSEvent *event;
|
||||
NSAutoreleasePool *pool;
|
||||
|
||||
|
||||
pool = [ [ NSAutoreleasePool alloc ] init ];
|
||||
distantPast = [ NSDate distantPast ];
|
||||
|
||||
|
||||
vga_hw_update();
|
||||
|
||||
do {
|
||||
@ -415,8 +415,8 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
|
||||
case NSKeyDown:
|
||||
{
|
||||
int keycode = cocoa_keycode_to_qemu([event keyCode]);
|
||||
|
||||
int keycode = cocoa_keycode_to_qemu([event keyCode]);
|
||||
|
||||
/* handle command Key Combos */
|
||||
if ([event modifierFlags] & NSCommandKeyMask) {
|
||||
switch ([event keyCode]) {
|
||||
@ -427,7 +427,7 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* handle control + alt Key Combos */
|
||||
if (([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask)) {
|
||||
switch (keycode) {
|
||||
@ -482,10 +482,10 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case NSKeyUp:
|
||||
{
|
||||
int keycode = cocoa_keycode_to_qemu([event keyCode]);
|
||||
int keycode = cocoa_keycode_to_qemu([event keyCode]);
|
||||
if (is_graphic_console()) {
|
||||
if (keycode & 0x80)
|
||||
kbd_put_keycode(0xe0);
|
||||
@ -493,7 +493,7 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case NSMouseMoved:
|
||||
if (grab) {
|
||||
int dx = [event deltaX];
|
||||
@ -503,11 +503,11 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
kbd_mouse_event(dx, dy, dz, buttons);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case NSLeftMouseDown:
|
||||
if (grab) {
|
||||
int buttons = 0;
|
||||
|
||||
|
||||
/* leftclick+command simulates rightclick */
|
||||
if ([event modifierFlags] & NSCommandKeyMask) {
|
||||
buttons |= MOUSE_EVENT_RBUTTON;
|
||||
@ -519,7 +519,7 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
[NSApp sendEvent: event];
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case NSLeftMouseDragged:
|
||||
if (grab) {
|
||||
int dx = [event deltaX];
|
||||
@ -534,7 +534,7 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
kbd_mouse_event(dx, dy, dz, buttons);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case NSLeftMouseUp:
|
||||
if (grab) {
|
||||
kbd_mouse_event(0, 0, 0, 0);
|
||||
@ -546,18 +546,18 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
//[NSApp sendEvent: event];
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case NSRightMouseDown:
|
||||
if (grab) {
|
||||
int buttons = 0;
|
||||
|
||||
|
||||
buttons |= MOUSE_EVENT_RBUTTON;
|
||||
kbd_mouse_event(0, 0, 0, buttons);
|
||||
} else {
|
||||
[NSApp sendEvent: event];
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case NSRightMouseDragged:
|
||||
if (grab) {
|
||||
int dx = [event deltaX];
|
||||
@ -568,7 +568,7 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
kbd_mouse_event(dx, dy, dz, buttons);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case NSRightMouseUp:
|
||||
if (grab) {
|
||||
kbd_mouse_event(0, 0, 0, 0);
|
||||
@ -576,7 +576,7 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
[NSApp sendEvent: event];
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case NSOtherMouseDragged:
|
||||
if (grab) {
|
||||
int dx = [event deltaX];
|
||||
@ -587,7 +587,7 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
kbd_mouse_event(dx, dy, dz, buttons);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case NSOtherMouseDown:
|
||||
if (grab) {
|
||||
int buttons = 0;
|
||||
@ -597,7 +597,7 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
[NSApp sendEvent:event];
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case NSOtherMouseUp:
|
||||
if (grab) {
|
||||
kbd_mouse_event(0, 0, 0, 0);
|
||||
@ -605,14 +605,14 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
[NSApp sendEvent: event];
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case NSScrollWheel:
|
||||
if (grab) {
|
||||
int dz = [event deltaY];
|
||||
kbd_mouse_event(0, 0, -dz, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default: [NSApp sendEvent:event];
|
||||
}
|
||||
}
|
||||
@ -625,7 +625,7 @@ static void cocoa_refresh(DisplayState *ds)
|
||||
------------------------------------------------------
|
||||
*/
|
||||
|
||||
static void cocoa_cleanup(void)
|
||||
static void cocoa_cleanup(void)
|
||||
{
|
||||
|
||||
}
|
||||
@ -641,9 +641,9 @@ void cocoa_display_init(DisplayState *ds, int full_screen)
|
||||
ds->dpy_update = cocoa_update;
|
||||
ds->dpy_resize = cocoa_resize;
|
||||
ds->dpy_refresh = cocoa_refresh;
|
||||
|
||||
|
||||
cocoa_resize(ds, 640, 400);
|
||||
|
||||
|
||||
atexit(cocoa_cleanup);
|
||||
}
|
||||
|
||||
@ -661,17 +661,17 @@ void cocoa_display_init(DisplayState *ds, int full_screen)
|
||||
------------------------------------------------------
|
||||
*/
|
||||
static void QZ_SetPortAlphaOpaque ()
|
||||
{
|
||||
{
|
||||
/* Assume 32 bit if( bpp == 32 )*/
|
||||
if ( 1 ) {
|
||||
|
||||
|
||||
uint32_t *pixels = (uint32_t*) current_ds.data;
|
||||
uint32_t rowPixels = current_ds.linesize / 4;
|
||||
uint32_t i, j;
|
||||
|
||||
|
||||
for (i = 0; i < current_ds.height; i++)
|
||||
for (j = 0; j < current_ds.width; j++) {
|
||||
|
||||
|
||||
pixels[ (i * rowPixels) + j ] |= 0xFF000000;
|
||||
}
|
||||
}
|
||||
@ -680,32 +680,32 @@ static void QZ_SetPortAlphaOpaque ()
|
||||
@implementation QemuWindow
|
||||
- (void)miniaturize:(id)sender
|
||||
{
|
||||
|
||||
|
||||
/* make the alpha channel opaque so anim won't have holes in it */
|
||||
QZ_SetPortAlphaOpaque ();
|
||||
|
||||
|
||||
[ super miniaturize:sender ];
|
||||
|
||||
|
||||
}
|
||||
- (void)display
|
||||
{
|
||||
/*
|
||||
{
|
||||
/*
|
||||
This method fires just before the window deminaturizes from the Dock.
|
||||
|
||||
|
||||
We'll save the current visible surface, let the window manager redraw any
|
||||
UI elements, and restore the SDL surface. This way, no expose event
|
||||
UI elements, and restore the SDL surface. This way, no expose event
|
||||
is required, and the deminiaturize works perfectly.
|
||||
*/
|
||||
|
||||
|
||||
/* make sure pixels are fully opaque */
|
||||
QZ_SetPortAlphaOpaque ();
|
||||
|
||||
|
||||
/* save current visible SDL surface */
|
||||
[ self cacheImageInRect:[ qd_view frame ] ];
|
||||
|
||||
|
||||
/* let the window manager redraw controls, border, etc */
|
||||
[ super display ];
|
||||
|
||||
|
||||
/* restore visible SDL surface */
|
||||
[ self restoreCachedImage ];
|
||||
}
|
||||
@ -742,13 +742,13 @@ static void QZ_SetPortAlphaOpaque ()
|
||||
if( gArgc <= 1 || strncmp (gArgv[1], "-psn", 4) == 0)
|
||||
{
|
||||
NSOpenPanel *op = [[NSOpenPanel alloc] init];
|
||||
|
||||
|
||||
cocoa_resize(¤t_ds, 640, 400);
|
||||
|
||||
|
||||
[op setPrompt:@"Boot image"];
|
||||
|
||||
|
||||
[op setMessage:@"Select the disk image you want to boot.\n\nHit the \"Cancel\" button to quit"];
|
||||
|
||||
|
||||
[op beginSheetForDirectory:nil file:nil types:[NSArray arrayWithObjects:@"img",@"iso",@"dmg",@"qcow",@"cow",@"cloop",@"vmdk",nil]
|
||||
modalForWindow:window modalDelegate:self
|
||||
didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:NULL];
|
||||
@ -774,20 +774,20 @@ static void QZ_SetPortAlphaOpaque ()
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
if(returnCode == NSOKButton)
|
||||
{
|
||||
char *bin = "qemu";
|
||||
char *img = (char*)[ [ sheet filename ] cString];
|
||||
|
||||
|
||||
char **argv = (char**)malloc( sizeof(char*)*3 );
|
||||
|
||||
|
||||
asprintf(&argv[0], "%s", bin);
|
||||
asprintf(&argv[1], "-hda");
|
||||
asprintf(&argv[2], "%s", img);
|
||||
|
||||
|
||||
printf("Using argc %d argv %s -hda %s\n", 3, bin, img);
|
||||
|
||||
|
||||
[self startEmulationWithArgc:3 argv:(char**)argv];
|
||||
}
|
||||
}
|
||||
@ -827,10 +827,10 @@ static void setApplicationMenu(void)
|
||||
NSMenuItem *menuItem;
|
||||
NSString *title;
|
||||
NSString *appName;
|
||||
|
||||
|
||||
appName = @"Qemu";
|
||||
appleMenu = [[NSMenu alloc] initWithTitle:@""];
|
||||
|
||||
|
||||
/* Add menu items */
|
||||
title = [@"About " stringByAppendingString:appName];
|
||||
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
|
||||
@ -850,7 +850,7 @@ static void setApplicationMenu(void)
|
||||
title = [@"Quit " stringByAppendingString:appName];
|
||||
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
|
||||
|
||||
|
||||
|
||||
/* Put menu into the menubar */
|
||||
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
|
||||
[menuItem setSubmenu:appleMenu];
|
||||
@ -872,17 +872,17 @@ static void setupWindowMenu(void)
|
||||
NSMenuItem *menuItem;
|
||||
|
||||
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
|
||||
|
||||
|
||||
/* "Minimize" item */
|
||||
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
|
||||
[windowMenu addItem:menuItem];
|
||||
[menuItem release];
|
||||
|
||||
|
||||
/* Put menu into the menubar */
|
||||
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
|
||||
[windowMenuItem setSubmenu:windowMenu];
|
||||
[[NSApp mainMenu] addItem:windowMenuItem];
|
||||
|
||||
|
||||
/* Tell the application object that this is now the window menu */
|
||||
[NSApp setWindowsMenu:windowMenu];
|
||||
|
||||
@ -896,14 +896,14 @@ static void CustomApplicationMain(void)
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
QemuCocoaGUIController *gui_controller;
|
||||
CPSProcessSerNum PSN;
|
||||
|
||||
|
||||
[NSApplication sharedApplication];
|
||||
|
||||
|
||||
if (!CPSGetCurrentProcess(&PSN))
|
||||
if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
|
||||
if (!CPSSetFrontProcess(&PSN))
|
||||
[NSApplication sharedApplication];
|
||||
|
||||
|
||||
/* Set up the menubar */
|
||||
[NSApp setMainMenu:[[NSMenu alloc] init]];
|
||||
setApplicationMenu();
|
||||
@ -912,10 +912,10 @@ static void CustomApplicationMain(void)
|
||||
/* Create SDLMain and make it the app delegate */
|
||||
gui_controller = [[QemuCocoaGUIController alloc] init];
|
||||
[NSApp setDelegate:gui_controller];
|
||||
|
||||
|
||||
/* Start the main event loop */
|
||||
[NSApp run];
|
||||
|
||||
|
||||
[gui_controller release];
|
||||
[pool release];
|
||||
}
|
||||
|
6
configure
vendored
6
configure
vendored
@ -403,7 +403,7 @@ if test "$mingw32" = "yes" ; then
|
||||
oss="no"
|
||||
fi
|
||||
|
||||
# Check for gcc4, error if pre-gcc4
|
||||
# Check for gcc4, error if pre-gcc4
|
||||
if test "$check_gcc" = "yes" ; then
|
||||
cat > $TMPC <<EOF
|
||||
#if __GNUC__ < 4
|
||||
@ -444,7 +444,7 @@ if test "$solaris" = "yes" ; then
|
||||
#
|
||||
# gcc for solaris 10/fcs in /usr/sfw/bin doesn't compile qemu correctly
|
||||
# override the check with --disable-gcc-check
|
||||
#
|
||||
#
|
||||
if test "$solarisrev" -eq 10 -a "$check_gcc" = "yes" ; then
|
||||
solgcc=`which $cc`
|
||||
if test "$solgcc" = "/usr/sfw/bin/gcc" ; then
|
||||
@ -475,7 +475,7 @@ if test "$solaris" = "yes" ; then
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if test -z "$target_list" ; then
|
||||
|
56
console.c
56
console.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU graphical console
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -180,8 +180,8 @@ static unsigned int vga_get_color(DisplayState *ds, unsigned int rgba)
|
||||
r = (rgba >> 16) & 0xff;
|
||||
g = (rgba >> 8) & 0xff;
|
||||
b = (rgba) & 0xff;
|
||||
color = (rgb_to_index[r] * 6 * 6) +
|
||||
(rgb_to_index[g] * 6) +
|
||||
color = (rgb_to_index[r] * 6 * 6) +
|
||||
(rgb_to_index[g] * 6) +
|
||||
(rgb_to_index[b]);
|
||||
break;
|
||||
#endif
|
||||
@ -205,14 +205,14 @@ static unsigned int vga_get_color(DisplayState *ds, unsigned int rgba)
|
||||
return color;
|
||||
}
|
||||
|
||||
static void vga_fill_rect (DisplayState *ds,
|
||||
static void vga_fill_rect (DisplayState *ds,
|
||||
int posx, int posy, int width, int height, uint32_t color)
|
||||
{
|
||||
uint8_t *d, *d1;
|
||||
int x, y, bpp;
|
||||
|
||||
|
||||
bpp = (ds->depth + 7) >> 3;
|
||||
d1 = ds->data +
|
||||
d1 = ds->data +
|
||||
ds->linesize * posy + bpp * posx;
|
||||
for (y = 0; y < height; y++) {
|
||||
d = d1;
|
||||
@ -250,9 +250,9 @@ static void vga_bitblt(DisplayState *ds, int xs, int ys, int xd, int yd, int w,
|
||||
bpp = (ds->depth + 7) >> 3;
|
||||
wb = w * bpp;
|
||||
if (yd <= ys) {
|
||||
s = ds->data +
|
||||
s = ds->data +
|
||||
ds->linesize * ys + bpp * xs;
|
||||
d = ds->data +
|
||||
d = ds->data +
|
||||
ds->linesize * yd + bpp * xd;
|
||||
for (y = 0; y < h; y++) {
|
||||
memmove(d, s, wb);
|
||||
@ -260,9 +260,9 @@ static void vga_bitblt(DisplayState *ds, int xs, int ys, int xd, int yd, int w,
|
||||
s += ds->linesize;
|
||||
}
|
||||
} else {
|
||||
s = ds->data +
|
||||
s = ds->data +
|
||||
ds->linesize * (ys + h - 1) + bpp * xs;
|
||||
d = ds->data +
|
||||
d = ds->data +
|
||||
ds->linesize * (yd + h - 1) + bpp * xd;
|
||||
for (y = 0; y < h; y++) {
|
||||
memmove(d, s, wb);
|
||||
@ -405,7 +405,7 @@ static void console_print_text_attributes(TextAttributes *t_attrib, char ch)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void vga_putcharxy(DisplayState *ds, int x, int y, int ch,
|
||||
static void vga_putcharxy(DisplayState *ds, int x, int y, int ch,
|
||||
TextAttributes *t_attrib)
|
||||
{
|
||||
uint8_t *d;
|
||||
@ -428,7 +428,7 @@ static void vga_putcharxy(DisplayState *ds, int x, int y, int ch,
|
||||
}
|
||||
|
||||
bpp = (ds->depth + 7) >> 3;
|
||||
d = ds->data +
|
||||
d = ds->data +
|
||||
ds->linesize * y * FONT_HEIGHT + bpp * x * FONT_WIDTH;
|
||||
linesize = ds->linesize;
|
||||
font_ptr = vgafont16 + FONT_HEIGHT * ch;
|
||||
@ -525,9 +525,9 @@ static void update_xy(TextConsole *s, int x, int y)
|
||||
y2 += s->total_height;
|
||||
if (y2 < s->height) {
|
||||
c = &s->cells[y1 * s->width + x];
|
||||
vga_putcharxy(s->ds, x, y2, c->ch,
|
||||
vga_putcharxy(s->ds, x, y2, c->ch,
|
||||
&(c->t_attrib));
|
||||
dpy_update(s->ds, x * FONT_WIDTH, y2 * FONT_HEIGHT,
|
||||
dpy_update(s->ds, x * FONT_WIDTH, y2 * FONT_HEIGHT,
|
||||
FONT_WIDTH, FONT_HEIGHT);
|
||||
}
|
||||
}
|
||||
@ -556,7 +556,7 @@ static void console_show_cursor(TextConsole *s, int show)
|
||||
} else {
|
||||
vga_putcharxy(s->ds, x, y, c->ch, &(c->t_attrib));
|
||||
}
|
||||
dpy_update(s->ds, x * FONT_WIDTH, y * FONT_HEIGHT,
|
||||
dpy_update(s->ds, x * FONT_WIDTH, y * FONT_HEIGHT,
|
||||
FONT_WIDTH, FONT_HEIGHT);
|
||||
}
|
||||
}
|
||||
@ -567,7 +567,7 @@ static void console_refresh(TextConsole *s)
|
||||
TextCell *c;
|
||||
int x, y, y1;
|
||||
|
||||
if (s != active_console)
|
||||
if (s != active_console)
|
||||
return;
|
||||
|
||||
vga_fill_rect(s->ds, 0, 0, s->ds->width, s->ds->height,
|
||||
@ -576,7 +576,7 @@ static void console_refresh(TextConsole *s)
|
||||
for(y = 0; y < s->height; y++) {
|
||||
c = s->cells + y1 * s->width;
|
||||
for(x = 0; x < s->width; x++) {
|
||||
vga_putcharxy(s->ds, x, y, c->ch,
|
||||
vga_putcharxy(s->ds, x, y, c->ch,
|
||||
&(c->t_attrib));
|
||||
c++;
|
||||
}
|
||||
@ -591,7 +591,7 @@ static void console_scroll(int ydelta)
|
||||
{
|
||||
TextConsole *s;
|
||||
int i, y1;
|
||||
|
||||
|
||||
s = active_console;
|
||||
if (!s || (s->console_type == GRAPHIC_CONSOLE))
|
||||
return;
|
||||
@ -646,13 +646,13 @@ static void console_put_lf(TextConsole *s)
|
||||
c++;
|
||||
}
|
||||
if (s == active_console && s->y_displayed == s->y_base) {
|
||||
vga_bitblt(s->ds, 0, FONT_HEIGHT, 0, 0,
|
||||
s->width * FONT_WIDTH,
|
||||
vga_bitblt(s->ds, 0, FONT_HEIGHT, 0, 0,
|
||||
s->width * FONT_WIDTH,
|
||||
(s->height - 1) * FONT_HEIGHT);
|
||||
vga_fill_rect(s->ds, 0, (s->height - 1) * FONT_HEIGHT,
|
||||
s->width * FONT_WIDTH, FONT_HEIGHT,
|
||||
s->width * FONT_WIDTH, FONT_HEIGHT,
|
||||
color_table[0][s->t_attrib_default.bgcol]);
|
||||
dpy_update(s->ds, 0, 0,
|
||||
dpy_update(s->ds, 0, 0,
|
||||
s->width * FONT_WIDTH, s->height * FONT_HEIGHT);
|
||||
}
|
||||
}
|
||||
@ -781,7 +781,7 @@ static void console_putchar(TextConsole *s, int ch)
|
||||
console_put_lf(s);
|
||||
break;
|
||||
case '\b': /* backspace */
|
||||
if (s->x > 0)
|
||||
if (s->x > 0)
|
||||
s->x--;
|
||||
break;
|
||||
case '\t': /* tabspace */
|
||||
@ -832,7 +832,7 @@ static void console_putchar(TextConsole *s, int ch)
|
||||
case TTY_STATE_CSI: /* handle escape sequence parameters */
|
||||
if (ch >= '0' && ch <= '9') {
|
||||
if (s->nb_esc_params < MAX_ESC_PARAMS) {
|
||||
s->esc_params[s->nb_esc_params] =
|
||||
s->esc_params[s->nb_esc_params] =
|
||||
s->esc_params[s->nb_esc_params] * 10 + ch - '0';
|
||||
}
|
||||
} else {
|
||||
@ -1047,7 +1047,7 @@ static void kbd_send_chars(void *opaque)
|
||||
TextConsole *s = opaque;
|
||||
int len;
|
||||
uint8_t buf[16];
|
||||
|
||||
|
||||
len = qemu_chr_can_read(s->chr);
|
||||
if (len > s->out_fifo.count)
|
||||
len = s->out_fifo.count;
|
||||
@ -1192,12 +1192,12 @@ CharDriverState *text_console_init(DisplayState *ds, const char *p)
|
||||
s->out_fifo.buf = s->out_fifo_buf;
|
||||
s->out_fifo.buf_size = sizeof(s->out_fifo_buf);
|
||||
s->kbd_timer = qemu_new_timer(rt_clock, kbd_send_chars, s);
|
||||
|
||||
|
||||
if (!color_inited) {
|
||||
color_inited = 1;
|
||||
for(j = 0; j < 2; j++) {
|
||||
for(i = 0; i < 8; i++) {
|
||||
color_table[j][i] = col_expand(s->ds,
|
||||
color_table[j][i] = col_expand(s->ds,
|
||||
vga_get_color(s->ds, color_table_rgb[j][i]));
|
||||
}
|
||||
}
|
||||
|
40
cpu-all.h
40
cpu-all.h
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* defines common to all virtual CPUs
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -24,16 +24,16 @@
|
||||
#define WORDS_ALIGNED
|
||||
#endif
|
||||
|
||||
/* some important defines:
|
||||
*
|
||||
/* some important defines:
|
||||
*
|
||||
* WORDS_ALIGNED : if defined, the host cpu can only make word aligned
|
||||
* memory accesses.
|
||||
*
|
||||
*
|
||||
* WORDS_BIGENDIAN : if defined, the host cpu is big endian and
|
||||
* otherwise little endian.
|
||||
*
|
||||
*
|
||||
* (TARGET_WORDS_ALIGNED : same for target cpu (not supported yet))
|
||||
*
|
||||
*
|
||||
* TARGET_WORDS_BIGENDIAN : same for target cpu
|
||||
*/
|
||||
|
||||
@ -147,7 +147,7 @@ typedef union {
|
||||
* type is:
|
||||
* (empty): integer access
|
||||
* f : float access
|
||||
*
|
||||
*
|
||||
* sign is:
|
||||
* (empty): for floats or 32 bit size
|
||||
* u : unsigned
|
||||
@ -158,7 +158,7 @@ typedef union {
|
||||
* w: 16 bits
|
||||
* l: 32 bits
|
||||
* q: 64 bits
|
||||
*
|
||||
*
|
||||
* endian is:
|
||||
* (empty): target cpu endianness or 8 bit access
|
||||
* r : reversed target cpu endianness (not implemented yet)
|
||||
@ -621,7 +621,7 @@ static inline void stfq_be_p(void *ptr, float64 v)
|
||||
#define stfq_raw(p, v) stfq_p(saddr((p)), v)
|
||||
|
||||
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
|
||||
/* if user mode, no other memory access functions */
|
||||
#define ldub(p) ldub_raw(p)
|
||||
@ -685,7 +685,7 @@ extern unsigned long qemu_host_page_mask;
|
||||
#define PAGE_VALID 0x0008
|
||||
/* original state of the write flag (used when tracking self-modifying
|
||||
code */
|
||||
#define PAGE_WRITE_ORG 0x0010
|
||||
#define PAGE_WRITE_ORG 0x0010
|
||||
|
||||
void page_dump(FILE *f);
|
||||
int page_get_flags(target_ulong address);
|
||||
@ -694,7 +694,7 @@ void page_unprotect_range(target_ulong data, target_ulong data_size);
|
||||
|
||||
CPUState *cpu_copy(CPUState *env);
|
||||
|
||||
void cpu_dump_state(CPUState *env, FILE *f,
|
||||
void cpu_dump_state(CPUState *env, FILE *f,
|
||||
int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
|
||||
int flags);
|
||||
void cpu_dump_statistics (CPUState *env, FILE *f,
|
||||
@ -732,7 +732,7 @@ void cpu_reset(CPUState *s);
|
||||
if no page found. */
|
||||
target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr);
|
||||
|
||||
#define CPU_LOG_TB_OUT_ASM (1 << 0)
|
||||
#define CPU_LOG_TB_OUT_ASM (1 << 0)
|
||||
#define CPU_LOG_TB_IN_ASM (1 << 1)
|
||||
#define CPU_LOG_TB_OP (1 << 2)
|
||||
#define CPU_LOG_TB_OP_OPT (1 << 3)
|
||||
@ -793,7 +793,7 @@ extern uint8_t *phys_ram_dirty;
|
||||
typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
|
||||
typedef uint32_t CPUReadMemoryFunc(void *opaque, target_phys_addr_t addr);
|
||||
|
||||
void cpu_register_physical_memory(target_phys_addr_t start_addr,
|
||||
void cpu_register_physical_memory(target_phys_addr_t start_addr,
|
||||
unsigned long size,
|
||||
unsigned long phys_offset);
|
||||
uint32_t cpu_get_physical_page_desc(target_phys_addr_t addr);
|
||||
@ -808,12 +808,12 @@ CPUReadMemoryFunc **cpu_get_io_memory_read(int io_index);
|
||||
|
||||
void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
|
||||
int len, int is_write);
|
||||
static inline void cpu_physical_memory_read(target_phys_addr_t addr,
|
||||
static inline void cpu_physical_memory_read(target_phys_addr_t addr,
|
||||
uint8_t *buf, int len)
|
||||
{
|
||||
cpu_physical_memory_rw(addr, buf, len, 0);
|
||||
}
|
||||
static inline void cpu_physical_memory_write(target_phys_addr_t addr,
|
||||
static inline void cpu_physical_memory_write(target_phys_addr_t addr,
|
||||
const uint8_t *buf, int len)
|
||||
{
|
||||
cpu_physical_memory_rw(addr, (uint8_t *)buf, len, 1);
|
||||
@ -829,9 +829,9 @@ void stw_phys(target_phys_addr_t addr, uint32_t val);
|
||||
void stl_phys(target_phys_addr_t addr, uint32_t val);
|
||||
void stq_phys(target_phys_addr_t addr, uint64_t val);
|
||||
|
||||
void cpu_physical_memory_write_rom(target_phys_addr_t addr,
|
||||
void cpu_physical_memory_write_rom(target_phys_addr_t addr,
|
||||
const uint8_t *buf, int len);
|
||||
int cpu_memory_rw_debug(CPUState *env, target_ulong addr,
|
||||
int cpu_memory_rw_debug(CPUState *env, target_ulong addr,
|
||||
uint8_t *buf, int len, int is_write);
|
||||
|
||||
#define VGA_DIRTY_FLAG 0x01
|
||||
@ -843,7 +843,7 @@ static inline int cpu_physical_memory_is_dirty(ram_addr_t addr)
|
||||
return phys_ram_dirty[addr >> TARGET_PAGE_BITS] == 0xff;
|
||||
}
|
||||
|
||||
static inline int cpu_physical_memory_get_dirty(ram_addr_t addr,
|
||||
static inline int cpu_physical_memory_get_dirty(ram_addr_t addr,
|
||||
int dirty_flags)
|
||||
{
|
||||
return phys_ram_dirty[addr >> TARGET_PAGE_BITS] & dirty_flags;
|
||||
@ -866,14 +866,14 @@ void dump_exec_info(FILE *f,
|
||||
|
||||
#if defined(__powerpc__)
|
||||
|
||||
static inline uint32_t get_tbl(void)
|
||||
static inline uint32_t get_tbl(void)
|
||||
{
|
||||
uint32_t tbl;
|
||||
asm volatile("mftb %0" : "=r" (tbl));
|
||||
return tbl;
|
||||
}
|
||||
|
||||
static inline uint32_t get_tbu(void)
|
||||
static inline uint32_t get_tbu(void)
|
||||
{
|
||||
uint32_t tbl;
|
||||
asm volatile("mftbu %0" : "=r" (tbl));
|
||||
|
14
cpu-defs.h
14
cpu-defs.h
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* common defines for all CPUs
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -29,7 +29,7 @@
|
||||
#error TARGET_LONG_BITS must be defined before including this header
|
||||
#endif
|
||||
|
||||
#ifndef TARGET_PHYS_ADDR_BITS
|
||||
#ifndef TARGET_PHYS_ADDR_BITS
|
||||
#if TARGET_LONG_BITS >= HOST_LONG_BITS
|
||||
#define TARGET_PHYS_ADDR_BITS TARGET_LONG_BITS
|
||||
#else
|
||||
@ -97,17 +97,17 @@ typedef unsigned long ram_addr_t;
|
||||
#define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
|
||||
|
||||
typedef struct CPUTLBEntry {
|
||||
/* bit 31 to TARGET_PAGE_BITS : virtual address
|
||||
/* bit 31 to TARGET_PAGE_BITS : virtual address
|
||||
bit TARGET_PAGE_BITS-1..IO_MEM_SHIFT : if non zero, memory io
|
||||
zone number
|
||||
bit 3 : indicates that the entry is invalid
|
||||
bit 2..0 : zero
|
||||
*/
|
||||
target_ulong addr_read;
|
||||
target_ulong addr_write;
|
||||
target_ulong addr_code;
|
||||
target_ulong addr_read;
|
||||
target_ulong addr_write;
|
||||
target_ulong addr_code;
|
||||
/* addend to virtual address to get physical address */
|
||||
target_phys_addr_t addend;
|
||||
target_phys_addr_t addend;
|
||||
} CPUTLBEntry;
|
||||
|
||||
/* Alpha has 4 different running levels */
|
||||
|
148
cpu-exec.c
148
cpu-exec.c
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* i386 emulator main execution loop
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003-2005 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -55,7 +55,7 @@ void cpu_loop_exit(void)
|
||||
/* exit the current TB from a signal handler. The host registers are
|
||||
restored in a state compatible with the CPU emulator
|
||||
*/
|
||||
void cpu_resume_from_signal(CPUState *env1, void *puc)
|
||||
void cpu_resume_from_signal(CPUState *env1, void *puc)
|
||||
{
|
||||
#if !defined(CONFIG_SOFTMMU)
|
||||
struct ucontext *uc = puc;
|
||||
@ -84,13 +84,13 @@ static TranslationBlock *tb_find_slow(target_ulong pc,
|
||||
unsigned int h;
|
||||
target_ulong phys_pc, phys_page1, phys_page2, virt_page2;
|
||||
uint8_t *tc_ptr;
|
||||
|
||||
|
||||
spin_lock(&tb_lock);
|
||||
|
||||
tb_invalidated_flag = 0;
|
||||
|
||||
|
||||
regs_to_env(); /* XXX: do it just before cpu_gen_code() */
|
||||
|
||||
|
||||
/* find translated block using physical mappings */
|
||||
phys_pc = get_phys_addr_code(env, pc);
|
||||
phys_page1 = phys_pc & TARGET_PAGE_MASK;
|
||||
@ -101,13 +101,13 @@ static TranslationBlock *tb_find_slow(target_ulong pc,
|
||||
tb = *ptb1;
|
||||
if (!tb)
|
||||
goto not_found;
|
||||
if (tb->pc == pc &&
|
||||
if (tb->pc == pc &&
|
||||
tb->page_addr[0] == phys_page1 &&
|
||||
tb->cs_base == cs_base &&
|
||||
tb->cs_base == cs_base &&
|
||||
tb->flags == flags) {
|
||||
/* check next page if needed */
|
||||
if (tb->page_addr[1] != -1) {
|
||||
virt_page2 = (pc & TARGET_PAGE_MASK) +
|
||||
virt_page2 = (pc & TARGET_PAGE_MASK) +
|
||||
TARGET_PAGE_SIZE;
|
||||
phys_page2 = get_phys_addr_code(env, virt_page2);
|
||||
if (tb->page_addr[1] == phys_page2)
|
||||
@ -135,7 +135,7 @@ static TranslationBlock *tb_find_slow(target_ulong pc,
|
||||
tb->flags = flags;
|
||||
cpu_gen_code(env, tb, CODE_GEN_MAX_SIZE, &code_gen_size);
|
||||
code_gen_ptr = (void *)(((unsigned long)code_gen_ptr + code_gen_size + CODE_GEN_ALIGN - 1) & ~(CODE_GEN_ALIGN - 1));
|
||||
|
||||
|
||||
/* check next page if needed */
|
||||
virt_page2 = (pc + tb->size - 1) & TARGET_PAGE_MASK;
|
||||
phys_page2 = -1;
|
||||
@ -143,7 +143,7 @@ static TranslationBlock *tb_find_slow(target_ulong pc,
|
||||
phys_page2 = get_phys_addr_code(env, virt_page2);
|
||||
}
|
||||
tb_link_phys(tb, phys_pc, phys_page2);
|
||||
|
||||
|
||||
found:
|
||||
/* we add the TB in the virtual pc hash table */
|
||||
env->tb_jmp_cache[tb_jmp_cache_hash_func(pc)] = tb;
|
||||
@ -252,7 +252,7 @@ int cpu_exec(CPUState *env1)
|
||||
if (cpu_halted(env1) == EXCP_HALTED)
|
||||
return EXCP_HALTED;
|
||||
|
||||
cpu_single_env = env1;
|
||||
cpu_single_env = env1;
|
||||
|
||||
/* first we save global registers */
|
||||
#define SAVE_HOST_REGS 1
|
||||
@ -304,9 +304,9 @@ int cpu_exec(CPUState *env1)
|
||||
which will be handled outside the cpu execution
|
||||
loop */
|
||||
#if defined(TARGET_I386)
|
||||
do_interrupt_user(env->exception_index,
|
||||
env->exception_is_int,
|
||||
env->error_code,
|
||||
do_interrupt_user(env->exception_index,
|
||||
env->exception_is_int,
|
||||
env->error_code,
|
||||
env->exception_next_eip);
|
||||
#endif
|
||||
ret = env->exception_index;
|
||||
@ -316,9 +316,9 @@ int cpu_exec(CPUState *env1)
|
||||
/* simulate a real cpu exception. On i386, it can
|
||||
trigger new exceptions, but we do not handle
|
||||
double or triple faults yet. */
|
||||
do_interrupt(env->exception_index,
|
||||
env->exception_is_int,
|
||||
env->error_code,
|
||||
do_interrupt(env->exception_index,
|
||||
env->exception_is_int,
|
||||
env->error_code,
|
||||
env->exception_next_eip, 0);
|
||||
/* successfully delivered */
|
||||
env->old_exception = -1;
|
||||
@ -339,7 +339,7 @@ int cpu_exec(CPUState *env1)
|
||||
#endif
|
||||
}
|
||||
env->exception_index = -1;
|
||||
}
|
||||
}
|
||||
#ifdef USE_KQEMU
|
||||
if (kqemu_is_ok(env) && env->interrupt_request == 0) {
|
||||
int ret;
|
||||
@ -369,9 +369,9 @@ int cpu_exec(CPUState *env1)
|
||||
T0 = 0; /* force lookup of first TB */
|
||||
for(;;) {
|
||||
#if defined(__sparc__) && !defined(HOST_SOLARIS)
|
||||
/* g1 can be modified by some libc? functions */
|
||||
/* g1 can be modified by some libc? functions */
|
||||
tmp_T0 = T0;
|
||||
#endif
|
||||
#endif
|
||||
interrupt_request = env->interrupt_request;
|
||||
if (__builtin_expect(interrupt_request, 0)) {
|
||||
if (interrupt_request & CPU_INTERRUPT_DEBUG) {
|
||||
@ -399,7 +399,7 @@ int cpu_exec(CPUState *env1)
|
||||
T0 = 0;
|
||||
#endif
|
||||
} else if ((interrupt_request & CPU_INTERRUPT_HARD) &&
|
||||
(env->eflags & IF_MASK) &&
|
||||
(env->eflags & IF_MASK) &&
|
||||
!(env->hflags & HF_INHIBIT_IRQ_MASK)) {
|
||||
int intno;
|
||||
env->interrupt_request &= ~CPU_INTERRUPT_HARD;
|
||||
@ -551,7 +551,7 @@ int cpu_exec(CPUState *env1)
|
||||
#elif defined(TARGET_ALPHA)
|
||||
cpu_dump_state(env, logfile, fprintf, 0);
|
||||
#else
|
||||
#error unsupported target CPU
|
||||
#error unsupported target CPU
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@ -565,7 +565,7 @@ int cpu_exec(CPUState *env1)
|
||||
#endif
|
||||
#if defined(__sparc__) && !defined(HOST_SOLARIS)
|
||||
T0 = tmp_T0;
|
||||
#endif
|
||||
#endif
|
||||
/* see if we can patch the calling TB. When the TB
|
||||
spans two pages, we cannot safely do a direct
|
||||
jump. */
|
||||
@ -576,7 +576,7 @@ int cpu_exec(CPUState *env1)
|
||||
#endif
|
||||
tb->page_addr[1] == -1
|
||||
#if defined(TARGET_I386) && defined(USE_CODE_COPY)
|
||||
&& (tb->cflags & CF_CODE_COPY) ==
|
||||
&& (tb->cflags & CF_CODE_COPY) ==
|
||||
(((TranslationBlock *)(T0 & ~3))->cflags & CF_CODE_COPY)
|
||||
#endif
|
||||
) {
|
||||
@ -584,7 +584,7 @@ int cpu_exec(CPUState *env1)
|
||||
tb_add_jump((TranslationBlock *)(long)(T0 & ~3), T0 & 3, tb);
|
||||
#if defined(USE_CODE_COPY)
|
||||
/* propagates the FP use info */
|
||||
((TranslationBlock *)(T0 & ~3))->cflags |=
|
||||
((TranslationBlock *)(T0 & ~3))->cflags |=
|
||||
(tb->cflags & CF_FP_USED);
|
||||
#endif
|
||||
spin_unlock(&tb_lock);
|
||||
@ -598,7 +598,7 @@ int cpu_exec(CPUState *env1)
|
||||
__asm__ __volatile__("call %0\n\t"
|
||||
"mov %%o7,%%i0"
|
||||
: /* no outputs */
|
||||
: "r" (gen_func)
|
||||
: "r" (gen_func)
|
||||
: "i0", "i1", "i2", "i3", "i4", "i5",
|
||||
"o0", "o1", "o2", "o3", "o4", "o5",
|
||||
"l0", "l1", "l2", "l3", "l4", "l5",
|
||||
@ -755,7 +755,7 @@ int cpu_exec(CPUState *env1)
|
||||
#include "hostregs_helper.h"
|
||||
|
||||
/* fail safe : never use cpu_single_env outside cpu_exec() */
|
||||
cpu_single_env = NULL;
|
||||
cpu_single_env = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -782,7 +782,7 @@ void cpu_x86_load_seg(CPUX86State *s, int seg_reg, int selector)
|
||||
env = s;
|
||||
if (!(env->cr[0] & CR0_PE_MASK) || (env->eflags & VM_MASK)) {
|
||||
selector &= 0xffff;
|
||||
cpu_x86_load_seg_cache(env, seg_reg, selector,
|
||||
cpu_x86_load_seg_cache(env, seg_reg, selector,
|
||||
(selector << 4), 0xffff, 0);
|
||||
} else {
|
||||
load_seg(seg_reg, selector);
|
||||
@ -796,7 +796,7 @@ void cpu_x86_fsave(CPUX86State *s, uint8_t *ptr, int data32)
|
||||
|
||||
saved_env = env;
|
||||
env = s;
|
||||
|
||||
|
||||
helper_fsave((target_ulong)ptr, data32);
|
||||
|
||||
env = saved_env;
|
||||
@ -808,7 +808,7 @@ void cpu_x86_frstor(CPUX86State *s, uint8_t *ptr, int data32)
|
||||
|
||||
saved_env = env;
|
||||
env = s;
|
||||
|
||||
|
||||
helper_frstor((target_ulong)ptr, data32);
|
||||
|
||||
env = saved_env;
|
||||
@ -825,7 +825,7 @@ void cpu_x86_frstor(CPUX86State *s, uint8_t *ptr, int data32)
|
||||
write caused the exception and otherwise 0'. 'old_set' is the
|
||||
signal set which should be restored */
|
||||
static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
int is_write, sigset_t *old_set,
|
||||
int is_write, sigset_t *old_set,
|
||||
void *puc)
|
||||
{
|
||||
TranslationBlock *tb;
|
||||
@ -834,7 +834,7 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
if (cpu_single_env)
|
||||
env = cpu_single_env; /* XXX: find a correct solution for multithread */
|
||||
#if defined(DEBUG_SIGNAL)
|
||||
qemu_printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
qemu_printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
pc, address, is_write, *(unsigned long *)old_set);
|
||||
#endif
|
||||
/* XXX: locking issue */
|
||||
@ -843,7 +843,7 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
}
|
||||
|
||||
/* see if it is an MMU fault */
|
||||
ret = cpu_x86_handle_mmu_fault(env, address, is_write,
|
||||
ret = cpu_x86_handle_mmu_fault(env, address, is_write,
|
||||
((env->hflags & HF_CPL_MASK) == 3), 0);
|
||||
if (ret < 0)
|
||||
return 0; /* not an MMU fault */
|
||||
@ -858,7 +858,7 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
}
|
||||
if (ret == 1) {
|
||||
#if 0
|
||||
printf("PF exception: EIP=0x%08x CR2=0x%08x error=0x%x\n",
|
||||
printf("PF exception: EIP=0x%08x CR2=0x%08x error=0x%x\n",
|
||||
env->eip, env->cr[2], env->error_code);
|
||||
#endif
|
||||
/* we restore the process signal mask as the sigreturn should
|
||||
@ -885,7 +885,7 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
if (cpu_single_env)
|
||||
env = cpu_single_env; /* XXX: find a correct solution for multithread */
|
||||
#if defined(DEBUG_SIGNAL)
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
pc, address, is_write, *(unsigned long *)old_set);
|
||||
#endif
|
||||
/* XXX: locking issue */
|
||||
@ -921,7 +921,7 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
if (cpu_single_env)
|
||||
env = cpu_single_env; /* XXX: find a correct solution for multithread */
|
||||
#if defined(DEBUG_SIGNAL)
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
pc, address, is_write, *(unsigned long *)old_set);
|
||||
#endif
|
||||
/* XXX: locking issue */
|
||||
@ -953,11 +953,11 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
{
|
||||
TranslationBlock *tb;
|
||||
int ret;
|
||||
|
||||
|
||||
if (cpu_single_env)
|
||||
env = cpu_single_env; /* XXX: find a correct solution for multithread */
|
||||
#if defined(DEBUG_SIGNAL)
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
pc, address, is_write, *(unsigned long *)old_set);
|
||||
#endif
|
||||
/* XXX: locking issue */
|
||||
@ -981,7 +981,7 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
}
|
||||
if (ret == 1) {
|
||||
#if 0
|
||||
printf("PF exception: NIP=0x%08x error=0x%x %p\n",
|
||||
printf("PF exception: NIP=0x%08x error=0x%x %p\n",
|
||||
env->nip, env->error_code, tb);
|
||||
#endif
|
||||
/* we restore the process signal mask as the sigreturn should
|
||||
@ -1007,7 +1007,7 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
if (cpu_single_env)
|
||||
env = cpu_single_env; /* XXX: find a correct solution for multithread */
|
||||
#if defined(DEBUG_SIGNAL)
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
pc, address, is_write, *(unsigned long *)old_set);
|
||||
#endif
|
||||
/* XXX: locking issue */
|
||||
@ -1042,11 +1042,11 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
{
|
||||
TranslationBlock *tb;
|
||||
int ret;
|
||||
|
||||
|
||||
if (cpu_single_env)
|
||||
env = cpu_single_env; /* XXX: find a correct solution for multithread */
|
||||
#if defined(DEBUG_SIGNAL)
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
pc, address, is_write, *(unsigned long *)old_set);
|
||||
#endif
|
||||
/* XXX: locking issue */
|
||||
@ -1070,7 +1070,7 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
}
|
||||
if (ret == 1) {
|
||||
#if 0
|
||||
printf("PF exception: PC=0x" TARGET_FMT_lx " error=0x%x %p\n",
|
||||
printf("PF exception: PC=0x" TARGET_FMT_lx " error=0x%x %p\n",
|
||||
env->PC, env->error_code, tb);
|
||||
#endif
|
||||
/* we restore the process signal mask as the sigreturn should
|
||||
@ -1092,11 +1092,11 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
{
|
||||
TranslationBlock *tb;
|
||||
int ret;
|
||||
|
||||
|
||||
if (cpu_single_env)
|
||||
env = cpu_single_env; /* XXX: find a correct solution for multithread */
|
||||
#if defined(DEBUG_SIGNAL)
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
pc, address, is_write, *(unsigned long *)old_set);
|
||||
#endif
|
||||
/* XXX: locking issue */
|
||||
@ -1119,7 +1119,7 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
cpu_restore_state(tb, env, pc, puc);
|
||||
}
|
||||
#if 0
|
||||
printf("PF exception: NIP=0x%08x error=0x%x %p\n",
|
||||
printf("PF exception: NIP=0x%08x error=0x%x %p\n",
|
||||
env->nip, env->error_code, tb);
|
||||
#endif
|
||||
/* we restore the process signal mask as the sigreturn should
|
||||
@ -1137,11 +1137,11 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
{
|
||||
TranslationBlock *tb;
|
||||
int ret;
|
||||
|
||||
|
||||
if (cpu_single_env)
|
||||
env = cpu_single_env; /* XXX: find a correct solution for multithread */
|
||||
#if defined(DEBUG_SIGNAL)
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
||||
pc, address, is_write, *(unsigned long *)old_set);
|
||||
#endif
|
||||
/* XXX: locking issue */
|
||||
@ -1164,7 +1164,7 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
cpu_restore_state(tb, env, pc, puc);
|
||||
}
|
||||
#if 0
|
||||
printf("PF exception: NIP=0x%08x error=0x%x %p\n",
|
||||
printf("PF exception: NIP=0x%08x error=0x%x %p\n",
|
||||
env->nip, env->error_code, tb);
|
||||
#endif
|
||||
/* we restore the process signal mask as the sigreturn should
|
||||
@ -1193,7 +1193,7 @@ static inline int handle_cpu_signal(unsigned long pc, unsigned long address,
|
||||
#endif
|
||||
|
||||
#if defined(USE_CODE_COPY)
|
||||
static void cpu_send_trap(unsigned long pc, int trap,
|
||||
static void cpu_send_trap(unsigned long pc, int trap,
|
||||
struct ucontext *uc)
|
||||
{
|
||||
TranslationBlock *tb;
|
||||
@ -1212,7 +1212,7 @@ static void cpu_send_trap(unsigned long pc, int trap,
|
||||
}
|
||||
#endif
|
||||
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
void *puc)
|
||||
{
|
||||
siginfo_t *info = pinfo;
|
||||
@ -1235,8 +1235,8 @@ int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
return 1;
|
||||
} else
|
||||
#endif
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
trapno == 0xe ?
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
trapno == 0xe ?
|
||||
(ERROR_sig(uc) >> 1) & 1 : 0,
|
||||
&uc->uc_sigmask, puc);
|
||||
}
|
||||
@ -1251,8 +1251,8 @@ int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
unsigned long pc;
|
||||
|
||||
pc = uc->uc_mcontext.gregs[REG_RIP];
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
uc->uc_mcontext.gregs[REG_TRAPNO] == 0xe ?
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
uc->uc_mcontext.gregs[REG_TRAPNO] == 0xe ?
|
||||
(uc->uc_mcontext.gregs[REG_ERR] >> 1) & 1 : 0,
|
||||
&uc->uc_sigmask, puc);
|
||||
}
|
||||
@ -1308,7 +1308,7 @@ typedef struct ucontext SIGCONTEXT;
|
||||
# define TRAP_sig(context) EXCEPREG_sig(exception, context) /* number of powerpc exception taken */
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
void *puc)
|
||||
{
|
||||
siginfo_t *info = pinfo;
|
||||
@ -1326,13 +1326,13 @@ int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
if (TRAP_sig(uc) != 0x400 && (DSISR_sig(uc) & 0x02000000))
|
||||
is_write = 1;
|
||||
#endif
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
is_write, &uc->uc_sigmask, puc);
|
||||
}
|
||||
|
||||
#elif defined(__alpha__)
|
||||
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
void *puc)
|
||||
{
|
||||
siginfo_t *info = pinfo;
|
||||
@ -1357,12 +1357,12 @@ int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
is_write = 1;
|
||||
}
|
||||
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
is_write, &uc->uc_sigmask, puc);
|
||||
}
|
||||
#elif defined(__sparc__)
|
||||
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
void *puc)
|
||||
{
|
||||
siginfo_t *info = pinfo;
|
||||
@ -1371,7 +1371,7 @@ int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
unsigned long pc;
|
||||
int is_write;
|
||||
uint32_t insn;
|
||||
|
||||
|
||||
/* XXX: is there a standard glibc define ? */
|
||||
pc = regs[1];
|
||||
/* XXX: need kernel patch to get write flag faster */
|
||||
@ -1390,42 +1390,42 @@ int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
break;
|
||||
}
|
||||
}
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
is_write, sigmask, NULL);
|
||||
}
|
||||
|
||||
#elif defined(__arm__)
|
||||
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
void *puc)
|
||||
{
|
||||
siginfo_t *info = pinfo;
|
||||
struct ucontext *uc = puc;
|
||||
unsigned long pc;
|
||||
int is_write;
|
||||
|
||||
|
||||
pc = uc->uc_mcontext.gregs[R15];
|
||||
/* XXX: compute is_write */
|
||||
is_write = 0;
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
is_write,
|
||||
&uc->uc_sigmask, puc);
|
||||
}
|
||||
|
||||
#elif defined(__mc68000)
|
||||
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
void *puc)
|
||||
{
|
||||
siginfo_t *info = pinfo;
|
||||
struct ucontext *uc = puc;
|
||||
unsigned long pc;
|
||||
int is_write;
|
||||
|
||||
|
||||
pc = uc->uc_mcontext.gregs[16];
|
||||
/* XXX: compute is_write */
|
||||
is_write = 0;
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
is_write,
|
||||
&uc->uc_sigmask, puc);
|
||||
}
|
||||
@ -1466,34 +1466,34 @@ int cpu_signal_handler(int host_signum, void *pinfo, void *puc)
|
||||
|
||||
#elif defined(__s390__)
|
||||
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
void *puc)
|
||||
{
|
||||
siginfo_t *info = pinfo;
|
||||
struct ucontext *uc = puc;
|
||||
unsigned long pc;
|
||||
int is_write;
|
||||
|
||||
|
||||
pc = uc->uc_mcontext.psw.addr;
|
||||
/* XXX: compute is_write */
|
||||
is_write = 0;
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
is_write, &uc->uc_sigmask, puc);
|
||||
}
|
||||
|
||||
#elif defined(__mips__)
|
||||
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
int cpu_signal_handler(int host_signum, void *pinfo,
|
||||
void *puc)
|
||||
{
|
||||
siginfo_t *info = pinfo;
|
||||
struct ucontext *uc = puc;
|
||||
greg_t pc = uc->uc_mcontext.pc;
|
||||
int is_write;
|
||||
|
||||
|
||||
/* XXX: compute is_write */
|
||||
is_write = 0;
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
return handle_cpu_signal(pc, (unsigned long)info->si_addr,
|
||||
is_write, &uc->uc_sigmask, puc);
|
||||
}
|
||||
|
||||
|
4
cutils.c
4
cutils.c
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Simple C functions to supplement the C library
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2006 Fabrice Bellard
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
@ -45,7 +45,7 @@ char *pstrcat(char *buf, int buf_size, const char *s)
|
||||
{
|
||||
int len;
|
||||
len = strlen(buf);
|
||||
if (len < buf_size)
|
||||
if (len < buf_size)
|
||||
pstrcpy(buf + len, buf_size - len, s);
|
||||
return buf;
|
||||
}
|
||||
|
@ -1336,7 +1336,7 @@ static inline long bswap_syctl(int * mib, int count, void *buf, int size)
|
||||
if(!(sysctl = sysctl->childs))
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if(ret->childs)
|
||||
qerror("we shouldn't have a directory element\n");
|
||||
|
||||
@ -1375,7 +1375,7 @@ long do___sysctl(int * name, uint32_t namelen, void * oldp, size_t * oldlenp, vo
|
||||
//bswap_syctl(name, namelen, newp, newlen);
|
||||
tswap32s((uint32_t*)oldlenp);
|
||||
}
|
||||
|
||||
|
||||
if(name) /* Sometimes sysctl is called with no arg1, ignore */
|
||||
ret = get_errno(sysctl(name, namelen, oldp, oldlenp, newp, newlen));
|
||||
|
||||
|
10
dis-asm.h
10
dis-asm.h
@ -44,7 +44,7 @@ enum bfd_flavour {
|
||||
|
||||
enum bfd_endian { BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN };
|
||||
|
||||
enum bfd_architecture
|
||||
enum bfd_architecture
|
||||
{
|
||||
bfd_arch_unknown, /* File arch not known */
|
||||
bfd_arch_obscure, /* Arch known, not one of these */
|
||||
@ -67,14 +67,14 @@ enum bfd_architecture
|
||||
#define bfd_mach_mcf5249 16
|
||||
#define bfd_mach_mcf547x 17
|
||||
#define bfd_mach_mcf548x 18
|
||||
bfd_arch_vax, /* DEC Vax */
|
||||
bfd_arch_vax, /* DEC Vax */
|
||||
bfd_arch_i960, /* Intel 960 */
|
||||
/* The order of the following is important.
|
||||
lower number indicates a machine type that
|
||||
lower number indicates a machine type that
|
||||
only accepts a subset of the instructions
|
||||
available to machines with higher numbers.
|
||||
The exception is the "ca", which is
|
||||
incompatible with all other machines except
|
||||
incompatible with all other machines except
|
||||
"core". */
|
||||
|
||||
#define bfd_mach_i960_core 1
|
||||
@ -228,7 +228,7 @@ enum dis_insn_type {
|
||||
dis_dref2 /* Two data references in instruction */
|
||||
};
|
||||
|
||||
/* This struct is passed into the instruction decoding routine,
|
||||
/* This struct is passed into the instruction decoding routine,
|
||||
and is passed back out into each callback. The various fields are used
|
||||
for conveying information from your main routine into your callbacks,
|
||||
for passing information into the instruction decoders (such as the
|
||||
|
12
disas.c
12
disas.c
@ -137,7 +137,7 @@ print_insn_thumb1(bfd_vma pc, disassemble_info *info)
|
||||
/* Disassemble this for me please... (debugging). 'flags' has the following
|
||||
values:
|
||||
i386 - nonzero means 16 bit code
|
||||
arm - nonzero means thumb code
|
||||
arm - nonzero means thumb code
|
||||
ppc - nonzero means little endian
|
||||
other targets - unused
|
||||
*/
|
||||
@ -162,7 +162,7 @@ void target_disas(FILE *out, target_ulong code, target_ulong size, int flags)
|
||||
#if defined(TARGET_I386)
|
||||
if (flags == 2)
|
||||
disasm_info.mach = bfd_mach_x86_64;
|
||||
else if (flags == 1)
|
||||
else if (flags == 1)
|
||||
disasm_info.mach = bfd_mach_i386_i8086;
|
||||
else
|
||||
disasm_info.mach = bfd_mach_i386_i386;
|
||||
@ -176,7 +176,7 @@ void target_disas(FILE *out, target_ulong code, target_ulong size, int flags)
|
||||
print_insn = print_insn_sparc;
|
||||
#ifdef TARGET_SPARC64
|
||||
disasm_info.mach = bfd_mach_sparc_v9b;
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(TARGET_PPC)
|
||||
if (flags)
|
||||
disasm_info.endian = BFD_ENDIAN_LITTLE;
|
||||
@ -261,7 +261,7 @@ void disas(FILE *out, void *code, unsigned long size)
|
||||
#if defined(__sparc_v8plus__) || defined(__sparc_v8plusa__) || defined(__sparc_v9__)
|
||||
disasm_info.mach = bfd_mach_sparc_v9b;
|
||||
#endif
|
||||
#elif defined(__arm__)
|
||||
#elif defined(__arm__)
|
||||
print_insn = print_insn_arm;
|
||||
#elif defined(__MIPSEB__)
|
||||
print_insn = print_insn_big_mips;
|
||||
@ -298,7 +298,7 @@ const char *lookup_symbol(target_ulong orig_addr)
|
||||
Elf32_Sym *sym;
|
||||
struct syminfo *s;
|
||||
target_ulong addr;
|
||||
|
||||
|
||||
for (s = syminfos; s; s = s->next) {
|
||||
sym = s->disas_symtab;
|
||||
for (i = 0; i < s->disas_num_syms; i++) {
|
||||
@ -377,7 +377,7 @@ void monitor_disas(CPUState *env,
|
||||
#if defined(TARGET_I386)
|
||||
if (flags == 2)
|
||||
disasm_info.mach = bfd_mach_x86_64;
|
||||
else if (flags == 1)
|
||||
else if (flags == 1)
|
||||
disasm_info.mach = bfd_mach_i386_i8086;
|
||||
else
|
||||
disasm_info.mach = bfd_mach_i386_i386;
|
||||
|
@ -209,7 +209,7 @@ extern int printf(const char *, ...);
|
||||
/* the symbols are considered non exported so a br immediate is generated */
|
||||
#define __hidden __attribute__((visibility("hidden")))
|
||||
#else
|
||||
#define __hidden
|
||||
#define __hidden
|
||||
#endif
|
||||
|
||||
#if defined(__alpha__)
|
||||
|
230
dyngen.c
230
dyngen.c
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Generic Dynamic compiler generator
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
*
|
||||
* The COFF object format support was extracted from Kazu's QEMU port
|
||||
@ -204,11 +204,11 @@ typedef uint32_t host_ulong;
|
||||
struct nlist_extended
|
||||
{
|
||||
union {
|
||||
char *n_name;
|
||||
long n_strx;
|
||||
char *n_name;
|
||||
long n_strx;
|
||||
} n_un;
|
||||
unsigned char n_type;
|
||||
unsigned char n_sect;
|
||||
unsigned char n_type;
|
||||
unsigned char n_sect;
|
||||
short st_desc;
|
||||
unsigned long st_value;
|
||||
unsigned long st_size;
|
||||
@ -372,10 +372,10 @@ int elf_must_swap(struct elfhdr *h)
|
||||
} swaptest;
|
||||
|
||||
swaptest.i = 1;
|
||||
return (h->e_ident[EI_DATA] == ELFDATA2MSB) !=
|
||||
return (h->e_ident[EI_DATA] == ELFDATA2MSB) !=
|
||||
(swaptest.b[0] == 0);
|
||||
}
|
||||
|
||||
|
||||
void elf_swap_ehdr(struct elfhdr *h)
|
||||
{
|
||||
swab16s(&h->e_type); /* Object file type */
|
||||
@ -428,7 +428,7 @@ void elf_swap_rel(ELF_RELOC *rel)
|
||||
#endif
|
||||
}
|
||||
|
||||
struct elf_shdr *find_elf_section(struct elf_shdr *shdr, int shnum, const char *shstr,
|
||||
struct elf_shdr *find_elf_section(struct elf_shdr *shdr, int shnum, const char *shstr,
|
||||
const char *name)
|
||||
{
|
||||
int i;
|
||||
@ -453,7 +453,7 @@ int find_reloc(int sh_index)
|
||||
|
||||
for(i = 0; i < ehdr.e_shnum; i++) {
|
||||
sec = &shdr[i];
|
||||
if (sec->sh_type == SHT_RELOC && sec->sh_info == sh_index)
|
||||
if (sec->sh_type == SHT_RELOC && sec->sh_info == sh_index)
|
||||
return i;
|
||||
}
|
||||
return 0;
|
||||
@ -483,11 +483,11 @@ int load_object(const char *filename)
|
||||
ElfW(Sym) *sym;
|
||||
char *shstr;
|
||||
ELF_RELOC *rel;
|
||||
|
||||
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd < 0)
|
||||
if (fd < 0)
|
||||
error("can't open file '%s'", filename);
|
||||
|
||||
|
||||
/* Read ELF header. */
|
||||
if (read(fd, &ehdr, sizeof (ehdr)) != sizeof (ehdr))
|
||||
error("unable to read file header");
|
||||
@ -524,7 +524,7 @@ int load_object(const char *filename)
|
||||
/* read all section data */
|
||||
sdata = malloc(sizeof(void *) * ehdr.e_shnum);
|
||||
memset(sdata, 0, sizeof(void *) * ehdr.e_shnum);
|
||||
|
||||
|
||||
for(i = 0;i < ehdr.e_shnum; i++) {
|
||||
sec = &shdr[i];
|
||||
if (sec->sh_type != SHT_NOBITS)
|
||||
@ -569,7 +569,7 @@ int load_object(const char *filename)
|
||||
|
||||
symtab = (ElfW(Sym) *)sdata[symtab_sec - shdr];
|
||||
strtab = (char *)sdata[symtab_sec->sh_link];
|
||||
|
||||
|
||||
nb_syms = symtab_sec->sh_size / sizeof(ElfW(Sym));
|
||||
if (do_swap) {
|
||||
for(i = 0, sym = symtab; i < nb_syms; i++, sym++) {
|
||||
@ -609,7 +609,7 @@ void sym_ent_name(struct external_syment *ext_sym, EXE_SYM *sym)
|
||||
{
|
||||
char *q;
|
||||
int c, i, len;
|
||||
|
||||
|
||||
if (ext_sym->e.e.e_zeroes != 0) {
|
||||
q = sym->st_name;
|
||||
for(i = 0; i < 8; i++) {
|
||||
@ -643,7 +643,7 @@ char *name_for_dotdata(struct coff_rel *rel)
|
||||
if (sym->st_syment->e_scnum == data_shndx &&
|
||||
text_data >= sym->st_value &&
|
||||
text_data < sym->st_value + sym->st_size) {
|
||||
|
||||
|
||||
return sym->st_name;
|
||||
|
||||
}
|
||||
@ -701,15 +701,15 @@ int load_object(const char *filename)
|
||||
uint32_t *n_strtab;
|
||||
EXE_SYM *sym;
|
||||
EXE_RELOC *rel;
|
||||
|
||||
fd = open(filename, O_RDONLY
|
||||
|
||||
fd = open(filename, O_RDONLY
|
||||
#ifdef _WIN32
|
||||
| O_BINARY
|
||||
#endif
|
||||
);
|
||||
if (fd < 0)
|
||||
if (fd < 0)
|
||||
error("can't open file '%s'", filename);
|
||||
|
||||
|
||||
/* Read COFF header. */
|
||||
if (read(fd, &fhdr, sizeof (fhdr)) != sizeof (fhdr))
|
||||
error("unable to read file header");
|
||||
@ -722,11 +722,11 @@ int load_object(const char *filename)
|
||||
|
||||
/* read section headers */
|
||||
shdr = load_data(fd, sizeof(struct external_filehdr) + fhdr.f_opthdr, fhdr.f_nscns * sizeof(struct external_scnhdr));
|
||||
|
||||
|
||||
/* read all section data */
|
||||
sdata = malloc(sizeof(void *) * fhdr.f_nscns);
|
||||
memset(sdata, 0, sizeof(void *) * fhdr.f_nscns);
|
||||
|
||||
|
||||
const char *p;
|
||||
for(i = 0;i < fhdr.f_nscns; i++) {
|
||||
sec = &shdr[i];
|
||||
@ -747,7 +747,7 @@ int load_object(const char *filename)
|
||||
if (!data_sec)
|
||||
error("could not find .data section");
|
||||
coff_data_shndx = data_sec - shdr;
|
||||
|
||||
|
||||
coff_symtab = load_data(fd, fhdr.f_symptr, fhdr.f_nsyms*SYMESZ);
|
||||
for (i = 0, ext_sym = coff_symtab; i < nb_syms; i++, ext_sym++) {
|
||||
for(i=0;i<8;i++)
|
||||
@ -757,8 +757,8 @@ int load_object(const char *filename)
|
||||
|
||||
|
||||
n_strtab = load_data(fd, (fhdr.f_symptr + fhdr.f_nsyms*SYMESZ), STRTAB_SIZE);
|
||||
strtab = load_data(fd, (fhdr.f_symptr + fhdr.f_nsyms*SYMESZ), *n_strtab);
|
||||
|
||||
strtab = load_data(fd, (fhdr.f_symptr + fhdr.f_nsyms*SYMESZ), *n_strtab);
|
||||
|
||||
nb_syms = fhdr.f_nsyms;
|
||||
|
||||
for (i = 0, ext_sym = coff_symtab; i < nb_syms; i++, ext_sym++) {
|
||||
@ -805,12 +805,12 @@ int load_object(const char *filename)
|
||||
} else {
|
||||
sym->st_size = 0;
|
||||
}
|
||||
|
||||
|
||||
sym->st_type = ext_sym->e_type;
|
||||
sym->st_shndx = ext_sym->e_scnum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* find text relocations, if any */
|
||||
sec = &shdr[coff_text_shndx];
|
||||
coff_relocs = load_data(fd, sec->s_relptr, sec->s_nreloc*RELSZ);
|
||||
@ -818,7 +818,7 @@ int load_object(const char *filename)
|
||||
|
||||
/* set coff relocation */
|
||||
relocs = malloc(sizeof(struct coff_rel) * nb_relocs);
|
||||
for (i = 0, ext_rel = coff_relocs, rel = relocs; i < nb_relocs;
|
||||
for (i = 0, ext_rel = coff_relocs, rel = relocs; i < nb_relocs;
|
||||
i++, ext_rel++, rel++) {
|
||||
memset(rel, 0, sizeof(*rel));
|
||||
rel->r_reloc = ext_rel;
|
||||
@ -847,7 +847,7 @@ uint8_t **sdata;
|
||||
|
||||
/* relocs */
|
||||
struct relocation_info *relocs;
|
||||
|
||||
|
||||
/* symbols */
|
||||
EXE_SYM *symtab;
|
||||
struct nlist *symtab_std;
|
||||
@ -867,10 +867,10 @@ static inline char *find_str_by_index(int index)
|
||||
static char *get_sym_name(EXE_SYM *sym)
|
||||
{
|
||||
char *name = find_str_by_index(sym->n_un.n_strx);
|
||||
|
||||
|
||||
if ( sym->n_type & N_STAB ) /* Debug symbols are ignored */
|
||||
return "debug";
|
||||
|
||||
|
||||
if(!name)
|
||||
return name;
|
||||
if(name[0]=='_')
|
||||
@ -880,7 +880,7 @@ static char *get_sym_name(EXE_SYM *sym)
|
||||
}
|
||||
|
||||
/* find a section index given its segname, sectname */
|
||||
static int find_mach_sec_index(struct section *section_hdr, int shnum, const char *segname,
|
||||
static int find_mach_sec_index(struct section *section_hdr, int shnum, const char *segname,
|
||||
const char *sectname)
|
||||
{
|
||||
int i;
|
||||
@ -896,7 +896,7 @@ static int find_mach_sec_index(struct section *section_hdr, int shnum, const cha
|
||||
}
|
||||
|
||||
/* find a section header given its segname, sectname */
|
||||
struct section *find_mach_sec_hdr(struct section *section_hdr, int shnum, const char *segname,
|
||||
struct section *find_mach_sec_hdr(struct section *section_hdr, int shnum, const char *segname,
|
||||
const char *sectname)
|
||||
{
|
||||
int index = find_mach_sec_index(section_hdr, shnum, segname, sectname);
|
||||
@ -909,7 +909,7 @@ struct section *find_mach_sec_hdr(struct section *section_hdr, int shnum, const
|
||||
static inline void fetch_next_pair_value(struct relocation_info * rel, unsigned int *value)
|
||||
{
|
||||
struct scattered_relocation_info * scarel;
|
||||
|
||||
|
||||
if(R_SCATTERED & rel->r_address) {
|
||||
scarel = (struct scattered_relocation_info*)rel;
|
||||
if(scarel->r_type != PPC_RELOC_PAIR)
|
||||
@ -926,7 +926,7 @@ static inline void fetch_next_pair_value(struct relocation_info * rel, unsigned
|
||||
static const char * find_sym_with_value_and_sec_number( int value, int sectnum, int * offset )
|
||||
{
|
||||
int i, ret = -1;
|
||||
|
||||
|
||||
for( i = 0 ; i < nb_syms; i++ )
|
||||
{
|
||||
if( !(symtab[i].n_type & N_STAB) && (symtab[i].n_type & N_SECT) &&
|
||||
@ -945,35 +945,35 @@ static const char * find_sym_with_value_and_sec_number( int value, int sectnum,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Find symbol name given a (virtual) address, and a section which is of type
|
||||
/*
|
||||
* Find symbol name given a (virtual) address, and a section which is of type
|
||||
* S_NON_LAZY_SYMBOL_POINTERS or S_LAZY_SYMBOL_POINTERS or S_SYMBOL_STUBS
|
||||
*/
|
||||
static const char * find_reloc_name_in_sec_ptr(int address, struct section * sec_hdr)
|
||||
{
|
||||
unsigned int tocindex, symindex, size;
|
||||
const char *name = 0;
|
||||
|
||||
|
||||
/* Sanity check */
|
||||
if(!( address >= sec_hdr->addr && address < (sec_hdr->addr + sec_hdr->size) ) )
|
||||
return (char*)0;
|
||||
|
||||
|
||||
if( sec_hdr->flags & S_SYMBOL_STUBS ){
|
||||
size = sec_hdr->reserved2;
|
||||
if(size == 0)
|
||||
error("size = 0");
|
||||
|
||||
|
||||
}
|
||||
else if( sec_hdr->flags & S_LAZY_SYMBOL_POINTERS ||
|
||||
sec_hdr->flags & S_NON_LAZY_SYMBOL_POINTERS)
|
||||
size = sizeof(unsigned long);
|
||||
else
|
||||
return 0;
|
||||
|
||||
|
||||
/* Compute our index in toc */
|
||||
tocindex = (address - sec_hdr->addr)/size;
|
||||
symindex = tocdylib[sec_hdr->reserved1 + tocindex];
|
||||
|
||||
|
||||
name = get_sym_name(&symtab[symindex]);
|
||||
|
||||
return name;
|
||||
@ -998,24 +998,24 @@ static const char * get_reloc_name(EXE_RELOC * rel, int * sslide)
|
||||
int sectnum = rel->r_symbolnum;
|
||||
int sectoffset;
|
||||
int other_half=0;
|
||||
|
||||
|
||||
/* init the slide value */
|
||||
*sslide = 0;
|
||||
|
||||
|
||||
if(R_SCATTERED & rel->r_address)
|
||||
return (char *)find_reloc_name_given_its_address(sca_rel->r_value);
|
||||
|
||||
if(rel->r_extern)
|
||||
{
|
||||
/* ignore debug sym */
|
||||
if ( symtab[rel->r_symbolnum].n_type & N_STAB )
|
||||
if ( symtab[rel->r_symbolnum].n_type & N_STAB )
|
||||
return 0;
|
||||
return get_sym_name(&symtab[rel->r_symbolnum]);
|
||||
}
|
||||
|
||||
/* Intruction contains an offset to the symbols pointed to, in the rel->r_symbolnum section */
|
||||
sectoffset = *(uint32_t *)(text + rel->r_address) & 0xffff;
|
||||
|
||||
|
||||
if(sectnum==0xffffff)
|
||||
return 0;
|
||||
|
||||
@ -1041,14 +1041,14 @@ static const char * get_reloc_name(EXE_RELOC * rel, int * sslide)
|
||||
|
||||
if(rel->r_pcrel)
|
||||
sectoffset += rel->r_address;
|
||||
|
||||
|
||||
if (rel->r_type == PPC_RELOC_BR24)
|
||||
name = (char *)find_reloc_name_in_sec_ptr((int)sectoffset, §ion_hdr[sectnum-1]);
|
||||
|
||||
/* search it in the full symbol list, if not found */
|
||||
if(!name)
|
||||
name = (char *)find_sym_with_value_and_sec_number(sectoffset, sectnum, sslide);
|
||||
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@ -1080,11 +1080,11 @@ int load_object(const char *filename)
|
||||
unsigned int i, j;
|
||||
EXE_SYM *sym;
|
||||
struct nlist *syment;
|
||||
|
||||
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd < 0)
|
||||
if (fd < 0)
|
||||
error("can't open file '%s'", filename);
|
||||
|
||||
|
||||
/* Read Mach header. */
|
||||
if (read(fd, &mach_hdr, sizeof (mach_hdr)) != sizeof (mach_hdr))
|
||||
error("unable to read file header");
|
||||
@ -1093,13 +1093,13 @@ int load_object(const char *filename)
|
||||
if (!check_mach_header(mach_hdr)) {
|
||||
error("bad Mach header");
|
||||
}
|
||||
|
||||
|
||||
if (mach_hdr.cputype != CPU_TYPE_POWERPC)
|
||||
error("Unsupported CPU");
|
||||
|
||||
|
||||
if (mach_hdr.filetype != MH_OBJECT)
|
||||
error("Unsupported Mach Object");
|
||||
|
||||
|
||||
/* read segment headers */
|
||||
for(i=0, j=sizeof(mach_hdr); i<mach_hdr.ncmds ; i++)
|
||||
{
|
||||
@ -1143,26 +1143,26 @@ int load_object(const char *filename)
|
||||
/* read all section data */
|
||||
sdata = (uint8_t **)malloc(sizeof(void *) * segment->nsects);
|
||||
memset(sdata, 0, sizeof(void *) * segment->nsects);
|
||||
|
||||
|
||||
/* Load the data in section data */
|
||||
for(i = 0; i < segment->nsects; i++) {
|
||||
sdata[i] = load_data(fd, section_hdr[i].offset, section_hdr[i].size);
|
||||
}
|
||||
|
||||
|
||||
/* text section */
|
||||
text_sec_hdr = find_mach_sec_hdr(section_hdr, segment->nsects, SEG_TEXT, SECT_TEXT);
|
||||
i = find_mach_sec_index(section_hdr, segment->nsects, SEG_TEXT, SECT_TEXT);
|
||||
if (i == -1 || !text_sec_hdr)
|
||||
error("could not find __TEXT,__text section");
|
||||
text = sdata[i];
|
||||
|
||||
|
||||
/* Make sure dysym was loaded */
|
||||
if(!(int)dysymtabcmd)
|
||||
error("could not find __DYSYMTAB segment");
|
||||
|
||||
|
||||
/* read the table of content of the indirect sym */
|
||||
tocdylib = load_data( fd, dysymtabcmd->indirectsymoff, dysymtabcmd->nindirectsyms * sizeof(uint32_t) );
|
||||
|
||||
|
||||
/* Make sure symtab was loaded */
|
||||
if(!(int)symtabcmd)
|
||||
error("could not find __SYMTAB segment");
|
||||
@ -1170,20 +1170,20 @@ int load_object(const char *filename)
|
||||
|
||||
symtab_std = load_data(fd, symtabcmd->symoff, symtabcmd->nsyms * sizeof(struct nlist));
|
||||
strtab = load_data(fd, symtabcmd->stroff, symtabcmd->strsize);
|
||||
|
||||
|
||||
symtab = malloc(sizeof(EXE_SYM) * nb_syms);
|
||||
|
||||
|
||||
/* Now transform the symtab, to an extended version, with the sym size, and the C name */
|
||||
for(i = 0, sym = symtab, syment = symtab_std; i < nb_syms; i++, sym++, syment++) {
|
||||
struct nlist *sym_follow, *sym_next = 0;
|
||||
unsigned int j;
|
||||
memset(sym, 0, sizeof(*sym));
|
||||
|
||||
|
||||
if ( syment->n_type & N_STAB ) /* Debug symbols are skipped */
|
||||
continue;
|
||||
|
||||
|
||||
memcpy(sym, syment, sizeof(*syment));
|
||||
|
||||
|
||||
/* Find the following symbol in order to get the current symbol size */
|
||||
for(j = 0, sym_follow = symtab_std; j < nb_syms; j++, sym_follow++) {
|
||||
if ( sym_follow->n_sect != 1 || sym_follow->n_type & N_STAB || !(sym_follow->n_value > sym->st_value))
|
||||
@ -1201,7 +1201,7 @@ int load_object(const char *filename)
|
||||
else
|
||||
sym->st_size = text_sec_hdr->size - sym->st_value;
|
||||
}
|
||||
|
||||
|
||||
/* Find Reloc */
|
||||
relocs = load_data(fd, text_sec_hdr->reloff, text_sec_hdr->nreloc * sizeof(struct relocation_info));
|
||||
nb_relocs = text_sec_hdr->nreloc;
|
||||
@ -1286,9 +1286,9 @@ int arm_emit_ldr_info(const char *name, unsigned long start_offset,
|
||||
uint8_t data_allocated[1024];
|
||||
unsigned int data_index;
|
||||
int type;
|
||||
|
||||
|
||||
memset(data_allocated, 0, sizeof(data_allocated));
|
||||
|
||||
|
||||
p = p_start;
|
||||
min_offset = p_end - p_start;
|
||||
spare = 0x7fffffff;
|
||||
@ -1331,25 +1331,25 @@ int arm_emit_ldr_info(const char *name, unsigned long start_offset,
|
||||
if (spare > max_pool - offset)
|
||||
spare = max_pool - offset;
|
||||
if ((offset & 3) !=0)
|
||||
error("%s:%04x: pc offset must be 32 bit aligned",
|
||||
error("%s:%04x: pc offset must be 32 bit aligned",
|
||||
name, start_offset + p - p_start);
|
||||
if (offset < 0)
|
||||
error("%s:%04x: Embedded literal value",
|
||||
name, start_offset + p - p_start);
|
||||
pc_offset = p - p_start + offset + 8;
|
||||
if (pc_offset <= (p - p_start) ||
|
||||
if (pc_offset <= (p - p_start) ||
|
||||
pc_offset >= (p_end - p_start))
|
||||
error("%s:%04x: pc offset must point inside the function code",
|
||||
error("%s:%04x: pc offset must point inside the function code",
|
||||
name, start_offset + p - p_start);
|
||||
if (pc_offset < min_offset)
|
||||
min_offset = pc_offset;
|
||||
if (outfile) {
|
||||
/* The intruction position */
|
||||
fprintf(outfile, " arm_ldr_ptr->ptr = gen_code_ptr + %d;\n",
|
||||
fprintf(outfile, " arm_ldr_ptr->ptr = gen_code_ptr + %d;\n",
|
||||
p - p_start);
|
||||
/* The position of the constant pool data. */
|
||||
data_index = ((p_end - p_start) - pc_offset) >> 2;
|
||||
fprintf(outfile, " arm_ldr_ptr->data_ptr = arm_data_ptr - %d;\n",
|
||||
fprintf(outfile, " arm_ldr_ptr->data_ptr = arm_data_ptr - %d;\n",
|
||||
data_index);
|
||||
fprintf(outfile, " arm_ldr_ptr->type = %d;\n", type);
|
||||
fprintf(outfile, " arm_ldr_ptr++;\n");
|
||||
@ -1432,7 +1432,7 @@ int arm_emit_ldr_info(const char *name, unsigned long start_offset,
|
||||
#define MAX_ARGS 3
|
||||
|
||||
/* generate op code */
|
||||
void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
FILE *outfile, int gen_switch)
|
||||
{
|
||||
int copy_size = 0;
|
||||
@ -1478,7 +1478,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
}
|
||||
copy_size = len;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(HOST_PPC)
|
||||
{
|
||||
uint8_t *p;
|
||||
@ -1510,7 +1510,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
#endif
|
||||
if (get32((uint32_t *)p) != 0x6bfa8001)
|
||||
error("ret expected at the end of %s", name);
|
||||
copy_size = p - p_start;
|
||||
copy_size = p - p_start;
|
||||
}
|
||||
#elif defined(HOST_IA64)
|
||||
{
|
||||
@ -1611,14 +1611,14 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
} else {
|
||||
error("No save at the beginning of %s", name);
|
||||
}
|
||||
|
||||
|
||||
/* Skip a preceeding nop, if present. */
|
||||
if (p > p_start) {
|
||||
skip_insn = get32((uint32_t *)(p - 0x4));
|
||||
if (skip_insn == 0x01000000)
|
||||
p -= 4;
|
||||
}
|
||||
|
||||
|
||||
copy_size = p - p_start;
|
||||
}
|
||||
#elif defined(HOST_ARM)
|
||||
@ -1639,7 +1639,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
p_start -= 4;
|
||||
start_offset -= 4;
|
||||
}
|
||||
copy_size = arm_emit_ldr_info(name, start_offset, NULL, p_start, p_end,
|
||||
copy_size = arm_emit_ldr_info(name, start_offset, NULL, p_start, p_end,
|
||||
relocs, nb_relocs);
|
||||
}
|
||||
#elif defined(HOST_M68K)
|
||||
@ -1650,7 +1650,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
error("empty code for %s", name);
|
||||
// remove NOP's, probably added for alignment
|
||||
while ((get16((uint16_t *)p) == 0x4e71) &&
|
||||
(p>p_start))
|
||||
(p>p_start))
|
||||
p -= 2;
|
||||
if (get16((uint16_t *)p) != 0x4e75)
|
||||
error("rts expected at the end of %s", name);
|
||||
@ -1700,7 +1700,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nb_args = 0;
|
||||
while (nb_args < MAX_ARGS && args_present[nb_args])
|
||||
nb_args++;
|
||||
@ -1737,7 +1737,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
sym_name = get_rel_sym_name(rel);
|
||||
if(!sym_name)
|
||||
continue;
|
||||
if (*sym_name &&
|
||||
if (*sym_name &&
|
||||
!strstart(sym_name, "__op_param", NULL) &&
|
||||
!strstart(sym_name, "__op_jmp", NULL) &&
|
||||
!strstart(sym_name, "__op_gen_label", NULL)) {
|
||||
@ -1784,7 +1784,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
if (strstart(sym_name, "__op_label", &p)) {
|
||||
uint8_t *ptr;
|
||||
unsigned long offset;
|
||||
|
||||
|
||||
/* test if the variable refers to a label inside
|
||||
the code we are generating */
|
||||
#ifdef CONFIG_FORMAT_COFF
|
||||
@ -1816,7 +1816,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
/* try to find a matching relocation */
|
||||
reloc_shndx = find_reloc(sym->st_shndx);
|
||||
if (reloc_shndx) {
|
||||
nb_relocs1 = shdr[reloc_shndx].sh_size /
|
||||
nb_relocs1 = shdr[reloc_shndx].sh_size /
|
||||
shdr[reloc_shndx].sh_entsize;
|
||||
rel = (ELF_RELOC *)sdata[reloc_shndx];
|
||||
for(j = 0; j < nb_relocs1; j++) {
|
||||
@ -1828,7 +1828,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
if (val >= start_offset && val <= start_offset + copy_size) {
|
||||
n = strtol(p, NULL, 10);
|
||||
fprintf(outfile, " label_offsets[%d] = %ld + (gen_code_ptr - gen_code_buf);\n", n, (long)(val - start_offset));
|
||||
@ -1874,11 +1874,11 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
type = ELF32_R_TYPE(rel->r_info);
|
||||
switch(type) {
|
||||
case R_386_32:
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
reloc_offset, relname, addend);
|
||||
break;
|
||||
case R_386_PC32:
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %d) + %d;\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %d) + %d;\n",
|
||||
reloc_offset, relname, reloc_offset, addend);
|
||||
break;
|
||||
default:
|
||||
@ -1901,11 +1901,11 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
type = rel->r_type;
|
||||
switch(type) {
|
||||
case DIR32:
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
reloc_offset, relname, addend);
|
||||
break;
|
||||
case DISP32:
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %d) + %d -4;\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %d) + %d -4;\n",
|
||||
reloc_offset, relname, reloc_offset, addend);
|
||||
break;
|
||||
default:
|
||||
@ -1933,15 +1933,15 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
reloc_offset = rel->r_offset - start_offset;
|
||||
switch(type) {
|
||||
case R_X86_64_32:
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (uint32_t)%s + %d;\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (uint32_t)%s + %d;\n",
|
||||
reloc_offset, relname, addend);
|
||||
break;
|
||||
case R_X86_64_32S:
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (int32_t)%s + %d;\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (int32_t)%s + %d;\n",
|
||||
reloc_offset, relname, addend);
|
||||
break;
|
||||
case R_X86_64_PC32:
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %d) + %d;\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %d) + %d;\n",
|
||||
reloc_offset, relname, reloc_offset, addend);
|
||||
break;
|
||||
default:
|
||||
@ -1973,30 +1973,30 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
n, reloc_offset);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
get_reloc_expr(relname, sizeof(relname), sym_name);
|
||||
type = ELF32_R_TYPE(rel->r_info);
|
||||
addend = rel->r_addend;
|
||||
switch(type) {
|
||||
case R_PPC_ADDR32:
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
reloc_offset, relname, addend);
|
||||
break;
|
||||
case R_PPC_ADDR16_LO:
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = (%s + %d);\n",
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = (%s + %d);\n",
|
||||
reloc_offset, relname, addend);
|
||||
break;
|
||||
case R_PPC_ADDR16_HI:
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = (%s + %d) >> 16;\n",
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = (%s + %d) >> 16;\n",
|
||||
reloc_offset, relname, addend);
|
||||
break;
|
||||
case R_PPC_ADDR16_HA:
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = (%s + %d + 0x8000) >> 16;\n",
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = (%s + %d + 0x8000) >> 16;\n",
|
||||
reloc_offset, relname, addend);
|
||||
break;
|
||||
case R_PPC_REL24:
|
||||
/* warning: must be at 32 MB distancy */
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (*(uint32_t *)(gen_code_ptr + %d) & ~0x03fffffc) | ((%s - (long)(gen_code_ptr + %d) + %d) & 0x03fffffc);\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (*(uint32_t *)(gen_code_ptr + %d) & ~0x03fffffc) | ((%s - (long)(gen_code_ptr + %d) + %d) & 0x03fffffc);\n",
|
||||
reloc_offset, reloc_offset, relname, reloc_offset, addend);
|
||||
break;
|
||||
default:
|
||||
@ -2036,7 +2036,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
|
||||
slide = offset - start_offset;
|
||||
|
||||
if (!(offset >= start_offset && offset < start_offset + size))
|
||||
if (!(offset >= start_offset && offset < start_offset + size))
|
||||
continue; /* not in our range */
|
||||
|
||||
sym_name = get_reloc_name(rel, &sslide);
|
||||
@ -2058,7 +2058,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
continue; /* dunno how to handle without final_sym_name */
|
||||
}
|
||||
|
||||
get_reloc_expr(final_sym_name, sizeof(final_sym_name),
|
||||
get_reloc_expr(final_sym_name, sizeof(final_sym_name),
|
||||
sym_name);
|
||||
switch(type) {
|
||||
case PPC_RELOC_BR24:
|
||||
@ -2074,15 +2074,15 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
}
|
||||
break;
|
||||
case PPC_RELOC_HI16:
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d + 2) = (%s + %d) >> 16;\n",
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d + 2) = (%s + %d) >> 16;\n",
|
||||
slide, final_sym_name, sslide);
|
||||
break;
|
||||
case PPC_RELOC_LO16:
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d + 2) = (%s + %d);\n",
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d + 2) = (%s + %d);\n",
|
||||
slide, final_sym_name, sslide);
|
||||
break;
|
||||
case PPC_RELOC_HA16:
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d + 2) = (%s + %d + 0x8000) >> 16;\n",
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d + 2) = (%s + %d + 0x8000) >> 16;\n",
|
||||
slide, final_sym_name, sslide);
|
||||
break;
|
||||
default:
|
||||
@ -2109,15 +2109,15 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
reloc_offset = rel->r_offset - start_offset;
|
||||
switch(type) {
|
||||
case R_390_32:
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
reloc_offset, relname, addend);
|
||||
break;
|
||||
case R_390_16:
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
reloc_offset, relname, addend);
|
||||
break;
|
||||
case R_390_8:
|
||||
fprintf(outfile, " *(uint8_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
fprintf(outfile, " *(uint8_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
reloc_offset, relname, addend);
|
||||
break;
|
||||
default:
|
||||
@ -2273,7 +2273,7 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
reloc_offset = rel->r_offset - start_offset;
|
||||
switch(type) {
|
||||
case R_SPARC_32:
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
reloc_offset, relname, addend);
|
||||
break;
|
||||
case R_SPARC_HI22:
|
||||
@ -2470,13 +2470,13 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
reloc_offset = rel->r_offset - start_offset;
|
||||
switch(type) {
|
||||
case R_ARM_ABS32:
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %d;\n",
|
||||
reloc_offset, relname, addend);
|
||||
break;
|
||||
case R_ARM_PC24:
|
||||
case R_ARM_JUMP24:
|
||||
case R_ARM_CALL:
|
||||
fprintf(outfile, " arm_reloc_pc24((uint32_t *)(gen_code_ptr + %d), 0x%x, %s);\n",
|
||||
fprintf(outfile, " arm_reloc_pc24((uint32_t *)(gen_code_ptr + %d), 0x%x, %s);\n",
|
||||
reloc_offset, addend, relname);
|
||||
break;
|
||||
default:
|
||||
@ -2504,12 +2504,12 @@ void gen_code(const char *name, host_ulong offset, host_ulong size,
|
||||
switch(type) {
|
||||
case R_68K_32:
|
||||
fprintf(outfile, " /* R_68K_32 RELOC, offset %x */\n", rel->r_offset) ;
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %#x;\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s + %#x;\n",
|
||||
reloc_offset, relname, addend );
|
||||
break;
|
||||
case R_68K_PC32:
|
||||
fprintf(outfile, " /* R_68K_PC32 RELOC, offset %x */\n", rel->r_offset);
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %#x) + %#x;\n",
|
||||
fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = %s - (long)(gen_code_ptr + %#x) + %#x;\n",
|
||||
reloc_offset, relname, reloc_offset, /*sym->st_value+*/ addend);
|
||||
break;
|
||||
default:
|
||||
@ -2652,7 +2652,7 @@ int gen_file(FILE *outfile, int out_type)
|
||||
gen_code(name, sym->st_value, sym->st_size, outfile, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
/* generate big code generation switch */
|
||||
|
||||
@ -2695,7 +2695,7 @@ fprintf(outfile,
|
||||
eliminating the neeed to jump around the pool.
|
||||
|
||||
We currently generate:
|
||||
|
||||
|
||||
[ For this example we assume merging would move op1_pool out of range.
|
||||
In practice we should be able to combine many ops before the offset
|
||||
limits are reached. ]
|
||||
@ -2782,7 +2782,7 @@ fprintf(outfile,
|
||||
" opc_ptr = opc_buf;\n"
|
||||
" opparam_ptr = opparam_buf;\n");
|
||||
|
||||
/* Generate prologue, if needed. */
|
||||
/* Generate prologue, if needed. */
|
||||
|
||||
fprintf(outfile,
|
||||
" for(;;) {\n");
|
||||
@ -2808,7 +2808,7 @@ fprintf(outfile,
|
||||
name = get_sym_name(sym);
|
||||
if (strstart(name, OP_PREFIX, NULL)) {
|
||||
#if 0
|
||||
printf("%4d: %s pos=0x%08x len=%d\n",
|
||||
printf("%4d: %s pos=0x%08x len=%d\n",
|
||||
i, name, sym->st_value, sym->st_size);
|
||||
#endif
|
||||
#if defined(CONFIG_FORMAT_ELF) || defined(CONFIG_FORMAT_COFF)
|
||||
@ -2850,7 +2850,7 @@ fprintf(outfile,
|
||||
"plt_target, plt_offset);\n }\n");
|
||||
#endif
|
||||
|
||||
/* generate some code patching */
|
||||
/* generate some code patching */
|
||||
#ifdef HOST_ARM
|
||||
fprintf(outfile,
|
||||
"if (arm_data_ptr != arm_data_table + ARM_LDR_TABLE_SIZE)\n"
|
||||
|
18
dyngen.h
18
dyngen.h
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* dyngen helpers
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -51,7 +51,7 @@ static void inline flush_icache_range(unsigned long start, unsigned long stop)
|
||||
|
||||
start &= ~(MIN_CACHE_LINE_SIZE - 1);
|
||||
stop = (stop + MIN_CACHE_LINE_SIZE - 1) & ~(MIN_CACHE_LINE_SIZE - 1);
|
||||
|
||||
|
||||
for (p = start; p < stop; p += MIN_CACHE_LINE_SIZE) {
|
||||
asm volatile ("dcbst 0,%0" : : "r"(p) : "memory");
|
||||
}
|
||||
@ -148,8 +148,8 @@ static inline void arm_reloc_pc24(uint32_t *ptr, uint32_t insn, int val)
|
||||
}
|
||||
|
||||
static uint8_t *arm_flush_ldr(uint8_t *gen_code_ptr,
|
||||
LDREntry *ldr_start, LDREntry *ldr_end,
|
||||
uint32_t *data_start, uint32_t *data_end,
|
||||
LDREntry *ldr_start, LDREntry *ldr_end,
|
||||
uint32_t *data_start, uint32_t *data_end,
|
||||
int gen_jmp)
|
||||
{
|
||||
LDREntry *le;
|
||||
@ -158,7 +158,7 @@ static uint8_t *arm_flush_ldr(uint8_t *gen_code_ptr,
|
||||
uint8_t *data_ptr;
|
||||
uint32_t insn;
|
||||
uint32_t mask;
|
||||
|
||||
|
||||
data_size = (data_end - data_start) << 2;
|
||||
|
||||
if (gen_jmp) {
|
||||
@ -169,17 +169,17 @@ static uint8_t *arm_flush_ldr(uint8_t *gen_code_ptr,
|
||||
arm_reloc_pc24((uint32_t *)gen_code_ptr, 0xeafffffe, target);
|
||||
gen_code_ptr += 4;
|
||||
}
|
||||
|
||||
|
||||
/* copy the data */
|
||||
data_ptr = gen_code_ptr;
|
||||
memcpy(gen_code_ptr, data_start, data_size);
|
||||
gen_code_ptr += data_size;
|
||||
|
||||
|
||||
/* patch the ldr to point to the data */
|
||||
for(le = ldr_start; le < ldr_end; le++) {
|
||||
ptr = (uint32_t *)le->ptr;
|
||||
offset = ((unsigned long)(le->data_ptr) - (unsigned long)data_start) +
|
||||
(unsigned long)data_ptr -
|
||||
offset = ((unsigned long)(le->data_ptr) - (unsigned long)data_start) +
|
||||
(unsigned long)data_ptr -
|
||||
(unsigned long)ptr - 8;
|
||||
if (offset < 0) {
|
||||
fprintf(stderr, "Negative constant pool offset\n");
|
||||
|
2
elf.h
2
elf.h
@ -1045,7 +1045,7 @@ typedef struct elf64_phdr {
|
||||
#define SHN_COMMON 0xfff2
|
||||
#define SHN_HIRESERVE 0xffff
|
||||
#define SHN_MIPS_ACCOMON 0xff00
|
||||
|
||||
|
||||
typedef struct elf32_shdr {
|
||||
Elf32_Word sh_name;
|
||||
Elf32_Word sh_type;
|
||||
|
10
elf_ops.h
10
elf_ops.h
@ -49,7 +49,7 @@ static void glue(bswap_sym, SZ)(struct elf_sym *sym)
|
||||
bswap16s(&sym->st_shndx);
|
||||
}
|
||||
|
||||
static struct elf_shdr *glue(find_section, SZ)(struct elf_shdr *shdr_table,
|
||||
static struct elf_shdr *glue(find_section, SZ)(struct elf_shdr *shdr_table,
|
||||
int n, int type)
|
||||
{
|
||||
int i;
|
||||
@ -71,17 +71,17 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab)
|
||||
int nsyms, i;
|
||||
char *str = NULL;
|
||||
|
||||
shdr_table = load_at(fd, ehdr->e_shoff,
|
||||
shdr_table = load_at(fd, ehdr->e_shoff,
|
||||
sizeof(struct elf_shdr) * ehdr->e_shnum);
|
||||
if (!shdr_table)
|
||||
return -1;
|
||||
|
||||
|
||||
if (must_swab) {
|
||||
for (i = 0; i < ehdr->e_shnum; i++) {
|
||||
glue(bswap_shdr, SZ)(shdr_table + i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
symtab = glue(find_section, SZ)(shdr_table, ehdr->e_shnum, SHT_SYMTAB);
|
||||
if (!symtab)
|
||||
goto fail;
|
||||
@ -176,7 +176,7 @@ int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend,
|
||||
glue(bswap_phdr, SZ)(ph);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
total_size = 0;
|
||||
for(i = 0; i < ehdr.e_phnum; i++) {
|
||||
ph = &phdr[i];
|
||||
|
54
exec-all.h
54
exec-all.h
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* internal execution defines for qemu
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -68,7 +68,7 @@ typedef void (GenOpFunc)(void);
|
||||
typedef void (GenOpFunc1)(long);
|
||||
typedef void (GenOpFunc2)(long, long);
|
||||
typedef void (GenOpFunc3)(long, long, long);
|
||||
|
||||
|
||||
#if defined(TARGET_I386)
|
||||
|
||||
void optimize_flags_init(void);
|
||||
@ -86,27 +86,27 @@ int gen_intermediate_code_pc(CPUState *env, struct TranslationBlock *tb);
|
||||
void dump_ops(const uint16_t *opc_buf, const uint32_t *opparam_buf);
|
||||
int cpu_gen_code(CPUState *env, struct TranslationBlock *tb,
|
||||
int max_code_size, int *gen_code_size_ptr);
|
||||
int cpu_restore_state(struct TranslationBlock *tb,
|
||||
int cpu_restore_state(struct TranslationBlock *tb,
|
||||
CPUState *env, unsigned long searched_pc,
|
||||
void *puc);
|
||||
int cpu_gen_code_copy(CPUState *env, struct TranslationBlock *tb,
|
||||
int max_code_size, int *gen_code_size_ptr);
|
||||
int cpu_restore_state_copy(struct TranslationBlock *tb,
|
||||
int cpu_restore_state_copy(struct TranslationBlock *tb,
|
||||
CPUState *env, unsigned long searched_pc,
|
||||
void *puc);
|
||||
void cpu_resume_from_signal(CPUState *env1, void *puc);
|
||||
void cpu_exec_init(CPUState *env);
|
||||
int page_unprotect(target_ulong address, unsigned long pc, void *puc);
|
||||
void tb_invalidate_phys_page_range(target_ulong start, target_ulong end,
|
||||
void tb_invalidate_phys_page_range(target_ulong start, target_ulong end,
|
||||
int is_cpu_write_access);
|
||||
void tb_invalidate_page_range(target_ulong start, target_ulong end);
|
||||
void tlb_flush_page(CPUState *env, target_ulong addr);
|
||||
void tlb_flush(CPUState *env, int flush_global);
|
||||
int tlb_set_page_exec(CPUState *env, target_ulong vaddr,
|
||||
target_phys_addr_t paddr, int prot,
|
||||
int tlb_set_page_exec(CPUState *env, target_ulong vaddr,
|
||||
target_phys_addr_t paddr, int prot,
|
||||
int is_user, int is_softmmu);
|
||||
static inline int tlb_set_page(CPUState *env, target_ulong vaddr,
|
||||
target_phys_addr_t paddr, int prot,
|
||||
static inline int tlb_set_page(CPUState *env, target_ulong vaddr,
|
||||
target_phys_addr_t paddr, int prot,
|
||||
int is_user, int is_softmmu)
|
||||
{
|
||||
if (prot & PAGE_READ)
|
||||
@ -156,7 +156,7 @@ static inline int tlb_set_page(CPUState *env, target_ulong vaddr,
|
||||
|
||||
#define CODE_GEN_MAX_BLOCKS (CODE_GEN_BUFFER_SIZE / CODE_GEN_AVG_BLOCK_SIZE)
|
||||
|
||||
#if defined(__powerpc__)
|
||||
#if defined(__powerpc__)
|
||||
#define USE_DIRECT_JUMP
|
||||
#endif
|
||||
#if defined(__i386__) && !defined(_WIN32)
|
||||
@ -177,11 +177,11 @@ typedef struct TranslationBlock {
|
||||
|
||||
uint8_t *tc_ptr; /* pointer to the translated code */
|
||||
/* next matching tb for physical address. */
|
||||
struct TranslationBlock *phys_hash_next;
|
||||
struct TranslationBlock *phys_hash_next;
|
||||
/* first and second physical page containing code. The lower bit
|
||||
of the pointer tells the index in page_next[] */
|
||||
struct TranslationBlock *page_next[2];
|
||||
target_ulong page_addr[2];
|
||||
struct TranslationBlock *page_next[2];
|
||||
target_ulong page_addr[2];
|
||||
|
||||
/* the following data are used to directly call another TB from
|
||||
the code of this one. */
|
||||
@ -195,7 +195,7 @@ typedef struct TranslationBlock {
|
||||
the two least significant bits of the pointers to tell what is
|
||||
the next pointer: 0 = jmp_next[0], 1 = jmp_next[1], 2 =
|
||||
jmp_first */
|
||||
struct TranslationBlock *jmp_next[2];
|
||||
struct TranslationBlock *jmp_next[2];
|
||||
struct TranslationBlock *jmp_first;
|
||||
} TranslationBlock;
|
||||
|
||||
@ -221,7 +221,7 @@ static inline unsigned int tb_phys_hash_func(unsigned long pc)
|
||||
|
||||
TranslationBlock *tb_alloc(target_ulong pc);
|
||||
void tb_flush(CPUState *env);
|
||||
void tb_link_phys(TranslationBlock *tb,
|
||||
void tb_link_phys(TranslationBlock *tb,
|
||||
target_ulong phys_pc, target_ulong phys_page2);
|
||||
|
||||
extern TranslationBlock *tb_phys_hash[CODE_GEN_PHYS_HASH_SIZE];
|
||||
@ -257,7 +257,7 @@ static inline void tb_set_jmp_target1(unsigned long jmp_addr, unsigned long addr
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void tb_set_jmp_target(TranslationBlock *tb,
|
||||
static inline void tb_set_jmp_target(TranslationBlock *tb,
|
||||
int n, unsigned long addr)
|
||||
{
|
||||
unsigned long offset;
|
||||
@ -272,7 +272,7 @@ static inline void tb_set_jmp_target(TranslationBlock *tb,
|
||||
#else
|
||||
|
||||
/* set the jump target */
|
||||
static inline void tb_set_jmp_target(TranslationBlock *tb,
|
||||
static inline void tb_set_jmp_target(TranslationBlock *tb,
|
||||
int n, unsigned long addr)
|
||||
{
|
||||
tb->tb_next[n] = addr;
|
||||
@ -280,14 +280,14 @@ static inline void tb_set_jmp_target(TranslationBlock *tb,
|
||||
|
||||
#endif
|
||||
|
||||
static inline void tb_add_jump(TranslationBlock *tb, int n,
|
||||
static inline void tb_add_jump(TranslationBlock *tb, int n,
|
||||
TranslationBlock *tb_next)
|
||||
{
|
||||
/* NOTE: this test is only needed for thread safety */
|
||||
if (!tb->jmp_next[n]) {
|
||||
/* patch the native jump address */
|
||||
tb_set_jmp_target(tb, n, (unsigned long)tb_next->tc_ptr);
|
||||
|
||||
|
||||
/* add in TB jmp circular list */
|
||||
tb->jmp_next[n] = tb_next->jmp_first;
|
||||
tb_next->jmp_first = (TranslationBlock *)((long)(tb) | (n));
|
||||
@ -398,7 +398,7 @@ static inline int testandset (int *p)
|
||||
static inline int testandset (int *p)
|
||||
{
|
||||
long int readval = 0;
|
||||
|
||||
|
||||
__asm__ __volatile__ ("lock; cmpxchgl %2, %0"
|
||||
: "+m" (*p), "+a" (readval)
|
||||
: "r" (1)
|
||||
@ -409,7 +409,7 @@ static inline int testandset (int *p)
|
||||
static inline int testandset (int *p)
|
||||
{
|
||||
long int readval = 0;
|
||||
|
||||
|
||||
__asm__ __volatile__ ("lock; cmpxchgl %2, %0"
|
||||
: "+m" (*p), "+a" (readval)
|
||||
: "r" (1)
|
||||
@ -424,7 +424,7 @@ static inline int testandset (int *p)
|
||||
__asm__ __volatile__ ("0: cs %0,%1,0(%2)\n"
|
||||
" jl 0b"
|
||||
: "=&d" (ret)
|
||||
: "r" (1), "a" (p), "0" (*p)
|
||||
: "r" (1), "a" (p), "0" (*p)
|
||||
: "cc", "memory" );
|
||||
return ret;
|
||||
}
|
||||
@ -464,7 +464,7 @@ static inline int testandset (int *spinlock)
|
||||
__asm__ __volatile__("swp %0, %1, [%2]"
|
||||
: "=r"(ret)
|
||||
: "0"(1), "r"(spinlock));
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
#elif defined(__mc68000)
|
||||
@ -549,7 +549,7 @@ extern int tb_invalidated_flag;
|
||||
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
|
||||
void tlb_fill(target_ulong addr, int is_write, int is_user,
|
||||
void tlb_fill(target_ulong addr, int is_write, int is_user,
|
||||
void *retaddr);
|
||||
|
||||
#define ACCESS_TYPE 3
|
||||
@ -607,7 +607,7 @@ static inline target_ulong get_phys_addr_code(CPUState *env, target_ulong addr)
|
||||
#else
|
||||
#error unimplemented CPU
|
||||
#endif
|
||||
if (__builtin_expect(env->tlb_table[is_user][index].addr_code !=
|
||||
if (__builtin_expect(env->tlb_table[is_user][index].addr_code !=
|
||||
(addr & TARGET_PAGE_MASK), 0)) {
|
||||
ldub_code(addr);
|
||||
}
|
||||
@ -638,11 +638,11 @@ void kqemu_record_dump(void);
|
||||
static inline int kqemu_is_ok(CPUState *env)
|
||||
{
|
||||
return(env->kqemu_enabled &&
|
||||
(env->cr[0] & CR0_PE_MASK) &&
|
||||
(env->cr[0] & CR0_PE_MASK) &&
|
||||
!(env->hflags & HF_INHIBIT_IRQ_MASK) &&
|
||||
(env->eflags & IF_MASK) &&
|
||||
!(env->eflags & VM_MASK) &&
|
||||
(env->kqemu_enabled == 2 ||
|
||||
(env->kqemu_enabled == 2 ||
|
||||
((env->hflags & HF_CPL_MASK) == 3 &&
|
||||
(env->eflags & IOPL_MASK) != IOPL_MASK)));
|
||||
}
|
||||
|
208
exec.c
208
exec.c
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* virtual page mapping and translated block handling
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -44,8 +44,8 @@
|
||||
//#define DEBUG_UNASSIGNED
|
||||
|
||||
/* make various TB consistency checks */
|
||||
//#define DEBUG_TB_CHECK
|
||||
//#define DEBUG_TLB_CHECK
|
||||
//#define DEBUG_TB_CHECK
|
||||
//#define DEBUG_TLB_CHECK
|
||||
|
||||
//#define DEBUG_IOPORT
|
||||
//#define DEBUG_SUBPAGE
|
||||
@ -95,7 +95,7 @@ static ram_addr_t phys_ram_alloc_offset = 0;
|
||||
CPUState *first_cpu;
|
||||
/* current CPU in the current thread. It is only valid inside
|
||||
cpu_exec() */
|
||||
CPUState *cpu_single_env;
|
||||
CPUState *cpu_single_env;
|
||||
|
||||
typedef struct PageDesc {
|
||||
/* list of TBs intersecting this ram page */
|
||||
@ -175,10 +175,10 @@ static void page_init(void)
|
||||
{
|
||||
SYSTEM_INFO system_info;
|
||||
DWORD old_protect;
|
||||
|
||||
|
||||
GetSystemInfo(&system_info);
|
||||
qemu_real_host_page_size = system_info.dwPageSize;
|
||||
|
||||
|
||||
VirtualProtect(code_gen_buffer, sizeof(code_gen_buffer),
|
||||
PAGE_EXECUTE_READWRITE, &old_protect);
|
||||
}
|
||||
@ -189,12 +189,12 @@ static void page_init(void)
|
||||
|
||||
start = (unsigned long)code_gen_buffer;
|
||||
start &= ~(qemu_real_host_page_size - 1);
|
||||
|
||||
|
||||
end = (unsigned long)code_gen_buffer + sizeof(code_gen_buffer);
|
||||
end += qemu_real_host_page_size - 1;
|
||||
end &= ~(qemu_real_host_page_size - 1);
|
||||
|
||||
mprotect((void *)start, end - start,
|
||||
|
||||
mprotect((void *)start, end - start,
|
||||
PROT_READ | PROT_WRITE | PROT_EXEC);
|
||||
}
|
||||
#endif
|
||||
@ -280,7 +280,7 @@ static inline PhysPageDesc *phys_page_find(target_phys_addr_t index)
|
||||
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
static void tlb_protect_code(ram_addr_t ram_addr);
|
||||
static void tlb_unprotect_code_phys(CPUState *env, ram_addr_t ram_addr,
|
||||
static void tlb_unprotect_code_phys(CPUState *env, ram_addr_t ram_addr,
|
||||
target_ulong vaddr);
|
||||
#endif
|
||||
|
||||
@ -339,13 +339,13 @@ void tb_flush(CPUState *env1)
|
||||
{
|
||||
CPUState *env;
|
||||
#if defined(DEBUG_FLUSH)
|
||||
printf("qemu: flush code_size=%d nb_tbs=%d avg_tb_size=%d\n",
|
||||
code_gen_ptr - code_gen_buffer,
|
||||
nb_tbs,
|
||||
printf("qemu: flush code_size=%d nb_tbs=%d avg_tb_size=%d\n",
|
||||
code_gen_ptr - code_gen_buffer,
|
||||
nb_tbs,
|
||||
nb_tbs > 0 ? (code_gen_ptr - code_gen_buffer) / nb_tbs : 0);
|
||||
#endif
|
||||
nb_tbs = 0;
|
||||
|
||||
|
||||
for(env = first_cpu; env != NULL; env = env->next_cpu) {
|
||||
memset (env->tb_jmp_cache, 0, TB_JMP_CACHE_SIZE * sizeof (void *));
|
||||
}
|
||||
@ -382,7 +382,7 @@ static void tb_page_check(void)
|
||||
{
|
||||
TranslationBlock *tb;
|
||||
int i, flags1, flags2;
|
||||
|
||||
|
||||
for(i = 0;i < CODE_GEN_PHYS_HASH_SIZE; i++) {
|
||||
for(tb = tb_phys_hash[i]; tb != NULL; tb = tb->phys_hash_next) {
|
||||
flags1 = page_get_flags(tb->pc);
|
||||
@ -491,11 +491,11 @@ static inline void tb_phys_invalidate(TranslationBlock *tb, unsigned int page_ad
|
||||
unsigned int h, n1;
|
||||
target_ulong phys_pc;
|
||||
TranslationBlock *tb1, *tb2;
|
||||
|
||||
|
||||
/* remove the TB from the hash list */
|
||||
phys_pc = tb->page_addr[0] + (tb->pc & ~TARGET_PAGE_MASK);
|
||||
h = tb_phys_hash_func(phys_pc);
|
||||
tb_remove(&tb_phys_hash[h], tb,
|
||||
tb_remove(&tb_phys_hash[h], tb,
|
||||
offsetof(TranslationBlock, phys_hash_next));
|
||||
|
||||
/* remove the TB from the page list */
|
||||
@ -571,7 +571,7 @@ static void build_page_bitmap(PageDesc *p)
|
||||
{
|
||||
int n, tb_start, tb_end;
|
||||
TranslationBlock *tb;
|
||||
|
||||
|
||||
p->code_bitmap = qemu_malloc(TARGET_PAGE_SIZE / 8);
|
||||
if (!p->code_bitmap)
|
||||
return;
|
||||
@ -600,7 +600,7 @@ static void build_page_bitmap(PageDesc *p)
|
||||
|
||||
#ifdef TARGET_HAS_PRECISE_SMC
|
||||
|
||||
static void tb_gen_code(CPUState *env,
|
||||
static void tb_gen_code(CPUState *env,
|
||||
target_ulong pc, target_ulong cs_base, int flags,
|
||||
int cflags)
|
||||
{
|
||||
@ -624,7 +624,7 @@ static void tb_gen_code(CPUState *env,
|
||||
tb->cflags = cflags;
|
||||
cpu_gen_code(env, tb, CODE_GEN_MAX_SIZE, &code_gen_size);
|
||||
code_gen_ptr = (void *)(((unsigned long)code_gen_ptr + code_gen_size + CODE_GEN_ALIGN - 1) & ~(CODE_GEN_ALIGN - 1));
|
||||
|
||||
|
||||
/* check next page if needed */
|
||||
virt_page2 = (pc + tb->size - 1) & TARGET_PAGE_MASK;
|
||||
phys_page2 = -1;
|
||||
@ -634,13 +634,13 @@ static void tb_gen_code(CPUState *env,
|
||||
tb_link_phys(tb, phys_pc, phys_page2);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* invalidate all TBs which intersect with the target physical page
|
||||
starting in range [start;end[. NOTE: start and end must refer to
|
||||
the same physical page. 'is_cpu_write_access' should be true if called
|
||||
from a real cpu write access: the virtual CPU will exit the current
|
||||
TB if code is modified inside this TB. */
|
||||
void tb_invalidate_phys_page_range(target_ulong start, target_ulong end,
|
||||
void tb_invalidate_phys_page_range(target_ulong start, target_ulong end,
|
||||
int is_cpu_write_access)
|
||||
{
|
||||
int n, current_tb_modified, current_tb_not_found, current_flags;
|
||||
@ -651,9 +651,9 @@ void tb_invalidate_phys_page_range(target_ulong start, target_ulong end,
|
||||
target_ulong current_pc, current_cs_base;
|
||||
|
||||
p = page_find(start >> TARGET_PAGE_BITS);
|
||||
if (!p)
|
||||
if (!p)
|
||||
return;
|
||||
if (!p->code_bitmap &&
|
||||
if (!p->code_bitmap &&
|
||||
++p->code_write_count >= SMC_BITMAP_USE_THRESHOLD &&
|
||||
is_cpu_write_access) {
|
||||
/* build code bitmap */
|
||||
@ -700,9 +700,9 @@ void tb_invalidate_phys_page_range(target_ulong start, target_ulong end,
|
||||
that the modification is after the current PC, but it
|
||||
would require a specialized function to partially
|
||||
restore the CPU state */
|
||||
|
||||
|
||||
current_tb_modified = 1;
|
||||
cpu_restore_state(current_tb, env,
|
||||
cpu_restore_state(current_tb, env,
|
||||
env->mem_write_pc, NULL);
|
||||
#if defined(TARGET_I386)
|
||||
current_flags = env->hflags;
|
||||
@ -745,7 +745,7 @@ void tb_invalidate_phys_page_range(target_ulong start, target_ulong end,
|
||||
modifying the memory. It will ensure that it cannot modify
|
||||
itself */
|
||||
env->current_tb = NULL;
|
||||
tb_gen_code(env, current_pc, current_cs_base, current_flags,
|
||||
tb_gen_code(env, current_pc, current_cs_base, current_flags,
|
||||
CF_SINGLE_INSN);
|
||||
cpu_resume_from_signal(env, NULL);
|
||||
}
|
||||
@ -760,15 +760,15 @@ static inline void tb_invalidate_phys_page_fast(target_ulong start, int len)
|
||||
#if 0
|
||||
if (1) {
|
||||
if (loglevel) {
|
||||
fprintf(logfile, "modifying code at 0x%x size=%d EIP=%x PC=%08x\n",
|
||||
cpu_single_env->mem_write_vaddr, len,
|
||||
cpu_single_env->eip,
|
||||
fprintf(logfile, "modifying code at 0x%x size=%d EIP=%x PC=%08x\n",
|
||||
cpu_single_env->mem_write_vaddr, len,
|
||||
cpu_single_env->eip,
|
||||
cpu_single_env->eip + (long)cpu_single_env->segs[R_CS].base);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
p = page_find(start >> TARGET_PAGE_BITS);
|
||||
if (!p)
|
||||
if (!p)
|
||||
return;
|
||||
if (p->code_bitmap) {
|
||||
offset = start & ~TARGET_PAGE_MASK;
|
||||
@ -782,7 +782,7 @@ static inline void tb_invalidate_phys_page_fast(target_ulong start, int len)
|
||||
}
|
||||
|
||||
#if !defined(CONFIG_SOFTMMU)
|
||||
static void tb_invalidate_phys_page(target_ulong addr,
|
||||
static void tb_invalidate_phys_page(target_ulong addr,
|
||||
unsigned long pc, void *puc)
|
||||
{
|
||||
int n, current_flags, current_tb_modified;
|
||||
@ -795,7 +795,7 @@ static void tb_invalidate_phys_page(target_ulong addr,
|
||||
|
||||
addr &= TARGET_PAGE_MASK;
|
||||
p = page_find(addr >> TARGET_PAGE_BITS);
|
||||
if (!p)
|
||||
if (!p)
|
||||
return;
|
||||
tb = p->first_tb;
|
||||
current_tb_modified = 0;
|
||||
@ -819,7 +819,7 @@ static void tb_invalidate_phys_page(target_ulong addr,
|
||||
that the modification is after the current PC, but it
|
||||
would require a specialized function to partially
|
||||
restore the CPU state */
|
||||
|
||||
|
||||
current_tb_modified = 1;
|
||||
cpu_restore_state(current_tb, env, pc, puc);
|
||||
#if defined(TARGET_I386)
|
||||
@ -842,7 +842,7 @@ static void tb_invalidate_phys_page(target_ulong addr,
|
||||
modifying the memory. It will ensure that it cannot modify
|
||||
itself */
|
||||
env->current_tb = NULL;
|
||||
tb_gen_code(env, current_pc, current_cs_base, current_flags,
|
||||
tb_gen_code(env, current_pc, current_cs_base, current_flags,
|
||||
CF_SINGLE_INSN);
|
||||
cpu_resume_from_signal(env, puc);
|
||||
}
|
||||
@ -851,7 +851,7 @@ static void tb_invalidate_phys_page(target_ulong addr,
|
||||
#endif
|
||||
|
||||
/* add the tb in the target page and protect it if necessary */
|
||||
static inline void tb_alloc_page(TranslationBlock *tb,
|
||||
static inline void tb_alloc_page(TranslationBlock *tb,
|
||||
unsigned int n, target_ulong page_addr)
|
||||
{
|
||||
PageDesc *p;
|
||||
@ -886,10 +886,10 @@ static inline void tb_alloc_page(TranslationBlock *tb,
|
||||
p2->flags &= ~PAGE_WRITE;
|
||||
page_get_flags(addr);
|
||||
}
|
||||
mprotect(g2h(page_addr), qemu_host_page_size,
|
||||
mprotect(g2h(page_addr), qemu_host_page_size,
|
||||
(prot & PAGE_BITS) & ~PAGE_WRITE);
|
||||
#ifdef DEBUG_TB_INVALIDATE
|
||||
printf("protecting code page: 0x%08lx\n",
|
||||
printf("protecting code page: 0x%08lx\n",
|
||||
page_addr);
|
||||
#endif
|
||||
}
|
||||
@ -911,7 +911,7 @@ TranslationBlock *tb_alloc(target_ulong pc)
|
||||
{
|
||||
TranslationBlock *tb;
|
||||
|
||||
if (nb_tbs >= CODE_GEN_MAX_BLOCKS ||
|
||||
if (nb_tbs >= CODE_GEN_MAX_BLOCKS ||
|
||||
(code_gen_ptr - code_gen_buffer) >= CODE_GEN_BUFFER_MAX_SIZE)
|
||||
return NULL;
|
||||
tb = &tbs[nb_tbs++];
|
||||
@ -922,7 +922,7 @@ TranslationBlock *tb_alloc(target_ulong pc)
|
||||
|
||||
/* add a new TB and link it to the physical page tables. phys_page2 is
|
||||
(-1) to indicate that only one page contains the TB. */
|
||||
void tb_link_phys(TranslationBlock *tb,
|
||||
void tb_link_phys(TranslationBlock *tb,
|
||||
target_ulong phys_pc, target_ulong phys_page2)
|
||||
{
|
||||
unsigned int h;
|
||||
@ -988,7 +988,7 @@ TranslationBlock *tb_find_pc(unsigned long tc_ptr)
|
||||
} else {
|
||||
m_min = m + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return &tbs[m_max];
|
||||
}
|
||||
|
||||
@ -1024,7 +1024,7 @@ static inline void tb_reset_jump_recursive2(TranslationBlock *tb, int n)
|
||||
}
|
||||
*ptb = tb->jmp_next[n];
|
||||
tb->jmp_next[n] = NULL;
|
||||
|
||||
|
||||
/* suppress the jump to next tb in generated code */
|
||||
tb_reset_jump(tb, n);
|
||||
|
||||
@ -1103,7 +1103,7 @@ int cpu_breakpoint_insert(CPUState *env, target_ulong pc)
|
||||
{
|
||||
#if defined(TARGET_HAS_ICE)
|
||||
int i;
|
||||
|
||||
|
||||
for(i = 0; i < env->nb_breakpoints; i++) {
|
||||
if (env->breakpoints[i] == pc)
|
||||
return 0;
|
||||
@ -1112,7 +1112,7 @@ int cpu_breakpoint_insert(CPUState *env, target_ulong pc)
|
||||
if (env->nb_breakpoints >= MAX_BREAKPOINTS)
|
||||
return -1;
|
||||
env->breakpoints[env->nb_breakpoints++] = pc;
|
||||
|
||||
|
||||
breakpoint_invalidate(env, pc);
|
||||
return 0;
|
||||
#else
|
||||
@ -1216,11 +1216,11 @@ void cpu_reset_interrupt(CPUState *env, int mask)
|
||||
}
|
||||
|
||||
CPULogItem cpu_log_items[] = {
|
||||
{ CPU_LOG_TB_OUT_ASM, "out_asm",
|
||||
{ CPU_LOG_TB_OUT_ASM, "out_asm",
|
||||
"show generated host assembly code for each compiled TB" },
|
||||
{ CPU_LOG_TB_IN_ASM, "in_asm",
|
||||
"show target assembly code for each compiled TB" },
|
||||
{ CPU_LOG_TB_OP, "op",
|
||||
{ CPU_LOG_TB_OP, "op",
|
||||
"show micro ops for each compiled TB (only usable if 'in_asm' used)" },
|
||||
#ifdef TARGET_I386
|
||||
{ CPU_LOG_TB_OP_OPT, "op_opt",
|
||||
@ -1249,7 +1249,7 @@ static int cmp1(const char *s1, int n, const char *s2)
|
||||
return 0;
|
||||
return memcmp(s1, s2, n) == 0;
|
||||
}
|
||||
|
||||
|
||||
/* takes a comma separated list of log masks. Return 0 if error. */
|
||||
int cpu_str_to_log_mask(const char *str)
|
||||
{
|
||||
@ -1365,11 +1365,11 @@ void tlb_flush(CPUState *env, int flush_global)
|
||||
|
||||
static inline void tlb_flush_entry(CPUTLBEntry *tlb_entry, target_ulong addr)
|
||||
{
|
||||
if (addr == (tlb_entry->addr_read &
|
||||
if (addr == (tlb_entry->addr_read &
|
||||
(TARGET_PAGE_MASK | TLB_INVALID_MASK)) ||
|
||||
addr == (tlb_entry->addr_write &
|
||||
addr == (tlb_entry->addr_write &
|
||||
(TARGET_PAGE_MASK | TLB_INVALID_MASK)) ||
|
||||
addr == (tlb_entry->addr_code &
|
||||
addr == (tlb_entry->addr_code &
|
||||
(TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
|
||||
tlb_entry->addr_read = -1;
|
||||
tlb_entry->addr_write = -1;
|
||||
@ -1423,20 +1423,20 @@ void tlb_flush_page(CPUState *env, target_ulong addr)
|
||||
can be detected */
|
||||
static void tlb_protect_code(ram_addr_t ram_addr)
|
||||
{
|
||||
cpu_physical_memory_reset_dirty(ram_addr,
|
||||
cpu_physical_memory_reset_dirty(ram_addr,
|
||||
ram_addr + TARGET_PAGE_SIZE,
|
||||
CODE_DIRTY_FLAG);
|
||||
}
|
||||
|
||||
/* update the TLB so that writes in physical page 'phys_addr' are no longer
|
||||
tested for self modifying code */
|
||||
static void tlb_unprotect_code_phys(CPUState *env, ram_addr_t ram_addr,
|
||||
static void tlb_unprotect_code_phys(CPUState *env, ram_addr_t ram_addr,
|
||||
target_ulong vaddr)
|
||||
{
|
||||
phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS] |= CODE_DIRTY_FLAG;
|
||||
}
|
||||
|
||||
static inline void tlb_reset_dirty_range(CPUTLBEntry *tlb_entry,
|
||||
static inline void tlb_reset_dirty_range(CPUTLBEntry *tlb_entry,
|
||||
unsigned long start, unsigned long length)
|
||||
{
|
||||
unsigned long addr;
|
||||
@ -1514,7 +1514,7 @@ void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
|
||||
p->phys_addr >= start && p->phys_addr < end &&
|
||||
(p->prot & PROT_WRITE)) {
|
||||
if (addr < MMAP_AREA_END) {
|
||||
mprotect((void *)addr, TARGET_PAGE_SIZE,
|
||||
mprotect((void *)addr, TARGET_PAGE_SIZE,
|
||||
p->prot & ~PROT_WRITE);
|
||||
}
|
||||
}
|
||||
@ -1532,7 +1532,7 @@ static inline void tlb_update_dirty(CPUTLBEntry *tlb_entry)
|
||||
ram_addr_t ram_addr;
|
||||
|
||||
if ((tlb_entry->addr_write & ~TARGET_PAGE_MASK) == IO_MEM_RAM) {
|
||||
ram_addr = (tlb_entry->addr_write & TARGET_PAGE_MASK) +
|
||||
ram_addr = (tlb_entry->addr_write & TARGET_PAGE_MASK) +
|
||||
tlb_entry->addend - (unsigned long)phys_ram_base;
|
||||
if (!cpu_physical_memory_is_dirty(ram_addr)) {
|
||||
tlb_entry->addr_write |= IO_MEM_NOTDIRTY;
|
||||
@ -1558,7 +1558,7 @@ void cpu_tlb_update_dirty(CPUState *env)
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void tlb_set_dirty1(CPUTLBEntry *tlb_entry,
|
||||
static inline void tlb_set_dirty1(CPUTLBEntry *tlb_entry,
|
||||
unsigned long start)
|
||||
{
|
||||
unsigned long addr;
|
||||
@ -1593,8 +1593,8 @@ static inline void tlb_set_dirty(CPUState *env,
|
||||
is permitted. Return 0 if OK or 2 if the page could not be mapped
|
||||
(can only happen in non SOFTMMU mode for I/O pages or pages
|
||||
conflicting with the host address space). */
|
||||
int tlb_set_page_exec(CPUState *env, target_ulong vaddr,
|
||||
target_phys_addr_t paddr, int prot,
|
||||
int tlb_set_page_exec(CPUState *env, target_ulong vaddr,
|
||||
target_phys_addr_t paddr, int prot,
|
||||
int is_user, int is_softmmu)
|
||||
{
|
||||
PhysPageDesc *p;
|
||||
@ -1619,7 +1619,7 @@ int tlb_set_page_exec(CPUState *env, target_ulong vaddr,
|
||||
|
||||
ret = 0;
|
||||
#if !defined(CONFIG_SOFTMMU)
|
||||
if (is_softmmu)
|
||||
if (is_softmmu)
|
||||
#endif
|
||||
{
|
||||
if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && !(pd & IO_MEM_ROMD)) {
|
||||
@ -1664,12 +1664,12 @@ int tlb_set_page_exec(CPUState *env, target_ulong vaddr,
|
||||
te->addr_code = -1;
|
||||
}
|
||||
if (prot & PAGE_WRITE) {
|
||||
if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_ROM ||
|
||||
if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_ROM ||
|
||||
(pd & IO_MEM_ROMD)) {
|
||||
/* write access calls the I/O callback */
|
||||
te->addr_write = vaddr |
|
||||
te->addr_write = vaddr |
|
||||
(pd & ~(TARGET_PAGE_MASK | IO_MEM_ROMD));
|
||||
} else if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_RAM &&
|
||||
} else if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_RAM &&
|
||||
!cpu_physical_memory_is_dirty(pd)) {
|
||||
te->addr_write = vaddr | IO_MEM_NOTDIRTY;
|
||||
} else {
|
||||
@ -1693,17 +1693,17 @@ int tlb_set_page_exec(CPUState *env, target_ulong vaddr,
|
||||
ret = 2;
|
||||
} else {
|
||||
if (prot & PROT_WRITE) {
|
||||
if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_ROM ||
|
||||
if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_ROM ||
|
||||
#if defined(TARGET_HAS_SMC) || 1
|
||||
first_tb ||
|
||||
#endif
|
||||
((pd & ~TARGET_PAGE_MASK) == IO_MEM_RAM &&
|
||||
((pd & ~TARGET_PAGE_MASK) == IO_MEM_RAM &&
|
||||
!cpu_physical_memory_is_dirty(pd))) {
|
||||
/* ROM: we do as if code was inside */
|
||||
/* if code is present, we only map as read only and save the
|
||||
original mapping */
|
||||
VirtPageDesc *vp;
|
||||
|
||||
|
||||
vp = virt_page_find_alloc(vaddr >> TARGET_PAGE_BITS, 1);
|
||||
vp->phys_addr = pd;
|
||||
vp->prot = prot;
|
||||
@ -1711,7 +1711,7 @@ int tlb_set_page_exec(CPUState *env, target_ulong vaddr,
|
||||
prot &= ~PAGE_WRITE;
|
||||
}
|
||||
}
|
||||
map_addr = mmap((void *)vaddr, TARGET_PAGE_SIZE, prot,
|
||||
map_addr = mmap((void *)vaddr, TARGET_PAGE_SIZE, prot,
|
||||
MAP_SHARED | MAP_FIXED, phys_ram_fd, (pd & TARGET_PAGE_MASK));
|
||||
if (map_addr == MAP_FAILED) {
|
||||
cpu_abort(env, "mmap failed when mapped physical address 0x%08x to virtual address 0x%08x\n",
|
||||
@ -1749,7 +1749,7 @@ int page_unprotect(target_ulong addr, unsigned long pc, void *puc)
|
||||
if (!(vp->prot & PAGE_WRITE))
|
||||
return 0;
|
||||
#if defined(DEBUG_TLB)
|
||||
printf("page_unprotect: addr=0x%08x phys_addr=0x%08x prot=%x\n",
|
||||
printf("page_unprotect: addr=0x%08x phys_addr=0x%08x prot=%x\n",
|
||||
addr, vp->phys_addr, vp->prot);
|
||||
#endif
|
||||
if (mprotect((void *)addr, TARGET_PAGE_SIZE, vp->prot) < 0)
|
||||
@ -1775,8 +1775,8 @@ void tlb_flush_page(CPUState *env, target_ulong addr)
|
||||
{
|
||||
}
|
||||
|
||||
int tlb_set_page_exec(CPUState *env, target_ulong vaddr,
|
||||
target_phys_addr_t paddr, int prot,
|
||||
int tlb_set_page_exec(CPUState *env, target_ulong vaddr,
|
||||
target_phys_addr_t paddr, int prot,
|
||||
int is_user, int is_softmmu)
|
||||
{
|
||||
return 0;
|
||||
@ -1808,7 +1808,7 @@ void page_dump(FILE *f)
|
||||
end = (i << (32 - L1_BITS)) | (j << TARGET_PAGE_BITS);
|
||||
if (start != -1) {
|
||||
fprintf(f, "%08lx-%08lx %08lx %c%c%c\n",
|
||||
start, end, end - start,
|
||||
start, end, end - start,
|
||||
prot & PAGE_READ ? 'r' : '-',
|
||||
prot & PAGE_WRITE ? 'w' : '-',
|
||||
prot & PAGE_EXEC ? 'x' : '-');
|
||||
@ -1852,7 +1852,7 @@ void page_set_flags(target_ulong start, target_ulong end, int flags)
|
||||
p = page_find_alloc(addr >> TARGET_PAGE_BITS);
|
||||
/* if the write protection is set, then we invalidate the code
|
||||
inside */
|
||||
if (!(p->flags & PAGE_WRITE) &&
|
||||
if (!(p->flags & PAGE_WRITE) &&
|
||||
(flags & PAGE_WRITE) &&
|
||||
p->first_tb) {
|
||||
tb_invalidate_phys_page(addr, 0, NULL);
|
||||
@ -1887,7 +1887,7 @@ int page_unprotect(target_ulong address, unsigned long pc, void *puc)
|
||||
if (prot & PAGE_WRITE_ORG) {
|
||||
pindex = (address - host_start) >> TARGET_PAGE_BITS;
|
||||
if (!(p1[pindex].flags & PAGE_WRITE)) {
|
||||
mprotect((void *)g2h(host_start), qemu_host_page_size,
|
||||
mprotect((void *)g2h(host_start), qemu_host_page_size,
|
||||
(prot & PAGE_BITS) | PAGE_WRITE);
|
||||
p1[pindex].flags |= PAGE_WRITE;
|
||||
/* and since the content will be modified, we must invalidate
|
||||
@ -1950,7 +1950,7 @@ static void *subpage_init (target_phys_addr_t base, uint32_t *phys,
|
||||
/* register physical memory. 'size' must be a multiple of the target
|
||||
page size. If (phys_offset & ~TARGET_PAGE_MASK) != 0, then it is an
|
||||
io memory page */
|
||||
void cpu_register_physical_memory(target_phys_addr_t start_addr,
|
||||
void cpu_register_physical_memory(target_phys_addr_t start_addr,
|
||||
unsigned long size,
|
||||
unsigned long phys_offset)
|
||||
{
|
||||
@ -2008,7 +2008,7 @@ void cpu_register_physical_memory(target_phys_addr_t start_addr,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* since each CPU stores ram addresses in its TLB cache, we must
|
||||
reset the modified entries */
|
||||
/* XXX: slow ! */
|
||||
@ -2033,7 +2033,7 @@ ram_addr_t qemu_ram_alloc(unsigned int size)
|
||||
{
|
||||
ram_addr_t addr;
|
||||
if ((phys_ram_alloc_offset + size) >= phys_ram_size) {
|
||||
fprintf(stderr, "Not enough memory (requested_size = %u, max memory = %d)\n",
|
||||
fprintf(stderr, "Not enough memory (requested_size = %u, max memory = %d)\n",
|
||||
size, phys_ram_size);
|
||||
abort();
|
||||
}
|
||||
@ -2448,7 +2448,7 @@ CPUReadMemoryFunc **cpu_get_io_memory_read(int io_index)
|
||||
|
||||
/* physical memory access (slow version, mainly for debug) */
|
||||
#if defined(CONFIG_USER_ONLY)
|
||||
void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
|
||||
void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
|
||||
int len, int is_write)
|
||||
{
|
||||
int l, flags;
|
||||
@ -2483,7 +2483,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
|
||||
}
|
||||
|
||||
#else
|
||||
void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
|
||||
void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
|
||||
int len, int is_write)
|
||||
{
|
||||
int l, io_index;
|
||||
@ -2492,7 +2492,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
|
||||
target_phys_addr_t page;
|
||||
unsigned long pd;
|
||||
PhysPageDesc *p;
|
||||
|
||||
|
||||
while (len > 0) {
|
||||
page = addr & TARGET_PAGE_MASK;
|
||||
l = (page + TARGET_PAGE_SIZE) - addr;
|
||||
@ -2504,7 +2504,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
|
||||
} else {
|
||||
pd = p->phys_offset;
|
||||
}
|
||||
|
||||
|
||||
if (is_write) {
|
||||
if ((pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM) {
|
||||
io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);
|
||||
@ -2536,12 +2536,12 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
|
||||
/* invalidate code */
|
||||
tb_invalidate_phys_page_range(addr1, addr1 + l, 0);
|
||||
/* set dirty bit */
|
||||
phys_ram_dirty[addr1 >> TARGET_PAGE_BITS] |=
|
||||
phys_ram_dirty[addr1 >> TARGET_PAGE_BITS] |=
|
||||
(0xff & ~CODE_DIRTY_FLAG);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM &&
|
||||
if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM &&
|
||||
!(pd & IO_MEM_ROMD)) {
|
||||
/* I/O case */
|
||||
io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);
|
||||
@ -2563,7 +2563,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
|
||||
}
|
||||
} else {
|
||||
/* RAM case */
|
||||
ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +
|
||||
ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +
|
||||
(addr & ~TARGET_PAGE_MASK);
|
||||
memcpy(buf, ptr, l);
|
||||
}
|
||||
@ -2575,7 +2575,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
|
||||
}
|
||||
|
||||
/* used for ROM loading : can write in RAM and ROM */
|
||||
void cpu_physical_memory_write_rom(target_phys_addr_t addr,
|
||||
void cpu_physical_memory_write_rom(target_phys_addr_t addr,
|
||||
const uint8_t *buf, int len)
|
||||
{
|
||||
int l;
|
||||
@ -2583,7 +2583,7 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr,
|
||||
target_phys_addr_t page;
|
||||
unsigned long pd;
|
||||
PhysPageDesc *p;
|
||||
|
||||
|
||||
while (len > 0) {
|
||||
page = addr & TARGET_PAGE_MASK;
|
||||
l = (page + TARGET_PAGE_SIZE) - addr;
|
||||
@ -2595,7 +2595,7 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr,
|
||||
} else {
|
||||
pd = p->phys_offset;
|
||||
}
|
||||
|
||||
|
||||
if ((pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM &&
|
||||
(pd & ~TARGET_PAGE_MASK) != IO_MEM_ROM &&
|
||||
!(pd & IO_MEM_ROMD)) {
|
||||
@ -2629,15 +2629,15 @@ uint32_t ldl_phys(target_phys_addr_t addr)
|
||||
} else {
|
||||
pd = p->phys_offset;
|
||||
}
|
||||
|
||||
if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM &&
|
||||
|
||||
if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM &&
|
||||
!(pd & IO_MEM_ROMD)) {
|
||||
/* I/O case */
|
||||
io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);
|
||||
val = io_mem_read[io_index][2](io_mem_opaque[io_index], addr);
|
||||
} else {
|
||||
/* RAM case */
|
||||
ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +
|
||||
ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +
|
||||
(addr & ~TARGET_PAGE_MASK);
|
||||
val = ldl_p(ptr);
|
||||
}
|
||||
@ -2659,7 +2659,7 @@ uint64_t ldq_phys(target_phys_addr_t addr)
|
||||
} else {
|
||||
pd = p->phys_offset;
|
||||
}
|
||||
|
||||
|
||||
if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM &&
|
||||
!(pd & IO_MEM_ROMD)) {
|
||||
/* I/O case */
|
||||
@ -2673,7 +2673,7 @@ uint64_t ldq_phys(target_phys_addr_t addr)
|
||||
#endif
|
||||
} else {
|
||||
/* RAM case */
|
||||
ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +
|
||||
ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +
|
||||
(addr & ~TARGET_PAGE_MASK);
|
||||
val = ldq_p(ptr);
|
||||
}
|
||||
@ -2712,12 +2712,12 @@ void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val)
|
||||
} else {
|
||||
pd = p->phys_offset;
|
||||
}
|
||||
|
||||
|
||||
if ((pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM) {
|
||||
io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);
|
||||
io_mem_write[io_index][2](io_mem_opaque[io_index], addr, val);
|
||||
} else {
|
||||
ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +
|
||||
ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +
|
||||
(addr & ~TARGET_PAGE_MASK);
|
||||
stl_p(ptr, val);
|
||||
}
|
||||
@ -2736,7 +2736,7 @@ void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val)
|
||||
} else {
|
||||
pd = p->phys_offset;
|
||||
}
|
||||
|
||||
|
||||
if ((pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM) {
|
||||
io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);
|
||||
#ifdef TARGET_WORDS_BIGENDIAN
|
||||
@ -2747,7 +2747,7 @@ void stq_phys_notdirty(target_phys_addr_t addr, uint64_t val)
|
||||
io_mem_write[io_index][2](io_mem_opaque[io_index], addr + 4, val >> 32);
|
||||
#endif
|
||||
} else {
|
||||
ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +
|
||||
ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +
|
||||
(addr & ~TARGET_PAGE_MASK);
|
||||
stq_p(ptr, val);
|
||||
}
|
||||
@ -2767,7 +2767,7 @@ void stl_phys(target_phys_addr_t addr, uint32_t val)
|
||||
} else {
|
||||
pd = p->phys_offset;
|
||||
}
|
||||
|
||||
|
||||
if ((pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM) {
|
||||
io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);
|
||||
io_mem_write[io_index][2](io_mem_opaque[io_index], addr, val);
|
||||
@ -2811,7 +2811,7 @@ void stq_phys(target_phys_addr_t addr, uint64_t val)
|
||||
#endif
|
||||
|
||||
/* virtual memory access for debug */
|
||||
int cpu_memory_rw_debug(CPUState *env, target_ulong addr,
|
||||
int cpu_memory_rw_debug(CPUState *env, target_ulong addr,
|
||||
uint8_t *buf, int len, int is_write)
|
||||
{
|
||||
int l;
|
||||
@ -2827,7 +2827,7 @@ int cpu_memory_rw_debug(CPUState *env, target_ulong addr,
|
||||
l = (page + TARGET_PAGE_SIZE) - addr;
|
||||
if (l > len)
|
||||
l = len;
|
||||
cpu_physical_memory_rw(phys_addr + (addr & ~TARGET_PAGE_MASK),
|
||||
cpu_physical_memory_rw(phys_addr + (addr & ~TARGET_PAGE_MASK),
|
||||
buf, l, is_write);
|
||||
len -= l;
|
||||
buf += l;
|
||||
@ -2842,7 +2842,7 @@ void dump_exec_info(FILE *f,
|
||||
int i, target_code_size, max_target_code_size;
|
||||
int direct_jmp_count, direct_jmp2_count, cross_page;
|
||||
TranslationBlock *tb;
|
||||
|
||||
|
||||
target_code_size = 0;
|
||||
max_target_code_size = 0;
|
||||
cross_page = 0;
|
||||
@ -2864,17 +2864,17 @@ void dump_exec_info(FILE *f,
|
||||
}
|
||||
/* XXX: avoid using doubles ? */
|
||||
cpu_fprintf(f, "TB count %d\n", nb_tbs);
|
||||
cpu_fprintf(f, "TB avg target size %d max=%d bytes\n",
|
||||
cpu_fprintf(f, "TB avg target size %d max=%d bytes\n",
|
||||
nb_tbs ? target_code_size / nb_tbs : 0,
|
||||
max_target_code_size);
|
||||
cpu_fprintf(f, "TB avg host size %d bytes (expansion ratio: %0.1f)\n",
|
||||
cpu_fprintf(f, "TB avg host size %d bytes (expansion ratio: %0.1f)\n",
|
||||
nb_tbs ? (code_gen_ptr - code_gen_buffer) / nb_tbs : 0,
|
||||
target_code_size ? (double) (code_gen_ptr - code_gen_buffer) / target_code_size : 0);
|
||||
cpu_fprintf(f, "cross page TB count %d (%d%%)\n",
|
||||
cross_page,
|
||||
cpu_fprintf(f, "cross page TB count %d (%d%%)\n",
|
||||
cross_page,
|
||||
nb_tbs ? (cross_page * 100) / nb_tbs : 0);
|
||||
cpu_fprintf(f, "direct jump count %d (%d%%) (2 jumps=%d %d%%)\n",
|
||||
direct_jmp_count,
|
||||
direct_jmp_count,
|
||||
nb_tbs ? (direct_jmp_count * 100) / nb_tbs : 0,
|
||||
direct_jmp2_count,
|
||||
nb_tbs ? (direct_jmp2_count * 100) / nb_tbs : 0);
|
||||
@ -2883,7 +2883,7 @@ void dump_exec_info(FILE *f,
|
||||
cpu_fprintf(f, "TLB flush count %d\n", tlb_flush_count);
|
||||
}
|
||||
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
#if !defined(CONFIG_USER_ONLY)
|
||||
|
||||
#define MMUSUFFIX _cmmu
|
||||
#define GETPC() NULL
|
||||
|
@ -59,7 +59,7 @@ double qemu_rint(double x)
|
||||
double y = 4503599627370496.0;
|
||||
if (fabs(x) >= y)
|
||||
return x;
|
||||
if (x < 0)
|
||||
if (x < 0)
|
||||
y = -y;
|
||||
y = (x + y) - y;
|
||||
if (y == 0.0)
|
||||
@ -131,7 +131,7 @@ static inline int long_to_int32(long a)
|
||||
#else
|
||||
static inline int long_to_int32(long a)
|
||||
{
|
||||
if (a != (int32_t)a)
|
||||
if (a != (int32_t)a)
|
||||
a = 0x80000000;
|
||||
return a;
|
||||
}
|
||||
|
12
gdbstub.c
12
gdbstub.c
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* gdb server stub
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003-2005 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -252,7 +252,7 @@ static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
|
||||
registers[41] = 0; /* foseg */
|
||||
registers[42] = 0; /* fooff */
|
||||
registers[43] = 0; /* fop */
|
||||
|
||||
|
||||
for(i = 0; i < 16; i++)
|
||||
tswapls(®isters[i]);
|
||||
for(i = 36; i < 44; i++)
|
||||
@ -543,7 +543,7 @@ static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
|
||||
/* F0-F7. The 68881/68040 have 12-bit extended precision registers.
|
||||
ColdFire has 8-bit double precision registers. */
|
||||
for (i = 0; i < 8; i++) {
|
||||
u.l.upper = tswap32(*(uint32_t *)ptr);
|
||||
u.l.upper = tswap32(*(uint32_t *)ptr);
|
||||
u.l.lower = tswap32(*(uint32_t *)ptr);
|
||||
env->fregs[i] = u.d;
|
||||
}
|
||||
@ -748,7 +748,7 @@ static int gdb_handle_packet(GDBState *s, CPUState *env, const char *line_buf)
|
||||
uint8_t mem_buf[2000];
|
||||
uint32_t *registers;
|
||||
target_ulong addr, len;
|
||||
|
||||
|
||||
#ifdef DEBUG_GDB
|
||||
printf("command='%s'\n", line_buf);
|
||||
#endif
|
||||
@ -1073,7 +1073,7 @@ static void gdb_read_byte(GDBState *s, int ch)
|
||||
/* when the CPU is running, we cannot do anything except stop
|
||||
it when receiving a char */
|
||||
vm_stop(EXCP_INTERRUPT);
|
||||
} else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
switch(s->state) {
|
||||
@ -1201,7 +1201,7 @@ static void gdb_accept(void *opaque)
|
||||
/* set short latency */
|
||||
val = 1;
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
|
||||
|
||||
|
||||
s = &gdbserver_state;
|
||||
memset (s, 0, sizeof (GDBState));
|
||||
s->env = first_cpu; /* XXX: allow to change CPU */
|
||||
|
16
hw/acpi.c
16
hw/acpi.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* ACPI implementation
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2006 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2 as published by the Free Software Foundation.
|
||||
@ -87,9 +87,9 @@ static void pm_update_sci(PIIX4PMState *s)
|
||||
{
|
||||
int sci_level, pmsts;
|
||||
int64_t expire_time;
|
||||
|
||||
|
||||
pmsts = get_pmsts(s);
|
||||
sci_level = (((pmsts & s->pmen) &
|
||||
sci_level = (((pmsts & s->pmen) &
|
||||
(RTC_EN | PWRBTN_EN | GBL_EN | TMROF_EN)) != 0);
|
||||
qemu_set_irq(s->dev.irq[0], sci_level);
|
||||
/* schedule a timer interruption if needed */
|
||||
@ -239,7 +239,7 @@ static uint32_t pm_smi_readb(void *opaque, uint32_t addr)
|
||||
{
|
||||
PIIX4PMState *s = opaque;
|
||||
uint32_t val;
|
||||
|
||||
|
||||
addr &= 1;
|
||||
if (addr == 0) {
|
||||
val = s->apmc;
|
||||
@ -413,7 +413,7 @@ static void pm_io_space_update(PIIX4PMState *s)
|
||||
}
|
||||
}
|
||||
|
||||
static void pm_write_config(PCIDevice *d,
|
||||
static void pm_write_config(PCIDevice *d,
|
||||
uint32_t address, uint32_t val, int len)
|
||||
{
|
||||
pci_default_write_config(d, address, val, len);
|
||||
@ -480,9 +480,9 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base)
|
||||
pci_conf[0x0b] = 0x06; // bridge device
|
||||
pci_conf[0x0e] = 0x00; // header_type
|
||||
pci_conf[0x3d] = 0x01; // interrupt pin 1
|
||||
|
||||
|
||||
pci_conf[0x40] = 0x01; /* PM io base read only bit */
|
||||
|
||||
|
||||
register_ioport_write(0xb2, 2, 1, pm_smi_writeb, s);
|
||||
register_ioport_read(0xb2, 2, 1, pm_smi_readb, s);
|
||||
|
||||
|
24
hw/adb.c
24
hw/adb.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU ADB support
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -96,9 +96,9 @@ int adb_poll(ADBBusState *s, uint8_t *obuf)
|
||||
return olen;
|
||||
}
|
||||
|
||||
ADBDevice *adb_register_device(ADBBusState *s, int devaddr,
|
||||
ADBDeviceRequest *devreq,
|
||||
ADBDeviceReset *devreset,
|
||||
ADBDevice *adb_register_device(ADBBusState *s, int devaddr,
|
||||
ADBDeviceRequest *devreq,
|
||||
ADBDeviceReset *devreset,
|
||||
void *opaque)
|
||||
{
|
||||
ADBDevice *d;
|
||||
@ -299,31 +299,31 @@ static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf)
|
||||
if (s->last_buttons_state == s->buttons_state &&
|
||||
s->dx == 0 && s->dy == 0)
|
||||
return 0;
|
||||
|
||||
|
||||
dx = s->dx;
|
||||
if (dx < -63)
|
||||
dx = -63;
|
||||
else if (dx > 63)
|
||||
dx = 63;
|
||||
|
||||
|
||||
dy = s->dy;
|
||||
if (dy < -63)
|
||||
dy = -63;
|
||||
else if (dy > 63)
|
||||
dy = 63;
|
||||
|
||||
|
||||
s->dx -= dx;
|
||||
s->dy -= dy;
|
||||
s->last_buttons_state = s->buttons_state;
|
||||
|
||||
|
||||
dx &= 0x7f;
|
||||
dy &= 0x7f;
|
||||
|
||||
|
||||
if (!(s->buttons_state & MOUSE_EVENT_LBUTTON))
|
||||
dy |= 0x80;
|
||||
if (!(s->buttons_state & MOUSE_EVENT_RBUTTON))
|
||||
dx |= 0x80;
|
||||
|
||||
|
||||
obuf[0] = dy;
|
||||
obuf[1] = dx;
|
||||
return 2;
|
||||
@ -334,7 +334,7 @@ static int adb_mouse_request(ADBDevice *d, uint8_t *obuf,
|
||||
{
|
||||
MouseState *s = d->opaque;
|
||||
int cmd, reg, olen;
|
||||
|
||||
|
||||
if ((buf[0] & 0x0f) == ADB_FLUSH) {
|
||||
/* flush mouse fifo */
|
||||
s->buttons_state = s->last_buttons_state;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Alpha emulation - PALcode emulation for qemu.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2007 Jocelyn Mayer
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -62,7 +62,7 @@ static void update_itb ()
|
||||
mtpr(TB_TAG);
|
||||
mtpr(TB_CTL);
|
||||
/* This commits the TB update */
|
||||
mtpr(ITB_PTE);
|
||||
mtpr(ITB_PTE);
|
||||
}
|
||||
|
||||
static void update_dtb ();
|
||||
@ -937,7 +937,7 @@ static int paddr_from_pte (uint64_t *paddr, int *zbitsp, int *prot,
|
||||
}
|
||||
}
|
||||
*paddr = (pfn << page_bits) | (vaddr & page_mask);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -998,7 +998,7 @@ int cpu_ppc_handle_mmu_fault (CPUState *env, uint32_t address, int rw,
|
||||
|
||||
if (env->user_mode_only) {
|
||||
ret = 2;
|
||||
} else {
|
||||
} else {
|
||||
ret = virtual_to_physical(env, &physical, &zbits, &prot,
|
||||
address, is_user, rw);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Arnewsh 5206 ColdFire system emulation.
|
||||
*
|
||||
* Copyright (c) 2007 CodeSourcery.
|
||||
|
@ -2,7 +2,7 @@
|
||||
* QEMU Ultrasparc APB PCI host
|
||||
*
|
||||
* Copyright (c) 2006 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -233,7 +233,7 @@ PCIBus *pci_apb_init(target_phys_addr_t special_base,
|
||||
cpu_register_physical_memory(special_base + 0x2000000ULL, 0x10000, pci_ioport);
|
||||
cpu_register_physical_memory(mem_base, 0x10000000, pci_mem_data); // XXX size should be 4G-prom
|
||||
|
||||
d = pci_register_device(s->bus, "Advanced PCI Bus", sizeof(PCIDevice),
|
||||
d = pci_register_device(s->bus, "Advanced PCI Bus", sizeof(PCIDevice),
|
||||
0, NULL, NULL);
|
||||
d->config[0x00] = 0x8e; // vendor_id : Sun
|
||||
d->config[0x01] = 0x10;
|
||||
|
40
hw/apic.c
40
hw/apic.c
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* APIC support
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004-2005 Fabrice Bellard
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -182,7 +182,7 @@ static inline void reset_bit(uint32_t *tab, int index)
|
||||
}\
|
||||
}
|
||||
|
||||
static void apic_bus_deliver(const uint32_t *deliver_bitmask,
|
||||
static void apic_bus_deliver(const uint32_t *deliver_bitmask,
|
||||
uint8_t delivery_mode,
|
||||
uint8_t vector_num, uint8_t polarity,
|
||||
uint8_t trigger_mode)
|
||||
@ -219,10 +219,10 @@ static void apic_bus_deliver(const uint32_t *deliver_bitmask,
|
||||
|
||||
case APIC_DM_INIT:
|
||||
/* normal INIT IPI sent to processors */
|
||||
foreach_apic(apic_iter, deliver_bitmask,
|
||||
foreach_apic(apic_iter, deliver_bitmask,
|
||||
apic_init_ipi(apic_iter) );
|
||||
return;
|
||||
|
||||
|
||||
case APIC_DM_EXTINT:
|
||||
/* handled in I/O APIC code */
|
||||
break;
|
||||
@ -231,7 +231,7 @@ static void apic_bus_deliver(const uint32_t *deliver_bitmask,
|
||||
return;
|
||||
}
|
||||
|
||||
foreach_apic(apic_iter, deliver_bitmask,
|
||||
foreach_apic(apic_iter, deliver_bitmask,
|
||||
apic_set_irq(apic_iter, vector_num, trigger_mode) );
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ void cpu_set_apic_base(CPUState *env, uint64_t val)
|
||||
#ifdef DEBUG_APIC
|
||||
printf("cpu_set_apic_base: %016" PRIx64 "\n", val);
|
||||
#endif
|
||||
s->apicbase = (val & 0xfffff000) |
|
||||
s->apicbase = (val & 0xfffff000) |
|
||||
(s->apicbase & (MSR_IA32_APICBASE_BSP | MSR_IA32_APICBASE_ENABLE));
|
||||
/* if disabled, cannot be enabled again */
|
||||
if (!(val & MSR_IA32_APICBASE_ENABLE)) {
|
||||
@ -407,7 +407,7 @@ static void apic_startup(APICState *s, int vector_num)
|
||||
if (!(env->hflags & HF_HALTED_MASK))
|
||||
return;
|
||||
env->eip = 0;
|
||||
cpu_x86_load_seg_cache(env, R_CS, vector_num << 8, vector_num << 12,
|
||||
cpu_x86_load_seg_cache(env, R_CS, vector_num << 8, vector_num << 12,
|
||||
0xffff, 0);
|
||||
env->hflags &= ~HF_HALTED_MASK;
|
||||
}
|
||||
@ -443,7 +443,7 @@ static void apic_deliver(APICState *s, uint8_t dest, uint8_t dest_mode,
|
||||
int trig_mode = (s->icr[0] >> 15) & 1;
|
||||
int level = (s->icr[0] >> 14) & 1;
|
||||
if (level == 0 && trig_mode == 1) {
|
||||
foreach_apic(apic_iter, deliver_bitmask,
|
||||
foreach_apic(apic_iter, deliver_bitmask,
|
||||
apic_iter->arb_id = apic_iter->id );
|
||||
return;
|
||||
}
|
||||
@ -451,7 +451,7 @@ static void apic_deliver(APICState *s, uint8_t dest, uint8_t dest_mode,
|
||||
break;
|
||||
|
||||
case APIC_DM_SIPI:
|
||||
foreach_apic(apic_iter, deliver_bitmask,
|
||||
foreach_apic(apic_iter, deliver_bitmask,
|
||||
apic_startup(apic_iter, vector_num) );
|
||||
return;
|
||||
}
|
||||
@ -471,7 +471,7 @@ int apic_get_interrupt(CPUState *env)
|
||||
return -1;
|
||||
if (!(s->spurious_vec & APIC_SV_ENABLE))
|
||||
return -1;
|
||||
|
||||
|
||||
/* XXX: spurious IRQ handling */
|
||||
intno = get_highest_priority_int(s->irr);
|
||||
if (intno < 0)
|
||||
@ -488,7 +488,7 @@ static uint32_t apic_get_current_count(APICState *s)
|
||||
{
|
||||
int64_t d;
|
||||
uint32_t val;
|
||||
d = (qemu_get_clock(vm_clock) - s->initial_count_load_time) >>
|
||||
d = (qemu_get_clock(vm_clock) - s->initial_count_load_time) >>
|
||||
s->count_shift;
|
||||
if (s->lvt[APIC_LVT_TIMER] & APIC_LVT_TIMER_PERIODIC) {
|
||||
/* periodic */
|
||||
@ -505,9 +505,9 @@ static uint32_t apic_get_current_count(APICState *s)
|
||||
static void apic_timer_update(APICState *s, int64_t current_time)
|
||||
{
|
||||
int64_t next_time, d;
|
||||
|
||||
|
||||
if (!(s->lvt[APIC_LVT_TIMER] & APIC_LVT_MASKED)) {
|
||||
d = (current_time - s->initial_count_load_time) >>
|
||||
d = (current_time - s->initial_count_load_time) >>
|
||||
s->count_shift;
|
||||
if (s->lvt[APIC_LVT_TIMER] & APIC_LVT_TIMER_PERIODIC) {
|
||||
d = ((d / ((uint64_t)s->initial_count + 1)) + 1) * ((uint64_t)s->initial_count + 1);
|
||||
@ -818,14 +818,14 @@ int apic_init(CPUState *env)
|
||||
s->id = last_apic_id++;
|
||||
env->cpuid_apic_id = s->id;
|
||||
s->cpu_env = env;
|
||||
s->apicbase = 0xfee00000 |
|
||||
s->apicbase = 0xfee00000 |
|
||||
(s->id ? 0 : MSR_IA32_APICBASE_BSP) | MSR_IA32_APICBASE_ENABLE;
|
||||
|
||||
/* XXX: mapping more APICs at the same memory location */
|
||||
if (apic_io_memory == 0) {
|
||||
/* NOTE: the APIC is directly connected to the CPU - it is not
|
||||
on the global memory bus. */
|
||||
apic_io_memory = cpu_register_io_memory(0, apic_mem_read,
|
||||
apic_io_memory = cpu_register_io_memory(0, apic_mem_read,
|
||||
apic_mem_write, NULL);
|
||||
cpu_register_physical_memory(s->apicbase & ~0xfff, 0x1000,
|
||||
apic_io_memory);
|
||||
@ -834,7 +834,7 @@ int apic_init(CPUState *env)
|
||||
|
||||
register_savevm("apic", s->id, 2, apic_save, apic_load, s);
|
||||
qemu_register_reset(apic_reset, s);
|
||||
|
||||
|
||||
local_apics[s->id] = s;
|
||||
return 0;
|
||||
}
|
||||
@ -868,9 +868,9 @@ static void ioapic_service(IOAPICState *s)
|
||||
vector = pic_read_irq(isa_pic);
|
||||
else
|
||||
vector = entry & 0xff;
|
||||
|
||||
|
||||
apic_get_delivery_bitmask(deliver_bitmask, dest, dest_mode);
|
||||
apic_bus_deliver(deliver_bitmask, delivery_mode,
|
||||
apic_bus_deliver(deliver_bitmask, delivery_mode,
|
||||
vector, polarity, trig_mode);
|
||||
}
|
||||
}
|
||||
@ -1036,12 +1036,12 @@ IOAPICState *ioapic_init(void)
|
||||
ioapic_reset(s);
|
||||
s->id = last_apic_id++;
|
||||
|
||||
io_memory = cpu_register_io_memory(0, ioapic_mem_read,
|
||||
io_memory = cpu_register_io_memory(0, ioapic_mem_read,
|
||||
ioapic_mem_write, s);
|
||||
cpu_register_physical_memory(0xfec00000, 0x1000, io_memory);
|
||||
|
||||
register_savevm("ioapic", 0, 1, ioapic_save, ioapic_load, s);
|
||||
qemu_register_reset(ioapic_reset, s);
|
||||
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* ARM kernel loader.
|
||||
*
|
||||
* Copyright (c) 2006 CodeSourcery.
|
||||
@ -30,8 +30,8 @@ static void main_cpu_reset(void *opaque)
|
||||
|
||||
cpu_reset(env);
|
||||
if (env->kernel_filename)
|
||||
arm_load_kernel(env, env->ram_size, env->kernel_filename,
|
||||
env->kernel_cmdline, env->initrd_filename,
|
||||
arm_load_kernel(env, env->ram_size, env->kernel_filename,
|
||||
env->kernel_cmdline, env->initrd_filename,
|
||||
env->board_id, env->loader_start);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* ARM AMBA Generic/Distributed Interrupt Controller
|
||||
*
|
||||
* Copyright (c) 2006 CodeSourcery.
|
||||
@ -115,7 +115,7 @@ static void gic_set_irq(void *opaque, int irq, int level)
|
||||
gic_state *s = (gic_state *)opaque;
|
||||
/* The first external input line is internal interrupt 32. */
|
||||
irq += 32;
|
||||
if (level == GIC_TEST_LEVEL(irq))
|
||||
if (level == GIC_TEST_LEVEL(irq))
|
||||
return;
|
||||
|
||||
if (level) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Generic ARM Programmable Interrupt Controller support.
|
||||
*
|
||||
* Copyright (c) 2006 CodeSourcery.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Generic ARM Programmable Interrupt Controller support.
|
||||
*
|
||||
* Copyright (c) 2006 CodeSourcery.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Status and system control registers for ARM RealView/Versatile boards.
|
||||
*
|
||||
* Copyright (c) 2006 CodeSourcery.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* ARM PrimeCell Timer modules.
|
||||
*
|
||||
* Copyright (c) 2005-2006 CodeSourcery.
|
||||
|
22
hw/cdrom.c
22
hw/cdrom.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU ATAPI CD-ROM Emulator
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2006 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -41,7 +41,7 @@ int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track)
|
||||
{
|
||||
uint8_t *q;
|
||||
int len;
|
||||
|
||||
|
||||
if (start_track > 1 && start_track != 0xaa)
|
||||
return -1;
|
||||
q = buf + 2;
|
||||
@ -85,7 +85,7 @@ int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num)
|
||||
{
|
||||
uint8_t *q;
|
||||
int len;
|
||||
|
||||
|
||||
q = buf + 2;
|
||||
*q++ = 1; /* first session */
|
||||
*q++ = 1; /* last session */
|
||||
@ -101,7 +101,7 @@ int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num)
|
||||
*q++ = 1; /* first track */
|
||||
*q++ = 0x00; /* disk type */
|
||||
*q++ = 0x00;
|
||||
|
||||
|
||||
*q++ = 1; /* session number */
|
||||
*q++ = 0x14; /* data track */
|
||||
*q++ = 0; /* track number */
|
||||
@ -113,7 +113,7 @@ int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num)
|
||||
*q++ = 1; /* last track */
|
||||
*q++ = 0x00;
|
||||
*q++ = 0x00;
|
||||
|
||||
|
||||
*q++ = 1; /* session number */
|
||||
*q++ = 0x14; /* data track */
|
||||
*q++ = 0; /* track number */
|
||||
@ -138,14 +138,14 @@ int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num)
|
||||
*q++ = 0; /* sec */
|
||||
*q++ = 0; /* frame */
|
||||
if (msf) {
|
||||
*q++ = 0;
|
||||
*q++ = 0;
|
||||
lba_to_msf(q, 0);
|
||||
q += 3;
|
||||
} else {
|
||||
*q++ = 0;
|
||||
*q++ = 0;
|
||||
*q++ = 0;
|
||||
*q++ = 0;
|
||||
*q++ = 0;
|
||||
*q++ = 0;
|
||||
*q++ = 0;
|
||||
*q++ = 0;
|
||||
}
|
||||
|
||||
len = q - buf;
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* QEMU Cirrus CLGD 54xx VGA Emulator.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004 Fabrice Bellard
|
||||
* Copyright (c) 2004 Makoto Suzuki (suzu)
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -275,7 +275,7 @@ typedef struct PCICirrusVGAState {
|
||||
} PCICirrusVGAState;
|
||||
|
||||
static uint8_t rop_to_index[256];
|
||||
|
||||
|
||||
/***************************************
|
||||
*
|
||||
* prototypes.
|
||||
@ -590,7 +590,7 @@ static inline void cirrus_bitblt_fgcol(CirrusVGAState *s)
|
||||
s->cirrus_blt_fgcol = le16_to_cpu(color);
|
||||
break;
|
||||
case 3:
|
||||
s->cirrus_blt_fgcol = s->cirrus_shadow_gr1 |
|
||||
s->cirrus_blt_fgcol = s->cirrus_shadow_gr1 |
|
||||
(s->gr[0x11] << 8) | (s->gr[0x13] << 16);
|
||||
break;
|
||||
default:
|
||||
@ -614,7 +614,7 @@ static inline void cirrus_bitblt_bgcol(CirrusVGAState *s)
|
||||
s->cirrus_blt_bgcol = le16_to_cpu(color);
|
||||
break;
|
||||
case 3:
|
||||
s->cirrus_blt_bgcol = s->cirrus_shadow_gr0 |
|
||||
s->cirrus_blt_bgcol = s->cirrus_shadow_gr0 |
|
||||
(s->gr[0x10] << 8) | (s->gr[0x12] << 16);
|
||||
break;
|
||||
default:
|
||||
@ -653,7 +653,7 @@ static int cirrus_bitblt_common_patterncopy(CirrusVGAState * s,
|
||||
|
||||
dst = s->vram_ptr + s->cirrus_blt_dstaddr;
|
||||
(*s->cirrus_rop) (s, dst, src,
|
||||
s->cirrus_blt_dstpitch, 0,
|
||||
s->cirrus_blt_dstpitch, 0,
|
||||
s->cirrus_blt_width, s->cirrus_blt_height);
|
||||
cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
|
||||
s->cirrus_blt_dstpitch, s->cirrus_blt_width,
|
||||
@ -668,7 +668,7 @@ static int cirrus_bitblt_solidfill(CirrusVGAState *s, int blt_rop)
|
||||
cirrus_fill_t rop_func;
|
||||
|
||||
rop_func = cirrus_fill[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1];
|
||||
rop_func(s, s->vram_ptr + s->cirrus_blt_dstaddr,
|
||||
rop_func(s, s->vram_ptr + s->cirrus_blt_dstaddr,
|
||||
s->cirrus_blt_dstpitch,
|
||||
s->cirrus_blt_width, s->cirrus_blt_height);
|
||||
cirrus_invalidate_region(s, s->cirrus_blt_dstaddr,
|
||||
@ -687,7 +687,7 @@ static int cirrus_bitblt_solidfill(CirrusVGAState *s, int blt_rop)
|
||||
static int cirrus_bitblt_videotovideo_patterncopy(CirrusVGAState * s)
|
||||
{
|
||||
return cirrus_bitblt_common_patterncopy(s,
|
||||
s->vram_ptr +
|
||||
s->vram_ptr +
|
||||
(s->cirrus_blt_srcaddr & ~7));
|
||||
}
|
||||
|
||||
@ -788,7 +788,7 @@ static void cirrus_bitblt_cputovideo_next(CirrusVGAState * s)
|
||||
{
|
||||
int copy_count;
|
||||
uint8_t *end_ptr;
|
||||
|
||||
|
||||
if (s->cirrus_srccounter > 0) {
|
||||
if (s->cirrus_blt_mode & CIRRUS_BLTMODE_PATTERNCOPY) {
|
||||
cirrus_bitblt_common_patterncopy(s, s->cirrus_bltbuf);
|
||||
@ -854,7 +854,7 @@ static int cirrus_bitblt_cputovideo(CirrusVGAState * s)
|
||||
} else {
|
||||
if (s->cirrus_blt_mode & CIRRUS_BLTMODE_COLOREXPAND) {
|
||||
w = s->cirrus_blt_width / s->cirrus_blt_pixelwidth;
|
||||
if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_DWORDGRANULARITY)
|
||||
if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_DWORDGRANULARITY)
|
||||
s->cirrus_blt_srcpitch = ((w + 31) >> 5);
|
||||
else
|
||||
s->cirrus_blt_srcpitch = ((w + 7) >> 3);
|
||||
@ -913,7 +913,7 @@ static void cirrus_bitblt_start(CirrusVGAState * s)
|
||||
|
||||
#ifdef DEBUG_BITBLT
|
||||
printf("rop=0x%02x mode=0x%02x modeext=0x%02x w=%d h=%d dpitch=%d spitch=%d daddr=0x%08x saddr=0x%08x writemask=0x%02x\n",
|
||||
blt_rop,
|
||||
blt_rop,
|
||||
s->cirrus_blt_mode,
|
||||
s->cirrus_blt_modeext,
|
||||
s->cirrus_blt_width,
|
||||
@ -957,16 +957,16 @@ static void cirrus_bitblt_start(CirrusVGAState * s)
|
||||
}
|
||||
|
||||
if ((s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_SOLIDFILL) &&
|
||||
(s->cirrus_blt_mode & (CIRRUS_BLTMODE_MEMSYSDEST |
|
||||
(s->cirrus_blt_mode & (CIRRUS_BLTMODE_MEMSYSDEST |
|
||||
CIRRUS_BLTMODE_TRANSPARENTCOMP |
|
||||
CIRRUS_BLTMODE_PATTERNCOPY |
|
||||
CIRRUS_BLTMODE_COLOREXPAND)) ==
|
||||
CIRRUS_BLTMODE_PATTERNCOPY |
|
||||
CIRRUS_BLTMODE_COLOREXPAND)) ==
|
||||
(CIRRUS_BLTMODE_PATTERNCOPY | CIRRUS_BLTMODE_COLOREXPAND)) {
|
||||
cirrus_bitblt_fgcol(s);
|
||||
cirrus_bitblt_solidfill(s, blt_rop);
|
||||
} else {
|
||||
if ((s->cirrus_blt_mode & (CIRRUS_BLTMODE_COLOREXPAND |
|
||||
CIRRUS_BLTMODE_PATTERNCOPY)) ==
|
||||
if ((s->cirrus_blt_mode & (CIRRUS_BLTMODE_COLOREXPAND |
|
||||
CIRRUS_BLTMODE_PATTERNCOPY)) ==
|
||||
CIRRUS_BLTMODE_COLOREXPAND) {
|
||||
|
||||
if (s->cirrus_blt_mode & CIRRUS_BLTMODE_TRANSPARENTCOMP) {
|
||||
@ -1059,7 +1059,7 @@ static void cirrus_write_bitblt(CirrusVGAState * s, unsigned reg_value)
|
||||
*
|
||||
***************************************/
|
||||
|
||||
static void cirrus_get_offsets(VGAState *s1,
|
||||
static void cirrus_get_offsets(VGAState *s1,
|
||||
uint32_t *pline_offset,
|
||||
uint32_t *pstart_addr,
|
||||
uint32_t *pline_compare)
|
||||
@ -1079,7 +1079,7 @@ static void cirrus_get_offsets(VGAState *s1,
|
||||
| ((s->cr[0x1d] & 0x80) << 12);
|
||||
*pstart_addr = start_addr;
|
||||
|
||||
line_compare = s->cr[0x18] |
|
||||
line_compare = s->cr[0x18] |
|
||||
((s->cr[0x07] & 0x10) << 4) |
|
||||
((s->cr[0x09] & 0x40) << 3);
|
||||
*pline_compare = line_compare;
|
||||
@ -1148,10 +1148,10 @@ static int cirrus_get_bpp(VGAState *s1)
|
||||
static void cirrus_get_resolution(VGAState *s, int *pwidth, int *pheight)
|
||||
{
|
||||
int width, height;
|
||||
|
||||
|
||||
width = (s->cr[0x01] + 1) * 8;
|
||||
height = s->cr[0x12] |
|
||||
((s->cr[0x07] & 0x02) << 7) |
|
||||
height = s->cr[0x12] |
|
||||
((s->cr[0x07] & 0x02) << 7) |
|
||||
((s->cr[0x07] & 0x40) << 3);
|
||||
height = (height + 1);
|
||||
/* interlace support */
|
||||
@ -2036,7 +2036,7 @@ static uint32_t cirrus_vga_mem_readl(void *opaque, target_phys_addr_t addr)
|
||||
return v;
|
||||
}
|
||||
|
||||
static void cirrus_vga_mem_writeb(void *opaque, target_phys_addr_t addr,
|
||||
static void cirrus_vga_mem_writeb(void *opaque, target_phys_addr_t addr,
|
||||
uint32_t mem_value)
|
||||
{
|
||||
CirrusVGAState *s = opaque;
|
||||
@ -2147,7 +2147,7 @@ static CPUWriteMemoryFunc *cirrus_vga_mem_write[3] = {
|
||||
static inline void invalidate_cursor1(CirrusVGAState *s)
|
||||
{
|
||||
if (s->last_hw_cursor_size) {
|
||||
vga_invalidate_scanlines((VGAState *)s,
|
||||
vga_invalidate_scanlines((VGAState *)s,
|
||||
s->last_hw_cursor_y + s->last_hw_cursor_y_start,
|
||||
s->last_hw_cursor_y + s->last_hw_cursor_y_end);
|
||||
}
|
||||
@ -2223,7 +2223,7 @@ static void cirrus_cursor_invalidate(VGAState *s1)
|
||||
s->last_hw_cursor_y != s->hw_cursor_y) {
|
||||
|
||||
invalidate_cursor1(s);
|
||||
|
||||
|
||||
s->last_hw_cursor_size = size;
|
||||
s->last_hw_cursor_x = s->hw_cursor_x;
|
||||
s->last_hw_cursor_y = s->hw_cursor_y;
|
||||
@ -2240,8 +2240,8 @@ static void cirrus_cursor_draw_line(VGAState *s1, uint8_t *d1, int scr_y)
|
||||
unsigned int color0, color1;
|
||||
const uint8_t *palette, *src;
|
||||
uint32_t content;
|
||||
|
||||
if (!(s->sr[0x12] & CIRRUS_CURSOR_SHOW))
|
||||
|
||||
if (!(s->sr[0x12] & CIRRUS_CURSOR_SHOW))
|
||||
return;
|
||||
/* fast test to see if the cursor intersects with the scan line */
|
||||
if (s->sr[0x12] & CIRRUS_CURSOR_LARGE) {
|
||||
@ -2252,7 +2252,7 @@ static void cirrus_cursor_draw_line(VGAState *s1, uint8_t *d1, int scr_y)
|
||||
if (scr_y < s->hw_cursor_y ||
|
||||
scr_y >= (s->hw_cursor_y + h))
|
||||
return;
|
||||
|
||||
|
||||
src = s->vram_ptr + s->real_vram_size - 16 * 1024;
|
||||
if (s->sr[0x12] & CIRRUS_CURSOR_LARGE) {
|
||||
src += (s->sr[0x13] & 0x3c) * 256;
|
||||
@ -2282,11 +2282,11 @@ static void cirrus_cursor_draw_line(VGAState *s1, uint8_t *d1, int scr_y)
|
||||
x2 = s->last_scr_width;
|
||||
w = x2 - x1;
|
||||
palette = s->cirrus_hidden_palette;
|
||||
color0 = s->rgb_to_pixel(c6_to_8(palette[0x0 * 3]),
|
||||
c6_to_8(palette[0x0 * 3 + 1]),
|
||||
color0 = s->rgb_to_pixel(c6_to_8(palette[0x0 * 3]),
|
||||
c6_to_8(palette[0x0 * 3 + 1]),
|
||||
c6_to_8(palette[0x0 * 3 + 2]));
|
||||
color1 = s->rgb_to_pixel(c6_to_8(palette[0xf * 3]),
|
||||
c6_to_8(palette[0xf * 3 + 1]),
|
||||
color1 = s->rgb_to_pixel(c6_to_8(palette[0xf * 3]),
|
||||
c6_to_8(palette[0xf * 3 + 1]),
|
||||
c6_to_8(palette[0xf * 3 + 2]));
|
||||
bpp = ((s->ds->depth + 7) >> 3);
|
||||
d1 += x1 * bpp;
|
||||
@ -2321,7 +2321,7 @@ static uint32_t cirrus_linear_readb(void *opaque, target_phys_addr_t addr)
|
||||
|
||||
addr &= s->cirrus_addr_mask;
|
||||
|
||||
if (((s->sr[0x17] & 0x44) == 0x44) &&
|
||||
if (((s->sr[0x17] & 0x44) == 0x44) &&
|
||||
((addr & s->linear_mmio_mask) == s->linear_mmio_mask)) {
|
||||
/* memory-mapped I/O */
|
||||
ret = cirrus_mmio_blt_read(s, addr & 0xff);
|
||||
@ -2379,8 +2379,8 @@ static void cirrus_linear_writeb(void *opaque, target_phys_addr_t addr,
|
||||
unsigned mode;
|
||||
|
||||
addr &= s->cirrus_addr_mask;
|
||||
|
||||
if (((s->sr[0x17] & 0x44) == 0x44) &&
|
||||
|
||||
if (((s->sr[0x17] & 0x44) == 0x44) &&
|
||||
((addr & s->linear_mmio_mask) == s->linear_mmio_mask)) {
|
||||
/* memory-mapped I/O */
|
||||
cirrus_mmio_blt_write(s, addr & 0xff, val);
|
||||
@ -2600,7 +2600,7 @@ static void cirrus_update_memory_access(CirrusVGAState *s)
|
||||
} else if (s->gr[0x0B] & 0x02) {
|
||||
goto generic_io;
|
||||
}
|
||||
|
||||
|
||||
mode = s->gr[0x05] & 0x7;
|
||||
if (mode < 4 || mode > 5 || ((s->gr[0x0B] & 0x4) == 0)) {
|
||||
s->cirrus_linear_write[0] = cirrus_linear_mem_writeb;
|
||||
@ -3110,9 +3110,9 @@ static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci)
|
||||
register_ioport_read(0x3ba, 1, 1, vga_ioport_read, s);
|
||||
register_ioport_read(0x3da, 1, 1, vga_ioport_read, s);
|
||||
|
||||
vga_io_memory = cpu_register_io_memory(0, cirrus_vga_mem_read,
|
||||
vga_io_memory = cpu_register_io_memory(0, cirrus_vga_mem_read,
|
||||
cirrus_vga_mem_write, s);
|
||||
cpu_register_physical_memory(isa_mem_base + 0x000a0000, 0x20000,
|
||||
cpu_register_physical_memory(isa_mem_base + 0x000a0000, 0x20000,
|
||||
vga_io_memory);
|
||||
|
||||
s->sr[0x06] = 0x0f;
|
||||
@ -3134,7 +3134,7 @@ static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci)
|
||||
} else {
|
||||
s->sr[0x1F] = 0x22; // MemClock
|
||||
s->sr[0x0F] = CIRRUS_MEMSIZE_2M;
|
||||
if (is_pci)
|
||||
if (is_pci)
|
||||
s->sr[0x17] = CIRRUS_BUSTYPE_PCI;
|
||||
else
|
||||
s->sr[0x17] = CIRRUS_BUSTYPE_ISA;
|
||||
@ -3184,14 +3184,14 @@ static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci)
|
||||
*
|
||||
***************************************/
|
||||
|
||||
void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base,
|
||||
void isa_cirrus_vga_init(DisplayState *ds, uint8_t *vga_ram_base,
|
||||
unsigned long vga_ram_offset, int vga_ram_size)
|
||||
{
|
||||
CirrusVGAState *s;
|
||||
|
||||
s = qemu_mallocz(sizeof(CirrusVGAState));
|
||||
|
||||
vga_common_init((VGAState *)s,
|
||||
|
||||
vga_common_init((VGAState *)s,
|
||||
ds, vga_ram_base, vga_ram_offset, vga_ram_size);
|
||||
cirrus_init_common(s, CIRRUS_ID_CLGD5430, 0);
|
||||
/* XXX ISA-LFB support */
|
||||
@ -3224,19 +3224,19 @@ static void cirrus_pci_mmio_map(PCIDevice *d, int region_num,
|
||||
s->cirrus_mmio_io_addr);
|
||||
}
|
||||
|
||||
void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
|
||||
void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
|
||||
unsigned long vga_ram_offset, int vga_ram_size)
|
||||
{
|
||||
PCICirrusVGAState *d;
|
||||
uint8_t *pci_conf;
|
||||
CirrusVGAState *s;
|
||||
int device_id;
|
||||
|
||||
|
||||
device_id = CIRRUS_ID_CLGD5446;
|
||||
|
||||
/* setup PCI configuration registers */
|
||||
d = (PCICirrusVGAState *)pci_register_device(bus, "Cirrus VGA",
|
||||
sizeof(PCICirrusVGAState),
|
||||
d = (PCICirrusVGAState *)pci_register_device(bus, "Cirrus VGA",
|
||||
sizeof(PCICirrusVGAState),
|
||||
-1, NULL, NULL);
|
||||
pci_conf = d->dev.config;
|
||||
pci_conf[0x00] = (uint8_t) (PCI_VENDOR_CIRRUS & 0xff);
|
||||
@ -3250,7 +3250,7 @@ void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base,
|
||||
|
||||
/* setup VGA */
|
||||
s = &d->cirrus_vga;
|
||||
vga_common_init((VGAState *)s,
|
||||
vga_common_init((VGAState *)s,
|
||||
ds, vga_ram_base, vga_ram_offset, vga_ram_size);
|
||||
cirrus_init_common(s, device_id, 1);
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU Cirrus CLGD 54xx VGA Emulator.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU Cirrus CLGD 54xx VGA Emulator.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -34,13 +34,13 @@
|
||||
#define PUTPIXEL() ROP_OP(((uint32_t *)d)[0], col)
|
||||
#else
|
||||
#error unsupported DEPTH
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static void
|
||||
glue(glue(glue(cirrus_patternfill_, ROP_NAME), _),DEPTH)
|
||||
(CirrusVGAState * s, uint8_t * dst,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
int bltwidth, int bltheight)
|
||||
{
|
||||
uint8_t *d;
|
||||
@ -94,8 +94,8 @@ glue(glue(glue(cirrus_patternfill_, ROP_NAME), _),DEPTH)
|
||||
static void
|
||||
glue(glue(glue(cirrus_colorexpand_transp_, ROP_NAME), _),DEPTH)
|
||||
(CirrusVGAState * s, uint8_t * dst,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
int bltwidth, int bltheight)
|
||||
{
|
||||
uint8_t *d;
|
||||
@ -143,8 +143,8 @@ glue(glue(glue(cirrus_colorexpand_transp_, ROP_NAME), _),DEPTH)
|
||||
static void
|
||||
glue(glue(glue(cirrus_colorexpand_, ROP_NAME), _),DEPTH)
|
||||
(CirrusVGAState * s, uint8_t * dst,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
int bltwidth, int bltheight)
|
||||
{
|
||||
uint32_t colors[2];
|
||||
@ -179,8 +179,8 @@ glue(glue(glue(cirrus_colorexpand_, ROP_NAME), _),DEPTH)
|
||||
static void
|
||||
glue(glue(glue(cirrus_colorexpand_pattern_transp_, ROP_NAME), _),DEPTH)
|
||||
(CirrusVGAState * s, uint8_t * dst,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
int bltwidth, int bltheight)
|
||||
{
|
||||
uint8_t *d;
|
||||
@ -223,8 +223,8 @@ glue(glue(glue(cirrus_colorexpand_pattern_transp_, ROP_NAME), _),DEPTH)
|
||||
static void
|
||||
glue(glue(glue(cirrus_colorexpand_pattern_, ROP_NAME), _),DEPTH)
|
||||
(CirrusVGAState * s, uint8_t * dst,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
const uint8_t * src,
|
||||
int dstpitch, int srcpitch,
|
||||
int bltwidth, int bltheight)
|
||||
{
|
||||
uint32_t colors[2];
|
||||
@ -254,10 +254,10 @@ glue(glue(glue(cirrus_colorexpand_pattern_, ROP_NAME), _),DEPTH)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
glue(glue(glue(cirrus_fill_, ROP_NAME), _),DEPTH)
|
||||
(CirrusVGAState *s,
|
||||
uint8_t *dst, int dst_pitch,
|
||||
uint8_t *dst, int dst_pitch,
|
||||
int width, int height)
|
||||
{
|
||||
uint8_t *d, *d1;
|
||||
|
48
hw/cuda.c
48
hw/cuda.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU CUDA support
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -94,7 +94,7 @@
|
||||
#define RTC_OFFSET 2082844800
|
||||
|
||||
typedef struct CUDATimer {
|
||||
int index;
|
||||
int index;
|
||||
uint16_t latch;
|
||||
uint16_t counter_value; /* counter value at load time */
|
||||
int64_t load_time;
|
||||
@ -116,10 +116,10 @@ typedef struct CUDAState {
|
||||
uint8_t anh; /* A-side data, no handshake */
|
||||
|
||||
CUDATimer timers[2];
|
||||
|
||||
|
||||
uint8_t last_b; /* last value of B register */
|
||||
uint8_t last_acr; /* last value of B register */
|
||||
|
||||
|
||||
int data_in_size;
|
||||
int data_in_index;
|
||||
int data_out_index;
|
||||
@ -135,9 +135,9 @@ static CUDAState cuda_state;
|
||||
ADBBusState adb_bus;
|
||||
|
||||
static void cuda_update(CUDAState *s);
|
||||
static void cuda_receive_packet_from_host(CUDAState *s,
|
||||
static void cuda_receive_packet_from_host(CUDAState *s,
|
||||
const uint8_t *data, int len);
|
||||
static void cuda_timer_update(CUDAState *s, CUDATimer *ti,
|
||||
static void cuda_timer_update(CUDAState *s, CUDATimer *ti,
|
||||
int64_t current_time);
|
||||
|
||||
static void cuda_update_irq(CUDAState *s)
|
||||
@ -154,7 +154,7 @@ static unsigned int get_counter(CUDATimer *s)
|
||||
int64_t d;
|
||||
unsigned int counter;
|
||||
|
||||
d = muldiv64(qemu_get_clock(vm_clock) - s->load_time,
|
||||
d = muldiv64(qemu_get_clock(vm_clock) - s->load_time,
|
||||
CUDA_TIMER_FREQ, ticks_per_sec);
|
||||
if (s->index == 0) {
|
||||
/* the timer goes down from latch to -1 (period of latch + 2) */
|
||||
@ -162,7 +162,7 @@ static unsigned int get_counter(CUDATimer *s)
|
||||
counter = (s->counter_value - d) & 0xffff;
|
||||
} else {
|
||||
counter = (d - (s->counter_value + 1)) % (s->latch + 2);
|
||||
counter = (s->latch - counter) & 0xffff;
|
||||
counter = (s->latch - counter) & 0xffff;
|
||||
}
|
||||
} else {
|
||||
counter = (s->counter_value - d) & 0xffff;
|
||||
@ -187,16 +187,16 @@ static int64_t get_next_irq_time(CUDATimer *s, int64_t current_time)
|
||||
unsigned int counter;
|
||||
|
||||
/* current counter value */
|
||||
d = muldiv64(current_time - s->load_time,
|
||||
d = muldiv64(current_time - s->load_time,
|
||||
CUDA_TIMER_FREQ, ticks_per_sec);
|
||||
/* the timer goes down from latch to -1 (period of latch + 2) */
|
||||
if (d <= (s->counter_value + 1)) {
|
||||
counter = (s->counter_value - d) & 0xffff;
|
||||
} else {
|
||||
counter = (d - (s->counter_value + 1)) % (s->latch + 2);
|
||||
counter = (s->latch - counter) & 0xffff;
|
||||
counter = (s->latch - counter) & 0xffff;
|
||||
}
|
||||
|
||||
|
||||
/* Note: we consider the irq is raised on 0 */
|
||||
if (counter == 0xffff) {
|
||||
next_time = d + s->latch + 1;
|
||||
@ -207,18 +207,18 @@ static int64_t get_next_irq_time(CUDATimer *s, int64_t current_time)
|
||||
}
|
||||
#if 0
|
||||
#ifdef DEBUG_CUDA
|
||||
printf("latch=%d counter=%" PRId64 " delta_next=%" PRId64 "\n",
|
||||
printf("latch=%d counter=%" PRId64 " delta_next=%" PRId64 "\n",
|
||||
s->latch, d, next_time - d);
|
||||
#endif
|
||||
#endif
|
||||
next_time = muldiv64(next_time, ticks_per_sec, CUDA_TIMER_FREQ) +
|
||||
next_time = muldiv64(next_time, ticks_per_sec, CUDA_TIMER_FREQ) +
|
||||
s->load_time;
|
||||
if (next_time <= current_time)
|
||||
next_time = current_time + 1;
|
||||
return next_time;
|
||||
}
|
||||
|
||||
static void cuda_timer_update(CUDAState *s, CUDATimer *ti,
|
||||
static void cuda_timer_update(CUDAState *s, CUDATimer *ti,
|
||||
int64_t current_time)
|
||||
{
|
||||
if (!ti->timer)
|
||||
@ -296,7 +296,7 @@ static uint32_t cuda_readb(void *opaque, target_phys_addr_t addr)
|
||||
break;
|
||||
case 13:
|
||||
val = s->ifr;
|
||||
if (s->ifr & s->ier)
|
||||
if (s->ifr & s->ier)
|
||||
val |= 0x80;
|
||||
break;
|
||||
case 14:
|
||||
@ -317,7 +317,7 @@ static uint32_t cuda_readb(void *opaque, target_phys_addr_t addr)
|
||||
static void cuda_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)
|
||||
{
|
||||
CUDAState *s = opaque;
|
||||
|
||||
|
||||
addr = (addr >> 9) & 0xf;
|
||||
#ifdef DEBUG_CUDA
|
||||
printf("cuda: write: reg=0x%x val=%02x\n", addr, val);
|
||||
@ -470,7 +470,7 @@ static void cuda_update(CUDAState *s)
|
||||
}
|
||||
}
|
||||
|
||||
static void cuda_send_packet_to_host(CUDAState *s,
|
||||
static void cuda_send_packet_to_host(CUDAState *s,
|
||||
const uint8_t *data, int len)
|
||||
{
|
||||
#ifdef DEBUG_CUDA_PACKET
|
||||
@ -502,12 +502,12 @@ static void cuda_adb_poll(void *opaque)
|
||||
obuf[1] = 0x40; /* polled data */
|
||||
cuda_send_packet_to_host(s, obuf, olen + 2);
|
||||
}
|
||||
qemu_mod_timer(s->adb_poll_timer,
|
||||
qemu_get_clock(vm_clock) +
|
||||
qemu_mod_timer(s->adb_poll_timer,
|
||||
qemu_get_clock(vm_clock) +
|
||||
(ticks_per_sec / CUDA_ADB_POLL_FREQ));
|
||||
}
|
||||
|
||||
static void cuda_receive_packet(CUDAState *s,
|
||||
static void cuda_receive_packet(CUDAState *s,
|
||||
const uint8_t *data, int len)
|
||||
{
|
||||
uint8_t obuf[16];
|
||||
@ -519,8 +519,8 @@ static void cuda_receive_packet(CUDAState *s,
|
||||
if (autopoll != s->autopoll) {
|
||||
s->autopoll = autopoll;
|
||||
if (autopoll) {
|
||||
qemu_mod_timer(s->adb_poll_timer,
|
||||
qemu_get_clock(vm_clock) +
|
||||
qemu_mod_timer(s->adb_poll_timer,
|
||||
qemu_get_clock(vm_clock) +
|
||||
(ticks_per_sec / CUDA_ADB_POLL_FREQ));
|
||||
} else {
|
||||
qemu_del_timer(s->adb_poll_timer);
|
||||
@ -562,7 +562,7 @@ static void cuda_receive_packet(CUDAState *s,
|
||||
}
|
||||
}
|
||||
|
||||
static void cuda_receive_packet_from_host(CUDAState *s,
|
||||
static void cuda_receive_packet_from_host(CUDAState *s,
|
||||
const uint8_t *data, int len)
|
||||
{
|
||||
#ifdef DEBUG_CUDA_PACKET
|
||||
|
@ -1618,7 +1618,7 @@ static int nic_load(QEMUFile * f, void *opaque, int version_id)
|
||||
for (i = 0; i < 3; i++)
|
||||
qemu_get_be32s(f, &s->region[i]);
|
||||
qemu_get_buffer(f, s->macaddr, 6);
|
||||
for (i = 0; i < 19; i++)
|
||||
for (i = 0; i < 19; i++)
|
||||
qemu_get_be32s(f, &s->statcounter[i]);
|
||||
for (i = 0; i < 32; i++)
|
||||
qemu_get_be16s(f, &s->mdimem[i]);
|
||||
@ -1697,7 +1697,7 @@ static void nic_save(QEMUFile * f, void *opaque)
|
||||
for (i = 0; i < 3; i++)
|
||||
qemu_put_be32s(f, &s->region[i]);
|
||||
qemu_put_buffer(f, s->macaddr, 6);
|
||||
for (i = 0; i < 19; i++)
|
||||
for (i = 0; i < 19; i++)
|
||||
qemu_put_be32s(f, &s->statcounter[i]);
|
||||
for (i = 0; i < 32; i++)
|
||||
qemu_put_be16s(f, &s->mdimem[i]);
|
||||
|
6
hw/esp.c
6
hw/esp.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU ESP/NCR53C9x emulation
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2005-2006 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -531,7 +531,7 @@ static void esp_save(QEMUFile *f, void *opaque)
|
||||
static int esp_load(QEMUFile *f, void *opaque, int version_id)
|
||||
{
|
||||
ESPState *s = opaque;
|
||||
|
||||
|
||||
if (version_id != 3)
|
||||
return -EINVAL; // Cannot emulate 2
|
||||
|
||||
|
18
hw/fdc.c
18
hw/fdc.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU Floppy disk emulator (Intel 82078)
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003, 2007 Jocelyn Mayer
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -217,7 +217,7 @@ static fd_format_t fd_formats[] = {
|
||||
{ FDRIVE_DRV_120, FDRIVE_DISK_288, 9, 40, 0, "180 kB 5\"1/4", },
|
||||
{ FDRIVE_DRV_120, FDRIVE_DISK_288, 10, 41, 1, "410 kB 5\"1/4", },
|
||||
{ FDRIVE_DRV_120, FDRIVE_DISK_288, 10, 42, 1, "420 kB 5\"1/4", },
|
||||
/* 320 kB 5"1/4 floppy disks */
|
||||
/* 320 kB 5"1/4 floppy disks */
|
||||
{ FDRIVE_DRV_120, FDRIVE_DISK_288, 8, 40, 1, "320 kB 5\"1/4", },
|
||||
{ FDRIVE_DRV_120, FDRIVE_DISK_288, 8, 40, 0, "160 kB 5\"1/4", },
|
||||
/* 360 kB must match 5"1/4 better than 3"1/2... */
|
||||
@ -467,7 +467,7 @@ static uint32_t fdctrl_read_mem (void *opaque, target_phys_addr_t reg)
|
||||
return fdctrl_read(opaque, (uint32_t)reg);
|
||||
}
|
||||
|
||||
static void fdctrl_write_mem (void *opaque,
|
||||
static void fdctrl_write_mem (void *opaque,
|
||||
target_phys_addr_t reg, uint32_t value)
|
||||
{
|
||||
fdctrl_write(opaque, (uint32_t)reg, value);
|
||||
@ -578,7 +578,7 @@ static void fdctrl_external_reset(void *opaque)
|
||||
fdctrl_reset(s, 0);
|
||||
}
|
||||
|
||||
fdctrl_t *fdctrl_init (qemu_irq irq, int dma_chann, int mem_mapped,
|
||||
fdctrl_t *fdctrl_init (qemu_irq irq, int dma_chann, int mem_mapped,
|
||||
target_phys_addr_t io_base,
|
||||
BlockDriverState **fds)
|
||||
{
|
||||
@ -590,7 +590,7 @@ fdctrl_t *fdctrl_init (qemu_irq irq, int dma_chann, int mem_mapped,
|
||||
fdctrl = qemu_mallocz(sizeof(fdctrl_t));
|
||||
if (!fdctrl)
|
||||
return NULL;
|
||||
fdctrl->result_timer = qemu_new_timer(vm_clock,
|
||||
fdctrl->result_timer = qemu_new_timer(vm_clock,
|
||||
fdctrl_result_timer, fdctrl);
|
||||
|
||||
fdctrl->version = 0x90; /* Intel 82078 controller */
|
||||
@ -842,7 +842,7 @@ static void fdctrl_write_rate (fdctrl_t *fdctrl, uint32_t value)
|
||||
static int fdctrl_media_changed(fdrive_t *drv)
|
||||
{
|
||||
int ret;
|
||||
if (!drv->bs)
|
||||
if (!drv->bs)
|
||||
return 0;
|
||||
ret = bdrv_media_changed(drv->bs);
|
||||
if (ret) {
|
||||
@ -1141,7 +1141,7 @@ static int fdctrl_transfer_handler (void *opaque, int nchan,
|
||||
cur_drv->sect = 1;
|
||||
if (FD_MULTI_TRACK(fdctrl->data_state)) {
|
||||
if (cur_drv->head == 0 &&
|
||||
(cur_drv->flags & FDISK_DBL_SIDES) != 0) {
|
||||
(cur_drv->flags & FDISK_DBL_SIDES) != 0) {
|
||||
cur_drv->head = 1;
|
||||
} else {
|
||||
cur_drv->head = 0;
|
||||
@ -1732,7 +1732,7 @@ enqueue:
|
||||
FLOPPY_DPRINTF("treat READ_ID command\n");
|
||||
/* XXX: should set main status register to busy */
|
||||
cur_drv->head = (fdctrl->fifo[1] >> 2) & 1;
|
||||
qemu_mod_timer(fdctrl->result_timer,
|
||||
qemu_mod_timer(fdctrl->result_timer,
|
||||
qemu_get_clock(vm_clock) + (ticks_per_sec / 50));
|
||||
break;
|
||||
case 0x4C:
|
||||
|
@ -2,7 +2,7 @@
|
||||
* QEMU Grackle (heathrow PPC) PCI host
|
||||
*
|
||||
* Copyright (c) 2006 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -95,13 +95,13 @@ PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic)
|
||||
s->bus = pci_register_bus(pci_grackle_set_irq, pci_grackle_map_irq,
|
||||
pic, 0, 0);
|
||||
|
||||
pci_mem_config = cpu_register_io_memory(0, pci_grackle_config_read,
|
||||
pci_mem_config = cpu_register_io_memory(0, pci_grackle_config_read,
|
||||
pci_grackle_config_write, s);
|
||||
pci_mem_data = cpu_register_io_memory(0, pci_grackle_read,
|
||||
pci_grackle_write, s);
|
||||
cpu_register_physical_memory(base, 0x1000, pci_mem_config);
|
||||
cpu_register_physical_memory(base + 0x00200000, 0x1000, pci_mem_data);
|
||||
d = pci_register_device(s->bus, "Grackle host bridge", sizeof(PCIDevice),
|
||||
d = pci_register_device(s->bus, "Grackle host bridge", sizeof(PCIDevice),
|
||||
0, NULL, NULL);
|
||||
d->config[0x00] = 0x57; // vendor_id
|
||||
d->config[0x01] = 0x10;
|
||||
@ -118,12 +118,12 @@ PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic)
|
||||
d->config[0x1a] = 0x00; // subordinate_bus
|
||||
d->config[0x1c] = 0x00;
|
||||
d->config[0x1d] = 0x00;
|
||||
|
||||
|
||||
d->config[0x20] = 0x00; // memory_base
|
||||
d->config[0x21] = 0x00;
|
||||
d->config[0x22] = 0x01; // memory_limit
|
||||
d->config[0x23] = 0x00;
|
||||
|
||||
|
||||
d->config[0x24] = 0x00; // prefetchable_memory_base
|
||||
d->config[0x25] = 0x00;
|
||||
d->config[0x26] = 0x00; // prefetchable_memory_limit
|
||||
@ -145,12 +145,12 @@ PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic)
|
||||
d->config[0x1a] = 0x1; // subordinate_bus
|
||||
d->config[0x1c] = 0x10; // io_base
|
||||
d->config[0x1d] = 0x20; // io_limit
|
||||
|
||||
|
||||
d->config[0x20] = 0x80; // memory_base
|
||||
d->config[0x21] = 0x80;
|
||||
d->config[0x22] = 0x90; // memory_limit
|
||||
d->config[0x23] = 0x80;
|
||||
|
||||
|
||||
d->config[0x24] = 0x00; // prefetchable_memory_base
|
||||
d->config[0x25] = 0x84;
|
||||
d->config[0x26] = 0x00; // prefetchable_memory_limit
|
||||
|
14
hw/gt64xxx.c
14
hw/gt64xxx.c
@ -2,7 +2,7 @@
|
||||
* QEMU GT64120 PCI host
|
||||
*
|
||||
* Copyright (c) 2006,2007 Aurelien Jarno
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -287,10 +287,10 @@ static void gt64120_pci_mapping(GT64120State *s)
|
||||
/* Update IO mapping */
|
||||
if ((s->regs[GT_PCI0IOLD] & 0x7f) <= s->regs[GT_PCI0IOHD])
|
||||
{
|
||||
/* Unmap old IO address */
|
||||
/* Unmap old IO address */
|
||||
if (s->PCI0IO_length)
|
||||
{
|
||||
cpu_register_physical_memory(s->PCI0IO_start, s->PCI0IO_length, IO_MEM_UNASSIGNED);
|
||||
cpu_register_physical_memory(s->PCI0IO_start, s->PCI0IO_length, IO_MEM_UNASSIGNED);
|
||||
}
|
||||
/* Map new IO address */
|
||||
s->PCI0IO_start = s->regs[GT_PCI0IOLD] << 21;
|
||||
@ -604,7 +604,7 @@ static uint32_t gt64120_readl (void *opaque,
|
||||
case GT_CPUERR_DATAHI:
|
||||
case GT_CPUERR_PARITY:
|
||||
/* Emulated memory has no error, always return the initial
|
||||
values */
|
||||
values */
|
||||
val = s->regs[saddr];
|
||||
break;
|
||||
|
||||
@ -614,7 +614,7 @@ static uint32_t gt64120_readl (void *opaque,
|
||||
/* Reading those register should empty all FIFO on the PCI
|
||||
bus, which are not emulated. The return value should be
|
||||
a random value that should be ignored. */
|
||||
val = 0xc000ffee;
|
||||
val = 0xc000ffee;
|
||||
break;
|
||||
|
||||
/* ECC */
|
||||
@ -624,7 +624,7 @@ static uint32_t gt64120_readl (void *opaque,
|
||||
case GT_ECC_CALC:
|
||||
case GT_ECC_ERRADDR:
|
||||
/* Emulated memory has no error, always return the initial
|
||||
values */
|
||||
values */
|
||||
val = s->regs[saddr];
|
||||
break;
|
||||
|
||||
@ -663,7 +663,7 @@ static uint32_t gt64120_readl (void *opaque,
|
||||
val = s->regs[saddr];
|
||||
break;
|
||||
case GT_PCI0_IACK:
|
||||
/* Read the IRQ number */
|
||||
/* Read the IRQ number */
|
||||
val = pic_read_irq(isa_pic);
|
||||
break;
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Heathrow PIC support (standard PowerMac PIC)
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2005 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -88,7 +88,7 @@ static uint32_t pic_readl (void *opaque, target_phys_addr_t addr)
|
||||
HeathrowPIC *pic;
|
||||
unsigned int n;
|
||||
uint32_t value;
|
||||
|
||||
|
||||
n = ((addr & 0xfff) - 0x10) >> 4;
|
||||
if (n >= 2) {
|
||||
value = 0;
|
||||
@ -159,7 +159,7 @@ static void heathrow_pic_set_irq(void *opaque, int num, int level)
|
||||
qemu_irq *heathrow_pic_init(int *pmem_index)
|
||||
{
|
||||
HeathrowPICS *s;
|
||||
|
||||
|
||||
s = qemu_mallocz(sizeof(HeathrowPICS));
|
||||
s->pics[0].level_triggered = 0;
|
||||
s->pics[1].level_triggered = 0x1ff00000;
|
||||
|
2
hw/i2c.c
2
hw/i2c.c
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QEMU I2C bus interface.
|
||||
*
|
||||
* Copyright (c) 2007 CodeSourcery.
|
||||
|
16
hw/i8254.c
16
hw/i8254.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU 8253/8254 interval timer emulation
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003-2004 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -121,7 +121,7 @@ int pit_get_out(PITState *pit, int channel, int64_t current_time)
|
||||
}
|
||||
|
||||
/* return -1 if no transition will occur. */
|
||||
static int64_t pit_get_next_transition_time(PITChannelState *s,
|
||||
static int64_t pit_get_next_transition_time(PITChannelState *s,
|
||||
int64_t current_time)
|
||||
{
|
||||
uint64_t d, next_time, base;
|
||||
@ -147,7 +147,7 @@ static int64_t pit_get_next_transition_time(PITChannelState *s,
|
||||
case 3:
|
||||
base = (d / s->count) * s->count;
|
||||
period2 = ((s->count + 1) >> 1);
|
||||
if ((d - base) < period2)
|
||||
if ((d - base) < period2)
|
||||
next_time = base + period2;
|
||||
else
|
||||
next_time = base + s->count;
|
||||
@ -309,7 +309,7 @@ static uint32_t pit_ioport_read(void *opaque, uint32_t addr)
|
||||
PITState *pit = opaque;
|
||||
int ret, count;
|
||||
PITChannelState *s;
|
||||
|
||||
|
||||
addr &= 3;
|
||||
s = &pit->channels[addr];
|
||||
if (s->status_latched) {
|
||||
@ -369,7 +369,7 @@ static void pit_irq_timer_update(PITChannelState *s, int64_t current_time)
|
||||
qemu_set_irq(s->irq, irq_level);
|
||||
#ifdef DEBUG_PIT
|
||||
printf("irq_level=%d next_delay=%f\n",
|
||||
irq_level,
|
||||
irq_level,
|
||||
(double)(expire_time - current_time) / ticks_per_sec);
|
||||
#endif
|
||||
s->next_transition_time = expire_time;
|
||||
@ -391,7 +391,7 @@ static void pit_save(QEMUFile *f, void *opaque)
|
||||
PITState *pit = opaque;
|
||||
PITChannelState *s;
|
||||
int i;
|
||||
|
||||
|
||||
for(i = 0; i < 3; i++) {
|
||||
s = &pit->channels[i];
|
||||
qemu_put_be32s(f, &s->count);
|
||||
@ -419,7 +419,7 @@ static int pit_load(QEMUFile *f, void *opaque, int version_id)
|
||||
PITState *pit = opaque;
|
||||
PITChannelState *s;
|
||||
int i;
|
||||
|
||||
|
||||
if (version_id != 1)
|
||||
return -EINVAL;
|
||||
|
||||
|
28
hw/i8259.c
28
hw/i8259.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU 8259 interrupt controller emulation
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003-2004 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -152,10 +152,10 @@ void pic_update_irq(PicState2 *s)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < 2; i++) {
|
||||
printf("pic%d: imr=%x irr=%x padd=%d\n",
|
||||
i, s->pics[i].imr, s->pics[i].irr,
|
||||
printf("pic%d: imr=%x irr=%x padd=%d\n",
|
||||
i, s->pics[i].imr, s->pics[i].irr,
|
||||
s->pics[i].priority_add);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
printf("pic: cpu_interrupt\n");
|
||||
@ -243,10 +243,10 @@ int pic_read_irq(PicState2 *s)
|
||||
intno = s->pics[0].irq_base + irq;
|
||||
}
|
||||
pic_update_irq(s);
|
||||
|
||||
|
||||
#ifdef DEBUG_IRQ_LATENCY
|
||||
printf("IRQ%d latency=%0.3fus\n",
|
||||
irq,
|
||||
printf("IRQ%d latency=%0.3fus\n",
|
||||
irq,
|
||||
(double)(qemu_get_clock(vm_clock) - irq_time[irq]) * 1000000.0 / ticks_per_sec);
|
||||
#endif
|
||||
#if defined(DEBUG_PIC)
|
||||
@ -429,7 +429,7 @@ uint32_t pic_intack_read(PicState2 *s)
|
||||
ret = pic_poll_read(&s->pics[1], 0x80) + 8;
|
||||
/* Prepare for ISR read */
|
||||
s->pics[0].read_reg_select = 1;
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -448,7 +448,7 @@ static uint32_t elcr_ioport_read(void *opaque, uint32_t addr1)
|
||||
static void pic_save(QEMUFile *f, void *opaque)
|
||||
{
|
||||
PicState *s = opaque;
|
||||
|
||||
|
||||
qemu_put_8s(f, &s->last_irr);
|
||||
qemu_put_8s(f, &s->irr);
|
||||
qemu_put_8s(f, &s->imr);
|
||||
@ -470,7 +470,7 @@ static void pic_save(QEMUFile *f, void *opaque)
|
||||
static int pic_load(QEMUFile *f, void *opaque, int version_id)
|
||||
{
|
||||
PicState *s = opaque;
|
||||
|
||||
|
||||
if (version_id != 1)
|
||||
return -EINVAL;
|
||||
|
||||
@ -510,15 +510,15 @@ void pic_info(void)
|
||||
{
|
||||
int i;
|
||||
PicState *s;
|
||||
|
||||
|
||||
if (!isa_pic)
|
||||
return;
|
||||
|
||||
for(i=0;i<2;i++) {
|
||||
s = &isa_pic->pics[i];
|
||||
term_printf("pic%d: irr=%02x imr=%02x isr=%02x hprio=%d irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n",
|
||||
i, s->irr, s->imr, s->isr, s->priority_add,
|
||||
s->irq_base, s->read_reg_select, s->elcr,
|
||||
i, s->irr, s->imr, s->isr, s->priority_add,
|
||||
s->irq_base, s->read_reg_select, s->elcr,
|
||||
s->special_fully_nested_mode);
|
||||
}
|
||||
}
|
||||
|
150
hw/ide.c
150
hw/ide.c
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* QEMU IDE disk and CD-ROM Emulator
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
* Copyright (c) 2006 Openedhand Ltd.
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -156,7 +156,7 @@
|
||||
#define WIN_WRITEDMA_ONCE 0xCB /* 28-Bit - without retries */
|
||||
#define WIN_WRITEDMA_QUEUED 0xCC /* write sectors using Queued DMA transfers */
|
||||
#define CFA_WRITE_MULTI_WO_ERASE 0xCD /* CFA Write multiple without erase */
|
||||
#define WIN_GETMEDIASTATUS 0xDA
|
||||
#define WIN_GETMEDIASTATUS 0xDA
|
||||
#define WIN_ACKMEDIACHANGE 0xDB /* ATA-1, ATA-2 vendor */
|
||||
#define WIN_POSTBOOT 0xDC
|
||||
#define WIN_PREBOOT 0xDD
|
||||
@ -248,12 +248,12 @@
|
||||
#define GPCMD_VERIFY_10 0x2f
|
||||
#define GPCMD_WRITE_10 0x2a
|
||||
#define GPCMD_WRITE_AND_VERIFY_10 0x2e
|
||||
/* This is listed as optional in ATAPI 2.6, but is (curiously)
|
||||
/* This is listed as optional in ATAPI 2.6, but is (curiously)
|
||||
* missing from Mt. Fuji, Table 57. It _is_ mentioned in Mt. Fuji
|
||||
* Table 377 as an MMC command for SCSi devices though... Most ATAPI
|
||||
* drives support it. */
|
||||
#define GPCMD_SET_SPEED 0xbb
|
||||
/* This seems to be a SCSI specific CD-ROM opcode
|
||||
/* This seems to be a SCSI specific CD-ROM opcode
|
||||
* to play data at track/index */
|
||||
#define GPCMD_PLAYAUDIO_TI 0x48
|
||||
/*
|
||||
@ -339,7 +339,7 @@ typedef struct IDEState {
|
||||
/* set for lba48 access */
|
||||
uint8_t lba48;
|
||||
/* depends on bit 4 in select, only meaningful for drive 0 */
|
||||
struct IDEState *cur_drive;
|
||||
struct IDEState *cur_drive;
|
||||
BlockDriverState *bs;
|
||||
/* ATAPI specific */
|
||||
uint8_t sense_key;
|
||||
@ -392,7 +392,7 @@ typedef struct BMDMAState {
|
||||
uint8_t cmd;
|
||||
uint8_t status;
|
||||
uint32_t addr;
|
||||
|
||||
|
||||
struct PCIIDEState *pci_dev;
|
||||
/* current transfer state */
|
||||
uint32_t cur_addr;
|
||||
@ -457,11 +457,11 @@ static void ide_identify(IDEState *s)
|
||||
memset(s->io_buffer, 0, 512);
|
||||
p = (uint16_t *)s->io_buffer;
|
||||
put_le16(p + 0, 0x0040);
|
||||
put_le16(p + 1, s->cylinders);
|
||||
put_le16(p + 1, s->cylinders);
|
||||
put_le16(p + 3, s->heads);
|
||||
put_le16(p + 4, 512 * s->sectors); /* XXX: retired, remove ? */
|
||||
put_le16(p + 5, 512); /* XXX: retired, remove ? */
|
||||
put_le16(p + 6, s->sectors);
|
||||
put_le16(p + 6, s->sectors);
|
||||
snprintf(buf, sizeof(buf), "QM%05d", s->drive_serial);
|
||||
padstr((uint8_t *)(p + 10), buf, 20); /* serial number */
|
||||
put_le16(p + 20, 3); /* XXX: retired, remove ? */
|
||||
@ -469,7 +469,7 @@ static void ide_identify(IDEState *s)
|
||||
put_le16(p + 22, 4); /* ecc bytes */
|
||||
padstr((uint8_t *)(p + 23), QEMU_VERSION, 8); /* firmware version */
|
||||
padstr((uint8_t *)(p + 27), "QEMU HARDDISK", 40); /* model */
|
||||
#if MAX_MULT_SECTORS > 1
|
||||
#if MAX_MULT_SECTORS > 1
|
||||
put_le16(p + 47, 0x8000 | MAX_MULT_SECTORS);
|
||||
#endif
|
||||
put_le16(p + 48, 1); /* dword I/O */
|
||||
@ -666,7 +666,7 @@ static inline void ide_set_irq(IDEState *s)
|
||||
}
|
||||
|
||||
/* prepare data transfer and tell what to do after */
|
||||
static void ide_transfer_start(IDEState *s, uint8_t *buf, int size,
|
||||
static void ide_transfer_start(IDEState *s, uint8_t *buf, int size,
|
||||
EndTransferFunc *end_transfer_func)
|
||||
{
|
||||
s->end_transfer_func = end_transfer_func;
|
||||
@ -771,7 +771,7 @@ static int dma_buf_rw(BMDMAState *bm, int is_write)
|
||||
|
||||
for(;;) {
|
||||
l = s->io_buffer_size - s->io_buffer_index;
|
||||
if (l <= 0)
|
||||
if (l <= 0)
|
||||
break;
|
||||
if (bm->cur_prd_len == 0) {
|
||||
/* end of table (with a fail safe of one page) */
|
||||
@ -793,10 +793,10 @@ static int dma_buf_rw(BMDMAState *bm, int is_write)
|
||||
l = bm->cur_prd_len;
|
||||
if (l > 0) {
|
||||
if (is_write) {
|
||||
cpu_physical_memory_write(bm->cur_prd_addr,
|
||||
cpu_physical_memory_write(bm->cur_prd_addr,
|
||||
s->io_buffer + s->io_buffer_index, l);
|
||||
} else {
|
||||
cpu_physical_memory_read(bm->cur_prd_addr,
|
||||
cpu_physical_memory_read(bm->cur_prd_addr,
|
||||
s->io_buffer + s->io_buffer_index, l);
|
||||
}
|
||||
bm->cur_prd_addr += l;
|
||||
@ -847,7 +847,7 @@ static void ide_read_dma_cb(void *opaque, int ret)
|
||||
#ifdef DEBUG_AIO
|
||||
printf("aio_read: sector_num=%lld n=%d\n", sector_num, n);
|
||||
#endif
|
||||
bm->aiocb = bdrv_aio_read(s->bs, sector_num, s->io_buffer, n,
|
||||
bm->aiocb = bdrv_aio_read(s->bs, sector_num, s->io_buffer, n,
|
||||
ide_read_dma_cb, bm);
|
||||
}
|
||||
|
||||
@ -923,7 +923,7 @@ static void ide_sector_write(IDEState *s)
|
||||
ide_transfer_start(s, s->io_buffer, 512 * n1, ide_sector_write);
|
||||
}
|
||||
ide_set_sector(s, sector_num + n);
|
||||
|
||||
|
||||
bm->aiocb = bdrv_aio_write(s->bs, sector_num, s->io_buffer, n,
|
||||
ide_sector_write_aio_cb, bm);
|
||||
}
|
||||
@ -969,7 +969,7 @@ static void ide_write_dma_cb(void *opaque, int ret)
|
||||
#ifdef DEBUG_AIO
|
||||
printf("aio_write: sector_num=%lld n=%d\n", sector_num, n);
|
||||
#endif
|
||||
bm->aiocb = bdrv_aio_write(s->bs, sector_num, s->io_buffer, n,
|
||||
bm->aiocb = bdrv_aio_write(s->bs, sector_num, s->io_buffer, n,
|
||||
ide_write_dma_cb, bm);
|
||||
}
|
||||
|
||||
@ -1051,7 +1051,7 @@ static void cd_data_to_raw(uint8_t *buf, int lba)
|
||||
memset(buf, 0, 288);
|
||||
}
|
||||
|
||||
static int cd_read_sector(BlockDriverState *bs, int lba, uint8_t *buf,
|
||||
static int cd_read_sector(BlockDriverState *bs, int lba, uint8_t *buf,
|
||||
int sector_size)
|
||||
{
|
||||
int ret;
|
||||
@ -1077,10 +1077,10 @@ static void ide_atapi_io_error(IDEState *s, int ret)
|
||||
{
|
||||
/* XXX: handle more errors */
|
||||
if (ret == -ENOMEDIUM) {
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ASC_MEDIUM_NOT_PRESENT);
|
||||
} else {
|
||||
ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
|
||||
ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
|
||||
ASC_LOGICAL_BLOCK_OOR);
|
||||
}
|
||||
}
|
||||
@ -1090,7 +1090,7 @@ static void ide_atapi_cmd_reply_end(IDEState *s)
|
||||
{
|
||||
int byte_count_limit, size, ret;
|
||||
#ifdef DEBUG_IDE_ATAPI
|
||||
printf("reply: tx_size=%d elem_tx_size=%d index=%d\n",
|
||||
printf("reply: tx_size=%d elem_tx_size=%d index=%d\n",
|
||||
s->packet_transfer_size,
|
||||
s->elementary_transfer_size,
|
||||
s->io_buffer_index);
|
||||
@ -1122,7 +1122,7 @@ static void ide_atapi_cmd_reply_end(IDEState *s)
|
||||
size = s->cd_sector_size - s->io_buffer_index;
|
||||
if (size > s->elementary_transfer_size)
|
||||
size = s->elementary_transfer_size;
|
||||
ide_transfer_start(s, s->io_buffer + s->io_buffer_index,
|
||||
ide_transfer_start(s, s->io_buffer + s->io_buffer_index,
|
||||
size, ide_atapi_cmd_reply_end);
|
||||
s->packet_transfer_size -= size;
|
||||
s->elementary_transfer_size -= size;
|
||||
@ -1151,7 +1151,7 @@ static void ide_atapi_cmd_reply_end(IDEState *s)
|
||||
if (size > (s->cd_sector_size - s->io_buffer_index))
|
||||
size = (s->cd_sector_size - s->io_buffer_index);
|
||||
}
|
||||
ide_transfer_start(s, s->io_buffer + s->io_buffer_index,
|
||||
ide_transfer_start(s, s->io_buffer + s->io_buffer_index,
|
||||
size, ide_atapi_cmd_reply_end);
|
||||
s->packet_transfer_size -= size;
|
||||
s->elementary_transfer_size -= size;
|
||||
@ -1246,7 +1246,7 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret)
|
||||
bm->aiocb = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
s->io_buffer_index = 0;
|
||||
if (s->cd_sector_size == 2352) {
|
||||
n = 1;
|
||||
@ -1262,12 +1262,12 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret)
|
||||
#ifdef DEBUG_AIO
|
||||
printf("aio_read_cd: lba=%u n=%d\n", s->lba, n);
|
||||
#endif
|
||||
bm->aiocb = bdrv_aio_read(s->bs, (int64_t)s->lba << 2,
|
||||
s->io_buffer + data_offset, n * 4,
|
||||
bm->aiocb = bdrv_aio_read(s->bs, (int64_t)s->lba << 2,
|
||||
s->io_buffer + data_offset, n * 4,
|
||||
ide_atapi_cmd_read_dma_cb, bm);
|
||||
if (!bm->aiocb) {
|
||||
/* Note: media not present is the most likely case */
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ASC_MEDIUM_NOT_PRESENT);
|
||||
goto eot;
|
||||
}
|
||||
@ -1289,7 +1289,7 @@ static void ide_atapi_cmd_read_dma(IDEState *s, int lba, int nb_sectors,
|
||||
ide_dma_start(s, ide_atapi_cmd_read_dma_cb);
|
||||
}
|
||||
|
||||
static void ide_atapi_cmd_read(IDEState *s, int lba, int nb_sectors,
|
||||
static void ide_atapi_cmd_read(IDEState *s, int lba, int nb_sectors,
|
||||
int sector_size)
|
||||
{
|
||||
#ifdef DEBUG_IDE_ATAPI
|
||||
@ -1326,7 +1326,7 @@ static void ide_atapi_cmd(IDEState *s)
|
||||
if (bdrv_is_inserted(s->bs)) {
|
||||
ide_atapi_cmd_ok(s);
|
||||
} else {
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ASC_MEDIUM_NOT_PRESENT);
|
||||
}
|
||||
break;
|
||||
@ -1375,7 +1375,7 @@ static void ide_atapi_cmd(IDEState *s)
|
||||
buf[9] = 0x12;
|
||||
buf[10] = 0x08;
|
||||
buf[11] = 0x00;
|
||||
|
||||
|
||||
buf[12] = 0x70;
|
||||
buf[13] = 3 << 5;
|
||||
buf[14] = (1 << 0) | (1 << 3) | (1 << 5);
|
||||
@ -1403,7 +1403,7 @@ static void ide_atapi_cmd(IDEState *s)
|
||||
goto error_cmd;
|
||||
default:
|
||||
case 3: /* saved values */
|
||||
ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
|
||||
ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
|
||||
ASC_SAVING_PARAMETERS_NOT_SUPPORTED);
|
||||
break;
|
||||
}
|
||||
@ -1423,7 +1423,7 @@ static void ide_atapi_cmd(IDEState *s)
|
||||
bdrv_set_locked(s->bs, packet[4] & 1);
|
||||
ide_atapi_cmd_ok(s);
|
||||
} else {
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ASC_MEDIUM_NOT_PRESENT);
|
||||
}
|
||||
break;
|
||||
@ -1469,7 +1469,7 @@ static void ide_atapi_cmd(IDEState *s)
|
||||
ide_atapi_cmd_read(s, lba, nb_sectors, 2352);
|
||||
break;
|
||||
default:
|
||||
ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
|
||||
ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
|
||||
ASC_INV_FIELD_IN_CMD_PACKET);
|
||||
break;
|
||||
}
|
||||
@ -1483,13 +1483,13 @@ static void ide_atapi_cmd(IDEState *s)
|
||||
bdrv_get_geometry(s->bs, &total_sectors);
|
||||
total_sectors >>= 2;
|
||||
if (total_sectors <= 0) {
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ASC_MEDIUM_NOT_PRESENT);
|
||||
break;
|
||||
}
|
||||
lba = ube32_to_cpu(packet + 2);
|
||||
if (lba >= total_sectors) {
|
||||
ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
|
||||
ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
|
||||
ASC_LOGICAL_BLOCK_OOR);
|
||||
break;
|
||||
}
|
||||
@ -1501,7 +1501,7 @@ static void ide_atapi_cmd(IDEState *s)
|
||||
int start, eject;
|
||||
start = packet[4] & 1;
|
||||
eject = (packet[4] >> 1) & 1;
|
||||
|
||||
|
||||
if (eject && !start) {
|
||||
/* eject the disk */
|
||||
bdrv_eject(s->bs, 1);
|
||||
@ -1533,7 +1533,7 @@ static void ide_atapi_cmd(IDEState *s)
|
||||
bdrv_get_geometry(s->bs, &total_sectors);
|
||||
total_sectors >>= 2;
|
||||
if (total_sectors <= 0) {
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ASC_MEDIUM_NOT_PRESENT);
|
||||
break;
|
||||
}
|
||||
@ -1564,7 +1564,7 @@ static void ide_atapi_cmd(IDEState *s)
|
||||
break;
|
||||
default:
|
||||
error_cmd:
|
||||
ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
|
||||
ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
|
||||
ASC_INV_FIELD_IN_CMD_PACKET);
|
||||
break;
|
||||
}
|
||||
@ -1577,7 +1577,7 @@ static void ide_atapi_cmd(IDEState *s)
|
||||
bdrv_get_geometry(s->bs, &total_sectors);
|
||||
total_sectors >>= 2;
|
||||
if (total_sectors <= 0) {
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ide_atapi_cmd_error(s, SENSE_NOT_READY,
|
||||
ASC_MEDIUM_NOT_PRESENT);
|
||||
break;
|
||||
}
|
||||
@ -1670,7 +1670,7 @@ static void ide_atapi_cmd(IDEState *s)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
|
||||
ide_atapi_cmd_error(s, SENSE_ILLEGAL_REQUEST,
|
||||
ASC_ILLEGAL_OPCODE);
|
||||
break;
|
||||
}
|
||||
@ -1838,7 +1838,7 @@ static void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
|
||||
#endif
|
||||
s = ide_if->cur_drive;
|
||||
/* ignore commands to non existant slave */
|
||||
if (s != ide_if && !s->bs)
|
||||
if (s != ide_if && !s->bs)
|
||||
break;
|
||||
|
||||
switch(val) {
|
||||
@ -1892,7 +1892,7 @@ static void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
|
||||
lba48 = 1;
|
||||
case WIN_READ:
|
||||
case WIN_READ_ONCE:
|
||||
if (!s->bs)
|
||||
if (!s->bs)
|
||||
goto abort_cmd;
|
||||
ide_cmd_lba48_transform(s, lba48);
|
||||
s->req_nb_sectors = 1;
|
||||
@ -1940,7 +1940,7 @@ static void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
|
||||
lba48 = 1;
|
||||
case WIN_READDMA:
|
||||
case WIN_READDMA_ONCE:
|
||||
if (!s->bs)
|
||||
if (!s->bs)
|
||||
goto abort_cmd;
|
||||
ide_cmd_lba48_transform(s, lba48);
|
||||
ide_sector_read_dma(s);
|
||||
@ -1949,7 +1949,7 @@ static void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
|
||||
lba48 = 1;
|
||||
case WIN_WRITEDMA:
|
||||
case WIN_WRITEDMA_ONCE:
|
||||
if (!s->bs)
|
||||
if (!s->bs)
|
||||
goto abort_cmd;
|
||||
ide_cmd_lba48_transform(s, lba48);
|
||||
ide_sector_write_dma(s);
|
||||
@ -2071,7 +2071,7 @@ static void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
|
||||
s->status = READY_STAT;
|
||||
s->atapi_dma = s->feature & 1;
|
||||
s->nsector = 1;
|
||||
ide_transfer_start(s, s->io_buffer, ATAPI_PACKET_SIZE,
|
||||
ide_transfer_start(s, s->io_buffer, ATAPI_PACKET_SIZE,
|
||||
ide_atapi_cmd);
|
||||
break;
|
||||
/* CF-ATA commands */
|
||||
@ -2330,7 +2330,7 @@ static uint32_t ide_data_readl(void *opaque, uint32_t addr)
|
||||
IDEState *s = ((IDEState *)opaque)->cur_drive;
|
||||
uint8_t *p;
|
||||
int ret;
|
||||
|
||||
|
||||
p = s->data_ptr;
|
||||
ret = cpu_to_le32(*(uint32_t *)p);
|
||||
p += 4;
|
||||
@ -2381,7 +2381,7 @@ struct partition {
|
||||
} __attribute__((packed));
|
||||
|
||||
/* try to guess the disk logical geometry from the MSDOS partition table. Return 0 if OK, -1 if could not guess */
|
||||
static int guess_disk_lchs(IDEState *s,
|
||||
static int guess_disk_lchs(IDEState *s,
|
||||
int *pcylinders, int *pheads, int *psectors)
|
||||
{
|
||||
uint8_t buf[512];
|
||||
@ -2412,7 +2412,7 @@ static int guess_disk_lchs(IDEState *s,
|
||||
*psectors = sectors;
|
||||
*pcylinders = cylinders;
|
||||
#if 0
|
||||
printf("guessed geometry: LCHS=%d %d %d\n",
|
||||
printf("guessed geometry: LCHS=%d %d %d\n",
|
||||
cylinders, heads, sectors);
|
||||
#endif
|
||||
return 0;
|
||||
@ -2495,7 +2495,7 @@ static void ide_init2(IDEState *ide_state,
|
||||
}
|
||||
s->drive_serial = drive_serial++;
|
||||
s->irq = irq;
|
||||
s->sector_write_timer = qemu_new_timer(vm_clock,
|
||||
s->sector_write_timer = qemu_new_timer(vm_clock,
|
||||
ide_sector_write_timer_cb, s);
|
||||
ide_reset(s);
|
||||
}
|
||||
@ -2509,7 +2509,7 @@ static void ide_init_ioport(IDEState *ide_state, int iobase, int iobase2)
|
||||
register_ioport_read(iobase2, 1, 1, ide_status_read, ide_state);
|
||||
register_ioport_write(iobase2, 1, 1, ide_cmd_write, ide_state);
|
||||
}
|
||||
|
||||
|
||||
/* data ports */
|
||||
register_ioport_write(iobase, 2, 2, ide_data_writew, ide_state);
|
||||
register_ioport_read(iobase, 2, 2, ide_data_readw, ide_state);
|
||||
@ -2584,7 +2584,7 @@ void isa_ide_init(int iobase, int iobase2, qemu_irq irq,
|
||||
ide_state = qemu_mallocz(sizeof(IDEState) * 2);
|
||||
if (!ide_state)
|
||||
return;
|
||||
|
||||
|
||||
ide_init2(ide_state, hd0, hd1, irq);
|
||||
ide_init_ioport(ide_state, iobase, iobase2);
|
||||
}
|
||||
@ -2594,7 +2594,7 @@ void isa_ide_init(int iobase, int iobase2, qemu_irq irq,
|
||||
|
||||
static void cmd646_update_irq(PCIIDEState *d);
|
||||
|
||||
static void ide_map(PCIDevice *pci_dev, int region_num,
|
||||
static void ide_map(PCIDevice *pci_dev, int region_num,
|
||||
uint32_t addr, uint32_t size, int type)
|
||||
{
|
||||
PCIIDEState *d = (PCIIDEState *)pci_dev;
|
||||
@ -2671,9 +2671,9 @@ static uint32_t bmdma_readb(void *opaque, uint32_t addr)
|
||||
BMDMAState *bm = opaque;
|
||||
PCIIDEState *pci_dev;
|
||||
uint32_t val;
|
||||
|
||||
|
||||
switch(addr & 3) {
|
||||
case 0:
|
||||
case 0:
|
||||
val = bm->cmd;
|
||||
break;
|
||||
case 1:
|
||||
@ -2719,7 +2719,7 @@ static void bmdma_writeb(void *opaque, uint32_t addr, uint32_t val)
|
||||
case 1:
|
||||
pci_dev = bm->pci_dev;
|
||||
if (pci_dev->type == IDE_TYPE_CMD646) {
|
||||
pci_dev->dev.config[MRDMODE] =
|
||||
pci_dev->dev.config[MRDMODE] =
|
||||
(pci_dev->dev.config[MRDMODE] & ~0x30) | (val & 0x30);
|
||||
cmd646_update_irq(pci_dev);
|
||||
}
|
||||
@ -2760,7 +2760,7 @@ static void bmdma_addr_writel(void *opaque, uint32_t addr, uint32_t val)
|
||||
bm->cur_addr = bm->addr;
|
||||
}
|
||||
|
||||
static void bmdma_map(PCIDevice *pci_dev, int region_num,
|
||||
static void bmdma_map(PCIDevice *pci_dev, int region_num,
|
||||
uint32_t addr, uint32_t size, int type)
|
||||
{
|
||||
PCIIDEState *d = (PCIIDEState *)pci_dev;
|
||||
@ -2818,9 +2818,9 @@ void pci_cmd646_ide_init(PCIBus *bus, BlockDriverState **hd_table,
|
||||
int i;
|
||||
qemu_irq *irq;
|
||||
|
||||
d = (PCIIDEState *)pci_register_device(bus, "CMD646 IDE",
|
||||
d = (PCIIDEState *)pci_register_device(bus, "CMD646 IDE",
|
||||
sizeof(PCIIDEState),
|
||||
-1,
|
||||
-1,
|
||||
NULL, NULL);
|
||||
d->type = IDE_TYPE_CMD646;
|
||||
pci_conf = d->dev.config;
|
||||
@ -2830,30 +2830,30 @@ void pci_cmd646_ide_init(PCIBus *bus, BlockDriverState **hd_table,
|
||||
pci_conf[0x03] = 0x06;
|
||||
|
||||
pci_conf[0x08] = 0x07; // IDE controller revision
|
||||
pci_conf[0x09] = 0x8f;
|
||||
pci_conf[0x09] = 0x8f;
|
||||
|
||||
pci_conf[0x0a] = 0x01; // class_sub = PCI_IDE
|
||||
pci_conf[0x0b] = 0x01; // class_base = PCI_mass_storage
|
||||
pci_conf[0x0e] = 0x00; // header_type
|
||||
|
||||
|
||||
if (secondary_ide_enabled) {
|
||||
/* XXX: if not enabled, really disable the seconday IDE controller */
|
||||
pci_conf[0x51] = 0x80; /* enable IDE1 */
|
||||
}
|
||||
|
||||
pci_register_io_region((PCIDevice *)d, 0, 0x8,
|
||||
pci_register_io_region((PCIDevice *)d, 0, 0x8,
|
||||
PCI_ADDRESS_SPACE_IO, ide_map);
|
||||
pci_register_io_region((PCIDevice *)d, 1, 0x4,
|
||||
pci_register_io_region((PCIDevice *)d, 1, 0x4,
|
||||
PCI_ADDRESS_SPACE_IO, ide_map);
|
||||
pci_register_io_region((PCIDevice *)d, 2, 0x8,
|
||||
pci_register_io_region((PCIDevice *)d, 2, 0x8,
|
||||
PCI_ADDRESS_SPACE_IO, ide_map);
|
||||
pci_register_io_region((PCIDevice *)d, 3, 0x4,
|
||||
pci_register_io_region((PCIDevice *)d, 3, 0x4,
|
||||
PCI_ADDRESS_SPACE_IO, ide_map);
|
||||
pci_register_io_region((PCIDevice *)d, 4, 0x10,
|
||||
pci_register_io_region((PCIDevice *)d, 4, 0x10,
|
||||
PCI_ADDRESS_SPACE_IO, bmdma_map);
|
||||
|
||||
pci_conf[0x3d] = 0x01; // interrupt on pin 1
|
||||
|
||||
|
||||
for(i = 0; i < 4; i++)
|
||||
d->ide_if[i].pci_dev = (PCIDevice *)d;
|
||||
|
||||
@ -2945,9 +2945,9 @@ void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn,
|
||||
{
|
||||
PCIIDEState *d;
|
||||
uint8_t *pci_conf;
|
||||
|
||||
|
||||
/* register a function 1 of PIIX3 */
|
||||
d = (PCIIDEState *)pci_register_device(bus, "PIIX3 IDE",
|
||||
d = (PCIIDEState *)pci_register_device(bus, "PIIX3 IDE",
|
||||
sizeof(PCIIDEState),
|
||||
devfn,
|
||||
NULL, NULL);
|
||||
@ -2965,7 +2965,7 @@ void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn,
|
||||
|
||||
piix3_reset(d);
|
||||
|
||||
pci_register_io_region((PCIDevice *)d, 4, 0x10,
|
||||
pci_register_io_region((PCIDevice *)d, 4, 0x10,
|
||||
PCI_ADDRESS_SPACE_IO, bmdma_map);
|
||||
|
||||
ide_init2(&d->ide_if[0], hd_table[0], hd_table[1], pic[14]);
|
||||
@ -3021,7 +3021,7 @@ void pci_piix4_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn,
|
||||
static void pmac_ide_writeb (void *opaque,
|
||||
target_phys_addr_t addr, uint32_t val)
|
||||
{
|
||||
addr = (addr & 0xFFF) >> 4;
|
||||
addr = (addr & 0xFFF) >> 4;
|
||||
switch (addr) {
|
||||
case 1 ... 7:
|
||||
ide_ioport_write(opaque, addr, val);
|
||||
@ -3058,7 +3058,7 @@ static uint32_t pmac_ide_readb (void *opaque,target_phys_addr_t addr)
|
||||
static void pmac_ide_writew (void *opaque,
|
||||
target_phys_addr_t addr, uint32_t val)
|
||||
{
|
||||
addr = (addr & 0xFFF) >> 4;
|
||||
addr = (addr & 0xFFF) >> 4;
|
||||
#ifdef TARGET_WORDS_BIGENDIAN
|
||||
val = bswap16(val);
|
||||
#endif
|
||||
@ -3071,7 +3071,7 @@ static uint32_t pmac_ide_readw (void *opaque,target_phys_addr_t addr)
|
||||
{
|
||||
uint16_t retval;
|
||||
|
||||
addr = (addr & 0xFFF) >> 4;
|
||||
addr = (addr & 0xFFF) >> 4;
|
||||
if (addr == 0) {
|
||||
retval = ide_data_readw(opaque, 0);
|
||||
} else {
|
||||
@ -3086,7 +3086,7 @@ static uint32_t pmac_ide_readw (void *opaque,target_phys_addr_t addr)
|
||||
static void pmac_ide_writel (void *opaque,
|
||||
target_phys_addr_t addr, uint32_t val)
|
||||
{
|
||||
addr = (addr & 0xFFF) >> 4;
|
||||
addr = (addr & 0xFFF) >> 4;
|
||||
#ifdef TARGET_WORDS_BIGENDIAN
|
||||
val = bswap32(val);
|
||||
#endif
|
||||
@ -3099,7 +3099,7 @@ static uint32_t pmac_ide_readl (void *opaque,target_phys_addr_t addr)
|
||||
{
|
||||
uint32_t retval;
|
||||
|
||||
addr = (addr & 0xFFF) >> 4;
|
||||
addr = (addr & 0xFFF) >> 4;
|
||||
if (addr == 0) {
|
||||
retval = ide_data_readl(opaque, 0);
|
||||
} else {
|
||||
@ -3133,7 +3133,7 @@ int pmac_ide_init (BlockDriverState **hd_table, qemu_irq irq)
|
||||
|
||||
ide_if = qemu_mallocz(sizeof(IDEState) * 2);
|
||||
ide_init2(&ide_if[0], hd_table[0], hd_table[1], irq);
|
||||
|
||||
|
||||
pmac_ide_memory = cpu_register_io_memory(0, pmac_ide_read,
|
||||
pmac_ide_write, &ide_if[0]);
|
||||
return pmac_ide_memory;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* ARM Integrator CP System emulation.
|
||||
*
|
||||
* Copyright (c) 2005-2007 CodeSourcery.
|
||||
|
@ -2,7 +2,7 @@
|
||||
* QEMU SPARC iommu emulation
|
||||
*
|
||||
* Copyright (c) 2003-2005 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -279,7 +279,7 @@ static void iommu_save(QEMUFile *f, void *opaque)
|
||||
{
|
||||
IOMMUState *s = opaque;
|
||||
int i;
|
||||
|
||||
|
||||
for (i = 0; i < IOMMU_NREGS; i++)
|
||||
qemu_put_be32s(f, &s->regs[i]);
|
||||
qemu_put_be64s(f, &s->iostart);
|
||||
@ -289,7 +289,7 @@ static int iommu_load(QEMUFile *f, void *opaque, int version_id)
|
||||
{
|
||||
IOMMUState *s = opaque;
|
||||
int i;
|
||||
|
||||
|
||||
if (version_id != 2)
|
||||
return -EINVAL;
|
||||
|
||||
@ -322,7 +322,7 @@ void *iommu_init(target_phys_addr_t addr)
|
||||
|
||||
iommu_io_memory = cpu_register_io_memory(0, iommu_mem_read, iommu_mem_write, s);
|
||||
cpu_register_physical_memory(addr, IOMMU_NREGS * 4, iommu_io_memory);
|
||||
|
||||
|
||||
register_savevm("iommu", addr, 2, iommu_save, iommu_load, s);
|
||||
qemu_register_reset(iommu_reset, s);
|
||||
return s;
|
||||
|
4
hw/irq.c
4
hw/irq.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU IRQ/GPIO common code.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2007 CodeSourcery.
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
|
@ -2,7 +2,7 @@
|
||||
* Memory mapped access to ISA IO space.
|
||||
*
|
||||
* Copyright (c) 2006 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU JAZZ LED emulator.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2007 Hervé Poussineau
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QEMU LSI53C895A SCSI Host Bus Adapter emulation
|
||||
*
|
||||
* Copyright (c) 2006 CodeSourcery.
|
||||
@ -1773,7 +1773,7 @@ static void lsi_io_writel(void *opaque, uint32_t addr, uint32_t val)
|
||||
lsi_reg_writeb(s, addr + 3, (val >> 24) & 0xff);
|
||||
}
|
||||
|
||||
static void lsi_io_mapfunc(PCIDevice *pci_dev, int region_num,
|
||||
static void lsi_io_mapfunc(PCIDevice *pci_dev, int region_num,
|
||||
uint32_t addr, uint32_t size, int type)
|
||||
{
|
||||
LSIState *s = (LSIState *)pci_dev;
|
||||
@ -1788,7 +1788,7 @@ static void lsi_io_mapfunc(PCIDevice *pci_dev, int region_num,
|
||||
register_ioport_read(addr, 256, 4, lsi_io_readl, s);
|
||||
}
|
||||
|
||||
static void lsi_ram_mapfunc(PCIDevice *pci_dev, int region_num,
|
||||
static void lsi_ram_mapfunc(PCIDevice *pci_dev, int region_num,
|
||||
uint32_t addr, uint32_t size, int type)
|
||||
{
|
||||
LSIState *s = (LSIState *)pci_dev;
|
||||
@ -1798,7 +1798,7 @@ static void lsi_ram_mapfunc(PCIDevice *pci_dev, int region_num,
|
||||
cpu_register_physical_memory(addr + 0, 0x2000, s->ram_io_addr);
|
||||
}
|
||||
|
||||
static void lsi_mmio_mapfunc(PCIDevice *pci_dev, int region_num,
|
||||
static void lsi_mmio_mapfunc(PCIDevice *pci_dev, int region_num,
|
||||
uint32_t addr, uint32_t size, int type)
|
||||
{
|
||||
LSIState *s = (LSIState *)pci_dev;
|
||||
|
24
hw/m48t59.c
24
hw/m48t59.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU M48T59 and M48T08 NVRAM emulation for PPC PREP and Sparc platforms
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003-2005, 2007 Jocelyn Mayer
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -90,7 +90,7 @@ static void get_time (m48t59_t *NVRAM, struct tm *tm)
|
||||
static void set_time (m48t59_t *NVRAM, struct tm *tm)
|
||||
{
|
||||
time_t now, new_time;
|
||||
|
||||
|
||||
new_time = mktime(tm);
|
||||
now = time(NULL);
|
||||
NVRAM->time_offset = new_time - now;
|
||||
@ -104,7 +104,7 @@ static void alarm_cb (void *opaque)
|
||||
m48t59_t *NVRAM = opaque;
|
||||
|
||||
qemu_set_irq(NVRAM->IRQ, 1);
|
||||
if ((NVRAM->buffer[0x1FF5] & 0x80) == 0 &&
|
||||
if ((NVRAM->buffer[0x1FF5] & 0x80) == 0 &&
|
||||
(NVRAM->buffer[0x1FF4] & 0x80) == 0 &&
|
||||
(NVRAM->buffer[0x1FF3] & 0x80) == 0 &&
|
||||
(NVRAM->buffer[0x1FF2] & 0x80) == 0) {
|
||||
@ -208,7 +208,7 @@ void m48t59_write (m48t59_t *NVRAM, uint32_t addr, uint32_t val)
|
||||
|
||||
if (addr > 0x1FF8 && addr < 0x2000)
|
||||
NVRAM_PRINTF("%s: 0x%08x => 0x%08x\n", __func__, addr, val);
|
||||
if (NVRAM->type == 8 &&
|
||||
if (NVRAM->type == 8 &&
|
||||
(addr >= 0x1ff0 && addr <= 0x1ff7))
|
||||
goto do_write;
|
||||
switch (addr) {
|
||||
@ -364,7 +364,7 @@ uint32_t m48t59_read (m48t59_t *NVRAM, uint32_t addr)
|
||||
struct tm tm;
|
||||
uint32_t retval = 0xFF;
|
||||
|
||||
if (NVRAM->type == 8 &&
|
||||
if (NVRAM->type == 8 &&
|
||||
(addr >= 0x1ff0 && addr <= 0x1ff7))
|
||||
goto do_read;
|
||||
switch (addr) {
|
||||
@ -430,7 +430,7 @@ uint32_t m48t59_read (m48t59_t *NVRAM, uint32_t addr)
|
||||
case 0x1FFF:
|
||||
/* year */
|
||||
get_time(NVRAM, &tm);
|
||||
if (NVRAM->type == 8)
|
||||
if (NVRAM->type == 8)
|
||||
retval = toBCD(tm.tm_year - 68); // Base year is 1968
|
||||
else
|
||||
retval = toBCD(tm.tm_year);
|
||||
@ -510,7 +510,7 @@ static uint32_t NVRAM_readb (void *opaque, uint32_t addr)
|
||||
static void nvram_writeb (void *opaque, target_phys_addr_t addr, uint32_t value)
|
||||
{
|
||||
m48t59_t *NVRAM = opaque;
|
||||
|
||||
|
||||
addr -= NVRAM->mem_base;
|
||||
m48t59_write(NVRAM, addr, value & 0xff);
|
||||
}
|
||||
@ -518,7 +518,7 @@ static void nvram_writeb (void *opaque, target_phys_addr_t addr, uint32_t value)
|
||||
static void nvram_writew (void *opaque, target_phys_addr_t addr, uint32_t value)
|
||||
{
|
||||
m48t59_t *NVRAM = opaque;
|
||||
|
||||
|
||||
addr -= NVRAM->mem_base;
|
||||
m48t59_write(NVRAM, addr, (value >> 8) & 0xff);
|
||||
m48t59_write(NVRAM, addr + 1, value & 0xff);
|
||||
@ -527,7 +527,7 @@ static void nvram_writew (void *opaque, target_phys_addr_t addr, uint32_t value)
|
||||
static void nvram_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
|
||||
{
|
||||
m48t59_t *NVRAM = opaque;
|
||||
|
||||
|
||||
addr -= NVRAM->mem_base;
|
||||
m48t59_write(NVRAM, addr, (value >> 24) & 0xff);
|
||||
m48t59_write(NVRAM, addr + 1, (value >> 16) & 0xff);
|
||||
@ -539,7 +539,7 @@ static uint32_t nvram_readb (void *opaque, target_phys_addr_t addr)
|
||||
{
|
||||
m48t59_t *NVRAM = opaque;
|
||||
uint32_t retval;
|
||||
|
||||
|
||||
addr -= NVRAM->mem_base;
|
||||
retval = m48t59_read(NVRAM, addr);
|
||||
return retval;
|
||||
@ -549,7 +549,7 @@ static uint32_t nvram_readw (void *opaque, target_phys_addr_t addr)
|
||||
{
|
||||
m48t59_t *NVRAM = opaque;
|
||||
uint32_t retval;
|
||||
|
||||
|
||||
addr -= NVRAM->mem_base;
|
||||
retval = m48t59_read(NVRAM, addr) << 8;
|
||||
retval |= m48t59_read(NVRAM, addr + 1);
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU MC146818 RTC emulation
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003-2004 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -75,7 +75,7 @@ static void rtc_timer_update(RTCState *s, int64_t current_time)
|
||||
int64_t cur_clock, next_irq_clock;
|
||||
|
||||
period_code = s->cmos_data[RTC_REG_A] & 0x0f;
|
||||
if (period_code != 0 &&
|
||||
if (period_code != 0 &&
|
||||
(s->cmos_data[RTC_REG_B] & REG_B_PIE)) {
|
||||
if (period_code <= 2)
|
||||
period_code += 7;
|
||||
@ -110,7 +110,7 @@ static void cmos_ioport_write(void *opaque, uint32_t addr, uint32_t data)
|
||||
#ifdef DEBUG_CMOS
|
||||
printf("cmos: write index=0x%02x val=0x%02x\n",
|
||||
s->cmos_index, data);
|
||||
#endif
|
||||
#endif
|
||||
switch(s->cmos_index) {
|
||||
case RTC_SECONDS_ALARM:
|
||||
case RTC_MINUTES_ALARM:
|
||||
@ -221,8 +221,8 @@ static void rtc_copy_date(RTCState *s)
|
||||
/* month is between 0 and 11. */
|
||||
static int get_days_in_month(int month, int year)
|
||||
{
|
||||
static const int days_tab[12] = {
|
||||
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||
static const int days_tab[12] = {
|
||||
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||
};
|
||||
int d;
|
||||
if ((unsigned )month >= 12)
|
||||
@ -253,7 +253,7 @@ static void rtc_next_second(struct tm *tm)
|
||||
tm->tm_wday++;
|
||||
if ((unsigned)tm->tm_wday >= 7)
|
||||
tm->tm_wday = 0;
|
||||
days_in_month = get_days_in_month(tm->tm_mon,
|
||||
days_in_month = get_days_in_month(tm->tm_mon,
|
||||
tm->tm_year + 1900);
|
||||
tm->tm_mday++;
|
||||
if (tm->tm_mday < 1) {
|
||||
@ -283,7 +283,7 @@ static void rtc_update_second(void *opaque)
|
||||
qemu_mod_timer(s->second_timer, s->next_second_time);
|
||||
} else {
|
||||
rtc_next_second(&s->current_tm);
|
||||
|
||||
|
||||
if (!(s->cmos_data[RTC_REG_B] & REG_B_SET)) {
|
||||
/* update in progress bit */
|
||||
s->cmos_data[RTC_REG_A] |= REG_A_UIP;
|
||||
@ -293,7 +293,7 @@ static void rtc_update_second(void *opaque)
|
||||
delay = (ticks_per_sec * 1) / 100;
|
||||
if (delay < 1)
|
||||
delay = 1;
|
||||
qemu_mod_timer(s->second_timer2,
|
||||
qemu_mod_timer(s->second_timer2,
|
||||
s->next_second_time + delay);
|
||||
}
|
||||
}
|
||||
@ -315,14 +315,14 @@ static void rtc_update_second2(void *opaque)
|
||||
((s->cmos_data[RTC_HOURS_ALARM] & 0xc0) == 0xc0 ||
|
||||
s->cmos_data[RTC_HOURS_ALARM] == s->current_tm.tm_hour)) {
|
||||
|
||||
s->cmos_data[RTC_REG_C] |= 0xa0;
|
||||
s->cmos_data[RTC_REG_C] |= 0xa0;
|
||||
qemu_irq_raise(s->irq);
|
||||
}
|
||||
}
|
||||
|
||||
/* update ended interrupt */
|
||||
if (s->cmos_data[RTC_REG_B] & REG_B_UIE) {
|
||||
s->cmos_data[RTC_REG_C] |= 0x90;
|
||||
s->cmos_data[RTC_REG_C] |= 0x90;
|
||||
qemu_irq_raise(s->irq);
|
||||
}
|
||||
|
||||
@ -356,7 +356,7 @@ static uint32_t cmos_ioport_read(void *opaque, uint32_t addr)
|
||||
case RTC_REG_C:
|
||||
ret = s->cmos_data[s->cmos_index];
|
||||
qemu_irq_lower(s->irq);
|
||||
s->cmos_data[RTC_REG_C] = 0x00;
|
||||
s->cmos_data[RTC_REG_C] = 0x00;
|
||||
break;
|
||||
default:
|
||||
ret = s->cmos_data[s->cmos_index];
|
||||
@ -411,7 +411,7 @@ static void rtc_save(QEMUFile *f, void *opaque)
|
||||
|
||||
qemu_put_buffer(f, s->cmos_data, 128);
|
||||
qemu_put_8s(f, &s->cmos_index);
|
||||
|
||||
|
||||
qemu_put_be32s(f, &s->current_tm.tm_sec);
|
||||
qemu_put_be32s(f, &s->current_tm.tm_min);
|
||||
qemu_put_be32s(f, &s->current_tm.tm_hour);
|
||||
@ -471,11 +471,11 @@ RTCState *rtc_init(int base, qemu_irq irq)
|
||||
|
||||
rtc_set_date_from_host(s);
|
||||
|
||||
s->periodic_timer = qemu_new_timer(vm_clock,
|
||||
s->periodic_timer = qemu_new_timer(vm_clock,
|
||||
rtc_periodic_timer, s);
|
||||
s->second_timer = qemu_new_timer(vm_clock,
|
||||
s->second_timer = qemu_new_timer(vm_clock,
|
||||
rtc_update_second, s);
|
||||
s->second_timer2 = qemu_new_timer(vm_clock,
|
||||
s->second_timer2 = qemu_new_timer(vm_clock,
|
||||
rtc_update_second2, s);
|
||||
|
||||
s->next_second_time = qemu_get_clock(vm_clock) + (ticks_per_sec * 99) / 100;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Motorola ColdFire MCF5206 SoC embedded peripheral emulation.
|
||||
*
|
||||
* Copyright (c) 2007 CodeSourcery.
|
||||
@ -58,7 +58,7 @@ static void m5206_timer_recalibrate(m5206_timer_state *s)
|
||||
prescale *= 16;
|
||||
|
||||
if (mode == 3 || mode == 0)
|
||||
cpu_abort(cpu_single_env,
|
||||
cpu_abort(cpu_single_env,
|
||||
"m5206_timer: mode %d not implemented\n", mode);
|
||||
if ((s->tmr & TMR_FRR) == 0)
|
||||
cpu_abort(cpu_single_env,
|
||||
@ -354,7 +354,7 @@ static void m5206_mbar_write(m5206_mbar_state *s, uint32_t offset,
|
||||
|
||||
/* Internal peripherals use a variety of register widths.
|
||||
This lookup table allows a single routine to handle all of them. */
|
||||
static const int m5206_mbar_width[] =
|
||||
static const int m5206_mbar_width[] =
|
||||
{
|
||||
/* 000-040 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
/* 040-080 */ 1, 2, 2, 2, 4, 1, 2, 4, 1, 2, 4, 2, 2, 4, 2, 2,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Motorola ColdFire MCF5208 SoC emulation.
|
||||
*
|
||||
* Copyright (c) 2007 CodeSourcery.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* ColdFire Fast Ethernet Controller emulation.
|
||||
*
|
||||
* Copyright (c) 2007 CodeSourcery.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* ColdFire Interrupt Controller emulation.
|
||||
*
|
||||
* Copyright (c) 2007 CodeSourcery.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* ColdFire UART emulation.
|
||||
*
|
||||
* Copyright (c) 2007 CodeSourcery.
|
||||
|
@ -510,9 +510,9 @@ static void write_bootloader (CPUState *env, unsigned long bios_offset, int64_t
|
||||
stl_raw(p++, 0x00000000); /* nop */
|
||||
|
||||
/* YAMON service vector */
|
||||
stl_raw(phys_ram_base + bios_offset + 0x500, 0xbfc00580); /* start: */
|
||||
stl_raw(phys_ram_base + bios_offset + 0x500, 0xbfc00580); /* start: */
|
||||
stl_raw(phys_ram_base + bios_offset + 0x504, 0xbfc0083c); /* print_count: */
|
||||
stl_raw(phys_ram_base + bios_offset + 0x520, 0xbfc00580); /* start: */
|
||||
stl_raw(phys_ram_base + bios_offset + 0x520, 0xbfc00580); /* start: */
|
||||
stl_raw(phys_ram_base + bios_offset + 0x52c, 0xbfc00800); /* flush_cache: */
|
||||
stl_raw(phys_ram_base + bios_offset + 0x534, 0xbfc00808); /* print: */
|
||||
stl_raw(phys_ram_base + bios_offset + 0x538, 0xbfc00800); /* reg_cpu_isr: */
|
||||
|
@ -221,7 +221,7 @@ void mips_r4k_init (int ram_size, int vga_ram_size, int boot_device,
|
||||
}
|
||||
}
|
||||
|
||||
isa_vga_init(ds, phys_ram_base + ram_size, ram_size,
|
||||
isa_vga_init(ds, phys_ram_base + ram_size, ram_size,
|
||||
vga_ram_size);
|
||||
|
||||
if (nd_table[0].vlan) {
|
||||
|
@ -323,7 +323,7 @@ static int nand_iid = 0;
|
||||
*
|
||||
* CE, WP and R/B are active low.
|
||||
*/
|
||||
void nand_setpins(struct nand_flash_s *s,
|
||||
void nand_setpins(struct nand_flash_s *s,
|
||||
int cle, int ale, int ce, int wp, int gnd)
|
||||
{
|
||||
s->cle = cle;
|
||||
@ -416,7 +416,7 @@ void nand_setio(struct nand_flash_s *s, uint8_t value)
|
||||
uint8_t nand_getio(struct nand_flash_s *s)
|
||||
{
|
||||
int offset;
|
||||
|
||||
|
||||
/* Allow sequential reading */
|
||||
if (!s->iolen && s->cmd == NAND_CMD_READ0) {
|
||||
offset = (s->addr & ((1 << s->addr_shift) - 1)) + s->offset;
|
||||
|
62
hw/ne2000.c
62
hw/ne2000.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU NE2000 emulation
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003-2004 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -212,7 +212,7 @@ static int ne2000_buffer_full(NE2000State *s)
|
||||
static int ne2000_can_receive(void *opaque)
|
||||
{
|
||||
NE2000State *s = opaque;
|
||||
|
||||
|
||||
if (s->cmd & E8390_STOP)
|
||||
return 1;
|
||||
return !ne2000_buffer_full(s);
|
||||
@ -226,16 +226,16 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size)
|
||||
uint8_t *p;
|
||||
unsigned int total_len, next, avail, len, index, mcast_idx;
|
||||
uint8_t buf1[60];
|
||||
static const uint8_t broadcast_macaddr[6] =
|
||||
static const uint8_t broadcast_macaddr[6] =
|
||||
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
|
||||
|
||||
#if defined(DEBUG_NE2000)
|
||||
printf("NE2000: received len=%d\n", size);
|
||||
#endif
|
||||
|
||||
if (s->cmd & E8390_STOP || ne2000_buffer_full(s))
|
||||
return;
|
||||
|
||||
|
||||
/* XXX: check this */
|
||||
if (s->rxcr & 0x10) {
|
||||
/* promiscuous: receive all */
|
||||
@ -252,10 +252,10 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size)
|
||||
if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))))
|
||||
return;
|
||||
} else if (s->mem[0] == buf[0] &&
|
||||
s->mem[2] == buf[1] &&
|
||||
s->mem[4] == buf[2] &&
|
||||
s->mem[6] == buf[3] &&
|
||||
s->mem[8] == buf[4] &&
|
||||
s->mem[2] == buf[1] &&
|
||||
s->mem[4] == buf[2] &&
|
||||
s->mem[6] == buf[3] &&
|
||||
s->mem[8] == buf[4] &&
|
||||
s->mem[10] == buf[5]) {
|
||||
/* match */
|
||||
} else {
|
||||
@ -336,7 +336,7 @@ static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
|
||||
}
|
||||
if (val & E8390_TRANS) {
|
||||
index = (s->tpsr << 8);
|
||||
/* XXX: next 2 lines are a hack to make netware 3.11 work */
|
||||
/* XXX: next 2 lines are a hack to make netware 3.11 work */
|
||||
if (index >= NE2000_PMEM_END)
|
||||
index -= NE2000_PMEM_SIZE;
|
||||
/* fail safe: check range on the transmitted length */
|
||||
@ -346,7 +346,7 @@ static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
|
||||
/* signal end of transfer */
|
||||
s->tsr = ENTSR_PTX;
|
||||
s->isr |= ENISR_TX;
|
||||
s->cmd &= ~E8390_TRANS;
|
||||
s->cmd &= ~E8390_TRANS;
|
||||
ne2000_update_irq(s);
|
||||
}
|
||||
}
|
||||
@ -482,30 +482,30 @@ static uint32_t ne2000_ioport_read(void *opaque, uint32_t addr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void ne2000_mem_writeb(NE2000State *s, uint32_t addr,
|
||||
static inline void ne2000_mem_writeb(NE2000State *s, uint32_t addr,
|
||||
uint32_t val)
|
||||
{
|
||||
if (addr < 32 ||
|
||||
if (addr < 32 ||
|
||||
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
|
||||
s->mem[addr] = val;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void ne2000_mem_writew(NE2000State *s, uint32_t addr,
|
||||
static inline void ne2000_mem_writew(NE2000State *s, uint32_t addr,
|
||||
uint32_t val)
|
||||
{
|
||||
addr &= ~1; /* XXX: check exact behaviour if not even */
|
||||
if (addr < 32 ||
|
||||
if (addr < 32 ||
|
||||
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
|
||||
*(uint16_t *)(s->mem + addr) = cpu_to_le16(val);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void ne2000_mem_writel(NE2000State *s, uint32_t addr,
|
||||
static inline void ne2000_mem_writel(NE2000State *s, uint32_t addr,
|
||||
uint32_t val)
|
||||
{
|
||||
addr &= ~1; /* XXX: check exact behaviour if not even */
|
||||
if (addr < 32 ||
|
||||
if (addr < 32 ||
|
||||
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
|
||||
cpu_to_le32wu((uint32_t *)(s->mem + addr), val);
|
||||
}
|
||||
@ -513,7 +513,7 @@ static inline void ne2000_mem_writel(NE2000State *s, uint32_t addr,
|
||||
|
||||
static inline uint32_t ne2000_mem_readb(NE2000State *s, uint32_t addr)
|
||||
{
|
||||
if (addr < 32 ||
|
||||
if (addr < 32 ||
|
||||
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
|
||||
return s->mem[addr];
|
||||
} else {
|
||||
@ -524,7 +524,7 @@ static inline uint32_t ne2000_mem_readb(NE2000State *s, uint32_t addr)
|
||||
static inline uint32_t ne2000_mem_readw(NE2000State *s, uint32_t addr)
|
||||
{
|
||||
addr &= ~1; /* XXX: check exact behaviour if not even */
|
||||
if (addr < 32 ||
|
||||
if (addr < 32 ||
|
||||
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
|
||||
return le16_to_cpu(*(uint16_t *)(s->mem + addr));
|
||||
} else {
|
||||
@ -535,7 +535,7 @@ static inline uint32_t ne2000_mem_readw(NE2000State *s, uint32_t addr)
|
||||
static inline uint32_t ne2000_mem_readl(NE2000State *s, uint32_t addr)
|
||||
{
|
||||
addr &= ~1; /* XXX: check exact behaviour if not even */
|
||||
if (addr < 32 ||
|
||||
if (addr < 32 ||
|
||||
(addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) {
|
||||
return le32_to_cpupu((uint32_t *)(s->mem + addr));
|
||||
} else {
|
||||
@ -718,11 +718,11 @@ static int ne2000_load(QEMUFile* f,void* opaque,int version_id)
|
||||
void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
|
||||
{
|
||||
NE2000State *s;
|
||||
|
||||
|
||||
s = qemu_mallocz(sizeof(NE2000State));
|
||||
if (!s)
|
||||
return;
|
||||
|
||||
|
||||
register_ioport_write(base, 16, 1, ne2000_ioport_write, s);
|
||||
register_ioport_read(base, 16, 1, ne2000_ioport_read, s);
|
||||
|
||||
@ -749,7 +749,7 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
|
||||
s->macaddr[3],
|
||||
s->macaddr[4],
|
||||
s->macaddr[5]);
|
||||
|
||||
|
||||
register_savevm("ne2000", 0, 2, ne2000_save, ne2000_load, s);
|
||||
}
|
||||
|
||||
@ -761,7 +761,7 @@ typedef struct PCINE2000State {
|
||||
NE2000State ne2000;
|
||||
} PCINE2000State;
|
||||
|
||||
static void ne2000_map(PCIDevice *pci_dev, int region_num,
|
||||
static void ne2000_map(PCIDevice *pci_dev, int region_num,
|
||||
uint32_t addr, uint32_t size, int type)
|
||||
{
|
||||
PCINE2000State *d = (PCINE2000State *)pci_dev;
|
||||
@ -786,22 +786,22 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||
PCINE2000State *d;
|
||||
NE2000State *s;
|
||||
uint8_t *pci_conf;
|
||||
|
||||
|
||||
d = (PCINE2000State *)pci_register_device(bus,
|
||||
"NE2000", sizeof(PCINE2000State),
|
||||
devfn,
|
||||
devfn,
|
||||
NULL, NULL);
|
||||
pci_conf = d->dev.config;
|
||||
pci_conf[0x00] = 0xec; // Realtek 8029
|
||||
pci_conf[0x01] = 0x10;
|
||||
pci_conf[0x02] = 0x29;
|
||||
pci_conf[0x03] = 0x80;
|
||||
pci_conf[0x0a] = 0x00; // ethernet network controller
|
||||
pci_conf[0x0a] = 0x00; // ethernet network controller
|
||||
pci_conf[0x0b] = 0x02;
|
||||
pci_conf[0x0e] = 0x00; // header_type
|
||||
pci_conf[0x3d] = 1; // interrupt pin 0
|
||||
|
||||
pci_register_io_region(&d->dev, 0, 0x100,
|
||||
|
||||
pci_register_io_region(&d->dev, 0, 0x100,
|
||||
PCI_ADDRESS_SPACE_IO, ne2000_map);
|
||||
s = &d->ne2000;
|
||||
s->irq = d->dev.irq[0];
|
||||
@ -819,7 +819,7 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||
s->macaddr[3],
|
||||
s->macaddr[4],
|
||||
s->macaddr[5]);
|
||||
|
||||
|
||||
/* XXX: instance number ? */
|
||||
register_savevm("ne2000", 0, 3, ne2000_save, ne2000_load, s);
|
||||
}
|
||||
|
@ -483,7 +483,7 @@ struct omap_mpu_state_s {
|
||||
qemu_irq wakeup;
|
||||
|
||||
struct omap_dma_port_if_s {
|
||||
uint32_t (*read[3])(struct omap_mpu_state_s *s,
|
||||
uint32_t (*read[3])(struct omap_mpu_state_s *s,
|
||||
target_phys_addr_t offset);
|
||||
void (*write[3])(struct omap_mpu_state_s *s,
|
||||
target_phys_addr_t offset, uint32_t value);
|
||||
|
@ -29,18 +29,18 @@
|
||||
|
||||
#if DEPTH == 8
|
||||
# define BPP 1
|
||||
# define PIXEL_TYPE uint8_t
|
||||
# define PIXEL_TYPE uint8_t
|
||||
#elif DEPTH == 15 || DEPTH == 16
|
||||
# define BPP 2
|
||||
# define PIXEL_TYPE uint16_t
|
||||
# define PIXEL_TYPE uint16_t
|
||||
#elif DEPTH == 32
|
||||
# define BPP 4
|
||||
# define PIXEL_TYPE uint32_t
|
||||
# define PIXEL_TYPE uint32_t
|
||||
#else
|
||||
# error unsupport depth
|
||||
#endif
|
||||
|
||||
/*
|
||||
/*
|
||||
* 2-bit colour
|
||||
*/
|
||||
static void glue(draw_line2_, DEPTH)(
|
||||
@ -78,7 +78,7 @@ static void glue(draw_line2_, DEPTH)(
|
||||
} while (width > 0);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* 4-bit colour
|
||||
*/
|
||||
static void glue(draw_line4_, DEPTH)(
|
||||
@ -104,7 +104,7 @@ static void glue(draw_line4_, DEPTH)(
|
||||
} while (width > 0);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* 8-bit colour
|
||||
*/
|
||||
static void glue(draw_line8_, DEPTH)(
|
||||
@ -123,7 +123,7 @@ static void glue(draw_line8_, DEPTH)(
|
||||
} while (-- width != 0);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* 12-bit colour
|
||||
*/
|
||||
static void glue(draw_line12_, DEPTH)(
|
||||
@ -143,7 +143,7 @@ static void glue(draw_line12_, DEPTH)(
|
||||
} while (-- width != 0);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* 16-bit colour
|
||||
*/
|
||||
static void glue(draw_line16_, DEPTH)(
|
||||
|
26
hw/openpic.c
26
hw/openpic.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* OpenPIC emulation
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004 Jocelyn Mayer
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -30,7 +30,7 @@
|
||||
* - Motorola Harrier programmer manuel
|
||||
*
|
||||
* Serial interrupts, as implemented in Raven chipset are not supported yet.
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "vl.h"
|
||||
|
||||
@ -224,7 +224,7 @@ static void IRQ_check (openpic_t *opp, IRQ_queue_t *q)
|
||||
priority = -1;
|
||||
for (i = 0; i < MAX_IRQ; i++) {
|
||||
if (IRQ_testbit(q, i)) {
|
||||
DPRINTF("IRQ_check: irq %d set ipvp_pr=%d pr=%d\n",
|
||||
DPRINTF("IRQ_check: irq %d set ipvp_pr=%d pr=%d\n",
|
||||
i, IPVP_PRIORITY(opp->src[i].ipvp), priority);
|
||||
if (IPVP_PRIORITY(opp->src[i].ipvp) > priority) {
|
||||
next = i;
|
||||
@ -350,7 +350,7 @@ static void openpic_set_irq(void *opaque, int n_IRQ, int level)
|
||||
IRQ_src_t *src;
|
||||
|
||||
src = &opp->src[n_IRQ];
|
||||
DPRINTF("openpic: set irq %d = %d ipvp=%08x\n",
|
||||
DPRINTF("openpic: set irq %d = %d ipvp=%08x\n",
|
||||
n_IRQ, level, src->ipvp);
|
||||
if (test_bit(&src->ipvp, IPVP_SENSE)) {
|
||||
/* level-sensitive irq */
|
||||
@ -438,11 +438,11 @@ static inline void write_IRQreg (openpic_t *opp, int n_IRQ,
|
||||
/* NOTE: not fully accurate for special IRQs, but simple and
|
||||
sufficient */
|
||||
/* ACTIVITY bit is read-only */
|
||||
opp->src[n_IRQ].ipvp =
|
||||
opp->src[n_IRQ].ipvp =
|
||||
(opp->src[n_IRQ].ipvp & 0x40000000) |
|
||||
(val & 0x800F00FF);
|
||||
openpic_update_irq(opp, n_IRQ);
|
||||
DPRINTF("Set IPVP %d to 0x%08x -> 0x%08x\n",
|
||||
DPRINTF("Set IPVP %d to 0x%08x -> 0x%08x\n",
|
||||
n_IRQ, val, opp->src[n_IRQ].ipvp);
|
||||
break;
|
||||
case IRQ_IDE:
|
||||
@ -475,7 +475,7 @@ static uint32_t read_doorbell_register (openpic_t *opp,
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
static void write_doorbell_register (penpic_t *opp, int n_dbl,
|
||||
uint32_t offset, uint32_t value)
|
||||
{
|
||||
@ -831,7 +831,7 @@ static uint32_t openpic_cpu_read (void *opaque, uint32_t addr)
|
||||
IRQ_dst_t *dst;
|
||||
uint32_t retval;
|
||||
int idx, n_IRQ;
|
||||
|
||||
|
||||
DPRINTF("%s: addr %08x\n", __func__, addr);
|
||||
retval = 0xFFFFFFFF;
|
||||
if (addr & 0xF)
|
||||
@ -971,7 +971,7 @@ static CPUReadMemoryFunc *openpic_read[] = {
|
||||
&openpic_readl,
|
||||
};
|
||||
|
||||
static void openpic_map(PCIDevice *pci_dev, int region_num,
|
||||
static void openpic_map(PCIDevice *pci_dev, int region_num,
|
||||
uint32_t addr, uint32_t size, int type)
|
||||
{
|
||||
openpic_t *opp;
|
||||
@ -1005,7 +1005,7 @@ qemu_irq *openpic_init (PCIBus *bus, int *pmem_index, int nb_cpus,
|
||||
openpic_t *opp;
|
||||
uint8_t *pci_conf;
|
||||
int i, m;
|
||||
|
||||
|
||||
/* XXX: for now, only one CPU is supported */
|
||||
if (nb_cpus != 1)
|
||||
return NULL;
|
||||
@ -1023,7 +1023,7 @@ qemu_irq *openpic_init (PCIBus *bus, int *pmem_index, int nb_cpus,
|
||||
pci_conf[0x0b] = 0x08;
|
||||
pci_conf[0x0e] = 0x00; // header_type
|
||||
pci_conf[0x3d] = 0x00; // no interrupt pin
|
||||
|
||||
|
||||
/* Register I/O spaces */
|
||||
pci_register_io_region((PCIDevice *)opp, 0, 0x40000,
|
||||
PCI_ADDRESS_SPACE_MEM, &openpic_map);
|
||||
@ -1032,7 +1032,7 @@ qemu_irq *openpic_init (PCIBus *bus, int *pmem_index, int nb_cpus,
|
||||
}
|
||||
opp->mem_index = cpu_register_io_memory(0, openpic_read,
|
||||
openpic_write, opp);
|
||||
|
||||
|
||||
// isu_base &= 0xFFFC0000;
|
||||
opp->nb_cpus = nb_cpus;
|
||||
/* Set IRQ types */
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* QEMU Parallel PORT emulation
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003-2005 Fabrice Bellard
|
||||
* Copyright (c) 2007 Marko Kohtala
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -88,7 +88,7 @@ static void
|
||||
parallel_ioport_write_sw(void *opaque, uint32_t addr, uint32_t val)
|
||||
{
|
||||
ParallelState *s = opaque;
|
||||
|
||||
|
||||
pdebug("write addr=0x%02x val=0x%02x\n", addr, val);
|
||||
|
||||
addr &= 7;
|
||||
|
66
hw/pc.c
66
hw/pc.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU PC System Emulator
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003-2004 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -65,7 +65,7 @@ uint64_t cpu_get_tsc(CPUX86State *env)
|
||||
#if USE_KQEMU
|
||||
if (env->kqemu_enabled) {
|
||||
return cpu_get_real_ticks();
|
||||
} else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
return cpu_get_ticks();
|
||||
@ -89,7 +89,7 @@ int cpu_get_pic_interrupt(CPUState *env)
|
||||
if (intno >= 0) {
|
||||
/* set irq request if a PIC irq is still pending */
|
||||
/* XXX: improve that */
|
||||
pic_update_irq(isa_pic);
|
||||
pic_update_irq(isa_pic);
|
||||
return intno;
|
||||
}
|
||||
/* read the irq from the PIC */
|
||||
@ -134,7 +134,7 @@ static int cmos_get_fd_drive_type(int fd0)
|
||||
return val;
|
||||
}
|
||||
|
||||
static void cmos_init_hd(int type_ofs, int info_ofs, BlockDriverState *hd)
|
||||
static void cmos_init_hd(int type_ofs, int info_ofs, BlockDriverState *hd)
|
||||
{
|
||||
RTCState *s = rtc_state;
|
||||
int cylinders, heads, sectors;
|
||||
@ -182,7 +182,7 @@ static void cmos_init(int ram_size, int boot_device, BlockDriverState **hd_table
|
||||
val = 65535;
|
||||
rtc_set_memory(s, 0x34, val);
|
||||
rtc_set_memory(s, 0x35, val >> 8);
|
||||
|
||||
|
||||
switch(boot_device) {
|
||||
case 'a':
|
||||
case 'b':
|
||||
@ -199,7 +199,7 @@ static void cmos_init(int ram_size, int boot_device, BlockDriverState **hd_table
|
||||
break;
|
||||
case 'n':
|
||||
rtc_set_memory(s, 0x3d, 0x04); /* Network boot */
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
/* floppy type */
|
||||
@ -209,7 +209,7 @@ static void cmos_init(int ram_size, int boot_device, BlockDriverState **hd_table
|
||||
|
||||
val = (cmos_get_fd_drive_type(fd0) << 4) | cmos_get_fd_drive_type(fd1);
|
||||
rtc_set_memory(s, 0x10, val);
|
||||
|
||||
|
||||
val = 0;
|
||||
nb = 0;
|
||||
if (fd0 < 3)
|
||||
@ -235,7 +235,7 @@ static void cmos_init(int ram_size, int boot_device, BlockDriverState **hd_table
|
||||
rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0));
|
||||
if (hd_table[0])
|
||||
cmos_init_hd(0x19, 0x1b, hd_table[0]);
|
||||
if (hd_table[1])
|
||||
if (hd_table[1])
|
||||
cmos_init_hd(0x1a, 0x24, hd_table[1]);
|
||||
|
||||
val = 0;
|
||||
@ -294,7 +294,7 @@ void bochs_bios_write(void *opaque, uint32_t addr, uint32_t val)
|
||||
{
|
||||
static const char shutdown_str[8] = "Shutdown";
|
||||
static int shutdown_index = 0;
|
||||
|
||||
|
||||
switch(addr) {
|
||||
/* Bochs BIOS messages */
|
||||
case 0x400:
|
||||
@ -404,7 +404,7 @@ static void generate_bootsect(uint32_t gpr[8], uint16_t segs[6], uint16_t ip)
|
||||
bdrv_set_boot_sector(bs_table[0], bootsect, sizeof(bootsect));
|
||||
}
|
||||
|
||||
int load_kernel(const char *filename, uint8_t *addr,
|
||||
int load_kernel(const char *filename, uint8_t *addr,
|
||||
uint8_t *real_addr)
|
||||
{
|
||||
int fd, size;
|
||||
@ -420,7 +420,7 @@ int load_kernel(const char *filename, uint8_t *addr,
|
||||
setup_sects = real_addr[0x1F1];
|
||||
if (!setup_sects)
|
||||
setup_sects = 4;
|
||||
if (read(fd, real_addr + 512, setup_sects * 512) !=
|
||||
if (read(fd, real_addr + 512, setup_sects * 512) !=
|
||||
setup_sects * 512)
|
||||
goto fail;
|
||||
|
||||
@ -708,7 +708,7 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device,
|
||||
/* BIOS load */
|
||||
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME);
|
||||
bios_size = get_image_size(buf);
|
||||
if (bios_size <= 0 ||
|
||||
if (bios_size <= 0 ||
|
||||
(bios_size % 65536) != 0) {
|
||||
goto bios_error;
|
||||
}
|
||||
@ -727,7 +727,7 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device,
|
||||
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME);
|
||||
}
|
||||
vga_bios_size = get_image_size(buf);
|
||||
if (vga_bios_size <= 0 || vga_bios_size > 65536)
|
||||
if (vga_bios_size <= 0 || vga_bios_size > 65536)
|
||||
goto vga_bios_error;
|
||||
vga_bios_offset = qemu_ram_alloc(65536);
|
||||
|
||||
@ -739,17 +739,17 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device,
|
||||
}
|
||||
|
||||
/* setup basic memory access */
|
||||
cpu_register_physical_memory(0xc0000, 0x10000,
|
||||
cpu_register_physical_memory(0xc0000, 0x10000,
|
||||
vga_bios_offset | IO_MEM_ROM);
|
||||
|
||||
/* map the last 128KB of the BIOS in ISA space */
|
||||
isa_bios_size = bios_size;
|
||||
if (isa_bios_size > (128 * 1024))
|
||||
isa_bios_size = 128 * 1024;
|
||||
cpu_register_physical_memory(0xd0000, (192 * 1024) - isa_bios_size,
|
||||
cpu_register_physical_memory(0xd0000, (192 * 1024) - isa_bios_size,
|
||||
IO_MEM_UNASSIGNED);
|
||||
cpu_register_physical_memory(0x100000 - isa_bios_size,
|
||||
isa_bios_size,
|
||||
cpu_register_physical_memory(0x100000 - isa_bios_size,
|
||||
isa_bios_size,
|
||||
(bios_offset + bios_size - isa_bios_size) | IO_MEM_ROM);
|
||||
|
||||
{
|
||||
@ -760,7 +760,7 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device,
|
||||
for (i = 0; i < nb_option_roms; i++) {
|
||||
size = get_image_size(option_rom[i]);
|
||||
if (size < 0) {
|
||||
fprintf(stderr, "Could not load option rom '%s'\n",
|
||||
fprintf(stderr, "Could not load option rom '%s'\n",
|
||||
option_rom[i]);
|
||||
exit(1);
|
||||
}
|
||||
@ -781,9 +781,9 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device,
|
||||
}
|
||||
|
||||
/* map all the bios at the top of memory */
|
||||
cpu_register_physical_memory((uint32_t)(-bios_size),
|
||||
cpu_register_physical_memory((uint32_t)(-bios_size),
|
||||
bios_size, bios_offset | IO_MEM_ROM);
|
||||
|
||||
|
||||
bochs_bios_init();
|
||||
|
||||
if (linux_boot)
|
||||
@ -807,11 +807,11 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device,
|
||||
|
||||
if (cirrus_vga_enabled) {
|
||||
if (pci_enabled) {
|
||||
pci_cirrus_vga_init(pci_bus,
|
||||
ds, phys_ram_base + vga_ram_addr,
|
||||
pci_cirrus_vga_init(pci_bus,
|
||||
ds, phys_ram_base + vga_ram_addr,
|
||||
vga_ram_addr, vga_ram_size);
|
||||
} else {
|
||||
isa_cirrus_vga_init(ds, phys_ram_base + vga_ram_addr,
|
||||
isa_cirrus_vga_init(ds, phys_ram_base + vga_ram_addr,
|
||||
vga_ram_addr, vga_ram_size);
|
||||
}
|
||||
} else if (vmsvga_enabled) {
|
||||
@ -822,10 +822,10 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device,
|
||||
fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__);
|
||||
} else {
|
||||
if (pci_enabled) {
|
||||
pci_vga_init(pci_bus, ds, phys_ram_base + vga_ram_addr,
|
||||
pci_vga_init(pci_bus, ds, phys_ram_base + vga_ram_addr,
|
||||
vga_ram_addr, vga_ram_size, 0, 0);
|
||||
} else {
|
||||
isa_vga_init(ds, phys_ram_base + vga_ram_addr,
|
||||
isa_vga_init(ds, phys_ram_base + vga_ram_addr,
|
||||
vga_ram_addr, vga_ram_size);
|
||||
}
|
||||
}
|
||||
@ -914,7 +914,7 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device,
|
||||
smbus_eeprom_device_init(smbus, 0x50 + i, eeprom_buf + (i * 256));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (i440fx_state) {
|
||||
i440fx_init_memory_mappings(i440fx_state);
|
||||
}
|
||||
@ -938,9 +938,9 @@ static void pc_init1(int ram_size, int vga_ram_size, int boot_device,
|
||||
}
|
||||
|
||||
static void pc_init_pci(int ram_size, int vga_ram_size, int boot_device,
|
||||
DisplayState *ds, const char **fd_filename,
|
||||
int snapshot,
|
||||
const char *kernel_filename,
|
||||
DisplayState *ds, const char **fd_filename,
|
||||
int snapshot,
|
||||
const char *kernel_filename,
|
||||
const char *kernel_cmdline,
|
||||
const char *initrd_filename,
|
||||
const char *cpu_model)
|
||||
@ -952,9 +952,9 @@ static void pc_init_pci(int ram_size, int vga_ram_size, int boot_device,
|
||||
}
|
||||
|
||||
static void pc_init_isa(int ram_size, int vga_ram_size, int boot_device,
|
||||
DisplayState *ds, const char **fd_filename,
|
||||
int snapshot,
|
||||
const char *kernel_filename,
|
||||
DisplayState *ds, const char **fd_filename,
|
||||
int snapshot,
|
||||
const char *kernel_filename,
|
||||
const char *kernel_cmdline,
|
||||
const char *initrd_filename,
|
||||
const char *cpu_model)
|
||||
|
42
hw/pci.c
42
hw/pci.c
@ -2,7 +2,7 @@
|
||||
* QEMU PCI bus manager
|
||||
*
|
||||
* Copyright (c) 2004 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -96,16 +96,16 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
|
||||
}
|
||||
|
||||
/* -1 for devfn means auto assign */
|
||||
PCIDevice *pci_register_device(PCIBus *bus, const char *name,
|
||||
PCIDevice *pci_register_device(PCIBus *bus, const char *name,
|
||||
int instance_size, int devfn,
|
||||
PCIConfigReadFunc *config_read,
|
||||
PCIConfigReadFunc *config_read,
|
||||
PCIConfigWriteFunc *config_write)
|
||||
{
|
||||
PCIDevice *pci_dev;
|
||||
|
||||
if (pci_irq_index >= PCI_DEVICES_MAX)
|
||||
return NULL;
|
||||
|
||||
|
||||
if (devfn < 0) {
|
||||
for(devfn = bus->devfn_min ; devfn < 256; devfn += 8) {
|
||||
if (!bus->devices[devfn])
|
||||
@ -134,8 +134,8 @@ PCIDevice *pci_register_device(PCIBus *bus, const char *name,
|
||||
return pci_dev;
|
||||
}
|
||||
|
||||
void pci_register_io_region(PCIDevice *pci_dev, int region_num,
|
||||
uint32_t size, int type,
|
||||
void pci_register_io_region(PCIDevice *pci_dev, int region_num,
|
||||
uint32_t size, int type,
|
||||
PCIMapIORegionFunc *map_func)
|
||||
{
|
||||
PCIIORegion *r;
|
||||
@ -166,7 +166,7 @@ static void pci_update_mappings(PCIDevice *d)
|
||||
PCIIORegion *r;
|
||||
int cmd, i;
|
||||
uint32_t last_addr, new_addr, config_ofs;
|
||||
|
||||
|
||||
cmd = le16_to_cpu(*(uint16_t *)(d->config + PCI_COMMAND));
|
||||
for(i = 0; i < PCI_NUM_REGIONS; i++) {
|
||||
r = &d->io_regions[i];
|
||||
@ -178,7 +178,7 @@ static void pci_update_mappings(PCIDevice *d)
|
||||
if (r->size != 0) {
|
||||
if (r->type & PCI_ADDRESS_SPACE_IO) {
|
||||
if (cmd & PCI_COMMAND_IO) {
|
||||
new_addr = le32_to_cpu(*(uint32_t *)(d->config +
|
||||
new_addr = le32_to_cpu(*(uint32_t *)(d->config +
|
||||
config_ofs));
|
||||
new_addr = new_addr & ~(r->size - 1);
|
||||
last_addr = new_addr + r->size - 1;
|
||||
@ -192,7 +192,7 @@ static void pci_update_mappings(PCIDevice *d)
|
||||
}
|
||||
} else {
|
||||
if (cmd & PCI_COMMAND_MEMORY) {
|
||||
new_addr = le32_to_cpu(*(uint32_t *)(d->config +
|
||||
new_addr = le32_to_cpu(*(uint32_t *)(d->config +
|
||||
config_ofs));
|
||||
/* the ROM slot has a specific enable bit */
|
||||
if (i == PCI_ROM_SLOT && !(new_addr & 1))
|
||||
@ -227,7 +227,7 @@ static void pci_update_mappings(PCIDevice *d)
|
||||
}
|
||||
} else {
|
||||
cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
|
||||
r->size,
|
||||
r->size,
|
||||
IO_MEM_UNASSIGNED);
|
||||
}
|
||||
}
|
||||
@ -240,7 +240,7 @@ static void pci_update_mappings(PCIDevice *d)
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t pci_default_read_config(PCIDevice *d,
|
||||
uint32_t pci_default_read_config(PCIDevice *d,
|
||||
uint32_t address, int len)
|
||||
{
|
||||
uint32_t val;
|
||||
@ -266,13 +266,13 @@ uint32_t pci_default_read_config(PCIDevice *d,
|
||||
return val;
|
||||
}
|
||||
|
||||
void pci_default_write_config(PCIDevice *d,
|
||||
void pci_default_write_config(PCIDevice *d,
|
||||
uint32_t address, uint32_t val, int len)
|
||||
{
|
||||
int can_write, i;
|
||||
uint32_t end, addr;
|
||||
|
||||
if (len == 4 && ((address >= 0x10 && address < 0x10 + 4 * 6) ||
|
||||
if (len == 4 && ((address >= 0x10 && address < 0x10 + 4 * 6) ||
|
||||
(address >= 0x30 && address < 0x34))) {
|
||||
PCIIORegion *r;
|
||||
int reg;
|
||||
@ -367,7 +367,7 @@ void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len)
|
||||
PCIBus *s = opaque;
|
||||
PCIDevice *pci_dev;
|
||||
int config_addr, bus_num;
|
||||
|
||||
|
||||
#if defined(DEBUG_PCI) && 0
|
||||
printf("pci_data_write: addr=%08x val=%08x len=%d\n",
|
||||
addr, val, len);
|
||||
@ -440,7 +440,7 @@ static void pci_set_irq(void *opaque, int irq_num, int level)
|
||||
PCIDevice *pci_dev = (PCIDevice *)opaque;
|
||||
PCIBus *bus;
|
||||
int change;
|
||||
|
||||
|
||||
change = level - pci_dev->irq_state[irq_num];
|
||||
if (!change)
|
||||
return;
|
||||
@ -465,7 +465,7 @@ typedef struct {
|
||||
const char *desc;
|
||||
} pci_class_desc;
|
||||
|
||||
static pci_class_desc pci_class_descriptions[] =
|
||||
static pci_class_desc pci_class_descriptions[] =
|
||||
{
|
||||
{ 0x0100, "SCSI controller"},
|
||||
{ 0x0101, "IDE controller"},
|
||||
@ -538,10 +538,10 @@ static void pci_info_device(PCIDevice *d)
|
||||
if (r->size != 0) {
|
||||
term_printf(" BAR%d: ", i);
|
||||
if (r->type & PCI_ADDRESS_SPACE_IO) {
|
||||
term_printf("I/O at 0x%04x [0x%04x].\n",
|
||||
term_printf("I/O at 0x%04x [0x%04x].\n",
|
||||
r->addr, r->addr + r->size - 1);
|
||||
} else {
|
||||
term_printf("32 bit memory at 0x%08x [0x%08x].\n",
|
||||
term_printf("32 bit memory at 0x%08x [0x%08x].\n",
|
||||
r->addr, r->addr + r->size - 1);
|
||||
}
|
||||
}
|
||||
@ -556,7 +556,7 @@ void pci_for_each_device(int bus_num, void (*fn)(PCIDevice *d))
|
||||
PCIBus *bus = first_bus;
|
||||
PCIDevice *d;
|
||||
int devfn;
|
||||
|
||||
|
||||
while (bus && bus->bus_num != bus_num)
|
||||
bus = bus->next;
|
||||
if (bus) {
|
||||
@ -603,7 +603,7 @@ typedef struct {
|
||||
PCIBus *bus;
|
||||
} PCIBridge;
|
||||
|
||||
void pci_bridge_write_config(PCIDevice *d,
|
||||
void pci_bridge_write_config(PCIDevice *d,
|
||||
uint32_t address, uint32_t val, int len)
|
||||
{
|
||||
PCIBridge *s = (PCIBridge *)d;
|
||||
@ -624,7 +624,7 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint32_t id,
|
||||
pci_map_irq_fn map_irq, const char *name)
|
||||
{
|
||||
PCIBridge *s;
|
||||
s = (PCIBridge *)pci_register_device(bus, name, sizeof(PCIBridge),
|
||||
s = (PCIBridge *)pci_register_device(bus, name, sizeof(PCIBridge),
|
||||
devfn, NULL, pci_bridge_write_config);
|
||||
s->dev.config[0x00] = id >> 16;
|
||||
s->dev.config[0x01] = id >> 24;
|
||||
|
@ -2,7 +2,7 @@
|
||||
* QEMU Common PCI Host bridge configuration data space access routines.
|
||||
*
|
||||
* Copyright (c) 2006 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
|
10
hw/pckbd.c
10
hw/pckbd.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU PC keyboard emulation
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -148,7 +148,7 @@ static void kbd_update_irq(KBDState *s)
|
||||
if (s->mode & KBD_MODE_MOUSE_INT)
|
||||
irq_mouse_level = 1;
|
||||
} else {
|
||||
if ((s->mode & KBD_MODE_KBD_INT) &&
|
||||
if ((s->mode & KBD_MODE_KBD_INT) &&
|
||||
!(s->mode & KBD_MODE_DISABLE_KBD))
|
||||
irq_kbd_level = 1;
|
||||
}
|
||||
@ -338,7 +338,7 @@ static void kbd_reset(void *opaque)
|
||||
static void kbd_save(QEMUFile* f, void* opaque)
|
||||
{
|
||||
KBDState *s = (KBDState*)opaque;
|
||||
|
||||
|
||||
qemu_put_8s(f, &s->write_cmd);
|
||||
qemu_put_8s(f, &s->status);
|
||||
qemu_put_8s(f, &s->mode);
|
||||
@ -348,7 +348,7 @@ static void kbd_save(QEMUFile* f, void* opaque)
|
||||
static int kbd_load(QEMUFile* f, void* opaque, int version_id)
|
||||
{
|
||||
KBDState *s = (KBDState*)opaque;
|
||||
|
||||
|
||||
if (version_id != 3)
|
||||
return -EINVAL;
|
||||
qemu_get_8s(f, &s->write_cmd);
|
||||
|
148
hw/pcnet.c
148
hw/pcnet.c
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* QEMU AMD PC-Net II (Am79C970A) emulation
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2004 Antony T Curtis
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -21,12 +21,12 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
/* This software was written to be compatible with the specification:
|
||||
* AMD Am79C970A PCnet-PCI II Ethernet Controller Data-Sheet
|
||||
* AMD Publication# 19436 Rev:E Amendment/0 Issue Date: June 2000
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* On Sparc32, this is the Lance (Am7990) part of chip STP2000 (Master I/O), also
|
||||
* produced as NCR89C100. See
|
||||
@ -652,10 +652,10 @@ static const uint32_t crctab[256] = {
|
||||
static inline int padr_match(PCNetState *s, const uint8_t *buf, int size)
|
||||
{
|
||||
struct qemu_ether_header *hdr = (void *)buf;
|
||||
uint8_t padr[6] = {
|
||||
uint8_t padr[6] = {
|
||||
s->csr[12] & 0xff, s->csr[12] >> 8,
|
||||
s->csr[13] & 0xff, s->csr[13] >> 8,
|
||||
s->csr[14] & 0xff, s->csr[14] >> 8
|
||||
s->csr[14] & 0xff, s->csr[14] >> 8
|
||||
};
|
||||
int result = (!CSR_DRCVPA(s)) && !memcmp(hdr->ether_dhost, padr, 6);
|
||||
#ifdef PCNET_DEBUG_MATCH
|
||||
@ -683,13 +683,13 @@ static inline int padr_bcast(PCNetState *s, const uint8_t *buf, int size)
|
||||
static inline int ladr_match(PCNetState *s, const uint8_t *buf, int size)
|
||||
{
|
||||
struct qemu_ether_header *hdr = (void *)buf;
|
||||
if ((*(hdr->ether_dhost)&0x01) &&
|
||||
if ((*(hdr->ether_dhost)&0x01) &&
|
||||
((uint64_t *)&s->csr[8])[0] != 0LL) {
|
||||
uint8_t ladr[8] = {
|
||||
uint8_t ladr[8] = {
|
||||
s->csr[8] & 0xff, s->csr[8] >> 8,
|
||||
s->csr[9] & 0xff, s->csr[9] >> 8,
|
||||
s->csr[10] & 0xff, s->csr[10] >> 8,
|
||||
s->csr[11] & 0xff, s->csr[11] >> 8
|
||||
s->csr[10] & 0xff, s->csr[10] >> 8,
|
||||
s->csr[11] & 0xff, s->csr[11] >> 8
|
||||
};
|
||||
int index = lnc_mchash(hdr->ether_dhost) >> 26;
|
||||
return !!(ladr[index >> 3] & (1 << (index & 7)));
|
||||
@ -697,7 +697,7 @@ static inline int ladr_match(PCNetState *s, const uint8_t *buf, int size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline target_phys_addr_t pcnet_rdra_addr(PCNetState *s, int idx)
|
||||
static inline target_phys_addr_t pcnet_rdra_addr(PCNetState *s, int idx)
|
||||
{
|
||||
while (idx < 1) idx += CSR_RCVRL(s);
|
||||
return s->rdra + ((CSR_RCVRL(s) - idx) * (BCR_SWSTYLE(s) ? 16 : 8));
|
||||
@ -705,8 +705,8 @@ static inline target_phys_addr_t pcnet_rdra_addr(PCNetState *s, int idx)
|
||||
|
||||
static inline int64_t pcnet_get_next_poll_time(PCNetState *s, int64_t current_time)
|
||||
{
|
||||
int64_t next_time = current_time +
|
||||
muldiv64(65536 - (CSR_SPND(s) ? 0 : CSR_POLL(s)),
|
||||
int64_t next_time = current_time +
|
||||
muldiv64(65536 - (CSR_SPND(s) ? 0 : CSR_POLL(s)),
|
||||
ticks_per_sec, 33000000L);
|
||||
if (next_time <= current_time)
|
||||
next_time = current_time + 1;
|
||||
@ -731,7 +731,7 @@ static void pcnet_s_reset(PCNetState *s)
|
||||
s->rdra = 0;
|
||||
s->tdra = 0;
|
||||
s->rap = 0;
|
||||
|
||||
|
||||
s->bcr[BCR_BSBC] &= ~0x0080;
|
||||
|
||||
s->csr[0] = 0x0004;
|
||||
@ -770,7 +770,7 @@ static void pcnet_update_irq(PCNetState *s)
|
||||
{
|
||||
int isr = 0;
|
||||
s->csr[0] &= ~0x0080;
|
||||
|
||||
|
||||
#if 1
|
||||
if (((s->csr[0] & ~s->csr[3]) & 0x5f00) ||
|
||||
(((s->csr[4]>>1) & ~s->csr[4]) & 0x0115) ||
|
||||
@ -790,11 +790,11 @@ static void pcnet_update_irq(PCNetState *s)
|
||||
(!!(s->csr[5] & 0x0008) && !!(s->csr[5] & 0x0010)) /* MPINT */)
|
||||
#endif
|
||||
{
|
||||
|
||||
|
||||
isr = CSR_INEA(s);
|
||||
s->csr[0] |= 0x0080;
|
||||
}
|
||||
|
||||
|
||||
if (!!(s->csr[4] & 0x0080) && CSR_INEA(s)) { /* UINT */
|
||||
s->csr[4] &= ~0x0080;
|
||||
s->csr[4] |= 0x0040;
|
||||
@ -806,7 +806,7 @@ static void pcnet_update_irq(PCNetState *s)
|
||||
}
|
||||
|
||||
#if 1
|
||||
if (((s->csr[5]>>1) & s->csr[5]) & 0x0500)
|
||||
if (((s->csr[5]>>1) & s->csr[5]) & 0x0500)
|
||||
#else
|
||||
if ((!!(s->csr[5] & 0x0400) && !!(s->csr[5] & 0x0800)) /* SINT */ ||
|
||||
(!!(s->csr[5] & 0x0100) && !!(s->csr[5] & 0x0200)) /* SLPINT */ )
|
||||
@ -834,7 +834,7 @@ static void pcnet_init(PCNetState *s)
|
||||
#ifdef PCNET_DEBUG
|
||||
printf("pcnet_init init_addr=0x%08x\n", PHYSADDR(s,CSR_IADR(s)));
|
||||
#endif
|
||||
|
||||
|
||||
if (BCR_SSIZE32(s)) {
|
||||
struct pcnet_initblk32 initblk;
|
||||
s->phys_mem_read(s->dma_opaque, PHYSADDR(s,CSR_IADR(s)),
|
||||
@ -893,12 +893,12 @@ static void pcnet_init(PCNetState *s)
|
||||
CSR_XMTRC(s) = CSR_XMTRL(s);
|
||||
|
||||
#ifdef PCNET_DEBUG
|
||||
printf("pcnet ss32=%d rdra=0x%08x[%d] tdra=0x%08x[%d]\n",
|
||||
printf("pcnet ss32=%d rdra=0x%08x[%d] tdra=0x%08x[%d]\n",
|
||||
BCR_SSIZE32(s),
|
||||
s->rdra, CSR_RCVRL(s), s->tdra, CSR_XMTRL(s));
|
||||
#endif
|
||||
|
||||
s->csr[0] |= 0x0101;
|
||||
s->csr[0] |= 0x0101;
|
||||
s->csr[0] &= ~0x0004; /* clear STOP bit */
|
||||
}
|
||||
|
||||
@ -910,7 +910,7 @@ static void pcnet_start(PCNetState *s)
|
||||
|
||||
if (!CSR_DTX(s))
|
||||
s->csr[0] |= 0x0010; /* set TXON */
|
||||
|
||||
|
||||
if (!CSR_DRX(s))
|
||||
s->csr[0] |= 0x0020; /* set RXON */
|
||||
|
||||
@ -940,15 +940,15 @@ static void pcnet_rdte_poll(PCNetState *s)
|
||||
target_phys_addr_t nrda = pcnet_rdra_addr(s, -1 + CSR_RCVRC(s));
|
||||
target_phys_addr_t nnrd = pcnet_rdra_addr(s, -2 + CSR_RCVRC(s));
|
||||
#else
|
||||
target_phys_addr_t crda = s->rdra +
|
||||
target_phys_addr_t crda = s->rdra +
|
||||
(CSR_RCVRL(s) - CSR_RCVRC(s)) *
|
||||
(BCR_SWSTYLE(s) ? 16 : 8 );
|
||||
int nrdc = CSR_RCVRC(s)<=1 ? CSR_RCVRL(s) : CSR_RCVRC(s)-1;
|
||||
target_phys_addr_t nrda = s->rdra +
|
||||
target_phys_addr_t nrda = s->rdra +
|
||||
(CSR_RCVRL(s) - nrdc) *
|
||||
(BCR_SWSTYLE(s) ? 16 : 8 );
|
||||
int nnrc = nrdc<=1 ? CSR_RCVRL(s) : nrdc-1;
|
||||
target_phys_addr_t nnrd = s->rdra +
|
||||
target_phys_addr_t nnrd = s->rdra +
|
||||
(CSR_RCVRL(s) - nnrc) *
|
||||
(BCR_SWSTYLE(s) ? 16 : 8 );
|
||||
#endif
|
||||
@ -976,7 +976,7 @@ static void pcnet_rdte_poll(PCNetState *s)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (CSR_CRDA(s)) {
|
||||
struct pcnet_RMD rmd;
|
||||
RMDLOAD(&rmd, PHYSADDR(s,CSR_CRDA(s)));
|
||||
@ -991,7 +991,7 @@ static void pcnet_rdte_poll(PCNetState *s)
|
||||
} else {
|
||||
CSR_CRBC(s) = CSR_CRST(s) = 0;
|
||||
}
|
||||
|
||||
|
||||
if (CSR_NRDA(s)) {
|
||||
struct pcnet_RMD rmd;
|
||||
RMDLOAD(&rmd, PHYSADDR(s,CSR_NRDA(s)));
|
||||
@ -1007,7 +1007,7 @@ static int pcnet_tdte_poll(PCNetState *s)
|
||||
{
|
||||
s->csr[34] = s->csr[35] = 0;
|
||||
if (s->tdra) {
|
||||
target_phys_addr_t cxda = s->tdra +
|
||||
target_phys_addr_t cxda = s->tdra +
|
||||
(CSR_XMTRL(s) - CSR_XMTRC(s)) *
|
||||
(BCR_SWSTYLE(s) ? 16 : 8);
|
||||
int bad = 0;
|
||||
@ -1030,14 +1030,14 @@ static int pcnet_tdte_poll(PCNetState *s)
|
||||
if (CSR_CXDA(s)) {
|
||||
struct pcnet_TMD tmd;
|
||||
|
||||
TMDLOAD(&tmd, PHYSADDR(s,CSR_CXDA(s)));
|
||||
TMDLOAD(&tmd, PHYSADDR(s,CSR_CXDA(s)));
|
||||
|
||||
CSR_CXBC(s) = GET_FIELD(tmd.length, TMDL, BCNT);
|
||||
CSR_CXST(s) = tmd.status;
|
||||
} else {
|
||||
CSR_CXBC(s) = CSR_CXST(s) = 0;
|
||||
}
|
||||
|
||||
|
||||
return !!(CSR_CXST(s) & 0x8000);
|
||||
}
|
||||
|
||||
@ -1046,7 +1046,7 @@ static int pcnet_can_receive(void *opaque)
|
||||
PCNetState *s = opaque;
|
||||
if (CSR_STOP(s) || CSR_SPND(s))
|
||||
return 0;
|
||||
|
||||
|
||||
if (s->recv_pos > 0)
|
||||
return 0;
|
||||
|
||||
@ -1076,8 +1076,8 @@ static void pcnet_receive(void *opaque, const uint8_t *buf, int size)
|
||||
size = MIN_BUF_SIZE;
|
||||
}
|
||||
|
||||
if (CSR_PROM(s)
|
||||
|| (is_padr=padr_match(s, buf, size))
|
||||
if (CSR_PROM(s)
|
||||
|| (is_padr=padr_match(s, buf, size))
|
||||
|| (is_bcast=padr_bcast(s, buf, size))
|
||||
|| (is_ladr=ladr_match(s, buf, size))) {
|
||||
|
||||
@ -1093,10 +1093,10 @@ static void pcnet_receive(void *opaque, const uint8_t *buf, int size)
|
||||
nrda = s->rdra +
|
||||
(CSR_RCVRL(s) - rcvrc) *
|
||||
(BCR_SWSTYLE(s) ? 16 : 8 );
|
||||
RMDLOAD(&rmd, PHYSADDR(s,nrda));
|
||||
RMDLOAD(&rmd, PHYSADDR(s,nrda));
|
||||
if (GET_FIELD(rmd.status, RMDS, OWN)) {
|
||||
#ifdef PCNET_DEBUG_RMD
|
||||
printf("pcnet - scan buffer: RCVRC=%d PREV_RCVRC=%d\n",
|
||||
printf("pcnet - scan buffer: RCVRC=%d PREV_RCVRC=%d\n",
|
||||
rcvrc, CSR_RCVRC(s));
|
||||
#endif
|
||||
CSR_RCVRC(s) = rcvrc;
|
||||
@ -1119,7 +1119,7 @@ static void pcnet_receive(void *opaque, const uint8_t *buf, int size)
|
||||
int pktcount = 0;
|
||||
|
||||
memcpy(src, buf, size);
|
||||
|
||||
|
||||
#if 1
|
||||
/* no need to compute the CRC */
|
||||
src[size] = 0;
|
||||
@ -1136,7 +1136,7 @@ static void pcnet_receive(void *opaque, const uint8_t *buf, int size)
|
||||
while (size < 46) {
|
||||
src[size++] = 0;
|
||||
}
|
||||
|
||||
|
||||
while (p != &src[size]) {
|
||||
CRC(fcs, *p++);
|
||||
}
|
||||
@ -1178,7 +1178,7 @@ static void pcnet_receive(void *opaque, const uint8_t *buf, int size)
|
||||
PCNET_RECV_STORE();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#undef PCNET_RECV_STORE
|
||||
@ -1198,27 +1198,27 @@ static void pcnet_receive(void *opaque, const uint8_t *buf, int size)
|
||||
s->csr[0] |= 0x0400;
|
||||
|
||||
#ifdef PCNET_DEBUG
|
||||
printf("RCVRC=%d CRDA=0x%08x BLKS=%d\n",
|
||||
printf("RCVRC=%d CRDA=0x%08x BLKS=%d\n",
|
||||
CSR_RCVRC(s), PHYSADDR(s,CSR_CRDA(s)), pktcount);
|
||||
#endif
|
||||
#ifdef PCNET_DEBUG_RMD
|
||||
PRINT_RMD(&rmd);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
while (pktcount--) {
|
||||
if (CSR_RCVRC(s) <= 1)
|
||||
CSR_RCVRC(s) = CSR_RCVRL(s);
|
||||
else
|
||||
CSR_RCVRC(s)--;
|
||||
CSR_RCVRC(s)--;
|
||||
}
|
||||
|
||||
|
||||
pcnet_rdte_poll(s);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pcnet_poll(s);
|
||||
pcnet_update_irq(s);
|
||||
pcnet_update_irq(s);
|
||||
}
|
||||
|
||||
static void pcnet_transmit(PCNetState *s)
|
||||
@ -1226,7 +1226,7 @@ static void pcnet_transmit(PCNetState *s)
|
||||
target_phys_addr_t xmit_cxda = 0;
|
||||
int count = CSR_XMTRL(s)-1;
|
||||
s->xmit_pos = -1;
|
||||
|
||||
|
||||
if (!CSR_TXON(s)) {
|
||||
s->csr[0] &= ~0x0008;
|
||||
return;
|
||||
@ -1285,7 +1285,7 @@ static void pcnet_transmit(PCNetState *s)
|
||||
if (count--)
|
||||
goto txagain;
|
||||
|
||||
} else
|
||||
} else
|
||||
if (s->xmit_pos >= 0) {
|
||||
struct pcnet_TMD tmd;
|
||||
TMDLOAD(&tmd, PHYSADDR(s,xmit_cxda));
|
||||
@ -1311,7 +1311,7 @@ static void pcnet_poll(PCNetState *s)
|
||||
pcnet_rdte_poll(s);
|
||||
}
|
||||
|
||||
if (CSR_TDMD(s) ||
|
||||
if (CSR_TDMD(s) ||
|
||||
(CSR_TXON(s) && !CSR_DPOLL(s) && pcnet_tdte_poll(s)))
|
||||
{
|
||||
/* prevent recursion */
|
||||
@ -1332,7 +1332,7 @@ static void pcnet_poll_timer(void *opaque)
|
||||
pcnet_transmit(s);
|
||||
}
|
||||
|
||||
pcnet_update_irq(s);
|
||||
pcnet_update_irq(s);
|
||||
|
||||
if (!CSR_STOP(s) && !CSR_SPND(s) && !CSR_DPOLL(s)) {
|
||||
uint64_t now = qemu_get_clock(vm_clock) * 33;
|
||||
@ -1346,7 +1346,7 @@ static void pcnet_poll_timer(void *opaque)
|
||||
} else
|
||||
CSR_POLL(s) = t;
|
||||
}
|
||||
qemu_mod_timer(s->poll_timer,
|
||||
qemu_mod_timer(s->poll_timer,
|
||||
pcnet_get_next_poll_time(s,qemu_get_clock(vm_clock)));
|
||||
}
|
||||
}
|
||||
@ -1379,7 +1379,7 @@ static void pcnet_csr_writew(PCNetState *s, uint32_t rap, uint32_t new_value)
|
||||
if (!CSR_STRT(s) && (val & 2))
|
||||
pcnet_start(s);
|
||||
|
||||
if (CSR_TDMD(s))
|
||||
if (CSR_TDMD(s))
|
||||
pcnet_transmit(s);
|
||||
|
||||
return;
|
||||
@ -1434,11 +1434,11 @@ static void pcnet_csr_writew(PCNetState *s, uint32_t rap, uint32_t new_value)
|
||||
case 3:
|
||||
break;
|
||||
case 4:
|
||||
s->csr[4] &= ~(val & 0x026a);
|
||||
s->csr[4] &= ~(val & 0x026a);
|
||||
val &= ~0x026a; val |= s->csr[4] & 0x026a;
|
||||
break;
|
||||
case 5:
|
||||
s->csr[5] &= ~(val & 0x0a90);
|
||||
s->csr[5] &= ~(val & 0x0a90);
|
||||
val &= ~0x0a90; val |= s->csr[5] & 0x0a90;
|
||||
break;
|
||||
case 16:
|
||||
@ -1592,11 +1592,11 @@ static void pcnet_aprom_writeb(void *opaque, uint32_t addr, uint32_t val)
|
||||
PCNetState *s = opaque;
|
||||
#ifdef PCNET_DEBUG
|
||||
printf("pcnet_aprom_writeb addr=0x%08x val=0x%02x\n", addr, val);
|
||||
#endif
|
||||
#endif
|
||||
/* Check APROMWE bit to enable write access */
|
||||
if (pcnet_bcr_readw(s,2) & 0x80)
|
||||
s->prom[addr & 15] = val;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t pcnet_aprom_readb(void *opaque, uint32_t addr)
|
||||
{
|
||||
@ -1685,7 +1685,7 @@ static void pcnet_ioport_writel(void *opaque, uint32_t addr, uint32_t val)
|
||||
pcnet_bcr_writew(s, BCR_BSBC, pcnet_bcr_readw(s, BCR_BSBC) | 0x0080);
|
||||
#ifdef PCNET_DEBUG_IO
|
||||
printf("device switched into dword i/o mode\n");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
pcnet_update_irq(s);
|
||||
}
|
||||
@ -1695,7 +1695,7 @@ static uint32_t pcnet_ioport_readl(void *opaque, uint32_t addr)
|
||||
PCNetState *s = opaque;
|
||||
uint32_t val = -1;
|
||||
pcnet_poll_timer(s);
|
||||
if (BCR_DWIO(s)) {
|
||||
if (BCR_DWIO(s)) {
|
||||
switch (addr & 0x0f) {
|
||||
case 0x00: /* RDP */
|
||||
val = pcnet_csr_readw(s, s->rap);
|
||||
@ -1719,7 +1719,7 @@ static uint32_t pcnet_ioport_readl(void *opaque, uint32_t addr)
|
||||
return val;
|
||||
}
|
||||
|
||||
static void pcnet_ioport_map(PCIDevice *pci_dev, int region_num,
|
||||
static void pcnet_ioport_map(PCIDevice *pci_dev, int region_num,
|
||||
uint32_t addr, uint32_t size, int type)
|
||||
{
|
||||
PCNetState *d = (PCNetState *)pci_dev;
|
||||
@ -1730,7 +1730,7 @@ static void pcnet_ioport_map(PCIDevice *pci_dev, int region_num,
|
||||
|
||||
register_ioport_write(addr, 16, 1, pcnet_aprom_writeb, d);
|
||||
register_ioport_read(addr, 16, 1, pcnet_aprom_readb, d);
|
||||
|
||||
|
||||
register_ioport_write(addr + 0x10, 0x10, 2, pcnet_ioport_writew, d);
|
||||
register_ioport_read(addr + 0x10, 0x10, 2, pcnet_ioport_readw, d);
|
||||
register_ioport_write(addr + 0x10, 0x10, 4, pcnet_ioport_writel, d);
|
||||
@ -1747,7 +1747,7 @@ static void pcnet_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t va
|
||||
pcnet_aprom_writeb(d, addr & 0x0f, val);
|
||||
}
|
||||
|
||||
static uint32_t pcnet_mmio_readb(void *opaque, target_phys_addr_t addr)
|
||||
static uint32_t pcnet_mmio_readb(void *opaque, target_phys_addr_t addr)
|
||||
{
|
||||
PCNetState *d = opaque;
|
||||
uint32_t val = -1;
|
||||
@ -1774,7 +1774,7 @@ static void pcnet_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t va
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t pcnet_mmio_readw(void *opaque, target_phys_addr_t addr)
|
||||
static uint32_t pcnet_mmio_readw(void *opaque, target_phys_addr_t addr)
|
||||
{
|
||||
PCNetState *d = opaque;
|
||||
uint32_t val = -1;
|
||||
@ -1809,7 +1809,7 @@ static void pcnet_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t va
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t pcnet_mmio_readl(void *opaque, target_phys_addr_t addr)
|
||||
static uint32_t pcnet_mmio_readl(void *opaque, target_phys_addr_t addr)
|
||||
{
|
||||
PCNetState *d = opaque;
|
||||
uint32_t val;
|
||||
@ -1931,7 +1931,7 @@ static CPUReadMemoryFunc *pcnet_mmio_read[] = {
|
||||
(CPUReadMemoryFunc *)&pcnet_mmio_readl
|
||||
};
|
||||
|
||||
static void pcnet_mmio_map(PCIDevice *pci_dev, int region_num,
|
||||
static void pcnet_mmio_map(PCIDevice *pci_dev, int region_num,
|
||||
uint32_t addr, uint32_t size, int type)
|
||||
{
|
||||
PCNetState *d = (PCNetState *)pci_dev;
|
||||
@ -1961,28 +1961,28 @@ void pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||
uint8_t *pci_conf;
|
||||
|
||||
#if 0
|
||||
printf("sizeof(RMD)=%d, sizeof(TMD)=%d\n",
|
||||
printf("sizeof(RMD)=%d, sizeof(TMD)=%d\n",
|
||||
sizeof(struct pcnet_RMD), sizeof(struct pcnet_TMD));
|
||||
#endif
|
||||
|
||||
d = (PCNetState *)pci_register_device(bus, "PCNet", sizeof(PCNetState),
|
||||
devfn, NULL, NULL);
|
||||
|
||||
|
||||
pci_conf = d->dev.config;
|
||||
|
||||
|
||||
*(uint16_t *)&pci_conf[0x00] = cpu_to_le16(0x1022);
|
||||
*(uint16_t *)&pci_conf[0x02] = cpu_to_le16(0x2000);
|
||||
*(uint16_t *)&pci_conf[0x04] = cpu_to_le16(0x0007);
|
||||
*(uint16_t *)&pci_conf[0x02] = cpu_to_le16(0x2000);
|
||||
*(uint16_t *)&pci_conf[0x04] = cpu_to_le16(0x0007);
|
||||
*(uint16_t *)&pci_conf[0x06] = cpu_to_le16(0x0280);
|
||||
pci_conf[0x08] = 0x10;
|
||||
pci_conf[0x09] = 0x00;
|
||||
pci_conf[0x0a] = 0x00; // ethernet network controller
|
||||
pci_conf[0x0a] = 0x00; // ethernet network controller
|
||||
pci_conf[0x0b] = 0x02;
|
||||
pci_conf[0x0e] = 0x00; // header_type
|
||||
|
||||
|
||||
*(uint32_t *)&pci_conf[0x10] = cpu_to_le32(0x00000001);
|
||||
*(uint32_t *)&pci_conf[0x14] = cpu_to_le32(0x00000000);
|
||||
|
||||
|
||||
pci_conf[0x3d] = 1; // interrupt pin 0
|
||||
pci_conf[0x3e] = 0x06;
|
||||
pci_conf[0x3f] = 0xff;
|
||||
@ -1991,12 +1991,12 @@ void pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn)
|
||||
d->mmio_index =
|
||||
cpu_register_io_memory(0, pcnet_mmio_read, pcnet_mmio_write, d);
|
||||
|
||||
pci_register_io_region((PCIDevice *)d, 0, PCNET_IOPORT_SIZE,
|
||||
pci_register_io_region((PCIDevice *)d, 0, PCNET_IOPORT_SIZE,
|
||||
PCI_ADDRESS_SPACE_IO, pcnet_ioport_map);
|
||||
|
||||
pci_register_io_region((PCIDevice *)d, 1, PCNET_PNPMMIO_SIZE,
|
||||
|
||||
pci_register_io_region((PCIDevice *)d, 1, PCNET_PNPMMIO_SIZE,
|
||||
PCI_ADDRESS_SPACE_MEM, pcnet_mmio_map);
|
||||
|
||||
|
||||
d->irq = d->dev.irq[0];
|
||||
d->phys_mem_read = pci_physical_memory_read;
|
||||
d->phys_mem_write = pci_physical_memory_write;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* CFI parallel flash with AMD command set emulation
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2005 Jocelyn Mayer
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -185,7 +185,7 @@ static uint32_t pflash_read (pflash_t *pfl, uint32_t offset, int width)
|
||||
}
|
||||
|
||||
/* update flash content on disk */
|
||||
static void pflash_update(pflash_t *pfl, int offset,
|
||||
static void pflash_update(pflash_t *pfl, int offset,
|
||||
int size)
|
||||
{
|
||||
int offset_end;
|
||||
@ -194,7 +194,7 @@ static void pflash_update(pflash_t *pfl, int offset,
|
||||
/* round to sectors */
|
||||
offset = offset >> 9;
|
||||
offset_end = (offset_end + 511) >> 9;
|
||||
bdrv_write(pfl->bs, offset, pfl->storage + (offset << 9),
|
||||
bdrv_write(pfl->bs, offset, pfl->storage + (offset << 9),
|
||||
offset_end - offset);
|
||||
}
|
||||
}
|
||||
@ -222,7 +222,7 @@ static void pflash_write (pflash_t *pfl, uint32_t offset, uint32_t value,
|
||||
offset -= (uint32_t)(long)pfl->storage;
|
||||
else
|
||||
offset -= pfl->base;
|
||||
|
||||
|
||||
DPRINTF("%s: offset " TARGET_FMT_lx " %08x %d\n", __func__,
|
||||
offset, value, width);
|
||||
/* Set the device in I/O access mode */
|
||||
@ -369,7 +369,7 @@ static void pflash_write (pflash_t *pfl, uint32_t offset, uint32_t value,
|
||||
pfl->status = 0x00;
|
||||
pflash_update(pfl, 0, pfl->total_len);
|
||||
/* Let's wait 5 seconds before chip erase is done */
|
||||
qemu_mod_timer(pfl->timer,
|
||||
qemu_mod_timer(pfl->timer,
|
||||
qemu_get_clock(vm_clock) + (ticks_per_sec * 5));
|
||||
break;
|
||||
case 0x30:
|
||||
@ -382,7 +382,7 @@ static void pflash_write (pflash_t *pfl, uint32_t offset, uint32_t value,
|
||||
pflash_update(pfl, offset, pfl->sector_len);
|
||||
pfl->status = 0x00;
|
||||
/* Let's wait 1/2 second before sector erase is done */
|
||||
qemu_mod_timer(pfl->timer,
|
||||
qemu_mod_timer(pfl->timer,
|
||||
qemu_get_clock(vm_clock) + (ticks_per_sec / 2));
|
||||
break;
|
||||
default:
|
||||
@ -524,7 +524,7 @@ static int ctz32 (uint32_t n)
|
||||
pflash_t *pflash_register (target_phys_addr_t base, ram_addr_t off,
|
||||
BlockDriverState *bs,
|
||||
uint32_t sector_len, int nb_blocs, int width,
|
||||
uint16_t id0, uint16_t id1,
|
||||
uint16_t id0, uint16_t id1,
|
||||
uint16_t id2, uint16_t id3)
|
||||
{
|
||||
pflash_t *pfl;
|
||||
|
@ -2,7 +2,7 @@
|
||||
* QEMU i440FX/PIIX3 PCI Bridge Emulation
|
||||
*
|
||||
* Copyright (c) 2006 Fabrice Bellard
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
@ -63,19 +63,19 @@ static void update_pam(PCIDevice *d, uint32_t start, uint32_t end, int r)
|
||||
switch(r) {
|
||||
case 3:
|
||||
/* RAM */
|
||||
cpu_register_physical_memory(start, end - start,
|
||||
cpu_register_physical_memory(start, end - start,
|
||||
start);
|
||||
break;
|
||||
case 1:
|
||||
/* ROM (XXX: not quite correct) */
|
||||
cpu_register_physical_memory(start, end - start,
|
||||
cpu_register_physical_memory(start, end - start,
|
||||
start | IO_MEM_ROM);
|
||||
break;
|
||||
case 2:
|
||||
case 0:
|
||||
/* XXX: should distinguish read/write cases */
|
||||
for(addr = start; addr < end; addr += 4096) {
|
||||
cpu_register_physical_memory(addr, 4096,
|
||||
cpu_register_physical_memory(addr, 4096,
|
||||
isa_page_descs[(addr - 0xa0000) >> 12]);
|
||||
}
|
||||
break;
|
||||
@ -97,7 +97,7 @@ static void i440fx_update_memory_mappings(PCIDevice *d)
|
||||
cpu_register_physical_memory(0xa0000, 0x20000, 0xa0000);
|
||||
} else {
|
||||
for(addr = 0xa0000; addr < 0xc0000; addr += 4096) {
|
||||
cpu_register_physical_memory(addr, 4096,
|
||||
cpu_register_physical_memory(addr, 4096,
|
||||
isa_page_descs[(addr - 0xa0000) >> 12]);
|
||||
}
|
||||
}
|
||||
@ -124,7 +124,7 @@ void i440fx_init_memory_mappings(PCIDevice *d)
|
||||
}
|
||||
}
|
||||
|
||||
static void i440fx_write_config(PCIDevice *d,
|
||||
static void i440fx_write_config(PCIDevice *d,
|
||||
uint32_t address, uint32_t val, int len)
|
||||
{
|
||||
/* XXX: implement SMRAM.D_LOCK */
|
||||
@ -175,7 +175,7 @@ PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
|
||||
register_ioport_read(0xcfc, 4, 2, pci_host_data_readw, s);
|
||||
register_ioport_read(0xcfc, 4, 4, pci_host_data_readl, s);
|
||||
|
||||
d = pci_register_device(b, "i440FX", sizeof(PCIDevice), 0,
|
||||
d = pci_register_device(b, "i440FX", sizeof(PCIDevice), 0,
|
||||
NULL, i440fx_write_config);
|
||||
|
||||
d->config[0x00] = 0x86; // vendor_id
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Arm PrimeCell PL011 UART
|
||||
*
|
||||
* Copyright (c) 2006 CodeSourcery.
|
||||
@ -44,7 +44,7 @@ static const unsigned char pl011_id[] =
|
||||
static void pl011_update(pl011_state *s)
|
||||
{
|
||||
uint32_t flags;
|
||||
|
||||
|
||||
flags = s->int_level & s->int_enabled;
|
||||
qemu_set_irq(s->irq, flags != 0);
|
||||
}
|
||||
@ -240,7 +240,7 @@ void pl011_init(uint32_t base, qemu_irq irq,
|
||||
s->ifl = 0x12;
|
||||
s->cr = 0x300;
|
||||
s->flags = 0x90;
|
||||
if (chr){
|
||||
if (chr){
|
||||
qemu_chr_add_handlers(chr, pl011_can_receive, pl011_receive,
|
||||
pl011_event, s);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Arm PrimeCell PL050 Keyboard / Mouse Interface
|
||||
*
|
||||
* Copyright (c) 2006-2007 CodeSourcery.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Arm PrimeCell PL080/PL081 DMA controller
|
||||
*
|
||||
* Copyright (c) 2006 CodeSourcery.
|
||||
@ -111,7 +111,7 @@ again:
|
||||
continue;
|
||||
flow = (ch->conf >> 11) & 7;
|
||||
if (flow >= 4) {
|
||||
cpu_abort(cpu_single_env,
|
||||
cpu_abort(cpu_single_env,
|
||||
"pl080_run: Peripheral flow control not implemented\n");
|
||||
}
|
||||
src_id = (ch->conf >> 1) & 0x1f;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Arm PrimeCell PL110 Color LCD Controller
|
||||
*
|
||||
* Copyright (c) 2005-2006 CodeSourcery.
|
||||
@ -117,7 +117,7 @@ static void pl110_update_display(void *opaque)
|
||||
|
||||
if (!pl110_enabled(s))
|
||||
return;
|
||||
|
||||
|
||||
switch (s->ds->depth) {
|
||||
case 0:
|
||||
return;
|
||||
@ -151,7 +151,7 @@ static void pl110_update_display(void *opaque)
|
||||
fn = fntable[s->bpp + 12];
|
||||
else
|
||||
fn = fntable[s->bpp];
|
||||
|
||||
|
||||
src_width = s->cols;
|
||||
switch (s->bpp) {
|
||||
case BPP_1:
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Arm PrimeCell PL110 Color LCD Controller
|
||||
*
|
||||
* Copyright (c) 2005 CodeSourcery, LLC.
|
||||
@ -15,7 +15,7 @@
|
||||
#define COPY_PIXEL(to, from) *(to++) = from
|
||||
#elif BITS == 15 || BITS == 16
|
||||
#define COPY_PIXEL(to, from) *(uint16_t *)to = from; to += 2;
|
||||
#elif BITS == 24
|
||||
#elif BITS == 24
|
||||
#define COPY_PIXEL(to, from) \
|
||||
*(to++) = from; *(to++) = (from) >> 8; *(to++) = (from) >> 16
|
||||
#elif BITS == 32
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user