OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [disk/] [tools/] [mkmboot/] [stage1/] [mbr.s] - Blame information for rev 17

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 hellwig
;
2
; mbr.s -- the master boot record
3
;
4
 
5
; Runtime environment:
6
;
7
; This code must be loaded and started at 0xC0000000.
8
; It allocates a stack from 0xC0001000 downwards. So
9
; it must run within 4K (code + data + stack).
10
;
11
; This code expects the disk number of the boot disk
12
; in $16, the start sector of the disk or partition
13
; to be booted in $17 and its size in $18.
14
;
15
; The boot manager, which is loaded by this code,
16
; must be in standalone (headerless) executable
17
; format, stored at absolute disk sectors 2..31,
18
; and gets loaded and started at 0xC0001000.
19
 
20
        .set    stacktop,0xC0001000     ; top of stack
21
        .set    loadaddr,0xC0001000     ; where to load the boot manager
22
 
23
        .set    cout,0xE0000018         ; ROM console output
24
        .set    dskio,0xE0000030        ; ROM disk I/O
25
 
26
        ; reset arrives here
27
reset:
28
        j       start
29
 
30
        ; interrupts arrive here
31
intrpt:
32
        j       userMiss
33
 
34
        ; user TLB misses arrive here
35
userMiss:
36
        add     $4,$0,intmsg             ; we do not expect any interrupt
37
        jal     msgout
38
        j       halt
39
 
40
        ; load the boot manager and start it
41
start:
42
        add     $29,$0,stacktop          ; setup stack
43
        add     $4,$0,strtmsg            ; say what is going on
44
        jal     msgout
45
        add     $4,$0,2                  ; start loading with sector 2
46
        add     $5,$0,loadaddr           ; where to load the boot manager
47
        and     $5,$5,0x3FFFFFFF        ; convert to physical address
48
        add     $6,$0,30         ; 30 sectors to load
49
        jal     rdsct
50
        add     $8,$0,loadaddr           ; start executing the boot manager
51
        jr      $8
52
 
53
        ; read disk sectors
54
        ;   $4 start sector number (disk or partition relative)
55
        ;   $5 transfer address
56
        ;   $6 number of sectors
57
rdsct:
58
        sub     $29,$29,32
59
        stw     $31,$29,20
60
        stw     $6,$29,16               ; sector count
61
        add     $7,$5,$0         ; transfer address
62
        add     $6,$4,$17               ; relative sector -> absolute
63
        add     $5,$0,'r'                ; command
64
        add     $4,$0,$16                ; disk number
65
        add     $8,$0,dskio
66
        jalr    $8
67
        bne     $2,$0,rderr              ; error?
68
        ldw     $31,$29,20
69
        add     $29,$29,32
70
        jr      $31
71
 
72
        ; disk read error
73
rderr:
74
        add     $4,$0,dremsg
75
        jal     msgout
76
        j       halt
77
 
78
        ; output message
79
        ;   $4 pointer to string
80
msgout:
81
        sub     $29,$29,8
82
        stw     $31,$29,4
83
        stw     $16,$29,0
84
        add     $16,$4,0         ; $16: pointer to string
85
msgout1:
86
        ldbu    $4,$16,0         ; get character
87
        beq     $4,$0,msgout2            ; done?
88
        jal     chrout                  ; output character
89
        add     $16,$16,1               ; bump pointer
90
        j       msgout1                 ; continue
91
msgout2:
92
        ldw     $16,$29,0
93
        ldw     $31,$29,4
94
        add     $29,$29,8
95
        jr      $31
96
 
97
        ; output character
98
        ;   $4 character
99
chrout:
100
        sub     $29,$29,4
101
        stw     $31,$29,0
102
        add     $8,$0,cout
103
        jalr    $8
104
        ldw     $31,$29,0
105
        add     $29,$29,4
106
        jr      $31
107
 
108
        ; halt execution by looping
109
halt:
110
        add     $4,$0,hltmsg
111
        jal     msgout
112
halt1:
113
        j       halt1
114
 
115
        ; messages
116
intmsg:
117
        .byte   "unexpected interrupt", 0x0D, 0x0A, 0
118
strtmsg:
119
        .byte   "MBR executing...", 0x0D, 0x0A, 0
120
dremsg:
121
        .byte   "disk read error", 0x0D, 0x0A, 0
122
hltmsg:
123
        .byte   "bootstrap halted", 0x0D, 0x0A, 0
124
 
125
        ; boot record signature
126
        .locate 512-2
127
        .byte   0x55, 0xAA

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.