Mercurial > hg > Members > kono > nitros9-code
annotate level1/modules/boot_common.asm @ 2152:74fb212cb659
Changelog comes from higher up
author | boisy |
---|---|
date | Wed, 14 May 2008 02:13:22 +0000 |
parents | 73a8a7fe0151 |
children | e0614e08fa5e |
rev | line source |
---|---|
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
1 ******************************************************************** |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
2 * Boot Common - Common code for NitrOS-9 booters |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
3 * |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
4 * $Id$ |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
5 * |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
6 * This common file is not a stand-alone module, but is 'used' by boot module |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
7 * source files to bring in support for booting from RBF file systems that have |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
8 * either standard or new-style fragmented bootfiles. |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
9 * |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
10 * This code uses several static variables which are expected to be defined in |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
11 * the main boot source code. See a booter like boot_1773.asm for an example on |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
12 * how to write a booter which uses this code. |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
13 * |
1894 | 14 * Important Notes: |
15 * For certain devices, only the lower 16 bits of DD.BT are used. This special | |
16 * case allows us to save some code by ignoring the loading LSN bits 23-16 in | |
17 * DD.BT and FDSL.A. Booters for such devices (floppy, RAMPak) should have the | |
18 * following line in their code to take advantage of this optimization: | |
19 * | |
20 * LSN24BIT equ 0 | |
21 * | |
22 * Floppy booters require the acquistion of DD.TKS and DD.FMT from LSN0 to make | |
23 * certain decisions about the boot process. In most cases, non-floppy booters | |
24 * do not need these values. Hence, floppy booters should have this line in their | |
25 * source code file: | |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
26 * |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
27 * FLOPPY equ 1 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
28 * |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
29 * Edt/Rev YYYY/MM/DD Modified by |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
30 * Comment |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
31 * ------------------------------------------------------------------ |
1894 | 32 * 2005/10/14 Boisy G. Pitre |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
33 * Created as a stand-alone file. |
1894 | 34 * |
35 * 2005/10/16 Boisy G. Pitre | |
36 * Further optimizations made | |
1964
0f25486b1d23
Added pointer to loaded LSN0 to data passed to hardware dependent section
afra
parents:
1952
diff
changeset
|
37 * |
2117
093b7a304dd1
Added subd #$00FF to undo addd #$00FF... fixed issue where F$SRqMem for bootfile was allocating one additional page more than needed
boisy
parents:
1964
diff
changeset
|
38 * 2006/01/04 P.Harvey-Smith. |
1964
0f25486b1d23
Added pointer to loaded LSN0 to data passed to hardware dependent section
afra
parents:
1952
diff
changeset
|
39 * Added pointer to loaded LSN0 to data passed to hardware dependent section. |
0f25486b1d23
Added pointer to loaded LSN0 to data passed to hardware dependent section
afra
parents:
1952
diff
changeset
|
40 * |
2117
093b7a304dd1
Added subd #$00FF to undo addd #$00FF... fixed issue where F$SRqMem for bootfile was allocating one additional page more than needed
boisy
parents:
1964
diff
changeset
|
41 * 2007/08/23 Boisy G. Pitre |
093b7a304dd1
Added subd #$00FF to undo addd #$00FF... fixed issue where F$SRqMem for bootfile was allocating one additional page more than needed
boisy
parents:
1964
diff
changeset
|
42 * Added 'subd #$00FF' to counteract earlier 'addd #$00FF'. We need to undo |
093b7a304dd1
Added subd #$00FF to undo addd #$00FF... fixed issue where F$SRqMem for bootfile was allocating one additional page more than needed
boisy
parents:
1964
diff
changeset
|
43 * to give F$SRqMem the right amount of memory to allocate. |
093b7a304dd1
Added subd #$00FF to undo addd #$00FF... fixed issue where F$SRqMem for bootfile was allocating one additional page more than needed
boisy
parents:
1964
diff
changeset
|
44 * |
2119 | 45 * 2007/08/24 Boisy G. Pitre |
46 * We no longer use F$SRqMem to get the 256 byte buffer for LSN0, but | |
47 * instead allocate the memory temporarily off the stack. This gives us | |
48 * two system ram pages that were not available before, and also prevents | |
49 * a needless system call. | |
2120
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
50 * Note: For Level 1, we actually use the page above the stack at $500-$5FF |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
51 * to hold LSN0 during the bootfile acquisition process. This is because the |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
52 * system stack is only 256 bytes and we are using more than that. Since |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
53 * the module directory table is at $400-$4FF, we must do this; otherwise, we |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
54 * would overwrite the bottom portion of the module directory table and corrupt |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
55 * it (it's already setup by krn before boot is called!) |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
56 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
57 start orcc #IntMasks ensure IRQs are off (necessary?) |
2119 | 58 * allocate memory on stack for vars and sector buffer |
2120
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
59 IFEQ Level-1 |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
60 * Level 1: stack is only 256 bytes and its bottom runs against moddir ptrs... so cheat and use free page just above stack |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
61 * for 256 byte disk buffer |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
62 leas -size,s |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
63 tfr s,u get pointer to data area |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
64 ldx #$500 |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
65 ELSE |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
66 leas -size-256,s |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
67 tfr s,u get pointer to data area |
2119 | 68 leax size,u point U to 256 byte sector buffer |
2120
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
69 ENDC |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
70 pshs u save pointer to data area |
2119 | 71 stx blockloc,u |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
72 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
73 * Initialize Hardware |
1894 | 74 ldy Address,pcr get hardware address |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
75 lbsr HWInit |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
76 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
77 * Read LSN0 |
1894 | 78 IFNE LSN24BIT |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
79 clrb MSB sector |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
80 ENDC |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
81 ldx #0 LSW sector |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
82 lbsr HWRead read LSN 0 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
83 bcs error branch if error |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
84 |
1894 | 85 IFGT Level-1 |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
86 lda #'0 --- loaded in LSN0' |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
87 jsr <D.BtBug --- |
1894 | 88 ENDC |
1964
0f25486b1d23
Added pointer to loaded LSN0 to data passed to hardware dependent section
afra
parents:
1952
diff
changeset
|
89 |
2119 | 90 stx LSN0Ptr,u Save LSN0 pointer |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
91 * Pull relevant values from LSN0 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
92 IFNE FLOPPY |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
93 lda DD.TKS,x number of tracks on this disk |
1894 | 94 ldb DD.FMT,x disk format byte |
95 std ddtks,u TAKE NOTE! ASSUMES ADJACENT VARS! | |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
96 ENDC |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
97 ldd DD.BSZ,x os9boot size in bytes |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
98 beq FragBoot if zero, do frag boot |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
99 std bootsize,u |
1894 | 100 * Old style boot -- make a fake FD segment right from LSN0! |
101 leax DD.BT,x | |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
102 addd #$00FF round up to next page |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
103 * Important note: We are making an assumption that the upper 8 bits of the |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
104 * FDSL.B field will always be zero. That is a safe assumption, since an |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
105 * FDSL.B value of $00FF would mean the file is 65280 bytes. A bootfile |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
106 * under NitrOS-9 cannot be this large, and therefore this assumption |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
107 * is safe. |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
108 sta FDSL.B+1,x save file size |
1894 | 109 IFNE LSN24BIT |
110 clr FDSL.S,x make next segment entry 0 | |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
111 ENDC |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
112 clr FDSL.S+1,x |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
113 clr FDSL.S+2,x |
2117
093b7a304dd1
Added subd #$00FF to undo addd #$00FF... fixed issue where F$SRqMem for bootfile was allocating one additional page more than needed
boisy
parents:
1964
diff
changeset
|
114 subd #$00FF undo previous add #$00FF |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
115 bra GrabBootMem |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
116 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
117 Back2Krn lbsr HWTerm call HW termination routine |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
118 ldx blockimg,u pointer to start of os9boot in memory |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
119 clrb clear carry |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
120 ldd bootsize,u |
2120
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
121 error |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
122 IFEQ Level-1 |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
123 leas 2+size,s reset the stack same as PULS U |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
124 ELSE |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
125 leas 2+size+256,s reset the stack same as PULS U |
73a8a7fe0151
fixed issue with stack overwrite in boot_common.asm for level 1.
boisy
parents:
2119
diff
changeset
|
126 ENDC |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
127 rts return to kernel |
2119 | 128 |
129 | |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
130 * NEW! Fragmented boot support! |
1894 | 131 *FragBoot ldb bootloc,u MSB fd sector location |
132 * ldx bootloc+1,u LSW fd sector location | |
133 FragBoot ldb DD.BT,x MSB fd sector location | |
134 ldx DD.BT+1,x LSW fd sector location | |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
135 lbsr HWRead get fd sector |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
136 ldd FD.SIZ+2,x get file size (we skip first two bytes) |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
137 std bootsize,u |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
138 leax FD.SEG,x point to segment table |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
139 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
140 GrabBootMem |
1894 | 141 IFGT Level-1 |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
142 os9 F$BtMem |
1894 | 143 ELSE |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
144 os9 F$SRqMem |
1894 | 145 ENDC |
2119 | 146 bcs error |
147 * Save off alloced mem from F$SRqMem into blockloc,u and restore | |
148 * the statics pointer in U | |
149 tfr u,d save pointer to requested memory | |
150 ldu ,s recover pointer to data stack | |
151 std blockloc,u | |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
152 std blockimg,u |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
153 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
154 * Get os9boot into memory |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
155 BootLoop stx seglist,u update segment list |
1894 | 156 IFNE LSN24BIT |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
157 ldb FDSL.A,x MSB sector location |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
158 ENDC |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
159 BL2 ldx FDSL.A+1,x LSW sector location |
1894 | 160 IFNE LSN24BIT |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
161 bne BL3 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
162 tstb |
1894 | 163 ENDC |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
164 beq Back2Krn |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
165 BL3 lbsr HWRead |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
166 inc blockloc,u point to next input sector in mem |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
167 |
1894 | 168 IFGT Level-1 |
169 lda #'. show .' | |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
170 jsr <D.BtBug |
1894 | 171 ENDC |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
172 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
173 ldx seglist,u get pointer to segment list |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
174 dec FDSL.B+1,x get segment size |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
175 beq NextSeg if <=0, get next segment |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
176 |
1894 | 177 ldd FDSL.A+1,x update sector location by one |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
178 addd #1 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
179 std FDSL.A+1,x |
1894 | 180 IFNE LSN24BIT |
1893
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
181 ldb FDSL.A,x |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
182 adcb #0 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
183 stb FDSL.A,x |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
184 ENDC |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
185 bra BL2 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
186 |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
187 NextSeg leax FDSL.S,x advance to next segment entry |
1827bb446188
Modified booters to use new boot strategy with boot_common.asm
boisy
parents:
diff
changeset
|
188 bra BootLoop |