Question: need help writing the bootup code for a simple operating system. I need to: Setup data segment for boot block. (Code segment is already set

need help writing the bootup code for a simple operating system.

I need to:

Setup data segment for boot block.

(Code segment is already set to 0x07c0 by BIOS).

  • Setup stack segment and stack.

  • Copykernelto0x01000.

  • Setup data segment for kernel.

  • Long jump to kernel.

    ljmp $KERNEL_SEGMENT, $KERNEL_OFFSET

file:

# bootblock.s
# .equ symbol, expression
# These directive set the value of the symbol to the expression
.equ BOOT_SEGMENT, 0x07c0
.equ DISPLAY_SEGMENT, 0xb800
.equ KERNEL_SEGMENT, 0x0000
.equ KERNEL_OFFSET, 0x1000
# You need to decide where to put the stack
# .equ STACK_SEGMENT, 0xXXXX
# .equ STACK_POINTER, 0xXXXX
.text # Code segment
.globl _start # The entry point must be global
.code16 # Real mode
.org 0x0
#
# The first instruction to execute in a program is called the entry
# point. The linker expects to find the entry point in the "symbol" _start
# (with underscore).
#
_start:
jmp beyondReservedSpace
kernelSize:
.word 0 # bootimage will write size of kernel, in sectors
beyondReservedSpace:
movw $DISPLAY_SEGMENT, %bx
movw %bx, %es
# Clear screen
movw $0x0a00, %ax # Fill with black background / green foreground
movw $2000, %cx # Number of characters (80x25 screen in text mode = 2000)
xorw %di, %di # DI = 0
rep stosw
movb $0x4b, %es:(0x0) # Write 'K' in the upper left corner of the screen
forever:
jmp forever # Loop forever

Detailed Requirements and Hints for bootblock.S

This file should contain the code that will be written on the boot sector of the usb disk. This has to be written in x86 assembly and should not exceed 512 bytes (1 sector). This code will be responsible for loading in the rest of the operating system, setting up a stack for the kernel and then invoking it. You are required to handle kernels of size up to 18 sectors. However, try to make your bootblock handle sizes greater than 18 sectors.

The bootblock gets loaded at 0x07c0:0000. Your bootblock should load the OS starting at 0x0000:1000. In real mode, you have 640 KBytes starting at 0x0000:0000. The low memory area has some system data like the interrupt vectors and BIOS data. So, to avoid overwriting them, you should only use memory above 0x0000:1000 for this assignment.

Note: You can assume that the entire OS is less or equal to 18 sectors for this project.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!