0xd3ba wrote:
Anyways, as far as I know,
-Ttext <linear_address> places the text section starting at location
linear_address right ? So if that is true, then shouldn't
ljmp work only when
-Ttext 0x7c00 ? I mean
ljmp jumps to location 0x7c0:offset and the offset is calculated from the starting address of the code and BIOS places the bootloader at address 0x7c00. Please correct me if I'm wrong
That's correct, you specify the address on the command line (without segment). But if you set the segment base address, then your segment offset should start at zero.
Now imagine that the difference of the text segment and your _here label is 0x1b for example. Then if you tell your linker to start the text segment at 0x7c00, then your _here label will be placed at address 0x7c1b. So the "ljmp 0x7c0:_here" will be translated to "ljmp 0x7c0:0x7c1b" which jumps to the wrong address. You either need "ljmp 0x7c0:0x1b" or "ljmp 0:0x7c1b".
I'd recommend to use CS=0 instead ("ljmp 0:_here"), that's clearer and easier, because there linear address == segment offset. It has a downside that you'll be limited to approx 32k of code (7c00-ffff instead of 500-ffff), but that should be more than enough to load your kernel.
My loader for example is 11k in size, and that includes serial console, VBE handling, gzip deflate uncompressor, PE and ELF parser, CRC32c and SHA-256 checksum calculation, SMP set up, GPT parser, USTAR, CPIO, FAT16, FAT32 and other filesystem parsers, and even initrd decryption, not to mention RAID mirror support, El Torito, Multiboot, Linux boot and BBS ROM compatibility layers. And with all those features I've only filled up the 1/3rd of the available space.
Cheers,
bzt