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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [stdalone/] [mkpart/] [mkmboot/] [stage1/] [mbr.s] - Blame information for rev 141

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

Line No. Rev Author Line
1 18 hellwig
;
2
; mbr.s -- the master boot record
3
;
4
 
5
; Runtime environment:
6
;
7 107 hellwig
; This code must be loaded and started at 0xC0010000.
8
; It allocates a stack from 0xC0011000 downwards. So
9 18 hellwig
; 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 107 hellwig
; and gets loaded and started at 0xC0011000.
19 18 hellwig
 
20 107 hellwig
        .set    stacktop,0xC0011000     ; top of stack
21
        .set    loadaddr,0xC0011000     ; where to load the boot manager
22 18 hellwig
 
23 107 hellwig
        .set    cout,0xC0000018         ; the monitor's console output
24
        .set    dskio,0xC0000030        ; the monitor's disk I/O
25 18 hellwig
 
26
        ; load the boot manager and start it
27
start:
28
        add     $29,$0,stacktop          ; setup stack
29
        add     $4,$0,strtmsg            ; say what is going on
30
        jal     msgout
31
        add     $4,$0,2                  ; start loading with sector 2
32
        add     $5,$0,loadaddr           ; where to load the boot manager
33
        and     $5,$5,0x3FFFFFFF        ; convert to physical address
34
        add     $6,$0,30         ; 30 sectors to load
35
        jal     rdsct
36
        add     $8,$0,loadaddr           ; start executing the boot manager
37
        jr      $8
38
 
39
        ; read disk sectors
40
        ;   $4 start sector number (disk or partition relative)
41
        ;   $5 transfer address
42
        ;   $6 number of sectors
43
rdsct:
44
        sub     $29,$29,32
45
        stw     $31,$29,20
46
        stw     $6,$29,16               ; sector count
47
        add     $7,$5,$0         ; transfer address
48
        add     $6,$4,$17               ; relative sector -> absolute
49
        add     $5,$0,'r'                ; command
50
        add     $4,$0,$16                ; disk number
51
        add     $8,$0,dskio
52
        jalr    $8
53
        bne     $2,$0,rderr              ; error?
54
        ldw     $31,$29,20
55
        add     $29,$29,32
56
        jr      $31
57
 
58
        ; disk read error
59
rderr:
60
        add     $4,$0,dremsg
61
        jal     msgout
62
        j       halt
63
 
64
        ; output message
65
        ;   $4 pointer to string
66
msgout:
67
        sub     $29,$29,8
68
        stw     $31,$29,4
69
        stw     $16,$29,0
70
        add     $16,$4,0         ; $16: pointer to string
71
msgout1:
72
        ldbu    $4,$16,0         ; get character
73
        beq     $4,$0,msgout2            ; done?
74
        jal     chrout                  ; output character
75
        add     $16,$16,1               ; bump pointer
76
        j       msgout1                 ; continue
77
msgout2:
78
        ldw     $16,$29,0
79
        ldw     $31,$29,4
80
        add     $29,$29,8
81
        jr      $31
82
 
83
        ; output character
84
        ;   $4 character
85
chrout:
86
        sub     $29,$29,4
87
        stw     $31,$29,0
88
        add     $8,$0,cout
89
        jalr    $8
90
        ldw     $31,$29,0
91
        add     $29,$29,4
92
        jr      $31
93
 
94
        ; halt execution by looping
95
halt:
96
        add     $4,$0,hltmsg
97
        jal     msgout
98
halt1:
99
        j       halt1
100
 
101
        ; messages
102
strtmsg:
103
        .byte   "MBR executing...", 0x0D, 0x0A, 0
104
dremsg:
105
        .byte   "disk read error", 0x0D, 0x0A, 0
106
hltmsg:
107
        .byte   "bootstrap halted", 0x0D, 0x0A, 0
108
 
109
        ; boot record signature
110
        .locate 512-2
111
        .byte   0x55, 0xAA

powered by: WebSVN 2.1.0

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