Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; kernelGate handler
- kernelGateEntryMarker:
- .db 0
- kernelGateOldSP:
- .ds 2
- kernelGateAsm:
- ;; Parameter passing
- ;; L: Module ID
- ;; H: Function ID
- ;; BC: par1 (user integer)
- ;; DE: ptr1 (user pointer)
- DI
- ;; Do not push HL since it's the return value.
- ;; Everything else is pushed.
- PUSH AF
- PUSH BC
- PUSH DE
- PUSH IX
- PUSH IY
- ;; Check whether we already entered the kernel.
- ;; If we didn't, save the old SP and set SP to the kernel stack.
- LD A,(#kernelGateEntryMarker)
- CP A,#0
- JP NZ,kernelGateAlreadyEntered
- PUSH HL
- LD HL,#0
- ADD HL,SP
- LD (#kernelGateOldSP),HL
- POP HL
- LD SP,#stackSpaceEnd-1
- kernelGateAlreadyEntered:
- ;; Store the old value of kernelGateEntryMarker on the stack
- ;; and set kernelGateEntryMarker to 1, so that calls to
- ;; kernelGate from within kernelmode do not switch stack again.
- PUSH AF
- LD A,#1
- LD (#kernelGateEntryMarker),A
- ;; Push the parameters onto the stack and call the dispatcher.
- ;; Rightmost parameter: User pointer
- PUSH DE
- ;; Next parameter: User int
- PUSH BC
- ;; First parameters: Module ID (L) & function ID (H)
- PUSH HL
- CALL _kernelGateDispatcher
- POP DE
- POP DE
- POP DE
- ;; Restore the old value of kernelGateEntryMarker
- POP AF
- LD (#kernelGateEntryMarker),A
- ;; If we were outside of kernelmode before we entered this instance
- ;; of kernelGate, restore SP and re-activate interrupts.
- CP A,#0
- JP NZ,kernelGateStillActive
- EX DE,HL
- LD HL,(#kernelGateOldSP)
- LD SP,HL
- EX DE,HL
- EI
- kernelGateStillActive:
- POP IY
- POP IX
- POP DE
- POP BC
- POP AF
- RET
Advertisement
Add Comment
Please, Sign In to add comment