Files
net/exec/startup.c
2025-12-20 18:49:21 -08:00

247 lines
6.7 KiB
C

#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <exec/debcon.h>
#include <exec/list.h>
#include <exec/task.h>
#include <exec/mem.h>
#include <exec/hal.h>
#include <exec/port.h>
#include <exec/library.h>
#include <exec/device.h>
#include <exec/detect.h>
#include <exec/net.h>
#include <gui/wm.h>
struct Task *testTask1;
struct Task *testTask2;
struct List testList = {0};
struct Node node1 = {.name = "Node 1\n"};
struct Node node2 = {.name = "Node 2\n"};
struct Node node3 = {.name = "Node 3\n"};
struct Port testPort = {0};
struct TestMsg {
struct Message msg;
char *data;
};
void print_mac_address(uint8_t address[6])
{
for (int i = 0; i < 6; i++) {
uint8_t byte = address[i];
// Print high nibble
uint8_t high = (byte >> 4) & 0x0F;
DebconPutChar(high < 10 ? ('0' + high) : ('A' + (high - 10)));
// Print low nibble
uint8_t low = byte & 0x0F;
DebconPutChar(low < 10 ? ('0' + low) : ('A' + (low - 10)));
// Separator
if (i < 5) DebconPutChar(':');
}
}
void TestTask1(void) {
struct TestMsg msg;
struct Port reply_port;
NewPort(&reply_port, 0);
msg.msg.reply_port = &reply_port;
msg.msg.length = sizeof(struct TestMsg);
//goto skip_lpt;
struct Port *rmp;
struct IOStdReq *req;
if (!(rmp = CreatePort(NULL, 0))) {
DebconPrint("Failed to create port for LPT.device\n");
for(;;);
}
if (!(req = CreateStdIO(rmp))) {
DebconPrint("Failed to create IOStdReq for LPT.device\n");
for(;;);
}
int status;
if ((status = OpenDevice("lpt.device", 0, (struct IORequest *)req, 0)) != ODE_OK) {
DebconPrint("Failed to open LPT.device\n");
DebconPrintHex(status);
for(;;);
}
req->ior.command = CMD_WRITE;
req->data = "Login";
req->reqlen = strlen(req->data)+1;
skip_lpt:
//for(;;);
while (1) {
msg.data = "Message from Task 1. ";
PutMsg(&testPort, (struct Message *)&msg);
DebconPrint(((struct TestMsg *)WaitPort(msg.msg.reply_port))->data);
DoIO((struct IORequest *)req);
}
}
void InitializeVideo(void) {
struct IOStdReq *req;
struct Port *rmp;
int open_status;
struct VideoMode vidmode = {
.width = 640,
.height = 480,
.bpp = 32
};
if ((rmp = CreatePort(NULL, 0))) {
if ((req = CreateStdIO(rmp))) {
if (!(open_status = OpenDevice("bga.device", 0, (struct IORequest *)req, 0))) {
req->ior.command = VID_SET_MODE;
req->data = &vidmode;
req->reqlen = sizeof(vidmode);
DoIO((struct IORequest *)req);
} else {
DebconPrint("Failed to open BGA.device\n");
DebconPrintHex(open_status);
}
} else {
DebconPrint("Failed to create IOStdReq\n");
}
} else {
DebconPrint("Failed to create Port\n");
}
}
void TestTask2(void) {
struct TestMsg replyMsg = {
.data = "Reply from Task 2\n",
.msg = {
.reply_port = NULL,
.length = sizeof(struct TestMsg),
}
};
InitializeVideo();
struct Screen screen = {
.buffer = (uint32_t *)0xfd000000,
.width = 640,
.height = 480
};
WmInit(&screen);
struct Window window = {
.title = "Test Window",
.x = 15,
.y = 20,
.width = 300,
.height = 200
};
AddWindow(&window);
goto skip_net;
//goto skip_net;
/* open ne2000 device */
struct IOStdReq *req;
struct Port *rmp;
int open_status;
if ((rmp = CreatePort(NULL, 0))) {
if ((req = CreateStdIO(rmp))) {
if (!(open_status = OpenDevice("ne2kisa.device", 0, (struct IORequest *)req, 0))) {
/* get mac address */
uint8_t mac_address[6];
req->ior.command = NIC_GET_ADDRESS;
req->data = mac_address;
req->reqlen = sizeof(mac_address);
BeginIO((struct IORequest *)req);
if (req->ior.error != DS_OK) {
DebconPutChar('A');
DebconPutChar('0'+req->ior.error);
for(;;);
}
print_mac_address(mac_address);
/* send frame */
char frame[100];
struct EthernetFrame *frameHeader = (struct EthernetFrame *)frame;
frameHeader->dest_mac[0] = 0xAA;
frameHeader->dest_mac[1] = 0xBB;
frameHeader->dest_mac[2] = 0xCC;
frameHeader->dest_mac[3] = 0xDD;
frameHeader->dest_mac[4] = 0x11;
frameHeader->dest_mac[5] = 0x22;
for (int i = 0; i < 6; i++) frameHeader->src_mac[i] = mac_address[i];
frameHeader->ethertype = 0x1234;
for (int i = 0; i < 64; i++) frameHeader->payload[i] = 'a'+(i%26);
req->ior.command = NIC_SEND_FRAME;
req->data = frame;
req->reqlen = sizeof(frame);
BeginIO((struct IORequest *)req);
if (req->ior.error != DS_OK) {
DebconPutChar('B');
DebconPutChar('0'+req->ior.error);
for(;;);
}
} else {
DebconPrint("Failed to open NE2KISA.device\n");
DebconPrintHex(open_status);
}
} else {
DebconPrint("Failed to create IOStdReq\n");
}
} else {
DebconPrint("Failed to create Port\n");
}
skip_net:
while (1) {
struct TestMsg *msg = (struct TestMsg *)WaitPort(&testPort);
DebconPrint(msg->data);
msg->data = "Message received by Task 2. ";
ReplyMsg((struct Message *)msg);
if (msg->msg.node.type == NT_FREEMSG) {
DebconPrint("Freeing message\n");
}
WmUpdate();
}
}
extern void PCLPT_Init(void);
extern void NE2KISA_Init(void);
extern void BGA_Init(void);
void ExecInit(void) {
DebconPutChar('E');
TasksInit();
DebconPutChar('x');
PortsInit();
DebconPutChar('e');
DevicesInit();
DebconPutChar('c');
DetectInit();
HalDetect();
DebconPutChar('!');
PrintDetects();
NewPort(&testPort, 0);
PCLPT_Init();
NE2KISA_Init();
BGA_Init();
testTask1 = CreateTask("TestTask1", 0, (uintptr_t)TestTask1, 4096);
testTask2 = CreateTask("TestTask2", 0, (uintptr_t)TestTask2, 4096);
/*Enqueue(&testList, &node1);
Enqueue(&testList, &node2);
Enqueue(&testList, &node3);
DebconPrint(RemTail(&testList)->name);
DebconPrint(RemTail(&testList)->name);
DebconPrint(RemTail(&testList)->name);*/
HalEnableInterrupts();
HalIdleTask();
}