flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Case Study: FAT12 bootloader |
Author |
|
bitshifter 31 Jul 2010, 06:01
I am working on new memory map...
Soon kernel will have 64kb max size. Also stack will have 64kb free space. |
|||
31 Jul 2010, 06:01 |
|
egos 31 Jul 2010, 20:50
If you place stack before loader and loader before kernel you can use all remainder continuous space for loading kernel. But don't forget about EBDA. You would use int 12h to get available memory. Here is the memory map from my boot spec (I'm using linear addressing in RM):
00000: IVT 00400: BDA 00500: used by BIOS? 00600: stack for loader/maybe some buffers 07C00: first sector of bootblock 07E00: additional sector of bootblock/data/unused 08000: kernel (its size is multiple of 1K) XXXXX aligned on 1K boundary: additional module (boot device and FS driver) XXXXX: free XXXXX aligned on 1K boundary: EBDA A0000: video RAM C0000: video ROM etc. When starting kernel it usually moves 0 into ss and 8000h into sp and then jumps to 0:next_instruction. |
|||
31 Jul 2010, 20:50 |
|
SeproMan 01 Aug 2010, 20:27
Some observations about your code:
To optimize your code:
One final suggestion. Take a look at the bootloader I posted today... _________________ Real Address Mode. |
|||
01 Aug 2010, 20:27 |
|
bitshifter 02 Aug 2010, 00:59
Thanks for the reply...
> _drive_number is NOT a word. It's a byte followed by a reserved byte! I will seperate them for clarity... > _heads_per_cylinder is confusing. Better use just _heads Really? > Whether the drive signature is 29h has nothing to do with a floppy or not Hmm, i read that in the FAT12 specs... > Luckily those 14 and 9 sectors are all on the same track. Else it would not work! I took certain liberties for simplicity > Make sure that the direction flag is clear before using string primitives Would the BIOS ever leave me with dirty FLAGS register? Anyway it probably a good idea to use it at least once. > Better use REPE CMPSB instead of trusting default behaviour of any assembler What? and Where? > Your "0eh shl 4" must shift left 8 times to get AH=0Eh Oops, thats surely my mistake... > The BIOS Teletype also needs at least BH=0 (BX=0007h) Correct, BH = the page number, BL only used in graphics modes. > Why not load 256 bytes higher in memory? Address 0500h does contain 1 BIOS variable. I will have to check a bit further into this... > For clarity don't be afraid to use expressions like ADD AX,1+9+9+14-2 Ok, understood. > Why do you STC before doing INT 13h? Some BIOS dont correctly set carry flag on failure. > Your "read_sectors" routine will NEVER return with the carry set! It will try to load the sectors indefinitely because you put a limit of 5 tries only on the reset function! Yep, i left the comment, but will remove it... To optimize your code: > Drop DS: and ES: everywhere Im ot sure how/where that will make any difference? > Use CWD instead of XOR DX,DX before that division, it safes 1 byte Ok, cool > Don't XOR DX,DX before MUL CX, it's useless There is a div instruction a little further down uses it. > Because you're working on a floppy you can byte-divide by the number of heads thus saving the XOR DX,DX How you mean that? > You don't really need the JMP 0:purge_code Its to make sure we have valid CS:IP > INC DL can safely be shortened with INC DX It saves a byte, cool > By NOT calling routine "int13" you could save some bytes I wasnt sure if int 13h would trash any registers so i pusha/popa I guess i can clean that up also. Well it seems i have some work to do. Thanks for taking a peek at it. |
|||
02 Aug 2010, 00:59 |
|
egos 02 Aug 2010, 02:48
Wow, guys! May you will become my friends? I have written some boot loaders and now I'm working on CD (ElTorito) boot loader.
|
|||
02 Aug 2010, 02:48 |
|
revolution 02 Aug 2010, 02:52
bitshifter wrote: > Don't XOR DX,DX before MUL CX, it's useless |
|||
02 Aug 2010, 02:52 |
|
egos 02 Aug 2010, 07:04
Floppy is a legacy storage device. But writing code for it is a good practice. Do you know about short format of BPB or about redefinition DPT (diskette parameter table)? I should show my boot loader for floppy. Just please don't say me about hard coded constants and comments. It was written about 10 years ago in my pupilage and was oriented on the 2x80x18 floppies only. It is working fine in our projects a long time. But one my friend (and partner) said me something about checking for last valid dir entry.
|
|||||||||||
02 Aug 2010, 07:04 |
|
SeproMan 08 Aug 2010, 17:09
Quote:
Each time you use a segment override prefix like DS: or ES: the assembler adds 1 byte to the code. When optimizing for size that counts! Quote:
Since your program is up and running you already have a valid CS:IP. You don't make any specific reference to CS, so the exact value is of no importance. Quote:
The numbers participating in this division are small. Both the quotient and the remainder fit in a byte. Don't waste DX. Quote:
You wrote REP CMPSB to compare the 11 character filename in the directory entry. REPE CMPSB is better because it truly expresses what you intended to achieve. "Repeat WHILE EQUAL Compare String Byte" _________________ Real Address Mode. |
|||
08 Aug 2010, 17:09 |
|
bitshifter 08 Aug 2010, 20:47
SeproMan wrote:
This is only true if you specify a segment other than default. So removing all those references does nothing to its size. I put them in there for clarity. _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
08 Aug 2010, 20:47 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.