flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > Cannot load GDT and go 32Bits |
Author |
|
antoniovazquezblanco 02 Dec 2010, 21:38
I've started to write my own OS.
First of all my code is hosted on GitHub: https://github.com/firebirdysc/Firebird-OS I've written a bootsector that loads a bootloader. My problem is that my bootloader can't load the GDT. If I use the same code in a separated file declaring ORG 7C00 it runs properly so I deduce that the problem resides in the value of the reisters but I'm lost. Can anybody review this code? Thanks! |
|||
02 Dec 2010, 21:38 |
|
antoniovazquezblanco 03 Dec 2010, 07:57
Humm I didn't really knew where to load my code. Where would you load it? In my repo there is a docs folder. This is a memory map. What errors did I commit?
Code: Starting address Ending address Content 00000 003FF Interrupt Vector Table 00400 004FF BIOS Data Area 00500 07BFF FREE MEMORY! 07C00 07DFF Boot Sector 07E00 9FBFF FREE MEMORY! 9FC00 9FDFF Kernel 9FE00 9FFFF Boot Loader A0000 BFFFF Video Memory C0000 C7FFF Video BIOS C8000 EFFFF BIOS Shadow Area F0000 FFFFF System BIOS |
|||
03 Dec 2010, 07:57 |
|
edfed 03 Dec 2010, 16:53
you can simplify with this equation:
bootloader = bootsector kernel = 1000h:0 |
|||
03 Dec 2010, 16:53 |
|
antoniovazquezblanco 03 Dec 2010, 18:27
edfed wrote: you can simplify with this equation: Bootloader + Bootsector > 512B... Too big to have a decent check system... |
|||
03 Dec 2010, 18:27 |
|
edfed 03 Dec 2010, 18:30
no need to check, if it happen to don't work, it just means there is a problem, and check for problems will not solve it not help to solve it.
for example, if your checker says, problem, unable to load kernel, it just means that you should first do a good loader, tested, and tested again, ones it works, it works. you just have to load kernel sectors to a location and jump to (or call) it. |
|||
03 Dec 2010, 18:30 |
|
antoniovazquezblanco 03 Dec 2010, 19:05
edfed wrote: no need to check, if it happen to don't work, it just means there is a problem, and check for problems will not solve it not help to solve it. Hummm. I can do everithing on the kernel . Thanks, I'll start now! |
|||
03 Dec 2010, 19:05 |
|
antoniovazquezblanco 03 Dec 2010, 19:54
Still crashing...
Bootloader loads kernel in 1000h:0. Kernel starts and enables A20 gate. GDT is loaded but I can't switch to PM... Please can anybody check kernel/kernel.asm file? Thanks! |
|||
03 Dec 2010, 19:54 |
|
ManOfSteel 03 Dec 2010, 20:28
For starters the GDT size (line 161) is wrong. It should be gdt_end-gdt-1. And by the way, the comment is wrong as your GDT has 3 descriptors, i.e. 24d/0x18 bytes.
|
|||
03 Dec 2010, 20:28 |
|
antoniovazquezblanco 03 Dec 2010, 21:48
ManOfSteel wrote: For starters the GDT size (line 161) is wrong. It should be gdt_end-gdt-1. And by the way, the comment is wrong as your GDT has 3 descriptors, i.e. 24d/0x18 bytes. Done. It doesn't work... do you see anything else? By the way, I cant understand your correction in my comment... |
|||
03 Dec 2010, 21:48 |
|
ManOfSteel 03 Dec 2010, 22:39
Okay, I took a longer look at your code. The problem is simple: the real-mode addressing is completely wrong.
First, load your kernel at a slightly lower address (0x9c0 for instance) so that the full offset is smaller than a word/64KB or else it won't even assemble the jump in the kernel at line 139. Then, make sure you copy the GDT using valid addressing. Now you can notice the protected mode works because it prints the green "S" at the top left corner. I also set the GDT base at 0x500 like your comment at line 119 says. Take a look at the diffs (bootsect.asm and kernel.asm respectively): Code: 100c100 < mov ax, 0x9c0 ;ES:BX = 1000:0000 --- > mov ax, 1000h ;ES:BX = 1000:0000 122c122 < jmp 0x9c0:0000 ;Jump to the program --- > jmp 1000h:0000 ;Jump to the program Code: 118,120c118,120 < mov si, gdt+0x9c0*16 ;start of GDT table into SI register < mov di, 0x500 ;locate GDT at 500h in memory < mov cx, gdt_end-gdt ;size of the GDT (defined my fancy footwork) --- > mov si, gdt ;start of GDT table into SI register > mov di, [gdtbse] ;locate GDT at 500h in memory > mov cx, [gdtsze] ;size of the GDT (defined my fancy footwork) 139c139 < jmp 08h:protected_mode+0x9c0*16 --- > jmp 08h:protected_mode 151c151 < mov word [0xb8000],'S ' --- > 162c162 < gdtbse dd 0x500 ;where GDT is located at (bootloader_end+gdt) --- > gdtbse dd 0xA0000 + gdt ;where GDT is located at (bootloader_end+gdt) ~~~~ antoniovazquezblanco wrote: By the way, I cant understand your correction in my comment... Just look at your code. How long is a segment descriptor? dd*2 or dw*2+db*4 = 8 bytes, not 64. It ensues that, having 3 descriptors, your GDT is merely 8*3=24 bytes long, not 192. |
|||
03 Dec 2010, 22:39 |
|
antoniovazquezblanco 03 Dec 2010, 23:03
Em... Feel so stupid.... emm THANKS! ^^. You're really cool! I really feel very pleased . WORKED!
|
|||
03 Dec 2010, 23:03 |
|
antoniovazquezblanco 05 Dec 2010, 17:45
As I followed your suggestions I consider the next question should be here.
I've created a function: Code: kernel_main() { } In C that prints a string. I've compiled both files with .o elf files as the result. I now want to link both. Can I link them or do I need to create a new bin file and call it? Thanks! |
|||
05 Dec 2010, 17:45 |
|
Coty 05 Dec 2010, 18:05
You can link them... Here is a tut on how to link FASM and TCC...
Are you trying to link both and get a raw BINARY file? Is this even possible? I hope you are not trying to link your boot sector and kernel together |
|||
05 Dec 2010, 18:05 |
|
antoniovazquezblanco 05 Dec 2010, 19:27
Not bootsector +kernel but almost. Bootsector only loads a file that enables A20 and set GDT and jumps 32bits. That is 16Bit code wich I want to link to 32Bit code + 32Bit C code... Can I? Xd don't think that is possible, but you told me not to use a 2 stage bootloader so maybe I'm not right... xD
|
|||
05 Dec 2010, 19:27 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.