From 174a079dbd6aa02af81c81d34d3e997d250db931 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Thu, 20 May 2021 13:53:19 -0400 Subject: [PATCH] decomp: Decompile `stats-h` (#504) * decomp: Decompile `stats-h` * linting --- decompiler/config/all-types.gc | 10 +- .../config/jak1_ntsc_black_label/hacks.jsonc | 7 +- goal_src/engine/debug/stats-h.gc | 91 +++++++++++ .../reference/all_forward_declarations.gc | 9 ++ .../reference/engine/debug/stats-h_REF.gc | 146 ++++++++++++++++++ test/offline/offline_test_main.cpp | 2 + 6 files changed, 259 insertions(+), 6 deletions(-) create mode 100644 test/decompiler/reference/engine/debug/stats-h_REF.gc diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index ab5c799add..ed83867d1b 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -10587,11 +10587,11 @@ :size-assert #x34 :flag-assert #xe00000034 (:methods - (dummy-9 () none 9) - (dummy-10 () none 10) - (dummy-11 () none 11) - (dummy-12 () none 12) - (dummy-13 () none 13) + (dummy-9 (_type_) none 9) + (dummy-10 (_type_) none 10) + (PERF-COUNTER-REG-ACCESS-11 (_type_) none 11) + (PERF-COUNTER-REG-ACCESS-12 (_type_) none 12) + (update-wait-stats-13 (_type_ uint uint uint) none 13) ) ) diff --git a/decompiler/config/jak1_ntsc_black_label/hacks.jsonc b/decompiler/config/jak1_ntsc_black_label/hacks.jsonc index 0fd937d80e..36055ba623 100644 --- a/decompiler/config/jak1_ntsc_black_label/hacks.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/hacks.jsonc @@ -425,7 +425,12 @@ // (these are NOT actually asm functions) "(method 15 sync-info)", // NEED *res-static-buf* "(method 15 sync-info-eased)", // NEED *res-static-buf* - "(method 15 sync-info-paused)" // NEED *res-static-buf* + "(method 15 sync-info-paused)", // NEED *res-static-buf* + + // stats-h + // May or may not be inline-asm but they are related to perf counter registers that only live on the PS2 + "(method 11 perf-stat)", + "(method 12 perf-stat)" ], "pair_functions_by_name": [ diff --git a/goal_src/engine/debug/stats-h.gc b/goal_src/engine/debug/stats-h.gc index a8de7897c7..86eb9b5a14 100644 --- a/goal_src/engine/debug/stats-h.gc +++ b/goal_src/engine/debug/stats-h.gc @@ -5,3 +5,94 @@ ;; name in dgo: stats-h ;; dgos: GAME, ENGINE +;; definition of type tr-stat +(deftype tr-stat (structure) + ((groups uint16 :offset-assert 0) + (fragments uint16 :offset-assert 2) + (tris uint32 :offset-assert 4) + (dverts uint32 :offset-assert 8) + (instances uint16 :offset-assert 12) + (pad uint16 :offset-assert 14) + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +;; definition of type merc-global-stats +(deftype merc-global-stats (structure) + ((merc tr-stat :inline :offset-assert 0) + (mercneric tr-stat :inline :offset-assert 16) + ) + :method-count-assert 9 + :size-assert #x20 + :flag-assert #x900000020 + ) + +;; definition of type perf-stat +(deftype perf-stat (structure) + ((frame-number uint32 :offset-assert 0) + (count uint32 :offset-assert 4) + (cycles uint32 :offset-assert 8) + (instructions uint32 :offset-assert 12) + (icache uint32 :offset-assert 16) + (dcache uint32 :offset-assert 20) + (select uint32 :offset-assert 24) + (ctrl uint32 :offset-assert 28) + (accum0 uint32 :offset-assert 32) + (accum1 uint32 :offset-assert 36) + (to-vu0-waits uint32 :offset-assert 40) + (to-spr-waits uint32 :offset-assert 44) + (from-spr-waits uint32 :offset-assert 48) + ) + :method-count-assert 14 + :size-assert #x34 + :flag-assert #xe00000034 + (:methods + (dummy-9 (_type_) none 9) + (dummy-10 (_type_) none 10) + (PERF-COUNTER-REG-ACCESS-11 (_type_) none 11) + (PERF-COUNTER-REG-ACCESS-12 (_type_) none 12) + (update-wait-stats-13 (_type_ uint uint uint) none 13) + ) + ) + +;; definition of type perf-stat-array +(deftype perf-stat-array (inline-array-class) + () + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +;; failed to figure out what this is: +(set! (-> perf-stat-array heap-base) (the-as uint 52)) + +;; definition for method 11 of type perf-stat +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for method 12 of type perf-stat +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for method 13 of type perf-stat +;; INFO: Return type mismatch int vs none. +(defmethod + update-wait-stats-13 + perf-stat + ((obj perf-stat) (arg0 uint) (arg1 uint) (arg2 uint)) + (when (nonzero? (-> obj ctrl)) + (set! (-> obj to-vu0-waits) (+ (-> obj to-vu0-waits) arg0)) + (set! (-> obj to-spr-waits) (+ (-> obj to-spr-waits) arg1)) + (set! (-> obj from-spr-waits) (+ (-> obj from-spr-waits) arg2)) + ) + (let ((v0-0 0)) + ) + (none) + ) + +;; failed to figure out what this is: +(when (not *debug-segment*) + (set! (-> perf-stat method-table 11) nothing) + (set! (-> perf-stat method-table 12) nothing) + (set! (-> perf-stat method-table 13) nothing) + ) diff --git a/test/decompiler/reference/all_forward_declarations.gc b/test/decompiler/reference/all_forward_declarations.gc index 17ee2a8ff1..05d445d80c 100644 --- a/test/decompiler/reference/all_forward_declarations.gc +++ b/test/decompiler/reference/all_forward_declarations.gc @@ -649,4 +649,13 @@ ;; TODO - for trajectory.gc (declare-type trajectory structure) +(deftype rgba (uint32) + ((r uint8 :offset 0) + (g uint8 :offset 8) + (b uint8 :offset 16) + (a uint8 :offset 24) + ) + :flag-assert #x900000004 + ) (define-extern add-debug-line (function symbol int vector vector rgba symbol int int)) + diff --git a/test/decompiler/reference/engine/debug/stats-h_REF.gc b/test/decompiler/reference/engine/debug/stats-h_REF.gc new file mode 100644 index 0000000000..b3616f0a86 --- /dev/null +++ b/test/decompiler/reference/engine/debug/stats-h_REF.gc @@ -0,0 +1,146 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type tr-stat +(deftype tr-stat (structure) + ((groups uint16 :offset-assert 0) + (fragments uint16 :offset-assert 2) + (tris uint32 :offset-assert 4) + (dverts uint32 :offset-assert 8) + (instances uint16 :offset-assert 12) + (pad uint16 :offset-assert 14) + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +;; definition for method 3 of type tr-stat +(defmethod inspect tr-stat ((obj tr-stat)) + (format #t "[~8x] ~A~%" obj 'tr-stat) + (format #t "~Tgroups: ~D~%" (-> obj groups)) + (format #t "~Tfragments: ~D~%" (-> obj fragments)) + (format #t "~Ttris: ~D~%" (-> obj tris)) + (format #t "~Tdverts: ~D~%" (-> obj dverts)) + (format #t "~Tinstances: ~D~%" (-> obj instances)) + (format #t "~Tpad: ~D~%" (-> obj pad)) + obj + ) + +;; definition of type merc-global-stats +(deftype merc-global-stats (structure) + ((merc tr-stat :inline :offset-assert 0) + (mercneric tr-stat :inline :offset-assert 16) + ) + :method-count-assert 9 + :size-assert #x20 + :flag-assert #x900000020 + ) + +;; definition for method 3 of type merc-global-stats +(defmethod inspect merc-global-stats ((obj merc-global-stats)) + (format #t "[~8x] ~A~%" obj 'merc-global-stats) + (format #t "~Tmerc: #~%" (-> obj merc)) + (format #t "~Tmercneric: #~%" (-> obj mercneric)) + obj + ) + +;; definition of type perf-stat +(deftype perf-stat (structure) + ((frame-number uint32 :offset-assert 0) + (count uint32 :offset-assert 4) + (cycles uint32 :offset-assert 8) + (instructions uint32 :offset-assert 12) + (icache uint32 :offset-assert 16) + (dcache uint32 :offset-assert 20) + (select uint32 :offset-assert 24) + (ctrl uint32 :offset-assert 28) + (accum0 uint32 :offset-assert 32) + (accum1 uint32 :offset-assert 36) + (to-vu0-waits uint32 :offset-assert 40) + (to-spr-waits uint32 :offset-assert 44) + (from-spr-waits uint32 :offset-assert 48) + ) + :method-count-assert 14 + :size-assert #x34 + :flag-assert #xe00000034 + (:methods + (dummy-9 (_type_) none 9) + (dummy-10 (_type_) none 10) + (PERF-COUNTER-REG-ACCESS-11 (_type_) none 11) + (PERF-COUNTER-REG-ACCESS-12 (_type_) none 12) + (update-wait-stats-13 (_type_ uint uint uint) none 13) + ) + ) + +;; definition for method 3 of type perf-stat +(defmethod inspect perf-stat ((obj perf-stat)) + (format #t "[~8x] ~A~%" obj 'perf-stat) + (format #t "~Tframe-number: ~D~%" (-> obj frame-number)) + (format #t "~Tcount: ~D~%" (-> obj count)) + (format #t "~Tcycles: ~D~%" (-> obj cycles)) + (format #t "~Tinstructions: ~D~%" (-> obj instructions)) + (format #t "~Ticache: ~D~%" (-> obj icache)) + (format #t "~Tdcache: ~D~%" (-> obj dcache)) + (format #t "~Tselect: ~D~%" (-> obj select)) + (format #t "~Tctrl: ~D~%" (-> obj ctrl)) + (format #t "~Taccum0: ~D~%" (-> obj accum0)) + (format #t "~Taccum1: ~D~%" (-> obj accum1)) + (format #t "~Tto-vu0-waits: ~D~%" (-> obj to-vu0-waits)) + (format #t "~Tto-spr-waits: ~D~%" (-> obj to-spr-waits)) + (format #t "~Tfrom-spr-waits: ~D~%" (-> obj from-spr-waits)) + obj + ) + +;; definition of type perf-stat-array +(deftype perf-stat-array (inline-array-class) + () + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +;; definition for method 3 of type perf-stat-array +(defmethod inspect perf-stat-array ((obj perf-stat-array)) + (format #t "[~8x] ~A~%" obj (-> obj type)) + (format #t "~Tlength: ~D~%" (-> obj length)) + (format #t "~Tallocated-length: ~D~%" (-> obj allocated-length)) + (format #t "~Tdata[0] @ #x~X~%" (&-> obj data 4)) + obj + ) + +;; failed to figure out what this is: +(set! (-> perf-stat-array heap-base) (the-as uint 52)) + +;; definition for method 11 of type perf-stat +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for method 12 of type perf-stat +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition for method 13 of type perf-stat +;; INFO: Return type mismatch int vs none. +(defmethod + update-wait-stats-13 + perf-stat + ((obj perf-stat) (arg0 uint) (arg1 uint) (arg2 uint)) + (when (nonzero? (-> obj ctrl)) + (set! (-> obj to-vu0-waits) (+ (-> obj to-vu0-waits) arg0)) + (set! (-> obj to-spr-waits) (+ (-> obj to-spr-waits) arg1)) + (set! (-> obj from-spr-waits) (+ (-> obj from-spr-waits) arg2)) + ) + (let ((v0-0 0)) + ) + (none) + ) + +;; failed to figure out what this is: +(when (not *debug-segment*) + (set! (-> perf-stat method-table 11) nothing) + (set! (-> perf-stat method-table 12) nothing) + (set! (-> perf-stat method-table 13) nothing) + ) + + + + diff --git a/test/offline/offline_test_main.cpp b/test/offline/offline_test_main.cpp index 3718d52740..ef4f824902 100644 --- a/test/offline/offline_test_main.cpp +++ b/test/offline/offline_test_main.cpp @@ -60,6 +60,8 @@ const std::unordered_set g_functions_expected_to_reject = { // display "vblank-handler", // asm "vif1-handler", "vif1-handler-debug", + // stats-h + "(method 11 perf-stat)", "(method 12 perf-stat)", // sync-info "(method 15 sync-info)", // needs *res-static-buf*