flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Converting IBM PC BIOS to FASM syntax |
Author |
|
nkeck72 12 Dec 2015, 21:43
Hi all, I am happy to say that I have successfully found the source code for the original IBM PC BIOS code at https://sites.google.com/site/pcdosretro/ibmpcbios. The source code was written in another assembler's syntax (Looks to me like NASM or MASM) and wish to convert it to a more understandable FASM syntax for two reasons:
1.) I wish to understand more about how the BIOS worked and how it tested all the different hardware and 2.) I wish to see if it compiles, and if it does I want to see how their source code was written to get all the data structures in their exact places. I also want to convert this to FASM syntax as I am starting a BIOS project and want to see what structure I should generally follow. However, the syntax is obviously from another assembler and I cannot seem to make any sense of it. I need help converting this code to a format FASM can understand, seeing as I will be using FASM to construct my project. I will definitely need help with this, and will set up a GitHub page for those who wish to contribute. In the mean time, I will post up the source code in the old syntax. The one thing that has been giving me the most trouble are the "* SEGMENT AT *" statements, which FASM doesn't seem to have support for in anything but MZ format. Cheers!
_________________ It may look hard, but it won't take long if you take it one byte at a time. NOS: www.github.com/nkeck720/nos |
|||||||||||
12 Dec 2015, 21:43 |
|
nkeck72 13 Dec 2015, 04:43
So what of this:
Code:
ABS0 SEGMENT AT 0
How would this translate? And what register is it setting? |
|||
13 Dec 2015, 04:43 |
|
revolution 13 Dec 2015, 04:52
No register is being set. The label ABS0 is allocated to address 0:0
|
|||
13 Dec 2015, 04:52 |
|
Tomasz Grysztar 13 Dec 2015, 12:39
To convert this to fasm syntax you'd have to drop all the ASSUME statement, because fasm does not track segment registers (the "flat" in its name originally referred to exactly that). Unfortunately that means you then have to be aware of how the label you use relates to the contents of segment registers at given moment - because of that writing segment code in NASM/fasm syntax is a bit harder.
And this also means that in the conversion the SEGMENT AT syntax becomes meaningless. You can rewrite this part: Code: ABS0 SEGMENT AT 0 STG_LOC0 LABEL BYTE ORG 2*4 NMI_PTR LABEL WORD ORG 5*4 INT5_PTR LABEL WORD ORG 8*4 INT_ADDR LABEL WORD INT_PTR LABEL DWORD ORG 10H*4 VIDEO_INT LABEL WORD ORG 1DH*4 PARM_PTR LABEL DWORD ; POINTER TO VIDEO PARMS ORG 01EH*4 ; INTERRUPT 1EH DISK_POINTER LABEL DWORD ORG 01FH*4 ; LOCATION OF POINTER EXT_PTR LABEL DWORD ; POINTER TO EXTENSION ORG 7C00H BOOT_LOCN LABEL FAR ABS0 ENDS Code: ; Note: these labels refer to offsets in segment 0 LABEL STG_LOC0 BYTE AT 0 LABEL NMI_PTR WORD AT 2*4 LABEL INT5_PTR WORD AT 5*4 LABEL INT_ADDR WORD AT 8*4 LABEL INT_PTR DWORD AT 8*4 LABEL VIDEO_INT WORD AT 10H*4 LABEL PARM_PTR DWORD AT 1DH*4 LABEL DISK_POINTER DWORD AT 01EH*4 LABEL EXT_PTR DWORD AT 01FH*4 LABEL BOOT_LOCN AT 7C00H And then this one: Code: DATA SEGMENT AT 40H RS232_BASE DW 4 DUP(?) ; ADDRESSES OF RS232 ADAPTERS PRINTER_BASE DW 4 DUP(?) ; ADDRESSES OF PRINTERS EQUIP_FLAG DW ? ; INSTALLED HARDWARE MFG_TST DB ? ; ... DATA ENDS Code: VIRTUAL AT 0 ; Note: these labels refer to offsets in segment 40h RS232_BASE DW 4 DUP(?) ; ADDRESSES OF RS232 ADAPTERS PRINTER_BASE DW 4 DUP(?) ; ADDRESSES OF PRINTERS EQUIP_FLAG DW ? ; INSTALLED HARDWARE MFG_TST DB ? ; ... END VIRTUAL When looking at this thread I had a thought that I could perhaps create a variant of my x86 macros for fasm g that would handle this syntax, and then you could reassemble this entire source with fasm g after only adding a single INCLUDE line on top. I think it would be quite easy to do (with ELEMENT-based segmented addresses the bracket-less memory operand would be distinguished from an absolute value and the right segment prefix could be chosen after extracting the segment number from ELEMENT metadata). But when I look at this syntax I also recall all the reasons I had for hating it, so I'm not jumping to it. |
|||
13 Dec 2015, 12:39 |
|
ACP 13 Dec 2015, 14:42
First of all I suggest you read Bios Disassembly Ninjutsu book http://www.amazon.com/BIOS-Disassembly-Ninjutsu-Uncovered/dp/1931769605
The author released some time ago PDF version of it. Secondly the assembler used is old version of MASM. You may download old MASM versions here for example: https://winworldpc.com/ It can't be in NASM syntax due to its age. Secondly - I know it it quite perverse method since you will either need to compile the source code or use BIOS ROM dump - but you can either try to use IDA or Sourcer Bios Preprocessor (take a look in here: https://corexor.wordpress.com/2015/12/09/sourcer-and-windows-source/) and select TASM as output assembler. This will be as close as you can get for FASM syntax. |
|||
13 Dec 2015, 14:42 |
|
nkeck72 13 Dec 2015, 15:22
Thanks much, I will download MASM and see if what ACP mentioned works.
Tomasz, I am assuming that your post means there is no way to explicitly specify to FASM what segments are being referred to in the SEGMENT AT statements? Also, yeah, I hate this syntax as well, it looks like a mess to me |
|||
13 Dec 2015, 15:22 |
|
Hayden 17 Dec 2015, 17:16
All BIOS code is coded for the motherboard its embedded on. data structures and code will vary with different manufuacture's. If you would really like to know how the BIOS operates and its services you might want to take a look it the following attachment.
_________________ New User.. Hayden McKay. |
|||||||||||
17 Dec 2015, 17:16 |
|
ACP 17 Dec 2015, 17:52
IMHO looking at coreboot + SeaBIOS sources and documentation is a better idea, but your mileage may vary.
http://coreboot.org The one big advantage is that coreboot + SeaBIOS can be run using QEMU while not every other BIOS will work correctly. |
|||
17 Dec 2015, 17:52 |
|
nkeck72 21 Dec 2015, 17:41
Hayden - The IBM PC became a standard in pretty much everything, right down to the I/O ports and the structures used. I think that looking through this BIOS would help, since it is essentially the standard for any PC with a BIOS (none of that UEFI rubbish). Thanks for the links, though, will do a bit of reading on those!
_________________ It may look hard, but it won't take long if you take it one byte at a time. NOS: www.github.com/nkeck720/nos |
|||
21 Dec 2015, 17:41 |
|
revolution 21 Dec 2015, 18:04
nkeck72 wrote: Hayden - The IBM PC became a standard in pretty much everything, right down to the I/O ports and the structures used. I think that looking through this BIOS would help, since it is essentially the standard for any PC with a BIOS (none of that UEFI rubbish). |
|||
21 Dec 2015, 18:04 |
|
nkeck72 21 Dec 2015, 18:11
Notice I said that it will help - I am not going to base the entire BIOS off of the IBM PC. The only reason I am interested in it is that it is a standard - the I/O ports and memory layout aren' gonna change anytime soon.
|
|||
21 Dec 2015, 18:11 |
|
ACP 22 Dec 2015, 20:30
revolution wrote: Sure, if you want FDD, DMA, parallel ports and serial ports and all the old peripheral interfaces. The current PCs you can buy today have changed considerably. For example ACPI, PCI bus, USB, south/north bridge, HDMI, touchpad, GPU, sound, etc. None of those things existed in the original PC. True, but coreboot does support most of newest technology sometimes in few different forms. The potential drawback is that it is using 3rd party binary blobs for some things but this is only due to the fact that manufacturer never released documentation or sources or there are restricted NDAs in place. Still it is great resource to learn about modern legacy BIOS thanks to SeaBIOS and other options includign UEFI. |
|||
22 Dec 2015, 20:30 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.