Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 19th, 2006, 8:40 PM   #1
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 437
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
Angry Why doesn't this work?

I'm working with FASM and essentially I'd just like the letter 'a' to appear from this boot loader code. I have no problems creating the disk or anything like that, but the code doesn't appear to work. Wondering if anyone can tell me what I'm doing wrong.
jmp 07c00h ; boot code start
mov ah, 09h
mov al, 97
mov bx, 100b
mov cx, 01h
int 10h
times 0x1fe-$ db 00h ; pads with 0's
db 55h,0aah ; boot signature
Thx for the help.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Oct 19th, 2006, 9:37 PM   #2
niteice
Programmer
 
niteice's Avatar
 
Join Date: Aug 2005
Posts: 98
Rep Power: 4 niteice is on a distinguished road
Send a message via AIM to niteice
You should clear the (segment) registers first.
niteice is offline   Reply With Quote
Old Oct 20th, 2006, 12:04 AM   #3
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 437
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
I believe that's what you were saying, but it doesn't appear to be working either.
mov ax, cs
mov ds, ax
mov es, ax
mov ah, 09h
mov al, 97
mov bx, 100b
mov cx, 01h
int 10h
times 0x1fe-$ db 00h ; pads with 0's
db 55h,0aah ; boot signature
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Oct 20th, 2006, 6:18 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
jmp 07c00h ; boot code start;  off we go, unconditionally
mov ah, 09h; execution will not reach here unless there's a branch to here
mov al, 97;    from somewhere else.
mov bx, 100b
mov cx, 01h
int 10h
times 0x1fe-$ db 00h ; pads with 0's
db 55h,0aah ; boot signature
This is pretty sparse, information wise. Issues such as privilege may or may not arise.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 20th, 2006, 2:05 PM   #5
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 437
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
Yeah I realized that the jmp was branching me somewhere it wasn't supposed to, but removing that instruction as in the reply before yours, and messing with those registers as niteice suggested didn't work either. For some reason the code produces the correct output on one emulator. However, when I try to put it in the bootsector of a floppy image and boot it in Bochs no output is produced. With a modification of other code It does work and I honestly can't tell why. This is the modified code from the bootstrapper of MenuetOS and I just stripped it down so that it would only display MenuetOS on the screen.
boot_program       equ 07c00h ;position for boot code
   
                   jmp start_program
                   nop
   



start_program:

  xor ax,ax
  mov ss,ax
  mov sp,boot_program
  push ss
  pop ds

  mov  si,loading+boot_program
loop_loading:
  lodsb
  or al,al
  jz procura_arquivo_novamente
  mov ah,0eh
  mov bx,07h
  int 010h
  jmp loop_loading


procura_arquivo_novamente:

  push ss
  pop es

  mov  bp,16

newtry:

  dec bp

loop_envio_mensagem:

  lodsb
  or al,al
  jz espera_digitar_tecla
  mov ah,0eh
  mov bx,07h
  int 010h
  jmp loop_envio_mensagem

espera_digitar_tecla:

  jmp $

loading   db 13,10,'Starting MenuetOS ',00h


times 0x1fe-$ db 00h

  db 55h,0aah ;boot signature
I fail to understand why this works and my simpler code doesn't.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Oct 20th, 2006, 2:20 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Perhaps your boot isn't setting up the software interrupt vectors, whereas your emulator is. Perhaps your boot is switching you into a protected mode before you're ready. Again, there is little overall information here. Do you know what takes place during the booting process, or are you more or less copying something and trying to modify it?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 20th, 2006, 2:57 PM   #7
niteice
Programmer
 
niteice's Avatar
 
Join Date: Aug 2005
Posts: 98
Rep Power: 4 niteice is on a distinguished road
Send a message via AIM to niteice
Shouldn't you have [org 0x7c00] instead of manually jumping there? Seems like a fairly roundabout way of getting the desired effect, and it probably isn't even right.
niteice is offline   Reply With Quote
Old Oct 20th, 2006, 3:09 PM   #8
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Not sure whether you have to do it this way for an assignment for your school, otherwise I would use an existing bootloader like GRUB if you want to write an operating system - when you start with the bootloader, there's a big risk that you give up before you even started on the actual work .
Polyphemus_ is offline   Reply With Quote
Old Oct 20th, 2006, 4:14 PM   #9
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 437
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
DaWei
Here's what I understand about the boot process. After the power and motherboard perform the POST and the like. The computer searches the first sector (512 bytes at 0:0:1) of one of the I/O drives (be it a hard drive or floppy or CD or however else your BIOS specifies it). This segment of code which should terminate with the "magic number" 0x55AA. Is loaded into the RAM at location 0x7C00. From here execution begins based on whatever you had in that 512 bytes of code assuming of course it meets the "magic number" condition and it is in fact 512 bytes long. Both of these conditions are met in the code that I wrote as I understand it. These are the only two conditions I have to meet in as far as I know. The Bochs emulator is loading the boot sector of a floppy image. Which works based on the most recent code I posted. This code is just modified code from the MenuetOS bootstrapper 'cause I wanted to see if I could get something to work since obviously my code isn't working and I don't know why. Whatever that segment of code from MenuetOS is doing it makes the characters MenuetOS appear on the virtual monitor of the Bochs emulator, which means that if I took it onto an actual computer it would most likely work. However, my own code which should've just printed an 'a' character on the screen isn't working. Therefore, logically, the problem is my code and not the Bochs emulator. The copy and modify is only because I wanted to get something which would display so as not to grow discouraged. I'm actually hoping that I understand the boot process, at least after the POST test so that I can just code a simple bootstrapper which prints 'a' on the screen, and then I'll go further from there. One step at a time I hope.

niteice
The [org 0x7c00] directive only specifies where the programmer believes the actual program will be in memory. In this case I know (or I think I know rather) the program is being loaded into 7c00. In the MenuetOS code listed there that jmp instruction was actually followed by a series of data declarations. Hence, why the program jmps. However, those bytes weren't relevant to the printing of the characters 'MenuetOS'.

Polyphemus_
The idea of an OS is cool, but I doubt I could ever get something like that working. More than anything I just want to display some text lol. This isn't for school, just satisfaction of my own curiosity and to see if I can grasp at any sort of "mastery" over assembly language. I realize that I can use assembly to program via the win32 api and all that other stuff, but I mean just nitty gritty fundamental stuff where here's the processor now do stuff with it with some limited inputs and outputs. Kinda like if I were programming a PIC microcontroller. I realize the levels of difficulty are very different, but I can control a stepper motor with a PIC lol.
-----------------------------------
So let me see if I can redefine my question. Compare these two segements of code:
MY CODE
mov ah, 09h
mov al, 97
mov bx, 100b
mov cx, 01h
int 10h
times 0x1fe-$ db 00h ; pads with 0's
db 55h,0aah ; boot signature
MenuetOS CODE
boot_program       equ 07c00h ;position for boot code
   
                   jmp start_program
                   nop
   



start_program:

  xor ax,ax
  mov ss,ax
  mov sp,boot_program
  push ss
  pop ds

  mov  si,loading+boot_program
loop_loading:
  lodsb
  or al,al
  jz procura_arquivo_novamente
  mov ah,0eh
  mov bx,07h
  int 010h
  jmp loop_loading


procura_arquivo_novamente:

  push ss
  pop es

  mov  bp,16

newtry:

  dec bp

loop_envio_mensagem:

  lodsb
  or al,al
  jz espera_digitar_tecla
  mov ah,0eh
  mov bx,07h
  int 010h
  jmp loop_envio_mensagem

espera_digitar_tecla:

  jmp $

loading   db 13,10,'Starting MenuetOS ',00h


times 0x1fe-$ db 00h

  db 55h,0aah ;boot signature

MY CODE doesn't boot on a Bochs emulator. The MenuetOS code does boot on the Bochs emulator. What is the menuetOS code doing that I am not doing and therefore failing to create a primitive bootstrapper? Is there some procedure relevant to the boot process (once the boot sector has been loaded into memory) that I have failed to take into account/do in my own code?
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Oct 20th, 2006, 4:26 PM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
int 10h

That is a key thing. It amounts to an indirect call of some particular function, of which there are normally many. If your boot process is not setting those up, but the MenuetOS thing is, that's one significant difference. A number of those wind up calling functions that live in the BIOS, others call functions that have to be loaded into the system (such as the large number of MSDOS calls that were available after a system booted MSDOS). I have not looked under the hood in years, but those software interrupts used to live in the memory beginning at location 0 (real memory address). Each storage location was considered a vector. That is, it contained the address of some function to execute. One could replace the vector with one's own function address and then call the old vector when one's function was done. This was a way to chain in things like timer functions, TSR apps, etc.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
tables dont work in firefox; they work in IE angry_asian HTML / XHTML / CSS 3 Aug 5th, 2006 7:00 PM
my console apps just close...system("pause") doesnt work angry_asian C++ 22 Jul 2nd, 2006 5:38 PM
Help:::::::: Why Wont This Work?????? paulchwd ASP 1 Jul 10th, 2005 2:34 PM
Can't get loop to work rockybalboa Java 3 Mar 20th, 2005 7:19 PM
40 Things you'd like to say out loud at work big_k105 Coder's Corner Lounge 11 Jan 25th, 2005 3:13 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:59 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC