mbr.s revision 47472
1261409Sbr# 2261409Sbr# Copyright (c) 1999 Robert Nordier 3261409Sbr# All rights reserved. 4261409Sbr# 5261409Sbr# Redistribution and use in source and binary forms are freely 6261409Sbr# permitted provided that the above copyright notice and this 7261409Sbr# paragraph and the following disclaimer are duplicated in all 8261409Sbr# such forms. 9261409Sbr# 10261409Sbr# This software is provided "AS IS" and without any express or 11261409Sbr# implied warranties, including, without limitation, the implied 12261409Sbr# warranties of merchantability and fitness for a particular 13261409Sbr# purpose. 14261409Sbr# 15261409Sbr 16261409Sbr# $Id: $ 17261409Sbr 18261409Sbr# Master boot record 19261409Sbr 20265155Simp .set LOAD,0x7c00 # Load address 21261409Sbr .set EXEC,0x600 # Execution address 22261409Sbr .set PT_OFF,0x1be # Partition table 23261409Sbr .set MAGIC,0xaa55 # Magic: bootable 24261409Sbr 25261409Sbr .set NDRIVE,0x8 # Drives to support 26263245Simp 27261409Sbr .globl start # Entry point 28261409Sbr 29263301Simpstart: cld # String ops inc 30263301Simp xorl %eax,%eax # Zero 31263301Simp movl %eax,%es # Address 32263301Simp movl %eax,%ds # data 33263301Simp cli # Disable interrupts 34263301Simp movl %eax,%ss # Set up 35263301Simp movwir(LOAD,_sp) # stack 36263301Simp sti # Enable interrupts 37263245Simp movwir(main-EXEC+LOAD,_si) # Source 38263245Simp movwir(main,_di) # Destination 39263301Simp movwir(0x200-(main-start),_cx) # Word count 40263301Simp rep # Relocate 41263301Simp movsb # code 42263301Simp jmpnwi(main-LOAD+EXEC) # To relocated code 43263301Simp 44263245Simpmain: xorl %esi,%esi # No active found 45263301Simp movwir(partbl,_bx) # Partition table 46263301Simp movb $0x4,%cl # Entries 47263301Simpmain.1: cmpbr0(_ch,_bx_) # Null entry? 48263301Simp je main.2 # Yes 49263301Simp jg err_pt # If bit 7 unset 50263301Simp testl %esi,%esi # Active found? 51263301Simp jnz err_pt # Yes 52263301Simp movl %ebx,%esi # Keep place 53263301Simpmain.2: addb $0x10,%bl # Till 54263301Simp loop main.1 # done 55261409Sbr testl %esi,%esi # Active found? 56261409Sbr jnz main.3 # Yes 57261409Sbr int $0x18 # BIOS: Diskless boot 58261409Sbr 59263245Simpmain.3: cmpb $0x80,%dl # Drive valid? 60261409Sbr jb main.4 # No 61261409Sbr cmpb $0x80+NDRIVE,%dl # Within range? 62263245Simp jb main.5 # Yes 63263301Simpmain.4: movb0r(_si_,_dl) # Load drive 64263245Simpmain.5: movb1r(0x1,_si_,_dh) # Load head 65263301Simp movw1r(0x2,_si_,_cx) # Load cylinder:sector 66263301Simp movwir(LOAD,_bx) # Transfer buffer 67263245Simp movwir(0x201,_ax) # BIOS: Read from 68263245Simp int $0x13 # disk 69263245Simp jc err_rd # If error 70263245Simp cmpwi2(MAGIC,0x1fe,_bx_) # Bootable? 71261778Sbr jne err_os # No 72261409Sbr jmp *%ebx # Invoke bootstrap 73261409Sbr 74263301Simperr_pt: movwir(msg_pt,_si) # "Invalid partition 75263301Simp jmp putstr # table" 76263301Simp 77261409Sbrerr_rd: movwir(msg_rd,_si) # "Error loading 78261409Sbr jmp putstr # operating system" 79263245Simp 80261409Sbrerr_os: movwir(msg_os,_si) # "Missing operating 81261409Sbr jmp putstr # system" 82261409Sbr 83261409Sbrputstr.0: movwir(0x7,_bx) # Page:attribute 84261409Sbr movb $0xe,%ah # BIOS: Display 85261409Sbr int $0x10 # character 86261409Sbrputstr: lodsb # Get character 87261409Sbr testb %al,%al # End of string? 88261409Sbr jnz putstr.0 # No 89261409Sbrputstr.1: jmp putstr.1 # Await reset 90263301Simp 91263301Simpmsg_pt: .asciz "Invalid partition table" 92263301Simpmsg_rd: .asciz "Error loading operating system" 93261409Sbrmsg_os: .asciz "Missing operating system" 94261409Sbr 95261409Sbr .org PT_OFF 96261409Sbr 97261409Sbrpartbl: .fill 0x10,0x4,0x0 # Partition table 98261409Sbr .word MAGIC # Magic number 99261409Sbr