<commit_before>#include "intrim.h"
#include <quark.h>
#include <intr.h>
#include <led.h>
#include <lib.h>
#include <ser.h>

#define IDDEV	20
#define IDFUN	6

#define VEC	0x30

static struct Idtrec idt[0x100];

#define RLAPICID	0xFEE00020

#define MSGADDR	0xFEE00000
#define MSGDATA	(0x00 | VEC)

#define OFFBAR0	0x10
#define OFFMSGADDR	0xA4
#define OFFMSGDATA	0xA8

static u32 *rintren;

static
void
configmsg()
{
	u16 v16;
	u32 *a;
	u32 v;

	a = (u32 *)RLAPICID;
	v = *a;
	pcicw32(OFFMSGADDR, MSGADDR | (v << 0xC));
	v = 0;
	pcicr32(OFFMSGADDR, &v);
	seroutf("MSGADDR(0x%X)\r\n", v);
	pcicw16(OFFMSGDATA, MSGDATA);
	v16 = 0;
	pcicr16(OFFMSGDATA, &v16);
	seroutf("MSGDATA(0x%X)\r\n", v16);
}

static
void
intrinit()
{
	u32 v32;
	struct Idtrec *rec;
	char tp[6];

	rec = &idt[VEC];
	sidt(tp);
	mmemcpy(idt, *(u32 *)(tp + 2), *(u16 *)tp + 1);
	cli();
	idtrsetssel(rec, 0x02);
	idtrsettype(rec, IDTRINTR);
	idtrsetad(rec, oneth);
	configmsg();
	pcicr32(OFFBAR0, &v32);
	v32 &= ~0 << 12;
	rintren = (u32 *)(v32 + 0x101C);

	seroutf("MM interrupt enable register(0x%X, 0x%X)\r\n", rintren, *rintren);
	packt((const char *)idt, sizeof idt / sizeof idt[0], tp);
	lidt(tp);
	sti();
}

int
main()
{
	int r;

	wait();
	ledminit();
	r = serinit();
	if (r != 0) {
		ledmemit(5, 100);
		for (;;)
			;
	}
	serout("serial port initialization has done.\r\n");
	serout("ethernet pci configuration registers.\r\n");
	pcicsetdev(IDDEV);
	pcicsetfn(IDFUN);
	pcicpr();
	intrinit();

	for (;;) {
		ledmemit(5, 1);
		wait();
		wait();
	}
	return 0;
}<commit_msg>* fix APIC ID. * set memory space enable. * check MAC Configuration register. * attempt to set interrupt enable register. * attempt to set spurious interrupt vector register. * check operation mode register. All code is very dirty. They are just experiments for me to understand.<commit_after>#include "intrim.h"
#include <quark.h>
#include <intr.h>
#include <led.h>
#include <lib.h>
#include <ser.h>

#define IDDEV	20
#define IDFUN	6

#define VEC	0x30
#define SVEC	0x31

static struct Idtrec idt[0x100];

#define RLAPICID	0xFEE00020
#define RSIV	0xFEE000F0
#define MAPICID 0x07000000
#define APICEN	0x00000100

#define MSGADDR	0xFEE00000
#define MSGDATA	(0x00 | VEC)


static u32 base0;
static volatile u32 *rmacconf;
static volatile u32 *rintren;
static volatile u32 *rsiv;
static volatile u32 *ropmod;

static
void
configmsg()
{
	u16 v16;
	u32 *a;
	u32 v;

	a = (u32 *)RLAPICID;
	v = *a;
	seroutf("APIC ID(0x%X)\r\n", v);
	v = ((unsigned)(v & MAPICID) >> 0x18);
	seroutf("MSGADDR VALUE(0x%X)\r\n", MSGADDR | (v << 0xC));
	pcicw32(POFFMSGADDR, MSGADDR | (v << 0xC));
	v = 0;
	pcicr32(POFFMSGADDR, &v);
	seroutf("MSGADDR(0x%X)\r\n", v);
	pcicw16(POFFMSGDATA, MSGDATA);
	v16 = 0;
	pcicr16(POFFMSGDATA, &v16);
	seroutf("MSGDATA(0x%X)\r\n", v16);
}

static
void
intrinit()
{
	u32 v32;
	struct Idtrec *rec;
	char tp[6];

	rec = &idt[VEC];
	sidt(tp);
	mmemcpy(idt, *(u32 *)(tp + 2), *(u16 *)tp + 1);
	cli();
	idtrsetssel(rec, 0x02);
	idtrsettype(rec, IDTRINTR);
	idtrsetad(rec, oneth);
	configmsg();
	pcicw16(POFFCMD, 0x0002);
	pcicr32(POFFBAR0, &v32);
	v32 &= ~0 << 12;
	base0 = v32;

	rmacconf = (u32 *)(base0 + 0x0000);
	seroutf("MAC Configuration register(0x%X)\r\n", *rmacconf);
	rintren = (u32 *)(v32 + 0x101C);

	seroutf("MM interrupt enable register(0x%X, 0x%X)\r\n", rintren, *rintren);
	*rintren |= 0x00000040;
	rsiv = (u32 *)RSIV;
	seroutf("Spurious Interrupt Vector Register(0x%X)\r\n", *rsiv);
	*rsiv = *rsiv | APICEN | VEC;

	ropmod = (u32 *)(base0 + 0x1018);
	seroutf("Operation mode register(0x%X)\r\n", *ropmod);

	packt((const char *)idt, sizeof idt / sizeof idt[0], tp);
	lidt(tp);
	sti();
}

int
main()
{
	int r;

	wait();
	ledminit();
	r = serinit();
	if (r != 0) {
		ledmemit(5, 100);
		for (;;)
			;
	}
	serout("serial port initialization has done.\r\n");
	serout("ethernet pci configuration registers.\r\n");
	pcicsetdev(IDDEV);
	pcicsetfn(IDFUN);
	pcicpr();
	intrinit();

	for (;;) {
#if 1
		asm ("int $0x30\n\t");
		ledmemit(10, 1);
#endif
		wait();
		wait();
	}
	return 0;
}
{'fraction_non_alphanumeric': 0.17814667988107036, 'fraction_numerical': 0.07234886025768088, 'mean_word_length': 4.389853137516689, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6352710', 'n_tokens_mistral': 2066, 'n_tokens_neox': 1867, 'n_words': 446}