bootloader?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

bootloader?

Post by Sam111 »

I have wrote this first stage boot loader

Code: Select all

org 0x7c00
BITS 16
jmp start
greetings	    db	'Greetings and welcome ',13d,10d,'$' 
BOOTLOADER_NAME db 'Nates BootLoader Stage 1' ,13d,10d,'$'
STARTSECTOR     db  2            ;start sector to load
LOADADDRESS     dw  8000h       ; where to load the sectors into memory
NUMBEROFSECTORS db  1           ; number of bytes to load begining at STARTSECTOR

; this function just clears the screen
clear_screen:
mov ax , 600h      ; clear screen scroll up function
mov bh , 7h        ; white on black background
mov ch , 0h        ;upper line (top)
mov cl , 0h        ;left col (far left)
mov dh , 18h       ;bottom 
mov dl , 4Fh       ;far right
int 10h  ;                          do the clearing 
ret

; this function should read the second sector of a floppy into memory 0000:8000
readsectors_into_memory:
mov ah , 02h                    ; read function
mov al , NUMBEROFSECTORS        ; number  of sectors to read
mov ch , 0h                     ; cylinder number
mov cl , STARTSECTOR            ; starting sector to begin reading from
mov dh , 0h                     ; head number
mov dl , 00h                    ;drive for floppy
mov bx , LOADADDRESS            ; es:ds-> buffer for where the sectors will be loaded in this case 0000:8000h
int 13                          ; execute the interrupt for reading into memory
ret


start:
call clear_screen ;first clear the screen

; display greeting message
mov ah , 13h
mov al , 01h 
mov bh , 0h
mov bl , 0Fh
mov dh , 5h
mov dl , 3h
mov cx , greetings
mov bp , cx
mov cx , 22d
int 10h

;display bootloader name message
mov cx , BOOTLOADER_NAME
mov bp , cx
mov cx , 24d
mov dh , 10h
mov dl , 0h
int 10h

call readsectors_into_memory ;should read the second sector of the floppy into 0000:8000h

jmp 0000:8000 ; should jump to the program specified below

; never should get here but if it does hang around
loop_it:
jmp loop_it


However when I do the jump it seems to just keep clearing the screen and displaying
Greetings and welcome ... and Nates BootLoader Stage 1 repeating this indefinitely over and over again. But it should jump to the second sector code below code .

Code: Select all

org 0x8000
BITS 16
jmp start
hello	db	'This is sector 2!',13d,10d,'$' ;Put any data here!

start:
;clear screen first
mov ax , 600h       ; clear screen scroll up function
mov bh , 7h         ; white on black background
mov ch , 0h         ;upper line (top)
mov cl , 0h         ;left col (far left)
mov dh , 18h        ;bottom 
mov dl , 4Fh        ;far right
int 10h             ;do the clearing 

; display the string This is sector 2 on the screen
mov ah , 13h
mov al , 01h 
mov bh , 0h
mov bl , 0Fh
mov dh , 5h
mov dl , 3h
mov cx , hello
mov bp , cx
mov cx , 16d
int 10h
; loop forever
endsss:
jmp endsss


and display This is sector 2!.

Basically I put the first bootloader program on sector 1 of the floppy image and the other program on the 2 sector.

Where did I go wrong.
Note I assumed main floppy device to be at 00h I could have probably got this first from dl but I don't think this is the problem.

I am using boches to run this on a 1.44 floppy image.
I know the floppy image is correct because I cut and pasted it with a hex editor into it. #-o #-o #-o
Last edited by Sam111 on Fri Nov 21, 2008 11:18 pm, edited 1 time in total.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: bootloader?

Post by neon »

Code: Select all

mov bx , LOADADDRESS ; es:ds-> buffer for where the sectors will be loaded in this case 0000:8000h
How do you know es==0 considering you have not cleared segments nor set up a stack?

Also, if possible, can you please post a log from Bochs? That might help us in finding the problem. From your description, it sounds either like an infinity loop or a triple fault.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: bootloader?

Post by Sam111 »

This is what was in bochsout.txt

Code: Select all

00000000000i[     ] Bochs x86 Emulator 2.3.6
00000000000i[     ]   Build from CVS snapshot, on December 24, 2007
00000000000i[     ] System configuration
00000000000i[     ]   processors: 1 (cores=1, HT threads=1)
00000000000i[     ]   A20 line support: yes
00000000000i[     ]   APIC support: yes
00000000000i[     ] CPU configuration
00000000000i[     ]   level: 6
00000000000i[     ]   TLB enabled: yes
00000000000i[     ]   SMP support: no
00000000000i[     ]   FPU support: yes
00000000000i[     ]   MMX support: yes
00000000000i[     ]   SSE support: 2
00000000000i[     ]   CLFLUSH support: yes
00000000000i[     ]   VME support: yes
00000000000i[     ]   3dnow! support: no
00000000000i[     ]   PAE support: yes
00000000000i[     ]   PGE support: yes
00000000000i[     ]   PSE support: yes
00000000000i[     ]   x86-64 support: yes
00000000000i[     ]   SEP support: yes
00000000000i[     ]   MWAIT support: no
00000000000i[     ] Optimization configuration
00000000000i[     ]   Guest2HostTLB support: yes
00000000000i[     ]   RepeatSpeedups support: yes
00000000000i[     ]   Icache support: yes
00000000000i[     ]   Trace cache support: yes
00000000000i[     ]   Fast function calls: yes
00000000000i[     ] Devices configuration
00000000000i[     ]   ACPI support: yes
00000000000i[     ]   NE2000 support: yes
00000000000i[     ]   PCI support: yes
00000000000i[     ]   SB16 support: yes
00000000000i[     ]   USB support: yes
00000000000i[     ]   VGA extension support: vbe cirrus
00000000000i[MEM0 ] allocated memory at 01D30020. after alignment, vector=01D31000
00000000000i[MEM0 ] 512.00MB
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('BIOS-bochs-latest')
00000000000i[MEM0 ] rom at 0xc0000/38400 ('../VGABIOS-lgpl-latest')
00000000000i[APIC?] set APIC ID to 0
00000000000i[APIC0] 80686
00000000000i[APIC0] local apic in CPU apicid=00 initializing
00000000000i[IOAP ] initializing I/O APIC
00000000000i[IOAP ] set APIC ID to 1
00000000000i[MEM0 ] Register memory access handlers: fec00000-fec00fff
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Sat Nov 22 00:19:36 2008 (time0=1227331176)
00000000000i[DMA  ] channel 4 used by cascade
00000000000i[DMA  ] channel 2 used by Floppy Drive
00000000000i[FDD  ] fd0: 'myfloppy.img' ro=0, h=2,t=80,spt=18
00000000000i[PCI  ] 440FX Host bridge present at device 0, function 0
00000000000i[PCI  ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[MEM0 ] Register memory access handlers: 000a0000-000bffff
00000000000i[WGUI ] Desktop Window dimensions: 1152 x 864
00000000000i[WGUI ] Number of Mouse Buttons = 3
00000000000i[WGUI ] IME disabled
00000000000i[MEM0 ] Register memory access handlers: e0000000-e07fffff
00000000000i[CLVGA] VBE Bochs Display Extension Enabled
00000000000i[CLVGA] interval=40000
00000000000i[     ] init_mem of 'harddrv' plugin device by virtual method
00000000000i[     ] init_mem of 'keyboard' plugin device by virtual method
00000000000i[     ] init_mem of 'serial' plugin device by virtual method
00000000000i[     ] init_mem of 'parallel' plugin device by virtual method
00000000000i[     ] init_mem of 'extfpuirq' plugin device by virtual method
00000000000i[     ] init_mem of 'gameport' plugin device by virtual method
00000000000i[     ] init_mem of 'speaker' plugin device by virtual method
00000000000i[     ] init_mem of 'pci_ide' plugin device by virtual method
00000000000i[     ] init_mem of 'acpi' plugin device by virtual method
00000000000i[     ] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD   ] Using boot sequence floppy, cdrom, disk
00000000000i[HD   ] Floppy boot signature check is enabled
00000000000i[     ] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD  ] will paste characters every 1000 keyboard ticks
00000000000i[     ] init_dev of 'serial' plugin device by virtual method
00000000000i[SER  ] com1 at 0x03f8 irq 4
00000000000i[     ] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR  ] parallel port 1 at 0x0378 irq 7
00000000000i[     ] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[     ] init_dev of 'gameport' plugin device by virtual method
00000000000i[     ] init_dev of 'speaker' plugin device by virtual method
00000000000i[     ] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[PCI  ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[     ] init_dev of 'acpi' plugin device by virtual method
00000000000i[PCI  ] ACPI Controller present at device 1, function 3
00000000000i[     ] register state of 'harddrv' plugin device by virtual method
00000000000i[     ] register state of 'keyboard' plugin device by virtual method
00000000000i[     ] register state of 'serial' plugin device by virtual method
00000000000i[     ] register state of 'parallel' plugin device by virtual method
00000000000i[     ] register state of 'extfpuirq' plugin device by virtual method
00000000000i[     ] register state of 'gameport' plugin device by virtual method
00000000000i[     ] register state of 'speaker' plugin device by virtual method
00000000000i[     ] register state of 'pci_ide' plugin device by virtual method
00000000000i[     ] register state of 'acpi' plugin device by virtual method
00000000000i[SYS  ] bx_pc_system_c::Reset(HARDWARE) called
00000000000i[CPU0 ] cpu hardware reset
00000000000i[APIC0] local apic in CPU 0 initializing
00000000000i[     ] reset of 'harddrv' plugin device by virtual method
00000000000i[     ] reset of 'keyboard' plugin device by virtual method
00000000000i[     ] reset of 'serial' plugin device by virtual method
00000000000i[     ] reset of 'parallel' plugin device by virtual method
00000000000i[     ] reset of 'extfpuirq' plugin device by virtual method
00000000000i[     ] reset of 'gameport' plugin device by virtual method
00000000000i[     ] reset of 'speaker' plugin device by virtual method
00000000000i[     ] reset of 'pci_ide' plugin device by virtual method
00000000000i[     ] reset of 'acpi' plugin device by virtual method
00000003445i[BIOS ] $Revision: 1.193 $ $Date: 2007/12/20 18:12:11 $
00000317060i[KBD  ] reset-disable command received
00000335566i[BIOS ] Starting rombios32
00000336288i[BIOS ] ram_size=0x20000000
00000356698i[BIOS ] Found 1 cpu(s)
00000372170i[BIOS ] bios_table_addr: 0x000faff8 end=0x000fe05b
00000372244i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00000699979i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001028426i[P2I  ] PCI IRQ routing: PIRQA# set to 0x0b
00001028475i[P2I  ] PCI IRQ routing: PIRQB# set to 0x09
00001028524i[P2I  ] PCI IRQ routing: PIRQC# set to 0x0b
00001028573i[P2I  ] PCI IRQ routing: PIRQD# set to 0x09
00001028588i[P2I  ] write: ELCR2 = 0x0a
00001029389i[BIOS ] PIIX3 init: elcr=00 0a
00001050302i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237
00001053275i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000
00001055716i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010
00001056198i[PIDE ] new BM-DMA address: 0xc000
00001056952i[BIOS ] region 4: 0x0000c000
00001059227i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113
00001059758i[ACPI ] new irq line = 11
00001059794i[ACPI ] new PM base address: 0xb000
00001059861i[ACPI ] new SM base address: 0xb100
00001060246i[CPU0 ] Enter to System Management Mode
00001060256i[CPU0 ] RSM: Resuming from System Management Mode
00001060290i[PCI  ] setting SMRAM control register to 0x4a
00001060508i[PCI  ] setting SMRAM control register to 0x0a
00001084183i[BIOS ] MP table addr=0x000fb0d0 MPC table addr=0x000fb000 size=0xd0
00001086126i[BIOS ] ACPI tables: RSDP addr=0x000fb0e0 ACPI DATA addr=0x1fff0000 size=0x978
00001098996i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001349337i[VBIOS] VGABios $Id: vgabios.c,v 1.66 2006/07/10 07:47:51 vruppert Exp $

00001349408i[CLVGA] VBE known Display Interface b0c0
00001349440i[CLVGA] VBE known Display Interface b0c4
00001352365i[VBIOS] VBE Bios $Id: vbe.c,v 1.58 2006/08/19 09:39:43 vruppert Exp $
00001440000i[WGUI ] dimension update x=720 y=400 fontheight=16 fontwidth=9 bpp=8
00001796627i[BIOS ] Booting from 0000:7c00
00023220000p[WGUI ] >>PANIC<< POWER button turned off.
00023220000i[CPU0 ] CPU is in real mode (active)
00023220000i[CPU0 ] CS.d_b = 16 bit
00023220000i[CPU0 ] SS.d_b = 16 bit
00023220000i[CPU0 ] EFER   = 0x00000000
00023220000i[CPU0 ] | RAX=000000000000023b  RBX=0000000000008000
00023220000i[CPU0 ] | RCX=0000000000000002  RDX=0000000000000000
00023220000i[CPU0 ] | RSP=000000000000ffdc  RBP=0000000000007c1c
00023220000i[CPU0 ] | RSI=00000000ffff88ca  RDI=0000000000080000
00023220000i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00023220000i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00023220000i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00023220000i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00023220000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf SF zf AF pf cf
00023220000i[CPU0 ] | SEG selector     base    limit G D
00023220000i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00023220000i[CPU0 ] |  CS:0000( 0004| 0|  0) 00000000 0000ffff 0 0
00023220000i[CPU0 ] |  DS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00023220000i[CPU0 ] |  SS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00023220000i[CPU0 ] |  ES:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00023220000i[CPU0 ] |  FS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00023220000i[CPU0 ] |  GS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00023220000i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00023220000i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00023220000i[CPU0 ] | RIP=000000000000555e (000000000000555e)
00023220000i[CPU0 ] | CR0=0x00000010 CR1=0x0 CR2=0x0000000000000000
00023220000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00023220000i[CPU0 ] >> add byte ptr ds:[bx+si], al : 0000
00023220000i[CMOS ] Last time is 1227331187 (Sat Nov 22 00:19:47 2008)
00023220000i[     ] restoring default signal behavior
00023220000i[CTRL ] quit_sim called with exit code 1


Hope this helps.

How do you know es==0 considering you have not cleared segments nor set up a stack?
I thought since it was displaying my greetings messages then es would have to equal 0.
Because my greetings message is at 0000:7c02 => ( es = 0 bp -> greetings) for the int 10 command to work. And as far as I know I did nothing to change this. Either way that won't explain why it infinitely loops printing my messages and clearing the screen and never jmp to 0000:8000.

Anyway to be safe I will try setting es = 0 .
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: bootloader?

Post by neon »

Thanks. Im actually a little tired now so might not be able to get back to it until tomorrow. I am sure someone here may be able to help out by then though :)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: bootloader?

Post by Sam111 »

This is the log with debuging in it.

Code: Select all

00000000000i[     ] Bochs x86 Emulator 2.3.6
00000000000i[     ]   Build from CVS snapshot, on December 24, 2007
00000000000i[     ] System configuration
00000000000i[     ]   processors: 1 (cores=1, HT threads=1)
00000000000i[     ]   A20 line support: yes
00000000000i[     ]   APIC support: yes
00000000000i[     ] CPU configuration
00000000000i[     ]   level: 6
00000000000i[     ]   TLB enabled: yes
00000000000i[     ]   SMP support: no
00000000000i[     ]   FPU support: yes
00000000000i[     ]   MMX support: yes
00000000000i[     ]   SSE support: 2
00000000000i[     ]   CLFLUSH support: yes
00000000000i[     ]   VME support: yes
00000000000i[     ]   3dnow! support: no
00000000000i[     ]   PAE support: yes
00000000000i[     ]   PGE support: yes
00000000000i[     ]   PSE support: yes
00000000000i[     ]   x86-64 support: yes
00000000000i[     ]   SEP support: yes
00000000000i[     ]   MWAIT support: no
00000000000i[     ] Optimization configuration
00000000000i[     ]   Guest2HostTLB support: yes
00000000000i[     ]   RepeatSpeedups support: yes
00000000000i[     ]   Icache support: yes
00000000000i[     ]   Trace cache support: yes
00000000000i[     ]   Fast function calls: yes
00000000000i[     ] Devices configuration
00000000000i[     ]   ACPI support: yes
00000000000i[     ]   NE2000 support: yes
00000000000i[     ]   PCI support: yes
00000000000i[     ]   SB16 support: yes
00000000000i[     ]   USB support: yes
00000000000i[     ]   VGA extension support: vbe cirrus
00000000000i[MEM0 ] allocated memory at 01D40020. after alignment, vector=01D41000
00000000000i[MEM0 ] 512.00MB
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('BIOS-bochs-latest')
00000000000i[MEM0 ] rom at 0xc0000/38400 ('../VGABIOS-lgpl-latest')
00000000000i[APIC?] set APIC ID to 0
00000000000i[APIC0] 80686
00000000000i[APIC0] local apic in CPU apicid=00 initializing
00000000000i[IOAP ] initializing I/O APIC
00000000000i[IOAP ] set APIC ID to 1
00000000000i[MEM0 ] Register memory access handlers: fec00000-fec00fff
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Sat Nov 22 00:41:18 2008 (time0=1227332478)
00000000000i[DMA  ] channel 4 used by cascade
00000000000i[DMA  ] channel 2 used by Floppy Drive
00000000000i[FDD  ] fd0: 'myfloppy.img' ro=0, h=2,t=80,spt=18
00000000000i[PCI  ] 440FX Host bridge present at device 0, function 0
00000000000i[PCI  ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[MEM0 ] Register memory access handlers: 000a0000-000bffff
00000000000i[WGUI ] Desktop Window dimensions: 1152 x 864
00000000000i[WGUI ] Number of Mouse Buttons = 3
00000000000i[WGUI ] IME disabled
00000000000i[MEM0 ] Register memory access handlers: e0000000-e07fffff
00000000000i[CLVGA] VBE Bochs Display Extension Enabled
00000000000i[CLVGA] interval=40000
00000000000i[     ] init_mem of 'harddrv' plugin device by virtual method
00000000000i[     ] init_mem of 'keyboard' plugin device by virtual method
00000000000i[     ] init_mem of 'serial' plugin device by virtual method
00000000000i[     ] init_mem of 'parallel' plugin device by virtual method
00000000000i[     ] init_mem of 'extfpuirq' plugin device by virtual method
00000000000i[     ] init_mem of 'gameport' plugin device by virtual method
00000000000i[     ] init_mem of 'speaker' plugin device by virtual method
00000000000i[     ] init_mem of 'pci_ide' plugin device by virtual method
00000000000i[     ] init_mem of 'acpi' plugin device by virtual method
00000000000i[     ] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD   ] Using boot sequence floppy, cdrom, disk
00000000000i[HD   ] Floppy boot signature check is enabled
00000000000i[     ] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD  ] will paste characters every 1000 keyboard ticks
00000000000i[     ] init_dev of 'serial' plugin device by virtual method
00000000000i[SER  ] com1 at 0x03f8 irq 4
00000000000i[     ] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR  ] parallel port 1 at 0x0378 irq 7
00000000000i[     ] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[     ] init_dev of 'gameport' plugin device by virtual method
00000000000i[     ] init_dev of 'speaker' plugin device by virtual method
00000000000i[     ] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[PCI  ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[     ] init_dev of 'acpi' plugin device by virtual method
00000000000i[PCI  ] ACPI Controller present at device 1, function 3
00000000000i[     ] register state of 'harddrv' plugin device by virtual method
00000000000i[     ] register state of 'keyboard' plugin device by virtual method
00000000000i[     ] register state of 'serial' plugin device by virtual method
00000000000i[     ] register state of 'parallel' plugin device by virtual method
00000000000i[     ] register state of 'extfpuirq' plugin device by virtual method
00000000000i[     ] register state of 'gameport' plugin device by virtual method
00000000000i[     ] register state of 'speaker' plugin device by virtual method
00000000000i[     ] register state of 'pci_ide' plugin device by virtual method
00000000000i[     ] register state of 'acpi' plugin device by virtual method
00000000000i[SYS  ] bx_pc_system_c::Reset(HARDWARE) called
00000000000i[CPU0 ] cpu hardware reset
00000000000i[APIC0] local apic in CPU 0 initializing
00000000000i[     ] reset of 'harddrv' plugin device by virtual method
00000000000i[     ] reset of 'keyboard' plugin device by virtual method
00000000000i[     ] reset of 'serial' plugin device by virtual method
00000000000i[     ] reset of 'parallel' plugin device by virtual method
00000000000i[     ] reset of 'extfpuirq' plugin device by virtual method
00000000000i[     ] reset of 'gameport' plugin device by virtual method
00000000000i[     ] reset of 'speaker' plugin device by virtual method
00000000000i[     ] reset of 'pci_ide' plugin device by virtual method
00000000000i[     ] reset of 'acpi' plugin device by virtual method
00000003445i[BIOS ] $Revision: 1.193 $ $Date: 2007/12/20 18:12:11 $
00000317060i[KBD  ] reset-disable command received
00000335566i[BIOS ] Starting rombios32
00000336288i[BIOS ] ram_size=0x20000000
00000356698i[BIOS ] Found 1 cpu(s)
00000372170i[BIOS ] bios_table_addr: 0x000faff8 end=0x000fe05b
00000372244i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00000699979i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001028426i[P2I  ] PCI IRQ routing: PIRQA# set to 0x0b
00001028475i[P2I  ] PCI IRQ routing: PIRQB# set to 0x09
00001028524i[P2I  ] PCI IRQ routing: PIRQC# set to 0x0b
00001028573i[P2I  ] PCI IRQ routing: PIRQD# set to 0x09
00001028588i[P2I  ] write: ELCR2 = 0x0a
00001029389i[BIOS ] PIIX3 init: elcr=00 0a
00001050302i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237
00001053275i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000
00001055716i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010
00001056198i[PIDE ] new BM-DMA address: 0xc000
00001056952i[BIOS ] region 4: 0x0000c000
00001059227i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113
00001059758i[ACPI ] new irq line = 11
00001059794i[ACPI ] new PM base address: 0xb000
00001059861i[ACPI ] new SM base address: 0xb100
00001060246i[CPU0 ] Enter to System Management Mode
00001060256i[CPU0 ] RSM: Resuming from System Management Mode
00001060290i[PCI  ] setting SMRAM control register to 0x4a
00001060508i[PCI  ] setting SMRAM control register to 0x0a
00001084183i[BIOS ] MP table addr=0x000fb0d0 MPC table addr=0x000fb000 size=0xd0
00001086126i[BIOS ] ACPI tables: RSDP addr=0x000fb0e0 ACPI DATA addr=0x1fff0000 size=0x978
00001098996i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001349337i[VBIOS] VGABios $Id: vgabios.c,v 1.66 2006/07/10 07:47:51 vruppert Exp $

00001349408i[CLVGA] VBE known Display Interface b0c0
00001349440i[CLVGA] VBE known Display Interface b0c4
00001352365i[VBIOS] VBE Bios $Id: vbe.c,v 1.58 2006/08/19 09:39:43 vruppert Exp $
00001440000i[WGUI ] dimension update x=720 y=400 fontheight=16 fontwidth=9 bpp=8
00001796627i[BIOS ] Booting from 0000:7c00
00031280000p[WGUI ] >>PANIC<< POWER button turned off.
00031280000i[CPU0 ] CPU is in real mode (active)
00031280000i[CPU0 ] CS.d_b = 16 bit
00031280000i[CPU0 ] SS.d_b = 16 bit
00031280000i[CPU0 ] EFER   = 0x00000000
00031280000i[CPU0 ] | RAX=000000000000023b  RBX=0000000000008000
00031280000i[CPU0 ] | RCX=0000000000000002  RDX=0000000000000000
00031280000i[CPU0 ] | RSP=000000000000ffdc  RBP=0000000000007c1c
00031280000i[CPU0 ] | RSI=00000000ffff88ca  RDI=0000000000080000
00031280000i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00031280000i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00031280000i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00031280000i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00031280000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf SF zf AF PF cf
00031280000i[CPU0 ] | SEG selector     base    limit G D
00031280000i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00031280000i[CPU0 ] |  CS:0000( 0004| 0|  0) 00000000 0000ffff 0 0
00031280000i[CPU0 ] |  DS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00031280000i[CPU0 ] |  SS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00031280000i[CPU0 ] |  ES:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00031280000i[CPU0 ] |  FS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00031280000i[CPU0 ] |  GS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00031280000i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00031280000i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00031280000i[CPU0 ] | RIP=0000000000006dfe (0000000000006dfe)
00031280000i[CPU0 ] | CR0=0x00000010 CR1=0x0 CR2=0x0000000000000000
00031280000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00031280000i[CPU0 ] >> add byte ptr ds:[bx+si], al : 0000
00031280000i[CMOS ] Last time is 1227332493 (Sat Nov 22 00:41:33 2008)
00031280000i[     ] restoring default signal behavior
00031280000i[CTRL ] quit_sim called with exit code 1

I have noticed add byte ptr ds:[bx+si], al : 0000 is this the problem?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: bootloader?

Post by Brendan »

Hi,

Some quick debugging help:
  • Start Bochs (a version with the inbuilt debugger enabled)
  • At the debugger prompt, type "vb 0:0x7C00" to set a breakpoint
  • Type "c" to execute everything up to your breakpoint (the BIOS code)
  • Now, type "p" to execute the first JMP instruction
  • Keep typing "p" and watch exactly what happens
  • Don't be afraid to try other debugger commands (e.g. "x /32 0x8000" to see what was loaded from floppy at 0x8000, or "r" to see the contents of general registers)
  • Don't be afraid to try "help" and "help vb" and "help <any_command_you_want>".
Also, one trick I do is put this in my code:

Code: Select all

    push cx
    xor cx,cx
.zz:
    jcxz .zz
    pop cx
This will lock up the computer, but, in Bochs debugger you can type "set cx=1" to continue. It's a useful trick if you don't want to find out the address to put a breakpoint. For example, you could put this loop just before your "jmp 0000:8000" instruction to give you a chance to find out if the second stage was loaded correctly.

Anyway, when your code is running, where is the stack and what are all the segment registers set to? For an example, if the BIOS left "0x0000:0x8200" in SS:SP and also left 0xF000 in DS and FS, then what would happen?

How do you know the second sector is loaded if you don't check the status returned from the BIOS? Floppy disks are unreliable - usually you need to have three retries before you give up.

Do you actually need a separate second stage? Can the first sector of the first stage load the rest of the first stage into RAM (e.g. have a 1024 byte binary where code in the first sector loads sector 2 at 0x7E00)? Note: for my OS, the floppy boot loader (first stage) is currently a 7 KiB binary, where code in the first sector loads the second and third sectors, and code in the second and third sectors is capable of loading any number of sectors (I could have a 500 KiB first stage if I wanted).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: bootloader?

Post by Sam111 »

Start Bochs (a version with the inbuilt debugger enabled)

How do you debug in boches I have version Bochs-2.3.6.

Anyway to answer your question about the stack. I didn't set it up. As well as any other segment I just let nasm default setting do it I guess.

I am a little shack on using the segment .data .text .stack ...etc

Because I use to use them like this

Code: Select all

segment data
;my data segment
segment code
mov ax , data ; this puts the begining address of the data segment into ax
mov ds , ax
However in bin format you don't get data as a symbol?
so how would I get data segment into ds. By default I think the bios sets ds ,cs,es,ss all to the same value when it jumps to the program it loaded at 0000:7c00.

Also when you specify segments do they get compiled into order.
Meaning if I do
segment data
segment code
segment stack

will the bin file have the first bytes being the data then after that section code ...etc etc
Or is it reorganized to have the code segment always first.

When I am creating an .exe or a com file I have no problem with this stuff since I always use the keywords data stack code ...etc and you also have wrt , and seg keywords. Which you don't have in bin format.

If I where to start splitting my content into different segments .
I am think that you would have to manual specify where each segment should begin. And by that hard code it.
Like if you put

Code: Select all

segment data 0x7C00
;data stuff
segment code
mov ax , 0x7C00
mov ds , ax
Am assuming the proper syntax is

Code: Select all

segment data 0x7C00
but I haven't check to see how you exactly specify where to place it . might be something like

Code: Select all

segment data .org 0x7C00
for all I know.

It seems like maybe the stack is the same as the code segment so when I execute a function.
The stack push something into the code that makes it infinitely loop. But I am not positive about that being the cause since I thought nasm defaults 256 byte stack.

But then I should be all set if I set the ss segment to any value except one that conflicts with the program at 0000:7c000 and the one at 0000:8000.

Either way you are right I have to learn how to use segments in bin format?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: bootloader?

Post by neon »

flat binaries dont use sections (.data, .text, .bss, etc..)

To set up the segments and stack, you need to select an address somewhere in memory that would be good and explicitly set up your registers. ie:

Code: Select all

xor ax, ax
mov ss, ax
mov esp, 0x9000   ;sets stack
By default I think the bios sets ds ,cs,es,ss all to the same value when it jumps to the program it loaded at 0000:7c00.
Its possible, but never bet on it. When programming ring 0 code, always program defensively.

To set the data segment in ds, because you are using ORG 0x7c00, all you need to do is set the segment to 0 (Because all addresses will already be added to 0x7c0 thanks to the org directive). To do this:

Code: Select all

xor ax, ax
mov ds, ax
mov es, ax
...etc...
How do you debug in boches I have version Bochs-2.3.6.
There are tutorials online: Clicky

Bochs debugger is really good if you know how to use it right.

I know in the earlier bochs debuggers, I could have just used a simple CLI+HLT combo and use the C (Continue) command in bochs to continue until it hit the breakpoint and the debugger will let me single step past the CLI+HLT combo (S command) so that I can debug it.

The newer debuggers dont seem to allow this anymore ( :( ) but Brendan posted another method that would work.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: bootloader?

Post by Sam111 »

Ok, I tried adding this to the start of the bootloader

Code: Select all

start:
mov ax , 0x9000 
mov ss , ax
xor ax , ax
mov ds , ax
mov es , ax
So the stack for the first stage bootloader should be located at 0000:9000.
Just in case I set ds , es , to zero before I do any work.

I also put in 3 calles to readsectors_into_memory since somebody said reading from I floppy
May take a few tries.

Code: Select all

call readsectors_into_memory
call readsectors_into_memory
call readsectors_into_memory
jmp 0000:8000
Still the same looping crap.
Note when I jump to 0000:8000 I don't set the stack to anything different.
Still using 9000 but I would think this is ok?
Never set ds , es to anything so they are still pointing to 0 I think after the jump?
Was I suppose to set the sp stack pointer as well as ss stack segment?

Anyway , a few question I have is what memory is reserved.
Like I would never load stuff to the first 1024 bytes since this is the IVT in 16 mode.
what is the places in memory you should never use? Is it just where IVT , VGA are in real mode.

Anyway I think I am OK to use 0000:8000 and 0000:9000 for loading.
#-o #-o #-o Why the hell is it looping?

This is the bochesout.txt gives

Code: Select all

00000000000i[     ] Bochs x86 Emulator 2.3.6
00000000000i[     ]   Build from CVS snapshot, on December 24, 2007
00000000000i[     ] System configuration
00000000000i[     ]   processors: 1 (cores=1, HT threads=1)
00000000000i[     ]   A20 line support: yes
00000000000i[     ]   APIC support: yes
00000000000i[     ] CPU configuration
00000000000i[     ]   level: 6
00000000000i[     ]   TLB enabled: yes
00000000000i[     ]   SMP support: no
00000000000i[     ]   FPU support: yes
00000000000i[     ]   MMX support: yes
00000000000i[     ]   SSE support: 2
00000000000i[     ]   CLFLUSH support: yes
00000000000i[     ]   VME support: yes
00000000000i[     ]   3dnow! support: no
00000000000i[     ]   PAE support: yes
00000000000i[     ]   PGE support: yes
00000000000i[     ]   PSE support: yes
00000000000i[     ]   x86-64 support: yes
00000000000i[     ]   SEP support: yes
00000000000i[     ]   MWAIT support: no
00000000000i[     ] Optimization configuration
00000000000i[     ]   Guest2HostTLB support: yes
00000000000i[     ]   RepeatSpeedups support: yes
00000000000i[     ]   Icache support: yes
00000000000i[     ]   Trace cache support: yes
00000000000i[     ]   Fast function calls: yes
00000000000i[     ] Devices configuration
00000000000i[     ]   ACPI support: yes
00000000000i[     ]   NE2000 support: yes
00000000000i[     ]   PCI support: yes
00000000000i[     ]   SB16 support: yes
00000000000i[     ]   USB support: yes
00000000000i[     ]   VGA extension support: vbe cirrus
00000000000i[MEM0 ] allocated memory at 02480020. after alignment, vector=02481000
00000000000i[MEM0 ] 512.00MB
00000000000i[MEM0 ] rom at 0xfffe0000/131072 ('BIOS-bochs-latest')
00000000000i[MEM0 ] rom at 0xc0000/38400 ('../VGABIOS-lgpl-latest')
00000000000i[APIC?] set APIC ID to 0
00000000000i[APIC0] 80686
00000000000i[APIC0] local apic in CPU apicid=00 initializing
00000000000i[IOAP ] initializing I/O APIC
00000000000i[IOAP ] set APIC ID to 1
00000000000i[MEM0 ] Register memory access handlers: fec00000-fec00fff
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Sat Nov 22 14:41:16 2008 (time0=1227382876)
00000000000i[DMA  ] channel 4 used by cascade
00000000000i[DMA  ] channel 2 used by Floppy Drive
00000000000i[FDD  ] fd0: 'myfloppy.img' ro=0, h=2,t=80,spt=18
00000000000i[PCI  ] 440FX Host bridge present at device 0, function 0
00000000000i[PCI  ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[MEM0 ] Register memory access handlers: 000a0000-000bffff
00000000000i[WGUI ] Desktop Window dimensions: 1152 x 864
00000000000i[WGUI ] Number of Mouse Buttons = 3
00000000000i[WGUI ] IME disabled
00000000000i[MEM0 ] Register memory access handlers: e0000000-e07fffff
00000000000i[CLVGA] VBE Bochs Display Extension Enabled
00000000000i[CLVGA] interval=40000
00000000000i[     ] init_mem of 'harddrv' plugin device by virtual method
00000000000i[     ] init_mem of 'keyboard' plugin device by virtual method
00000000000i[     ] init_mem of 'serial' plugin device by virtual method
00000000000i[     ] init_mem of 'parallel' plugin device by virtual method
00000000000i[     ] init_mem of 'extfpuirq' plugin device by virtual method
00000000000i[     ] init_mem of 'gameport' plugin device by virtual method
00000000000i[     ] init_mem of 'speaker' plugin device by virtual method
00000000000i[     ] init_mem of 'pci_ide' plugin device by virtual method
00000000000i[     ] init_mem of 'acpi' plugin device by virtual method
00000000000i[     ] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD   ] Using boot sequence floppy, cdrom, disk
00000000000i[HD   ] Floppy boot signature check is enabled
00000000000i[     ] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD  ] will paste characters every 1000 keyboard ticks
00000000000i[     ] init_dev of 'serial' plugin device by virtual method
00000000000i[SER  ] com1 at 0x03f8 irq 4
00000000000i[     ] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR  ] parallel port 1 at 0x0378 irq 7
00000000000i[     ] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[     ] init_dev of 'gameport' plugin device by virtual method
00000000000i[     ] init_dev of 'speaker' plugin device by virtual method
00000000000i[     ] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[PCI  ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[     ] init_dev of 'acpi' plugin device by virtual method
00000000000i[PCI  ] ACPI Controller present at device 1, function 3
00000000000i[     ] register state of 'harddrv' plugin device by virtual method
00000000000i[     ] register state of 'keyboard' plugin device by virtual method
00000000000i[     ] register state of 'serial' plugin device by virtual method
00000000000i[     ] register state of 'parallel' plugin device by virtual method
00000000000i[     ] register state of 'extfpuirq' plugin device by virtual method
00000000000i[     ] register state of 'gameport' plugin device by virtual method
00000000000i[     ] register state of 'speaker' plugin device by virtual method
00000000000i[     ] register state of 'pci_ide' plugin device by virtual method
00000000000i[     ] register state of 'acpi' plugin device by virtual method
00000000000i[SYS  ] bx_pc_system_c::Reset(HARDWARE) called
00000000000i[CPU0 ] cpu hardware reset
00000000000i[APIC0] local apic in CPU 0 initializing
00000000000i[     ] reset of 'harddrv' plugin device by virtual method
00000000000i[     ] reset of 'keyboard' plugin device by virtual method
00000000000i[     ] reset of 'serial' plugin device by virtual method
00000000000i[     ] reset of 'parallel' plugin device by virtual method
00000000000i[     ] reset of 'extfpuirq' plugin device by virtual method
00000000000i[     ] reset of 'gameport' plugin device by virtual method
00000000000i[     ] reset of 'speaker' plugin device by virtual method
00000000000i[     ] reset of 'pci_ide' plugin device by virtual method
00000000000i[     ] reset of 'acpi' plugin device by virtual method
00000003445i[BIOS ] $Revision: 1.193 $ $Date: 2007/12/20 18:12:11 $
00000317060i[KBD  ] reset-disable command received
00000335566i[BIOS ] Starting rombios32
00000336288i[BIOS ] ram_size=0x20000000
00000356698i[BIOS ] Found 1 cpu(s)
00000372170i[BIOS ] bios_table_addr: 0x000faff8 end=0x000fe05b
00000372244i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00000699979i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001028426i[P2I  ] PCI IRQ routing: PIRQA# set to 0x0b
00001028475i[P2I  ] PCI IRQ routing: PIRQB# set to 0x09
00001028524i[P2I  ] PCI IRQ routing: PIRQC# set to 0x0b
00001028573i[P2I  ] PCI IRQ routing: PIRQD# set to 0x09
00001028588i[P2I  ] write: ELCR2 = 0x0a
00001029389i[BIOS ] PIIX3 init: elcr=00 0a
00001050302i[BIOS ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237
00001053275i[BIOS ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000
00001055716i[BIOS ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010
00001056198i[PIDE ] new BM-DMA address: 0xc000
00001056952i[BIOS ] region 4: 0x0000c000
00001059227i[BIOS ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113
00001059758i[ACPI ] new irq line = 11
00001059794i[ACPI ] new PM base address: 0xb000
00001059861i[ACPI ] new SM base address: 0xb100
00001060246i[CPU0 ] Enter to System Management Mode
00001060256i[CPU0 ] RSM: Resuming from System Management Mode
00001060290i[PCI  ] setting SMRAM control register to 0x4a
00001060508i[PCI  ] setting SMRAM control register to 0x0a
00001084183i[BIOS ] MP table addr=0x000fb0d0 MPC table addr=0x000fb000 size=0xd0
00001086126i[BIOS ] ACPI tables: RSDP addr=0x000fb0e0 ACPI DATA addr=0x1fff0000 size=0x978
00001098996i[PCI  ] 440FX PMC write to PAM register 59 (TLB Flush)
00001349337i[VBIOS] VGABios $Id: vgabios.c,v 1.66 2006/07/10 07:47:51 vruppert Exp $

00001349408i[CLVGA] VBE known Display Interface b0c0
00001349440i[CLVGA] VBE known Display Interface b0c4
00001352365i[VBIOS] VBE Bios $Id: vbe.c,v 1.58 2006/08/19 09:39:43 vruppert Exp $
00001440000i[WGUI ] dimension update x=720 y=400 fontheight=16 fontwidth=9 bpp=8
00001796627i[BIOS ] Booting from 0000:7c00
00027100000p[WGUI ] >>PANIC<< POWER button turned off.
00027100000i[CPU0 ] CPU is in real mode (active)
00027100000i[CPU0 ] CS.d_b = 16 bit
00027100000i[CPU0 ] SS.d_b = 16 bit
00027100000i[CPU0 ] EFER   = 0x00000000
00027100000i[CPU0 ] | RAX=000000000000023a  RBX=0000000000007c38
00027100000i[CPU0 ] | RCX=0000000000000037  RDX=0000000000000000
00027100000i[CPU0 ] | RSP=000000000000ffdc  RBP=0000000000007c1c
00027100000i[CPU0 ] | RSI=00000000ffff88ca  RDI=0000000000080000
00027100000i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00027100000i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00027100000i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00027100000i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00027100000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt OF df if tf SF zf af PF cf
00027100000i[CPU0 ] | SEG selector     base    limit G D
00027100000i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00027100000i[CPU0 ] |  CS:0000( 0004| 0|  0) 00000000 0000ffff 0 0
00027100000i[CPU0 ] |  DS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00027100000i[CPU0 ] |  SS:9000( 0005| 0|  0) 00090000 0000ffff 0 0
00027100000i[CPU0 ] |  ES:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00027100000i[CPU0 ] |  FS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00027100000i[CPU0 ] |  GS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00027100000i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00027100000i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00027100000i[CPU0 ] | RIP=00000000000079a2 (00000000000079a2)
00027100000i[CPU0 ] | CR0=0x00000010 CR1=0x0 CR2=0x0000000000000000
00027100000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00027100000i[CPU0 ] >> add byte ptr ds:[bx+si], al : 0000
00027100000i[CMOS ] Last time is 1227382889 (Sat Nov 22 14:41:29 2008)
00027100000i[     ] restoring default signal behavior
00027100000i[CTRL ] quit_sim called with exit code 1

If you have a look you see that all the segment registers are at zero except the ss segemtn register equals 9000 as should be?

Is their something wrong with my jump command jmp 0000:8000 should I add an h on the end for hex value or is this implied. AHHHHHHHH I just don't know. I am currently in the process o learning how to use the boches debugger. But I havn't figured it out fully yet.
I think it's only for higher versions
You must use flex version 2.5.4 or greater. I have heard that version 2.5.2 will not work.
I have 2.3.6 and I don't want to start downloadiing a new version when I have everything setup perfectly.
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: bootloader?

Post by Sam111 »

Wait could it be the jmp start label is used in both programs and it is jumping back to the orignial start in the first program? Why would this happen ? I thought nasm would know the difference of the same label in 2 different programs as being different?

So I tried changing start label in second program to
jmp main

main:

Changing labels Didn't work either. So forget the above thought.

I am curious if you place the stack at 0000:9000 and then push a byte on the stack.
Is the stack pointer now at 0000:9001 or 0000:8FFF. I.E does the stack grow down or up?

So if your code segment was below it could your stack clash with it ,provided the answer was grow's down? maybe this is it? #-o


Also for boches
I have a bat file that runs everything it has this in it

Code: Select all

cd "C:\Program Files\Bochs-2.3.6\FloppyTest"
..\bochs -q -f floppy.txt
The configrations file floppy.text is

Code: Select all

###############################################################
# bochsrc.txt file for floppy boot image.
###############################################################

# how much memory the emulated machine will have
megs: 512

# filename of ROM images
romimage: file=BIOS-bochs-latest
vgaromimage: file=../VGABIOS-lgpl-latest

# what disk images will be used 
floppya: 1_44="myfloppy.img", status=inserted
#floppyb: 1_44=floppyb.img, status=inserted

# hard disk
#ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
#ata0-master: type=cdrom, path="cdfloppy.iso", cylinders=306, heads=4, spt=17

# 
#KNOPPIX_V5.0.1CD-2006-06-01-EN.iso
# choose the boot disk.
boot: floppy , cdrom , disk


# default config interface is textconfig.
#config_interface: textconfig
#config_interface: wx

#display_library: x
# other choices: win32 sdl wx carbon amigaos beos macintosh nogui rfb term svga

# where do we send log messages?
log: bochsout.txt

# disable the mouse, since DLX is text only
mouse: enabled=0

# enable key mapping, using US layout as default.
#
# NOTE: In Bochs 1.4, keyboard mapping is only 100% implemented on X windows.
# However, the key mapping tables are used in the paste function, so 
# in the DLX Linux example I'm enabling keyboard_mapping so that paste 
# will work.  Cut&Paste is currently implemented on win32 and X windows only.

#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-us.map
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-fr.map
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-de.map
#keyboard_mapping: enabled=1, map=$BXSHARE/keymaps/x11-pc-es.map

Can I set the debugger stuff in the bat file in some way so when I click the bat file it executes
my stuff in debug mode?
Last edited by Sam111 on Sat Nov 22, 2008 3:40 pm, edited 1 time in total.
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: bootloader?

Post by ru2aqare »

Sam111 wrote:I am curious if you place the stack at 0000:9000 and then push a byte on the stack.
Is the stack pointer now at 0000:9001 or 0000:8FFF. I.E does the stack grow down or up?

So if your code segment was below it could your stack clash with it ,provided the answer was grow's down? maybe this is it? #-o
In real mode, the stack always expands downwards and stores word-sized items. If you push a byte, it will be zero-extended to a word. So the new stack pointer in your case would be 0000:8FFE.
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

Re: bootloader?

Post by Sam111 »

Thanks I didn't know that real mode push 16 bits always even if you just push al (8 bits).
Good to know.
Is it the same thing with pmode if you push al or ax will it always push 32 bits on the stack.

Either way I don't think the stack is my problem.
I never really have done far jmps before is this correct to jump to my second program.
jmp 0000:8000

Or am I doing something wrong? Either way I am assuming the floppy is device 00h.
Does boches not use this for the floppy.img it loads. Because if that is the case then it is never loading the sector 2 on the floppy.img

Anyway I will try to check the carry flag on return of

Code: Select all

call readsectors_into_memory
. But I havn't found a good way of debugging this because I have read that the carry could be set even though the floppy disk was read. #-o
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: bootloader?

Post by Brendan »

Hi,
Sam111 wrote:Thanks I didn't know that real mode push 16 bits always even if you just push al (8 bits).
Good to know.
Is it the same thing with pmode if you push al or ax will it always push 32 bits on the stack.
In protected mode it depends on how it's setup - you can use a 16-bit stack or a 32-bit stack (just like you can run 16-bit code or 32-bit code). Most people use a 32-bit stack (and 32-bit code), so that if you push a byte or a word onto the stack it's zero extended and takes up 4 bytes.
Sam111 wrote:I never really have done far jmps before is this correct to jump to my second program.
jmp 0000:8000
No - these values are in decimal. You probably want:

Code: Select all

jmp 0x0000:0x8000
Sam111 wrote:Either way I am assuming the floppy is device 00h.
Device 0x00 is either the first floppy or something emulating the first floppy. Of course your OS could have been booted from the second floppy (for e.g. by some sort of boot manager). AFAIK it's possible to have up to 4 ISA floppy drive controllers with 2 floppy drives on each controller (device numbers 0x00 to 0x07) plus lots of USB floppy drives, and your OS could be booted from any of them by a boot manager. Also, if the BIOS is emulating the first floppy (e.g. an El Torito boot CD is pretending to be the first floppy) then the device numbers are shifted, so the emulated floppy becomes device 0x00, the first real floppy becomes device number 0x01, the second floppy becomes device number 0x02, etc. In some cases (e.g. a boot manager installed on a bootable CD being used to chain-load from the real floppy disk) that'd mean you could be booted from the first real floppy disk with device number 0x01.
Sam111 wrote:Does boches not use this for the floppy.img it loads. Because if that is the case then it is never loading the sector 2 on the floppy.img
Maybe it loads the right sector to the wrong address, or the wrong sector to the right address, or maybe the second sector wasn't stored on the floppy to begin with (or maybe the second sector was stored on the floppy somewhere else).
Sam111 wrote:Anyway I will try to check the carry flag on return of

Code: Select all

call readsectors_into_memory
. But I havn't found a good way of debugging this because I have read that the carry could be set even though the floppy disk was read. #-o
If the BIOS returns with "carry clear" then it did load all the sectors you asked it to load.

If you ask the BIOS to read 2 sectors and the first sector is read correctly but the second sector fails, then the BIOS will return with carry set because it couldn't load the second sector (even though it did load the first sector).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: bootloader?

Post by Troy Martin »

Brendan wrote:
Sam111 wrote:Either way I am assuming the floppy is device 00h.
Device 0x00 is either the first floppy or something emulating the first floppy. Of course your OS could have been booted from the second floppy (for e.g. by some sort of boot manager). AFAIK it's possible to have up to 4 ISA floppy drive controllers with 2 floppy drives on each controller (device numbers 0x00 to 0x07) plus lots of USB floppy drives, and your OS could be booted from any of them by a boot manager. Also, if the BIOS is emulating the first floppy (e.g. an El Torito boot CD is pretending to be the first floppy) then the device numbers are shifted, so the emulated floppy becomes device 0x00, the first real floppy becomes device number 0x01, the second floppy becomes device number 0x02, etc. In some cases (e.g. a boot manager installed on a bootable CD being used to chain-load from the real floppy disk) that'd mean you could be booted from the first real floppy disk with device number 0x01.
Exactly, so you should probably put the boot device (dl on startup) in a db and use that in your code. Remember brackets for the content of an address/label.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: bootloader?

Post by Love4Boobies »

Brendan wrote:Device 0x00 is either the first floppy or something emulating the first floppy. Of course your OS could have been booted from the second floppy (for e.g. by some sort of boot manager). AFAIK it's possible to have up to 4 ISA floppy drive controllers with 2 floppy drives on each controller (device numbers 0x00 to 0x07) plus lots of USB floppy drives, and your OS could be booted from any of them by a boot manager. Also, if the BIOS is emulating the first floppy (e.g. an El Torito boot CD is pretending to be the first floppy) then the device numbers are shifted, so the emulated floppy becomes device 0x00, the first real floppy becomes device number 0x01, the second floppy becomes device number 0x02, etc. In some cases (e.g. a boot manager installed on a bootable CD being used to chain-load from the real floppy disk) that'd mean you could be booted from the first real floppy disk with device number 0x01.
As far as BAIDs go, only the first HD and FD are valid IPL devices (that means 00H and 80H). The workaround is having a PnP BIOS; that way any INT 13H drive can be used for booting.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply