Skip to content

Commit 8625d9d

Browse files
committed
* semi implemented driver for amd pcnet-FAST III
* bumped kernel version to 2.4.1 * Added 2 new syscalls writehdd and readhdd * Added syscalls.txt * Updated interrupts.txt
1 parent a86dbcc commit 8625d9d

17 files changed

+804
-568
lines changed

CPU/syscall.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
void printf(char*);
44
void printfchar(char);
55
PowerControl syscontrol;
6+
AdvancedTechnologyAttachment hdd1s(0x1F0, false);
67

78
inline GlobalDescriptorTable gdt;
89
void taskA();
@@ -45,6 +46,14 @@ uint32_t SyscallHandler::HandleInterrupt(uint32_t esp)
4546
esp = (uint32_t)taskManager.SwitchTask((int)cpu->ebx, (CPUState*)esp);
4647
break;
4748

49+
case 5: // sys_writehdd
50+
hdd1s.Write28((uint32_t)cpu->ebx, (uint8_t*)cpu->ecx, (int)cpu->edx);
51+
break;
52+
53+
case 6: // sys_readhdd
54+
hdd1s.Read28((uint32_t)cpu->ebx, (uint8_t*)cpu->ecx);
55+
break;
56+
4857
default:
4958
break;
5059
}

CPU/syscall.h

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "../Include/types.h"
55
#include "Interrupts.h"
66
#include "PowerControl.h"
7+
#include "../Drivers/HDD-ATA.h"
78
#include "../kernel/MultiTask.h"
89

910
class SyscallHandler : public InterruptHandler

Docs/Interrupts.txt

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
Interrupt table:
22

3-
__________________________________________________________________
4-
| Interrupt Number | Type of interrupt | Hardware |
5-
|________________________|_______________________|_______________|
6-
| 0x20 | Hardware | Timer |
7-
| 0x21 | Hardware | Keyboard |
8-
| 0x2C | Hardware | Mouse |
9-
|________________________|_______________________|_______________|
3+
____________________________________________________________________________
4+
| Interrupt Number | Type of interrupt | Hardware / software |
5+
|________________________|_______________________|__________________________|
6+
| 0x20 | Hardware | Timer |
7+
| 0x21 | Hardware | Keyboard |
8+
| 0x2C | Hardware | Mouse |
9+
| 0x80 | software | Syscall |
10+
|________________________|_______________________|__________________________|

Docs/syscalls.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
list of Syscalls [0x80]:
2+
3+
SYS_PRINTF[TEXT]: eax=1, ebx=(char*)"Text to print"
4+
SYS_PRINTC[TEXT]: eax=2, ebx=(char)"character to print"
5+
6+
SYS_REBOOT[POWER]: eax=3
7+
8+
SYS_CNGTSK[TASK]: eax=4, ebx=(int)tasknumber
9+
10+
SYS_WRITEHDD[ATA]: eax=5, ebx=(uint32_t)sectornumber, ecx=(uint8_t*)pointertovariable, edx=(int)count
11+
SYS_READHDD[ATA] : eax=6, ebx=(uint32_t)sectornumber, ecx=(uint8_t*)pointertovariable

Drivers/AM79C973.cpp

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#include "AM79C973.h"
2+
3+
void printHex(uint8_t Key);
4+
5+
AM79C973::AM79C973(PCIDeviceDescriptor *dev, InterruptManager *interrupts)
6+
: Driver(),
7+
InterruptHandler(dev->interrupt + interrupts->HardwareInterruptOffset(), interrupts),
8+
MACAddress0Port(dev->portBase),
9+
MACAddress2Port(dev->portBase + 0x02),
10+
MACAddress4Port(dev->portBase + 0x04),
11+
registerDataPort(dev->portBase + 0x10),
12+
registerAddressPort(dev->portBase + 0x12),
13+
resetPort(dev->portBase + 0x14),
14+
busControlRegisterDataPort(dev->portBase + 0x16)
15+
{
16+
currentSendBuffer = 0;
17+
currentRecvBuffer = 0;
18+
19+
uint64_t MAC0 = MACAddress0Port.ReadFromPort() % 256;
20+
uint64_t MAC1 = MACAddress0Port.ReadFromPort() / 256;
21+
uint64_t MAC2 = MACAddress2Port.ReadFromPort() % 256;
22+
uint64_t MAC3 = MACAddress2Port.ReadFromPort() / 256;
23+
uint64_t MAC4 = MACAddress4Port.ReadFromPort() % 256;
24+
uint64_t MAC5 = MACAddress4Port.ReadFromPort() / 256;
25+
26+
uint64_t MAC = MAC5 << 40 | MAC4 << 32 | MAC3 << 24 | MAC2 << 16 | MAC1 << 8 | MAC0;
27+
28+
registerAddressPort.WriteToPort(20);
29+
busControlRegisterDataPort.WriteToPort(0x102);
30+
31+
registerAddressPort.WriteToPort(0);
32+
registerDataPort.WriteToPort(0x04);
33+
34+
initBlock.mode = 0x0000; // promiscuous mode = false
35+
initBlock.reserved1 = 0;
36+
initBlock.numSendBuffers = 3;
37+
initBlock.reserved2 = 0;
38+
initBlock.numRecvBuffers = 3;
39+
initBlock.physicalAddress = MAC;
40+
initBlock.reserved3 = 0;
41+
initBlock.logicalAddress = 0;
42+
43+
sendBufferDescr = (BufferDescriptor *)((((uint32_t)&sendBufferDescrMemory[0]) + 15) & ~((uint32_t)0xF));
44+
initBlock.sendBufferDescrAddress = (uint32_t)sendBufferDescr;
45+
recvBufferDescr = (BufferDescriptor *)((((uint32_t)&recvBufferDescrMemory[0]) + 15) & ~((uint32_t)0xF));
46+
initBlock.recvBufferDescrAddress = (uint32_t)recvBufferDescr;
47+
48+
for (uint8_t i = 0; i < 8; i++)
49+
{
50+
sendBufferDescr[i].address = (((uint32_t)&sendBuffers[i]) + 15) & ~(uint32_t)0xF;
51+
sendBufferDescr[i].flags = 0x7FF | 0xF000;
52+
sendBufferDescr[i].flags2 = 0;
53+
sendBufferDescr[i].avail = 0;
54+
55+
recvBufferDescr[i].address = (((uint32_t)&recvBuffers[i]) + 15) & ~(uint32_t)0xF;
56+
recvBufferDescr[i].flags = 0xF7FF | 0x80000000;
57+
recvBufferDescr[i].flags2 = 0;
58+
sendBufferDescr[i].avail = 0;
59+
}
60+
61+
registerAddressPort.WriteToPort(1);
62+
registerDataPort.WriteToPort((uint32_t)(&initBlock) & 0xFFFF);
63+
registerAddressPort.WriteToPort(2);
64+
registerDataPort.WriteToPort(((uint32_t)(&initBlock) >> 16) & 0xFFFF);
65+
}
66+
67+
AM79C973::~AM79C973()
68+
{
69+
}
70+
71+
void AM79C973::activate()
72+
{
73+
registerAddressPort.WriteToPort(0);
74+
registerDataPort.WriteToPort(0x41);
75+
76+
registerAddressPort.WriteToPort(4);
77+
uint32_t temp = registerDataPort.ReadFromPort();
78+
registerAddressPort.WriteToPort(4);
79+
registerDataPort.WriteToPort(temp | 0xC00);
80+
81+
registerAddressPort.WriteToPort(0);
82+
registerDataPort.WriteToPort(0x42);
83+
}
84+
85+
int AM79C973::reset()
86+
{
87+
resetPort.ReadFromPort();
88+
resetPort.WriteToPort(0);
89+
return 10;
90+
}
91+
92+
void printf(char *);
93+
94+
uint32_t AM79C973::HandleInterrupt(uint32_t esp)
95+
{
96+
printf("AM79C973: Interrupt\n");
97+
98+
registerAddressPort.WriteToPort(0);
99+
uint32_t temp = registerDataPort.ReadFromPort();
100+
101+
if ((temp & 0x8000) == 0x8000)
102+
printf("AM79c973 ERROR\n");
103+
if ((temp & 0x2000) == 0x2000)
104+
printf("AM79c973 COLLISION ERROR\n");
105+
if ((temp & 0x1000) == 0x1000)
106+
printf("AM79c973 MISSED FRAME\n");
107+
if ((temp & 0x0800) == 0x0800)
108+
printf("AM79c973 MEMORY ERROR\n");
109+
if ((temp & 0x0400) == 0x0400)
110+
receive();
111+
if ((temp & 0x0200) == 0x0200)
112+
printf("AM79c973 DATA SENT\n");
113+
114+
registerAddressPort.WriteToPort(0);
115+
registerDataPort.WriteToPort(temp);
116+
117+
if ((temp & 0x0200) == 0x0200)
118+
printf("AM79c973 INIT DONE\n");
119+
120+
return esp;
121+
}
122+
123+
void AM79C973::send(uint8_t *buffer, int size)
124+
{
125+
int sendDescriptor = currentSendBuffer;
126+
currentSendBuffer = (currentSendBuffer + 1) % 8;
127+
128+
if (size > 1518)
129+
size = 1518;
130+
131+
for (uint8_t *src = buffer + size - 1,*dst = (uint8_t *)(sendBufferDescr[sendDescriptor].address + size - 1);src >= buffer; src--, dst--)
132+
*dst = *src;
133+
134+
sendBufferDescr[sendDescriptor].avail = 0;
135+
sendBufferDescr[sendDescriptor].flags2 = 0;
136+
sendBufferDescr[sendDescriptor].flags = 0x8300F000 | ((uint16_t)((-size) & 0xFFF));
137+
registerAddressPort.WriteToPort(0);
138+
registerDataPort.WriteToPort(0x48);
139+
}
140+
141+
void AM79C973::receive()
142+
{
143+
printf("AM79c973 DATA RECEIVED\n");
144+
145+
for (; (recvBufferDescr[currentRecvBuffer].flags & 0x80000000) == 0;currentRecvBuffer = (currentRecvBuffer + 1) % 8)
146+
{
147+
if (!(recvBufferDescr[currentRecvBuffer].flags & 0x40000000) && (recvBufferDescr[currentRecvBuffer].flags & 0x03000000) == 0x03000000)
148+
149+
{
150+
uint32_t size = recvBufferDescr[currentRecvBuffer].flags & 0xFFF;
151+
if (size > 64)
152+
size -= 4;
153+
154+
uint8_t *buffer = (uint8_t *)(recvBufferDescr[currentRecvBuffer].address);
155+
156+
for (int i = 0; i < size; i++)
157+
{
158+
printHex(buffer[i]);
159+
printf(" ");
160+
}
161+
}
162+
163+
recvBufferDescr[currentRecvBuffer].flags2 = 0;
164+
recvBufferDescr[currentRecvBuffer].flags = 0x8000F7FF;
165+
}
166+
}

Drivers/AM79C973.h

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#ifndef __AM79C973_H__
2+
#define __AM79C973_H__
3+
4+
#include "../Hardcom/pci.h"
5+
#include "Driver.h"
6+
#include "../Include/types.h"
7+
#include "../CPU/Interrupts.h"
8+
#include "IOPorts.h"
9+
10+
class AM79C973 : public Driver, public InterruptHandler
11+
{
12+
struct InitializationBlock
13+
{
14+
uint16_t mode;
15+
unsigned reserved1 : 4;
16+
unsigned numSendBuffers : 4;
17+
unsigned reserved2 : 4;
18+
unsigned numRecvBuffers : 4;
19+
uint64_t physicalAddress : 48;
20+
uint16_t reserved3;
21+
uint64_t logicalAddress;
22+
uint32_t recvBufferDescrAddress;
23+
uint32_t sendBufferDescrAddress;
24+
} __attribute__((packed));
25+
26+
struct BufferDescriptor
27+
{
28+
uint32_t address;
29+
uint32_t flags;
30+
uint32_t flags2;
31+
uint32_t avail;
32+
} __attribute__((packed));
33+
34+
port16BIT MACAddress0Port;
35+
port16BIT MACAddress2Port;
36+
port16BIT MACAddress4Port;
37+
port16BIT registerDataPort;
38+
port16BIT registerAddressPort;
39+
port16BIT resetPort;
40+
port16BIT busControlRegisterDataPort;
41+
42+
InitializationBlock initBlock;
43+
44+
BufferDescriptor *sendBufferDescr;
45+
uint8_t sendBufferDescrMemory[2048 + 15];
46+
uint8_t sendBuffers[2 * 1024 + 15][8];
47+
uint8_t currentSendBuffer;
48+
49+
BufferDescriptor *recvBufferDescr;
50+
uint8_t recvBufferDescrMemory[2048 + 15];
51+
uint8_t recvBuffers[2 * 1024 + 15][8];
52+
uint8_t currentRecvBuffer;
53+
54+
public:
55+
AM79C973(PCIDeviceDescriptor *dev, InterruptManager *interrupts);
56+
~AM79C973();
57+
58+
void send(uint8_t* buffer, int count);
59+
void receive();
60+
61+
void activate();
62+
int reset();
63+
uint32_t HandleInterrupt(uint32_t esp);
64+
};
65+
66+
#endif

Drivers/Driver.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class DriverManager
1616
{
17-
private:
17+
public:
1818
Driver* drivers[255];
1919
int numDrivers;
2020

Drivers/HDD-ATA.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void AdvancedTechnologyAttachment::Read28(uint32_t sector, uint8_t *data, int co
8888
return;
8989
}
9090

91-
printf("Reading from ATA: ");
91+
//printf("Reading from ATA: ");
9292

9393
for (uint16_t i = 0; i < count; i += 2)
9494
{
@@ -126,7 +126,7 @@ void AdvancedTechnologyAttachment::Write28(uint32_t sector, uint8_t *data, int c
126126
lbaHiPort.WriteToPort((sector & 0x00FF0000) >> 16);
127127
commandPort.WriteToPort(0x30);
128128

129-
printf("Writing to ATA: ");
129+
//printf("Writing to ATA: ");
130130

131131
for (uint16_t i = 0; i < count; i += 2)
132132
{

0 commit comments

Comments
 (0)