OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 26, 2024 11:10 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Bochs int 10h problems
PostPosted: Mon Jun 02, 2008 5:14 pm 
Offline

Joined: Mon Jun 02, 2008 4:53 pm
Posts: 4
I have been trying to test bootloader code on Bochs, but it is not working. I am trying to make it post an A to the screen. What happens is that the Bochs BIOS info appears, then the screen clears and resizes and the cursor blinks. Code:

Code:
.code16

/* Jump past the BPP */
start:
   jmp real_start
   nop

/* BPP */
bios_parameter_block:
   .quad 0

   .ascii "Fake Filler BPB 1.0000000"
   .byte 0
   .byte 0
   .byte 0
   .byte 0
   .quad 0
   .quad 0
   .quad 0
   .double 0
   .double 0
   .quad 0
   .double 0

real_start:
   /* Set Segment Registers */
   mov 0x07c0, %ax
   mov %ax, %ds
   mov %ax, %es
   mov %ax, %fs
   mov %ax, %gs
   
   /* Print an A */
   mov 0x0e, %ah
   mov 'A', %al
   mov 0x00, %bh
   mov 0x07, %bl
   int $0x10

/* Loop forever */
loop:
   jmp loop


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 5:36 pm 
Offline
Member
Member

Joined: Tue May 06, 2008 9:32 am
Posts: 87
Location: The Netherlands
You didn't setup a stack.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 5:42 pm 
Offline
Member
Member
User avatar

Joined: Tue Feb 20, 2007 3:00 pm
Posts: 672
Location: London UK
Is that your whole bootloader?
You do realize that your bootloader is meant to be exactly 512 bytes long with 0xAA55 as the signature at the end?
Your supposed to fill the unused space with nulls.
Jules


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 5:44 pm 
Offline
Member
Member
User avatar

Joined: Tue Feb 20, 2007 3:00 pm
Posts: 672
Location: London UK
svdmeer wrote:
You didn't setup a stack.

A stack isn't necessary, he can print using int 0x10 without setting up a stack.
(Though you should probably do that, once you get passed this you'll be needing one soon...)
Jules


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 5:50 pm 
Offline
Member
Member
User avatar

Joined: Tue Feb 20, 2007 3:00 pm
Posts: 672
Location: London UK
Oh and welcome :wink:
Jules


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 5:52 pm 
Offline

Joined: Mon Jun 02, 2008 4:53 pm
Posts: 4
I added a stack. It still does not work.

Code:
.code16

/* Jump past the BPP */
start:
   jmp real_start
   nop

/* BPP */
bios_parameter_block:
   .quad 0

   .ascii "Fake Filler BPB 1.0000000"
   .byte 0
   .byte 0
   .byte 0
   .byte 0
   .quad 0
   .quad 0
   .quad 0
   .double 0
   .double 0
   .quad 0
   .double 0

real_start:
   /* Disable Interrupts */
   cli

   /* Set Segment Registers */
   mov 0x07c0, %ax
   mov %ax, %ds
   mov %ax, %es
   mov %ax, %fs
   mov %ax, %gs

   /* Create a Stack */
   mov 0, %ax
   mov %ax, %ss
   mov 0x2000, %sp

   /* Enable Interrupts */
   sti
   
   /* Print an A */
   mov 0x0e, %ah
   mov 'A', %al
   mov 0x00, %bh
   mov 0x07, %bl
   int $0x10

/* Loop forever */
loop:
   jmp loop


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 5:57 pm 
Offline
Member
Member
User avatar

Joined: Tue Feb 20, 2007 3:00 pm
Posts: 672
Location: London UK
suthers wrote:
Is that your whole bootloader?
You do realize that your bootloader is meant to be exactly 512 bytes long with 0xAA55 as the signature at the end?
Your supposed to fill the unused space with nulls.
Jules

Hey listen to me, nothing to do with stack, you don't need a stack, you need your bootloader to have the write length and signature:
Code:
times 510-($-$$) db 0           
dw 0xAA55 

This is how you do it in nasm, don't know how to do in that syntax (can't remember what its called anymore...), so you'll have to figure that out yourself...
Jules


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 6:03 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 07, 2007 1:45 pm
Posts: 1401
Location: Eugene, OR, US
Bochs doesn't test the signature byte -- so you don't really need it until you are running on a real PC.
But I'm kinda stumped on why the code isn't working -- it looks fine to me.

You could try setting one of the segment registers (say FS) to 0xb800, and then copy the 'A' to fs:0, and see what happens -- to see if skipping the INT 0x10 will make things work.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 6:31 pm 
Offline

Joined: Mon Jun 02, 2008 4:53 pm
Posts: 4
I'm afraid that it has not worked yet. I added padding commands that I have verified to be working, and have switched it to using video memory. Additionally, the Bochs log output seems odd.

Code:
.code16

/* Jump past the BPP */
start:
   jmp real_start
   nop

/* BPP */
bios_parameter_block:
   .quad 0

   .ascii "Fake Filler BPB 1.0000000"
   .byte 0
   .byte 0
   .byte 0
   .byte 0
   .quad 0
   .quad 0
   .quad 0
   .double 0
   .double 0
   .quad 0
   .double 0

real_start:
   /* Disable Interrupts */
   cli

   /* Set Segment Registers */
   mov 0x07c0, %ax
   mov %ax, %ds
   mov %ax, %es
   mov %ax, %fs
   mov %ax, %gs

   /* Create a Stack */
   mov 0, %ax
   mov %ax, %ss
   mov 0x2000, %sp

   /* Enable Interrupts */
   sti
   
   /* Print an A */
   /*
   mov 0x0e, %ah
   mov 'A', %al
   mov 0x00, %bh
   mov 0x07, %bl
   int $0x10
   */

   mov 0xb800, %es
   mov 'A', %al
   mov 0x07, %ah
   mov %ax, %es : 0

/* Loop forever */
loop:
   jmp loop

/* Padding */
. = 510
.byte 0x55
.byte 0xaa


Code:
00000000000i[     ] lt_dlhandle is 0x827bef0
00000000000i[PLGIN] loaded plugin libbx_x.la
00000000000i[     ] installing x module as the Bochs GUI
00000000000i[     ] Bochs x86 Emulator 2.3
00000000000i[     ]   Build from CVS snapshot on August 27, 2006
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[     ]   paging support: yes, tlb enabled: yes
00000000000i[     ]   SMP support: no
00000000000i[     ]   FPU support: yes
00000000000i[     ]   MMX support: yes
00000000000i[     ]   SSE support: 2
00000000000i[     ]   v8086 mode support: yes
00000000000i[     ]   VME support: yes
00000000000i[     ]   3dnow! support: yes
00000000000i[     ]   PAE support: yes
00000000000i[     ]   PGE support: yes
00000000000i[     ]   PSE support: yes
00000000000i[     ]   x86-64 support: no
00000000000i[     ]   SEP support: yes
00000000000i[     ] Optimization configuration
00000000000i[     ]   Guest2HostTLB support: yes
00000000000i[     ]   RepeatSpeedups support: yes
00000000000i[     ]   Icache support: yes
00000000000i[     ]   Host Asm support: yes
00000000000i[     ]   Fast function calls: yes
00000000000i[     ] Devices configuration
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 0xb59e4008. after alignment, vector=0xb59e5000
00000000000i[MEM0 ] 32.00MB
00000000000i[MEM0 ] rom at 0xffff0000/65536 ('/usr/share/bochs/BIOS-bochs-latest')
00000000000i[MEM0 ] rom at 0xc0000/38400 ('/usr/share/bochs/VGABIOS-lgpl-latest')
00000000000i[APIC?] set APIC ID to 0
00000000000i[APIC0] 80686
00000000000i[APIC0] local apic in CPU apicid=00 initializing
00000000000i[     ] lt_dlhandle is 0x8288ae0
00000000000i[PLGIN] loaded plugin libbx_unmapped.la
00000000000i[     ] lt_dlhandle is 0x8288fc0
00000000000i[PLGIN] loaded plugin libbx_biosdev.la
00000000000i[     ] lt_dlhandle is 0x8289578
00000000000i[PLGIN] loaded plugin libbx_cmos.la
00000000000i[     ] lt_dlhandle is 0x82895f0
00000000000i[PLGIN] loaded plugin libbx_dma.la
00000000000i[     ] lt_dlhandle is 0x8289c70
00000000000i[PLGIN] loaded plugin libbx_pic.la
00000000000i[     ] lt_dlhandle is 0x828a638
00000000000i[PLGIN] loaded plugin libbx_vga.la
00000000000i[     ] lt_dlhandle is 0x828a7d0
00000000000i[PLGIN] loaded plugin libbx_floppy.la
00000000000i[     ] lt_dlhandle is 0x828b320
00000000000i[PLGIN] loaded plugin libbx_harddrv.la
00000000000i[     ] lt_dlhandle is 0x829cf28
00000000000i[PLGIN] loaded plugin libbx_keyboard.la
00000000000i[     ] lt_dlhandle is 0x829d048
00000000000i[PLGIN] loaded plugin libbx_serial.la
00000000000i[     ] lt_dlhandle is 0x829d5d8
00000000000i[PLGIN] loaded plugin libbx_parallel.la
00000000000i[     ] lt_dlhandle is 0x829e208
00000000000i[PLGIN] loaded plugin libbx_extfpuirq.la
00000000000i[     ] lt_dlhandle is 0x829e6b0
00000000000i[PLGIN] loaded plugin libbx_gameport.la
00000000000i[     ] lt_dlhandle is 0x829f020
00000000000i[PLGIN] loaded plugin libbx_speaker.la
00000000000i[     ] lt_dlhandle is 0x829f598
00000000000i[PLGIN] loaded plugin libbx_pci.la
00000000000i[     ] lt_dlhandle is 0x829f6f8
00000000000i[PLGIN] loaded plugin libbx_pci2isa.la
00000000000i[     ] lt_dlhandle is 0x82a0128
00000000000i[PLGIN] loaded plugin libbx_pci_ide.la
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: Mon Jun  2 20:28:28 2008 (time0=1212452908)
00000000000i[DMA  ] channel 4 used by cascade
00000000000i[DMA  ] channel 2 used by Floppy Drive
00000000000i[FDD  ] fd0: 'floppy.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[XGUI ] test_alloc_colors: 16 colors available out of 16 colors tried
00000000000i[XGUI ] font 8 wide x 16 high, display depth = 24
00000000000i[MEM0 ] Register memory access handlers: e0000000-e07fffff
00000000000i[CLVGA] VBE Bochs Display Extension Enabled
00000000000i[CLVGA] interval=40000
00000000000i[PLGIN] init_mem of 'harddrv' plugin device by virtual method
00000000000i[PLGIN] init_mem of 'keyboard' plugin device by virtual method
00000000000i[PLGIN] init_mem of 'serial' plugin device by virtual method
00000000000i[PLGIN] init_mem of 'parallel' plugin device by virtual method
00000000000i[PLGIN] init_mem of 'extfpuirq' plugin device by virtual method
00000000000i[PLGIN] init_mem of 'gameport' plugin device by virtual method
00000000000i[PLGIN] init_mem of 'speaker' plugin device by virtual method
00000000000i[PLGIN] init_mem of 'pci_ide' plugin device by virtual method
00000000000i[PLGIN] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD   ] Using boot sequence floppy, none, none
00000000000i[HD   ] Floppy boot signature check is enabled
00000000000i[PLGIN] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD  ] will paste characters every 1000 keyboard ticks
00000000000i[PLGIN] init_dev of 'serial' plugin device by virtual method
00000000000i[SER  ] com1 at 0x03f8 irq 4
00000000000i[PLGIN] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR  ] parallel port 1 at 0x0378 irq 7
00000000000i[PLGIN] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[PLGIN] init_dev of 'gameport' plugin device by virtual method
00000000000i[PLGIN] init_dev of 'speaker' plugin device by virtual method
00000000000i[SPEAK] Failed to open /dev/console: No such file or directory
00000000000i[SPEAK] Deactivating beep on console
00000000000i[PLGIN] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[PCI  ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[SYS  ] bx_pc_system_c::Reset(HARDWARE) called
00000000000i[APIC0] local apic in CPU 0 initializing
00000000000i[PLGIN] reset of 'harddrv' plugin device by virtual method
00000000000i[PLGIN] reset of 'keyboard' plugin device by virtual method
00000000000i[PLGIN] reset of 'serial' plugin device by virtual method
00000000000i[PLGIN] reset of 'parallel' plugin device by virtual method
00000000000i[PLGIN] reset of 'extfpuirq' plugin device by virtual method
00000000000i[PLGIN] reset of 'gameport' plugin device by virtual method
00000000000i[PLGIN] reset of 'speaker' plugin device by virtual method
00000000000i[PLGIN] reset of 'pci_ide' plugin device by virtual method
00000000000i[XGUI ] [x] Mouse off
00000003740i[BIOS ] $Revision: 1.166 $ $Date: 2006/08/11 17:34:12 $
00000080000e[CLVGA] character height = 1, skipping text update
00000160000e[CLVGA] character height = 1, skipping text update
00000240000e[CLVGA] character height = 1, skipping text update
00000318057i[KBD  ] reset-disable command received
00000319679i[PIDE ] new BM-DMA address: 0xc000
00000320000e[CLVGA] character height = 1, skipping text update
00000400000e[CLVGA] character height = 1, skipping text update
00000443898i[VBIOS] VGABios $Id: vgabios.c,v 1.66 2006/07/10 07:47:51 vruppert Exp $
00000443969i[CLVGA] VBE known Display Interface b0c0
00000444001i[CLVGA] VBE known Display Interface b0c4
00000446926i[VBIOS] VBE Bios $Id: vbe.c,v 1.58 2006/08/19 09:39:43 vruppert Exp $
00000560000i[XGUI ] charmap update. Font Height is 16
00081582000p[XGUI ] >>PANIC<< POWER button turned off.
00081582000i[SYS  ] Last time is 1212452948
00081582000i[XGUI ] Exit.
00081582000i[CPU0 ] real mode
00081582000i[CPU0 ] CS.d_b = 16 bit
00081582000i[CPU0 ] SS.d_b = 16 bit
00081582000i[CPU0 ] | EAX=0000f001  EBX=00000000  ECX=00000001  EDX=00000000
00081582000i[CPU0 ] | ESP=00000000  EBP=00000000  ESI=000088ca  EDI=0000ffde
00081582000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df IF tf SF zf af pf cf
00081582000i[CPU0 ] | SEG selector     base    limit G D
00081582000i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00081582000i[CPU0 ] |  CS:0000( 1e00| 0|  0) 00000000 0000ffff 0 0
00081582000i[CPU0 ] |  DS:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00081582000i[CPU0 ] |  SS:ff53( 0000| 0|  0) 000ff530 0000ffff 0 0
00081582000i[CPU0 ] |  ES:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00081582000i[CPU0 ] |  FS:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00081582000i[CPU0 ] |  GS:0000( 0000| 0|  0) 00000000 0000ffff 0 0
00081582000i[CPU0 ] | EIP=00007c85 (00007c85)
00081582000i[CPU0 ] | CR0=0x00000010 CR1=0 CR2=0x00000000
00081582000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00081582000i[CPU0 ] >> jmp .+0xfffe (0x00007c85) : EBFE
00081582000i[     ] restoring default signal behavior
========================================================================
Bochs is exiting with the following message:
[XGUI ] POWER button turned off.
========================================================================
00081582000i[CTRL ] quit_sim called with exit code 1


None of the registers that should have data do.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 7:00 pm 
Offline
Member
Member
User avatar

Joined: Tue Apr 10, 2007 4:42 pm
Posts: 224
Is GAS compiling it as a FLAT BINARY? It seems like the code is executing (gets to the infinite loop), but improperly. Also, I don't think GAS will handle segment changing properly unless you explicitly tell it to.

Also, something weird is happening to your stack segment, and your segment registers aren't changing. Also, cli and sti only inhibit maskable hardware-generated interrupts, not ones you explicitly call.

For 16-bit, best to stay with an assembler like NASM.

_________________
"Sufficiently advanced stupidity is indistinguishable from malice."


Top
 Profile  
 
 Post subject: Bochs int 10h problems [SOLVED]
PostPosted: Tue Jun 03, 2008 10:00 am 
Offline

Joined: Mon Jun 02, 2008 4:53 pm
Posts: 4
I was able to figure the problem out. The problem was that gas assumes that unqualified numbers, such as 0x6d, are memory addresses. They have to be written as $0x6d to work. Here is my working code:

Code:
.code16

/* Jump past the BPP */
_start:
   jmp real_start
   nop

/* BPP */
bios_parameter_block:
   .quad 0

   .ascii "Fake Filler BPB 1.0000000"
   .byte 0
   .byte 0
   .byte 0
   .byte 0
   .quad 0
   .quad 0
   .quad 0
   .double 0
   .double 0
   .quad 0
   .double 0

real_start:
   /* Set Segment Registers */
   mov $0x07c0, %ax
   mov %ax, %ds
   
clear_screen:   
   /* Clear screen */
   mov $0x00, %ah
   mov $0x03, %al
   int $0x10

print:
   /* Print message */
   mov $0x0e, %ah
   mov $'H', %al
   mov $0x00, %bh
   mov $0x07, %bl
   int $0x10
   
   mov $'e', %al
   int $0x10
   
   mov $'l', %al
   int $0x10
   
   mov $'l', %al
   int $0x10
   
   mov $'o', %al
   int $0x10
   
   mov $13, %al
   int $0x10

   mov $10, %al
   int $0x10

/* Loop forever */
loop:
   jmp loop

/* Padding */
. = 510
.byte 0x55
.byte 0xaa


Thanks all.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 4:12 pm 
Offline
Member
Member
User avatar

Joined: Tue Apr 10, 2007 4:42 pm
Posts: 224
You're right. Since I use GAS for pratically all my OS assembly, I can't believe I didn't notice/remember that.

Best of luck with your OS!

_________________
"Sufficiently advanced stupidity is indistinguishable from malice."


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 42 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group