59 changed files with 3927 additions and 15 deletions
@ -0,0 +1,244 @@ |
|||
/* BFD back-end for Zilog Z80 COFF binaries.
|
|||
Copyright 2005 Free Software Foundation, Inc. |
|||
Contributed by Arnold Metselaar <arnold_m@operamail.com> |
|||
|
|||
This file is part of BFD, the Binary File Descriptor library. |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 2 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
|||
MA 02110-1301, USA. */ |
|||
|
|||
#include "bfd.h" |
|||
#include "sysdep.h" |
|||
#include "libbfd.h" |
|||
#include "bfdlink.h" |
|||
#include "coff/z80.h" |
|||
#include "coff/internal.h" |
|||
#include "libcoff.h" |
|||
|
|||
#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 0 |
|||
|
|||
static reloc_howto_type r_imm32 = |
|||
HOWTO (R_IMM32, 0, 1, 32, FALSE, 0, |
|||
complain_overflow_dont, 0, "r_imm32", TRUE, 0xffffffff, 0xffffffff, |
|||
FALSE); |
|||
|
|||
static reloc_howto_type r_imm16 = |
|||
HOWTO (R_IMM16, 0, 1, 16, FALSE, 0, |
|||
complain_overflow_dont, 0, "r_imm16", TRUE, 0x0000ffff, 0x0000ffff, |
|||
FALSE); |
|||
|
|||
static reloc_howto_type r_imm8 = |
|||
HOWTO (R_IMM8, 0, 0, 8, FALSE, 0, |
|||
complain_overflow_bitfield, 0, "r_imm8", TRUE, 0x000000ff, 0x000000ff, |
|||
FALSE); |
|||
|
|||
static reloc_howto_type r_jr = |
|||
HOWTO (R_JR, 0, 0, 8, TRUE, 0, |
|||
complain_overflow_signed, 0, "r_jr", FALSE, 0, 0xFF, |
|||
FALSE); |
|||
|
|||
static reloc_howto_type r_off8 = |
|||
HOWTO (R_OFF8, 0, 0, 8, FALSE, 0, |
|||
complain_overflow_signed, 0,"r_off8", FALSE, 0, 0xff, |
|||
FALSE); |
|||
|
|||
|
|||
#define BADMAG(x) Z80BADMAG(x) |
|||
#define Z80 1 /* Customize coffcode.h. */ |
|||
#define __A_MAGIC_SET__ |
|||
|
|||
/* Code to swap in the reloc. */ |
|||
|
|||
#define SWAP_IN_RELOC_OFFSET H_GET_32 |
|||
#define SWAP_OUT_RELOC_OFFSET H_PUT_32 |
|||
|
|||
#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst) \ |
|||
dst->r_stuff[0] = 'S'; \ |
|||
dst->r_stuff[1] = 'C'; |
|||
|
|||
/* Code to turn a r_type into a howto ptr, uses the above howto table. */ |
|||
|
|||
static void |
|||
rtype2howto (arelent *internal, struct internal_reloc *dst) |
|||
{ |
|||
switch (dst->r_type) |
|||
{ |
|||
default: |
|||
abort (); |
|||
break; |
|||
case R_IMM8: |
|||
internal->howto = &r_imm8; |
|||
break; |
|||
case R_IMM16: |
|||
internal->howto = &r_imm16; |
|||
break; |
|||
case R_IMM32: |
|||
internal->howto = &r_imm32; |
|||
break; |
|||
case R_JR: |
|||
internal->howto = &r_jr; |
|||
break; |
|||
case R_OFF8: |
|||
internal->howto = &r_off8; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
#define RTYPE2HOWTO(internal, relocentry) rtype2howto (internal, relocentry) |
|||
|
|||
static reloc_howto_type * |
|||
coff_z80_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
|||
bfd_reloc_code_real_type code) |
|||
{ |
|||
switch (code) |
|||
{ |
|||
case BFD_RELOC_8: return & r_imm8; |
|||
case BFD_RELOC_16: return & r_imm16; |
|||
case BFD_RELOC_32: return & r_imm32; |
|||
case BFD_RELOC_8_PCREL: return & r_jr; |
|||
case BFD_RELOC_Z80_DISP8: return & r_off8; |
|||
default: BFD_FAIL (); |
|||
return NULL; |
|||
} |
|||
} |
|||
|
|||
/* Perform any necessary magic to the addend in a reloc entry. */ |
|||
|
|||
#define CALC_ADDEND(abfd, symbol, ext_reloc, cache_ptr) \ |
|||
cache_ptr->addend = ext_reloc.r_offset; |
|||
|
|||
#define RELOC_PROCESSING(relent,reloc,symbols,abfd,section) \ |
|||
reloc_processing(relent, reloc, symbols, abfd, section) |
|||
|
|||
static void |
|||
reloc_processing (arelent *relent, |
|||
struct internal_reloc *reloc, |
|||
asymbol **symbols, |
|||
bfd *abfd, |
|||
asection *section) |
|||
{ |
|||
relent->address = reloc->r_vaddr; |
|||
rtype2howto (relent, reloc); |
|||
|
|||
if (reloc->r_symndx > 0) |
|||
relent->sym_ptr_ptr = symbols + obj_convert (abfd)[reloc->r_symndx]; |
|||
else |
|||
relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; |
|||
|
|||
relent->addend = reloc->r_offset; |
|||
relent->address -= section->vma; |
|||
} |
|||
|
|||
static void |
|||
extra_case (bfd *in_abfd, |
|||
struct bfd_link_info *link_info, |
|||
struct bfd_link_order *link_order, |
|||
arelent *reloc, |
|||
bfd_byte *data, |
|||
unsigned int *src_ptr, |
|||
unsigned int *dst_ptr) |
|||
{ |
|||
asection * input_section = link_order->u.indirect.section; |
|||
int val; |
|||
|
|||
switch (reloc->howto->type) |
|||
{ |
|||
case R_OFF8: |
|||
val = bfd_coff_reloc16_get_value (reloc, link_info, |
|||
input_section); |
|||
if (val>127 || val<-128) /* Test for overflow. */ |
|||
{ |
|||
if (! ((*link_info->callbacks->reloc_overflow) |
|||
(link_info, NULL, |
|||
bfd_asymbol_name (*reloc->sym_ptr_ptr), |
|||
reloc->howto->name, reloc->addend, input_section->owner, |
|||
input_section, reloc->address))) |
|||
abort (); |
|||
} |
|||
bfd_put_8 (in_abfd, val, data + *dst_ptr); |
|||
(*dst_ptr) += 1; |
|||
(*src_ptr) += 1; |
|||
break; |
|||
|
|||
case R_IMM8: |
|||
val = bfd_get_16 ( in_abfd, data+*src_ptr) |
|||
+ bfd_coff_reloc16_get_value (reloc, link_info, input_section); |
|||
bfd_put_8 (in_abfd, val, data + *dst_ptr); |
|||
(*dst_ptr) += 1; |
|||
(*src_ptr) += 1; |
|||
break; |
|||
|
|||
case R_IMM16: |
|||
val = bfd_get_16 ( in_abfd, data+*src_ptr) |
|||
+ bfd_coff_reloc16_get_value (reloc, link_info, input_section); |
|||
bfd_put_16 (in_abfd, val, data + *dst_ptr); |
|||
(*dst_ptr) += 2; |
|||
(*src_ptr) += 2; |
|||
break; |
|||
|
|||
case R_IMM32: |
|||
val = bfd_get_32 ( in_abfd, data+*src_ptr) |
|||
+ bfd_coff_reloc16_get_value (reloc, link_info, input_section); |
|||
bfd_put_32 (in_abfd, val, data + *dst_ptr); |
|||
(*dst_ptr) += 4; |
|||
(*src_ptr) += 4; |
|||
break; |
|||
|
|||
case R_JR: |
|||
{ |
|||
bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info, |
|||
input_section); |
|||
bfd_vma dot = (link_order->offset |
|||
+ *dst_ptr |
|||
+ input_section->output_section->vma); |
|||
int gap = dst - dot - 1; /* -1, Since the offset is relative
|
|||
to the value of PC after reading |
|||
the offset. */ |
|||
|
|||
if (gap >= 128 || gap < -128) |
|||
{ |
|||
if (! ((*link_info->callbacks->reloc_overflow) |
|||
(link_info, NULL, |
|||
bfd_asymbol_name (*reloc->sym_ptr_ptr), |
|||
reloc->howto->name, reloc->addend, input_section->owner, |
|||
input_section, reloc->address))) |
|||
abort (); |
|||
} |
|||
bfd_put_8 (in_abfd, gap, data + *dst_ptr); |
|||
(*dst_ptr)++; |
|||
(*src_ptr)++; |
|||
break; |
|||
} |
|||
|
|||
default: |
|||
abort (); |
|||
} |
|||
} |
|||
|
|||
#define coff_reloc16_extra_cases extra_case |
|||
#define coff_bfd_reloc_type_lookup coff_z80_reloc_type_lookup |
|||
|
|||
#include "coffcode.h" |
|||
|
|||
#undef coff_bfd_get_relocated_section_contents |
|||
#define coff_bfd_get_relocated_section_contents \ |
|||
bfd_coff_reloc16_get_relocated_section_contents |
|||
|
|||
#undef coff_bfd_relax_section |
|||
#define coff_bfd_relax_section bfd_coff_reloc16_relax_section |
|||
|
|||
CREATE_LITTLE_COFF_TARGET_VEC (z80coff_vec, "coff-z80", 0, 0, '\0', NULL, |
|||
COFF_SWAP_TABLE) |
|||
|
|||
@ -0,0 +1,57 @@ |
|||
/* BFD library support routines for the Z80 architecture.
|
|||
Copyright 2005 Free Software Foundation, Inc. |
|||
Contributed by Arnold Metselaar <arnold_m@operamail.com> |
|||
|
|||
This file is part of BFD, the Binary File Descriptor library. |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 2 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
|||
MA 02110-1301, USA. */ |
|||
|
|||
#include "bfd.h" |
|||
#include "sysdep.h" |
|||
#include "libbfd.h" |
|||
|
|||
const bfd_arch_info_type bfd_z80_arch; |
|||
|
|||
/* This routine is provided two arch_infos and
|
|||
returns whether they'd be compatible. */ |
|||
|
|||
static const bfd_arch_info_type * |
|||
compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b) |
|||
{ |
|||
if (a->arch != b->arch) |
|||
return NULL; |
|||
|
|||
if (a->mach == b->mach) |
|||
return a; |
|||
|
|||
return (a->arch == bfd_arch_z80) ? & bfd_z80_arch : NULL; |
|||
} |
|||
|
|||
#define N(name,print,default,next) \ |
|||
{ 16, 16, 8, bfd_arch_z80, name, "z80", print, 0, default, \ |
|||
compatible, bfd_default_scan, next } |
|||
|
|||
#define M(n) &arch_info_struct[n] |
|||
|
|||
static const bfd_arch_info_type arch_info_struct[] = |
|||
{ |
|||
N (bfd_mach_z80strict, "z80-strict", FALSE, M(1)), |
|||
N (bfd_mach_z80, "z80", FALSE, M(2)), |
|||
N (bfd_mach_z80full, "z80-full", FALSE, M(3)), |
|||
N (bfd_mach_r800, "r800", FALSE, NULL) |
|||
}; |
|||
|
|||
const bfd_arch_info_type bfd_z80_arch = N (0, "z80-any", TRUE, M(0)); |
|||
File diff suppressed because it is too large
@ -0,0 +1,103 @@ |
|||
/* this is tc-z80.h
|
|||
Copyright 2005 Free Software Foundation, Inc. |
|||
|
|||
Contributed by Arnold Metselaar <arnold_m@operamail.com> |
|||
|
|||
This file is part of GAS, the GNU Assembler. |
|||
|
|||
GAS 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, or (at your option) |
|||
any later version. |
|||
|
|||
GAS is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with GAS; see the file COPYING. If not, write to the Free |
|||
Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
|||
02110-1301, USA. */ |
|||
|
|||
#ifndef TC_Z80 |
|||
#define TC_Z80 |
|||
|
|||
#define TARGET_ARCH bfd_arch_z80 |
|||
#define BFD_ARCH TARGET_ARCH |
|||
#define COFF_MAGIC 0x5A80 |
|||
#define TARGET_MACH 0 |
|||
#define TARGET_BYTES_BIG_ENDIAN 0 |
|||
|
|||
/* If you define this macro, GAS will warn about the
|
|||
use of nonstandard escape sequences in a string. */ |
|||
#define ONLY_STANDARD_ESCAPES |
|||
|
|||
/* GAS will call this function for any expression that can not be
|
|||
recognized. When the function is called, `input_line_pointer' |
|||
will point to the start of the expression. */ |
|||
#define md_operand(x) |
|||
|
|||
/* This should just call either `number_to_chars_bigendian' or
|
|||
`number_to_chars_littleendian', whichever is appropriate. On |
|||
targets like the MIPS which support options to change the |
|||
endianness, which function to call is a runtime decision. On |
|||
other targets, `md_number_to_chars' can be a simple macro. */ |
|||
#define md_number_to_chars number_to_chars_littleendian |
|||
|
|||
#define TC_COUNT_RELOC(x) 1 |
|||
|
|||
#define TC_COFF_FIX2RTYPE(fixP) tc_coff_fix2rtype (fixP) |
|||
#define md_convert_frag(b,s,f) as_fatal ("convert_frag called\n") |
|||
#define md_estimate_size_before_relax(f,s) \ |
|||
(as_fatal (_("estimate_size_before_relax called")), 1) |
|||
|
|||
/* Define some functions to be called by generic code. */ |
|||
#define md_end z80_md_end |
|||
#define md_start_line_hook() { if (z80_start_line_hook ()) continue; } |
|||
#define md_optimize_expr z80_optimize_expr |
|||
|
|||
extern void z80_md_end (void); |
|||
extern int z80_start_line_hook (void); |
|||
extern int z80_optimize_expr (expressionS *, operatorT, expressionS *); |
|||
|
|||
#define WORKING_DOT_WORD |
|||
|
|||
/* If you define this macro, it means that `tc_gen_reloc' may return
|
|||
multiple relocation entries for a single fixup. In this case, the |
|||
return value of `tc_gen_reloc' is a pointer to a null terminated |
|||
array. */ |
|||
#undef RELOC_EXPANSION_POSSIBLE |
|||
|
|||
/* No shared lib support, so we don't need to ensure
|
|||
externally visible symbols can be overridden. */ |
|||
#define EXTERN_FORCE_RELOC 0 |
|||
|
|||
/* Values passed to md_apply_fix3 don't include the symbol value. */ |
|||
#define MD_APPLY_SYM_VALUE(FIX) 0 |
|||
|
|||
#define LISTING_WORD_SIZE 2 |
|||
|
|||
/* A '$' is used to refer to the current location or as a hex. prefix. */ |
|||
#define DOLLAR_DOT |
|||
#define DOLLAR_AMBIGU 1 |
|||
#define SINGLE_EQ_COMPARES |
|||
#define LOCAL_LABELS_FB 1 |
|||
#define LITERAL_PREFIXPERCENT_BIN |
|||
#define NUMBERS_WITH_SUFFIX 1 |
|||
#define NO_PSEUDO_DOT 1 |
|||
/* We allow single quotes to delimit character constants as
|
|||
well, but it is cleaner to handle that in tc-z80.c. */ |
|||
#define SINGLE_QUOTE_STRINGS |
|||
#define NO_STRING_ESCAPES |
|||
|
|||
/* An `.lcomm' directive with no explicit alignment parameter will
|
|||
use this macro to set P2VAR to the alignment that a request for |
|||
SIZE bytes will have. The alignment is expressed as a power of |
|||
two. If no alignment should take place, the macro definition |
|||
should do nothing. Some targets define a `.bss' directive that is |
|||
also affected by this macro. The default definition will set |
|||
P2VAR to the truncated power of two of sizes up to eight bytes. */ |
|||
#define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) (P2VAR) = 0 |
|||
|
|||
#endif |
|||
@ -0,0 +1,248 @@ |
|||
@c This is part of the GAS manual. |
|||
@c For copying conditions, see the file as.texinfo. |
|||
|
|||
@ifset GENERIC |
|||
@page |
|||
@node Z80-Dependent |
|||
@chapter Z80 Dependent Features |
|||
@end ifset |
|||
|
|||
@c DO-NOT-COMMIT |
|||
|
|||
@ifclear GENERIC |
|||
@node Machine Dependencies |
|||
@chapter Z80 Dependent Features |
|||
@end ifclear |
|||
|
|||
@cindex Z80 support |
|||
@menu |
|||
* Z80 Options:: Options |
|||
* Z80 Syntax:: Syntax |
|||
* Z80 Floating Point:: Floating Point |
|||
* Z80 Directives:: Z80 Machine Directives |
|||
* Z80 Opcodes:: Opcodes |
|||
@end menu |
|||
|
|||
@node Z80 Options |
|||
@section Options |
|||
@cindex Z80 options |
|||
@cindex options for Z80 |
|||
The Zilog Z80 and Ascii R800 version of @code{@value{AS}} have a few machine |
|||
dependent options. |
|||
@table @option |
|||
@cindex @code{-z80} command line option, Z80 |
|||
@item -z80 |
|||
Produce code for the Z80 processor. There are additional options to |
|||
request warnings and error messages for undocumented instructions. |
|||
@item -ignore-undocumented-instructions |
|||
@itemx -Wnud |
|||
Silently assemble undocumented Z80-instructions that have been adopted |
|||
as documented R800-instructions. |
|||
@item -ignore-unportable-instructions |
|||
@itemx -Wnup |
|||
Silently assemble all undocumented Z80-instructions. |
|||
@item -warn-undocumented-instructions |
|||
@itemx -Wud |
|||
Issue warnings for undocumented Z80-instructions that work on R800, do |
|||
not assemble other undocumented instructions without warning. |
|||
@item -warn-unportable-instructions |
|||
@itemx -Wup |
|||
Issue warnings for other undocumented Z80-instructions, do not treat any |
|||
undocumented instructions as errors. |
|||
@item -forbid-undocumented-instructions |
|||
@itemx -Fud |
|||
Treat all undocumented z80-instructions as errors. |
|||
@item -forbid-unportable-instructions |
|||
@itemx -Fup |
|||
Treat undocumented z80-instructions that do not work on R800 as errors. |
|||
|
|||
@cindex @code{-r800} command line option, Z80 |
|||
@item -r800 |
|||
Produce code for the R800 processor. The assembler does not support |
|||
undocumented instructions for the R800. |
|||
In line with common practice, @code{@value{AS}} uses Z80 instriction names |
|||
for the R800 processor, as far as they exist. |
|||
@end table |
|||
|
|||
@cindex Z80 Syntax |
|||
@node Z80 Syntax |
|||
@section Syntax |
|||
The assembler syntax closely follows the 'Z80 family CPU User Manual' by |
|||
Zilog. |
|||
In expressions a single @samp{=} may be used as ``is equal to'' |
|||
comparison operator. |
|||
|
|||
Suffices can be used to indicate the radix of integer constants; |
|||
@samp{H} or @samp{h} for hexadecimal, @samp{D} or @samp{d} for decimal, |
|||
@samp{Q}, @samp{O}, @samp{q} or @samp{o} for octal, and @samp{B} for |
|||
binary. |
|||
|
|||
The suffix @samp{b} denotes a backreference to local label. |
|||
|
|||
@menu |
|||
* Z80-Chars:: Special Characters |
|||
* Z80-Regs:: Register Names |
|||
* Z80-Case:: Case Sensitivity |
|||
@end menu |
|||
|
|||
@node Z80-Chars |
|||
@subsection Special Characters |
|||
|
|||
@cindex line comment character, Z80 |
|||
@cindex Z80 line comment character |
|||
The semicolon @samp{;} is the line comment character; |
|||
|
|||
@cindex location counter, Z80 |
|||
@cindex hexadecimal prefix, Z80 |
|||
@cindex Z80 $ |
|||
The dollar sign @samp{$} can be used as a prefix for hexadecimal numbers |
|||
and as a symbol denoting the current location counter. |
|||
|
|||
@cindex character escapes, Z80 |
|||
@cindex Z80, \ |
|||
A backslash @samp{\} is an ordinary character for the Z80 assembler. |
|||
|
|||
@cindex character constant, Z80 |
|||
@cindex single quote, Z80 |
|||
@cindex Z80 ' |
|||
The single quote @samp{'} must be followed by a closing quote. If there |
|||
is one character inbetween, it is a character constant, otherwise it is |
|||
a string constant. |
|||
|
|||
@node Z80-Regs |
|||
@subsection Register Names |
|||
@cindex Z80 registers |
|||
@cindex register names, Z80 |
|||
|
|||
The registers are referred to with the letters assigned to them by |
|||
Zilog. In addition @command{@value{AS}} recognises @samp{ixl} and |
|||
@samp{ixh} as the least and most significant octet in @samp{ix}, and |
|||
similarly @samp{iyl} and @samp{iyh} as parts of @samp{iy}. |
|||
|
|||
@c The @samp{'} in @samp{ex af,af'} may be omitted. |
|||
|
|||
@node Z80-Case |
|||
@subsection Case Sensitivity |
|||
@cindex Z80, case sensitivity |
|||
@cindex case sensitivity, Z80 |
|||
|
|||
Upper and lower case are equivalent in register names, opcodes, |
|||
condition codes and assembler directives. |
|||
The case of letters is significant in labels and symbol names. The case |
|||
is also important to distinguish the suffix @samp{b} for a backward reference |
|||
to a local label from the suffix @samp{B} for a number in binary notation. |
|||
|
|||
@node Z80 Floating Point |
|||
@section Floating Point |
|||
@cindex floating point, Z80 |
|||
@cindex Z80 floating point |
|||
Floating-point numbers are not supported. |
|||
|
|||
@node Z80 Directives |
|||
@section Z80 Assembler Directives |
|||
|
|||
@command{@value{AS}} for the Z80 supports some additional directives for |
|||
compatibility with other assemblers. |
|||
|
|||
@cindex Z80-only directives |
|||
These are the additional directives in @code{@value{AS}} for the Z80: |
|||
|
|||
@table @code |
|||
@item db @var{expression}|@var{string}[,@var{expression}|@var{string}...] |
|||
@itemx defb @var{expression}|@var{string}[,@var{expression}|@var{string}...] |
|||
For each @var{string} the characters are copied to the object file, for |
|||
each other @var{expression} the value is stored in one byte, ignoring |
|||
overflow. |
|||
|
|||
@item dw @var{expression}[,@var{expression}...] |
|||
@itemx defw @var{expression}[,@var{expression}...] |
|||
For each @var{expression} the value is stored in two bytes, ignoring |
|||
overflow. |
|||
|
|||
@item ds @var{count}[, @var{value}] |
|||
@itemx defs @var{count}[, @var{value}] |
|||
@c Synonyms for @code{ds.b}, |
|||
@c which should have been described elsewhre |
|||
Fill @var{count} bytes in the object file with @var{value}, if |
|||
@var{value} is omitted it defaults to zero. |
|||
|
|||
@item @var{symbol} equ @var{expression} |
|||
@itemx @var{symbol} defl @var{expression} |
|||
These directives set the value of @var{symbol} to @var{expression}. To |
|||
keep code portable to other assemblers it is best to use @samp{equ} for |
|||
the first definition and @samp{defl} for redefinitions. |
|||
|
|||
@item set |
|||
This is a normal instruction on Z80, and not an assembler directive. |
|||
|
|||
@item psect @var{name} |
|||
A synonym for @xref{Section}, no second argument should be given. |
|||
@ignore |
|||
|
|||
The following attributes will possibly be recognised in the future |
|||
@table @code |
|||
@item abs |
|||
The section is to be absolute. @code{@value{AS}} will issue an error |
|||
message because it can not produce an absolute section. |
|||
@item global |
|||
The section is to be concatenated with other sections of the same name |
|||
by the linker, this is the default. |
|||
@item local |
|||
The section is not global. @code{@value{AS}} will issue a warning if |
|||
object file format is not soff. |
|||
@item ovrld |
|||
The section is to be overlapped with other sections of the same name by |
|||
the linker. @code{@value{AS}} will issue an error message |
|||
because it can not mark a section as such. |
|||
@item pure |
|||
The section is marked as read only. |
|||
@end table |
|||
@end ignore |
|||
|
|||
@end table |
|||
|
|||
@node Z80 Opcodes |
|||
@section Opcodes |
|||
In line with commmon practice Z80 mnonics are used for both the Z80 and |
|||
the R800. |
|||
|
|||
In many instructions it is possible to use one of the half index |
|||
registers (@samp{ixl},@samp{ixh},@samp{iyl},@samp{iyh}) in stead of an |
|||
8-bit general purpose register. This yields instructions that are |
|||
documented on the R800 and undocumented on the Z80. |
|||
Similarly @code{in f,(c)} is documented on the R800 and undocumented on |
|||
the Z80. |
|||
|
|||
The assembler also supports the following undocumented Z80-instructions, |
|||
that have not been adopted in the R800 instruction set: |
|||
@table @code |
|||
@item out (c),0 |
|||
Sends zero to the port pointed to by register c. |
|||
|
|||
@item sli @var{m} |
|||
Equivalent to @code{@var{m} = (@var{m}<<1)+1}, the operand @var{m} can |
|||
be any operand that is valid for @samp{sla}. One can use @samp{sll} as a |
|||
synonym for @samp{sli}. |
|||
|
|||
@item @var{op} (ix+@var{d}), @var{r} |
|||
This is equivalent to |
|||
|
|||
@example |
|||
ld @var{r}, (ix+@var{d}) |
|||
@var{opc} @var{r} |
|||
ld (ix+@var{d}), @var{r} |
|||
@end example |
|||
|
|||
The operation @samp{@var{opc}} may be any of @samp{res @var{b},}, |
|||
@samp{set @var{b},}, @samp{rl}, @samp{rlc}, @samp{rr}, @samp{rrc}, |
|||
@samp{sla}, @samp{sli}, @samp{sra} and @samp{srl}, and the register |
|||
@samp{@var{r}} may be any of @samp{a}, @samp{b}, @samp{c}, @samp{d}, |
|||
@samp{e}, @samp{h} and @samp{l}. |
|||
|
|||
@item @var{opc} (iy+@var{d}), @var{r} |
|||
As above, but with @samp{iy} instead of @samp{ix}. |
|||
@end table |
|||
|
|||
The web site at @uref{http://www.z80.info} is a good starting place to |
|||
find more information on programming the Z80. |
|||
|
|||
@ -0,0 +1,9 @@ |
|||
#objdump: -s -j .data |
|||
#name: quotes |
|||
|
|||
.*:.* |
|||
|
|||
Contents of section .data: |
|||
0000 73696e67 6c653a27 646f7562 6c653a22[ ]+................ |
|||
0010 00657363 6170653a 5c5c08fe 3a[ ]+................ |
|||
#pass |
|||
@ -0,0 +1,11 @@ |
|||
;; test the parsing of strings and character constants |
|||
section .data |
|||
laf: |
|||
defb "single:'" |
|||
defb 'double:"',laf |
|||
defb 'escape:\\' |
|||
|
|||
ex af,af' |
|||
af0: |
|||
cp '9'+1 |
|||
|
|||
@ -0,0 +1,8 @@ |
|||
#objdump: -s -j .data |
|||
#name: .equ redefinitions |
|||
|
|||
.*: .* |
|||
|
|||
Contents of section .data: |
|||
0000 00000000 0[04]00000[04] 0[08]00000[08] 0[0c]00000[0c][ ]+................[ ]* |
|||
#pass |
|||
@ -0,0 +1,11 @@ |
|||
.data |
|||
_start: |
|||
x: defl .-_start |
|||
.long x |
|||
.balign 4 |
|||
x: defl .-_start |
|||
.long x |
|||
x: defl .-_start |
|||
.long x |
|||
x: defl .-_start |
|||
.long x |
|||
@ -0,0 +1,10 @@ |
|||
# run targets for target Z80. |
|||
|
|||
if [istarget z80-*-*] then |
|||
{ |
|||
# test redefinitions |
|||
run_dump_test "redef" |
|||
# test parsing of " and ' |
|||
run_dump_test "quotes" |
|||
|
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
/* coff information for Zilog Z80
|
|||
Copyright 2005 Free Software Foundation, Inc. |
|||
Contributed by Arnold Metselaar <arnold_m@operamail.com> |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 2 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
|||
|
|||
#define L_LNNO_SIZE 4 |
|||
#include "coff/external.h" |
|||
|
|||
/* z80 backend does not use dots in section names. */ |
|||
#undef _TEXT |
|||
#define _TEXT "text" |
|||
#undef _DATA |
|||
#define _DATA "data" |
|||
#undef _BSS |
|||
#define _BSS "bss" |
|||
|
|||
/* Type of cpu is stored in flags. */ |
|||
#define F_MACHMASK 0xF000 |
|||
|
|||
#define Z80MAGIC 0x805A |
|||
|
|||
#define Z80BADMAG(x) (((x).f_magic != Z80MAGIC)) |
|||
|
|||
/* Relocation directives. */ |
|||
|
|||
/* This format actually has more bits than we need. */ |
|||
|
|||
struct external_reloc |
|||
{ |
|||
char r_vaddr[4]; |
|||
char r_symndx[4]; |
|||
char r_offset[4]; |
|||
char r_type[2]; |
|||
char r_stuff[2]; |
|||
}; |
|||
|
|||
#define RELOC struct external_reloc |
|||
#define RELSZ 16 |
|||
@ -0,0 +1,6 @@ |
|||
SCRIPT_NAME=z80 |
|||
OUTPUT_FORMAT="coff-z80" |
|||
OUTPUT_ARCH="z80" |
|||
TEXT_START_ADDR=0x100 |
|||
EXTRA_EM_FILE=z80 |
|||
ARCH=z80 |
|||
@ -0,0 +1,85 @@ |
|||
# This shell script emits C code -*- C -*- |
|||
# to keep track of the machine type of Z80 object files |
|||
# It does some substitutions. |
|||
|
|||
LDEMUL_BEFORE_PARSE=gldz80_before_parse |
|||
LDEMUL_RECOGNIZED_FILE=gldz80_recognized_file |
|||
LDEMUL_AFTER_OPEN=gldz80_after_open |
|||
|
|||
cat >>e${EMULATION_NAME}.c <<EOF |
|||
/* --- \begin{z80.em} */ |
|||
/* Codes for machine types, bitwise or gives the code to use for the |
|||
output. */ |
|||
#define M_Z80STRICT 1 |
|||
#define M_Z80 3 |
|||
#define M_Z80FULL 7 |
|||
#define M_R800 11 |
|||
#define M_Z80ANY 15 |
|||
|
|||
/* Bitwise or of the machine types seen so far. */ |
|||
static int result_mach_type; |
|||
|
|||
static void |
|||
${LDEMUL_BEFORE_PARSE} (void) |
|||
{ |
|||
#ifndef TARGET_ /* I.e., if not generic. */ |
|||
ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown); |
|||
#endif /* not TARGET_ */ |
|||
result_mach_type = M_Z80STRICT; |
|||
} |
|||
|
|||
|
|||
/* Update result_mach_type. */ |
|||
static bfd_boolean |
|||
${LDEMUL_RECOGNIZED_FILE} (lang_input_statement_type *entry) |
|||
{ |
|||
unsigned long mach_type; |
|||
|
|||
mach_type = bfd_get_mach (entry->the_bfd); |
|||
switch (mach_type) |
|||
{ |
|||
case bfd_mach_z80strict: |
|||
result_mach_type |= M_Z80STRICT; |
|||
break; |
|||
case bfd_mach_z80: |
|||
result_mach_type |= M_Z80; |
|||
break; |
|||
case bfd_mach_z80full: |
|||
result_mach_type |= M_Z80FULL; |
|||
break; |
|||
case bfd_mach_r800: |
|||
result_mach_type |= M_R800; |
|||
break; |
|||
default: |
|||
result_mach_type |= M_Z80ANY; |
|||
} |
|||
return FALSE; |
|||
} |
|||
|
|||
/* Set the machine type of the output file based on result_mach_type. */ |
|||
static void |
|||
gldz80_after_open (void) |
|||
{ |
|||
unsigned long mach_type; |
|||
|
|||
switch (result_mach_type) |
|||
{ |
|||
case M_Z80STRICT: |
|||
mach_type = bfd_mach_z80strict; |
|||
break; |
|||
case M_Z80: |
|||
mach_type = bfd_mach_z80; |
|||
break; |
|||
case M_Z80FULL: |
|||
mach_type = bfd_mach_z80full; |
|||
break; |
|||
case M_R800: |
|||
mach_type = bfd_mach_r800; |
|||
break; |
|||
default: |
|||
mach_type = 0; |
|||
} |
|||
bfd_set_arch_mach (output_bfd, bfd_arch_z80, mach_type); |
|||
} |
|||
/* --- \end{z80.em} */ |
|||
EOF |
|||
@ -0,0 +1,35 @@ |
|||
if [ x${LD_FLAG} = x ] |
|||
then |
|||
cat << EOF |
|||
/* Create a cp/m executable; load and execute at 0x100. */ |
|||
OUTPUT_FORMAT("binary") |
|||
. = 0x100; |
|||
__Ltext = .; |
|||
ENTRY (__Ltext) |
|||
EOF |
|||
else |
|||
echo "OUTPUT_FORMAT(\"${OUTPUT_FORMAT}\")" |
|||
fi |
|||
cat <<EOF |
|||
OUTPUT_ARCH("${OUTPUT_ARCH}") |
|||
SECTIONS |
|||
{ |
|||
.text : { |
|||
*(.text) |
|||
*(text) |
|||
${RELOCATING+ __Htext = .;} |
|||
} |
|||
.data : { |
|||
${RELOCATING+ __Ldata = .;} |
|||
*(.data) |
|||
*(data) |
|||
${RELOCATING+ __Hdata = .;} |
|||
} |
|||
.bss : { |
|||
${RELOCATING+ __Lbss = .;} |
|||
*(.bss) |
|||
*(bss) |
|||
${RELOCATING+ __Hbss = .;} |
|||
} |
|||
} |
|||
EOF |
|||
@ -0,0 +1,620 @@ |
|||
/* Print Z80 and R800 instructions
|
|||
Copyright 2005 Free Software Foundation, Inc. |
|||
Contributed by Arnold Metselaar <arnold_m@operamail.com> |
|||
|
|||
This file is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 2 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
|||
MA 02110-1301, USA. */ |
|||
|
|||
#include "sysdep.h" |
|||
#include "dis-asm.h" |
|||
#include <stdio.h> |
|||
|
|||
struct buffer |
|||
{ |
|||
bfd_vma base; |
|||
int n_fetch; |
|||
int n_used; |
|||
char data[4]; |
|||
} ; |
|||
|
|||
typedef int (*func)(struct buffer *, disassemble_info *, char *); |
|||
|
|||
struct tab_elt |
|||
{ |
|||
unsigned char val; |
|||
unsigned char mask; |
|||
func fp; |
|||
char * text; |
|||
} ; |
|||
|
|||
#define TXTSIZ 16 |
|||
/* Names of 16-bit registers. */ |
|||
static char * rr_str[] = { "bc", "de", "hl", "sp" }; |
|||
/* Names of 8-bit registers. */ |
|||
static char * r_str[] = { "b", "c", "d", "e", "h", "l", "(hl)", "a" }; |
|||
/* Texts for condition codes. */ |
|||
static char * cc_str[] = { "nz", "z", "nc", "c", "po", "pe", "p", "m" }; |
|||
/* Instruction names for 8-bit arithmetic, operand "a" is often implicit */ |
|||
static char * arit_str[] = |
|||
{ |
|||
"add a,", "adc a,", "sub ", "sbc a,", "and ", "xor ", "or ", "cp " |
|||
} ; |
|||
|
|||
static int |
|||
fetch_data (struct buffer *buf, disassemble_info * info, int n) |
|||
{ |
|||
int r; |
|||
|
|||
if (buf->n_fetch + n > 4) |
|||
abort (); |
|||
|
|||
r = info->read_memory_func (buf->base + buf->n_fetch, |
|||
buf->data + buf->n_fetch, |
|||
n, info); |
|||
if (r == 0) |
|||
buf->n_fetch += n; |
|||
return !r; |
|||
} |
|||
|
|||
static int |
|||
prt (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
info->fprintf_func (info->stream, "%s", txt); |
|||
buf->n_used = buf->n_fetch; |
|||
return 1; |
|||
} |
|||
|
|||
static int |
|||
prt_e (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
char e; |
|||
int target_addr; |
|||
|
|||
if (fetch_data (buf, info, 1)) |
|||
{ |
|||
e = buf->data[1]; |
|||
target_addr = (buf->base + 2 + e) & 0xffff; |
|||
buf->n_used = buf->n_fetch; |
|||
info->fprintf_func (info->stream, "%s0x%04x", txt, target_addr); |
|||
} |
|||
else |
|||
buf->n_used = -1; |
|||
|
|||
return buf->n_used; |
|||
} |
|||
|
|||
static int |
|||
jr_cc (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
char mytxt[TXTSIZ]; |
|||
|
|||
snprintf (mytxt, TXTSIZ, txt, cc_str[(buf->data[0] >> 3) & 3]); |
|||
return prt_e (buf, info, mytxt); |
|||
} |
|||
|
|||
static int |
|||
prt_nn (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
int nn; |
|||
unsigned char *p; |
|||
|
|||
p = (unsigned char*) buf->data + buf->n_fetch; |
|||
if (fetch_data (buf, info, 2)) |
|||
{ |
|||
nn = p[0] + (p[1] << 8); |
|||
info->fprintf_func (info->stream, txt, nn); |
|||
buf->n_used = buf->n_fetch; |
|||
} |
|||
else |
|||
buf->n_used = -1; |
|||
return buf->n_used; |
|||
} |
|||
|
|||
static int |
|||
prt_rr_nn (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
char mytxt[TXTSIZ]; |
|||
|
|||
snprintf (mytxt, TXTSIZ, txt, rr_str[(buf->data[0] >> 4) & 3]); |
|||
return prt_nn (buf, info, mytxt); |
|||
} |
|||
|
|||
static int |
|||
prt_rr (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
info->fprintf_func (info->stream, "%s%s", txt, |
|||
rr_str[(buf->data[buf->n_fetch - 1] >> 4) & 3]); |
|||
buf->n_used = buf->n_fetch; |
|||
return buf->n_used; |
|||
} |
|||
|
|||
static int |
|||
prt_n (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
int n; |
|||
unsigned char *p; |
|||
|
|||
p = (unsigned char*) buf->data + buf->n_fetch; |
|||
|
|||
if (fetch_data (buf, info, 1)) |
|||
{ |
|||
n = p[0]; |
|||
info->fprintf_func (info->stream, txt, n); |
|||
buf->n_used = buf->n_fetch; |
|||
} |
|||
else |
|||
buf->n_used = -1; |
|||
|
|||
return buf->n_used; |
|||
} |
|||
|
|||
static int |
|||
ld_r_n (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
char mytxt[TXTSIZ]; |
|||
|
|||
snprintf (mytxt, TXTSIZ, txt, r_str[(buf->data[0] >> 3) & 7]); |
|||
return prt_n (buf, info, mytxt); |
|||
} |
|||
|
|||
static int |
|||
prt_r (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
info->fprintf_func (info->stream, txt, |
|||
r_str[(buf->data[buf->n_fetch - 1] >> 3) & 7]); |
|||
buf->n_used = buf->n_fetch; |
|||
return buf->n_used; |
|||
} |
|||
|
|||
static int |
|||
ld_r_r (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
info->fprintf_func (info->stream, txt, |
|||
r_str[(buf->data[buf->n_fetch - 1] >> 3) & 7], |
|||
r_str[buf->data[buf->n_fetch - 1] & 7]); |
|||
buf->n_used = buf->n_fetch; |
|||
return buf->n_used; |
|||
} |
|||
|
|||
static int |
|||
arit_r (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
info->fprintf_func (info->stream, txt, |
|||
arit_str[(buf->data[buf->n_fetch - 1] >> 3) & 7], |
|||
r_str[buf->data[buf->n_fetch - 1] & 7]); |
|||
buf->n_used = buf->n_fetch; |
|||
return buf->n_used; |
|||
} |
|||
|
|||
static int |
|||
prt_cc (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
info->fprintf_func (info->stream, "%s%s", txt, |
|||
cc_str[(buf->data[0] >> 3) & 7]); |
|||
buf->n_used = buf->n_fetch; |
|||
return buf->n_used; |
|||
} |
|||
|
|||
static int |
|||
pop_rr (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
static char *rr_stack[] = { "bc","de","hl","af"}; |
|||
|
|||
info->fprintf_func (info->stream, "%s %s", txt, |
|||
rr_stack[(buf->data[0] >> 4) & 3]); |
|||
buf->n_used = buf->n_fetch; |
|||
return buf->n_used; |
|||
} |
|||
|
|||
|
|||
static int |
|||
jp_cc_nn (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
char mytxt[TXTSIZ]; |
|||
|
|||
snprintf (mytxt,TXTSIZ, |
|||
"%s%s,0x%%04x", txt, cc_str[(buf->data[0] >> 3) & 7]); |
|||
return prt_nn (buf, info, mytxt); |
|||
} |
|||
|
|||
static int |
|||
arit_n (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
char mytxt[TXTSIZ]; |
|||
|
|||
snprintf (mytxt,TXTSIZ, txt, arit_str[(buf->data[0] >> 3) & 7]); |
|||
return prt_n (buf, info, mytxt); |
|||
} |
|||
|
|||
static int |
|||
rst (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
info->fprintf_func (info->stream, txt, buf->data[0] & 0x38); |
|||
buf->n_used = buf->n_fetch; |
|||
return buf->n_used; |
|||
} |
|||
|
|||
|
|||
static int |
|||
cis (struct buffer *buf, disassemble_info * info, char *txt ATTRIBUTE_UNUSED) |
|||
{ |
|||
static char * opar[] = { "ld", "cp", "in", "out" }; |
|||
char * op; |
|||
char c; |
|||
|
|||
c = buf->data[1]; |
|||
op = ((0x13 & c) == 0x13) ? "ot" : (opar[c & 3]); |
|||
info->fprintf_func (info->stream, |
|||
"%s%c%s", op, |
|||
(c & 0x08) ? 'd' : 'i', |
|||
(c & 0x10) ? "r" : ""); |
|||
buf->n_used = 2; |
|||
return buf->n_used; |
|||
} |
|||
|
|||
static int |
|||
dump (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
int i; |
|||
|
|||
info->fprintf_func (info->stream, "defb "); |
|||
for (i = 0; txt[i]; ++i) |
|||
info->fprintf_func (info->stream, i ? ", 0x%02x" : "0x%02x", |
|||
(unsigned char) buf->data[i]); |
|||
buf->n_used = i; |
|||
return buf->n_used; |
|||
} |
|||
|
|||
/* Table to disassemble machine codes with prefix 0xED. */ |
|||
struct tab_elt opc_ed[] = |
|||
{ |
|||
{ 0x70, 0xFF, prt, "in f,(c)" }, |
|||
{ 0x70, 0xFF, dump, "xx" }, |
|||
{ 0x40, 0xC7, prt_r, "in %s,(c)" }, |
|||
{ 0x71, 0xFF, prt, "out (c),0" }, |
|||
{ 0x70, 0xFF, dump, "xx" }, |
|||
{ 0x41, 0xC7, prt_r, "out (c),%s" }, |
|||
{ 0x42, 0xCF, prt_rr, "sbc hl," }, |
|||
{ 0x43, 0xCF, prt_rr_nn, "ld (0x%%04x),%s" }, |
|||
{ 0x44, 0xFF, prt, "neg" }, |
|||
{ 0x45, 0xFF, prt, "retn" }, |
|||
{ 0x46, 0xFF, prt, "im 0" }, |
|||
{ 0x47, 0xFF, prt, "ld i,a" }, |
|||
{ 0x4A, 0xCF, prt_rr, "adc hl," }, |
|||
{ 0x4B, 0xCF, prt_rr_nn, "ld %s,(0x%%04x)" }, |
|||
{ 0x4D, 0xFF, prt, "reti" }, |
|||
{ 0x56, 0xFF, prt, "im 1" }, |
|||
{ 0x57, 0xFF, prt, "ld a,i" }, |
|||
{ 0x5E, 0xFF, prt, "im 2" }, |
|||
{ 0x67, 0xFF, prt, "rrd" }, |
|||
{ 0x6F, 0xFF, prt, "rld" }, |
|||
{ 0xA0, 0xE4, cis, "" }, |
|||
{ 0xC3, 0xFF, prt, "muluw hl,bc" }, |
|||
{ 0xC5, 0xE7, prt_r, "mulub a,%s" }, |
|||
{ 0xF3, 0xFF, prt, "muluw hl,sp" }, |
|||
{ 0x00, 0x00, dump, "xx" } |
|||
}; |
|||
|
|||
static int |
|||
pref_ed (struct buffer * buf, disassemble_info * info, |
|||
char* txt ATTRIBUTE_UNUSED) |
|||
{ |
|||
struct tab_elt *p; |
|||
|
|||
if (fetch_data(buf, info, 1)) |
|||
{ |
|||
for (p = opc_ed; p->val != (buf->data[1] & p->mask); ++p) |
|||
; |
|||
p->fp (buf, info, p->text); |
|||
} |
|||
else |
|||
buf->n_used = -1; |
|||
|
|||
return buf->n_used; |
|||
} |
|||
|
|||
/* Instruction names for the instructions addressing single bits. */ |
|||
static char *cb1_str[] = { "", "bit", "res", "set"}; |
|||
/* Instruction names for shifts and rotates. */ |
|||
static char *cb2_str[] = |
|||
{ |
|||
"rlc", "rrc", "rl", "rr", "sla", "sra", "sli", "srl" |
|||
}; |
|||
|
|||
static int |
|||
pref_cb (struct buffer * buf, disassemble_info * info, |
|||
char* txt ATTRIBUTE_UNUSED) |
|||
{ |
|||
if (fetch_data (buf, info, 1)) |
|||
{ |
|||
buf->n_used = 2; |
|||
if ((buf->data[1] & 0xc0) == 0) |
|||
info->fprintf_func (info->stream, "%s %s", |
|||
cb2_str[(buf->data[1] >> 3) & 7], |
|||
r_str[buf->data[1] & 7]); |
|||
else |
|||
info->fprintf_func (info->stream, "%s %d,%s", |
|||
cb1_str[(buf->data[1] >> 6) & 3], |
|||
(buf->data[1] >> 3) & 7, |
|||
r_str[buf->data[1] & 7]); |
|||
} |
|||
else |
|||
buf->n_used = -1; |
|||
|
|||
return buf->n_used; |
|||
} |
|||
|
|||
static int |
|||
addvv (struct buffer * buf, disassemble_info * info, char* txt) |
|||
{ |
|||
info->fprintf_func (info->stream, "add %s,%s", txt, txt); |
|||
|
|||
return buf->n_used = buf->n_fetch; |
|||
} |
|||
|
|||
static int |
|||
ld_v_v (struct buffer * buf, disassemble_info * info, char* txt) |
|||
{ |
|||
char mytxt[TXTSIZ]; |
|||
|
|||
snprintf (mytxt, TXTSIZ, "ld %s%%s,%s%%s", txt, txt); |
|||
return ld_r_r (buf, info, mytxt); |
|||
} |
|||
|
|||
static int |
|||
prt_d (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
int d; |
|||
signed char *p; |
|||
|
|||
p = (unsigned char*) buf->data + buf->n_fetch; |
|||
|
|||
if (fetch_data (buf, info, 1)) |
|||
{ |
|||
d = p[0]; |
|||
info->fprintf_func (info->stream, txt, d); |
|||
buf->n_used = buf->n_fetch; |
|||
} |
|||
else |
|||
buf->n_used = -1; |
|||
|
|||
return buf->n_used; |
|||
} |
|||
|
|||
static int |
|||
prt_d_n (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
char mytxt[TXTSIZ]; |
|||
int d; |
|||
signed char *p; |
|||
|
|||
p = (unsigned char*) buf->data + buf->n_fetch; |
|||
|
|||
if (fetch_data (buf, info, 1)) |
|||
{ |
|||
d = p[0]; |
|||
snprintf (mytxt, TXTSIZ, txt, d); |
|||
return prt_n (buf, info, mytxt); |
|||
} |
|||
else |
|||
buf->n_used = -1; |
|||
|
|||
return buf->n_used; |
|||
} |
|||
|
|||
static int |
|||
arit_d (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
char mytxt[TXTSIZ]; |
|||
unsigned char c; |
|||
|
|||
c = buf->data[buf->n_fetch - 1]; |
|||
snprintf (mytxt, TXTSIZ, txt, arit_str[(c >> 3) & 7]); |
|||
return prt_d (buf, info, mytxt); |
|||
} |
|||
|
|||
static int |
|||
ld_r_d (struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
char mytxt[TXTSIZ]; |
|||
unsigned char c; |
|||
|
|||
c = buf->data[buf->n_fetch - 1]; |
|||
snprintf (mytxt, TXTSIZ, txt, r_str[(c >> 3) & 7]); |
|||
return prt_d (buf, info, mytxt); |
|||
} |
|||
|
|||
static int |
|||
ld_d_r(struct buffer *buf, disassemble_info * info, char *txt) |
|||
{ |
|||
char mytxt[TXTSIZ]; |
|||
unsigned char c; |
|||
|
|||
c = buf->data[buf->n_fetch - 1]; |
|||
snprintf (mytxt, TXTSIZ, txt, r_str[c & 7]); |
|||
return prt_d (buf, info, mytxt); |
|||
} |
|||
|
|||
static int |
|||
pref_xd_cb (struct buffer * buf, disassemble_info * info, char* txt) |
|||
{ |
|||
if (fetch_data (buf, info, 2)) |
|||
{ |
|||
int d; |
|||
char arg[TXTSIZ]; |
|||
signed char *p; |
|||
|
|||
buf->n_used = 4; |
|||
p = buf->data; |
|||
d = p[2]; |
|||
|
|||
if (((p[3] & 0xC0) == 0x40) || ((p[3] & 7) == 0x06)) |
|||
snprintf (arg, TXTSIZ, "(%s+%d)", txt, d); |
|||
else |
|||
snprintf (arg, TXTSIZ, "(%s+%d),%s", txt, d, r_str[p[3] & 7]); |
|||
|
|||
if ((p[3] & 0xc0) == 0) |
|||
info->fprintf_func (info->stream, "%s %s", |
|||
cb2_str[(buf->data[3] >> 3) & 7], |
|||
arg); |
|||
else |
|||
info->fprintf_func (info->stream, "%s %d,%s", |
|||
cb1_str[(buf->data[3] >> 6) & 3], |
|||
(buf->data[3] >> 3) & 7, |
|||
arg); |
|||
} |
|||
else |
|||
buf->n_used = -1; |
|||
|
|||
return buf->n_used; |
|||
} |
|||
|
|||
/* Table to disassemble machine codes with prefix 0xDD or 0xFD. */ |
|||
static struct tab_elt opc_ind[] = |
|||
{ |
|||
{ 0x24, 0xF7, prt_r, "inc %s%%s" }, |
|||
{ 0x25, 0xF7, prt_r, "dec %s%%s" }, |
|||
{ 0x26, 0xF7, ld_r_n, "ld %s%%s,0x%%%%02x" }, |
|||
{ 0x21, 0xFF, prt_nn, "ld %s,0x%%04x" }, |
|||
{ 0x22, 0xFF, prt_nn, "ld (0x%%04x),%s" }, |
|||
{ 0x2A, 0xFF, prt_nn, "ld %s,(0x%%04x)" }, |
|||
{ 0x23, 0xFF, prt, "inc %s" }, |
|||
{ 0x2B, 0xFF, prt, "dec %s" }, |
|||
{ 0x29, 0xFF, addvv, "%s" }, |
|||
{ 0x09, 0xCF, prt_rr, "add %s," }, |
|||
{ 0x34, 0xFF, prt_d, "inc (%s+%%d)" }, |
|||
{ 0x35, 0xFF, prt_d, "dec (%s+%%d)" }, |
|||
{ 0x36, 0xFF, prt_d_n, "ld (%s+%%d),0x%%02x" }, |
|||
|
|||
{ 0x76, 0xFF, dump, "h" }, |
|||
{ 0x46, 0xC7, ld_r_d, "ld %%s,(%s+%%%%d)" }, |
|||
{ 0x70, 0xF8, ld_d_r, "ld (%s+%%%%d),%%s" }, |
|||
{ 0x64, 0xF6, ld_v_v, "%s" }, |
|||
{ 0x60, 0xF0, ld_r_r, "ld %s%%s,%%s" }, |
|||
{ 0x44, 0xC6, ld_r_r, "ld %%s,%s%%s" }, |
|||
|
|||
{ 0x86, 0xC7, arit_d, "%%s(%s+%%%%d)" }, |
|||
{ 0x84, 0xC6, arit_r, "%%s%s%%s" }, |
|||
|
|||
{ 0xE1, 0xFF, prt, "pop %s" }, |
|||
{ 0xE5, 0xFF, prt, "push %s" }, |
|||
{ 0xCB, 0xFF, pref_xd_cb, "%s" }, |
|||
{ 0xE3, 0xFF, prt, "ex (sp),%s" }, |
|||
{ 0xE9, 0xFF, prt, "jp (%s)" }, |
|||
{ 0xF9, 0xFF, prt, "ld sp,%s" }, |
|||
{ 0x00, 0x00, dump, "?" }, |
|||
} ; |
|||
|
|||
static int |
|||
pref_ind (struct buffer * buf, disassemble_info * info, char* txt) |
|||
{ |
|||
if (fetch_data (buf, info, 1)) |
|||
{ |
|||
char mytxt[TXTSIZ]; |
|||
struct tab_elt *p; |
|||
|
|||
for (p = opc_ind; p->val != (buf->data[1] & p->mask); ++p) |
|||
; |
|||
snprintf (mytxt, TXTSIZ, p->text, txt); |
|||
p->fp (buf, info, mytxt); |
|||
} |
|||
else |
|||
buf->n_used = -1; |
|||
|
|||
return buf->n_used; |
|||
} |
|||
|
|||
/* Table to disassemble machine codes without prefix. */ |
|||
static struct tab_elt opc_main[] = |
|||
{ |
|||
{ 0x00, 0xFF, prt, "nop" }, |
|||
{ 0x01, 0xCF, prt_rr_nn, "ld %s,0x%%04x" }, |
|||
{ 0x02, 0xFF, prt, "ld (bc),a" }, |
|||
{ 0x03, 0xCF, prt_rr, "inc " }, |
|||
{ 0x04, 0xC7, prt_r, "inc %s" }, |
|||
{ 0x05, 0xC7, prt_r, "dec %s" }, |
|||
{ 0x06, 0xC7, ld_r_n, "ld %s,0x%%02x" }, |
|||
{ 0x07, 0xFF, prt, "rlca" }, |
|||
{ 0x08, 0xFF, prt, "ex af,af'" }, |
|||
{ 0x09, 0xCF, prt_rr, "add hl," }, |
|||
{ 0x0A, 0xFF, prt, "ld a,(bc)" }, |
|||
{ 0x0B, 0xCF, prt_rr, "dec " }, |
|||
{ 0x0F, 0xFF, prt, "rrca" }, |
|||
{ 0x10, 0xFF, prt_e, "djnz " }, |
|||
{ 0x12, 0xFF, prt, "ld (de),a" }, |
|||
{ 0x17, 0xFF, prt, "rla" }, |
|||
{ 0x18, 0xFF, prt_e, "jr "}, |
|||
{ 0x1A, 0xFF, prt, "ld a,(de)" }, |
|||
{ 0x1F, 0xFF, prt, "rra" }, |
|||
{ 0x20, 0xE7, jr_cc, "jr %s,"}, |
|||
{ 0x22, 0xFF, prt_nn, "ld (0x%04x),hl" }, |
|||
{ 0x27, 0xFF, prt, "daa"}, |
|||
{ 0x2A, 0xFF, prt_nn, "ld hl,(0x%04x)" }, |
|||
{ 0x2F, 0xFF, prt, "cpl" }, |
|||
{ 0x32, 0xFF, prt_nn, "ld (0x%04x),a" }, |
|||
{ 0x37, 0xFF, prt, "scf" }, |
|||
{ 0x3A, 0xFF, prt_nn, "ld a,(0x%04x)" }, |
|||
{ 0x3F, 0xFF, prt, "ccf" }, |
|||
|
|||
{ 0x76, 0xFF, prt, "halt" }, |
|||
{ 0x40, 0xC0, ld_r_r, "ld %s,%s"}, |
|||
|
|||
{ 0x80, 0xC0, arit_r, "%s%s" }, |
|||
|
|||
{ 0xC0, 0xC7, prt_cc, "ret " }, |
|||
{ 0xC1, 0xCF, pop_rr, "pop" }, |
|||
{ 0xC2, 0xC7, jp_cc_nn, "jp " }, |
|||
{ 0xC3, 0xFF, prt_nn, "jp 0x%04x" }, |
|||
{ 0xC4, 0xC7, jp_cc_nn, "call " }, |
|||
{ 0xC5, 0xCF, pop_rr, "push" }, |
|||
{ 0xC6, 0xC7, arit_n, "%s0x%%02x" }, |
|||
{ 0xC7, 0xC7, rst, "rst 0x%02x" }, |
|||
{ 0xC9, 0xFF, prt, "ret" }, |
|||
{ 0xCB, 0xFF, pref_cb, "" }, |
|||
{ 0xCD, 0xFF, prt_nn, "call 0x%04x" }, |
|||
{ 0xD3, 0xFF, prt_n, "out (0x%02x),a" }, |
|||
{ 0xD9, 0xFF, prt, "exx" }, |
|||
{ 0xDB, 0xFF, prt_n, "in a,(0x%02x)" }, |
|||
{ 0xDD, 0xFF, pref_ind, "ix" }, |
|||
{ 0xE3, 0xFF, prt, "ex (sp),hl" }, |
|||
{ 0xE9, 0xFF, prt, "jp (hl)" }, |
|||
{ 0xEB, 0xFF, prt, "ex de,hl" }, |
|||
{ 0xED, 0xFF, pref_ed, ""}, |
|||
{ 0xF3, 0xFF, prt, "di" }, |
|||
{ 0xF9, 0xFF, prt, "ld sp,hl" }, |
|||
{ 0xFB, 0xFF, prt, "ei" }, |
|||
{ 0xFD, 0xFF, pref_ind, "iy" }, |
|||
{ 0x00, 0x00, prt, "????" }, |
|||
} ; |
|||
|
|||
int |
|||
print_insn_z80 (bfd_vma addr, disassemble_info * info) |
|||
{ |
|||
struct buffer buf; |
|||
struct tab_elt *p; |
|||
|
|||
buf.base = addr; |
|||
buf.n_fetch = 0; |
|||
buf.n_used = 0; |
|||
|
|||
if (! fetch_data (& buf, info, 1)) |
|||
return -1; |
|||
|
|||
for (p = opc_main; p->val != (buf.data[0] & p->mask); ++p) |
|||
; |
|||
p->fp (& buf, info, p->text); |
|||
|
|||
return buf.n_used; |
|||
} |
|||
Loading…
Reference in new issue