OK, turing.

<- leave blank

Fri Jan 21 15:47:11 EST 2022

#include <u.h>
#include <libc.h>

typedef struct Tcphdr Tcphdr;
struct Tcphdr {
	int tid;
	int proto;
	int len;
	int sa;
};

Tcphdr*
tcphdr(uchar *buf, int blen)
{
	if( blen != 7 || buf == 0)
		return 0;

	Tcphdr th;
	memset(&th, 0, sizeof(Tcphdr));

	th.tid = buf[0] << 8 | buf[1] << 0;
	th.proto = buf[2] << 8 | buf[3] << 0;
	th.len = buf[4] << 8 | buf[5] << 0;
	th.sa = buf[6] << 0;

	return &th;
}

void
main(int argc, char *argv[])
{
	Tcphdr *th;
	uchar buf[512] = {0x00, 0x06, 0x00, 0x05, 0x00, 0x08, 0x16};

	th = tcphdr(buf, 7);

	print("tid: %d \n", th->tid);
	print("proto: %d \n", th->proto);
	print("len: %d \n", th->len);
	print("sa: %d \n", th->sa);

	exits(nil);
}


Thu Jan 20 14:14:58 EST 2022
/*
 * Interrupt/exception handling.
 * Each entry in the vector table calls either _strayintr or _strayintrx depending
 * on whether an error code has been automatically pushed onto the stack
 * (_strayintrx) or not, in which case a dummy entry must be pushed before
 retrieving
 * the trap type from the vector table entry and placing it on the stack as part
 * of the Ureg structure.
 * The size of each entry in the vector table (6 bytes) is known in trapinit0().
 * Volume 3A 6-14
 * Stack is (high -> low)
 * SS, RSP, RFLAGS, CS, RIP, Error Code (if any), vectortable(SB) return PC
 * (SP) = Vectortable(SB) return PC. The first byte of this return PC will be the
 * byte we used to identify the trap type.
 * Removed the nested check that 9front does as we are not using different code
 * segments or tasks.
 */

TEXT _strayintr(SB), 1, $-4 /* no error code pushed */
	PUSHQ AX /* some value to fill the ecode slot in the stack and also store
	AX value */
	MOVQ 8(SP), AX /* vectortable(SB) PC */
						/* Stack is SS, RSP, RFLAGS, CS,
						RIP, vectortable(SB) Return PC, AX
							AX = vectortable(SB)
							return PC */
	JMP _intrcommon

TEXT _strayintrx(SB), 1, $-4/* error code pushed */
	XCHGQ AX, (SP) /* exchange AX with pointer to trap type */
						/* Stack is SS, RSP, RFLAGS, CS,
						RIP, Error Code, AX
							AX = vectortable(SB)
							return PC */
_intrcommon:
	MOVBQZX (AX), AX /* extract trap type from the vectortable(SB) return PC
	-> AX */
	XCHGQ AX, (SP) /* exchange vectortable(SB) return PC with the trap type in
	AX */
						/* Stack is SS, RSP, RFLAGS, CS,
						RIP, Error Code or vectortable(SB)
						Return PC, trap type
								AX = AX */

	PUSHW GS
	PUSHW FS
	MOVW ES, AX /* PUSHW ES is invalid in amd64, but showing the value for
	debugging */
	PUSHW AX
	MOVW DS, AX /* PUSHW DS is invalid in amd64, but showing the value as JMP
	uses it */
	PUSHW AX

	PUSHQ R15 /* RMACH m-> */
	PUSHQ R14 /* RUSER up-> */
	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 /* Ureg* argument to trap */
	PUSHQ SP
	CALL trap(SB)

TEXT _intrr(SB), 1, $-4
_intrestore:
	POPQ AX /* ignore the SP pushed before the call to trap() */

	POPQ AX /* restore registers */
	POPQ BX
	POPQ CX
	POPQ DX
	POPQ SI
	POPQ DI
	POPQ BP
	POPQ R8
	POPQ R9
	POPQ R10
	POPQ R11
	POPQ R12
	POPQ R13
	POPQ R14 /* RUSER up-> */
	POPQ R15 /* RMACH m-> */

	ADDQ $8, SP /* to ignore the [DEFG]S registers as they should not be
	changing */

	ADDQ $16, SP /* pop error code and trap type */
	IRETQ

TEXT noteret(SB), 1, $-4
	CLI
	JMP _intrestore

TEXT vectortable(SB), $0
	CALL _strayintr(SB); BYTE $0x00 /* divide error */
	CALL _strayintr(SB); BYTE $0x01 /* debug exception */
	CALL _strayintr(SB); BYTE $0x02 /* NMI interrupt */
	CALL _strayintr(SB); BYTE $0x03 /* breakpoint */
	CALL _strayintr(SB); BYTE $0x04 /* overflow */
	CALL _strayintr(SB); BYTE $0x05 /* bound */
	CALL _strayintr(SB); BYTE $0x06 /* invalid opcode */
	CALL _strayintr(SB); BYTE $0x07 /* no coprocessor available */
	CALL _strayintrx(SB); BYTE $0x08 /* double fault */
	CALL _strayintr(SB); BYTE $0x09 /* coprocessor segment overflow */
	CALL _strayintrx(SB); BYTE $0x0A /* invalid TSS */
	CALL _strayintrx(SB); BYTE $0x0B /* segment not available */
	CALL _strayintrx(SB); BYTE $0x0C /* stack exception */
	CALL _strayintrx(SB); BYTE $0x0D /* general protection error */
	CALL _strayintrx(SB); BYTE $0x0E /* page fault */
	CALL _strayintr(SB); BYTE $0x0F /* */
	CALL _strayintr(SB); BYTE $0x10 /* coprocessor error */
	CALL _strayintrx(SB); BYTE $0x11 /* alignment check */
	CALL _strayintr(SB); BYTE $0x12 /* machine check */
	CALL _strayintr(SB); BYTE $0x13 /* simd error */
	CALL _strayintr(SB); BYTE $0x14
	CALL _strayintr(SB); BYTE $0x15
	CALL _strayintr(SB); BYTE $0x16
	CALL _strayintr(SB); BYTE $0x17
	CALL _strayintr(SB); BYTE $0x18
	CALL _strayintr(SB); BYTE $0x19
	CALL _strayintr(SB); BYTE $0x1A
	CALL _strayintr(SB); BYTE $0x1B
	CALL _strayintr(SB); BYTE $0x1C
	CALL _strayintr(SB); BYTE $0x1D
	CALL _strayintr(SB); BYTE $0x1E
	CALL _strayintr(SB); BYTE $0x1F
	CALL _strayintr(SB); BYTE $0x20 /* VectorLAPIC */
	CALL _strayintr(SB); BYTE $0x21
	CALL _strayintr(SB); BYTE $0x22
	CALL _strayintr(SB); BYTE $0x23
	CALL _strayintr(SB); BYTE $0x24
	CALL _strayintr(SB); BYTE $0x25
	CALL _strayintr(SB); BYTE $0x26


Thu Jan 20 06:27:31 EST 2022
test

Wed Jan 19 20:14:07 EST 2022


Raw Hex (zero bytes in bold):

2EFF2425910E2000

String Literal:

"\x2E\xFF\x24\x25\x91\x0E\x20\x00"

Array Literal:

{ 0x2E, 0xFF, 0x24, 0x25, 0x91, 0x0E, 0x20, 0x00 }
Disassembly:

0: 2e ff 24 25 91 0e 20 jmp QWORD PTR cs:0x200e91
7: 00


Tue Jan 18 17:00:54 EST 2022
Authentication-Results: minnie.tuhs.org;
	dkim=fail reason="signature verification failed" (2048-bit key;
	unprotected) header.d=dartmouth.edu header.i=@dartmouth.edu
	header.b="QJC5D68b";
	dkim-atps=neutral
From: Douglas McIlroy <douglas.mcilroy@dartmouth.edu>
Date: Mon, 17 Jan 2022 22:22:44 -0500
To: TUHS main list <tuhs@minnie.tuhs.org>
Subject: Re: [TUHS] BWK talk on early Unix Friday 14 January 2022
Errors-To: tuhs-bounces@minnie.tuhs.org
Sender: "TUHS" <tuhs-bounces@minnie.tuhs.org>

> I've just watched an interesting presentation given last Friday via
> video link to the Linux Conference in Australia:

 > Brian Kernighan
 > The early days of Unix at Bell Labs
 > https://www.youtube.com/watch?v=ECCr_KFl41E

Here's an earlier incarnation of the talk:
https://www.youtube.com/watch?v=nS-0Vrmok6Y
I rather enjoyed seeing it with closed captions in Spanish and
speakers turned off.  Aided by the slides, I was pretty well able to
read the Spanish, which otherwise would have been quite mysterious.

Doug




Tue Jan 18 15:41:19 EST 2022

	CMPQ TOP, $-1 /* return value == -1?  */
	JEQ fsread_checkfd /* return value = -1 */
	TESTQ TOP, TOP /* check if read return value == 0 */
	JNZ fsread_continue
fsread_checkfd:
	MOVQ 32(SP), CX /* read return value == 0, check if fd is stdin */
	TESTQ CX, CX
	JNZ fsread_continue
	/* and fd == 0, terminate */
	ADDQ $40, SP
	/* TODO
	 * this should have been JMP terminate(SB), but it is raising a #GP error.
	 * CALL terminate(SB) works fine.
	 * Would have to dig through the amd64 manuals and
	 * https://www.felixcloutier.com/x86/jmp to figure out why.
	 * until then, use the label to jump to

JMP to a label: JMP _fthterminate
2011b8 4883c428 (644) ADDQ $40,SP
2011bc e9d0fcffff (493) JMP ,200e91
2011c1 4883c428 (656) ADDQ $40,SP

JMP to symbol: JMP terminate(SB)
2011b8 4883c428 (645) ADDQ $40,SP
2011bc ff2425910e2000 (654) JMP ,terminate+0(SB)
2011c3 4883c428 (657) ADDQ $40,SP

CALL to symbol: CALL terminate(SB)
2011b8 4883c428 (645) ADDQ $40,SP
2011bc e8d0fcffff (655) CALL ,200e91+terminate
2011c1 4883c428 (657) ADDQ $40,SP
	JMP _fthterminate
	 */
	JMP fthdump(SB)

fsread_continue:
	ADDQ $40, SP
	NEXT


Tue Jan 18 15:26:35 EST 2022


Raw Hex (zero bytes in bold):

FF2425910E2000

String Literal:

"\xFF\x24\x25\x91\x0E\x20\x00"

Array Literal:

{ 0xFF, 0x24, 0x25, 0x91, 0x0E, 0x20, 0x00 }
Disassembly:

0: ff 24 25 91 0e 20 00 jmp QWORD PTR ds:0x200e91


JMP to a label: JMP _fthterminate
2011b8 4883c428 (644) ADDQ $40,SP
2011bc e9d0fcffff (493) JMP ,200e91
2011c1 4883c428 (656) ADDQ $40,SP

JMP to symbol: JMP terminate(SB)
2011b8 4883c428 (645) ADDQ $40,SP
2011bc ff2425910e2000 (654) JMP ,terminate+0(SB)
2011c3 4883c428 (657) ADDQ $40,SP

CALL to symbol: CALL terminate(SB)
2011b8 4883c428 (645) ADDQ $40,SP
2011bc e8d0fcffff (655) CALL ,200e91+terminate
2011c1 4883c428 (657) ADDQ $40,SP
	JMP _fthterminate


Tue Jan 18 14:16:25 EST 2022
forth.s:426 bindings.s:169 syntax error, last name: terminate
rom: *.reg
rom: *.omem
saw LNAME
mk: 'install' is up to date
mk: 6a forth.s : exit status=rc 16797397: 6a 16797427: error


Tue Jan 18 14:13:10 EST 2022
/*
 * Simple segment descriptors with no translation.
 */
#define EXECSEGM(p) { 0, SEGL|SEGP|SEGPL(p)|SEGEXEC }
#define DATASEGM(p) { 0, SEGB|SEGG|SEGP|SEGPL(p)|SEGDATA|SEGW }

Segdesc gdt[NGDT] =
{
[NULLSEG] { 0, 0}, /* null descriptor */
[KESEG] EXECSEGM(0), /* code - kernel privilege for all */
[KDSEG] DATASEGM(0), /* data - kernel privilege for all */
};


Tue Jan 18 13:43:33 EST 2022
Jump out the house, jump out the house (what?)
Jump out the house, jump out the house (what?)
Jump out the house, jump out the house (what?)
Jump out the house, jump out the house (what?)
Jump out the house, jump out the house (what?)
Jump out the house, jump out the house (what?)
Jump out the house, jump out the house (what?)
Jump out the house
Jump out that bitch (what?), jump out that bitch (what?)
Jump out that bitch (what?), jump out that bitch (what?)
Jump out that bitch (what?), jump out that bitch (I jump out that bitch, what?)
Jump out that bitch (jump out that bitch, what?)
Jump out that bitch (jump out that bitch, what?)

Tue Jan 18 13:42:40 EST 2022
What a night.  Usually when I’m up this late it’s because I’m listening to NBA
Youngboy.

next