boot1.S (42638) | boot1.S (48919) |
---|---|
1# 2# Copyright (c) 1998 Robert Nordier 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms are freely 6# permitted provided that the above copyright notice and this 7# paragraph and the following disclaimer are duplicated in all 8# such forms. 9# 10# This software is provided "AS IS" and without any express or 11# implied warranties, including, without limitation, the implied 12# warranties of merchantability and fitness for a particular 13# purpose. 14# 15 | 1# 2# Copyright (c) 1998 Robert Nordier 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms are freely 6# permitted provided that the above copyright notice and this 7# paragraph and the following disclaimer are duplicated in all 8# such forms. 9# 10# This software is provided "AS IS" and without any express or 11# implied warranties, including, without limitation, the implied 12# warranties of merchantability and fitness for a particular 13# purpose. 14# 15 |
16# $Id: boot1.s,v 1.7 1999/01/10 13:29:51 peter Exp $ | 16# $Id: boot1.s,v 1.8 1999/01/13 23:30:07 rnordier Exp $ |
17 18 .set MEM_REL,0x700 # Relocation address 19 .set MEM_ARG,0x900 # Arguments 20 .set MEM_ORG,0x7c00 # Origin 21 .set MEM_BUF,0x8c00 # Load area 22 .set MEM_BTX,0x9000 # BTX start 23 .set MEM_JMP,0x9010 # BTX entry point 24 .set MEM_USR,0xa000 # Client start --- 9 unchanged lines hidden (view full) --- 34 .globl xread 35 36start: jmp main # Start recognizably 37 38 .org 0x4,0x90 39 40# External read from disk 41 | 17 18 .set MEM_REL,0x700 # Relocation address 19 .set MEM_ARG,0x900 # Arguments 20 .set MEM_ORG,0x7c00 # Origin 21 .set MEM_BUF,0x8c00 # Load area 22 .set MEM_BTX,0x9000 # BTX start 23 .set MEM_JMP,0x9010 # BTX entry point 24 .set MEM_USR,0xa000 # Client start --- 9 unchanged lines hidden (view full) --- 34 .globl xread 35 36start: jmp main # Start recognizably 37 38 .org 0x4,0x90 39 40# External read from disk 41 |
42xread: pushl %ecx # Set 43 pushl %eax # LBA 44 pushl %es # Set transfer 45 pushl %ebx # buffer 46 pushl %edx # Set count:drive | 42xread: pushl %ss # Address 43 popl %ds # data 44xread.1: o16 # Starting 45 pushb $0x0 # absolute 46 pushl %ecx # block 47 pushl %eax # number 48 pushl %es # Address of 49 pushl %ebx # transfer buffer 50 xorl %eax,%eax # Number of 51 movb %dh,%al # blocks to 52 pushl %eax # transfer 53 pushb $0x10 # Size of packet 54 movl %esp,%ebp # Packet pointer |
47 callwi(read) # Read from disk | 55 callwi(read) # Read from disk |
48 popl %edx # Pop all 49 popl %ebx # registers 50 popl %es # pushed, but 51 popl %ecx # preserve 52 popl %ecx # AX | 56 leaw1r(0x10,_bp_,_sp) # Clear stack |
53 lret # To far caller 54 55# Bootstrap 56 57main: cld # String ops inc 58 xorl %ecx,%ecx # Zero 59 movl %cx,%es # Address 60 movl %cx,%ds # data --- 61 unchanged lines hidden (view full) --- 122 ret # To caller 123 124# Local read from disk 125 126nread: movwir(MEM_BUF,_bx) # Transfer buffer 127 movw1r(0x8,_si_,_ax) # Get 128 movw1r(0xa,_si_,_cx) # LBA 129 pushl %cs # Read from | 57 lret # To far caller 58 59# Bootstrap 60 61main: cld # String ops inc 62 xorl %ecx,%ecx # Zero 63 movl %cx,%es # Address 64 movl %cx,%ds # data --- 61 unchanged lines hidden (view full) --- 126 ret # To caller 127 128# Local read from disk 129 130nread: movwir(MEM_BUF,_bx) # Transfer buffer 131 movw1r(0x8,_si_,_ax) # Get 132 movw1r(0xa,_si_,_cx) # LBA 133 pushl %cs # Read from |
130 callwi(xread) # disk | 134 callwi(xread.1) # disk |
131 jnc return # If success 132 movwir(msg_read,_si) # Message 133 134# Error exit 135 136error: callwi(putstr) # Display message 137 movwir(prompt,_si) # Display 138 callwi(putstr) # prompt --- 11 unchanged lines hidden (view full) --- 150 jne putstr.0 # No 151 152ereturn: movb $0x1,%ah # Invalid 153 stc # argument 154return: ret # To caller 155 156# Read from disk 157 | 135 jnc return # If success 136 movwir(msg_read,_si) # Message 137 138# Error exit 139 140error: callwi(putstr) # Display message 141 movwir(prompt,_si) # Display 142 callwi(putstr) # prompt --- 11 unchanged lines hidden (view full) --- 154 jne putstr.0 # No 155 156ereturn: movb $0x1,%ah # Invalid 157 stc # argument 158return: ret # To caller 159 160# Read from disk 161 |
158read: movl %esp,%ebp # Address stack frame | 162read: cs_ # LBA support 163 tstbim(0x80,MEM_REL+flags-start)# enabled? 164 jz read.1 # No 165 movwir(0x55aa,_bx) # Magic |
159 pushl %edx # Save | 166 pushl %edx # Save |
167 movb $0x41,%ah # BIOS: Check 168 int $0x13 # extensions present 169 popl %edx # Restore 170 jc read.1 # If error 171 cmpwir(0xaa55,_bx) # Magic? 172 jne read.1 # No 173 testb $0x1,%cl # Packet interface? 174 jz read.1 # No 175 movl %ebp,%esi # Disk packet 176 movb $0x42,%ah # BIOS: Extended 177 int $0x13 # read 178 ret # To caller 179 180read.1: pushl %edx # Save |
|
160 movb $0x8,%ah # BIOS: Get drive 161 int $0x13 # parameters 162 movb %dh,%ch # Max head number 163 popl %edx # Restore 164 jc return # If error 165 andb $0x3f,%cl # Sectors per track 166 jz ereturn # If zero 167 cli # Disable interrupts --- 16 unchanged lines hidden (view full) --- 184 ja ereturn # No 185 xchgb %al,%ah # Set up cylinder 186 rorb $0x2,%al # number 187 orb %ch,%al # Merge 188 incl %eax # sector 189 xchgl %eax,%ecx # number 190 movb %bh,%dh # Head number 191 subb %ah,%al # Sectors this track | 181 movb $0x8,%ah # BIOS: Get drive 182 int $0x13 # parameters 183 movb %dh,%ch # Max head number 184 popl %edx # Restore 185 jc return # If error 186 andb $0x3f,%cl # Sectors per track 187 jz ereturn # If zero 188 cli # Disable interrupts --- 16 unchanged lines hidden (view full) --- 205 ja ereturn # No 206 xchgb %al,%ah # Set up cylinder 207 rorb $0x2,%al # number 208 orb %ch,%al # Merge 209 incl %eax # sector 210 xchgl %eax,%ecx # number 211 movb %bh,%dh # Head number 212 subb %ah,%al # Sectors this track |
192 movb1r(0x3,_bp_,_ah) # Blocks to read | 213 movb1r(0x2,_bp_,_ah) # Blocks to read |
193 cmpb %ah,%al # To read | 214 cmpb %ah,%al # To read |
194 jb read.1 # this | 215 jb read.2 # this |
195 movb %ah,%al # track | 216 movb %ah,%al # track |
196read.1: movwir(0x5,_di) # Try count 197read.2: lesw1r(0x4,_bp_,_bx) # Transfer buffer | 217read.2: movwir(0x5,_di) # Try count 218read.3: lesw1r(0x4,_bp_,_bx) # Transfer buffer |
198 pushl %eax # Save 199 movb $0x2,%ah # BIOS: Read 200 int $0x13 # from disk 201 popl %ebx # Restore | 219 pushl %eax # Save 220 movb $0x2,%ah # BIOS: Read 221 int $0x13 # from disk 222 popl %ebx # Restore |
202 jnc read.3 # If success | 223 jnc read.4 # If success |
203 decl %edi # Retry? | 224 decl %edi # Retry? |
204 jz read.5 # No | 225 jz read.6 # No |
205 xorb %ah,%ah # BIOS: Reset 206 int $0x13 # disk system 207 xchgl %ebx,%eax # Block count | 226 xorb %ah,%ah # BIOS: Reset 227 int $0x13 # disk system 228 xchgl %ebx,%eax # Block count |
208 jmp read.2 # Continue 209read.3: movzbl %bl,%eax # Sectors read | 229 jmp read.3 # Continue 230read.4: movzbl %bl,%eax # Sectors read |
210 addwr1(_ax,0x8,_bp_) # Adjust | 231 addwr1(_ax,0x8,_bp_) # Adjust |
211 jnc read.4 # LBA, | 232 jnc read.5 # LBA, |
212 incw1(0xa,_bp_) # transfer | 233 incw1(0xa,_bp_) # transfer |
213read.4: shlb %bl # buffer | 234read.5: shlb %bl # buffer |
214 addbr1(_bl,0x5,_bp_) # pointer, | 235 addbr1(_bl,0x5,_bp_) # pointer, |
215 subbr1(_al,0x3,_bp_) # block count 216 ja read # If not done 217read.5: ret # To caller | 236 subbr1(_al,0x2,_bp_) # block count 237 ja read.1 # If not done 238read.6: ret # To caller |
218 219# Messages 220 221msg_read: .asciz "Read" 222msg_part: .asciz "Boot" 223 224prompt: .asciz " error\r\n" 225 | 239 240# Messages 241 242msg_read: .asciz "Read" 243msg_part: .asciz "Boot" 244 245prompt: .asciz " error\r\n" 246 |
247flags: .byte FLAGS # Flags 248 |
|
226 .org PRT_OFF,0x90 227 228# Partition table 229 230 .fill 0x30,0x1,0x0 231part4: .byte 0x80, 0x00, 0x01, 0x00 232 .byte 0xa5, 0xff, 0xff, 0xff 233 .byte 0x00, 0x00, 0x00, 0x00 234 .byte 0x50, 0xc3, 0x00, 0x00 235 236 .word 0xaa55 # Magic number | 249 .org PRT_OFF,0x90 250 251# Partition table 252 253 .fill 0x30,0x1,0x0 254part4: .byte 0x80, 0x00, 0x01, 0x00 255 .byte 0xa5, 0xff, 0xff, 0xff 256 .byte 0x00, 0x00, 0x00, 0x00 257 .byte 0x50, 0xc3, 0x00, 0x00 258 259 .word 0xaa55 # Magic number |