Commit bcf7f61f authored by Shenghou Ma's avatar Shenghou Ma

[dev.power64] cmd/9a: use liblink, add required additional instructions.

LGTM=rsc
R=rsc, iant
CC=golang-codereviews
https://golang.org/cl/127730043
parent fcb842c6
# Copyright 2012 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
include ../../Make.dist
install: y.tab.h
y.tab.h: a.y
LANG=C LANGUAGE=en_US.UTF8 bison -d -v -y a.y
...@@ -27,19 +27,23 @@ ...@@ -27,19 +27,23 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#include <u.h>
#include <libc.h>
#include <bio.h> #include <bio.h>
#include "../9c/9.out.h" #include <link.h>
#include "../9l/9.out.h"
#ifndef EXTERN #ifndef EXTERN
#define EXTERN extern #define EXTERN extern
#endif #endif
#undef getc
#undef ungetc
#undef BUFSIZ
#define getc ccgetc
#define ungetc ccungetc
typedef struct Sym Sym; typedef struct Sym Sym;
typedef struct Gen Gen;
typedef struct Io Io; typedef struct Io Io;
typedef struct Hist Hist;
#define MAXALIGN 7 #define MAXALIGN 7
#define FPCHIP 1 #define FPCHIP 1
...@@ -48,32 +52,15 @@ typedef struct Hist Hist; ...@@ -48,32 +52,15 @@ typedef struct Hist Hist;
#define HISTSZ 20 #define HISTSZ 20
#define NINCLUDE 10 #define NINCLUDE 10
#define NHUNK 10000 #define NHUNK 10000
#ifndef EOF
#define EOF (-1) #define EOF (-1)
#endif
#define IGN (-2) #define IGN (-2)
#define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff) #define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)
#define NHASH 503 #define NHASH 503
#define STRINGSZ 200 #define STRINGSZ 200
#define NMACRO 10 #define NMACRO 10
#define ALLOC(lhs, type)\
while(nhunk < sizeof(type))\
gethunk();\
lhs = (type*)hunk;\
nhunk -= sizeof(type);\
hunk += sizeof(type);
#define ALLOCN(lhs, len, n)\
if(lhs+len != hunk || nhunk < n) {\
while(nhunk <= len)\
gethunk();\
memmove(hunk, lhs, len);\
lhs = hunk;\
hunk += len;\
nhunk -= len;\
}\
hunk += n;\
nhunk -= n;
struct Sym struct Sym
{ {
Sym* link; Sym* link;
...@@ -85,7 +72,7 @@ struct Sym ...@@ -85,7 +72,7 @@ struct Sym
}; };
#define S ((Sym*)0) #define S ((Sym*)0)
struct EXTERN struct
{ {
char* p; char* p;
int c; int c;
...@@ -101,72 +88,47 @@ struct Io ...@@ -101,72 +88,47 @@ struct Io
}; };
#define I ((Io*)0) #define I ((Io*)0)
struct
{
Sym* sym;
short type;
} h[NSYM];
struct Gen
{
Sym* sym;
vlong offset;
short type;
short reg;
short xreg;
short name;
ushort mask;
double dval;
char sval[8];
};
struct Hist
{
Hist* link;
char* name;
long line;
vlong offset;
};
#define H ((Hist*)0)
enum enum
{ {
CLAST, CLAST,
CMACARG, CMACARG,
CMACRO, CMACRO,
CPREPROC CPREPROC,
}; };
EXTERN char debug[256]; EXTERN int debug[256];
EXTERN Sym* hash[NHASH]; EXTERN Sym* hash[NHASH];
EXTERN char* Dlist[30]; EXTERN char** Dlist;
EXTERN int nDlist; EXTERN int nDlist;
EXTERN Hist* ehist;
EXTERN int newflag; EXTERN int newflag;
EXTERN Hist* hist;
EXTERN char* hunk; EXTERN char* hunk;
EXTERN char* include[NINCLUDE]; EXTERN char** include;
EXTERN Io* iofree; EXTERN Io* iofree;
EXTERN Io* ionext; EXTERN Io* ionext;
EXTERN Io* iostack; EXTERN Io* iostack;
EXTERN long lineno; EXTERN int32 lineno;
EXTERN int nerrors; EXTERN int nerrors;
EXTERN long nhunk; EXTERN int32 nhunk;
EXTERN int nosched; EXTERN int nosched;
EXTERN int ninclude; EXTERN int ninclude;
EXTERN Gen nullgen; EXTERN int32 nsymb;
EXTERN Addr nullgen;
EXTERN char* outfile; EXTERN char* outfile;
EXTERN int pass; EXTERN int pass;
EXTERN char* pathname; EXTERN int32 pc;
EXTERN long pc;
EXTERN int peekc; EXTERN int peekc;
EXTERN int sym; EXTERN int sym;
EXTERN char symb[NSYMB]; EXTERN char* symb;
EXTERN int thechar; EXTERN int thechar;
EXTERN char* thestring; EXTERN char* thestring;
EXTERN long thunk; EXTERN int32 thunk;
EXTERN Biobuf obuf; EXTERN Biobuf obuf;
EXTERN Link* ctxt;
EXTERN Biobuf bstdout;
void* alloc(int32);
void* allocn(void*, int32, int32);
void ensuresymb(int32);
void errorexit(void); void errorexit(void);
void pushio(void); void pushio(void);
void newio(void); void newio(void);
...@@ -174,7 +136,7 @@ void newfile(char*, int); ...@@ -174,7 +136,7 @@ void newfile(char*, int);
Sym* slookup(char*); Sym* slookup(char*);
Sym* lookup(void); Sym* lookup(void);
void syminit(Sym*); void syminit(Sym*);
long yylex(void); int32 yylex(void);
int getc(void); int getc(void);
int getnsc(void); int getnsc(void);
void unget(int); void unget(int);
...@@ -182,11 +144,8 @@ int escchar(int); ...@@ -182,11 +144,8 @@ int escchar(int);
void cinit(void); void cinit(void);
void pinit(char*); void pinit(char*);
void cclean(void); void cclean(void);
void outcode(int, Gen*, int, Gen*); void outcode(int, Addr*, int, Addr*);
void outgcode(int, Gen*, int, Gen*, Gen*); void outgcode(int, Addr*, int, Addr*, Addr*);
void zname(char*, int, int);
void zaddr(Gen*, int);
void ieeedtod(Ieee*, double);
int filbuf(void); int filbuf(void);
Sym* getsym(void); Sym* getsym(void);
void domacro(void); void domacro(void);
...@@ -199,31 +158,10 @@ void maclin(void); ...@@ -199,31 +158,10 @@ void maclin(void);
void macif(int); void macif(int);
void macend(void); void macend(void);
void dodefine(char*); void dodefine(char*);
void prfile(long); void prfile(int32);
void outhist(void);
void linehist(char*, int); void linehist(char*, int);
void gethunk(void); void gethunk(void);
void yyerror(char*, ...); void yyerror(char*, ...);
int yyparse(void); int yyparse(void);
void setinclude(char*); void setinclude(char*);
int assemble(char*); int assemble(char*);
/*
* system-dependent stuff from ../cc/compat.c
*/
enum /* keep in synch with ../cc/cc.h */
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2
};
int mywait(int*);
int mycreat(char*, int);
int systemtype(int);
int pathchar(void);
char* mygetwd(char*, int);
int myexec(char*, char*[]);
int mydup(int, int);
int myfork(void);
int mypipe(int*);
void* mysbrk(ulong);
...@@ -28,7 +28,11 @@ ...@@ -28,7 +28,11 @@
// THE SOFTWARE. // THE SOFTWARE.
%{ %{
#include <u.h>
#include <stdio.h> /* if we don't, bison will, and a.h re-#defines getc */
#include <libc.h>
#include "a.h" #include "a.h"
#include "../../pkg/runtime/funcdata.h"
%} %}
%union %union
{ {
...@@ -36,7 +40,7 @@ ...@@ -36,7 +40,7 @@
vlong lval; vlong lval;
double dval; double dval;
char sval[8]; char sval[8];
Gen gen; Addr addr;
} }
%left '|' %left '|'
%left '^' %left '^'
...@@ -50,14 +54,14 @@ ...@@ -50,14 +54,14 @@
%token <lval> LCONST LSP LSB LFP LPC LCREG LFLUSH %token <lval> LCONST LSP LSB LFP LPC LCREG LFLUSH
%token <lval> LREG LFREG LR LCR LF LFPSCR %token <lval> LREG LFREG LR LCR LF LFPSCR
%token <lval> LLR LCTR LSPR LSPREG LSEG LMSR %token <lval> LLR LCTR LSPR LSPREG LSEG LMSR
%token <lval> LSCHED LXLD LXST LXOP LXMV %token <lval> LPCDAT LFUNCDAT LSCHED LXLD LXST LXOP LXMV
%token <lval> LRLWM LMOVMW LMOVEM LMOVFL LMTFSB LMA %token <lval> LRLWM LMOVMW LMOVEM LMOVFL LMTFSB LMA
%token <dval> LFCONST %token <dval> LFCONST
%token <sval> LSCONST %token <sval> LSCONST
%token <sym> LNAME LLAB LVAR %token <sym> LNAME LLAB LVAR
%type <lval> con expr pointer offset sreg %type <lval> con expr pointer offset sreg
%type <gen> addr rreg regaddr name creg freg xlreg lr ctr %type <addr> addr rreg regaddr name creg freg xlreg lr ctr
%type <gen> imm ximm fimm rel psr lcr cbit fpscr fpscrf msr mask %type <addr> imm ximm fimm rel psr lcr cbit fpscr fpscrf msr mask
%% %%
prog: prog:
| prog line | prog line
...@@ -400,7 +404,7 @@ inst: ...@@ -400,7 +404,7 @@ inst:
} }
| LBRA con ',' con ',' rel | LBRA con ',' con ',' rel
{ {
Gen g; Addr g;
g = nullgen; g = nullgen;
g.type = D_CONST; g.type = D_CONST;
g.offset = $2; g.offset = $2;
...@@ -408,7 +412,7 @@ inst: ...@@ -408,7 +412,7 @@ inst:
} }
| LBRA con ',' con ',' addr | LBRA con ',' con ',' addr
{ {
Gen g; Addr g;
g = nullgen; g = nullgen;
g.type = D_CONST; g.type = D_CONST;
g.offset = $2; g.offset = $2;
...@@ -416,7 +420,7 @@ inst: ...@@ -416,7 +420,7 @@ inst:
} }
| LBRA con ',' con ',' '(' xlreg ')' | LBRA con ',' con ',' '(' xlreg ')'
{ {
Gen g; Addr g;
g = nullgen; g = nullgen;
g.type = D_CONST; g.type = D_CONST;
g.offset = $2; g.offset = $2;
...@@ -572,21 +576,41 @@ inst: ...@@ -572,21 +576,41 @@ inst:
{ {
outcode($1, &nullgen, NREG, &$3); outcode($1, &nullgen, NREG, &$3);
} }
| LNOP imm /* SYSCALL $num: load $num to R0 before syscall and restore R0 to 0 afterwards. */
{
outcode($1, &$2, NREG, &nullgen);
}
/* /*
* word * word
*/ */
| LWORD imm comma | LWORD imm comma
{ {
if($1 == ADWORD && $2.type == D_CONST)
$2.type = D_DCONST;
outcode($1, &$2, NREG, &nullgen); outcode($1, &$2, NREG, &nullgen);
} }
| LWORD ximm comma | LWORD ximm comma
{ {
if($1 == ADWORD && $2.type == D_CONST)
$2.type = D_DCONST;
outcode($1, &$2, NREG, &nullgen); outcode($1, &$2, NREG, &nullgen);
} }
/*
* PCDATA
*/
| LPCDAT imm ',' imm
{
if($2.type != D_CONST || $4.type != D_CONST)
yyerror("arguments to PCDATA must be integer constants");
outcode($1, &$2, NREG, &$4);
}
/*
* FUNCDATA
*/
| LFUNCDAT imm ',' addr
{
if($2.type != D_CONST)
yyerror("index for FUNCDATA must be integer constant");
if($4.type != D_EXTERN && $4.type != D_STATIC && $4.type != D_OREG)
yyerror("value for FUNCDATA must be symbol reference");
outcode($1, &$2, NREG, &$4);
}
/* /*
* END * END
*/ */
...@@ -603,15 +627,15 @@ inst: ...@@ -603,15 +627,15 @@ inst:
} }
| LTEXT name ',' con ',' imm | LTEXT name ',' con ',' imm
{ {
$6.offset &= 0xffffffffull;
$6.offset |= (vlong)ArgsSizeUnknown << 32;
outcode($1, &$2, $4, &$6); outcode($1, &$2, $4, &$6);
} }
| LTEXT name ',' imm ':' imm | LTEXT name ',' con ',' imm '-' con
{ {
outgcode($1, &$2, NREG, &$6, &$4); $6.offset &= 0xffffffffull;
} $6.offset |= ($8 & 0xffffffffull) << 32;
| LTEXT name ',' con ',' imm ':' imm outcode($1, &$2, $4, &$6);
{
outgcode($1, &$2, $4, &$8, &$6);
} }
/* /*
* DATA * DATA
...@@ -649,14 +673,12 @@ rel: ...@@ -649,14 +673,12 @@ rel:
if(pass == 2) if(pass == 2)
yyerror("undefined label: %s", $1->name); yyerror("undefined label: %s", $1->name);
$$.type = D_BRANCH; $$.type = D_BRANCH;
$$.sym = $1;
$$.offset = $2; $$.offset = $2;
} }
| LLAB offset | LLAB offset
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_BRANCH; $$.type = D_BRANCH;
$$.sym = $1;
$$.offset = $1->value + $2; $$.offset = $1->value + $2;
} }
...@@ -774,7 +796,7 @@ mask: ...@@ -774,7 +796,7 @@ mask:
con ',' con con ',' con
{ {
int mb, me; int mb, me;
ulong v; uint32 v;
$$ = nullgen; $$ = nullgen;
$$.type = D_CONST; $$.type = D_CONST;
...@@ -785,9 +807,9 @@ mask: ...@@ -785,9 +807,9 @@ mask:
mb = me = 0; mb = me = 0;
} }
if(mb <= me) if(mb <= me)
v = ((ulong)~0L>>mb) & (~0L<<(31-me)); v = ((uint32)~0L>>mb) & (~0L<<(31-me));
else else
v = ~(((ulong)~0L>>(me+1)) & (~0L<<(31-(mb-1)))); v = ~(((uint32)~0L>>(me+1)) & (~0L<<(31-(mb-1))));
$$.offset = v; $$.offset = v;
} }
...@@ -801,7 +823,7 @@ ximm: ...@@ -801,7 +823,7 @@ ximm:
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_SCONST; $$.type = D_SCONST;
memcpy($$.sval, $2, sizeof($$.sval)); memcpy($$.u.sval, $2, sizeof($$.u.sval));
} }
fimm: fimm:
...@@ -809,13 +831,13 @@ fimm: ...@@ -809,13 +831,13 @@ fimm:
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_FCONST; $$.type = D_FCONST;
$$.dval = $2; $$.u.dval = $2;
} }
| '$' '-' LFCONST | '$' '-' LFCONST
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_FCONST; $$.type = D_FCONST;
$$.dval = -$3; $$.u.dval = -$3;
} }
imm: '$' con imm: '$' con
...@@ -847,7 +869,7 @@ regaddr: ...@@ -847,7 +869,7 @@ regaddr:
$$ = nullgen; $$ = nullgen;
$$.type = D_OREG; $$.type = D_OREG;
$$.reg = $2; $$.reg = $2;
$$.xreg = $4; $$.scale = $4;
$$.offset = 0; $$.offset = 0;
} }
...@@ -867,7 +889,7 @@ name: ...@@ -867,7 +889,7 @@ name:
$$ = nullgen; $$ = nullgen;
$$.type = D_OREG; $$.type = D_OREG;
$$.name = $3; $$.name = $3;
$$.sym = S; $$.sym = nil;
$$.offset = $1; $$.offset = $1;
} }
| LNAME offset '(' pointer ')' | LNAME offset '(' pointer ')'
...@@ -875,7 +897,7 @@ name: ...@@ -875,7 +897,7 @@ name:
$$ = nullgen; $$ = nullgen;
$$.type = D_OREG; $$.type = D_OREG;
$$.name = $4; $$.name = $4;
$$.sym = $1; $$.sym = linklookup(ctxt, $1->name, 0);
$$.offset = $2; $$.offset = $2;
} }
| LNAME '<' '>' offset '(' LSB ')' | LNAME '<' '>' offset '(' LSB ')'
...@@ -883,7 +905,7 @@ name: ...@@ -883,7 +905,7 @@ name:
$$ = nullgen; $$ = nullgen;
$$.type = D_OREG; $$.type = D_OREG;
$$.name = D_STATIC; $$.name = D_STATIC;
$$.sym = $1; $$.sym = linklookup(ctxt, $1->name, 0);
$$.offset = $4; $$.offset = $4;
} }
......
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
/*
9a is a version of the Plan 9 assembler. The original is documented at
http://plan9.bell-labs.com/magic/man2html/1/8a
Go-specific considerations are documented at
http://golang.org/doc/asm
Its target architecture is the Power64, referred to by these tools as
power64 (big endian) or power64le (little endian).
*/
package main
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
/* A Bison parser, made by GNU Bison 2.5. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
LMOVW = 258,
LMOVB = 259,
LABS = 260,
LLOGW = 261,
LSHW = 262,
LADDW = 263,
LCMP = 264,
LCROP = 265,
LBRA = 266,
LFMOV = 267,
LFCONV = 268,
LFCMP = 269,
LFADD = 270,
LFMA = 271,
LTRAP = 272,
LXORW = 273,
LNOP = 274,
LEND = 275,
LRETT = 276,
LWORD = 277,
LTEXT = 278,
LDATA = 279,
LRETRN = 280,
LCONST = 281,
LSP = 282,
LSB = 283,
LFP = 284,
LPC = 285,
LCREG = 286,
LFLUSH = 287,
LREG = 288,
LFREG = 289,
LR = 290,
LCR = 291,
LF = 292,
LFPSCR = 293,
LLR = 294,
LCTR = 295,
LSPR = 296,
LSPREG = 297,
LSEG = 298,
LMSR = 299,
LPCDAT = 300,
LFUNCDAT = 301,
LSCHED = 302,
LXLD = 303,
LXST = 304,
LXOP = 305,
LXMV = 306,
LRLWM = 307,
LMOVMW = 308,
LMOVEM = 309,
LMOVFL = 310,
LMTFSB = 311,
LMA = 312,
LFCONST = 313,
LSCONST = 314,
LNAME = 315,
LLAB = 316,
LVAR = 317
};
#endif
/* Tokens. */
#define LMOVW 258
#define LMOVB 259
#define LABS 260
#define LLOGW 261
#define LSHW 262
#define LADDW 263
#define LCMP 264
#define LCROP 265
#define LBRA 266
#define LFMOV 267
#define LFCONV 268
#define LFCMP 269
#define LFADD 270
#define LFMA 271
#define LTRAP 272
#define LXORW 273
#define LNOP 274
#define LEND 275
#define LRETT 276
#define LWORD 277
#define LTEXT 278
#define LDATA 279
#define LRETRN 280
#define LCONST 281
#define LSP 282
#define LSB 283
#define LFP 284
#define LPC 285
#define LCREG 286
#define LFLUSH 287
#define LREG 288
#define LFREG 289
#define LR 290
#define LCR 291
#define LF 292
#define LFPSCR 293
#define LLR 294
#define LCTR 295
#define LSPR 296
#define LSPREG 297
#define LSEG 298
#define LMSR 299
#define LPCDAT 300
#define LFUNCDAT 301
#define LSCHED 302
#define LXLD 303
#define LXST 304
#define LXOP 305
#define LXMV 306
#define LRLWM 307
#define LMOVMW 308
#define LMOVEM 309
#define LMOVFL 310
#define LMTFSB 311
#define LMA 312
#define LFCONST 313
#define LSCONST 314
#define LNAME 315
#define LLAB 316
#define LVAR 317
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
/* Line 2068 of yacc.c */
#line 38 "a.y"
Sym *sym;
vlong lval;
double dval;
char sval[8];
Addr addr;
/* Line 2068 of yacc.c */
#line 184 "y.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment