Browse Source

have mksys.go replace sys/src/9/mk/parse at large
- get rid of amd64l.h
- get rid of sys.h (mksys generates it now)
- rename _seek.c to seek.c and seek.s to _seek.s, to properly
reflect the symbol names they export
- introduce sys/src/sysconf.json, which contains an array of
system calls and an array of errors.
- bunch of updates to the json files affected

Change-Id: I974e7e0284e02c8c5c19fcae0e8e4970c44fd3d8

Aki Nyrhinen 8 years ago
parent
commit
7c0e118965

+ 4 - 1
.gitignore

@@ -12,8 +12,11 @@ amd64/bin
 amd64/init
 amd64/lib
 
+sys/src/libc/9syscall/sys.h
+sys/src/9/k10/errstr.h
 sys/src/9/k10/sipi.h
-sys/src/9/port/systab.c
+sys/src/9/port/error.h
+sys/src/9/k10/systab.c
 sys/src/9/root/nvram
 
 *.orig

+ 168 - 194
sys/src/9/k10/amd64.h

@@ -1,4 +1,4 @@
-/* 
+/*
  * This file is part of the UCB release of Plan 9. It is subject to the license
  * terms in the LICENSE file found in the top-level directory of this
  * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
@@ -7,199 +7,173 @@
  * in the LICENSE file.
  */
 
-enum {						/* Cr0 */
-	Pe		= 0x00000001,		/* Protected Mode Enable */
-	Mp		= 0x00000002,		/* Monitor Coprocessor */
-	Em		= 0x00000004,		/* Emulate Coprocessor */
-	Ts		= 0x00000008,		/* Task Switched */
-	Et		= 0x00000010,		/* Extension Type */
-	Ne		= 0x00000020,		/* Numeric Error  */
-	Wp		= 0x00010000,		/* Write Protect */
-	Am		= 0x00040000,		/* Alignment Mask */
-	Nw		= 0x20000000,		/* Not Writethrough */
-	Cd		= 0x40000000,		/* Cache Disable */
-	Pg		= 0x80000000,		/* Paging Enable */
-};
-
-enum {						/* Cr3 */
-	Pwt		= 0x00000008,		/* Page-Level Writethrough */
-	Pcd		= 0x00000010,		/* Page-Level Cache Disable */
-};
-
-enum {						/* Cr4 */
-	Vme		= 0x00000001,		/* Virtual-8086 Mode Extensions */
-	Pvi		= 0x00000002,		/* Protected Mode Virtual Interrupts */
-	Tsd		= 0x00000004,		/* Time-Stamp Disable */
-	De		= 0x00000008,		/* Debugging Extensions */
-	Pse		= 0x00000010,		/* Page-Size Extensions */
-	Pae		= 0x00000020,		/* Physical Address Extension */
-	Mce		= 0x00000040,		/* Machine Check Enable */
-	Pge		= 0x00000080,		/* Page-Global Enable */
-	Pce		= 0x00000100,		/* Performance Monitoring Counter Enable */
-	Osfxsr		= 0x00000200,		/* FXSAVE/FXRSTOR Support */
-	Osxmmexcpt	= 0x00000400,		/* Unmasked Exception Support */
-};
-
-enum {						/* Rflags */
-	Cf		= 0x00000001,		/* Carry Flag */
-	Pf		= 0x00000004,		/* Parity Flag */
-	Af		= 0x00000010,		/* Auxiliary Flag */
-	Zf		= 0x00000040,		/* Zero Flag */
-	Sf		= 0x00000080,		/* Sign Flag */
-	Tf		= 0x00000100,		/* Trap Flag */
-	If		= 0x00000200,		/* Interrupt Flag */
-	Df		= 0x00000400,		/* Direction Flag */
-	Of		= 0x00000800,		/* Overflow Flag */
-	Iopl0		= 0x00000000,		/* I/O Privilege Level */
-	Iopl1		= 0x00001000,
-	Iopl2		= 0x00002000,
-	Iopl3		= 0x00003000,
-	Nt		= 0x00004000,		/* Nested Task */
-	Rf		= 0x00010000,		/* Resume Flag */
-	Vm		= 0x00020000,		/* Virtual-8086 Mode */
-	Ac		= 0x00040000,		/* Alignment Check */
-	Vif		= 0x00080000,		/* Virtual Interrupt Flag */
-	Vip		= 0x00100000,		/* Virtual Interrupt Pending */
-	Id		= 0x00200000,		/* ID Flag */
-};
-
-enum {						/* MSRs */
-	PerfEvtbase	= 0xc0010000,		/* Performance Event Select */
-	PerfCtrbase	= 0xc0010004,		/* Performance Counters */
-
-	Efer		= 0xc0000080,		/* Extended Feature Enable */
-	Star		= 0xc0000081,		/* Legacy Target IP and [CS]S */
-	Lstar		= 0xc0000082,		/* Long Mode Target IP */
-	Cstar		= 0xc0000083,		/* Compatibility Target IP */
-	Sfmask		= 0xc0000084,		/* SYSCALL Flags Mask */
-	FSbase		= 0xc0000100,		/* 64-bit FS Base Address */
-	GSbase		= 0xc0000101,		/* 64-bit GS Base Address */
-	KernelGSbase	= 0xc0000102,		/* SWAPGS instruction */
-};
-
-enum {						/* Efer */
-	Sce		= 0x00000001,		/* System Call Extension */
-	Lme		= 0x00000100,		/* Long Mode Enable */
-	Lma		= 0x00000400,		/* Long Mode Active */
-	Nxe		= 0x00000800,		/* No-Execute Enable */
-	Svme		= 0x00001000,		/* SVM Extension Enable */
-	Ffxsr		= 0x00004000,		/* Fast FXSAVE/FXRSTOR */
-};
-
-enum {						/* PML4E/PDPE/PDE/PTE */
-	PteP		= 0x0000000000000001ull,/* Present */
-	PteRW		= 0x0000000000000002ull,/* Read/Write */
-	PteU		= 0x0000000000000004ull,/* User/Supervisor */
-	PtePWT		= 0x0000000000000008ull,/* Page-Level Write Through */
-	PtePCD		= 0x0000000000000010ull,/* Page Level Cache Disable */
-	PteA		= 0x0000000000000020ull,/* Accessed */
-	PteD		= 0x0000000000000040ull,/* Dirty */
-	PtePS		= 0x0000000000000080ull,/* Page Size */
-	Pte4KPAT	= PtePS,		/* PTE PAT */
-	PteG		= 0x0000000000000100ull,/* Global */
-	Pte2MPAT	= 0x0000000000001000ull,/* PDE PAT */
-	Pte1GPAT	= Pte2MPAT,		/* PDPE PAT */
-	PteNX		= 0x8000000000000000ull,/* No Execute */
-};
-
-enum {						/* Exceptions */
-	IdtDE		= 0,			/* Divide-by-Zero Error */
-	IdtDB		= 1,			/* Debug */
-	IdtNMI		= 2,			/* Non-Maskable-Interrupt */
-	IdtBP		= 3,			/* Breakpoint */
-	IdtOF		= 4,			/* Overflow */
-	IdtBR		= 5,			/* Bound-Range */
-	IdtUD		= 6,			/* Invalid-Opcode */
-	IdtNM		= 7,			/* Device-Not-Available */
-	IdtDF		= 8,			/* Double-Fault */
-	Idt09		= 9,			/* unsupported */
-	IdtTS		= 10,			/* Invalid-TSS */
-	IdtNP		= 11,			/* Segment-Not-Present */
-	IdtSS		= 12,			/* Stack */
-	IdtGP		= 13,			/* General-Protection */
-	IdtPF		= 14,			/* Page-Fault */
-	Idt0F		= 15,			/* reserved */
-	IdtMF		= 16,			/* x87 FPE-Pending */
-	IdtAC		= 17,			/* Alignment-Check */
-	IdtMC		= 18,			/* Machine-Check */
-	IdtXF		= 19,			/* SIMD Floating-Point */
-};
-
-/*
- * Vestigial Segmented Virtual Memory.
- */
-enum {						/* Segment Descriptor */
-	SdISTM		= 0x0000000700000000ull,/* Interrupt Stack Table Mask */
-	SdA		= 0x0000010000000000ull,/* Accessed */
-	SdR		= 0x0000020000000000ull,/* Readable (Code) */
-	SdW		= 0x0000020000000000ull,/* Writeable (Data) */
-	SdE		= 0x0000040000000000ull,/* Expand Down */
-	SdaTSS		= 0x0000090000000000ull,/* Available TSS */
-	SdbTSS		= 0x00000b0000000000ull,/* Busy TSS */
-	SdCG		= 0x00000c0000000000ull,/* Call Gate */
-	SdIG		= 0x00000e0000000000ull,/* Interrupt Gate */
-	SdTG		= 0x00000f0000000000ull,/* Trap Gate */
-	SdCODE		= 0x0000080000000000ull,/* Code/Data */
-	SdS		= 0x0000100000000000ull,/* System/User */
-	SdDPL0		= 0x0000000000000000ull,/* Descriptor Privilege Level */
-	SdDPL1		= 0x0000200000000000ull,
-	SdDPL2		= 0x0000400000000000ull,
-	SdDPL3		= 0x0000600000000000ull,
-	SdP		= 0x0000800000000000ull,/* Present */
-	Sd4G		= 0x000f00000000ffffull,/* 4G Limit */
-	SdL		= 0x0020000000000000ull,/* Long Attribute */
-	SdD		= 0x0040000000000000ull,/* Default Operand Size */
-	SdG		= 0x0080000000000000ull,/* Granularity */
-};
-
-/*
- * Performance Counter Configuration
- */
-enum {						/* Performance Event Selector */
-    				 
-	PeHo		= 0x0000020000000000ull,/* Host only */
-	PeGo		= 0x0000010000000000ull,/* Guest only */
-	PeEvMskH	= 0x0000000f00000000ull,/* Event mask H */
-	PeCtMsk		= 0x00000000ff000000ull,/* Counter mask */
-	PeInMsk		= 0x0000000000800000ull,/* Invert mask */
-	PeCtEna		= 0x0000000000400000ull,/* Counter enable */
-	PeInEna		= 0x0000000000100000ull,/* Interrupt enable */
-	PePnCtl		= 0x0000000000080000ull,/* Pin control */
-	PeEdg		= 0x0000000000040000ull,/* Edge detect */
-	PeOS		= 0x0000000000020000ull,/* OS mode */
-	PeUsr		= 0x0000000000010000ull,/* User mode */
-	PeUnMsk		= 0x000000000000ff00ull,/* Unit Mask */
-	PeEvMskL	= 0x00000000000000ffull,/* Event Mask L */
-
-	PeEvMsksh	= 32ull,		/* Event mask shift */
-};
-
-enum {						/* Segment Selector */
-	SsRPL0		= 0x0000,		/* Requestor Privilege Level */
-	SsRPL1		= 0x0001,
-	SsRPL2		= 0x0002,
-	SsRPL3		= 0x0003,
-	SsTIGDT		= 0x0000,		/* GDT Table Indicator  */
-	SsTILDT		= 0x0004,		/* LDT Table Indicator */
-	SsSIM		= 0xfff8,		/* Selector Index Mask */
-};
+/* Cr0 */
+#define Pe		0x00000001		/* Protected Mode Enable */
+#define Mp		0x00000002		/* Monitor Coprocessor */
+#define Em		0x00000004		/* Emulate Coprocessor */
+#define Ts		0x00000008		/* Task Switched */
+#define Et		0x00000010		/* Extension Type */
+#define Ne		0x00000020		/* Numeric Error  */
+#define Wp		0x00010000		/* Write Protect */
+#define Am		0x00040000		/* Alignment Mask */
+#define Nw		0x20000000		/* Not Writethrough */
+#define Cd		0x40000000		/* Cache Disable */
+#define Pg		0x80000000		/* Paging Enable */
+
+/* Cr3 */
+#define Pwt		0x00000008		/* Page-Level Writethrough */
+#define Pcd		0x00000010		/* Page-Level Cache Disable */
+
+/* Cr4 */
+#define Vme		0x00000001		/* Virtual-8086 Mode Extensions */
+#define Pvi		0x00000002		/* Protected Mode Virtual Interrupts */
+#define Tsd		0x00000004		/* Time-Stamp Disable */
+#define De		0x00000008		/* Debugging Extensions */
+#define Pse		0x00000010		/* Page-Size Extensions */
+#define Pae		0x00000020		/* Physical Address Extension */
+#define Mce		0x00000040		/* Machine Check Enable */
+#define Pge		0x00000080		/* Page-Global Enable */
+#define Pce		0x00000100		/* Performance Monitoring Counter Enable */
+#define Osfxsr		0x00000200		/* FXSAVE/FXRSTOR Support */
+#define Osxmmexcpt	0x00000400		/* Unmasked Exception Support */
+
+/* Rflags */
+#define Cf		0x00000001		/* Carry Flag */
+#define Pf		0x00000004		/* Parity Flag */
+#define Af		0x00000010		/* Auxiliary Flag */
+#define Zf		0x00000040		/* Zero Flag */
+#define Sf		0x00000080		/* Sign Flag */
+#define Tf		0x00000100		/* Trap Flag */
+#define If		0x00000200		/* Interrupt Flag */
+#define Df		0x00000400		/* Direction Flag */
+#define Of		0x00000800		/* Overflow Flag */
+#define Iopl0		0x00000000		/* I/O Privilege Level */
+#define Iopl1		0x00001000
+#define Iopl2		0x00002000
+#define Iopl3		0x00003000
+#define Nt		0x00004000		/* Nested Task */
+#define Rf		0x00010000		/* Resume Flag */
+#define Vm		0x00020000		/* Virtual-8086 Mode */
+#define Ac		0x00040000		/* Alignment Check */
+#define Vif		0x00080000		/* Virtual Interrupt Flag */
+#define Vip		0x00100000		/* Virtual Interrupt Pending */
+#define Id		0x00200000		/* ID Flag */
+
+/* MSRs */
+#define PerfEvtbase	0xc0010000		/* Performance Event Select */
+#define PerfCtrbase	0xc0010004		/* Performance Counters */
+
+#define Efer		0xc0000080		/* Extended Feature Enable */
+#define Star		0xc0000081		/* Legacy Target IP and [CS]S */
+#define Lstar		0xc0000082		/* Long Mode Target IP */
+#define Cstar		0xc0000083		/* Compatibility Target IP */
+#define Sfmask		0xc0000084		/* SYSCALL Flags Mask */
+#define FSbase		0xc0000100		/* 64-bit FS Base Address */
+#define GSbase		0xc0000101		/* 64-bit GS Base Address */
+#define KernelGSbase	0xc0000102		/* SWAPGS instruction */
+
+/* Efer */
+#define Sce		0x00000001		/* System Call Extension */
+#define Lme		0x00000100		/* Long Mode Enable */
+#define Lma		0x00000400		/* Long Mode Active */
+#define Nxe		0x00000800		/* No-Execute Enable */
+#define Svme		0x00001000		/* SVM Extension Enable */
+#define Ffxsr		0x00004000		/* Fast FXSAVE/FXRSTOR */
+
+/* PML4E/PDPE/PDE/PTE */
+#define PteP		0x0000000000000001	/* Present */
+#define PteRW		0x0000000000000002	/* Read/Write */
+#define PteU		0x0000000000000004	/* User/Supervisor */
+#define PtePWT		0x0000000000000008	/* Page-Level Write Through */
+#define PtePCD		0x0000000000000010	/* Page Level Cache Disable */
+#define PteA		0x0000000000000020	/* Accessed */
+#define PteD		0x0000000000000040	/* Dirty */
+#define PtePS		0x0000000000000080	/* Page Size */
+#define Pte4KPAT	PtePS			/* PTE PAT */
+#define PteG		0x0000000000000100	/* Global */
+#define Pte2MPAT	0x0000000000001000	/* PDE PAT */
+#define Pte1GPAT	Pte2MPAT		/* PDPE PAT */
+#define PteNX		0x8000000000000000	/* No Execute */
+
+/* Exceptions */
+#define IdtDE		0			/* Divide-by-Zero Error */
+#define IdtDB		1			/* Debug */
+#define IdtNMI		2			/* Non-Maskable-Interrupt */
+#define IdtBP		3			/* Breakpoint */
+#define IdtOF		4			/* Overflow */
+#define IdtBR		5			/* Bound-Range */
+#define IdtUD		6			/* Invalid-Opcode */
+#define IdtNM		7			/* Device-Not-Available */
+#define IdtDF		8			/* Double-Fault */
+#define Idt09		9			/* unsupported */
+#define IdtTS		10			/* Invalid-TSS */
+#define IdtNP		11			/* Segment-Not-Present */
+#define IdtSS		12			/* Stack */
+#define IdtGP		13			/* General-Protection */
+#define IdtPF		14			/* Page-Fault */
+#define Idt0F		15			/* reserved */
+#define IdtMF		16			/* x87 FPE-Pending */
+#define IdtAC		17			/* Alignment-Check */
+#define IdtMC		18			/* Machine-Check */
+#define IdtXF		19			/* SIMD Floating-Point */
+
+/* Vestigial Segmented Virtual Memory */
+#define SdISTM		0x0000000700000000	/* Interrupt Stack Table Mask */
+#define SdA		0x0000010000000000	/* Accessed */
+#define SdR		0x0000020000000000	/* Readable (Code) */
+#define SdW		0x0000020000000000	/* Writeable (Data) */
+#define SdE		0x0000040000000000	/* Expand Down */
+#define SdaTSS		0x0000090000000000	/* Available TSS */
+#define SdbTSS		0x00000b0000000000	/* Busy TSS */
+#define SdCG		0x00000c0000000000	/* Call Gate */
+#define SdIG		0x00000e0000000000	/* Interrupt Gate */
+#define SdTG		0x00000f0000000000	/* Trap Gate */
+#define SdCODE		0x0000080000000000	/* Code/Data */
+#define SdS		0x0000100000000000	/* System/User */
+#define SdDPL0		0x0000000000000000	/* Descriptor Privilege Level */
+#define SdDPL1		0x0000200000000000
+#define SdDPL2		0x0000400000000000
+#define SdDPL3		0x0000600000000000
+#define SdP		0x0000800000000000	/* Present */
+#define Sd4G		0x000f00000000ffff	/* 4G Limit */
+#define SdL		0x0020000000000000	/* Long Attribute */
+#define SdD		0x0040000000000000	/* Default Operand Size */
+#define SdG		0x0080000000000000	/* Granularity */
+
+/* Performance Counter Configuration */
+#define PeHo		0x0000020000000000	/* Host only */
+#define PeGo		0x0000010000000000	/* Guest only */
+#define PeEvMskH	0x0000000f00000000	/* Event mask H */
+#define PeCtMsk		0x00000000ff000000	/* Counter mask */
+#define PeInMsk		0x0000000000800000	/* Invert mask */
+#define PeCtEna		0x0000000000400000	/* Counter enable */
+#define PeInEna		0x0000000000100000	/* Interrupt enable */
+#define PePnCtl		0x0000000000080000	/* Pin control */
+#define PeEdg		0x0000000000040000	/* Edge detect */
+#define PeOS		0x0000000000020000	/* OS mode */
+#define PeUsr		0x0000000000010000	/* User mode */
+#define PeUnMsk		0x000000000000ff00	/* Unit Mask */
+#define PeEvMskL	0x00000000000000ff	/* Event Mask L */
+
+#define PeEvMsksh	32			/* Event mask shift */
+
+/* Segment Selector */
+#define SsRPL0		0x0000			/* Requestor Privilege Level */
+#define SsRPL1		0x0001
+#define SsRPL2		0x0002
+#define SsRPL3		0x0003
+#define SsTIGDT		0x0000			/* GDT Table Indicator  */
+#define SsTILDT		0x0004			/* LDT Table Indicator */
+#define SsSIM		0xfff8			/* Selector Index Mask */
 
 #define SSEL(si, tirpl)	(((si)<<3)|(tirpl))	/* Segment Selector */
 
-enum {
-	SiNULL		= 0,			/* NULL selector index */
-	SiCS		= 1,			/* CS selector index */
-	SiDS		= 2,			/* DS selector index */
-	SiU32CS		= 3,			/* User CS selector index */
-	SiUDS		= 4,			/* User DS selector index */
-	SiUCS		= 5,			/* User CS selector index */
-	SiFS		= 6,			/* FS selector index */
-	SiGS		= 7,			/* GS selector index */
-	SiTSS		= 8,			/* TSS selector index */
-};
-
-/*
- * Extern registers.
- */
-#define RMACH		R15			/* m-> */
-#define RUSER		R14			/* m->externup-> */
+#define SiNULL		0			/* NULL selector index */
+#define SiCS		1			/* CS selector index */
+#define SiDS		2			/* DS selector index */
+#define SiU32CS		3			/* User CS selector index */
+#define SiUDS		4			/* User DS selector index */
+#define SiUCS		5			/* User CS selector index */
+#define SiFS		6			/* FS selector index */
+#define SiGS		7			/* GS selector index */
+#define SiTSS		8			/* TSS selector index */

+ 2 - 3
sys/src/9/k10/core.json

@@ -42,9 +42,8 @@
 		"${TOOLPREFIX}objdump -S 9$CONF \u003e 9$CONF.asm"
 	],
 	"Pre": [
-		"awk -f ../mk/parse -- -mksystab ../../libc/9syscall/sys.h $CONF \u003e systab.c",
-		"awk -f ../mk/mkenumb amd64.h \u003e amd64l.h",
-		"awk -f ../mk/parse -- -mkerrstr $CONF \u003e errstr.h"
+		"mksys -o systab.c -mode=systab.c $HARVEY/sys/src/sysconf.json",
+		"mksys -o errstr.h -mode=errstr.h $HARVEY/sys/src/sysconf.json"
 	],
 	"Projects": [
 		"clean.json",

+ 1 - 1
sys/src/9/k10/entry.S

@@ -1,5 +1,5 @@
 #include "mem.h"
-#include "amd64l.h"
+#include "amd64.h"
 #ifndef __ASSEMBLER__
 #define __ASSEMBLER__
 #endif

+ 1 - 1
sys/src/9/k10/l64acidt.S

@@ -1,7 +1,7 @@
 /*
  * Interrupt/exception handling.
  */
-#include "amd64l.h"
+#include "amd64.h"
 
 .code64
 

+ 1 - 1
sys/src/9/k10/l64idt.S

@@ -1,7 +1,7 @@
 /*
  * Interrupt/exception handling.
  */
-#include "amd64l.h"
+#include "amd64.h"
 
 .code64
 

+ 1 - 1
sys/src/9/k10/l64syscall.s

@@ -1,5 +1,5 @@
 #include "mem.h"
-#include "amd64l.h"
+#include "amd64.h"
 
 .code64
 

+ 1 - 1
sys/src/9/k10/l64v.S

@@ -1,4 +1,4 @@
-#include "amd64l.h"
+#include "amd64.h"
 
 .code64
 

+ 1 - 1
sys/src/9/k10/l64vsyscall.S

@@ -1,5 +1,5 @@
 #include "mem.h"
-#include "amd64l.h"
+#include "amd64.h"
 #ifndef __ASSEMBLER__
 #define __ASSEMBLER__
 #endif

+ 0 - 52
sys/src/9/port/error.h

@@ -1,52 +0,0 @@
-extern char Enoerror[];		/* no error */
-extern char Emount[];		/* inconsistent mount */
-extern char Eunmount[];		/* not mounted */
-extern char Eismtpt[];		/* is a mount point */
-extern char Eunion[];		/* not in union */
-extern char Emountrpc[];	/* mount rpc error */
-extern char Eshutdown[];	/* device shut down */
-extern char Enocreate[];	/* mounted directory forbids creation */
-extern char Enonexist[];	/* file does not exist */
-extern char Eexist[];		/* file already exists */
-extern char Ebadsharp[];	/* unknown device in # filename */
-extern char Enotdir[];		/* not a directory */
-extern char Eisdir[];		/* file is a directory */
-extern char Ebadchar[];		/* bad character in file name */
-extern char Efilename[];	/* file name syntax */
-extern char Eperm[];		/* permission denied */
-extern char Ebadusefd[];	/* inappropriate use of fd */
-extern char Ebadarg[];		/* bad arg in system call */
-extern char Einuse[];		/* device or object already in use */
-extern char Eio[];		/* i/o error */
-extern char Etoobig[];		/* read or write too large */
-extern char Etoosmall[];	/* read or write too small */
-extern char Enoport[];		/* network port not available */
-extern char Ehungup[];		/* i/o on hungup channel */
-extern char Ebadctl[];		/* bad process or channel control request */
-extern char Enodev[];		/* no free devices */
-extern char Eprocdied[];	/* process exited */
-extern char Enochild[];		/* no living children */
-extern char Eioload[];		/* i/o error in demand load */
-extern char Enovmem[];		/* virtual memory allocation failed */
-extern char Ebadfd[];		/* fd out of range or not open */
-extern char Enofd[];		/* no free file descriptors */
-extern char Eisstream[];	/* seek on a stream */
-extern char Ebadexec[];		/* exec header invalid */
-extern char Etimedout[];	/* connection timed out */
-extern char Econrefused[];	/* connection refused */
-extern char Econinuse[];	/* connection in use */
-extern char Eintr[];		/* interrupted */
-extern char Enomem[];		/* kernel allocate failed */
-extern char Enoswap[];		/* swap space full */
-extern char Esoverlap[];	/* segments overlap */
-extern char Eshort[];		/* i/o count too small */
-extern char Egreg[];		/* ken has left the building */
-extern char Ebadspec[];		/* bad attach specifier */
-extern char Enoreg[];		/* process has no saved registers */
-extern char Enoattach[];	/* mount/attach disallowed */
-extern char Eshortstat[];	/* stat buffer too small */
-extern char Ebadstat[];		/* malformed stat buffer */
-extern char Enegoff[];		/* negative i/o offset */
-extern char Ecmdargs[];		/* wrong #args in control message */
-extern char Ebadip[];		/* bad ip address syntax */
-extern char Edirseek[];		/* seek in directory */

+ 3 - 0
sys/src/9/port/port.json

@@ -1,5 +1,8 @@
 {
 	"Name": "port",
+	"Pre": [
+		"mksys -o ../port/error.h -mode=error.h $HARVEY/sys/src/sysconf.json"
+	],
 	"SourceFiles": [
 		"../port/alarm.c",
 		"../port/allocb.c",

+ 6 - 3
sys/src/9/port/portdat.h

@@ -975,12 +975,15 @@ extern	Procalloc	procalloc;
 extern	uint	qiomaxatomic;
 extern	char*	statename[];
 extern	char*	sysname;
-typedef	struct {
+
+typedef	struct Systab Systab;
+struct Systab {
 	char*	n;
 	void (*f)(Ar0*, ...);
 	Ar0	r;
-} systab_t[];
-extern systab_t systab;
+};
+
+extern Systab systab[];
 
 enum
 {

+ 2 - 1
sys/src/all.json

@@ -1,8 +1,9 @@
 {
 	"Name": "All",
 	"Projects": [
-		"libs.json",
 		"klibs.json",
+		"libs.json",
+		"cmd/kcmds.json",
 		"cmd/cmds.json",
 		"9/k10/k8cpu.json"
 	]

+ 2 - 1
sys/src/libc/9syscall/9syscall.json

@@ -2,6 +2,7 @@
 	"Library": "klibc.a",
 	"Name": "KernelLibc",
 	"Pre": [
-		"../../../../util/mksys amd64"
+		"mksys -o sys.h -mode=sys.h $HARVEY/sys/src/sysconf.json",
+		"mksys -o . -mode=syscallfiles $HARVEY/sys/src/sysconf.json"
 	]
 }

+ 0 - 64
sys/src/libc/9syscall/sys.h

@@ -1,64 +0,0 @@
-/* This is going to use linux amd64 numbering. At some point sys.h should move
- * into architecture-dependent directories.
- */
-#define	SYSR1		4096+0
-#define	_ERRSTR		4096+1
-#define	BIND		4096+2
-#define	CHDIR		4096+3
-#define	CLOSE		3
-/* This is Linux dup2. There is no dup on Plan 9. */
-#define	DUP		21
-#define	ALARM		4096+6
-#define	EXEC		4096+7
-#define	EXITS		4096+8
-#define	_FSESSION	4096+9
-#define	FAUTH		4096+10
-#define	_FSTAT		4096+11
-#define	SEGBRK		4096+12
-#define	_MOUNT		4096+13
-#define	OPEN		2
-#define	READ		0
-#define	OSEEK		4096+16
-#define	SLEEP		4096+17
-#define	_STAT		4096+18
-#define	RFORK		4096+19
-#define	WRITE		1
-#define	PIPE		4096+21
-#define	CREATE		4096+22
-#define	FD2PATH		4096+23
-#define	BRK_		4096+24
-#define	REMOVE		4096+25
-#define	_WSTAT		4096+26
-#define	_FWSTAT		4096+27
-#define	NOTIFY		4096+28
-#define	NOTED		4096+29
-#define	SEGATTACH	4096+30
-#define	SEGDETACH	4096+31
-#define	SEGFREE		4096+32
-#define	SEGFLUSH	4096+33
-#define	RENDEZVOUS	4096+34
-#define	UNMOUNT		4096+35
-#define	_WAIT		4096+36
-#define	SEMACQUIRE	4096+37
-#define	SEMRELEASE	4096+38
-#define	SEEK		4096+39
-#define	FVERSION	4096+40
-#define	ERRSTR		4096+41
-#define	STAT		4096+42
-#define	FSTAT		4096+43
-#define	WSTAT		4096+44
-#define	FWSTAT		4096+45
-#define	MOUNT		4096+46
-#define	AWAIT		4096+47
-#define	PREAD		0x11
-#define	PWRITE		0x12
-#define	TSEMACQUIRE	4096+52
-#define NSEC		4096+53
-#define	SEMSLEEP	4096+54
-#define	SEMWAKEUP	4096+55
-#define	SEMALT		4096+56
-#define	EXECAC		4096+57
-#define	NIXSYSCALL	4096+58
-#define	ZIOPREAD	4096+59
-#define	ZIOPWRITE	4096+60
-#define	ZIOFREE		4096+61

+ 0 - 0
sys/src/libc/amd64/_seek.c → sys/src/libc/amd64/seek.c


+ 2 - 2
sys/src/libc/klibc.json

@@ -95,7 +95,7 @@
 		"9syscall/remove.s",
 		"9syscall/rendezvous.s",
 		"9syscall/rfork.s",
-		"9syscall/seek.s",
+		"9syscall/_seek.s",
 		"9syscall/segattach.s",
 		"9syscall/segbrk.s",
 		"9syscall/segdetach.s",
@@ -258,7 +258,7 @@
 		"port/u16.c",
 		"port/u32.c",
 		"port/u64.c",
-		"amd64/_seek.c",
+		"amd64/seek.c",
 		"amd64/notejmp.c",
 		"amd64/cycles.c",
 		"amd64/argv0.c",

+ 2 - 2
sys/src/libc/libc.json

@@ -95,7 +95,7 @@
 		"9syscall/remove.s",
 		"9syscall/rendezvous.s",
 		"9syscall/rfork.s",
-		"9syscall/seek.s",
+		"9syscall/_seek.s",
 		"9syscall/segattach.s",
 		"9syscall/segbrk.s",
 		"9syscall/segdetach.s",
@@ -258,7 +258,7 @@
 		"port/u16.c",
 		"port/u32.c",
 		"port/u64.c",
-		"amd64/_seek.c",
+		"amd64/seek.c",
 		"amd64/notejmp.c",
 		"amd64/cycles.c",
 		"amd64/argv0.c",

+ 917 - 0
sys/src/sysconf.json

@@ -0,0 +1,917 @@
+{
+	"Syscalls": [
+		{
+			"#Id": 0,
+			"Id": 4096,
+			"Name": "sysr1",
+			"Ret": [
+				"int32_t"
+			],
+			"Sysname": "sysr1"
+		},
+		{
+			"#Id": 1,
+			"Args": [
+				"char*"
+			],
+			"Id": 4097,
+			"Name": "_errstr",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 2,
+			"Args": [
+				"char*",
+				"char*",
+				"int32_t"
+			],
+			"Id": 4098,
+			"Name": "bind",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 3,
+			"Args": [
+				"char*"
+			],
+			"Id": 4099,
+			"Name": "chdir",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 4,
+			"Args": [
+				"int32_t"
+			],
+			"Id": 3,
+			"Name": "close",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 5,
+			"Args": [
+				"int32_t",
+				"int32_t"
+			],
+			"Id": 21,
+			"Name": "dup",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 6,
+			"Args": [
+				"uint32_t"
+			],
+			"Id": 4102,
+			"Name": "alarm",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 7,
+			"Args": [
+				"char*",
+				"char*[]"
+			],
+			"Id": 4103,
+			"Name": "exec",
+			"Ret": [
+				"void*"
+			]
+		},
+		{
+			"#Id": 8,
+			"Args": [
+				"char*"
+			],
+			"Id": 4104,
+			"Libname": "_exits",
+			"Name": "exits",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 9,
+			"Id": 4105,
+			"Name": "_fsession",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 10,
+			"Id": 4106,
+			"Name": "fauth",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 11,
+			"Args": [
+				"int32_t",
+				"uint8_t*"
+			],
+			"Id": 4107,
+			"Name": "_fstat",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 12,
+			"Id": 4108,
+			"Name": "segbrk",
+			"Ret": [
+				"void*"
+			]
+		},
+		{
+			"#Id": 13,
+			"Args": [
+				"int32_t",
+				"char*",
+				"int32_t",
+				"char*"
+			],
+			"Id": 4109,
+			"Name": "_mount",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 14,
+			"Args": [
+				"char*",
+				"int32_t"
+			],
+			"Id": 2,
+			"Name": "open",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 15,
+			"Args": [
+				"int32_t",
+				"void*",
+				"int32_t"
+			],
+			"Id": 0,
+			"Name": "read",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 16,
+			"Args": [
+				"int32_t",
+				"int32_t",
+				"int32_t"
+			],
+			"Id": 4112,
+			"Name": "oseek",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 17,
+			"Args": [
+				"int32_t"
+			],
+			"Id": 4113,
+			"Name": "sleep",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 18,
+			"Args": [
+				"char*",
+				"uint8_t*"
+			],
+			"Id": 4114,
+			"Name": "_stat",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 19,
+			"Args": [
+				"int32_t"
+			],
+			"Id": 4115,
+			"Name": "rfork",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 20,
+			"Args": [
+				"int32_t",
+				"void*",
+				"int32_t"
+			],
+			"Id": 1,
+			"Name": "write",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 21,
+			"Args": [
+				"int32_t*"
+			],
+			"Id": 4117,
+			"Name": "pipe",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 22,
+			"Args": [
+				"char*",
+				"int32_t",
+				"int32_t"
+			],
+			"Id": 4118,
+			"Name": "create",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 23,
+			"Args": [
+				"int32_t",
+				"char*",
+				"uint32_t"
+			],
+			"Id": 4119,
+			"Name": "fd2path",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 24,
+			"Id": 4120,
+			"Name": "brk_",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 25,
+			"Args": [
+				"char*"
+			],
+			"Id": 4121,
+			"Name": "remove",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 26,
+			"Id": 4122,
+			"Name": "_wstat",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 27,
+			"Id": 4123,
+			"Name": "_fwstat",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 28,
+			"Args": [
+				"void*"
+			],
+			"Id": 4124,
+			"Name": "notify",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 29,
+			"Args": [
+				"int32_t"
+			],
+			"Id": 4125,
+			"Name": "noted",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 30,
+			"Id": 4126,
+			"Name": "segattach",
+			"Ret": [
+				"void*"
+			]
+		},
+		{
+			"#Id": 31,
+			"Id": 4127,
+			"Name": "segdetach",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 32,
+			"Id": 4128,
+			"Name": "segfree",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 33,
+			"Id": 4129,
+			"Name": "segflush",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 34,
+			"Args": [
+				"void*"
+			],
+			"Id": 4130,
+			"Name": "rendezvous",
+			"Ret": [
+				"void*"
+			]
+		},
+		{
+			"#Id": 35,
+			"Args": [
+				"char*",
+				"char*"
+			],
+			"Id": 4131,
+			"Name": "unmount",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 36,
+			"Args": [
+				"void*"
+			],
+			"Id": 4132,
+			"Name": "_wait",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 37,
+			"Args": [
+				"int32_t*",
+				"int32_t"
+			],
+			"Id": 4133,
+			"Name": "semacquire",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 38,
+			"Args": [
+				"int32_t*",
+				"int32_t"
+			],
+			"Id": 4134,
+			"Name": "semrelease",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 39,
+			"Args": [
+				"int64_t*",
+				"int32_t",
+				"int64_t",
+				"int32_t"
+			],
+			"Id": 4135,
+			"Libname": "_seek",
+			"Name": "seek",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 40,
+			"Id": 4136,
+			"Name": "fversion",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 41,
+			"Args": [
+				"char*",
+				"uint32_t"
+			],
+			"Id": 4137,
+			"Name": "errstr",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 42,
+			"Args": [
+				"char*",
+				"uint8_t*",
+				"uint32_t"
+			],
+			"Id": 4138,
+			"Name": "stat",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 43,
+			"Args": [
+				"int32_t",
+				"uint8_t*",
+				"uint32_t"
+			],
+			"Id": 4139,
+			"Name": "fstat",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 44,
+			"Args": [
+				"char*",
+				"uint8_t*",
+				"uint32_t"
+			],
+			"Id": 4140,
+			"Name": "wstat",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 45,
+			"Args": [
+				"int32_t",
+				"uint8_t*",
+				"uint32_t"
+			],
+			"Id": 4141,
+			"Name": "fwstat",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 46,
+			"Args": [
+				"int32_t",
+				"char*",
+				"int32_t",
+				"char*"
+			],
+			"Id": 4142,
+			"Name": "mount",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 47,
+			"Args": [
+				"char*",
+				"int32_t"
+			],
+			"Id": 4143,
+			"Name": "await",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 48,
+			"Args": [
+				"int32_t",
+				"void*",
+				"int32_t",
+				"int64_t"
+			],
+			"Id": 17,
+			"Name": "pread",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 49,
+			"Args": [
+				"int32_t",
+				"void*",
+				"int32_t",
+				"int64_t"
+			],
+			"Id": 18,
+			"Name": "pwrite",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 52,
+			"Args": [
+				"int32_t*",
+				"uint32_t"
+			],
+			"Id": 4148,
+			"Name": "tsemacquire",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 53,
+			"Id": 4149,
+			"Name": "nsec",
+			"Ret": [
+				"int64_t"
+			]
+		},
+		{
+			"#Id": 54,
+			"Id": 4150,
+			"Name": "semsleep",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 55,
+			"Id": 4151,
+			"Name": "semwakeup",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 56,
+			"Id": 4152,
+			"Name": "semalt",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 57,
+			"Args": [
+				"uint32_t",
+				"char*",
+				"char*[]"
+			],
+			"Id": 4153,
+			"Name": "execac",
+			"Ret": [
+				"void*"
+			]
+		},
+		{
+			"#Id": 58,
+			"Id": 4154,
+			"Name": "nixsyscall",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 59,
+			"Id": 4155,
+			"Name": "ziopread",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 60,
+			"Id": 4156,
+			"Name": "ziopwrite",
+			"Ret": [
+				"int32_t"
+			]
+		},
+		{
+			"#Id": 61,
+			"Id": 4157,
+			"Name": "ziofree",
+			"Ret": [
+				"int32_t"
+			]
+		}
+	],
+	"Syserrors": [
+		{
+			"Id": 0,
+			"Name": "Ebadarg",
+			"String": "bad arg in system call"
+		},
+		{
+			"Id": 1,
+			"Name": "Ebadchar",
+			"String": "bad character in file name"
+		},
+		{
+			"Id": 2,
+			"Name": "Ebadctl",
+			"String": "bad process or channel control request"
+		},
+		{
+			"Id": 3,
+			"Name": "Ebadexec",
+			"String": "exec header invalid"
+		},
+		{
+			"Id": 4,
+			"Name": "Ebadfd",
+			"String": "fd out of range or not open"
+		},
+		{
+			"Id": 5,
+			"Name": "Ebadip",
+			"String": "bad ip address syntax"
+		},
+		{
+			"Id": 6,
+			"Name": "Ebadsharp",
+			"String": "unknown device in # filename"
+		},
+		{
+			"Id": 7,
+			"Name": "Ebadspec",
+			"String": "bad attach specifier"
+		},
+		{
+			"Id": 8,
+			"Name": "Ebadstat",
+			"String": "malformed stat buffer"
+		},
+		{
+			"Id": 9,
+			"Name": "Ebadusefd",
+			"String": "inappropriate use of fd"
+		},
+		{
+			"Id": 10,
+			"Name": "Ecmdargs",
+			"String": "wrong #args in control message"
+		},
+		{
+			"Id": 11,
+			"Name": "Econinuse",
+			"String": "connection in use"
+		},
+		{
+			"Id": 12,
+			"Name": "Econrefused",
+			"String": "connection refused"
+		},
+		{
+			"Id": 13,
+			"Name": "Edirseek",
+			"String": "seek in directory"
+		},
+		{
+			"Id": 14,
+			"Name": "Eexist",
+			"String": "file already exists"
+		},
+		{
+			"Id": 15,
+			"Name": "Efilename",
+			"String": "file name syntax"
+		},
+		{
+			"Id": 16,
+			"Name": "Egreg",
+			"String": "ken has left the building"
+		},
+		{
+			"Id": 17,
+			"Name": "Ehungup",
+			"String": "i/o on hungup channel"
+		},
+		{
+			"Id": 18,
+			"Name": "Eintr",
+			"String": "interrupted"
+		},
+		{
+			"Id": 19,
+			"Name": "Einuse",
+			"String": "device or object already in use"
+		},
+		{
+			"Id": 20,
+			"Name": "Eio",
+			"String": "i/o error"
+		},
+		{
+			"Id": 21,
+			"Name": "Eioload",
+			"String": "i/o error in demand load"
+		},
+		{
+			"Id": 22,
+			"Name": "Eisdir",
+			"String": "file is a directory"
+		},
+		{
+			"Id": 23,
+			"Name": "Eismtpt",
+			"String": "is a mount point"
+		},
+		{
+			"Id": 24,
+			"Name": "Eisstream",
+			"String": "seek on a stream"
+		},
+		{
+			"Id": 25,
+			"Name": "Emount",
+			"String": "inconsistent mount"
+		},
+		{
+			"Id": 26,
+			"Name": "Emountrpc",
+			"String": "mount rpc error"
+		},
+		{
+			"Id": 27,
+			"Name": "Enegoff",
+			"String": "negative i/o offset"
+		},
+		{
+			"Id": 28,
+			"Name": "Enoattach",
+			"String": "mount/attach disallowed"
+		},
+		{
+			"Id": 29,
+			"Name": "Enochild",
+			"String": "no living children"
+		},
+		{
+			"Id": 30,
+			"Name": "Enocreate",
+			"String": "mounted directory forbids creation"
+		},
+		{
+			"Id": 31,
+			"Name": "Enodev",
+			"String": "no free devices"
+		},
+		{
+			"Id": 32,
+			"Name": "Enoerror",
+			"String": "no error"
+		},
+		{
+			"Id": 33,
+			"Name": "Enofd",
+			"String": "no free file descriptors"
+		},
+		{
+			"Id": 34,
+			"Name": "Enomem",
+			"String": "kernel allocate failed"
+		},
+		{
+			"Id": 35,
+			"Name": "Enonexist",
+			"String": "file does not exist"
+		},
+		{
+			"Id": 36,
+			"Name": "Enoport",
+			"String": "network port not available"
+		},
+		{
+			"Id": 37,
+			"Name": "Enoreg",
+			"String": "process has no saved registers"
+		},
+		{
+			"Id": 38,
+			"Name": "Enoswap",
+			"String": "swap space full"
+		},
+		{
+			"Id": 39,
+			"Name": "Enotdir",
+			"String": "not a directory"
+		},
+		{
+			"Id": 40,
+			"Name": "Enovmem",
+			"String": "virtual memory allocation failed"
+		},
+		{
+			"Id": 41,
+			"Name": "Eperm",
+			"String": "permission denied"
+		},
+		{
+			"Id": 42,
+			"Name": "Eprocdied",
+			"String": "process exited"
+		},
+		{
+			"Id": 43,
+			"Name": "Eshort",
+			"String": "i/o count too small"
+		},
+		{
+			"Id": 44,
+			"Name": "Eshortstat",
+			"String": "stat buffer too small"
+		},
+		{
+			"Id": 45,
+			"Name": "Eshutdown",
+			"String": "device shut down"
+		},
+		{
+			"Id": 46,
+			"Name": "Esoverlap",
+			"String": "segments overlap"
+		},
+		{
+			"Id": 47,
+			"Name": "Etimedout",
+			"String": "connection timed out"
+		},
+		{
+			"Id": 48,
+			"Name": "Etoobig",
+			"String": "read or write too large"
+		},
+		{
+			"Id": 49,
+			"Name": "Etoosmall",
+			"String": "read or write too small"
+		},
+		{
+			"Id": 50,
+			"Name": "Eunion",
+			"String": "not in union"
+		},
+		{
+			"Id": 51,
+			"Name": "Eunmount",
+			"String": "not mounted"
+		}
+	]
+}

+ 189 - 24
util/mksys.go

@@ -10,42 +10,207 @@
 package main
 
 import (
+	"encoding/json"
+	"flag"
 	"fmt"
 	"io/ioutil"
 	"log"
+	"os"
+	"path"
 	"strings"
+	"text/template"
 )
 
+type Syscall struct {
+	Ret     []string
+	Args    []string
+	Name    string
+	Id      uint32
+	Define  string
+	Sysname string
+	Libname string
+	Fudge   string `json:"-"`
+	Ret0    string `json:"-"`
+}
+
+type Syserror struct {
+	Name   string
+	String string
+	Id     uint32
+}
+
+type Sysconf struct {
+	Syscalls  []Syscall
+	Syserrors []Syserror
+}
+
+var mode = flag.String("mode", "", "must be one of: sys.h, sysdecl.h, syscallfiles, systab.c, error.h, errstr.h")
+var outpath = flag.String("o", "", "path/to/output.c")
+
+func usage(msg string) {
+	fmt.Fprint(os.Stderr, msg)
+	fmt.Fprint(os.Stderr, "Usage: mksys [-o outpath] -mode=MODE path/to/sysconf.json\n")
+	flag.PrintDefaults()
+	os.Exit(1)
+}
+
 func main() {
-	s, err := ioutil.ReadFile("sys.h")
+
+	flag.Parse()
+
+	if flag.NArg() != 1 {
+		usage("no path to sysconf.json")
+	}
+
+	outfile := os.Stdout
+	if *mode != "syscallfiles" && *outpath != "" {
+		of, err := os.Create(*outpath)
+		if err != nil {
+			log.Fatal(err)
+		}
+		outfile = of
+	}
+
+	buf, err := ioutil.ReadFile(flag.Arg(0))
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	var sysconf Sysconf
+	err = json.Unmarshal(buf, &sysconf)
 	if err != nil {
 		log.Fatal(err)
 	}
-	lines := strings.Split(string(s), "\n")
-	for _, line := range lines {
-		ass := ".globl "
-		ll := strings.Fields(line)
-		if len(ll) < 3 {
-			continue
-		}
-		name := strings.ToLower(ll[1])
-		if name == "exits" {
-			name = "_" + name
-		}
-		filename := name + ".s"
-		if name == "seek" {
-			name = "_" + name
-		}
-		ass = ass + fmt.Sprintf("%v\n%v: ", name, name)
-		// linux system call args. di si dx r10 r8 r0
-		// rcx is not used because it is needed for sysenter
-		ass = ass + "\tMOVQ %rcx, %r10 /* rcx gets smashed by systenter. Use r10.*/\n"
-		ass = ass + "\tMOVQ $" + ll[2]
-		ass = ass + ",%rax  /* Put the system call into rax, just like linux. */\n"
-		ass = ass + "\tSYSCALL\n\tRET\n"
-		err = ioutil.WriteFile(filename, []byte(ass), 0666)
+
+	syscalls := sysconf.Syscalls
+	syserrors := sysconf.Syserrors
+
+	for i := range syscalls {
+		if syscalls[i].Define == "" {
+			syscalls[i].Define = strings.ToUpper(syscalls[i].Name)
+		}
+		if syscalls[i].Sysname == "" {
+			syscalls[i].Sysname = "sys" + syscalls[i].Name
+		}
+		if syscalls[i].Libname == "" {
+			syscalls[i].Libname = syscalls[i].Name
+		}
+
+		var fudge string
+		switch syscalls[i].Ret[0] {
+		case "int32_t":
+			fudge = "{ .i = -1 }"
+		case "int64_t":
+			fudge = "{ .vl = -1ll }"
+		case "void*":
+			fudge = "{ .v = (void*)-1ll }"
+		default:
+			log.Fatalf("unsupported Ret[0] in syscall: %v", syscalls[i])
+		}
+		if syscalls[i].Fudge == "" {
+			syscalls[i].Fudge = fudge
+		}
+
+		syscalls[i].Ret0 = syscalls[i].Ret[0]
+	}
+
+	switch *mode {
+	case "syscallfiles":
+		if os.Getenv("ARCH") != "amd64" {
+			usage("ARCH unsupported or not set")
+		}
+		tmpl, err := template.New("syscall.s").Parse(`/* automatically generated by mksys */
+.globl	{{ .Libname }}
+{{ .Libname }}:
+	movq %rcx, %r10 /* rcx gets smashed by systenter. Use r10.*/
+	movq ${{ .Id }},%rax  /* Put the system call into rax, just like linux. */
+	syscall
+	ret
+`)
+		if err != nil {
+			log.Fatal(err)
+		}
+
+		for i := range syscalls {
+
+			path := path.Join(*outpath, syscalls[i].Libname+".s")
+			file, err := os.Create(path)
+			if err != nil {
+				log.Fatal(err)
+			}
+
+			err = tmpl.Execute(file, syscalls[i])
+			if err != nil {
+				log.Fatal(err)
+			}
+
+			err = file.Close()
+			if err != nil {
+				log.Fatal(err)
+			}
+		}
+
+	case "sys.h":
+		tmpl, err := template.New("sys.h").Parse(`/* automatically generated by mksys */
+{{ range . }}#define {{ .Define }} {{ .Id }}
+{{ end }}
+`)
+		err = tmpl.Execute(outfile, syscalls)
+		if err != nil {
+			log.Fatal(err)
+		}
+
+	case "sysdecl.h":
+		tmpl, err := template.New("sysdecl.h").Parse(`/* automatically generated by mksys */
+{{ range . }}extern {{ .Ret0 }} {{ .Libname }}({{ range $i, $e := .Args }}{{ if $i }}, {{ end }}{{ $e }}{{ end }});
+{{ end }}
+`)
+		err = tmpl.Execute(outfile, syscalls)
+		if err != nil {
+			log.Fatal(err)
+		}
+
+	case "systab.c":
+		tmpl, err := template.New("systab.c").Parse(`/* automatically generated by mksys */
+#include "u.h"
+#include "../port/lib.h"
+#include "mem.h"
+#include "dat.h"
+#include "fns.h"
+#include "../../libc/9syscall/sys.h"
+
+{{ range . }}extern void {{ .Sysname }}(Ar0*, ...);
+{{ end }}
+Systab systab[] = {
+{{ range . }}[{{ .Define }}] { "{{ .Name }}", {{ .Sysname }}, {{ .Fudge }} },
+{{ end }}
+};
+int nsyscall = nelem(systab);
+`)
+		err = tmpl.Execute(outfile, syscalls)
 		if err != nil {
 			log.Fatal(err)
 		}
+
+	case "error.h":
+		tmpl, err := template.New("error.h").Parse(`/* automatically generated by mksys */
+{{ range . }}extern char {{ .Name }}[]; /* {{ .String }} */
+{{ end }}
+`)
+		err = tmpl.Execute(outfile, syserrors)
+		if err != nil {
+			log.Fatal(err)
+		}
+
+	case "errstr.h":
+		tmpl, err := template.New("errstr.h").Parse(`/* automatically generated by mksys */
+{{ range . }}char {{ .Name }}[] = "{{ .String }}";
+{{ end }}
+`)
+		err = tmpl.Execute(outfile, syserrors)
+		if err != nil {
+			log.Fatal(err)
+		}
+
 	}
 }