Skip to content

Commit 99560c2

Browse files
authored
Merge pull request #5 from rickgaiser/for-ps2dev
Fix warnings and DMA packing/alignment
2 parents 8767d46 + 54eb647 commit 99560c2

File tree

11 files changed

+129
-127
lines changed

11 files changed

+129
-127
lines changed

include/ps2s/core.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,14 @@ inline ptrType MakePtrUncachedAccl(ptrType ptr)
5757

5858
// used to override new() to allocate on qword boundaries (only for linux)
5959

60-
// PLIN -- need to override delete as well...
6160
inline void* New16(size_t size)
6261
{
63-
return ::operator new(size);
62+
return ::operator new(size, std::align_val_t(16));
63+
}
64+
65+
inline void Delete16(void* p)
66+
{
67+
::operator delete(p);
6468
}
6569

6670
// cop0 counter

include/ps2s/displayenv.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,8 @@ class CDisplayEnv {
126126

127127
void SendSettings(void);
128128

129-
inline void* operator new(size_t size)
130-
{
131-
return Core::New16(size);
132-
}
129+
inline void* operator new(size_t size) { return Core::New16(size); }
130+
inline void operator delete(void* p) { Core::Delete16(p); }
133131

134132
protected:
135133
private:

include/ps2s/dmac.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ typedef struct tSourceChainTag_t {
3737
tU64 SPR : 1;
3838
tU32 opt1;
3939
tU32 opt2;
40-
} tSourceChainTag __attribute__((aligned(16)));
40+
} __attribute__((packed,aligned(16))) tSourceChainTag;
4141

4242
typedef tSourceChainTag tDmaTag;
4343

include/ps2s/drawenv.h

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -189,40 +189,41 @@ class CDrawEnv {
189189
// accessors
190190
tU32 GetFrameBufferAddr(void) { return gsrFrame.fb_addr * 2048; }
191191

192-
inline void* operator new(size_t size)
193-
{
194-
return Core::New16(size);
195-
}
192+
inline void* operator new(size_t size) { return Core::New16(size); }
193+
inline void operator delete(void* p) { Core::Delete16(p); }
196194

197195
protected:
198-
tSourceChainTag SettingsDmaTag;
199-
tGifTag SettingsGifTag;
200-
GS::tFrame gsrFrame;
201-
tU64 FrameAddr;
202-
GS::tZbuf gsrZBuf;
203-
tU64 ZBufAddr;
204-
GS::tXyoffset gsrXYOffset;
205-
tU64 XYOffsetAddr;
206-
GS::tPrmodecont gsrPrModeCont;
207-
tU64 PrModeContAddr;
208-
GS::tColclamp gsrColClamp;
209-
tU64 ColClampAddr;
210-
GS::tTest gsrTest;
211-
tU64 TestAddr;
212-
GS::tAlpha gsrAlpha;
213-
tU64 AlphaAddr;
214-
GS::tPabe gsrPABE;
215-
tU64 PABEAddr;
216-
GS::tFba gsrFBA;
217-
tU64 FBAAddr;
218-
GS::tDthe gsrDTHE;
219-
tU64 DTHEAddr;
220-
GS::tDimx gsrDIMX;
221-
tU64 DIMXAddr;
222-
GS::tScissor gsrScissor;
223-
tU64 ScissorAddr;
224-
GS::tFogcol gsrFogCol;
225-
tU64 FogColAddr;
196+
struct {
197+
// DMA tag + GIF tag + 13 register settings
198+
tSourceChainTag SettingsDmaTag;
199+
tGifTag SettingsGifTag;
200+
GS::tFrame gsrFrame;
201+
tU64 FrameAddr;
202+
GS::tZbuf gsrZBuf;
203+
tU64 ZBufAddr;
204+
GS::tXyoffset gsrXYOffset;
205+
tU64 XYOffsetAddr;
206+
GS::tPrmodecont gsrPrModeCont;
207+
tU64 PrModeContAddr;
208+
GS::tColclamp gsrColClamp;
209+
tU64 ColClampAddr;
210+
GS::tTest gsrTest;
211+
tU64 TestAddr;
212+
GS::tAlpha gsrAlpha;
213+
tU64 AlphaAddr;
214+
GS::tPabe gsrPABE;
215+
tU64 PABEAddr;
216+
GS::tFba gsrFBA;
217+
tU64 FBAAddr;
218+
GS::tDthe gsrDTHE;
219+
tU64 DTHEAddr;
220+
GS::tDimx gsrDIMX;
221+
tU64 DIMXAddr;
222+
GS::tScissor gsrScissor;
223+
tU64 ScissorAddr;
224+
GS::tFogcol gsrFogCol;
225+
tU64 FogColAddr;
226+
} __attribute__((packed,aligned(16)));
226227
tU32 uiNumGSRegs;
227228

228229
CSCDmaPacket GifPacket;
@@ -234,7 +235,7 @@ class CDrawEnv {
234235
private:
235236
void InitCommon(GS::tContext context);
236237

237-
} __attribute__((aligned(16)));
238+
};
238239

239240
/********************************************
240241
* inline methods

include/ps2s/gs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ typedef struct tGifTag_t {
202202
unsigned long long REGS13 : 4;
203203
unsigned long long REGS14 : 4;
204204
unsigned long long REGS15 : 4;
205-
} tGifTag __attribute__((aligned(16)));
205+
} __attribute__((packed,aligned(16))) tGifTag;
206206

207207
inline unsigned int
208208
GS::GetBitsPerPixel(tPSM psm)

include/ps2s/gs_reg_types.h

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,38 @@
1313
namespace GS {
1414

1515
typedef struct {
16-
tU64 DIMX00 : 3 __attribute__((packed));
17-
tU64 pad03 : 1 __attribute__((packed));
18-
tU64 DIMX01 : 3 __attribute__((packed));
19-
tU64 pad07 : 1 __attribute__((packed));
20-
tU64 DIMX02 : 3 __attribute__((packed));
21-
tU64 pad11 : 1 __attribute__((packed));
22-
tU64 DIMX03 : 3 __attribute__((packed));
23-
tU64 pad15 : 1 __attribute__((packed));
24-
tU64 DIMX10 : 3 __attribute__((packed));
25-
tU64 pad19 : 1 __attribute__((packed));
26-
tU64 DIMX11 : 3 __attribute__((packed));
27-
tU64 pad23 : 1 __attribute__((packed));
28-
tU64 DIMX12 : 3 __attribute__((packed));
29-
tU64 pad27 : 1 __attribute__((packed));
30-
tU64 DIMX13 : 3 __attribute__((packed));
31-
tU64 pad31 : 1 __attribute__((packed));
32-
tU64 DIMX20 : 3 __attribute__((packed));
33-
tU64 pad35 : 1 __attribute__((packed));
34-
tU64 DIMX21 : 3 __attribute__((packed));
35-
tU64 pad39 : 1 __attribute__((packed));
36-
tU64 DIMX22 : 3 __attribute__((packed));
37-
tU64 pad43 : 1 __attribute__((packed));
38-
tU64 DIMX23 : 3 __attribute__((packed));
39-
tU64 pad47 : 1 __attribute__((packed));
40-
tU64 DIMX30 : 3 __attribute__((packed));
41-
tU64 pad51 : 1 __attribute__((packed));
42-
tU64 DIMX31 : 3 __attribute__((packed));
43-
tU64 pad55 : 1 __attribute__((packed));
44-
tU64 DIMX32 : 3 __attribute__((packed));
45-
tU64 pad59 : 1 __attribute__((packed));
46-
tU64 DIMX33 : 3 __attribute__((packed));
47-
tU64 pad63 : 1 __attribute__((packed));
16+
tU64 DIMX00 : 3;
17+
tU64 pad03 : 1;
18+
tU64 DIMX01 : 3;
19+
tU64 pad07 : 1;
20+
tU64 DIMX02 : 3;
21+
tU64 pad11 : 1;
22+
tU64 DIMX03 : 3;
23+
tU64 pad15 : 1;
24+
tU64 DIMX10 : 3;
25+
tU64 pad19 : 1;
26+
tU64 DIMX11 : 3;
27+
tU64 pad23 : 1;
28+
tU64 DIMX12 : 3;
29+
tU64 pad27 : 1;
30+
tU64 DIMX13 : 3;
31+
tU64 pad31 : 1;
32+
tU64 DIMX20 : 3;
33+
tU64 pad35 : 1;
34+
tU64 DIMX21 : 3;
35+
tU64 pad39 : 1;
36+
tU64 DIMX22 : 3;
37+
tU64 pad43 : 1;
38+
tU64 DIMX23 : 3;
39+
tU64 pad47 : 1;
40+
tU64 DIMX30 : 3;
41+
tU64 pad51 : 1;
42+
tU64 DIMX31 : 3;
43+
tU64 pad55 : 1;
44+
tU64 DIMX32 : 3;
45+
tU64 pad59 : 1;
46+
tU64 DIMX33 : 3;
47+
tU64 pad63 : 1;
4848
} __attribute__((packed)) tDimx ;
4949

5050
typedef GS_ALPHA tAlpha;

include/ps2s/imagepackets.h

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,33 @@ class CImageUploadPkt : protected CVifSCDmaPacket {
7070
void Send(CSCDmaPacket& packet);
7171
void Send(CVifSCDmaPacket& packet);
7272

73-
inline void* operator new(size_t size)
74-
{
75-
return Core::New16(size);
76-
}
73+
inline void* operator new(size_t size) { return Core::New16(size); }
74+
inline void operator delete(void* p) { Core::Delete16(p); }
7775

7876
protected:
7977
private:
8078
// gs packet to setup the texture image transfer
81-
tU128 FirstDmaTag;
82-
tGifTag ImageXferSettingsGifTag;
83-
GS::tBitbltbuf gsrBitBltBuf;
84-
tU64 BitBltBufAddr;
85-
GS::tTrxpos gsrTrxPos;
86-
tU64 TrxPosAddr;
87-
GS::tTrxreg gsrTrxReg;
88-
tU64 TrxRegAddr;
89-
GS::tTrxdir gsrTrxDir;
90-
tU64 TrxDirAddr;
91-
tU128 RestOfPacket[15];
79+
struct {
80+
// DMA tag + GIF tag + 4 register settings (+ 15 rest ?)
81+
tU128 FirstDmaTag;
82+
tGifTag ImageXferSettingsGifTag;
83+
GS::tBitbltbuf gsrBitBltBuf;
84+
tU64 BitBltBufAddr;
85+
GS::tTrxpos gsrTrxPos;
86+
tU64 TrxPosAddr;
87+
GS::tTrxreg gsrTrxReg;
88+
tU64 TrxRegAddr;
89+
GS::tTrxdir gsrTrxDir;
90+
tU64 TrxDirAddr;
91+
tU128 RestOfPacket[15];
92+
} __attribute__((packed,aligned(16)));
9293

9394
tU32 uiNumXferGSRegs;
9495
tU128* pImage;
9596

9697
void InitCommon(void);
9798
void BuildXferTags(void);
98-
} __attribute__((aligned(16)));
99+
};
99100

100101
/********************************************
101102
* CClutUploadPkt
@@ -135,10 +136,8 @@ class CClutUploadPkt : protected CImageUploadPkt {
135136
inline void Send(CSCDmaPacket& packet) { CImageUploadPkt::Send(packet); }
136137
inline void Send(CVifSCDmaPacket& packet) { CImageUploadPkt::Send(packet); }
137138

138-
inline void* operator new(size_t size)
139-
{
140-
return Core::New16(size);
141-
}
139+
inline void* operator new(size_t size) { return Core::New16(size); }
140+
inline void operator delete(void* p) { Core::Delete16(p); }
142141
};
143142

144143
#endif // ps2s_imagepackets_h

include/ps2s/sprite.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,23 +82,24 @@ class CSprite {
8282

8383
CDmaPacket& GetPacket(void) { return GifPacket; }
8484

85-
inline void* operator new(size_t size)
86-
{
87-
return Core::New16(size);
88-
}
85+
inline void* operator new(size_t size) { return Core::New16(size); }
86+
inline void operator delete(void* p) { Core::Delete16(p); }
8987

9088
protected:
9189
private:
92-
tGifTag DrawGifTag;
93-
tU32 Color[4];
94-
tTexCoords TexCoords1;
95-
tU32 Vertex1[4];
96-
tTexCoords TexCoords2;
97-
tU32 Vertex2[4];
90+
struct {
91+
// GIF tag + 5 qwords data
92+
tGifTag DrawGifTag;
93+
tU32 Color[4];
94+
tTexCoords TexCoords1;
95+
tU32 Vertex1[4];
96+
tTexCoords TexCoords2;
97+
tU32 Vertex2[4];
98+
} __attribute__((packed,aligned(16)));
9899

99100
CDmaPacket GifPacket;
100101

101-
} __attribute__((aligned(16)));
102+
};
102103

103104
/********************************************
104105
* inline methods

include/ps2s/texture.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,26 @@ class CTexEnv {
120120
CTexEnv(const CTexEnv& rhs);
121121
CTexEnv& operator=(const CTexEnv& rhs);
122122

123-
inline void* operator new(size_t size)
124-
{
125-
return Core::New16(size);
126-
}
123+
inline void* operator new(size_t size) { return Core::New16(size); }
124+
inline void operator delete(void* p) { Core::Delete16(p); }
127125

128126
protected:
129127
// gs packet to setup texture environment
130-
tSourceChainTag SettingsDmaTag;
131-
tGifTag SettingsGifTag;
132-
GS::tTexflush gsrTexflush;
133-
tU64 TexflushAddr;
134-
GS::tClamp gsrClamp;
135-
tU64 ClampAddr;
136-
GS::tTex1 gsrTex1;
137-
tU64 Tex1Addr;
138-
GS::tTex0 gsrTex0;
139-
tU64 Tex0Addr;
140-
GS::tTexa gsrTexA;
141-
tU64 TexAAddr;
128+
struct {
129+
// DMA tag + GIF tag + 5 register settings
130+
tSourceChainTag SettingsDmaTag;
131+
tGifTag SettingsGifTag;
132+
GS::tTexflush gsrTexflush;
133+
tU64 TexflushAddr;
134+
GS::tClamp gsrClamp;
135+
tU64 ClampAddr;
136+
GS::tTex1 gsrTex1;
137+
tU64 Tex1Addr;
138+
GS::tTex0 gsrTex0;
139+
tU64 Tex0Addr;
140+
GS::tTexa gsrTexA;
141+
tU64 TexAAddr;
142+
} __attribute__((packed,aligned(16)));
142143

143144
tU32 uiNumSettingsGSRegs;
144145
tU32 uiTexPixelWidth, uiTexPixelHeight;
@@ -148,7 +149,7 @@ class CTexEnv {
148149
private:
149150
void InitCommon(GS::tContext context);
150151

151-
} __attribute__((aligned(16)));
152+
};
152153

153154
/********************************************
154155
* CTexture
@@ -203,7 +204,7 @@ class CTexture : public CTexEnv {
203204

204205
void InitCommon(GS::tContext context);
205206

206-
} __attribute__((aligned(16)));
207+
};
207208

208209
/********************************************
209210
* CClut

src/gs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ typedef struct {
1717
tGifTag gt;
1818
tU64 texFlush;
1919
tU64 texFlushAddr;
20-
} tFlushPkt;
21-
static tFlushPkt FlushPkt __attribute__((aligned(16)));
20+
} __attribute__((packed,aligned(16))) tFlushPkt;
21+
static tFlushPkt FlushPkt;
2222

2323
/********************************************
2424
* functions

0 commit comments

Comments
 (0)