7

I'm a green hand to assembly language. These days I used bochs to simulate the boot procedure from virtual floppy. But one thing I don't know is what the CS register value is when the system initializes.

;;  init registers

org 0x7c00

BaseOfStack equ 0x7c00

Label_Start:

mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov sp, BaseOfStack

;; clear screen

mov ax, 0600h
mov bx, 0700h
mov cx, 0
mov dx, 0184h
int 10h

The above code is only part of it. When the ORG command was executed, what was the CS register value at the instruction mov ax, cs. Is it the same as 0x7c00? Thanks.

Below is bochsrc configuration:

romimage: file="$BXSHARE/BIOS-bochs-latest"
vgaromimage: file="$BXSHARE/VGABIOS-lgpl-latest"
boot: floppy
floppy_bootsig_check: disabled=0
floppya: type=1_44, 1_44="myboot.img", status=inserted
pci: enabled=1, chipset=i440fx
vga: extension=vbe, update_freq=15
cpu: ips=15000000
log: bochsout.txt
mouse: enabled=0
megs: 32
Fifoernik
  • 9,779
  • 1
  • 21
  • 27
Layne Liu
  • 452
  • 5
  • 10
  • It depends on your BIOS whether it sets CS=0 or IP=0 with a non-zero CS, or whatever. You may not need to care, as long as you access *data* (not code) through known segment bases. – Peter Cordes Sep 29 '18 at 07:01
  • 1
    As far as I can see, your BOCHS has created a log file called "bochsout.txt". There you will find an entry "Booting from 0000:7c00". This is `CS:IP` when starting the boot sector, i.e. your code. So, the value of `CS` is 0x0000. – rkhb Sep 29 '18 at 10:50
  • 1
    The `org` is assembler directive, not command. It will affect how assembler does calculate offsets of labels used further in the code, so it is command for the assembler, but not part of the binary bootloader. – Ped7g Sep 29 '18 at 11:14

1 Answers1

6

The specification says that CS:IP = 0000:7C00 at boot time, but some BIOS vendors boot off 07C0:0000 instead. The best way is to write your boot sector such that it works with both conventions by doing a far jump to a known selector early on:

    org 0x7c00

    xor ax, ax
    mov ds, ax
    mov es, ax
    mov ss, ax
    mov sp, 0x7c00
    jmp 0x0000:set_cs

set_cs:
    ...
fuz
  • 88,405
  • 25
  • 200
  • 352