Administrative OverviewCOS 318 Project 1 BootloaderProblemBooting a Computer On Startup…Bootup DetailsSlide 6BootloaderEntering the BootloaderThe kernel might be bigSolutionLoading the kernelDesign Review print_char, print_stringDesign ReviewHow long will this take?AddressingRegistersAT&T SyntaxAssembly PitfallsAdministrative Overview6 ProjectsDesign Review: Monday before 6:30pmLab Friend Center 010 (“Fishbowl”)COS 318 Project 1BootloaderProblemWe will write an Operating SystemManages programs, resources, users, etc.How are programs loaded?The OS takes care of thisHow is the OS loaded?…Booting a ComputerOn Startup…The BIOS is loadedTypically doesn’t know anything about the OSMinimal functionalityThe BIOS loads & runs the first sector of a boot device.An OS cannot fit in just one sectorBootup DetailsStart at 0xFFFF0Self test & initializationSearch for a boot deviceHard diskFloppyFlash…Bootup Details1st sector loaded to 0x7c00Jump to 0x7c00512 bytes to load the kernelBootloaderBootloaderKernelDiskMemoryEntering the Bootloader%dl = Boot device numberLoad the kernel from this device%cs = Code segmentNO STACK! (%ss, %sp unset)%ds unset (set it to 0x07c0 before fetching from memory!)Other registers unsetThe kernel might be bigKernelSolutionMove the bootloaderKernelLoading the kernelLoad to address 0x0000:1000Set up the stack%ss = 0x9000, %sp=0xfffe%ds = 0Long Jump to 0x0000:1000Design Reviewprint_char, print_stringExample:_start:jmp past_datawelcome_msg: .asciz “OS Project 1\n\rLoading…”past_data: push welcome_msg call print_string jmp somewhere_elseDesign ReviewBootloaderHow to find the kernel on disk?Where to copy the kernel?How to copy the kernel?CreateimageHow do you find the code segments in ELF using header information?Give a formula for the disk/image address of segment i in the program header. Where do you use padding?How long will this take?BootloaderAbout 80 lines assemblySimple instructions (int, mov, cld)CreateimageAbout 200 lines of CHardest part: navigating ELF structsDebugging will take the most time.AddressingReal Mode1 MBFormat: 0x0000:0000Physical address = (segment << 4)+offsetEx: 0x07c0:0000 = 0x0000:7c00Protected Mode4 GB (32-bit)Format: 0x0000:00000000 (32-bit)Virtual Addressing (user mode)Physical address = a bit more complicated…Registers31 16 8 0E_X EAX, EBX, ECX, EDX_X AX, BX, CX, DX_H _L AH, AL, BH, BL, …Segment Registers16CS, DS, SS, ES, FS, GSIndex Registers32BP, SI, DI, SPStatus & Control32EFLAGS, EIPGeneral RegistersAT&T SyntaxRegisters: %ax, %ah, %eax ,…Definitions.equ BOOT_SEGMENT, 0x07c0Constants: $0x0100, $4Labels_start:print_string:Memory accessmovw %ax, (0x40)movb %dl, (a_label)movw %es:(%ax), %dxComments/* multiline */# to the end of the lineDirectives.equ, .byte, .word, .ascii, .ascizAssembly Pitfalls.equ BOOT_SEGMENT, 0x07c0movw BOOT_SEGMENT,
View Full Document