2007-04-22 00:15:45 +02:00
|
|
|
;
|
|
|
|
; Copyright (c) 2004, Adam Dunkels.
|
|
|
|
; All rights reserved.
|
|
|
|
;
|
|
|
|
; Redistribution and use in source and binary forms, with or without
|
|
|
|
; modification, are permitted provided that the following conditions
|
|
|
|
; are met:
|
|
|
|
; 1. Redistributions of source code must retain the above copyright
|
|
|
|
; notice, this list of conditions and the following disclaimer.
|
|
|
|
; 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
; notice, this list of conditions and the following disclaimer in the
|
|
|
|
; documentation and/or other materials provided with the distribution.
|
|
|
|
; 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
; may be used to endorse or promote products derived from this software
|
|
|
|
; without specific prior written permission.
|
|
|
|
;
|
|
|
|
; THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
; ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
; SUCH DAMAGE.
|
|
|
|
;
|
|
|
|
; This file is part of the Contiki operating system.
|
|
|
|
;
|
|
|
|
; Author: Adam Dunkels <adam@sics.se>
|
|
|
|
;
|
2007-12-15 01:14:18 +01:00
|
|
|
; $Id: mtarch-asm.S,v 1.1 2007/12/15 00:14:19 oliverschmidt Exp $
|
2007-04-22 00:15:45 +02:00
|
|
|
;
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
.import __ZP_START__
|
|
|
|
|
|
|
|
.import _mtarch_asm_threadspreg
|
|
|
|
.import _mtarch_asm_threadzp
|
|
|
|
.import _mtarch_asm_threadstack
|
|
|
|
|
|
|
|
.export _mtarch_asm_start
|
|
|
|
.export _mtarch_asm_yield
|
|
|
|
.export _mtarch_asm_exec
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
.bss
|
2007-08-10 12:45:35 +02:00
|
|
|
kernelspreg: .res 1
|
|
|
|
zpsave: .res 2
|
2007-04-22 00:15:45 +02:00
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
zpspace = 26 ; see <cc65 source>/asminc/zeropage.inc
|
2007-04-22 00:15:45 +02:00
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
.code
|
2007-08-10 12:45:35 +02:00
|
|
|
; Switch to thread defined by threadzp, threadstack and threadspreg.
|
|
|
|
; The kernel CPU stack is swapped onto the threadstack, and the
|
|
|
|
; CPU stack pointer is saved to the local variable "kernelspreg".
|
|
|
|
; Also, the zeropage variables are saved.
|
2007-04-22 00:15:45 +02:00
|
|
|
_mtarch_asm_exec:
|
|
|
|
sei
|
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
; Save kernel CPU stack pointer
|
2007-04-22 00:15:45 +02:00
|
|
|
tsx
|
|
|
|
stx kernelspreg
|
2007-08-10 12:45:35 +02:00
|
|
|
|
|
|
|
; Save zp locations FE/FF
|
|
|
|
lda $FE
|
|
|
|
sta zpsave
|
|
|
|
lda $FF
|
|
|
|
sta zpsave+1
|
|
|
|
|
|
|
|
; Get zero page buffer addr
|
2007-04-22 00:15:45 +02:00
|
|
|
lda _mtarch_asm_threadzp
|
2007-08-10 12:45:35 +02:00
|
|
|
sta $FE
|
2007-04-22 00:15:45 +02:00
|
|
|
lda _mtarch_asm_threadzp+1
|
2007-08-10 12:45:35 +02:00
|
|
|
sta $FF
|
2007-04-22 00:15:45 +02:00
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
; Swap zero page content with buffer content
|
2007-04-22 00:15:45 +02:00
|
|
|
ldy #0
|
|
|
|
: lda <__ZP_START__,y
|
|
|
|
tax
|
2007-08-10 12:45:35 +02:00
|
|
|
lda ($FE),y
|
2007-04-22 00:15:45 +02:00
|
|
|
sta <__ZP_START__,y
|
|
|
|
txa
|
2007-08-10 12:45:35 +02:00
|
|
|
sta ($FE),y
|
2007-04-22 00:15:45 +02:00
|
|
|
iny
|
2007-08-10 12:45:35 +02:00
|
|
|
cpy #zpspace
|
2007-04-22 00:15:45 +02:00
|
|
|
bne :-
|
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
; Get CPU stack buffer addr
|
2007-04-22 00:15:45 +02:00
|
|
|
lda _mtarch_asm_threadstack
|
2007-08-10 12:45:35 +02:00
|
|
|
sta $FE
|
2007-04-22 00:15:45 +02:00
|
|
|
lda _mtarch_asm_threadstack+1
|
2007-08-10 12:45:35 +02:00
|
|
|
sta $FF
|
2007-04-22 00:15:45 +02:00
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
; Get CPU stack size
|
2007-04-22 00:15:45 +02:00
|
|
|
ldy kernelspreg ; Determine the smallest of the two stack pointers,
|
|
|
|
cpy _mtarch_asm_threadspreg ; as we only need to swap the used part of the stack.
|
|
|
|
bcc :+
|
|
|
|
ldy _mtarch_asm_threadspreg
|
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
; Swap CPU stack content with buffer content
|
2007-04-22 00:15:45 +02:00
|
|
|
: lda $0100,y
|
|
|
|
tax
|
2007-08-10 12:45:35 +02:00
|
|
|
lda ($FE),y
|
2007-04-22 00:15:45 +02:00
|
|
|
sta $0100,y
|
|
|
|
txa
|
2007-08-10 12:45:35 +02:00
|
|
|
sta ($FE),y
|
2007-04-22 00:15:45 +02:00
|
|
|
iny
|
|
|
|
bne :-
|
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
; Restore zp locations FE/FF
|
|
|
|
lda zpsave
|
|
|
|
sta $FE
|
|
|
|
lda zpsave+1
|
|
|
|
sta $FF
|
|
|
|
|
|
|
|
; Set thread CPU stack pointer
|
2007-04-22 00:15:45 +02:00
|
|
|
ldx _mtarch_asm_threadspreg
|
|
|
|
txs
|
|
|
|
|
|
|
|
pla
|
|
|
|
tay
|
|
|
|
pla
|
|
|
|
tax
|
|
|
|
pla
|
|
|
|
rti
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
2007-08-10 12:45:35 +02:00
|
|
|
; Switch from thread defined by threadzp, threadstack and threadspreg.
|
|
|
|
; The kernel CPU stack is swapped back from the threadstack, and the
|
|
|
|
; CPU stack pointer is restored from the local variable "kernelspreg".
|
|
|
|
; Also, the zeropage variables are restored.
|
2007-04-22 00:15:45 +02:00
|
|
|
_mtarch_asm_yield:
|
|
|
|
php
|
|
|
|
pha
|
|
|
|
txa
|
|
|
|
pha
|
|
|
|
tya
|
|
|
|
pha
|
|
|
|
|
|
|
|
sei
|
|
|
|
tsx ; The rts adds 1 to the PC
|
|
|
|
; saved on the stack. We want
|
|
|
|
lda $0105,x ; the stack to look like is would
|
|
|
|
clc ; do inside of an interrupt
|
|
|
|
adc #1 ; (this is what the 'rts' does,
|
|
|
|
sta $0105,x ; but not the 'rti').
|
|
|
|
lda $0106,x
|
|
|
|
adc #0
|
|
|
|
sta $0106,x
|
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
; Save thread CPU stack pointer
|
2007-04-22 00:15:45 +02:00
|
|
|
tsx
|
|
|
|
stx _mtarch_asm_threadspreg
|
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
; Save zp locations FE/FF
|
|
|
|
lda $FE
|
|
|
|
sta zpsave
|
|
|
|
lda $FF
|
|
|
|
sta zpsave+1
|
|
|
|
|
|
|
|
; Get zero page buffer addr
|
2007-04-22 00:15:45 +02:00
|
|
|
lda _mtarch_asm_threadzp
|
2007-08-10 12:45:35 +02:00
|
|
|
sta $FE
|
2007-04-22 00:15:45 +02:00
|
|
|
lda _mtarch_asm_threadzp+1
|
2007-08-10 12:45:35 +02:00
|
|
|
sta $FF
|
2007-04-22 00:15:45 +02:00
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
; Swap zero page content with buffer content
|
|
|
|
ldy #0
|
2007-04-22 00:15:45 +02:00
|
|
|
: lda <__ZP_START__,y
|
|
|
|
tax
|
2007-08-10 12:45:35 +02:00
|
|
|
lda ($FE),y
|
2007-04-22 00:15:45 +02:00
|
|
|
sta <__ZP_START__,y
|
|
|
|
txa
|
2007-08-10 12:45:35 +02:00
|
|
|
sta ($FE),y
|
2007-04-22 00:15:45 +02:00
|
|
|
iny
|
2007-08-10 12:45:35 +02:00
|
|
|
cpy #zpspace
|
2007-04-22 00:15:45 +02:00
|
|
|
bne :-
|
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
; Get CPU stack buffer addr
|
2007-04-22 00:15:45 +02:00
|
|
|
lda _mtarch_asm_threadstack
|
2007-08-10 12:45:35 +02:00
|
|
|
sta $FE
|
2007-04-22 00:15:45 +02:00
|
|
|
lda _mtarch_asm_threadstack+1
|
2007-08-10 12:45:35 +02:00
|
|
|
sta $FF
|
2007-04-22 00:15:45 +02:00
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
; Get CPU stack size
|
|
|
|
ldy kernelspreg ; Determine the smallest of the two stack pointers,
|
|
|
|
cpy _mtarch_asm_threadspreg ; as we only need to swap the used part of the stack.
|
|
|
|
bcc :+
|
|
|
|
ldy _mtarch_asm_threadspreg
|
|
|
|
|
|
|
|
; Swap CPU stack content with buffer content
|
2007-04-22 00:15:45 +02:00
|
|
|
: lda $0100,y
|
|
|
|
tax
|
2007-08-10 12:45:35 +02:00
|
|
|
lda ($FE),y
|
2007-04-22 00:15:45 +02:00
|
|
|
sta $0100,y
|
|
|
|
txa
|
2007-08-10 12:45:35 +02:00
|
|
|
sta ($FE),y
|
2007-04-22 00:15:45 +02:00
|
|
|
iny
|
|
|
|
bne :-
|
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
; Restore zp locations FE/FF
|
|
|
|
lda zpsave
|
|
|
|
sta $FE
|
|
|
|
lda zpsave+1
|
|
|
|
sta $FF
|
|
|
|
|
|
|
|
; Set kernel CPU stack pointer
|
2007-04-22 00:15:45 +02:00
|
|
|
ldx kernelspreg
|
|
|
|
txs
|
|
|
|
|
|
|
|
cli
|
|
|
|
rts
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
_mtarch_asm_start:
|
2007-08-10 12:45:35 +02:00
|
|
|
; Save zp locations FE/FF
|
|
|
|
lda $FE
|
|
|
|
sta zpsave
|
|
|
|
lda $FF
|
|
|
|
sta zpsave+1
|
|
|
|
|
|
|
|
; Get zero page buffer addr
|
2007-04-22 00:15:45 +02:00
|
|
|
lda _mtarch_asm_threadzp
|
2007-08-10 12:45:35 +02:00
|
|
|
sta $FE
|
2007-04-22 00:15:45 +02:00
|
|
|
lda _mtarch_asm_threadzp+1
|
2007-08-10 12:45:35 +02:00
|
|
|
sta $FF
|
2007-04-22 00:15:45 +02:00
|
|
|
|
2007-08-10 12:45:35 +02:00
|
|
|
; Copy zero page content to buffer
|
|
|
|
ldy #$00
|
2007-04-22 00:15:45 +02:00
|
|
|
: lda <__ZP_START__,y
|
2007-08-10 12:45:35 +02:00
|
|
|
sta ($FE),y
|
2007-04-22 00:15:45 +02:00
|
|
|
iny
|
2007-08-10 12:45:35 +02:00
|
|
|
cpy #zpspace
|
2007-04-22 00:15:45 +02:00
|
|
|
bne :-
|
2007-08-10 12:45:35 +02:00
|
|
|
|
|
|
|
; Restore zp locations FE/FF
|
|
|
|
lda zpsave
|
|
|
|
sta $FE
|
|
|
|
lda zpsave+1
|
|
|
|
sta $FF
|
|
|
|
|
2007-04-22 00:15:45 +02:00
|
|
|
rts
|
|
|
|
;---------------------------------------------------------------------
|