Files
jak-project/goal_src/jak1/kernel/pskernel.gc
Tyler Wilding c162c66118 g/j1: Cleanup all main issues in the formatter and format all of goal_src/jak1 (#3535)
This PR does two main things:
1. Work through the main low-hanging fruit issues in the formatter
keeping it from feeling mature and usable
2. Iterate and prove that point by formatting all of the Jak 1 code
base. **This has removed around 100K lines in total.**
- The decompiler will now format it's results for jak 1 to keep things
from drifting back to where they were. This is controlled by a new
config flag `format_code`.

How am I confident this hasn't broken anything?:
- I compiled the entire project and stored it's `out/jak1/obj` files
separately
- I then recompiled the project after formatting and wrote a script that
md5's each file and compares it (`compare-compilation-outputs.py`
- The results (eventually) were the same:

![Screenshot 2024-05-25
132900](https://github.com/open-goal/jak-project/assets/13153231/015e6f20-8d19-49b7-9951-97fa88ddc6c2)
> This proves that the only difference before and after is non-critical
whitespace for all code/macros that is actually in use.

I'm still aware of improvements that could be made to the formatter, as
well as general optimization of it's performance. But in general these
are for rare or non-critical situations in my opinion and I'll work
through them before doing Jak 2. The vast majority looks great and is
working properly at this point. Those known issues are the following if
you are curious:

![image](https://github.com/open-goal/jak-project/assets/13153231/0edfaba1-6d36-40f5-ab23-0642209867c4)
2024-06-05 22:17:31 -04:00

109 lines
3.7 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "KERNEL.CGO")
(require "kernel/gcommon.gc")
#|
pskernel.gc contains a bunch of utilities for poking around the PS2's kernel.
These are unused in the retail game, and wouldn't be "safe" to use on a retail console,
as later console revisions may have different memory layout of the BIOS. I suspect this
was used for the purposes of debugging and handling crashes.
They took over syscall 102 to access memory inside the kernel.
There's an error message:
"I CANNOT CONTINUE TO LOAD GOAL, BECAUSE THE KERNEL VERSION HAS CHANGED~%"
"~%Alternatively, try removing pskernel.gc and debug-handlers.gc from project.cl, do an (lg) and then (:r) again~%"
My theory is that debug-handlers.gc held crash handlers, and on load would install them using functions defined in pskernel.gc.
In the retail game, they removed debug-handlers, but not pskernel.
In the PC port, all of these functions are just stubs.
|#
;; map of the kernel's memory.
(deftype lowmemmap (structure)
((irq-info-stack uint32)
(irq2-info-stack uint32)
(kernel-copy-fn uint32)
(kernel-write-fn uint32)
(r1-save uint128)
(last-time uint32)
(high-time uint32)
(dma-status uint32)
(dma-qnext uint32)
(dma-qwc uint32)
(dma-tnext uint32)
(dma-stack0 uint32)
(dma-stack1 uint32)
(kernel-read-fn uint32)))
(defmacro nyi-break (name)
`(begin
(format 0 "~A is not implemented!~%" (quote ,name))
(break)
(none)))
(defun kernel-copy-function (unused source dest size)
"Copy size words from source to dest. The a0 argument is ignored.
Uses registers a0, a1, a2, a3"
(nyi-break kernel-copy-function))
(defun kernel-copy-to-kernel-ram ()
"Does a syscall 102. This is CpuConfig on released PS2 BIOSes.
I'm guessing this somehow calls kernel-copy-function"
(nyi-break kernel-copy-to-kernel-ram))
(defun kernel-write-function (unused source dest)
"Writes a single word to the destination"
(nyi-break kernel-write-function))
(defun kernel-write ()
"Does a syscall 102. I'm guessing this somehow calls kernel-write-function."
(nyi-break kernel-write))
(defun kernel-read-function (unused source)
"Read a single word (signed) from source"
(nyi-break kernel-read-function))
(defun kernel-read ()
"Does a syscall 102. I'm guessing this somehow calls kernel-read-function"
(nyi-break kernel-read))
(defun kernel-check-hardwired-addresses ()
"Checks a bunch of stuff in the kernel using kernel-read.
If the memory layout isn't what it expects, it prints an error and crashes."
(nyi-break kernel-check-hardwired-addresses))
(defun install-default-debug-handler (handler)
"Installs the given handler as the debug handler 1 through 13.
Uses the install-debug-handler function defined in kmachine.cpp"
(nyi-break install-default-debug-handler))
(defun return-from-exception (regs)
"Restore the registers and eret."
(nyi-break return-from-exception))
(defun kernel-set-exception-vector ()
"Use syscall 13/syscall 14 to set exception handlers"
(nyi-break kernel-set-exception-vector))
(defun kernel-set-interrupt-vector ()
"Use syscall 15 to set an interrupt handler"
(nyi-break kernel-set-interrupt-vector))
(defun kernel-set-level2-vector ()
"Set some handler by writing directly to kernel memory. Not sure what this is."
(nyi-break kernel-set-level2-vector))
(defun deinstall-debug-handler ()
"Set the kernel exception handler back to the default?"
(nyi-break deinstall-debug-handler))
(defun deinstall-debug-handlers ()
"Set a bunch of excpetion handlers back to the default?"
(nyi-break deinstall-debug-handlers))
(defun resend-exception ()
"I think this was to return from a GOAL crash handler back to the EE kernel's crash handler."
(nyi-break resend-exception))