• How to run ASM x86 that is longer than 512B
    12 replies, posted
Hi guys, I'm working on an assembly project, which is basically making a piano from scratch. I'm using VMWare, asm x86 (16 bits only) and I'm having trouble with the length of my program. As the script must be smaller than 512 bytes (which is the size of the master boot record), I would like to know if there's a quite simple way to use a bootloader that can link multiple parts of the script together, so that I can extend my program beyond basic highlighting chars feature. I know that's what I should do, but every documentation I found stops at this point. (Don't ask me why I'm doing this, school stuff)
There are plenty of resources on writing bootloaders, and you can just read the MBR stages of existing ones (e.g. [url=http://anonscm.debian.org/cgit/lilo/lilo.git/tree/src/mbr.S]LILO[/url]). But I imagine your class would've included instructions on how to access storage if they wanted you to.
The bootloader isn't really the issue, I found a couple of tutorials on how to write one, what I'm stuck on is how do I put my actual code on a virtual disk (VMWare). Our teacher implied that having a bootloader to run longer code was an option, however our assembly course consisted of a single day where we learned simple arithmetic operations. And we used emu8086 so we have no experience in running assembly on a virtual machine, so far I've used NASM but the project will defenitely require more than 512 instructions, that's why I'm planning ahead and looking into making a bootloader.
The MBR boot loader area is likely too small for your code. What you can do is to write code in this area that loads more code from a disk, as [url=http://wiki.osdev.org/Rolling_Your_Own_Bootloader#How_do_I_actually_load_bytes]hinted at here[/url]. If you're using a virtual floppy image (you probably are), fill the area after the loader code with enough data to occupy the sector, then use int 13h to load the rest of your code from floppy and jump to it.
[QUOTE=Eirheinger;50336659]The bootloader isn't really the issue, I found a couple of tutorials on how to write one, what I'm stuck on is how do I put my actual code on a virtual disk (VMWare). Our teacher implied that having a bootloader to run longer code was an option, however our assembly course consisted of a single day where we learned simple arithmetic operations. And we used emu8086 so we have no experience in running assembly on a virtual machine, so far I've used NASM but the project will defenitely require more than 512 instructions, that's why I'm planning ahead and looking into making a bootloader.[/QUOTE] You can use dd to write a disk image, not sure how well VMware handles odd sizes so you may want to make a standard floppy disk image which is 2880 sectors. Here some work I did ages ago: [url]https://github.com/Chryseus/aros[/url]
Thank you for the link ! I searched about dd, but looking at your work I found pretty big lacks in my own code, actually I managed to reduce its size considerably. Because I had new space available, I preferred work harder on the other part of the project, making actual sounds through the speakers. Fifty fifty, kind of works but I'm not satisfied : I have a huge delay before a sound come out again. Do you guys know if deactivating the sound port could cause such problems ? Is a for loop with many iteration between port ON and port OFF lines a good way to make the sound longer ? (EDIT: NO it isn"t. I was foolish to think so. A timer is a better idea) I know this isn't really part of the topic, but it would be really helpful !
Most audio processing is done with two threads, one thread processes the audio and prepares a buffer, then a second thread reads from that buffer and plays the audio. Double buffering done right makes sure that there are no gaps in playback by preprocessing audio signals before they're played.
[QUOTE=FalconKrunch;50417063]Most audio processing is done with two threads, one thread processes the audio and prepares a buffer, then a second thread reads from that buffer and plays the audio. Double buffering done right makes sure that there are no gaps in playback by preprocessing audio signals before they're played.[/QUOTE] ...that is waaay overkill for what OP is trying to do. You don't need multithreading or double buffering when outputting sounds to the [I]motherboard speaker[/I] (at least I assume that's what OP's expected to use) from a [I]bootloader[/I].
Right now, I found out how to use speakers through port 61h and change frequency through port 43h. What I'm doing is : -Initialize port 43h -Turn speakers ON through port 61h -Change frequency through port 42h (if needed) -Turn speakers OFF Now that I have this, I should make a timer (or whatever you call it), so the sound will stay a bit before the speaker turns OFF. (tried rdtsc, didn't worked, 90% chance I'm doing it wrong) [editline]30th May 2016[/editline] Okay, I did it. Using interruption 0x1A with AH = 0 ; I get the number of seconds since midnight. Little loop with substraction test, and 1 second sound comes out. Time to mix this feature with everything else !
As I reached the end of the master boot record, I finally have to write a bootloader. I took a look at Chryseus's work (which is wonderfully commented, used some of his code, but nothing works.. I asked to some teachers, they gave me a tutorial, which doesn't work neither. Everything works fine (int 13h, etc) and then, on jump instruction, nothing happens.... Does someone have an idea ?
[QUOTE=Eirheinger;50454370]As I reached the end of the master boot record, I finally have to write a bootloader. I took a look at Chryseus's work (which is wonderfully commented, used some of his code, but nothing works.. I asked to some teachers, they gave me a tutorial, which doesn't work neither. Everything works fine (int 13h, etc) and then, on jump instruction, nothing happens.... Does someone have an idea ?[/QUOTE] I suggest you use bochs with gdb and step through it, I'm pretty sure the kernel loading code is fine although I didn't test it over 20 sectors.
[QUOTE=Chryseus;50455172]I suggest you use bochs with gdb and step through it, I'm pretty sure the kernel loading code is fine although I didn't test it over 20 sectors.[/QUOTE] Ninja'd. While you'll eventually want your code to run in VMWare if that's what your teachers expect, VMWare is really not a good tool for [I]developing[/I] boot code. Bochs is an emulator that will allow you to watch it working every step along the way.
Finally it works ! I'm not proud of it though. I took the whole code of Chryseus. Of course it worked. Then I took the pieces down instruction by instruction, dropping all the functionalities I do not need in my project. (instead of adding functionalities one by one) I'd like to thank you all for the help, It really made the difference. (yeah I love licking some ass, sorry) PS: I'll use Bochs as soon as possible !
Sorry, you need to Log In to post a reply to this thread.