Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [rom/] [reset.asm] - Diff between revs 371 and 384

Show entire file | Details | Blame | View Log

Rev 371 Rev 384
Line 17... Line 17...
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
;THE SOFTWARE.
;THE SOFTWARE.
 
.include        "sysvars.inc"
 
.include        "sysdefs.inc"
 
.include        "spectranet.inc"
 
.include        "w5100_defs.inc"
 
.include        "flashconf.inc"
 
.include        "ctrlchars.inc"
 
.include        "page3.xinc"
 
 
; Locations in the data rom that need to be copied.
; Locations in the data rom that need to be copied.
; The jump table lives in the first 256 bytes of ROM3
; The jump table lives in the first 256 bytes of ROM3
JUMPTABLE_COPYFROM      equ 0x1F00
JUMPTABLE_COPYFROM:     equ 0x1F00
JUMPTABLE_SIZE          equ 0xF8
JUMPTABLE_SIZE:         equ 0xF8
UPPER_ENTRYPT           equ 0x1FF8
UPPER_ENTRYPT:          equ 0x1FF8
UPPER_ENTRYPT_SIZE      equ 0x08
UPPER_ENTRYPT_SIZE:     equ 0x08
 
 
; Initialization routines that are run on reset.
; Initialization routines that are run on reset.
;
;
; The first thing that's done is to page in the configuration area into
; The first thing that's done is to page in the configuration area into
; paging area B. This is nominally in the last page of the flash chip
; paging area B. This is nominally in the last page of the flash chip
; (page 0x20, chip 0). From this we can figure out what we're supposed
; (page 0x20, chip 0). From this we can figure out what we're supposed
; to do next.
; to do next.
;
;
J_reset
.text
 
.globl J_reset
 
J_reset:
        ; a delay loop to allow the rubber key machine's very slow reset
        ; a delay loop to allow the rubber key machine's very slow reset
        ; circuit to become quiescent.
        ; circuit to become quiescent.
        ld bc, 0xFFFF
        ld bc, 0xFFFF
.delay
.delay0:
        ld (ix+7), a            ; a nice long instruction
        ld (ix+7), a            ; a nice long instruction
        dec bc
        dec bc
        ld a, b
        ld a, b
        or c
        or c
        jr nz, .delay
        jr nz, .delay0
 
 
        ; Clear upper page.
        ; Clear upper page.
        ld sp, NMISTACK         ; use our own memory for the stack
        ld sp, NMISTACK         ; use our own memory for the stack
        ld hl, 0x3000           ; Clear down the fixed RAM page.
        ld hl, 0x3000           ; Clear down the fixed RAM page.
        ld de, 0x3001
        ld de, 0x3001
Line 133... Line 142...
        call F_clear
        call F_clear
 
 
        ld sp, 32767            ; lowest guaranteed stack addr
        ld sp, 32767            ; lowest guaranteed stack addr
        ld hl, 0                ; We're done so put 0x0000
        ld hl, 0                ; We're done so put 0x0000
        push hl                 ; on the stack
        push hl                 ; on the stack
        jp UNPAGE               ; unpage (a ret instruction)
        jp PAGEOUT              ; unpage (a ret instruction)
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_initroms
; F_initroms
; Pages each 4k page of flash, checking for a boot vector in each.
; Pages each 4k page of flash, checking for a boot vector in each.
; When a boot vector is found, that address is CALLed. That ROM then
; When a boot vector is found, that address is CALLed. That ROM then
; gets an opportunity to do whatever initialization it needs to do.
; gets an opportunity to do whatever initialization it needs to do.
; Note this is how the W5100 actually gets configured - for the
; Note this is how the W5100 actually gets configured - for the
; Spectranet to work at all, the Spectranet utility ROM must occupy some
; Spectranet to work at all, the Spectranet utility ROM must occupy some
; page somewhere in the flash chip and get initialized.
; page somewhere in the flash chip and get initialized.
F_initroms
.globl F_initroms
 
F_initroms:
        ld b, 1         ; start from page 2 (page 0=fixed, page 1=data)
        ld b, 1         ; start from page 2 (page 0=fixed, page 1=data)
        ld hl, vectors  ; pointer to the valid vector table
        ld hl, vectors  ; pointer to the valid vector table
.initloop
.initloop1:
        inc b
        inc b
        ld a, 0x1F
        ld a, 0x1F
        cp b            ; last ROM?
        cp b            ; last ROM?
        ret z           ; finished
        ret z           ; finished
        ld a, b
        ld a, b
        call F_checkromsig      ; Z = valid signature found for executable
        call F_checkromsig      ; Z = valid signature found for executable
        jr z, .rominit          ; Valid sig found
        jr z, .rominit1         ; Valid sig found
        cp 0xFF                 ; empty slot
        cp 0xFF                 ; empty slot
        jr z, .skip
        jr z, .skip1
        ld (hl), 0xFF           ; "occupied but not executable"
        ld (hl), 0xFF           ; "occupied but not executable"
.skip
.skip1:
        inc hl
        inc hl
        jr .initloop
        jr .initloop1
 
 
.rominit
.rominit1:
        ; Put an entry in the vector table to indicate the ROM page has
        ; Put an entry in the vector table to indicate the ROM page has
        ; a valid vector table.
        ; a valid vector table.
        ld a, (0x2001)          ; fetch the ROM ID
        ld a, (0x2001)          ; fetch the ROM ID
        ld (hl), a              ; store it in the rom vector table
        ld (hl), a              ; store it in the rom vector table
        inc hl                  ; point to next entry in the table
        inc hl                  ; point to next entry in the table
        push hl                 ; save the table address pointer
        push hl                 ; save the table address pointer
        push bc                 ; save which ROM we've examined
        push bc                 ; save which ROM we've examined
        ld hl, (ROM_INIT_VECTOR) ; get initialization vector from ROM
        ld hl, (ROM_INIT_VECTOR) ; get initialization vector from ROM
        ld a, 0xFF
        ld a, 0xFF
        cp h                    ; does the vector point somewhere useful?
        cp h                    ; does the vector point somewhere useful?
        jr z, .returnaddr       ; no - skip calling it
        jr z, .returnaddr1      ; no - skip calling it
        ld de, .returnaddr      ; get return address
        ld de, .returnaddr1     ; get return address
        push de                 ; stack it to simulate CALL
        push de                 ; stack it to simulate CALL
        jp (hl)                 ; and call it
        jp (hl)                 ; and call it
.returnaddr
.returnaddr1:
        pop bc
        pop bc
        pop hl
        pop hl
        jr .initloop
        jr .initloop1
 
 
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
; F_initfs
; F_initfs
; Initializes filesystems.
; Initializes filesystems.
; TODO: Initialize multiple filesystems.
; TODO: Initialize multiple filesystems.
F_initfs
.globl F_initfs
 
F_initfs:
        ld a, CONFIGPAGE        ; config page
        ld a, CONFIGPAGE        ; config page
        call F_setpageA
        call F_setpageA
        ld a, (0x1000+DEF_FS_PROTO0)
        ld a, (0x1000+DEF_FS_PROTO0)
        and a                   ; empty string?
        and a                   ; empty string?
        ret z
        ret z
Line 202... Line 213...
        ld bc, 0x80
        ld bc, 0x80
        ldir
        ldir
        ld ix, FSTAB
        ld ix, FSTAB
        ld a, 0
        ld a, 0
        call F_mount
        call F_mount
        jr c, .error
        jr c, .error2
        ret
        ret
.error
.error2:
        ld hl, 0x3000
        ld hl, 0x3000
        call F_itoh8
        call F_itoh8
        ld hl, 0x3000
        ld hl, 0x3000
        call F_print
        call F_print
        ret
        ret
 
 
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
; F_w5100init
; F_w5100init
; Initialize the W5100 - MAC address and hardware registers.
; Initialize the W5100 - MAC address and hardware registers.
F_w5100init
.globl F_w5100init
 
F_w5100init:
        ; Set up memory pages to configure the hardware
        ; Set up memory pages to configure the hardware
        ld a, REGPAGE           ; registers are in page 0 of the W5100
        ld a, REGPAGE           ; registers are in page 0 of the W5100
        call F_setpageA         ; page it into area A
        call F_setpageA         ; page it into area A
        ld a, CONFIGPAGE        ; configuration page (flash)
        ld a, CONFIGPAGE        ; configuration page (flash)
        call F_setpageB         ; paged into area B
        call F_setpageB         ; paged into area B
Line 237... Line 249...
        ld (TMSR), a
        ld (TMSR), a
        ld (RMSR), a
        ld (RMSR), a
        ld a, %11101111         ; set the IMR
        ld a, %11101111         ; set the IMR
        ld (IMR), a
        ld (IMR), a
        ret
        ret
 
.data
STR_bootmsg
STR_bootmsg:
        defb "Alioth Spectranet ",0
        defb "Alioth Spectranet ",0
        include "ver.asm"       ; include the build number file
        include "ver.xinc"      ; include the build number file
STR_mounting
STR_mounting:
        defb "FS mount\n",0
        defb "FS mount",NEWLINE,0
FSTAB
FSTAB:
        defw 0x3001             ; TODO - proper filesystem things
        defw 0x3001             ; TODO - proper filesystem things
        defw 0x3007
        defw 0x3007
        defw 0x3030
        defw 0x3030
        defw 0x3060
        defw 0x3060
        defw 0x3070
        defw 0x3070
MOUNT   equ  0x3EA8