From 39103cc8a3737f253b267a5020f809a11d414b1a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 2 Apr 2021 22:17:32 +0900 Subject: [PATCH] [sw] Fix some 32-bit assembly issues I'm not sure that the mismatch between refdef_t and the assembly defines was a problem (many fields unused), but the main problem was due to execute permission on the pages: one chunk of asm was in the data section, and the patched code was not marked as being executable (due to such a thing not existing when quake was written). --- include/QF/render.h | 4 ++-- include/asm_draw.h | 26 ++++++++++++++------------ include/d_local.h | 3 +-- include/r_local.h | 3 +-- include/r_shared.h | 6 ++---- libs/util/sys.c | 2 +- libs/video/renderer/sw/sw_rvarsa.S | 1 + 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/include/QF/render.h b/include/QF/render.h index adc5e141e..3b86c9038 100644 --- a/include/QF/render.h +++ b/include/QF/render.h @@ -161,9 +161,9 @@ typedef struct { vec4f_t viewposition; vec4f_t viewrotation; - float fov_x, fov_y; - int ambientlight; + + float fov_x, fov_y; } refdef_t; // color shifts ============================================================= diff --git a/include/asm_draw.h b/include/asm_draw.h index ec6d99283..1e2ae1da4 100644 --- a/include/asm_draw.h +++ b/include/asm_draw.h @@ -42,14 +42,14 @@ #define espan_t_v 4 #define espan_t_count 8 #define espan_t_pnext 12 -#define espan_t_size 16 +#define espan_t_size 16 // sizeof(espan_t) // sspan_t structure // !!! if this is changed, it must be changed in d_local.h too !!! #define sspan_t_u 0 #define sspan_t_v 4 #define sspan_t_count 8 -#define sspan_t_size 12 +#define sspan_t_size 12 // sizeof(sspan_t) // spanpackage_t structure // !!! if this is changed, it must be changed in d_polyset.c too !!! @@ -61,7 +61,7 @@ #define spanpackage_t_tfrac 20 #define spanpackage_t_light 24 #define spanpackage_t_zi 28 -#define spanpackage_t_size 32 +#define spanpackage_t_size 32 // sizeof(spanpackage_t) // edge_t structure // !!! if this is changed, it must be changed in r_shared.h too !!! @@ -73,7 +73,7 @@ #define et_nextremove 20 #define et_nearzi 24 #define et_owner 28 -#define et_size 32 +#define et_size 32 // sizeof(edge_t) // surf_t structure // !!! if this is changed, it must be changed in r_shared.h too !!! @@ -93,7 +93,7 @@ #define st_d_zistepu 48 #define st_d_zistepv 52 #define st_pad 56 -#define st_size 64 +#define st_size 64 // sizeof (surf_t) // clipplane_t structure // !!! if this is changed, it must be changed in r_local.h too !!! @@ -103,18 +103,18 @@ #define cp_leftedge 20 #define cp_rightedge 21 #define cp_reserved 22 -#define cp_size 24 +#define cp_size 24 // sizeof (clipplane_t) // medge_t structure // !!! if this is changed, it must be changed in model.h too !!! #define me_v 0 #define me_cachededgeoffset 8 -#define me_size 12 +#define me_size 12 // sizeof (medge_t) // mvertex_t structure // !!! if this is changed, it must be changed in model.h too !!! #define mv_position 0 -#define mv_size 12 +#define mv_size 12 // sizeof (mvertex_t) // refdef_t structure // !!! if this is changed, it must be changed in render.h too !!! @@ -138,10 +138,12 @@ #define rd_horizontalFieldOfView 100 #define rd_xOrigin 104 #define rd_yOrigin 108 -#define rd_vieworg 112 -#define rd_viewangles 124 -#define rd_ambientlight 136 -#define rd_size 140 +#define rd_viewposition 112 +#define rd_viewrotation 128 +#define rd_ambientlight 144 +#defin rd_fov_x 148 +#defin rd_fov_y 152 +#define rd_size 156 // sizeof (refdef_t) // mtriangle_t structure // !!! if this is changed, it must be changed in model.h too !!! diff --git a/include/d_local.h b/include/d_local.h index 7143277b1..f67dcea74 100644 --- a/include/d_local.h +++ b/include/d_local.h @@ -59,8 +59,7 @@ typedef struct surfcache_s } surfcache_t; // !!! if this is changed, it must be changed in asm_draw.h too !!! -typedef struct sspan_s -{ +typedef struct sspan_s { int u, v, count; } sspan_t; diff --git a/include/r_local.h b/include/r_local.h index 37d5308c1..ba8063561 100644 --- a/include/r_local.h +++ b/include/r_local.h @@ -98,8 +98,7 @@ extern float cl_wateralpha; #define DIST_NOT_SET 98765 // !!! if this is changed, it must be changed in asm_draw.h too !!! -typedef struct clipplane_s -{ +typedef struct clipplane_s { vec3_t normal; float dist; struct clipplane_s *next; diff --git a/include/r_shared.h b/include/r_shared.h index 521024d68..b39e387f8 100644 --- a/include/r_shared.h +++ b/include/r_shared.h @@ -81,16 +81,14 @@ extern struct entity_s *currententity; #define MAXSPANS 3000 // !!! if this is changed, it must be changed in asm_draw.h too !!! -typedef struct espan_s -{ +typedef struct espan_s { int u, v, count; struct espan_s *pnext; } espan_t; // FIXME: compress, make a union if that will help // insubmodel is only 1, flags is fewer than 32, spanstate could be a byte -typedef struct surf_s -{ +typedef struct surf_s { struct surf_s *next; // active surface stack in r_edge.c struct surf_s *prev; // used in r_edge.c for active surf stack struct espan_s *spans; // pointer to linked list of spans to draw diff --git a/libs/util/sys.c b/libs/util/sys.c index cada787f2..8758f270a 100644 --- a/libs/util/sys.c +++ b/libs/util/sys.c @@ -437,7 +437,7 @@ Sys_MakeCodeWriteable (uintptr_t startaddr, size_t length) DWORD flOldProtect; if (!VirtualProtect - ((LPVOID) startaddr, length, PAGE_READWRITE, &flOldProtect)) + ((LPVOID) startaddr, length, PAGE_EXECUTE_READWRITE, &flOldProtect)) Sys_Error ("Protection change failed"); #else # ifdef HAVE_MPROTECT diff --git a/libs/video/renderer/sw/sw_rvarsa.S b/libs/video/renderer/sw/sw_rvarsa.S index c53d26cf1..be32f8918 100644 --- a/libs/video/renderer/sw/sw_rvarsa.S +++ b/libs/video/renderer/sw/sw_rvarsa.S @@ -76,6 +76,7 @@ C(r_single_cw): .long 0 .globl C(r_bmodelactive) C(r_bmodelactive): .long 0 + .text .global C(R_InitVars) C(R_InitVars): movl C(ceil_cw), %eax