.globl _irqvector
.globl _need_resched
.globl _int_disabled
+ .globl _udata
; imported symbols
.globl _ramsize
.include "kernel.def"
.include "../cpu-z180/z180.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; Initialisation code
; CPU stalled until DMA completes
; Copy common memory code from kernel bank (from end of U_DATA to end of memory)
- ld de, #(0x10000 - U_DATA__TOTALSIZE - U_DATA) ; copy to end of memory
+ ; ld de, #(0x10000 - U_DATA__TOTALSIZE - _udata) ; copy to end of memory
+ ; Only the linker isn't smart enough....
+ or a
+ push hl
+ ld hl,#0
+ ld de,#_udata + U_DATA__TOTALSIZE
+ sbc hl,de
+ ex de,hl
+ pop hl
out0 (DMA_BCR0H), d ; set byte count
out0 (DMA_BCR0L), e
- ld de, #(U_DATA+U_DATA__TOTALSIZE)
+ ld de, #(_udata + U_DATA__TOTALSIZE)
ld a, #((OS_BANK + FIRST_RAM_BANK) >> 4) ; source bank -- kernel is always 64K aligned
out0 (DMA_SAR0B), a
out0 (DMA_SAR0H), d ; source is kernel, always 64K aligned
out0 (DMA_SAR0L), a
out0 (DMA_SAR0H), l
out0 (DMA_SAR0B), h
- ld de, #(U_DATA + U_DATA__TOTALSIZE - 0x100) ; byte count
+ ld de, #(_udata + U_DATA__TOTALSIZE - 0x100) ; byte count
out0 (DMA_BCR0H), d ; set byte count
out0 (DMA_BCR0L), e
; call dump_dma_state
; _switchin which will immediately return (appearing to be _dofork()
; returning) and with HL (ie return code) containing the child PID.
; Hooray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; now we're in a safe state for _switchin to return in the parent
; process.
push hl ; return code
push ix
push iy
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
; no need to stash udata on this platform since common memory is dedicated
; to each process.
out0 (MMU_CBR), a
; sanity check: u_data->u_ptab matches what we wanted?
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
or a ; clear carry flag
sbc hl, de ; subtract, result will be zero if DE==IX
jr nz, switchinfail
; wants optimising up a bit
- ld ix, (U_DATA__U_PTAB)
+ ld ix, (_udata + U_DATA__U_PTAB)
; next_process->p_status = P_RUNNING
ld P_TAB__P_STATUS_OFFSET(ix), #P_RUNNING
; restore machine state -- note we may be returning from either
; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
pop iy
pop ix
pop hl ; return code
; enable interrupts, if the ISR isn't already running
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
ld (_int_disabled),a
or a
ret nz ; in ISR, leave interrupts off
ld a, #'='
call outchar
.endif
- ld a, (U_DATA__U_PAGE)
+ ld a, (_udata + U_DATA__U_PAGE)
out0 (MMU_BBR), a
.if DEBUGBANK
call outcharhex
.globl _fd_tick
.include "../platform/kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
;------------------------------------------------------------------------------
.globl _rd_read
.globl _rd_write
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "kernel.def"
.area _CODE
.globl _devmem_write
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "../cpu-z180/z180.def"
.area _CODE
_devmem_go:
ld (_rd_dst_userspace), a ; 1 = userspace
; load the other parameters
- ld hl, (U_DATA__U_BASE)
+ ld hl, (_udata + U_DATA__U_BASE)
ld (_rd_dst_address), hl
- ld hl, (U_DATA__U_COUNT)
+ ld hl, (_udata + U_DATA__U_COUNT)
ld (_rd_cpy_count), hl
- ld hl, (U_DATA__U_OFFSET)
+ ld hl, (_udata + U_DATA__U_OFFSET)
ld (_rd_src_address), hl
- ld hl, (U_DATA__U_OFFSET+2)
+ ld hl, (_udata + U_DATA__U_OFFSET+2)
ld (_rd_src_address+2), hl
; FALL THROUGH INTO _rd_platform_copy
ld hl, #(OS_BANK + FIRST_RAM_BANK) << 4
jr rd_done_translate
rd_translate_userspace:
- ld hl,(U_DATA__U_PAGE) ; load page number
+ ld hl,(_udata + U_DATA__U_PAGE) ; load page number
add hl, hl ; shift left 4 bits
add hl, hl
add hl, hl
.globl _ds1302_get_pin_data
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; DS1302 interface
.globl _ds1302_get_pin_data
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; DS1302 interface
.globl _fd_tick
.include "../platform/kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
;------------------------------------------------------------------------------
.globl _sd_spi_rx_sector
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.globl _spi_port ; Port to use
.globl outstring, outde, outhl, outbc, outnewline, outchar, outcharhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.area _COMMONMEM
ld a,(current_map)
push af
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
;
; We are now running on the sleeping process stack. The switchin
;
; Stash the uarea back into process memory
- ld hl, (U_DATA__U_PAGE)
+ ld hl, (_udata + U_DATA__U_PAGE)
ld a, l
ld bc, #0x7ffd
or #BANK_BITS
out (c), a
; This includes the stacks, so be careful on restore
- ld hl, #U_DATA
+ ld hl, #_udata
ld de, #U_DATA_STASH
ld bc, #U_DATA__TOTALSIZE
ldir
ld (_inswap),a
ld a, (hl) ; We should now have a page assigned
not_swapped:
- ld hl,(U_DATA__U_PTAB)
+ ld hl,(_udata + U_DATA__U_PTAB)
or a
sbc hl,de
; Turn this on once debugged
;
exx
ld hl, #U_DATA_STASH
- ld de, #U_DATA
+ ld de, #_udata
ld bc, #U_DATA__TOTALSIZE
ldir
exx
nofliplow:
; check u_data->u_ptab matches what we wanted
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
or a ; clear carry flag
sbc hl, de ; subtract, result will be zero if DE == HL
jr nz, switchinfail
; wants optimising up a bit
- ld ix, (U_DATA__U_PTAB)
+ ld ix, (_udata + U_DATA__U_PTAB)
; next_process->p_status = P_RUNNING
ld P_TAB__P_STATUS_OFFSET(ix), #P_RUNNING
; Fix any moved page pointers
; Just do one byte as that is all we use on this platform
ld a, P_TAB__P_PAGE_OFFSET(ix)
- ld (U_DATA__U_PAGE), a
+ ld (_udata + U_DATA__U_PAGE), a
; runticks = 0
ld hl, #0
ld (_runticks), hl
; restore machine state -- note we may be returning from either
; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
;
; We can now use the stack again
call switch_bank
; enable interrupts, if the ISR isn't already running
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
ld (_int_disabled),a
or a
ret nz ; in ISR, leave interrupts off
; _switchin which will immediately return (appearing to be _dofork()
; returning) and with HL (ie return code) containing the child PID.
; Hurray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; now we're in a safe state for _switchin to return in the parent
; process.
add hl, de
; load p_page
ld c, (hl)
- ld hl, (U_DATA__U_PAGE)
+ ld hl, (_udata + U_DATA__U_PAGE)
ld a, l
;
; Copy done
- ld a, (U_DATA__U_PAGE) ; parent memory
+ ld a, (_udata + U_DATA__U_PAGE) ; parent memory
or #BANK_BITS ; get the right ROMs
ld bc, #0x7ffd
out (c), a ; Switch context to parent in 0xC000+
; We are going to copy the uarea into the parents uarea stash
; we must not touch the parent uarea after this point, any
; changes only affect the child
- ld hl, #U_DATA ; copy the udata from common into the
+ ld hl, #_udata ; copy the udata from common into the
ld de, #U_DATA_STASH ; target process
ld bc, #U_DATA__TOTALSIZE
ldir
; Keep these in sync with struct u_data!!
-U_DATA__U_PTAB .equ (U_DATA+0) ; struct p_tab*
-U_DATA__U_PAGE .equ (U_DATA+2) ; uint16_t
-U_DATA__U_PAGE2 .equ (U_DATA+4) ; uint16_t
-U_DATA__U_INSYS .equ (U_DATA+6) ; bool
-U_DATA__U_CALLNO .equ (U_DATA+7) ; uint8_t
-U_DATA__U_SYSCALL_SP .equ (U_DATA+8) ; void *
-U_DATA__U_RETVAL .equ (U_DATA+10) ; int16_t
-U_DATA__U_ERROR .equ (U_DATA+12) ; int16_t
-U_DATA__U_SP .equ (U_DATA+14) ; void *
-U_DATA__U_ININTERRUPT .equ (U_DATA+16) ; bool
-U_DATA__U_CURSIG .equ (U_DATA+17) ; int8_t
-U_DATA__U_ARGN .equ (U_DATA+18) ; uint16_t
-U_DATA__U_ARGN1 .equ (U_DATA+20) ; uint16_t
-U_DATA__U_ARGN2 .equ (U_DATA+22) ; uint16_t
-U_DATA__U_ARGN3 .equ (U_DATA+24) ; uint16_t
-U_DATA__U_ISP .equ (U_DATA+26) ; void * (initial stack pointer when _exec()ing)
-U_DATA__U_TOP .equ (U_DATA+28) ; uint16_t
-U_DATA__U_BREAK .equ (U_DATA+30) ; uint16_t
-U_DATA__U_SIGVEC .equ (U_DATA+32) ; table of function pointers (void *)
-U_DATA__U_BASE .equ (U_DATA+96) ; uint8_t *
-U_DATA__U_COUNT .equ (U_DATA+98) ; uint16_t
-U_DATA__U_OFFSET .equ (U_DATA+100) ; uint32_t
+U_DATA__U_PTAB .equ 0 ; struct p_tab*
+U_DATA__U_PAGE .equ 2 ; uint16_t
+U_DATA__U_PAGE2 .equ 4 ; uint16_t
+U_DATA__U_INSYS .equ 6 ; bool
+U_DATA__U_CALLNO .equ 7 ; uint8_t
+U_DATA__U_SYSCALL_SP .equ 8 ; void *
+U_DATA__U_RETVAL .equ 10 ; int16_t
+U_DATA__U_ERROR .equ 12 ; int16_t
+U_DATA__U_SP .equ 14 ; void *
+U_DATA__U_ININTERRUPT .equ 16 ; bool
+U_DATA__U_CURSIG .equ 17 ; int8_t
+U_DATA__U_ARGN .equ 18 ; uint16_t
+U_DATA__U_ARGN1 .equ 20 ; uint16_t
+U_DATA__U_ARGN2 .equ 22 ; uint16_t
+U_DATA__U_ARGN3 .equ 24 ; uint16_t
+U_DATA__U_ISP .equ 26 ; void * (initial stack pointer when _exec()ing)
+U_DATA__U_TOP .equ 28 ; uint16_t
+U_DATA__U_BREAK .equ 30 ; uint16_t
+U_DATA__U_SIGVEC .equ 32 ; table of function pointers (void *)
+U_DATA__U_BASE .equ 96 ; uint8_t *
+U_DATA__U_COUNT .equ 98 ; uint16_t
+U_DATA__U_OFFSET .equ 100 ; uint32_t
; Keep these in sync with struct p_tab!!
P_TAB__P_STATUS_OFFSET .equ 0
--- /dev/null
+
+ .globl _udata
+
+; Keep these in sync with struct u_data!!
+U_DATA__U_PTAB .equ 0 ; struct p_tab*
+U_DATA__U_PAGE .equ 2 ; uint16_t
+U_DATA__U_PAGE2 .equ 4 ; uint16_t
+U_DATA__U_INSYS .equ 6 ; bool
+U_DATA__U_CALLNO .equ 7 ; uint8_t
+U_DATA__U_SYSCALL_SP .equ 8 ; void *
+U_DATA__U_RETVAL .equ 10 ; int16_t
+U_DATA__U_ERROR .equ 12 ; int16_t
+U_DATA__U_SP .equ 14 ; void *
+U_DATA__U_ININTERRUPT .equ 16 ; bool
+U_DATA__U_CURSIG .equ 17 ; int8_t
+U_DATA__U_ARGN .equ 18 ; uint16_t
+U_DATA__U_ARGN1 .equ 20 ; uint16_t
+U_DATA__U_ARGN2 .equ 22 ; uint16_t
+U_DATA__U_ARGN3 .equ 24 ; uint16_t
+U_DATA__U_ISP .equ 26 ; void * (initial stack pointer when _exec()ing)
+U_DATA__U_TOP .equ 28 ; uint16_t
+U_DATA__U_BREAK .equ 30 ; uint16_t
+U_DATA__U_SIGVEC .equ 32 ; table of function pointers (void *)
+U_DATA__U_BASE .equ 96 ; uint8_t *
+U_DATA__U_COUNT .equ 98 ; uint16_t
+U_DATA__U_OFFSET .equ 100 ; uint32_t
+
+; Keep these in sync with struct p_tab!!
+P_TAB__P_STATUS_OFFSET .equ 0
+P_TAB__P_TTY_OFFSET .equ 1
+P_TAB__P_PID_OFFSET .equ 2
+P_TAB__P_PAGE_OFFSET .equ 14
+P_TAB__P_PAGE2_OFFSET .equ 16
+
+P_RUNNING .equ 1 ; value from include/kernel.h
+P_READY .equ 2 ; value from include/kernel.h
+
+OS_BANK .equ 0 ; value from include/kernel.h
+
+EAGAIN .equ 11 ; value from include/kernel.h
+
+; Keep in sync with struct blkbuf
+BUFSIZE .equ 520
ld hl, #0 ; return code set here is ignored, but _switchin can
; return from either _switchout OR _dofork, so they must both write
- ; U_DATA__U_SP with the following on the stack:
+ ; _udata + U_DATA__U_SP with the following on the stack:
push hl ; return code
push ix
push iy
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
; find another process to run (may select this one again)
call _getproc
; ------- No stack -------
; check u_data->u_ptab matches what we wanted
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
or a ; clear carry flag
sbc hl, de ; subtract, result will be zero if DE==IX
jr nz, switchinfail
; restore machine state -- note we may be returning from either
; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
; ---- New task stack ----
pop hl ; return code
; enable interrupts, if the ISR isn't already running
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
ld (_int_disabled),a
or a
ret nz ; in ISR, leave interrupts off
; _switchin which will immediately return (appearing to be _dofork()
; returning) and with HL (ie return code) containing the child PID.
; Hurray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; now we're in a safe state for _switchin to return in the parent
; process.
; imported debug symbols
.globl outstring, outde, outhl, outbc, outnewline, outchar, outcharhex
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.area _COMMONMEM
push iy
call map_save_kmap ; save kernel bank mapping
push af ; on stack in AF
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
; Stash the uarea back into process memory
call map_process_save
- ld hl, #U_DATA
+ ld hl, #_udata
ld de, #U_DATA_STASH
ld bc, #U_DATA__TOTALSIZE
ldir
.endif
ld a, (hl)
not_swapped:
- ld hl, (U_DATA__U_PTAB)
+ ld hl, (_udata + U_DATA__U_PTAB)
or a
sbc hl, de
jr z, skip_copyback ; Tormod's optimisation: don't copy the
exx ; thank goodness for exx 8)
ld hl, #U_DATA_STASH
- ld de, #U_DATA
+ ld de, #_udata
ld bc, #U_DATA__TOTALSIZE
ldir
exx
; Restore the stack in case we are not swap based so we don't
; scribble the bank stack
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
call map_kernel_restore
; check u_data->u_ptab matches what we wanted
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
or a ; clear carry flag
sbc hl, de ; subtract, result will be zero if DE==HL
jr nz, switchinfail
skip_copyback:
; wants optimising up a bit
- ld ix, (U_DATA__U_PTAB)
+ ld ix, (_udata + U_DATA__U_PTAB)
; next_process->p_status = P_RUNNING
ld P_TAB__P_STATUS_OFFSET(ix), #P_RUNNING
; Fix the moved page pointers
; Just do one byte as that is all we use on this platform
ld a, P_TAB__P_PAGE_OFFSET(ix)
- ld (U_DATA__U_PAGE), a
+ ld (_udata + U_DATA__U_PAGE), a
; runticks = 0
ld hl, #0
ld (_runticks), hl
call map_restore_kmap
; enable interrupts, if we didn't pre-empt in an ISR
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
ld (_int_disabled),a
or a
ret nz ; Not an ISR, leave interrupts off
; returning) and with HL (ie return code) containing the child PID.
; Hurray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; now we're in a safe state for _switchin to return in the parent
; process.
; load p_page
ld c, (hl)
; load existing page ptr
- ld a, (U_DATA__U_PAGE)
+ ld a, (_udata + U_DATA__U_PAGE)
call bankfork ; do the bank to bank copy
; We are going to copy the uarea into the parents uarea stash
; we must not touch the parent uarea after this point, any
; changes only affect the child
- ld hl, #U_DATA ; copy the udata from common into the
+ ld hl, #_udata ; copy the udata from common into the
ld de, #U_DATA_STASH ; target process
ld bc, #U_DATA__TOTALSIZE
ldir
; imported debug symbols
.globl outstring, outde, outhl, outbc, outnewline, outchar, outcharhex
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.area _COMMONMEM
push hl ; return code
push ix
push iy
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
; Stash the uarea back into process memory
call map_process_always
- ld hl, #U_DATA
+ ld hl, #_udata
ld de, #U_DATA_STASH
ld bc, #U_DATA__TOTALSIZE
ldir
.endif
ld a, (hl)
not_swapped:
- ld hl, (U_DATA__U_PTAB)
+ ld hl, (_udata + U_DATA__U_PTAB)
or a
sbc hl, de
jr z, skip_copyback ; Tormod's optimisation: don't copy the
exx ; thank goodness for exx 8)
ld hl, #U_DATA_STASH
- ld de, #U_DATA
+ ld de, #_udata
ld bc, #U_DATA__TOTALSIZE
ldir
exx
; In the non swap case we must set so before we use the stack
; otherwise we risk corrupting the restored stack frame
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
call map_kernel
; check u_data->u_ptab matches what we wanted
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
or a ; clear carry flag
sbc hl, de ; subtract, result will be zero if DE==HL
jr nz, switchinfail
skip_copyback:
; wants optimising up a bit
- ld ix, (U_DATA__U_PTAB)
+ ld ix, (_udata + U_DATA__U_PTAB)
; next_process->p_status = P_RUNNING
ld P_TAB__P_STATUS_OFFSET(ix), #P_RUNNING
; Fix the moved page pointers
; Just do one byte as that is all we use on this platform
ld a, P_TAB__P_PAGE_OFFSET(ix)
- ld (U_DATA__U_PAGE), a
+ ld (_udata + U_DATA__U_PAGE), a
; runticks = 0
ld hl, #0
ld (_runticks), hl
; restore machine state -- note we may be returning from either
; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
pop iy
pop ix
pop hl ; return code
; enable interrupts, if we didn't pre-empt in an ISR
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
ld (_int_disabled),a
or a
ret nz ; Not an ISR, leave interrupts off
; returning) and with HL (ie return code) containing the child PID.
; Hurray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; now we're in a safe state for _switchin to return in the parent
; process.
; load p_page
ld c, (hl)
; load existing page ptr
- ld a, (U_DATA__U_PAGE)
+ ld a, (_udata + U_DATA__U_PAGE)
call bankfork ; do the bank to bank copy
; We are going to copy the uarea into the parents uarea stash
; we must not touch the parent uarea after this point, any
; changes only affect the child
- ld hl, #U_DATA ; copy the udata from common into the
+ ld hl, #_udata ; copy the udata from common into the
ld de, #U_DATA_STASH ; target process
ld bc, #U_DATA__TOTALSIZE
ldir
push hl ; return code
push ix
push iy
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
; find another process to run (may select this one again)
call _getproc
; practice that means it exited. We don't need to write
; it back out as it's dead.
;
- ld ix,(U_DATA__U_PTAB)
+ ld ix,(_udata + U_DATA__U_PTAB)
ld a,P_TAB__P_PAGE_OFFSET(ix)
or a
;
push de ; save process
; We will always swap out the current process
- ld hl, (U_DATA__U_PTAB)
+ ld hl, (_udata + U_DATA__U_PTAB)
push hl
call _swapout
pop hl
not_swapped:
; check u_data->u_ptab matches what we wanted
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
or a ; clear carry flag
sbc hl, de ; subtract, result will be zero if DE==HL
jr nz, switchinfail
; wants optimising up a bit
- ld ix, (U_DATA__U_PTAB)
+ ld ix, (_udata + U_DATA__U_PTAB)
; next_process->p_status = P_RUNNING
ld P_TAB__P_STATUS_OFFSET(ix), #P_RUNNING
; Fix the moved page pointers
; Just do one byte as that is all we use on this platform
ld a, P_TAB__P_PAGE_OFFSET(ix)
- ld (U_DATA__U_PAGE), a
+ ld (_udata + U_DATA__U_PAGE), a
; runticks = 0
ld hl, #0
ld (_runticks), hl
; restore machine state -- note we may be returning from either
; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
pop iy
pop ix
pop hl ; return code
; enable interrupts, if the ISR isn't already running
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
; put th einterrupt status flag back correctly
ld (_int_disabled),a
or a
; _switchin which will immediately return (appearing to be _dofork()
; returning) and with HL (ie return code) containing the child PID.
; Hurray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; now we're in a safe state for _switchin to return in the parent
; process.
;
deliver_signals:
; Pending signal
- ld a, (U_DATA__U_CURSIG)
+ ld a, (_udata + U_DATA__U_CURSIG)
or a,a
ret z
; Handler to use
add hl, hl
- ld de, #U_DATA__U_SIGVEC
+ ld de, #_udata + U_DATA__U_SIGVEC
add hl, de
ld e, (hl)
inc hl
; Indicate processed
xor a,a
- ld (U_DATA__U_CURSIG), a
+ ld (_udata + U_DATA__U_CURSIG), a
; Semantics for now: signal delivery clears handler
ld (hl), a
; element of this processing, as we don't want to
; set INSYS flags here.
;
- ld (U_DATA__U_SYSCALL_SP), sp
+ ld (_udata + U_DATA__U_SYSCALL_SP), sp
ld sp, #kstack_top
call map_kernel
call _chksigs
call map_process_always
- ld sp, (U_DATA__U_SYSCALL_SP)
+ ld sp, (_udata + U_DATA__U_SYSCALL_SP)
jr deliver_signals
;
;; call mmu_kernel ; must preserve HL
; save system call number
ld a, (hl)
- ld (U_DATA__U_CALLNO), a
+ ld (_udata + U_DATA__U_CALLNO), a
; advance to syscall arguments
inc hl
inc hl
; copy arguments to common memory
- ld de, #U_DATA__U_ARGN
+ ld de, #_udata + U_DATA__U_ARGN
ldi
ldi
ldi
ldi
ld a, #1
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_INSYS), a
; save process stack pointer
- ld (U_DATA__U_SYSCALL_SP), sp
+ ld (_udata + U_DATA__U_SYSCALL_SP), sp
; switch to kernel stack
ld sp, #kstack_top
call map_process_always
xor a,a
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_INSYS), a
; Back to the user stack
- ld sp, (U_DATA__U_SYSCALL_SP)
+ ld sp, (_udata + U_DATA__U_SYSCALL_SP)
- ld hl, (U_DATA__U_ERROR)
- ld de, (U_DATA__U_RETVAL)
+ ld hl, (_udata + U_DATA__U_ERROR)
+ ld de, (_udata + U_DATA__U_RETVAL)
- ld a, (U_DATA__U_CURSIG)
+ ld a, (_udata + U_DATA__U_CURSIG)
or a,a
; Fast path the normal case
; Get off the kernel syscall stack before we start signal
; handling. Our signal handlers may themselves elect to make system
; calls. This means we must also save the error/return code
- ld hl, (U_DATA__U_ERROR)
+ ld hl, (_udata + U_DATA__U_ERROR)
push hl
- ld hl, (U_DATA__U_RETVAL)
+ ld hl, (_udata + U_DATA__U_RETVAL)
push hl
; Signal processing. This may longjmp back into userland
pop bc ; return address
pop de ; start address
- ld hl, (U_DATA__U_ISP)
+ ld hl, (_udata + U_DATA__U_ISP)
ld sp, hl ; Initialize user stack, below main() parameters and the environment
; u_data.u_insys = false
xor a,a
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_INSYS), a
ex de, hl
;
null_handler:
; kernel jump to NULL is bad
- ld a, (U_DATA__U_INSYS)
+ ld a, (_udata + U_DATA__U_INSYS)
or a,a
jp nz, trap_illegal
ld a, (_inint)
; user is merely not good
ld hl, #7
push hl
- ld ix, (U_DATA__U_PTAB)
+ ld ix, (_udata + U_DATA__U_PTAB)
ld l,P_TAB__P_PID_OFFSET(ix)
ld h,P_TAB__P_PID_OFFSET+1(ix)
push hl
ld a, #1
ld (_inint), a
; So we know that this task should resume with IRQs off
- ld (U_DATA__U_ININTERRUPT), a
+ ld (_udata + U_DATA__U_ININTERRUPT), a
call _platform_interrupt
intout:
xor a,a
- ld (U_DATA__U_ININTERRUPT), a
+ ld (_udata + U_DATA__U_ININTERRUPT), a
intret:
ipset1
- ld a, (U_DATA__U_INSYS)
+ ld a, (_udata + U_DATA__U_INSYS)
or a,a
jr nz, interrupt_pop
ld hl, #11 ; SIGSEGV
trap_signal:
push hl
- ld hl, (U_DATA__U_PTAB);
+ ld hl, (_udata + U_DATA__U_PTAB);
push hl
call _ssig
pop hl
call map_restore
ld hl, (istack_switched_sp)
- ld (U_DATA__U_SYSCALL_SP), hl
+ ld (_udata + U_DATA__U_SYSCALL_SP), hl
ld sp, #kstack_top ; We don't pre-empt in a syscall
; so this is fine
; pre-empted when switchout re-enables interrupts.
;
ld a, #1
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_INSYS), a
;
; Check for signals
;
;
; Process status is offset 0
;
- ld hl, (U_DATA__U_PTAB)
+ ld hl, (_udata + U_DATA__U_PTAB)
ld a,(hl)
cp a,#P_RUNNING
jr nz, not_running
; We are no longer in an interrupt or a syscall
;
xor a,a
- ld (U_DATA__U_ININTERRUPT), a
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_ININTERRUPT), a
+ ld (_udata + U_DATA__U_INSYS), a
;
; We have been rescheduled, remap ourself and go back to user
; space via signal handling
call map_process_always ; Get our user mapping back
; We were pre-empted but have now been rescheduled
; User stack
- ld sp, (U_DATA__U_SYSCALL_SP)
- ld a, (U_DATA__U_CURSIG)
+ ld sp, (_udata + U_DATA__U_SYSCALL_SP)
+ ld a, (_udata + U_DATA__U_CURSIG)
or a,a
jr z, nosigs
call deliver_signals_2
.globl istack_switched_sp
.globl istack_top
.globl _ssig
+ .globl _udata
.include "platform/kernel.def"
- .include "kernel.def"
+ .include "kernel-z80.def"
; these make the code below more readable. sdas allows us only to
; test if an expression is zero or non-zero.
;
deliver_signals:
; Pending signal
- ld a, (U_DATA__U_CURSIG)
+ ld a, (_udata + U_DATA__U_CURSIG)
or a
ret z
; Handler to use
add hl, hl
- ld de, #U_DATA__U_SIGVEC
+ ld de, #_udata + U_DATA__U_SIGVEC
add hl, de
ld e, (hl)
inc hl
; Indicate processed
xor a
- ld (U_DATA__U_CURSIG), a
+ ld (_udata + U_DATA__U_CURSIG), a
; and we will handle the signal with interrupts on so clear the
; flag
ld (_int_disabled),a
; element of this processing, as we don't want to
; set INSYS flags here.
;
- ld (U_DATA__U_SYSCALL_SP), sp
+ ld (_udata + U_DATA__U_SYSCALL_SP), sp
ld sp, #kstack_top
ld a,#1
ld (_int_disabled),a
call _chksigs
pop af
call map_process_always
- ld sp, (U_DATA__U_SYSCALL_SP)
+ ld sp, (_udata + U_DATA__U_SYSCALL_SP)
jr deliver_signals
add hl, sp
; save system call number
ld a, (hl)
- ld (U_DATA__U_CALLNO), a
+ ld (_udata + U_DATA__U_CALLNO), a
; advance to syscall arguments
inc hl
inc hl
; copy arguments to common memory
ld bc, #8 ; four 16-bit values
- ld de, #U_DATA__U_ARGN
+ ld de, #_udata + U_DATA__U_ARGN
ldir ; copy
ld a, #1
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_INSYS), a
; save process stack pointer
- ld (U_DATA__U_SYSCALL_SP), sp
+ ld (_udata + U_DATA__U_SYSCALL_SP), sp
; switch to kernel stack
ld sp, #kstack_top
call map_process_always
xor a
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_INSYS), a
; Back to the user stack
- ld sp, (U_DATA__U_SYSCALL_SP)
+ ld sp, (_udata + U_DATA__U_SYSCALL_SP)
- ld hl, (U_DATA__U_ERROR)
- ld de, (U_DATA__U_RETVAL)
+ ld hl, (_udata + U_DATA__U_ERROR)
+ ld de, (_udata + U_DATA__U_RETVAL)
- ld a, (U_DATA__U_CURSIG)
+ ld a, (_udata + U_DATA__U_CURSIG)
or a
; Fast path the normal case
; Get off the kernel syscall stack before we start signal
; handling. Our signal handlers may themselves elect to make system
; calls. This means we must also save the error/return code
- ld hl, (U_DATA__U_ERROR)
+ ld hl, (_udata + U_DATA__U_ERROR)
push hl
- ld hl, (U_DATA__U_RETVAL)
+ ld hl, (_udata + U_DATA__U_RETVAL)
push hl
; Signal processing. This may longjmp back into userland
pop af ; bank number
pop de ; start address
- ld hl, (U_DATA__U_ISP)
+ ld hl, (_udata + U_DATA__U_ISP)
ld sp, hl ; Initialize user stack, below main() parameters and the environment
; u_data.u_insys = false
xor a
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_INSYS), a
ex de, hl
;
null_handler:
; kernel jump to NULL is bad
- ld a, (U_DATA__U_INSYS)
+ ld a, (_udata + U_DATA__U_INSYS)
or a
jp nz, trap_illegal
; user is merely not good
ld hl, #7
push hl
- ld ix, (U_DATA__U_PTAB)
+ ld ix, (_udata + U_DATA__U_PTAB)
ld l,P_TAB__P_PID_OFFSET(ix)
ld h,P_TAB__P_PID_OFFSET+1(ix)
push hl
ld a, #1
ld (_inint), a
; So we know that this task should resume with IRQs off
- ld (U_DATA__U_ININTERRUPT), a
+ ld (_udata + U_DATA__U_ININTERRUPT), a
; Load the interrupt flag properly. It got an implicit di from
; the IRQ being taken
ld (_int_disabled),a
intout:
xor a
- ld (U_DATA__U_ININTERRUPT), a
+ ld (_udata + U_DATA__U_ININTERRUPT), a
ld hl, #intret
push hl
; have DI set
intret:
di
- ld a, (U_DATA__U_INSYS)
+ ld a, (_udata + U_DATA__U_INSYS)
or a
jr nz, interrupt_pop
ld hl, #11 ; SIGSEGV
trap_signal:
push hl
- ld hl, (U_DATA__U_PTAB);
+ ld hl, (_udata + U_DATA__U_PTAB);
push hl
push af
call _ssig
call map_restore
ld hl, (istack_switched_sp)
- ld (U_DATA__U_SYSCALL_SP), hl
+ ld (_udata + U_DATA__U_SYSCALL_SP), hl
ld sp, #kstack_top ; We don't pre-empt in a syscall
; so this is fine
; pre-empted when switchout re-enables interrupts.
;
ld a, #1
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_INSYS), a
;
; Check for signals
;
;
; Process status is offset 0
;
- ld hl, (U_DATA__U_PTAB)
+ ld hl, (_udata + U_DATA__U_PTAB)
ld a, #P_RUNNING
cp (hl)
jr nz, not_running
; We are no longer in an interrupt or a syscall
;
xor a
- ld (U_DATA__U_ININTERRUPT), a
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_ININTERRUPT), a
+ ld (_udata + U_DATA__U_INSYS), a
;
; We have been rescheduled, remap ourself and go back to user
; space via signal handling
; We were pre-empted but have now been rescheduled
; User stack
- ld sp, (U_DATA__U_SYSCALL_SP)
- ld a, (U_DATA__U_CURSIG)
+ ld sp, (_udata + U_DATA__U_SYSCALL_SP)
+ ld a, (_udata + U_DATA__U_CURSIG)
or a
call nz, deliver_signals_2
;
.globl istack_switched_sp
.globl istack_top
.globl _ssig
+ .globl _udata
.include "platform/kernel.def"
- .include "kernel.def"
+ .include "kernel-z80.def"
; these make the code below more readable. sdas allows us only to
; test if an expression is zero or non-zero.
di
call map_user_low
xor a
- ld (U_DATA__U_INSYS),a
+ ld (_udata + U_DATA__U_INSYS),a
pop bc
pop de ; start address
- ld hl,(U_DATA__U_ISP)
+ ld hl,(_udata + U_DATA__U_ISP)
ld sp,hl
ex de,hl
ld de,#PROGLOAD
- ld a,(U_DATA__U_PAGE+HIGHPAGE) ; pass high page to trampoline
+ ld a,(_udata + U_DATA__U_PAGE+HIGHPAGE) ; pass high page to trampoline
jp _platform_doexec ; jump into the low memory stub
;
;
unix_syscall_entry:
; Start by saving the arguments. That frees up all our registers
- ld (U_DATA__U_CALLNO),a
- ld (U_DATA__U_ARGN),bc
- ld (U_DATA__U_ARGN1),de
- ld (U_DATA__U_ARGN2),ix
- ld (U_DATA__U_ARGN3),hl
+ ld (_udata + U_DATA__U_CALLNO),a
+ ld (_udata + U_DATA__U_ARGN),bc
+ ld (_udata + U_DATA__U_ARGN1),de
+ ld (_udata + U_DATA__U_ARGN2),ix
+ ld (_udata + U_DATA__U_ARGN3),hl
; Stack the alternate registers
exx
push bc
push af
; Tell the pre-emption code we are in kernel right now
ld a,#1
- ld (U_DATA__U_INSYS),a
+ ld (_udata + U_DATA__U_INSYS),a
; Make the kernel appear
call map_kernel_low
; Call into the kernel with interrupts on
call map_user_low
; We are now not in kernel
xor a
- ld (U_DATA__U_INSYS),a
+ ld (_udata + U_DATA__U_INSYS),a
; Recover the return data
- ld hl, (U_DATA__U_ERROR)
- ld de, (U_DATA__U_RETVAL)
- ld a, (U_DATA__U_CURSIG)
+ ld hl, (_udata + U_DATA__U_ERROR)
+ ld de, (_udata + U_DATA__U_RETVAL)
+ ld a, (_udata + U_DATA__U_CURSIG)
or a
; Keep the hot path inline
jr nz, signal_path
exx
; Return page for caller (may not be the page we can in on if we
; swapped
- ld a,(U_DATA__U_PAGE+HIGHPAGE)
+ ld a,(_udata + U_DATA__U_PAGE+HIGHPAGE)
ret
signal_path:
ld h,a ; save signal number
push hl
; Get the signal vector and zero it
add a,a
- ld hl,#U_DATA__U_SIGVEC
+ ld hl,#_udata + U_DATA__U_SIGVEC
ld c,a
xor a
- ld (U_DATA__U_CURSIG),a
+ ld (_udata + U_DATA__U_CURSIG),a
ld b,a
add hl,bc
ld c,(hl)
call map_save_low ; save old and map kernel
ld a,#1
ld (_inint),a
- ld (U_DATA__U_ININTERRUPT),a
+ ld (_udata + U_DATA__U_ININTERRUPT),a
ld (_int_disabled),a
call _platform_interrupt
xor a
; any interrupt controller
intreti:di
xor a
- ld (U_DATA__U_ININTERRUPT),a
+ ld (_udata + U_DATA__U_ININTERRUPT),a
; Are we returning to kernel ?
- ld a, (U_DATA__U_INSYS)
+ ld a, (_udata + U_DATA__U_INSYS)
or a
jr nz, interrupt_kernel
intsig:
call map_user_low
- ld a,(U_DATA__U_CURSIG)
+ ld a,(_udata + U_DATA__U_CURSIG)
or a
jr nz, interrupt_sig
; Nothing special to do
xor a
ld (_int_disabled),a
ld e,a
- ld a,(U_DATA__U_PAGE+HIGHPAGE)
+ ld a,(_udata + U_DATA__U_PAGE+HIGHPAGE)
intret:
ret
ld (_int_disabled),a
ld e,a
ld c,a
- ld (U_DATA__U_CURSIG),a
- ld hl,#U_DATA__U_SIGVEC
+ ld (_udata + U_DATA__U_CURSIG),a
+ ld hl,#_udata + U_DATA__U_SIGVEC
add hl,de
add hl,de
ld e,(hl)
xor a
ld (_need_resched),a ; we are doing it thank you
ld hl,(istack_switched_sp)
- ld (U_DATA__U_SYSCALL_SP), hl ; save the stack save
+ ld (_udata + U_DATA__U_SYSCALL_SP), hl ; save the stack save
ld sp, #kstack_top ; free because we are not pre-empted
; during a system call
push de ; return address onto our kstack
di
; Fake being in a syscall
ld a,#1
- ld (U_DATA__U_INSYS),a
+ ld (_udata + U_DATA__U_INSYS),a
call _chksigs
- ld hl, (U_DATA__U_PTAB)
+ ld hl, (_udata + U_DATA__U_PTAB)
ld a,#P_RUNNING
cp (hl)
jr nz, not_running
call _platform_switchout
; Undo the fakery
xor a
- ld (U_DATA__U_ININTERRUPT),a
- ld (U_DATA__U_INSYS),a
+ ld (_udata + U_DATA__U_ININTERRUPT),a
+ ld (_udata + U_DATA__U_INSYS),a
; The istack was lost but that is ok as we saved the return onto the
; kernel stack, so when we finally ret we end up in the right place
ld sp,#kstack_top - 2 ; saved return address
- ld hl,(U_DATA__U_SYSCALL_SP)
+ ld hl,(_udata + U_DATA__U_SYSCALL_SP)
ld (istack_switched_sp),hl
; Now continue on the interrupt return path
.globl istack_switched_sp
.globl istack_top
.globl _ssig
+ .globl _udata
.include "platform/kernel.def"
- .include "kernel.def"
+ .include "kernel-z80.def"
; these make the code below more readable. sdas allows us only to
; test if an expression is zero or non-zero.
;
deliver_signals:
; Pending signal
- ld a, (U_DATA__U_CURSIG)
+ ld a, (_udata + U_DATA__U_CURSIG)
or a
ret z
; Handler to use
add hl, hl
- ld de, #U_DATA__U_SIGVEC
+ ld de, #_udata + U_DATA__U_SIGVEC
add hl, de
ld e, (hl)
inc hl
; Indicate processed
xor a
- ld (U_DATA__U_CURSIG), a
+ ld (_udata + U_DATA__U_CURSIG), a
; and we will handle the signal with interrupts on so clear the
; flag
ld (_int_disabled),a
; element of this processing, as we don't want to
; set INSYS flags here.
;
- ld (U_DATA__U_SYSCALL_SP), sp
+ ld (_udata + U_DATA__U_SYSCALL_SP), sp
ld sp, #kstack_top
;
; Ensure chksigs and friends see the right status
call map_kernel_di
call _chksigs
call map_process_always_di
- ld sp, (U_DATA__U_SYSCALL_SP)
+ ld sp, (_udata + U_DATA__U_SYSCALL_SP)
jr deliver_signals
.endif
; save system call number
ld a, (hl)
- ld (U_DATA__U_CALLNO), a
+ ld (_udata + U_DATA__U_CALLNO), a
; advance to syscall arguments
inc hl
inc hl
; copy arguments to common memory
ld bc, #8 ; four 16-bit values
- ld de, #U_DATA__U_ARGN
+ ld de, #_udata + U_DATA__U_ARGN
ldir ; copy FIXME use LDI x 8
ld a, #1
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_INSYS), a
; save process stack pointer
- ld (U_DATA__U_SYSCALL_SP), sp
+ ld (_udata + U_DATA__U_SYSCALL_SP), sp
; switch to kernel stack
ld sp, #kstack_top
call map_process_always_di
xor a
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_INSYS), a
; Back to the user stack
- ld sp, (U_DATA__U_SYSCALL_SP)
+ ld sp, (_udata + U_DATA__U_SYSCALL_SP)
- ld hl, (U_DATA__U_ERROR)
- ld de, (U_DATA__U_RETVAL)
+ ld hl, (_udata + U_DATA__U_ERROR)
+ ld de, (_udata + U_DATA__U_RETVAL)
- ld a, (U_DATA__U_CURSIG)
+ ld a, (_udata + U_DATA__U_CURSIG)
or a
; Fast path the normal case
; Get off the kernel syscall stack before we start signal
; handling. Our signal handlers may themselves elect to make system
; calls. This means we must also save the error/return code
- ld hl, (U_DATA__U_ERROR)
+ ld hl, (_udata + U_DATA__U_ERROR)
push hl
- ld hl, (U_DATA__U_RETVAL)
+ ld hl, (_udata + U_DATA__U_RETVAL)
push hl
; Signal processing. This may longjmp back into userland
pop bc ; return address
pop de ; start address
- ld hl, (U_DATA__U_ISP)
+ ld hl, (_udata + U_DATA__U_ISP)
ld sp, hl ; Initialize user stack, below main() parameters and the environment
; u_data.u_insys = false
xor a
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_INSYS), a
ex de, hl
;
null_handler:
; kernel jump to NULL is bad
- ld a, (U_DATA__U_INSYS)
+ ld a, (_udata + U_DATA__U_INSYS)
or a
jp nz, trap_illegal
ld a, (_inint)
; user is merely not good
ld hl, #7
push hl
- ld ix, (U_DATA__U_PTAB)
+ ld ix, (_udata + U_DATA__U_PTAB)
ld l,P_TAB__P_PID_OFFSET(ix)
ld h,P_TAB__P_PID_OFFSET+1(ix)
push hl
ld a, #1
ld (_inint), a
; So we know that this task should resume with IRQs off
- ld (U_DATA__U_ININTERRUPT), a
+ ld (_udata + U_DATA__U_ININTERRUPT), a
; Load the interrupt flag properly. It got an implicit di from
; the IRQ being taken
ld (_int_disabled),a
intout:
xor a
- ld (U_DATA__U_ININTERRUPT), a
+ ld (_udata + U_DATA__U_ININTERRUPT), a
ld hl, #intret
push hl
; have DI set
intret:
di
- ld a, (U_DATA__U_INSYS)
+ ld a, (_udata + U_DATA__U_INSYS)
or a
jr nz, interrupt_pop
ld hl, #11 ; SIGSEGV
trap_signal:
push hl
- ld hl, (U_DATA__U_PTAB);
+ ld hl, (_udata + U_DATA__U_PTAB);
push hl
call _ssig
pop hl
call map_restore
ld hl, (istack_switched_sp)
- ld (U_DATA__U_SYSCALL_SP), hl
+ ld (_udata + U_DATA__U_SYSCALL_SP), hl
ld sp, #kstack_top ; We don't pre-empt in a syscall
; so this is fine
; pre-empted when switchout re-enables interrupts.
;
ld a, #1
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_INSYS), a
;
; Check for signals
;
;
; Process status is offset 0
;
- ld hl, (U_DATA__U_PTAB)
+ ld hl, (_udata + U_DATA__U_PTAB)
ld a,#P_RUNNING
cp (hl)
jr nz, not_running
; We are no longer in an interrupt or a syscall
;
xor a
- ld (U_DATA__U_ININTERRUPT), a
- ld (U_DATA__U_INSYS), a
+ ld (_udata + U_DATA__U_ININTERRUPT), a
+ ld (_udata + U_DATA__U_INSYS), a
;
; We have been rescheduled, remap ourself and go back to user
; space via signal handling
; We were pre-empted but have now been rescheduled
; User stack
- ld sp, (U_DATA__U_SYSCALL_SP)
- ld a, (U_DATA__U_CURSIG)
+ ld sp, (_udata + U_DATA__U_SYSCALL_SP)
+ ld a, (_udata + U_DATA__U_CURSIG)
or a
call nz, deliver_signals_2
;
.module fdc765
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.globl map_process_always
.globl map_kernel
.globl outstringhex
.include "platform/kernel.def"
- .include "../../kernel.def" ; Kernel
+ .include "../../kernel-z80.def" ; Kernel
.include "nc100.def"
; -----------------------------------------------------------------------------
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xF000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x300 ; 256+256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @0xF000
Z80_TYPE .equ 0
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xF000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x300 ; 256+256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @0xF000
Z80_TYPE .equ 0
.module tricks
.include "platform/kernel.def"
- .include "../../kernel.def" ; Kernel
+ .include "../../kernel-z80.def" ; Kernel
TOP_PORT .equ 0x13
.globl _panic
.globl _need_resched
.globl _ssig
+ .globl _udata
.globl _set_irq
.globl _spurious
.globl outstringhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (0xF200 upwards)
nop
rst18:
; Activate the user bank (which also holds these bytes)
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
out (0x40),a
ei
; and leap into user space
; This needs some properly optimized versions!
;
ldir_to_user:
- ld de,(U_DATA__U_PAGE) ; will load with 0 e with page
+ ld de,(_udata + U_DATA__U_PAGE) ; will load with 0 e with page
inc d ; Kernel is in #1
ldir_far:
push bc
out (0x40),a ; Select kernel
ret
ldir_from_user:
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
ld e,#1
ld d,a
jr ldir_far
out (0x40),a
ex af,af'
; Stack now invalid
- ld (U_DATA__U_SYSCALL_SP),sp
+ ld (_udata + U_DATA__U_SYSCALL_SP),sp
ld sp,#kstack_top
call unix_syscall_entry
; FIXME check di rules
; stack now invalid. Grab the new sp before we unbank the
; memory holding it
- ld sp,(U_DATA__U_SYSCALL_SP)
- ld a, (U_DATA__U_PAGE) ; back to the user page
+ ld sp,(_udata + U_DATA__U_SYSCALL_SP)
+ ld a, (_udata + U_DATA__U_PAGE) ; back to the user page
out (0x40),a
xor a
cp h
; For the boot vector
.globl init
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.area _BOOT
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xF200 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @0xF200
U_DATA_STASH .equ 0xF000 ; F000-F200
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
;
; We can't quite use the standard helpers as we have rather weird
push hl ; return code
push ix
push iy
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
; Stash the uarea back into process memory
- ld hl, #U_DATA
+ ld hl, #_udata
ld ix, #U_DATA_STASH
ld bc, #U_DATA__TOTALSIZE
; Slow - must be a more elegant way to tackle this ! FIXME
; We need the swap stack anyway or we run out of registers
ld sp, #_swapstack
- ld hl, (U_DATA__U_PTAB)
+ ld hl, (_udata + U_DATA__U_PTAB)
or a
sbc hl, de
jr z, skip_copyback ; Tormod's optimisation: don't copy the
; or #0x80
; out (0x40),a
; ld hl, #U_DATA_STASH
-; ld de, #U_DATA
+; ld de, #_udata
; ld bc, #U_DATA__TOTALSIZE
; ldir
; ld a,#1 ; back to kernel
; out (0x40),a
- ld hl,# U_DATA_STASH
- ld ix, #U_DATA
+ ld hl, # U_DATA_STASH
+ ld ix, #_udata
ld bc, #U_DATA__TOTALSIZE
ld d,a
ld e,#0x01
; In the non swap case we must set sp before we use the stack
; otherwise we risk corrupting the restored stack frame
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
; check u_data->u_ptab matches what we wanted
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
or a ; clear carry flag
sbc hl, de ; subtract, result will be zero if DE==HL
jr nz, switchinfail
skip_copyback:
; wants optimising up a bit
- ld ix, (U_DATA__U_PTAB)
+ ld ix, (_udata + U_DATA__U_PTAB)
; next_process->p_status = P_RUNNING
ld P_TAB__P_STATUS_OFFSET(ix), #P_RUNNING
; Fix the moved page pointers
; Just do one byte as that is all we use on this platform
ld a, P_TAB__P_PAGE_OFFSET(ix)
- ld (U_DATA__U_PAGE), a
+ ld (_udata + U_DATA__U_PAGE), a
; runticks = 0
ld hl, #0
ld (_runticks), hl
; restore machine state -- note we may be returning from either
; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
pop iy
pop ix
pop hl ; return code
; enable interrupts, if we didn't pre-empt in an ISR
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
ld (_int_disabled),a
or a
ret nz ; Not an ISR, leave interrupts off
; returning) and with HL (ie return code) containing the child PID.
; Hurray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; now we're in a safe state for _switchin to return in the parent
; process.
; load p_page
ld c, (hl)
; load existing page ptr
- ld a, (U_DATA__U_PAGE)
+ ld a, (_udata + U_DATA__U_PAGE)
push bc
call bankfork ; do the bank to bank copy
; We are going to copy the uarea into the parents uarea stash
; we must not touch the parent uarea after this point, any
; changes only affect the child
- ld hl, #U_DATA ; copy the udata from common into the
+ ld hl, #_udata ; copy the udata from common into the
ld ix, #U_DATA_STASH ; target process
ld bc, #U_DATA__TOTALSIZE
.module usermem
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; exported symbols
.globl __uget
ld a,b
or c
ret z
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
out (0x40),a ; user bank
ld (hl),#0
dec bc
pop hl
push hl
push bc
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
out (0x40),a
ld l,(hl)
ld h,#0
pop hl
push hl
push bc
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
out (0x40),a
ld a,(hl)
inc hl
push hl
push de
push bc
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
out (0x40),a
ld (hl),e
jr uout
push hl
push de
push bc
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
out (0x40),a
ld (hl),e
inc hl
.globl kstack_top
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; startup code
.area _BOOT
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0x0200 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 (we don't save istack)
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256@0x0200
PROGBASE .equ 0x8000
PROGLOAD .equ 0x8000
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80single.s"
.globl null_handler
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
;
; These live below 0x8000 so they are not switched out
.globl null_handler
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (0x0000 upwards after the udata etc)
.globl l__COMMONMEM
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
;
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80single.s"
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0x8200 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 @8200
Z80_TYPE .equ 0
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80single.s"
.globl outstringhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (not meaningful on swap only)
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xF000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @ F000
-U_DATA_STASH .equ 0x7D00 ; 0x7D00-0x7FFF
+U_DATA_STASH .equ 0x7E00 ; 0x7E00-0x7FFF
; as far as I can tell either is allowed by the spec
.globl vdpinit
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (0xF000 upwards)
.module bank_msx1
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; imported symbols
.globl _ramsize
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80single.s"
.module vdp
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xF000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes@F000
; as far as I can tell either is allowed by the spec
.globl _vdpinit
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.area _BUFFERS
.globl outstring, outde, outhl, outbc, outnewline, outchar, outcharhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.area _COMMONMEM
push hl ; return code
push ix
push iy
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
; find another process to run (may select this one again)
call _getproc
; ------- No stack -------
; check u_data->u_ptab matches what we wanted
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
or a ; clear carry flag
sbc hl, de ; subtract, result will be zero if DE==IX
jr nz, switchinfail
; restore machine state -- note we may be returning from either
; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
; ---- New task stack ----
pop hl ; return code
; enable interrupts, if the ISR isn't already running
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
ld (_int_disabled),a
or a
ret nz ; in ISR, leave interrupts off
; _switchin which will immediately return (appearing to be _dofork()
; returning) and with HL (ie return code) containing the child PID.
; Hurray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; now we're in a safe state for _switchin to return in the parent
; process.
; and map_restore
;
fork_copy:
- ld hl, (U_DATA__U_TOP)
+ ld hl, (_udata + U_DATA__U_TOP)
ld de, #0x0fff
add hl, de ; + 0x1000 (-1 for the rounding to follow)
ld a, h
ld de, #P_TAB__P_PAGE_OFFSET
add hl, de
; hl now points into the child pages
- ld de, #U_DATA__U_PAGE
+ ld de, #_udata + U_DATA__U_PAGE
; and de is the parent
fork_next:
ld a,(hl)
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xF000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @ F000
U_DATA_STASH .equ 0xBE00 ; BE00-BFFF
.globl outstringhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (0xC000 upwards)
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80fixedbank.s"
.module vdp
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "../dev/vdp1.s"
.include "kernel.def"
.include "../cpu-z180/z180.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; DS1302 interface
; UZI mnemonics for memory addresses etc
; Move down to 0xF600 to fit the monitor in
-U_DATA .equ 0xF800 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @ F800
Z80_TYPE .equ 2
OS_BANK .equ 0x00 ; value from include/kernel.h
.include "kernel.def"
.include "../cpu-z180/z180.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; Buffers
.module gm833
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.globl _gm833_in
.globl _gm833_out
; ACK handling.
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.globl _si_read
.globl _si_write
.module gm8x9
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.globl _gm8x9_ioread
.globl _gm8x9_iowrite
.globl _io_page
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.area _CODE
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xFC00 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 (we don't save istack)
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256@FC00
U_DATA_STASH .equ 0xE600 ; E800-E9FF
.globl l__COMMONMEM
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
;
; We keep the probe routine in the common copy area as we need
map_process_always_di:
push af
push hl
- ld hl, #U_DATA__U_PAGE
+ ld hl, #_udata + U_DATA__U_PAGE
ld a, (hl)
ld (pagereg),a
out (0xFF),a
.globl _bufpool
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.area _BUFFERS
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80fixedbank.s"
.include "kernel.def"
.include "../cpu-z180/z180.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; DS1202 interface
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xF800 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @F800
OS_BANK .equ 0x00 ; value from include/kernel.h
.include "kernel.def"
.include "../cpu-z180/z180.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; Buffers
WIP - lots to do to add swap support and memory map needs a re-arrange so we
can get fork() going
+FIXME:
+- Move disk buffers into own bank and use external disk buffers to keep under
+ the 48K line
+
+
Supported Hardware (all only in early test)
------------------
#define CONFIG_INPUT_GRABMAX 2 /* We could in theory do full up/down but later */
#define MAX_BLKDEV 1 /* UIDE or FIDHD never both */
#define CONFIG_IDE /* Has an IDE controller - maybe anyway: UIDE */
-#define CONFIG_NET
-#define CONFIG_NET_NATIVE
+#undef CONFIG_NET
+#undef CONFIG_NET_NATIVE
#define TICKSPERSEC 300 /* FIXME: double check - Ticks per second */
#define PROGBASE 0x0000 /* memory base of program */
#define NUM_DEV_TTY 3
#define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */
#define SWAPDEV 5 /* Device for swapping. */
-#define NBUFS 6 /* Number of block buffers */
+#define NBUFS 5 /* Number of block buffers */
#define NMOUNTS 2 /* Number of mounts at a time */
#define CONFIG_LARGE_IO_DIRECT(x) 1
.area _HEAP
; note that areas below here may be overwritten by the heap at runtime, so
; put initialisation stuff in here
- .area _INITIALIZER
.area _FONT
.area _GSINIT
.area _GSFINAL
+ .area _INITIALIZER
.area _COMMONMEM
.area _DISCARD
.globl l__DISCARD
.globl s__COMMONMEM
.globl l__COMMONMEM
- .globl s__INITIALIZER
.globl kstack_top
.globl start
__sfr __at 0xE5 ctc1;
__sfr __at 0xE7 ctcmode;
-static char tbuf1[TTYSIZ];
-static char tbuf2[TTYSIZ];
-static char tbuf3[TTYSIZ];
+static uint8_t tbuf1[TTYSIZ];
+static uint8_t tbuf2[TTYSIZ];
+static uint8_t tbuf3[TTYSIZ];
static uint8_t sleeping;
{ tbuf3, tbuf3, tbuf3, TTYSIZ, 0, TTYSIZ/2 }
};
+static tcflag_t console_mask[4] = {
+ _ISYS,
+ _OSYS,
+ _CSYS,
+ _LSYS
+};
+
+
+static tcflag_t uart_mask[4] = {
+ _ISYS,
+ _OSYS,
+ _CSYS, /* For now - need to do DART code */
+ _LSYS
+};
+
+
+tcflag_t *termios_mask[NUM_DEV_TTY + 1] = {
+ NULL,
+ console_mask,
+ uart_mask,
+ uart_mask,
+};
+
/* console driver for errors etc */
void kputchar(char c)
{
-i fuzix.ihx
-b _CODE=0x0000
-b _COMMONMEM=0xF400
--b _DISCARD=0xE800
+-b _DISCARD=0xEB00
-l z80
platform-pcw8256/crt0.rel
platform-pcw8256/commonmem.rel
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xF400 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @ F400
Z80_TYPE .equ 0 ; FIXME: check
#include <printf.h>
#include <devtty.h>
-uint16_t ramtop;
-
/* Kernel is 0-3 screen for now is 4 and bits of 5
Apps 6,7,8,9,10,11,12,13,14,15 etc
.globl map_kernel_di
.globl map_process_di
.globl map_process_always_di
- .globl _need_resched
.globl _int_disabled
.globl map_save_kernel
.globl map_restore
.globl outstringhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; VIDEO MEMORY BANK (0x4000-0xBFFF during video work)
map_process_always_di:
push af
push hl
- ld hl, #U_DATA__U_PAGE
+ ld hl, #_udata + U_DATA__U_PAGE
call map_process_1
pop hl
pop af
or l
jr z, map_kernel
map_process_1:
- ld a, (int_disabled)
+ ld a, (_int_disabled)
push af
di ; ensure we don't take an irq mid update
push de
.db 0
.db 0
-_need_resched:
- .db 0
-
_int_disabled:
.db 1
.module tricks
- .globl _ptab_alloc
- .globl _newproc
- .globl _chksigs
- .globl _getproc
- .globl _platform_monitor
- .globl trap_illegal
- .globl _inint
- .globl _platform_switchout
- .globl _switchin
- .globl _doexec
- .globl _dofork
- .globl _runticks
- .globl unix_syscall_entry
- .globl map_process
- .globl map_kernel
- .globl _swapper
- .globl _int_disabled
-
- ; imported debug symbols
- .globl outstring, outde, outhl, outbc, outnewline, outchar, outcharhex
-
.include "kernel.def"
- .include "../kernel.def"
-
- .area _COMMONMEM
-
-; Switchout switches out the current process, finds another that is READY,
-; possibly the same process, and switches it in. When a process is
-; restarted after calling switchout, it thinks it has just returned
-; from switchout().
-;
-; FIXME: make sure we optimise the switch to self case higher up the stack!
-;
-; This function can have no arguments or auto variables.
-_platform_switchout:
- di
- ; save machine state
-
- ld a, #'O'
- call outchar
- ld hl, (U_DATA__U_PTAB)
- call outhl
-
- ld hl, #0 ; return code set here is ignored, but _switchin can
- ; return from either _switchout OR _dofork, so they must both write
- ; U_DATA__U_SP with the following on the stack:
- push hl ; return code
- push ix
- push iy
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
-
- ; find another process to run (may select this one again)
- call _getproc
-
- push hl
- call _switchin
-
- ; we should never get here
- call _platform_monitor
-
-badswitchmsg: .ascii "_switchin: FAIL"
- .db 13, 10, 0
-_switchin:
- di
- pop bc ; return address
- pop de ; new process pointer
- push de ; restore stack
- push bc ; restore stack
-
- push de
- ld a, #'I'
- call outchar
- call outde
- pop de
- ld hl, #P_TAB__P_PAGE_OFFSET
- add hl, de ; process ptr
-
- ld a, (hl)
- or a
- jr nz, not_swapped
-
- ld a, #'S'
- call outchar
- ;
- ; Run the swapper
- ;
- push hl
- push de
- call _swapper
- pop de
- pop hl
-
-not_swapped:
- push de
- call outde
- pop de
- ld hl, #P_TAB__P_PAGE_OFFSET + 3
- add hl, de
- ld a, (hl) ; common page
-
- push af
- call outcharhex
- pop af
- ; ----------- Stack is switched across this instruction
-;FIXME out (0xF3), a
-
- ; bear in mind that the stack will be switched now, so we can't use it
- ; to carry values over this point
-
- ; check u_data->u_ptab matches what we wanted
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
- or a ; clear carry flag
- sbc hl, de ; subtract, result will be zero if DE==HL
- jr nz, switchinfail
-
- ld hl, #P_TAB__P_STATUS_OFFSET
- add hl, de
- ; next_process->p_status = P_RUNNING
- ld (hl), #P_RUNNING
-
- ; runticks = 0
- ld hl, #0
- ld (_runticks), hl
+ .include "../kernel-z80.def"
- ; restore machine state -- note we may be returning from either
- ; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+TOP_PORT .equ 0xF3
- ; ------------- Stack may be used again ------------
- pop iy
- pop ix
- pop hl ; return code
+ .include "../lib/z80bank16.s"
- ; enable interrupts, if the ISR isn't already running
- ld a, (U_DATA__U_ININTERRUPT)
- ld (_int_disabled),a
- or a
- ret nz ; in ISR, leave interrupts off
- ei
- ret ; return with interrupts on
-
-switchinfail:
- ld hl, #badswitchmsg
- call outstring
- ; something went wrong and we didn't switch in what we asked for
- jp _platform_monitor
-
-fork_proc_ptr: .dw 0 ; (C type is struct p_tab *) -- address of child process p_tab entry
-
-;
-; Called from _fork. We are in a syscall, the uarea is live as the
-; parent uarea. The kernel is the mapped object.
-;
-_dofork:
- ; always disconnect the vehicle battery before performing maintenance
- di ; should already be the case ... belt and braces.
-
- pop de ; return address
- pop hl ; new process p_tab*
- push hl
- push de
-
- ld (fork_proc_ptr), hl
-
- ; prepare return value in parent process -- HL = p->p_pid;
- ld de, #P_TAB__P_PID_OFFSET
- add hl, de
- ld a, (hl)
- inc hl
- ld h, (hl)
- ld l, a
-
- ; Save the stack pointer and critical registers.
- ; When this process (the parent) is switched back in, it will be as if
- ; it returns with the value of the child's pid.
- push hl ; HL still has p->p_pid from above, the return value in the parent
- push ix
- push iy
-
- ; save kernel stack pointer -- when it comes back in the parent we'll be in
- ; _switchin which will immediately return (appearing to be _dofork()
- ; returning) and with HL (ie return code) containing the child PID.
- ; Hurray.
- ld (U_DATA__U_SP), sp
-
- ; now we're in a safe state for _switchin to return in the parent
- ; process.
-
- ; --------- copy process ---------
-
- ld hl, (fork_proc_ptr)
- ld de, #P_TAB__P_PAGE_OFFSET
- add hl, de
- ; load p_page
- ld c, (hl)
- ld hl, (U_DATA__U_PTAB)
- add hl, de
- ld b, (hl)
-
- ; in this call we will switch stack to the child copy, which has
- ; everything below this point from the parent. We will also change
- ; our common instance
-
- call fork_copy ; do the bank to bank copy
-
- ; now the copy operation is complete we can get rid of the stuff
- ; _switchin will be expecting from our copy of the stack.
- pop bc
- pop bc
- pop bc
-
- ; Make a new process table entry, etc.
- ld hl, (fork_proc_ptr)
- push hl
- call _newproc
- pop bc
-
- ; runticks = 0;
- ld hl, #0
- ld (_runticks), hl
- ; in the child process, fork() returns zero.
- ;
- ; And we exit, with the kernel mapped, the child now being deemed
- ; to be the live uarea. The parent is frozen in time and space as
- ; if it had done a switchout().
- ret
+ .area _COMMONMEM
fork_copy:
ld hl, (U_DATA__U_TOP)
out (0xf3), a ; our last bank repeats up to common
; --- we are now on the stack copy, parent stack is locked away ---
ret ; this stack is copied so safe to return on
+
+top_bank:
+ .db 0 ; dummy for core code
+
+
.globl nmi_handler
.globl interrupt_handler
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.area _CODE1
; startup code
; UZI mnemonics for memory addresses etc
; We stick it straight after the tag
-U_DATA .equ 0x100 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @0x0100
U_DATA_STASH .equ 0xFE00 ; FE00-FFFF
.globl _need_resched
.globl _int_disabled
+ .globl _udata
; exported debugging tools
.globl _platform_monitor
.globl __stub_3_2
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (below 0xC000)
push af
ld a, (current_map)
ld (ksave_map), a
- ld a, (U_DATA__U_PAGE)
+ ld a, (_udata + U_DATA__U_PAGE)
call switch_bank
pop af
ret
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0x0100 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 @0100
VIDBASE .equ 0xF8 ; Video for now
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (not unmapped when we flip to ROM)
.globl outstring, outde, outhl, outbc, outnewline, outchar, outcharhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.area _COMMONMEM
push hl ; return code
push ix
push iy
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
; find another process to run (may select this one again)
push af
;
; check u_data->u_ptab matches what we wanted
;
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
or a ; clear carry flag
sbc hl, de ; subtract, result will be zero if DE==IX
jr nz, switchinfail
; wants optimising up a bit
- ld ix, (U_DATA__U_PTAB)
+ ld ix, (_udata + U_DATA__U_PTAB)
; next_process->p_status = P_RUNNING
ld P_TAB__P_STATUS_OFFSET(ix), #P_RUNNING
; Fix the moved page pointers
; Just do one byte as that is all we use on this platform
ld a, P_TAB__P_PAGE_OFFSET(ix)
- ld (U_DATA__U_PAGE), a
+ ld (_udata + U_DATA__U_PAGE), a
; runticks = 0
ld hl, #0
ld (_runticks), hl
; restore machine state -- note we may be returning from either
; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
pop iy
pop ix
pop hl ; return code
; enable interrupts, if the ISR isn't already running
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
or a
ret nz ; in ISR, leave interrupts off
ei
; _switchin which will immediately return (appearing to be _dofork()
; returning) and with HL (ie return code) containing the child PID.
; Hurray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; now we're in a safe state for _switchin to return in the parent
; process.
ld a, c
call outcharhex
pop af
- ld a, (U_DATA__U_PAGE)
+ ld a, (_udata + U_DATA__U_PAGE)
call bankfork ; do the bank to bank copy
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xE000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @E000
U_DATA_STASH .equ 0xBE00 ; BE00-BFFF
.globl _kdataseg
+
+ .globl _udata
+
map_kernel:
map_kernel_di:
push af
map_process_always:
map_process_always_di:
push af
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
ioi
ld (DATASEG),a
pop af
inc hl
inc a
cp a,(hl) ; in ptr
- jr nz, ser'X'_empty
+ jr z, ser'X'_empty
dec hl
+ and #63
ipset3
ld (hl),a
ld hl,#_ser'X'_rxbuf ; work around dumb linker limit
.globl _sio1_present
.globl _tty_resume
.globl _ide_resume
+ .globl _udata
; exported debugging tools
.globl outchar
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
;=========================================================================
; Constants
map_process_always:
map_process_always_di:
push af
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
map_pop_a:
ld (pagereg),a
out (0x1f),a
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80fixedbank-core.s"
; FUZIX mnemonics for memory addresses etc
-U_DATA .equ 0xC000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @ 0xC000
Z80_TYPE .equ 0 ; CMOS
Z80_MMU_HOOKS .equ 0
.globl outchar
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
;=========================================================================
; Constants
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80single.s"
.module buffers
.area _COMMONMEM
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.globl _do_blkzero
.globl _do_blkcopyk
; imported symbols
.globl map_kernel, mpgsel_cache, _kernel_pages
.globl _rd_platform_copy
+ .globl _udata
; exported symbols
.globl _rd_page_copy
.globl _devmem_read
.globl _devmem_write
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.area _CODE
_devmem_write:
_devmem_go:
ld (_rd_dst_userspace), a ; 1 = userspace
; load the other parameters
- ld hl, (U_DATA__U_BASE)
+ ld hl, (_udata + U_DATA__U_BASE)
ld (_rd_dst_address), hl
- ld hl, (U_DATA__U_OFFSET)
+ ld hl, (_udata + U_DATA__U_OFFSET)
ld (_rd_src_address), hl
- ld hl, (U_DATA__U_OFFSET+2)
+ ld hl, (_udata + U_DATA__U_OFFSET+2)
ld (_rd_src_address+2), hl
- ld hl, (U_DATA__U_COUNT)
+ ld hl, (_udata + U_DATA__U_COUNT)
ld (_rd_cpy_count), hl
; for single byte transfers we can optimise away the outer loop
dec l ; test for HL=1
ld hl, #_kernel_pages ; get kernel page table
jr rd_do_translate
rd_translate_userspace:
- ld hl, #U_DATA__U_PAGE ; get user process page table
+ ld hl, #_udata + U_DATA__U_PAGE ; get user process page table
rd_do_translate:
add hl, bc ; add index to base ptr (uint8_t *)
ld a, (hl) ; load the page number from the page table
; FUZIX mnemonics for memory addresses etc
-U_DATA .equ 0xD000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @ D000
Z80_TYPE .equ 0 ; just a old good Z80
USE_FANCY_MONITOR .equ 1 ; disabling this saves around approx 0.5KB
.globl _ctc_present
.globl _sio_present
.globl _sio1_present
+ .globl _udata
; exported debugging tools
.globl outchar
.globl inchar
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
;=========================================================================
; Constants
map_process_always:
map_process_always_di:
push hl
- ld hl,#U_DATA__U_PAGE
+ ld hl,#_udata + U_DATA__U_PAGE
jr map_process_2_pophl_ret
map_buffers_user:
push hl
- ld hl,(U_DATA__U_PAGE)
+ ld hl,(_udata + U_DATA__U_PAGE)
ld h,#36
ld (_ubuffer_pages),hl
- ld hl,(U_DATA__U_PAGE + 2)
+ ld hl,(_udata + U_DATA__U_PAGE + 2)
ld (_ubuffer_pages + 2),hl
ld hl,#_ubuffer_pages
jr map_process_2_pophl_ret
map_buffers_user_h:
push hl
- ld hl,(U_DATA__U_PAGE)
+ ld hl,(_udata + U_DATA__U_PAGE)
ld (_ubuffer_pages),hl
- ld hl,(U_DATA__U_PAGE + 2)
+ ld hl,(_udata + U_DATA__U_PAGE + 2)
ld l,#36
ld (_ubuffer_pages + 2),hl
ld hl,#_ubuffer_pages
.module tricks
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
TOP_PORT .equ MPGSEL_3
.globl mpgsel_cache
fork_copy:
- ld hl, (U_DATA__U_TOP)
+ ld hl, (_udata + U_DATA__U_TOP)
ld de, #0x0fff
add hl, de ; + 0x1000 (-1 for the rounding to follow)
ld a, h
ld de, #P_TAB__P_PAGE_OFFSET
add hl, de
; hl now points into the child pages
- ld de, #U_DATA__U_PAGE
+ ld de, #_udata + U_DATA__U_PAGE
; and de is the parent
fork_next:
ld a,(hl)
.module vfdterm
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.globl VFDTERM_PREINIT
.globl VFDTERM_PUTC
.module atom
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.globl _devide_read_data
atomlite_read_user:
push ix
; HL is the user buffer, BC length
- ld ix,#U_DATA__U_PAGE
+ ld ix,#_udata + U_DATA__U_PAGE
call user_mapping
jr z,ide_r2
call atomlite_reader
atomlite_write_user:
push ix
; HL is the user buffer, BC length
- ld ix,#U_DATA__U_PAGE
+ ld ix,#_udata + U_DATA__U_PAGE
call user_mapping
jr z,ide_w2
call atomlite_writer
; Fuzix mnemonics for memory addresses etc
-U_DATA .equ 0xF800 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 512 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 512 bytes @ F800
U_DATA_STASH .equ 0xFD00 ; FD00-FEFF
; FF00-FFFF is the high stubs
.globl _mouse12
.globl _mouse_probe
.globl _int_disabled
+ .globl _udata
; exported debugging tools
.globl _platform_monitor
.globl l__COMMONMEM
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
KERNEL_LOW .equ 0x20 ; 0/1 low 2/3 high (ROM off)
KERNEL_HIGH .equ 2
ld a, (low_save)
jr map_page_low
map_user_low:
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
map_page_low:
or #0x20 ; force ROM off
out (250),a
or #KERNEL_HIGH
out (251),a
; Stack now invalid
- ld (U_DATA__U_SYSCALL_SP),sp
+ ld (_udata + U_DATA__U_SYSCALL_SP),sp
ld sp,#kstack_top
ld a,(syscall_stash)
call unix_syscall_entry
pop bc
; stack now invalid. Grab the new sp before we unbank the
; memory holding it
- ld sp,(U_DATA__U_SYSCALL_SP)
+ ld sp,(_udata + U_DATA__U_SYSCALL_SP)
out (251),a
xor a
cp h
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
;FIXME .include "../lib/z80fixedbank.s"
push hl ; stack a retcode of 0 (see fork)
push ix ; save registers
push iy
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; The U_DATA stash lives in the top of the user process. Map that
; low with interrupts off so we can ldir between the two
- ld a,(U_DATA__U_PAGE + 1)
+ ld a,(_udata + U_DATA__U_PAGE + 1)
call map_page_low
- ld hl,#U_DATA
+ ld hl,#_udata
ld de,#U_DATA_STASH-0x8000
ld bc,#U_DATA__TOTALSIZE
ldir
; FIXME: add swap support
- ld hl,(U_DATA__U_PTAB)
+ ld hl,(_udata + U_DATA__U_PTAB)
or a
sbc hl,de
jr z, skip_copyback
; a moment
exx
ld hl,#U_DATA_STASH-0x8000
- ld de,#U_DATA
+ ld de,#_udata
ld bc,#U_DATA__TOTALSIZE
ldir
exx
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
; Ok our stack is now valid
call map_kernel_low
- ld hl, (U_DATA__U_PTAB)
+ ld hl, (_udata + U_DATA__U_PTAB)
or a
sbc hl,de
jr nz, switchin_failed ; invalid u_data
skip_copyback:
- ld sp, (U_DATA__U_SP)
- ld ix, (U_DATA__U_PTAB)
+ ld sp, (_udata + U_DATA__U_SP)
+ ld ix, (_udata + U_DATA__U_PTAB)
ld P_TAB__P_STATUS_OFFSET(ix), #P_RUNNING
ld a, P_TAB__P_PAGE_OFFSET(ix)
- ld (U_DATA__U_PAGE),a
+ ld (_udata + U_DATA__U_PAGE),a
ld a, P_TAB__P_PAGE_OFFSET+1(ix)
- ld (U_DATA__U_PAGE + 1),a
+ ld (_udata + U_DATA__U_PAGE + 1),a
ld hl,#0
ld (_runticks), hl
; Recover IX and IY, return value
pop hl
; if we pre-empted in an ISR IRQ's stay off, if not they get enabled
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
ld (_int_disabled), a
or a
ret nz
push ix
push iy
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; Parent state built and in u_data
; modify it for the child
; Map parent high page
- ld a,(U_DATA__U_PAGE+1)
+ ld a,(_udata + U_DATA__U_PAGE+1)
call map_page_low
; Copy udata
- ld hl, #U_DATA
+ ld hl, #_udata
ld de, #U_DATA_STASH - 0x8000
ld bc, #U_DATA__TOTALSIZE
ldir
copy_process:
ld de,#P_TAB__P_PAGE_OFFSET
add hl,de
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
call map_page_low
call setup_platform_copier
ld ix,#cp1ret
inc hl
cp (hl)
ret z
- ld a,(U_DATA__U_PAGE+1)
+ ld a,(_udata + U_DATA__U_PAGE+1)
call map_page_low
call setup_platform_copier
ld ix,#cp2ret
; of common memory. We do actually have a symbol for udata so
; eventually this needs to go away
;
-U_DATA .equ 0xF000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes)
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @ F000
;
; Space for the udata of a switched out process within the bank of
; memory that it uses. Normally placed at the very top
.globl l__COMMONMEM
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
;
; Buffers (we use asm to set this up as we need them in a special segment
map_process_always:
push af
push hl
- ld hl, #U_DATA__U_PAGE
+ ld hl, #_udata + U_DATA__U_PAGE
call map_process_hl
pop hl
pop af
dec a
ld a, (_blk_op + BLKPARAM_SWAP_PAGE)
jr nz, do_read_a
- ld a, (U_DATA__U_PAGE)
+ ld a, (_udata + U_DATA__U_PAGE)
do_read_a: call map_process_a
do_read: ld bc,#0xAB
inir
dec a
ld a, (_blk_op + BLKPARAM_SWAP_PAGE)
jr nz, do_write_a
- ld a, (U_DATA__U_PAGE)
+ ld a, (_udata + U_DATA__U_PAGE)
do_write_a: call map_process_a
do_write: ld bc,#0xAB
otir
; only reason to do otherwise is for speed. A custom bank logic aware
; bank to bank copier will give vastly better fork() performance.
;
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
+
;
; All of the fixed bank support is available as a library routine,
; however it is a performance sensitive area. Start with
; FUZIX mnemonics for memory addresses etc
-U_DATA .equ 0xF000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @ F000
Z80_TYPE .equ 0 ; CMOS
Z80_MMU_HOOKS .equ 0
.globl l__COMMONMEM
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; Base address of SIO/2 chip 0x80
out (0x38),a
ex af,af'
; Stack now invalid
- ld (U_DATA__U_SYSCALL_SP),sp
+ ld (_udata + U_DATA__U_SYSCALL_SP),sp
ld sp,#kstack_top
call unix_syscall_entry
; FIXME check di rules
; stack now invalid. Grab the new sp before we unbank the
; memory holding it
- ld sp,(U_DATA__U_SYSCALL_SP)
+ ld sp,(_udata + U_DATA__U_SYSCALL_SP)
ld a,#0x81 ; back to the user page
out (0x38),a
xor a
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80single.s"
.module usermem
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; exported symbols
.globl __uget
.globl l__COMMONMEM
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
;
out (0x30),a
ex af,af'
; Stack now invalid
- ld (U_DATA__U_SYSCALL_SP),sp
+ ld (_udata + U_DATA__U_SYSCALL_SP),sp
ld sp,#kstack_top
call unix_syscall_entry
; FIXME check di rules
; stack now invalid. Grab the new sp before we unbank the
; memory holding it
- ld sp,(U_DATA__U_SYSCALL_SP)
+ ld sp,(_udata + U_DATA__U_SYSCALL_SP)
ld a,#0x81 ; back to the user page
out (0x38),a
rlca
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80single.s"
.module usermem
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; exported symbols
.globl __uget
.module commonmem
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.area _COMMONMEM
; ------------------------------------------------------------------------------------------------
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xf800 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @ F800
Z80_TYPE .equ 0 ; Actually a T80
.include "socz80.def"
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (0xF000 upwards)
map_process_always:
map_process_always_di:
push hl
- ld hl, #U_DATA__U_PAGE
+ ld hl, #_udata + U_DATA__U_PAGE
call map_loadhl
pop hl
ret
.globl outstring, outde, outhl, outbc, outnewline, outchar, outcharhex
.include "socz80.def"
- .include "../kernel.def"
.include "kernel.def"
-
+ .include "../kernel-z80.def"
;
; These do not need to be in common memory as we don't have to
; pull udata remapping tricks on a 16K banked system. In the case of
push hl ; return code
push ix
push iy
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
; find another process to run (may select this one again)
call _getproc
; ------------- Our stack just left the building ---------------
; check u_data->u_ptab matches what we wanted
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
or a ; clear carry flag
sbc hl, de ; subtract, result will be zero if DE==HL
jr nz, switchinfail
; restore machine state -- note we may be returning from either
; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
pop iy
pop ix
pop hl ; return code
; enable interrupts, if the ISR isn't already running
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
ld (_int_disabled),a
or a
ret nz ; in ISR, leave interrupts off
; _switchin which will immediately return (appearing to be _dofork()
; returning) and with HL (ie return code) containing the child PID.
; Hurray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
;
; We will return on the parent stack with everything copied. We can
ld de, #P_TAB__P_PAGE_OFFSET
add hl, de
; parent mapping to be copied
- ld de, #U_DATA__U_PAGE
+ ld de, #_udata + U_DATA__U_PAGE
;
; Walk the 16K banks using a generic code pattern
.module usermem
.include "socz80.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "kernel.def"
; imported symbols
ugetputsetup:
; compute 32-bit dest address based on process MMU page and userspace address in DE
- ld hl, (U_DATA__U_PAGE) ; load 4K page address
+ ld hl, (_udata + U_DATA__U_PAGE) ; load 4K page address
; we shift HL 4 bits to the left (would need to handle overflow for future hardware with >16MB RAM)
add hl, hl
.globl nmi_handler
.globl interrupt_handler
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
;
; startup code. Runs from 0x100. The kernel is mapped into pages
-U_DATA .equ 0xF000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @ F000
Z80_TYPE .equ 1
.globl outstringhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (above 0xE000)
push bc
push de
push hl
- ld hl,(U_DATA__U_PAGE)
+ ld hl,(_udata + U_DATA__U_PAGE)
map_write_hl:
; Switch this to nextreg at some point FIXME
ld bc,#0x243b
.globl outstring, outde, outhl, outbc, outnewline, outchar, outcharhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.area _COMMONMEM
push hl ; return code
push ix
push iy
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
; find another process to run (may select this one again)
call _getproc
; ------- No stack -------
; check u_data->u_ptab matches what we wanted
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
or a ; clear carry flag
sbc hl, de ; subtract, result will be zero if DE==IX
jr nz, switchinfail
; restore machine state -- note we may be returning from either
; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
; ---- New task stack ----
pop hl ; return code
; enable interrupts, if the ISR isn't already running
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
ld (_int_disabled),a
or a
ret nz ; in ISR, leave interrupts off
; _switchin which will immediately return (appearing to be _dofork()
; returning) and with HL (ie return code) containing the child PID.
; Hurray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; now we're in a safe state for _switchin to return in the parent
; process.
; DE is now the 8 page pointers for the child
- ld hl, (U_DATA__U_PAGE) ; pointer to banks of parent
+ ld hl, (_udata + U_DATA__U_PAGE) ; pointer to banks of parent
; HL for the parent
.globl nmi_handler
.globl interrupt_handler
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
;
; startup code
.globl outstringhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (below 0x4000)
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80single.s"
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xE800 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 (we don't save istack)
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 @ E800
U_DATA_STASH .equ 0x7E00 ; 7E00-7FFF
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80fixedbank.s"
.globl l__COMMONMEM
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; KERNEL MEMORY BANK (below 0xE800, only accessible when the kernel is mapped)
map_process_always_di:
push af
push hl
- ld hl, #U_DATA__U_PAGE
+ ld hl, #_udata + U_DATA__U_PAGE
call map_process_hl
pop hl
pop af
.globl _bufpool
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.area _BUFFERS
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0x4100 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 (we don't save istack)
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 @4100
U_DATA_STASH .equ 0xFE00 ; FE00-FFFF
.globl _tape_err
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.area _COMMONMEM
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80fixedbank-banked.s"
.globl __uzero
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; KERNEL MEMORY BANK (above 08000, only accessible when the kernel is mapped)
push bc
ld bc, (map_reg)
ld (ksave_map), bc
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
ld b,a
ld (map_reg),bc
out (c),b
; Use helper as NMOS Z80 has bugs in this area
call ___hard_di
; Our banks
- ld a, (U_DATA__U_PAGE)
+ ld a, (_udata + U_DATA__U_PAGE)
ld c, a
ld a, (map_bank2 + 1) ; kernel is source
ld b, a
jr z, uput_out
exx
call ___hard_di
- ld a, (U_DATA__U_PAGE)
+ ld a, (_udata + U_DATA__U_PAGE)
ld b, a
ld a, (map_bank2 + 1) ; kernel is destination
ld c, a
.globl mapper_init
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (0x4000 upwards after the udata etc)
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xF000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256@F000
U_DATA_STASH .equ 0x7E00 ; 7E00-7FFF
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80fixedbank.s"
.globl l__COMMONMEM
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
;
; Buffers (we use asm to set this up as we need them in a special segment
map_process_always_di:
push af
push hl
- ld hl, #U_DATA__U_PAGE
+ ld hl, #_udata + U_DATA__U_PAGE
call map_process_hl
pop hl
pop af
; UZI mnemonics for memory addresses etc
; Move down to 0xF600 to fit the monitor in
-U_DATA .equ 0xF800 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256@F800
Z80_TYPE .equ 2
OS_BANK .equ 0x00 ; value from include/kernel.h
.include "kernel.def"
.include "../cpu-z180/z180.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; Buffers
/*
* One buffer for each tty. For now just the console
*/
-static char tbuf1[TTYSIZ];
+static unsigned char tbuf1[TTYSIZ];
+
+static tcflag_t console_mask[4] = {
+ _ISYS,
+ _OSYS,
+ _CSYS,
+ _LSYS
+};
+
+tcflag_t *termios_mask[NUM_DEV_TTY + 1] = {
+ NULL,
+ console_mask
+};
/*
* One entry per tty. The 0th entry is never used as tty minor 0 is
; of common memory. We do actually have a symbol for udata so
; eventually this needs to go away
;
-U_DATA .equ 0xE000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes)
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes@E000
;
; Space for the udata of a switched out process within the bank of
; memory that it uses. Normally placed at the very top
; approach. The morbidly curious can read the TRS80 model 1 bank to
; bank copier.
;
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80fixedbank.s"
; Minimal for now to get us up and running
;
- .module sbcv2
+ .module z280rc
; exported symbols
.globl init_early
.globl l__COMMONMEM
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
;
; Buffers (we use asm to set this up as we need them in a special segment
map_process_always_di:
push af
push hl
- ld hl, #U_DATA__U_PAGE
+ ld hl, #_udata + U_DATA__U_PAGE
call map_process_hl
pop hl
pop af
ld a,(_inint)
or a
jr nz, diediedie
- ld a,(U_DATA__U_INSYS)
+ ld a,(_udata + U_DATA__U_INSYS)
or a
jr nz, diediedie
; TODO - we need to go via the syscall signal path as we need this
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xF000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes@F000
Z80_TYPE .equ 0
PROGBASE .equ 0x0000
.globl outstring, outde, outhl, outbc, outnewline, outchar, outcharhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.area _COMMONMEM
push hl ; return code
push ix
push iy
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
; find another process to run (may select this one again)
call _getproc
ld (hl), a
not_swapped:
; check u_data->u_ptab matches what we wanted
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
or a ; clear carry flag
sbc hl, de ; subtract, result will be zero if DE==IX
jr nz, switchinfail
add hl, de
ld (hl), #P_RUNNING
- ld (U_DATA__U_PAGE), a ; save page offset
+ ld (_udata + U_DATA__U_PAGE), a ; save page offset
; runticks = 0
ld hl, #0
ld (_runticks), hl
; restore machine state -- note we may be returning from either
; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
ld hl, #0
add hl, sp
pop hl ; return code
; enable interrupts, if the ISR isn't already running
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
or a
ret z ; in ISR, leave interrupts off
ei
; _switchin which will immediately return (appearing to be _dofork()
; returning) and with HL (ie return code) containing the child PID.
; Hurray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; now we're in a safe state for _switchin to return in the parent
; process.
; --------- copy process ---------
- ld hl, #U_DATA__U_PAGE
+ ld hl, #_udata + U_DATA__U_PAGE
ld a, (hl)
call map_process_a
- ld hl, (U_DATA__U_PTAB)
+ ld hl, (_udata + U_DATA__U_PTAB)
push hl
call _swapout
pop de
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
-; COMMON MEMORY BANK (0xF000 upwards)
+; COMMON MEMORY BANK
; -----------------------------------------------------------------------------
.area _COMMONMEM
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0xF400 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @ F400
U_DATA_STASH .equ 0xEE00 ; EE00-EFFF
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80fixedbank.s"
.globl outstringhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (0xF000 upwards)
map_process_always:
map_process_always_di:
push af
- ld a, (U_DATA__U_PAGE)
+ ld a, (_udata + U_DATA__U_PAGE)
out (21), a
pop af
ret
; something bad has happened to our process (or the kernel)
;
badstack:
- ld a, (U_DATA__U_INSYS)
+ ld a, (_udata + U_DATA__U_INSYS)
or a
jr nz, badbadstack
ld a, (_inint)
call _panic
badstackifu:
- ld a, (U_DATA__U_INSYS)
+ ld a, (_udata + U_DATA__U_INSYS)
or a
jr nz, do_mmu_kernel
ld a, (_inint)
ld (mmusave),a
jp mmu_irq_ret
- ld a, (U_DATA__U_INSYS)
+ ld a, (_udata + U_DATA__U_INSYS)
or a
ld a, (_inint)
or a
badstackirq:
- ld a, (U_DATA__U_INSYS)
+ ld a, (_udata + U_DATA__U_INSYS)
or a
jr nz, badbadstack_irq
ld a, (_inint)
call map_save_kernel
ld hl,#9
push hl
- ld hl,(U_DATA__U_PTAB)
+ ld hl,(_udata + U_DATA__U_PTAB)
push hl
call _ssig
pop hl
; This will complete the IRQ and then hit preemption at which
; point it'll call switchout, chksigs and vanish forever
badstackirqifu:
- ld a, (U_DATA__U_INSYS)
+ ld a, (_udata + U_DATA__U_INSYS)
or a
jr nz, do_mmu_kernel_irq
ld a, (_inint)
.globl _devmem_read
.globl _devmem_write
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
.area _CODE
_devmem_write:
_devmem_go:
ld (_rd_dst_userspace), a ; 1 = userspace
; load the other parameters
- ld hl, (U_DATA__U_BASE)
+ ld hl, (_udata + U_DATA__U_BASE)
ld (_rd_dst_address), hl
- ld hl, (U_DATA__U_OFFSET)
+ ld hl, (_udata + U_DATA__U_OFFSET)
ld (_rd_src_address), hl
- ld hl, (U_DATA__U_OFFSET+2)
+ ld hl, (_udata + U_DATA__U_OFFSET+2)
ld (_rd_src_address+2), hl
- ld hl, (U_DATA__U_COUNT)
+ ld hl, (_udata + U_DATA__U_COUNT)
ld (_rd_cpy_count), hl
; for single byte transfers we can optimise away the outer loop
dec l ; test for HL=1
ld hl, #_kernel_pages ; get kernel page table
jr rd_do_translate
rd_translate_userspace:
- ld hl, #U_DATA__U_PAGE ; get user process page table
+ ld hl, #_udata + U_DATA__U_PAGE ; get user process page table
rd_do_translate:
add hl, bc ; add index to base ptr (uint8_t *)
ld a, (hl) ; load the page number from the page table
.globl _ds1302_get_pin_data
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; DS1302 interface
; FUZIX mnemonics for memory addresses etc
-U_DATA .equ 0xF000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256@F000
Z80_TYPE .equ 0 ; just an old good Z80
USE_FANCY_MONITOR .equ 1 ; disabling this saves around approx 0.5KB
.module tricks
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
TOP_PORT .equ MPGSEL_3
ld de, #P_TAB__P_PAGE_OFFSET
add hl, de
; hl now points into the child pages
- ld de, #U_DATA__U_PAGE
+ ld de, #_udata + U_DATA__U_PAGE
; and de is the parent
fork_next:
ld a,(hl)
.globl outchar
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
;=========================================================================
; Constants
map_process_always:
map_process_always_di:
push hl
- ld hl,#U_DATA__U_PAGE
+ ld hl,#_udata + U_DATA__U_PAGE
jr map_process_2_pophl_ret
;=========================================================================
.globl nmi_handler
.globl interrupt_handler
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
;
; startup code
.module fdc765
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.globl map_process_always
.globl map_kernel
; UZI mnemonics for memory addresses etc
; We stick it straight after the tag
-U_DATA .equ 0xF000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256@F000
Z80_TYPE .equ 1
.globl outstringhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (below 0x4000)
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.include "../lib/z80single.s"
; UZI mnemonics for memory addresses etc
-U_DATA .equ 0x4000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @4000
U_DATA_STASH .equ 0xFD00 ; FD00-FEFF
.globl outstring, outde, outhl, outbc, outnewline, outchar, outcharhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.area _COMMONMEM
push hl ; return code
push ix
push iy
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
;
; We are now running on the sleeping process stack. The switchin
;
; Stash the uarea back into process memory
- ld hl, (U_DATA__U_PAGE)
+ ld hl, (_udata + U_DATA__U_PAGE)
ld a, l
ld bc, #0x7ffd
or #0x18
out (c), a
; This includes the stacks, so be careful on restore
- ld hl, #U_DATA
+ ld hl, #_udata
ld de, #U_DATA_STASH
ld bc, #U_DATA__TOTALSIZE
ldir
;
exx
ld hl, #U_DATA_STASH
- ld de, #U_DATA
+ ld de, #_udata
ld bc, #U_DATA__TOTALSIZE
ldir
exx
nofliplow:
; check u_data->u_ptab matches what we wanted
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
or a ; clear carry flag
sbc hl, de ; subtract, result will be zero if DE == HL
jr nz, switchinfail
; wants optimising up a bit
- ld ix, (U_DATA__U_PTAB)
+ ld ix, (_udata + U_DATA__U_PTAB)
; next_process->p_status = P_RUNNING
ld P_TAB__P_STATUS_OFFSET(ix), #P_RUNNING
; Fix any moved page pointers
; Just do one byte as that is all we use on this platform
ld a, P_TAB__P_PAGE_OFFSET(ix)
- ld (U_DATA__U_PAGE), a
+ ld (_udata + U_DATA__U_PAGE), a
; runticks = 0
ld hl, #0
ld (_runticks), hl
; restore machine state -- note we may be returning from either
; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
;
; We can now use the stack again
pop hl ; return code
; enable interrupts, if the ISR isn't already running
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
or a
ret nz ; in ISR, leave interrupts off
ei
; _switchin which will immediately return (appearing to be _dofork()
; returning) and with HL (ie return code) containing the child PID.
; Hurray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; now we're in a safe state for _switchin to return in the parent
; process.
add hl, de
; load p_page
ld c, (hl)
- ld hl, (U_DATA__U_PAGE)
+ ld hl, (_udata + U_DATA__U_PAGE)
ld a, l
;
; Copy done
- ld a, (U_DATA__U_PAGE) ; parent memory
+ ld a, (_udata + U_DATA__U_PAGE) ; parent memory
or #0x18 ; get the right ROMs
ld bc, #0x7ffd
out (c), a ; Switch context to parent in 0xC000+
; We are going to copy the uarea into the parents uarea stash
; we must not touch the parent uarea after this point, any
; changes only affect the child
- ld hl, #U_DATA ; copy the udata from common into the
+ ld hl, #_udata ; copy the udata from common into the
ld de, #U_DATA_STASH ; target process
ld bc, #U_DATA__TOTALSIZE
ldir
push af
ld a, (current_map)
ld (ksave_map), a
- ld a, (U_DATA__U_PAGE)
+ ld a, (_udata + U_DATA__U_PAGE)
call switch_bank
pop af
ret
.globl nmi_handler
.globl interrupt_handler
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
; startup code
;
; UZI mnemonics for memory addresses etc
; We stick it straight after the tag
-U_DATA .equ 0x2204 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 @ 2204
U_DATA_STASH .equ 0xFE00 ; FE00-FFFF
.globl __stub_3_2
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
; COMMON MEMORY BANK (below 0xC000)
push af
ld a, (current_map)
ld (ksave_map), a
- ld a, (U_DATA__U_PAGE)
+ ld a, (_udata + U_DATA__U_PAGE)
call switch_bank
pop af
ret
.globl nmi_handler
.globl interrupt_handler
- .include "../kernel.def"
.include "kernel.def"
+ .include "../kernel-z80.def"
;
; startup code. Runs from 0x100. The kernel is mapped into pages
-U_DATA .equ 0xF000 ; (this is struct u_data from kernel.h)
-U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes.
+U_DATA__TOTALSIZE .equ 0x200 ; 256+256 bytes @ F000
Z80_TYPE .equ 1
.globl outstring, outde, outhl, outbc, outnewline, outchar, outcharhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
.area _COMMONMEM
push hl ; return code
push ix
push iy
- ld (U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
+ ld (_udata + U_DATA__U_SP), sp ; this is where the SP is restored in _switchin
; find another process to run (may select this one again)
call _getproc
; ------- No stack -------
; check u_data->u_ptab matches what we wanted
- ld hl, (U_DATA__U_PTAB) ; u_data->u_ptab
+ ld hl, (_udata + U_DATA__U_PTAB) ; u_data->u_ptab
sbc hl, de ; subtract, result will be zero if DE==IX
jr nz, switchinfail
; restore machine state -- note we may be returning from either
; _switchout or _dofork
- ld sp, (U_DATA__U_SP)
+ ld sp, (_udata + U_DATA__U_SP)
; ---- New task stack ----
pop hl ; return code
; enable interrupts, if the ISR isn't already running
- ld a, (U_DATA__U_ININTERRUPT)
+ ld a, (_udata + U_DATA__U_ININTERRUPT)
ld (_int_disabled),a
or a
ret nz ; in ISR, leave interrupts off
; _switchin which will immediately return (appearing to be _dofork()
; returning) and with HL (ie return code) containing the child PID.
; Hurray.
- ld (U_DATA__U_SP), sp
+ ld (_udata + U_DATA__U_SP), sp
; now we're in a safe state for _switchin to return in the parent
; process.
ret
fork_copy:
- ld hl, (U_DATA__U_TOP)
+ ld hl, (_udata + U_DATA__U_TOP)
ld de, #0x0fff
add hl, de ; + 0x1000 (-1 for the rounding to follow)
ld a, h
ld de, #P_TAB__P_PAGE_OFFSET
add hl, de
; hl now points into the child pages
- ld de, #U_DATA__U_PAGE
+ ld de, #_udata + U_DATA__U_PAGE
; and de is the parent
fork_next:
.globl outstringhex
.include "kernel.def"
- .include "../kernel.def"
+ .include "../kernel-z80.def"
; -----------------------------------------------------------------------------
-; COMMON MEMORY BANK (above 0xE000)
+; COMMON MEMORY BANK
; -----------------------------------------------------------------------------
.area _COMMONMEM
; -----------------------------------------------------------------------------
-; KERNEL CODE BANK (below 0xC000, only accessible when the kernel is mapped)
+; KERNEL CODE BANK (only accessible when the kernel is mapped)
; -----------------------------------------------------------------------------
.area _CODE
push af
push bc
push hl
- ld hl,(U_DATA__U_PAGE)
+ ld hl,(_udata + U_DATA__U_PAGE)
map_write_hl:
ld (current_map),hl
;
.module usermem
.include "platform/kernel.def"
- .include "kernel.def"
+ .include "kernel-z80.def"
; exported symbols
.globl __uget
.module usermem32
.include "platform/kernel.def"
- .include "kernel.def"
+ .include "kernel-z80.def"
; exported symbols
.globl __uget
ld e, 6(ix)
ld d, 7(ix)
; And now load ix with our paging pointer
- ld ix,#U_DATA__U_PAGE
+ ld ix,#_udata + U_DATA__U_PAGE
ret
__uget:
or c
ret z
push ix
- ld ix,#U_DATA__U_PAGE
+ ld ix,#_udata + U_DATA__U_PAGE
call user_mapping
jr z, zeroit_1
call zeroit
push hl
push bc
bit 7,h
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
jr z, ugetcl
- ld a,(U_DATA__U_PAGE + 1)
+ ld a,(_udata + U_DATA__U_PAGE + 1)
res 7,h
ugetcl:
call map_page_low
bit 7,h
jr z, ugetwl
; High page - no wrap possible
- ld a,(U_DATA__U_PAGE + 1)
+ ld a,(_udata + U_DATA__U_PAGE + 1)
call map_page_low
res 7,h
ld a,(hl)
jp map_kernel_low
ugetwl:
; Low page - we might be fetching 7FFF/8000
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
call map_page_low
ld a,(hl)
inc hl
jr z, normal_wl ; No split
; We fetched 7FFF/8000
ld l,a
- ld a,(U_DATA__U_PAGE + 1)
+ ld a,(_udata + U_DATA__U_PAGE + 1)
call map_page_low
ld a,(0) ; Split can only mean one address
ld h,a
push de
push bc
bit 7,h
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
jr z, uputcl
- ld a,(U_DATA__U_PAGE + 1)
+ ld a,(_udata + U_DATA__U_PAGE + 1)
res 7,h
uputcl:
call map_page_low
push bc
bit 7,h
jr z, uputwl
- ld a,(U_DATA__U_PAGE + 1)
+ ld a,(_udata + U_DATA__U_PAGE + 1)
call map_page_low
res 7,h
ld (hl),e
ld (hl),d
jp map_kernel_low
uputwl:
- ld a,(U_DATA__U_PAGE)
+ ld a,(_udata + U_DATA__U_PAGE)
call map_page_low
ld (hl),e
inc hl
bit 7,h
jr z, normal_pwl
- ld a,(U_DATA__U_PAGE + 1)
+ ld a,(_udata + U_DATA__U_PAGE + 1)
call map_page_low
ld a,d
ld (0),a ; Split can only mean one address
.module usermem
.include "platform/kernel.def"
- .include "kernel.def"
+ .include "kernel-z80.def"
; exported symbols
.globl __uget