extern uint16_t ramsize;
extern uint16_t procmem;
extern uint16_t nproc; /* Current number of processes */
-extern uint16_t nready; /* Number of ready processes */
+extern uint8_t nready; /* Number of ready processes */
extern inoptr root; /* Address of root dir in inode table */
extern uint16_t root_dev; /* Device number of root filesystem. */
p_tab *init_process;
unsigned char *cmdline = (unsigned char *) CMDLINE;
-uint16_t ramsize, procmem, maxproc, nproc, nready;
+uint16_t ramsize, procmem, maxproc, nproc;
+uint8_t nready;
uint16_t runticks;
bool inint;
uint16_t root_dev;
.globl interrupt_handler
.globl _swapper
.globl _need_resched
+ .globl _nready
+ .globl _platform_idle
.globl map_kernel
.globl map_process
push iy
ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld a, (_nready)
+ or a
+ jr nz, slow_path
+
+idling:
+ ei
+ call _platform_idle
+ di
+ ld a, (_nready)
+ or a
+ jr z, idling
+ cp #1
+ jr nz, slow_path
+ ld hl, (U_DATA__U_PTAB)
+ ld a, (hl) ; Process table status is first byte
+ ; Are we the one process ?
+ cp #P_READY
+ jr nz, slow_path
+ ; We are - fast path return from switchout
+ ld (hl), #P_RUNNING
+ pop iy
+ pop ix
+ pop hl
+ ei
+ ret
+
+slow_path:
; Stash the uarea back into process memory
call map_process_always
ld hl, #U_DATA
.globl map_process_a
.globl map_process_always
.globl copybank
+ .globl _nready
+ .globl _platform_idle
# exported
.globl _switchout
pshs d,y,u
sts U_DATA__U_SP ; this is where the SP is restored in _switchin
+ ; See if we are about to go idle
+ lda _nready
+ ; Someone else will run - go the slow path into the scheduler
+; bne slow_path
+ bra slow_path
+
+ ;
+ ; Wait for something to become ready
+ ;
+idling:
+ andcc #0xef
+ jsr _platform_idle
+ orcc #0x10
+
+ lda _nready
+ beq idling
+
+ ; Did multiple things wake up, if so we must follow the slow
+ ; path
+ cmpa #1
+ bne slow_path
+
+ ; Was the waker us ?
+ ldx U_DATA + U_DATA__U_PTAB
+ lda P_TAB__P_STATUS_OFFSET,x
+ cmpa #P_READY
+ ; No: follow the slow path
+ bne slow_path
+
+ ; We can use the fast path for returning.
+ ;
+ ; Mark ourself running with a new time slice allocation
+ ;
+ lda #P_RUNNING
+ sta P_TAB__P_STATUS_OFFSET,x
+ ldx #0
+ stx _runticks
+ ;
+ ; We idled and got the CPU back - fast path, and we know
+ ; we are not a pre-emption. In effect the switchout() becomes
+ ; a normal function call and we don't have to stash anything or
+ ; bank switch.
+ ;
+ andcc #0xef
+ puls x,y,u,pc
+
+
+slow_path:
; Stash the uarea into process memory bank
jsr map_process_always