ref: 0538b85a46b6bfc88cd1fd22a96e46072befa57b
parent: 7d9f5607e87defb4366ff3c8ad9d24128884d869
author: glenda <glenda@cirno>
date: Sat May 4 11:01:48 EDT 2024
add more nix files
--- a/sys/src/nix/pc64/acore.c
+++ b/sys/src/nix/pc64/acore.c
@@ -8,6 +8,7 @@
#include "../port/pci.h"
#include "ureg.h"
#include "pool.h"
+#include "mp.h"
/*
* NIX code run at the AC.
@@ -150,6 +151,12 @@
/* done by actrap() */
}
+/* leave this here, we probably want something for it some day */
+void
+_pmcupdate(Mach *)
+{
+}
+
/*
* Entered in AP core context, upon traps (system calls go through acsyscall)
* using up->dbgreg means cores MUST be homogeneous.
@@ -168,7 +175,7 @@
n = nil;
- //_pmcupdate(m);
+ _pmcupdate(m);
if(m->proc != nil){
m->proc->nactrap++;
m->proc->actime1 = fastticks(nil);
@@ -187,14 +194,14 @@
case Vector2F:
print("AC: double fault\n");
dumpregs(u);
- ndnr();
+ halt();
case 62: //IdtIPI:
m->intr++;
DBG("actrap: cpu%d: IPI\n", m->machno);
- apiceoi(62);
+ lapiceoi(62);
break;
case 50: //IdtTIMER:
- apiceoi(50);
+ lapiceoi(50);
panic("timer interrupt in an AC");
break;
case VectorPF:
@@ -276,7 +283,7 @@
dumpreg(void *u)
{
print("reg is %p\n", u);
- ndnr();
+ halt();
}
char *rolename[] =
@@ -284,7 +291,7 @@
[NIXAC] "AC",
[NIXTC] "TC",
[NIXKC] "KC",
- [NIXXC] "XC",
+// [NIXXC] "XC",
};
void
@@ -294,7 +301,7 @@
case NIXAC:
case NIXKC:
case NIXTC:
- case NIXXC:
+// case NIXXC:
break;
default:
panic("acmodeset: bad mode %d", mode);
@@ -313,7 +320,7 @@
* to accept interrupts.
* Raise it later if needed to disable them.
*/
- apicpri(0);
+ lapicintron();
/*
* Be sure a few assembler assumptions still hold.
@@ -323,5 +330,5 @@
pp = 0;
assert((uintptr)&mp->proc == 16);
assert((uintptr)&pp->dbgreg == 24);
- assert((uintptr)&mp->stack == 24);
+ //assert((uintptr)&mp->stack == 24);
}
--- /dev/null
+++ b/sys/src/nix/pc64/amd64l.h
@@ -1,0 +1,162 @@
+#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 */
+
+#define Pwt 0x00000008 /* Page-Level Writethrough */
+#define Pcd 0x00000010 /* Page-Level Cache Disable */
+
+#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 */
+
+#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 */
+
+#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 */
+
+#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 */
+
+#define PteP 0x0000000000000001ull /* Present */
+#define PteRW 0x0000000000000002ull /* Read/Write */
+#define PteU 0x0000000000000004ull /* User/Supervisor */
+#define PtePWT 0x0000000000000008ull /* Page-Level Write Through */
+#define PtePCD 0x0000000000000010ull /* Page Level Cache Disable */
+#define PteA 0x0000000000000020ull /* Accessed */
+#define PteD 0x0000000000000040ull /* Dirty */
+#define PtePS 0x0000000000000080ull /* Page Size */
+#define Pte4KPAT PtePS /* PTE PAT */
+#define PteG 0x0000000000000100ull /* Global */
+#define Pte2MPAT 0x0000000000001000ull /* PDE PAT */
+#define Pte1GPAT Pte2MPAT /* PDPE PAT */
+#define PteNX 0x8000000000000000ull /* No Execute */
+
+#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 */
+
+#define SdISTM 0x0000000700000000ull /* Interrupt Stack Table Mask */
+#define SdA 0x0000010000000000ull /* Accessed */
+#define SdR 0x0000020000000000ull /* Readable (Code) */
+#define SdW 0x0000020000000000ull /* Writeable (Data) */
+#define SdE 0x0000040000000000ull /* Expand Down */
+#define SdaTSS 0x0000090000000000ull /* Available TSS */
+#define SdbTSS 0x00000b0000000000ull /* Busy TSS */
+#define SdCG 0x00000c0000000000ull /* Call Gate */
+#define SdIG 0x00000e0000000000ull /* Interrupt Gate */
+#define SdTG 0x00000f0000000000ull /* Trap Gate */
+#define SdCODE 0x0000080000000000ull /* Code/Data */
+#define SdS 0x0000100000000000ull /* System/User */
+#define SdDPL0 0x0000000000000000ull /* Descriptor Privilege Level */
+#define SdDPL1 0x0000200000000000ull
+#define SdDPL2 0x0000400000000000ull
+#define SdDPL3 0x0000600000000000ull
+#define SdP 0x0000800000000000ull /* Present */
+#define Sd4G 0x000f00000000ffffull /* 4G Limit */
+#define SdL 0x0020000000000000ull /* Long Attribute */
+#define SdD 0x0040000000000000ull /* Default Operand Size */
+#define SdG 0x0080000000000000ull /* Granularity */
+
+#define PeHo 0x0000020000000000ull /* Host only */
+#define PeGo 0x0000010000000000ull /* Guest only */
+#define PeEvMskH 0x0000000f00000000ull /* Event mask H */
+#define PeCtMsk 0x00000000ff000000ull /* Counter mask */
+#define PeInMsk 0x0000000000800000ull /* Invert mask */
+#define PeCtEna 0x0000000000400000ull /* Counter enable */
+#define PeInEna 0x0000000000100000ull /* Interrupt enable */
+#define PePnCtl 0x0000000000080000ull /* Pin control */
+#define PeEdg 0x0000000000040000ull /* Edge detect */
+#define PeOS 0x0000000000020000ull /* OS mode */
+#define PeUsr 0x0000000000010000ull /* User mode */
+#define PeUnMsk 0x000000000000ff00ull /* Unit Mask */
+#define PeEvMskL 0x00000000000000ffull /* Event Mask L */
+
+#define PeEvMsksh 32ull /* Event mask shift */
+
+#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 */
+
+#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 */
+
+#define RMACH R15 /* m-> */
+#define RUSER R14 /* up-> */
--- a/sys/src/nix/pc64/dat.h
+++ b/sys/src/nix/pc64/dat.h
@@ -224,6 +224,7 @@
u64int mmumap[4]; /* bitmap of pml4 entries for zapping */
NIX;
+ u64int cr2;
uintptr stack[1];
};
--- /dev/null
+++ b/sys/src/nix/pc64/l64acidt.s
@@ -1,0 +1,341 @@
+/*
+ * Interrupt/exception handling.
+ */
+#include "amd64l.h"
+
+MODE $64
+
+TEXT _acintrp<>(SB), 1, $-4 /* no error code pushed */
+ PUSHQ AX /* save AX */
+ MOVQ 8(SP), AX /* idthandlers(SB) PC */
+ JMP _acintrcommon
+
+TEXT _acintre<>(SB), 1, $-4 /* error code pushed */
+ XCHGQ AX, (SP)
+_acintrcommon:
+ MOVBQZX (AX), AX
+ XCHGQ AX, (SP)
+
+ SUBQ $24, SP /* R1[45], [DEFG]S */
+ CMPW 48(SP), $SSEL(SiCS, SsTIGDT|SsRPL0) /* old CS */
+ JEQ _acintrnested
+
+ MOVQ RUSER, 0(SP)
+ MOVQ RMACH, 8(SP)
+ MOVW DS, 16(SP)
+ MOVW ES, 18(SP)
+ MOVW FS, 20(SP)
+ MOVW GS, 22(SP)
+
+ SWAPGS
+ BYTE $0x65; MOVQ 0, RMACH /* m-> (MOVQ GS:0x0, R15) */
+ MOVQ 16(RMACH), RUSER /* up */
+
+_acintrnested:
+ PUSHQ R13
+ PUSHQ R12
+ PUSHQ R11
+ PUSHQ R10
+ PUSHQ R9
+ PUSHQ R8
+ PUSHQ BP
+ PUSHQ DI
+ PUSHQ SI
+ PUSHQ DX
+ PUSHQ CX
+ PUSHQ BX
+ PUSHQ AX
+
+ MOVQ SP, RARG
+ PUSHQ SP
+ CALL actrap(SB)
+
+TEXT _acintrr<>(SB), 1, $-4 /* so ktrace can pop frame */
+ POPQ AX
+
+ POPQ AX
+ POPQ BX
+ POPQ CX
+ POPQ DX
+ POPQ SI
+ POPQ DI
+ POPQ BP
+ POPQ R8
+ POPQ R9
+ POPQ R10
+ POPQ R11
+ POPQ R12
+ POPQ R13
+
+ CMPQ 48(SP), $SSEL(SiCS, SsTIGDT|SsRPL0)
+ JEQ _aciretnested
+
+ SWAPGS
+ MOVW 22(SP), GS
+ MOVW 20(SP), FS
+ MOVW 18(SP), ES
+ MOVW 16(SP), DS
+ MOVQ 8(SP), RMACH
+ MOVQ 0(SP), RUSER
+
+_aciretnested:
+ ADDQ $40, SP
+ IRETQ
+
+TEXT acidthandlers(SB), 1, $-4
+ CALL _acintrp<>(SB); BYTE $IdtDE /* #DE Divide-by-Zero Error */
+ CALL _acintrp<>(SB); BYTE $IdtDB /* #DB Debug */
+ CALL _acintrp<>(SB); BYTE $IdtNMI /* #NMI Borked */
+ CALL _acintrp<>(SB); BYTE $IdtBP /* #BP Breakpoint */
+ CALL _acintrp<>(SB); BYTE $IdtOF /* #OF Overflow */
+ CALL _acintrp<>(SB); BYTE $IdtBR /* #BR Bound-Range */
+ CALL _acintrp<>(SB); BYTE $IdtUD /* #UD Invalid-Opcode */
+ CALL _acintrp<>(SB); BYTE $IdtNM /* #NM Device-Not-Available */
+ CALL _acintre<>(SB); BYTE $IdtDF /* #DF Double-Fault */
+ CALL _acintrp<>(SB); BYTE $Idt09 /* reserved */
+ CALL _acintre<>(SB); BYTE $IdtTS /* #TS Invalid-TSS */
+ CALL _acintre<>(SB); BYTE $IdtNP /* #NP Segment-Not-Present */
+ CALL _acintre<>(SB); BYTE $IdtSS /* #SS Stack */
+ CALL _acintre<>(SB); BYTE $IdtGP /* #GP General-Protection */
+ CALL _acintre<>(SB); BYTE $IdtPF /* #PF Page-Fault */
+ CALL _acintrp<>(SB); BYTE $Idt0F /* reserved */
+ CALL _acintrp<>(SB); BYTE $IdtMF /* #MF x87 FPE-Pending */
+ CALL _acintre<>(SB); BYTE $IdtAC /* #AC Alignment-Check */
+ CALL _acintrp<>(SB); BYTE $IdtMC /* #MC Machine-Check */
+ CALL _acintrp<>(SB); BYTE $IdtXF /* #XF SIMD Floating-Point */
+ CALL _acintrp<>(SB); BYTE $0x14 /* reserved */
+ CALL _acintrp<>(SB); BYTE $0x15 /* reserved */
+ CALL _acintrp<>(SB); BYTE $0x16 /* reserved */
+ CALL _acintrp<>(SB); BYTE $0x17 /* reserved */
+ CALL _acintrp<>(SB); BYTE $0x18 /* reserved */
+ CALL _acintrp<>(SB); BYTE $0x19 /* reserved */
+ CALL _acintrp<>(SB); BYTE $0x1a /* reserved */
+ CALL _acintrp<>(SB); BYTE $0x1b /* reserved */
+ CALL _acintrp<>(SB); BYTE $0x1c /* reserved */
+ CALL _acintrp<>(SB); BYTE $0x1d /* reserved */
+ CALL _acintrp<>(SB); BYTE $0x1e /* reserved */
+ CALL _acintrp<>(SB); BYTE $0x1f /* reserved */
+ CALL _acintrp<>(SB); BYTE $0x20
+ CALL _acintrp<>(SB); BYTE $0x21
+ CALL _acintrp<>(SB); BYTE $0x22
+ CALL _acintrp<>(SB); BYTE $0x23
+ CALL _acintrp<>(SB); BYTE $0x24
+ CALL _acintrp<>(SB); BYTE $0x25
+ CALL _acintrp<>(SB); BYTE $0x26
+ CALL _acintrp<>(SB); BYTE $0x27
+ CALL _acintrp<>(SB); BYTE $0x28
+ CALL _acintrp<>(SB); BYTE $0x29
+ CALL _acintrp<>(SB); BYTE $0x2a
+ CALL _acintrp<>(SB); BYTE $0x2b
+ CALL _acintrp<>(SB); BYTE $0x2c
+ CALL _acintrp<>(SB); BYTE $0x2d
+ CALL _acintrp<>(SB); BYTE $0x2e
+ CALL _acintrp<>(SB); BYTE $0x2f
+ CALL _acintrp<>(SB); BYTE $0x30
+ CALL _acintrp<>(SB); BYTE $0x31
+ CALL _acintrp<>(SB); BYTE $0x32
+ CALL _acintrp<>(SB); BYTE $0x33
+ CALL _acintrp<>(SB); BYTE $0x34
+ CALL _acintrp<>(SB); BYTE $0x35
+ CALL _acintrp<>(SB); BYTE $0x36
+ CALL _acintrp<>(SB); BYTE $0x37
+ CALL _acintrp<>(SB); BYTE $0x38
+ CALL _acintrp<>(SB); BYTE $0x39
+ CALL _acintrp<>(SB); BYTE $0x3a
+ CALL _acintrp<>(SB); BYTE $0x3b
+ CALL _acintrp<>(SB); BYTE $0x3c
+ CALL _acintrp<>(SB); BYTE $0x3d
+ CALL _acintrp<>(SB); BYTE $0x3e
+ CALL _acintrp<>(SB); BYTE $0x3f
+ CALL _acintrp<>(SB); BYTE $0x40
+ CALL _acintrp<>(SB); BYTE $0x41
+ CALL _acintrp<>(SB); BYTE $0x42
+ CALL _acintrp<>(SB); BYTE $0x43
+ CALL _acintrp<>(SB); BYTE $0x44
+ CALL _acintrp<>(SB); BYTE $0x45
+ CALL _acintrp<>(SB); BYTE $0x46
+ CALL _acintrp<>(SB); BYTE $0x47
+ CALL _acintrp<>(SB); BYTE $0x48
+ CALL _acintrp<>(SB); BYTE $0x49
+ CALL _acintrp<>(SB); BYTE $0x4a
+ CALL _acintrp<>(SB); BYTE $0x4b
+ CALL _acintrp<>(SB); BYTE $0x4c
+ CALL _acintrp<>(SB); BYTE $0x4d
+ CALL _acintrp<>(SB); BYTE $0x4e
+ CALL _acintrp<>(SB); BYTE $0x4f
+ CALL _acintrp<>(SB); BYTE $0x50
+ CALL _acintrp<>(SB); BYTE $0x51
+ CALL _acintrp<>(SB); BYTE $0x52
+ CALL _acintrp<>(SB); BYTE $0x53
+ CALL _acintrp<>(SB); BYTE $0x54
+ CALL _acintrp<>(SB); BYTE $0x55
+ CALL _acintrp<>(SB); BYTE $0x56
+ CALL _acintrp<>(SB); BYTE $0x57
+ CALL _acintrp<>(SB); BYTE $0x58
+ CALL _acintrp<>(SB); BYTE $0x59
+ CALL _acintrp<>(SB); BYTE $0x5a
+ CALL _acintrp<>(SB); BYTE $0x5b
+ CALL _acintrp<>(SB); BYTE $0x5c
+ CALL _acintrp<>(SB); BYTE $0x5d
+ CALL _acintrp<>(SB); BYTE $0x5e
+ CALL _acintrp<>(SB); BYTE $0x5f
+ CALL _acintrp<>(SB); BYTE $0x60
+ CALL _acintrp<>(SB); BYTE $0x61
+ CALL _acintrp<>(SB); BYTE $0x62
+ CALL _acintrp<>(SB); BYTE $0x63
+ CALL _acintrp<>(SB); BYTE $0x64
+ CALL _acintrp<>(SB); BYTE $0x65
+ CALL _acintrp<>(SB); BYTE $0x66
+ CALL _acintrp<>(SB); BYTE $0x67
+ CALL _acintrp<>(SB); BYTE $0x68
+ CALL _acintrp<>(SB); BYTE $0x69
+ CALL _acintrp<>(SB); BYTE $0x6a
+ CALL _acintrp<>(SB); BYTE $0x6b
+ CALL _acintrp<>(SB); BYTE $0x6c
+ CALL _acintrp<>(SB); BYTE $0x6d
+ CALL _acintrp<>(SB); BYTE $0x6e
+ CALL _acintrp<>(SB); BYTE $0x6f
+ CALL _acintrp<>(SB); BYTE $0x70
+ CALL _acintrp<>(SB); BYTE $0x71
+ CALL _acintrp<>(SB); BYTE $0x72
+ CALL _acintrp<>(SB); BYTE $0x73
+ CALL _acintrp<>(SB); BYTE $0x74
+ CALL _acintrp<>(SB); BYTE $0x75
+ CALL _acintrp<>(SB); BYTE $0x76
+ CALL _acintrp<>(SB); BYTE $0x77
+ CALL _acintrp<>(SB); BYTE $0x78
+ CALL _acintrp<>(SB); BYTE $0x79
+ CALL _acintrp<>(SB); BYTE $0x7a
+ CALL _acintrp<>(SB); BYTE $0x7b
+ CALL _acintrp<>(SB); BYTE $0x7c
+ CALL _acintrp<>(SB); BYTE $0x7d
+ CALL _acintrp<>(SB); BYTE $0x7e
+ CALL _acintrp<>(SB); BYTE $0x7f
+ CALL _acintrp<>(SB); BYTE $0x80
+ CALL _acintrp<>(SB); BYTE $0x81
+ CALL _acintrp<>(SB); BYTE $0x82
+ CALL _acintrp<>(SB); BYTE $0x83
+ CALL _acintrp<>(SB); BYTE $0x84
+ CALL _acintrp<>(SB); BYTE $0x85
+ CALL _acintrp<>(SB); BYTE $0x86
+ CALL _acintrp<>(SB); BYTE $0x87
+ CALL _acintrp<>(SB); BYTE $0x88
+ CALL _acintrp<>(SB); BYTE $0x89
+ CALL _acintrp<>(SB); BYTE $0x8a
+ CALL _acintrp<>(SB); BYTE $0x8b
+ CALL _acintrp<>(SB); BYTE $0x8c
+ CALL _acintrp<>(SB); BYTE $0x8d
+ CALL _acintrp<>(SB); BYTE $0x8e
+ CALL _acintrp<>(SB); BYTE $0x8f
+ CALL _acintrp<>(SB); BYTE $0x90
+ CALL _acintrp<>(SB); BYTE $0x91
+ CALL _acintrp<>(SB); BYTE $0x92
+ CALL _acintrp<>(SB); BYTE $0x93
+ CALL _acintrp<>(SB); BYTE $0x94
+ CALL _acintrp<>(SB); BYTE $0x95
+ CALL _acintrp<>(SB); BYTE $0x96
+ CALL _acintrp<>(SB); BYTE $0x97
+ CALL _acintrp<>(SB); BYTE $0x98
+ CALL _acintrp<>(SB); BYTE $0x99
+ CALL _acintrp<>(SB); BYTE $0x9a
+ CALL _acintrp<>(SB); BYTE $0x9b
+ CALL _acintrp<>(SB); BYTE $0x9c
+ CALL _acintrp<>(SB); BYTE $0x9d
+ CALL _acintrp<>(SB); BYTE $0x9e
+ CALL _acintrp<>(SB); BYTE $0x9f
+ CALL _acintrp<>(SB); BYTE $0xa0
+ CALL _acintrp<>(SB); BYTE $0xa1
+ CALL _acintrp<>(SB); BYTE $0xa2
+ CALL _acintrp<>(SB); BYTE $0xa3
+ CALL _acintrp<>(SB); BYTE $0xa4
+ CALL _acintrp<>(SB); BYTE $0xa5
+ CALL _acintrp<>(SB); BYTE $0xa6
+ CALL _acintrp<>(SB); BYTE $0xa7
+ CALL _acintrp<>(SB); BYTE $0xa8
+ CALL _acintrp<>(SB); BYTE $0xa9
+ CALL _acintrp<>(SB); BYTE $0xaa
+ CALL _acintrp<>(SB); BYTE $0xab
+ CALL _acintrp<>(SB); BYTE $0xac
+ CALL _acintrp<>(SB); BYTE $0xad
+ CALL _acintrp<>(SB); BYTE $0xae
+ CALL _acintrp<>(SB); BYTE $0xaf
+ CALL _acintrp<>(SB); BYTE $0xb0
+ CALL _acintrp<>(SB); BYTE $0xb1
+ CALL _acintrp<>(SB); BYTE $0xb2
+ CALL _acintrp<>(SB); BYTE $0xb3
+ CALL _acintrp<>(SB); BYTE $0xb4
+ CALL _acintrp<>(SB); BYTE $0xb5
+ CALL _acintrp<>(SB); BYTE $0xb6
+ CALL _acintrp<>(SB); BYTE $0xb7
+ CALL _acintrp<>(SB); BYTE $0xb8
+ CALL _acintrp<>(SB); BYTE $0xb9
+ CALL _acintrp<>(SB); BYTE $0xba
+ CALL _acintrp<>(SB); BYTE $0xbb
+ CALL _acintrp<>(SB); BYTE $0xbc
+ CALL _acintrp<>(SB); BYTE $0xbd
+ CALL _acintrp<>(SB); BYTE $0xbe
+ CALL _acintrp<>(SB); BYTE $0xbf
+ CALL _acintrp<>(SB); BYTE $0xc0
+ CALL _acintrp<>(SB); BYTE $0xc1
+ CALL _acintrp<>(SB); BYTE $0xc2
+ CALL _acintrp<>(SB); BYTE $0xc3
+ CALL _acintrp<>(SB); BYTE $0xc4
+ CALL _acintrp<>(SB); BYTE $0xc5
+ CALL _acintrp<>(SB); BYTE $0xc6
+ CALL _acintrp<>(SB); BYTE $0xc7
+ CALL _acintrp<>(SB); BYTE $0xc8
+ CALL _acintrp<>(SB); BYTE $0xc9
+ CALL _acintrp<>(SB); BYTE $0xca
+ CALL _acintrp<>(SB); BYTE $0xcb
+ CALL _acintrp<>(SB); BYTE $0xcc
+ CALL _acintrp<>(SB); BYTE $0xce
+ CALL _acintrp<>(SB); BYTE $0xce
+ CALL _acintrp<>(SB); BYTE $0xcf
+ CALL _acintrp<>(SB); BYTE $0xd0
+ CALL _acintrp<>(SB); BYTE $0xd1
+ CALL _acintrp<>(SB); BYTE $0xd2
+ CALL _acintrp<>(SB); BYTE $0xd3
+ CALL _acintrp<>(SB); BYTE $0xd4
+ CALL _acintrp<>(SB); BYTE $0xd5
+ CALL _acintrp<>(SB); BYTE $0xd6
+ CALL _acintrp<>(SB); BYTE $0xd7
+ CALL _acintrp<>(SB); BYTE $0xd8
+ CALL _acintrp<>(SB); BYTE $0xd9
+ CALL _acintrp<>(SB); BYTE $0xda
+ CALL _acintrp<>(SB); BYTE $0xdb
+ CALL _acintrp<>(SB); BYTE $0xdc
+ CALL _acintrp<>(SB); BYTE $0xdd
+ CALL _acintrp<>(SB); BYTE $0xde
+ CALL _acintrp<>(SB); BYTE $0xdf
+ CALL _acintrp<>(SB); BYTE $0xe0
+ CALL _acintrp<>(SB); BYTE $0xe1
+ CALL _acintrp<>(SB); BYTE $0xe2
+ CALL _acintrp<>(SB); BYTE $0xe3
+ CALL _acintrp<>(SB); BYTE $0xe4
+ CALL _acintrp<>(SB); BYTE $0xe5
+ CALL _acintrp<>(SB); BYTE $0xe6
+ CALL _acintrp<>(SB); BYTE $0xe7
+ CALL _acintrp<>(SB); BYTE $0xe8
+ CALL _acintrp<>(SB); BYTE $0xe9
+ CALL _acintrp<>(SB); BYTE $0xea
+ CALL _acintrp<>(SB); BYTE $0xeb
+ CALL _acintrp<>(SB); BYTE $0xec
+ CALL _acintrp<>(SB); BYTE $0xed
+ CALL _acintrp<>(SB); BYTE $0xee
+ CALL _acintrp<>(SB); BYTE $0xef
+ CALL _acintrp<>(SB); BYTE $0xf0
+ CALL _acintrp<>(SB); BYTE $0xf1
+ CALL _acintrp<>(SB); BYTE $0xf2
+ CALL _acintrp<>(SB); BYTE $0xf3
+ CALL _acintrp<>(SB); BYTE $0xf4
+ CALL _acintrp<>(SB); BYTE $0xf5
+ CALL _acintrp<>(SB); BYTE $0xf6
+ CALL _acintrp<>(SB); BYTE $0xf7
+ CALL _acintrp<>(SB); BYTE $0xf8
+ CALL _acintrp<>(SB); BYTE $0xf9
+ CALL _acintrp<>(SB); BYTE $0xfa
+ CALL _acintrp<>(SB); BYTE $0xfb
+ CALL _acintrp<>(SB); BYTE $0xfc
+ CALL _acintrp<>(SB); BYTE $0xfd
+ CALL _acintrp<>(SB); BYTE $0xfe
+ CALL _acintrp<>(SB); BYTE $0xff
--- /dev/null
+++ b/sys/src/nix/pc64/l64acsyscall.s
@@ -1,0 +1,80 @@
+#include "mem.h"
+#include "amd64l.h"
+
+MODE $64
+
+/*
+ */
+TEXT acsyscallentry(SB), 1, $-4
+ SWAPGS
+ BYTE $0x65; MOVQ 0, RMACH /* m-> (MOVQ GS:0x0, R15) */
+ MOVQ 16(RMACH), RUSER /* m->proc */
+ MOVQ 24(RUSER), R12 /* m->proc->dbgregs */
+
+ /* save sp to r13; set up kstack so we can call acsyscall */
+ MOVQ SP, R13
+ MOVQ 24(RMACH), SP /* m->stack */
+ ADDQ $MACHSTKSZ, SP
+
+ MOVQ $SSEL(SiUDS, SsRPL3), BX /* old stack segment */
+ MOVQ BX, 176(R12) /* save ss */
+ MOVQ R13, 168(R12) /* old sp */
+ MOVQ R11, 160(R12) /* old flags */
+ MOVQ $SSEL(SiUCS, SsRPL3), BX /* old code segment */
+ MOVQ BX, 152(R12) /* save cs */
+ MOVQ CX, 144(R12) /* old ip */
+
+ MOVW $SSEL(SiUDS, SsRPL3), 120(R12)
+ MOVW ES, 122(R12)
+ MOVW FS, 124(R12)
+ MOVW GS, 126(R12)
+
+ MOVQ RARG, 0(R12) /* system call number: up->dbgregs->ax */
+ CALL acsyscall(SB)
+NDNR: JMP NDNR
+
+TEXT _acsysret(SB), 1, $-4
+ CLI
+ SWAPGS
+
+ MOVQ 24(RUSER), R12 /* m->proc->dbgregs */
+ MOVQ 0(R12), AX /* m->proc->dbgregs->ax */
+ MOVQ (6*8)(R12), BP /* m->proc->dbgregs->bp */
+ ADDQ $(15*8), R12 /* after ax--r15, 8 bytes each */
+
+ MOVW 0(R12), DS
+ MOVW 2(R12), ES
+ MOVW 4(R12), FS
+ MOVW 6(R12), GS
+
+ MOVQ 24(R12), CX /* ip */
+ MOVQ 40(R12), R11 /* flags */
+
+ MOVQ 48(R12), SP /* sp */
+
+ BYTE $0x48; SYSRET /* SYSRETQ */
+
+/*
+ * Return from an exec() system call that we never did,
+ * DX is ar0->p by the time we call it. See syscall()
+ */
+TEXT xactouser(SB), 1, $-4
+ CLI
+ BYTE $0x65; MOVQ 0, RMACH /* m-> (MOVQ GS:0x0, R15) */
+ MOVQ 16(RMACH), RUSER /* m->proc */
+ MOVQ 24(RUSER), R12 /* m->proc->dbgregs */
+ MOVQ 144(R12), CX /* old ip */
+ MOVQ 0(R12), BX /* save AX */
+ SWAPGS
+ MOVQ $SSEL(SiUDS, SsRPL3), AX
+ MOVW AX, DS
+ MOVW AX, ES
+ MOVW AX, FS
+ MOVW AX, GS
+
+ MOVQ BX, AX /* restore AX */
+ MOVQ $If, R11 /* flags */
+
+ MOVQ RARG, SP /* sp */
+
+ BYTE $0x48; SYSRET /* SYSRETQ */
--- /dev/null
+++ b/sys/src/nix/port/lib.h
@@ -1,0 +1,265 @@
+/*
+ * functions (possibly) linked in, complete, from libc.
+ */
+#define nelem(x) (sizeof(x)/sizeof((x)[0]))
+#define offsetof(s, m) (ulong)(&(((s*)0)->m))
+#define assert(x) if(x){}else _assert("x")
+
+/*
+ * mem routines
+ */
+extern void* memccpy(void*, void*, int, usize);
+extern void* memset(void*, int, usize);
+extern int memcmp(void*, void*, usize);
+extern void* memmove(void*, void*, usize);
+extern void* memchr(void*, int, usize);
+
+/*
+ * string routines
+ */
+extern char* strcat(char*, char*);
+extern char* strchr(char*, int);
+extern char* strrchr(char*, int);
+extern int strcmp(char*, char*);
+extern char* strcpy(char*, char*);
+extern char* strecpy(char*, char*, char*);
+extern char* strncat(char*, char*, long);
+extern char* strncpy(char*, char*, long);
+extern int strncmp(char*, char*, long);
+extern long strlen(char*);
+extern char* strstr(char*, char*);
+extern int atoi(char*);
+extern int fullrune(char*, int);
+extern int cistrcmp(char*, char*);
+extern int cistrncmp(char*, char*, int);
+
+enum
+{
+ UTFmax = 4, /* maximum bytes per rune */
+ Runesync = 0x80, /* cannot represent part of a UTF sequence */
+ Runeself = 0x80, /* rune and UTF sequences are the same (<) */
+ Runeerror = 0xFFFD, /* decoding error in UTF */
+ Runemax = 0x10FFFF, /* 21 bit rune */
+};
+
+/*
+ * rune routines
+ */
+extern int runetochar(char*, Rune*);
+extern int chartorune(Rune*, char*);
+extern char* utfecpy(char *s1, char *es1, char *s2);
+extern char* utfrune(char*, long);
+extern int utflen(char*);
+extern int utfnlen(char*, long);
+extern int runelen(long);
+
+/*
+ * random number
+ */
+extern int rand(void);
+extern int nrand(int);
+extern long lrand(void);
+extern long lnrand(long);
+
+extern int abs(int);
+
+/*
+ * print routines
+ */
+typedef struct Fmt Fmt;
+typedef int (*Fmts)(Fmt*);
+struct Fmt{
+ uchar runes; /* output buffer is runes or chars? */
+ void *start; /* of buffer */
+ void *to; /* current place in the buffer */
+ void *stop; /* end of the buffer; overwritten if flush fails */
+ int (*flush)(Fmt *); /* called when to == stop */
+ void *farg; /* to make flush a closure */
+ int nfmt; /* num chars formatted so far */
+ va_list args; /* args passed to dofmt */
+ int r; /* % format Rune */
+ int width;
+ int prec;
+ ulong flags;
+};
+extern int print(char*, ...);
+extern char* seprint(char*, char*, char*, ...);
+extern char* vseprint(char*, char*, char*, va_list);
+extern int snprint(char*, int, char*, ...);
+extern int vsnprint(char*, int, char*, va_list);
+extern int sprint(char*, char*, ...);
+
+#pragma varargck argpos fmtprint 2
+#pragma varargck argpos print 1
+#pragma varargck argpos seprint 3
+#pragma varargck argpos snprint 3
+#pragma varargck argpos sprint 2
+
+#pragma varargck type "llb" vlong
+#pragma varargck type "lld" vlong
+#pragma varargck type "llx" vlong
+#pragma varargck type "llb" uvlong
+#pragma varargck type "lld" uvlong
+#pragma varargck type "llx" uvlong
+#pragma varargck type "lb" long
+#pragma varargck type "ld" long
+#pragma varargck type "lx" long
+#pragma varargck type "lb" ulong
+#pragma varargck type "ld" ulong
+#pragma varargck type "lx" ulong
+#pragma varargck type "zd" intptr
+#pragma varargck type "zo" intptr
+#pragma varargck type "zx" intptr
+#pragma varargck type "zb" intptr
+#pragma varargck type "zd" uintptr
+#pragma varargck type "zo" uintptr
+#pragma varargck type "zx" uintptr
+#pragma varargck type "zb" uintptr
+#pragma varargck type "b" int
+#pragma varargck type "d" int
+#pragma varargck type "x" int
+#pragma varargck type "c" int
+#pragma varargck type "C" int
+#pragma varargck type "b" uint
+#pragma varargck type "d" uint
+#pragma varargck type "x" uint
+#pragma varargck type "c" uint
+#pragma varargck type "C" uint
+#pragma varargck type "s" char*
+#pragma varargck type "q" char*
+#pragma varargck type "S" Rune*
+#pragma varargck type "%" void
+#pragma varargck type "p" uintptr
+#pragma varargck type "p" void*
+#pragma varargck flag ','
+
+extern int fmtstrinit(Fmt*);
+extern int fmtinstall(int, int (*)(Fmt*));
+extern void quotefmtinstall(void);
+extern int fmtprint(Fmt*, char*, ...);
+extern int fmtstrcpy(Fmt*, char*);
+extern char* fmtstrflush(Fmt*);
+
+/*
+ * one-of-a-kind
+ */
+extern char* cleanname(char*);
+extern uintptr getcallerpc(void*);
+
+extern long strtol(char*, char**, int);
+extern ulong strtoul(char*, char**, int);
+extern vlong strtoll(char*, char**, int);
+extern uvlong strtoull(char*, char**, int);
+extern char etext[];
+extern char edata[];
+extern char end[];
+extern int getfields(char*, char**, int, int, char*);
+extern int tokenize(char*, char**, int);
+extern int dec64(uchar*, int, char*, int);
+extern int dec16(uchar*, int, char*, int);
+extern int encodefmt(Fmt*);
+extern void qsort(void*, usize, usize, int (*)(void*, void*));
+
+/*
+ * Syscall data structures
+ */
+#define MORDER 0x0003 /* mask for bits defining order of mounting */
+#define MREPL 0x0000 /* mount replaces object */
+#define MBEFORE 0x0001 /* mount goes before others in union directory */
+#define MAFTER 0x0002 /* mount goes after others in union directory */
+#define MCREATE 0x0004 /* permit creation in mounted directory */
+#define MCACHE 0x0010 /* cache some data */
+#define MMASK 0x0017 /* all bits on */
+
+#define OREAD 0 /* open for read */
+#define OWRITE 1 /* write */
+#define ORDWR 2 /* read and write */
+#define OEXEC 3 /* execute, == read but check execute permission */
+#define OTRUNC 16 /* or'ed in (except for exec), truncate file first */
+#define OCEXEC 32 /* or'ed in (per file descriptor), close on exec */
+#define ORCLOSE 64 /* or'ed in, remove on close */
+#define OEXCL 0x1000 /* or'ed in, exclusive create */
+
+#define NCONT 0 /* continue after note */
+#define NDFLT 1 /* terminate after note */
+#define NSAVE 2 /* clear note but hold state */
+#define NRSTR 3 /* restore saved state */
+
+typedef struct Qid Qid;
+typedef struct Dir Dir;
+typedef struct OWaitmsg OWaitmsg;
+typedef struct Waitmsg Waitmsg;
+
+#define ERRMAX 128 /* max length of error string */
+#define KNAMELEN 28 /* max length of name held in kernel */
+
+/* bits in Qid.type */
+#define QTDIR 0x80 /* type bit for directories */
+#define QTAPPEND 0x40 /* type bit for append only files */
+#define QTEXCL 0x20 /* type bit for exclusive use files */
+#define QTMOUNT 0x10 /* type bit for mounted channel */
+#define QTAUTH 0x08 /* type bit for authentication file */
+#define QTFILE 0x00 /* plain file */
+
+/* bits in Dir.mode */
+#define DMDIR 0x80000000 /* mode bit for directories */
+#define DMAPPEND 0x40000000 /* mode bit for append only files */
+#define DMEXCL 0x20000000 /* mode bit for exclusive use files */
+#define DMMOUNT 0x10000000 /* mode bit for mounted channel */
+#define DMREAD 0x4 /* mode bit for read permission */
+#define DMWRITE 0x2 /* mode bit for write permission */
+#define DMEXEC 0x1 /* mode bit for execute permission */
+
+struct Qid
+{
+ uvlong path;
+ ulong vers;
+ uchar type;
+};
+
+struct Dir {
+ /* system-modified data */
+ ushort type; /* server type */
+ uint dev; /* server subtype */
+ /* file data */
+ Qid qid; /* unique id from server */
+ ulong mode; /* permissions */
+ ulong atime; /* last read time */
+ ulong mtime; /* last write time */
+ vlong length; /* file length: see <u.h> */
+ char *name; /* last element of path */
+ char *uid; /* owner name */
+ char *gid; /* group name */
+ char *muid; /* last modifier name */
+};
+
+struct OWaitmsg
+{
+ char pid[12]; /* of loved one */
+ char time[3*12]; /* of loved one and descendants */
+ char msg[64]; /* compatibility BUG */
+};
+
+struct Waitmsg
+{
+ int pid; /* of loved one */
+ ulong time[3]; /* of loved one and descendants */
+ char msg[ERRMAX]; /* actually variable-size in user mode */
+};
+
+// NIX
+/*
+ * NIX core types
+ */
+enum
+{
+ NIXTC = 0,
+ NIXKC,
+ NIXAC,
+};
+
+
+/*
+ * NIX system calls and library functions.
+ */
+extern int execac(int, char*, char*[]);
\ No newline at end of file