flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > [CONTRIBUTION] Long mode multi-core test pre-OS |
Author |
|
Madis731 14 Jan 2010, 19:53
Problems solved:
-pre-boot environment, multiple loading stages -built-in FAT12 image-maker (from source to *.IMG in one click ) -GDT/IDT initialized -directly to long mode (16-bit => 64-bit) -paging (in long mode there's no way around) -Use APIC to initiate IPI -program PIC and INTs -keyboard input (sort of - only increments a counter on anykey-press) Missing: -MP floating structure skipped (some emulators/PCs don't have it? why?) -need to replace PIC timer with APIC one (PIC only works on BSP) Usage: You can change Stage2\IPI_KRNL.asm and assemble only IPI_KRNL.asm and IPI_test.asm -OR- If you need to change all sources you are better off editing make_IPI_test.bat to make 'fasm' point to the correct executable and then run the batch.
|
|||||||||||
14 Jan 2010, 19:53 |
|
Madis731 16 Jan 2010, 10:15
The suggested part is what confuses me. Why are there so many places it can be and how do I know that I've searched all of them?
a) What gives me the EBDA 1st KB? b) What does undefined mean and where is the end of base memory? c) top of physical? Is it the last 1KB or last 1MB or last 1GB to search? RAM? d) That is probably the most understood one I just scan 00000 to FFFFF (the 1st MB) The spec is written many years ago and full of errors, how do I find a newer one that applies? |
|||
16 Jan 2010, 10:15 |
|
cod3b453 16 Jan 2010, 11:21
The BIOS is responsible for the tables, so different implementation use different locations. The areas I scan are:
Code: 0x9FC00 - 0x9FFFF ; EBDA [using word at 0x040E for base segment] (a) 0xE0000 - 0xFFFFF ; ROM (b?)(d) This has been enough for QEMU and VirtualBox so far but you can get the memory map from BIOS (int 0x15, ax = 0xE820) to check (c) and the word at 0x040E to get the EBDA base segment. If they're not here you can still test for APIC using CPUID/MSRs and use the sequential method mentioned, booting one processor at a time. EDIT: The newest thing I can find is Intel #318148 x2APIC specification seems to suggest looking at ACPI tables instead... |
|||
16 Jan 2010, 11:21 |
|
sinsi 16 Jan 2010, 13:56
If you can't find the tables it's because there is a dual cpu setup (not a dual-core) so you use the defaults. Goes back to the 386/486/ppro.
Funnily enough in the linux mp init code they actually complain in the comments if they have to parse a table... Last edited by sinsi on 17 Jan 2010, 12:15; edited 1 time in total |
|||
16 Jan 2010, 13:56 |
|
XanClic 16 Jan 2010, 17:00
Madis731 wrote: b) Where is the end of base memory? The size of this memory in kilobytes can be read from the word on offset 0x13 in the BDA (physical address 0x413). So you need to read that word from 0x413, decrement it and multiply it by 1024 to get the physical address of the last kilobyte of conventional memory (where to look for the MP table). |
|||
16 Jan 2010, 17:00 |
|
egos 16 Jan 2010, 21:08
Madis731 wrote: a) What gives me the EBDA 1st KB? Quote: b) What does undefined mean and where is the end of base memory? Quote: c) top of physical? Is it the last 1KB or last 1MB or last 1GB to search? RAM? |
|||
16 Jan 2010, 21:08 |
|
XanClic 17 Jan 2010, 11:27
egos wrote:
For BDA: It's actually word cell 0:40Eh (physical address 0x40E). This word contains the real mode segment of the EBDA. egos wrote: The end of base memory is 640 kb mark (when the size of the available base memory is equal to 640 kb search for the structures under this mark). Don't rely on that. Read the appropriate word in the BDA (physical address 0x413, as said before) which tells you about the real size of the base memory. |
|||
17 Jan 2010, 11:27 |
|
egos 17 Jan 2010, 18:01
[0:40Eh] = [0:413h] shl 6, but [0:413h] is more documented.
Quote: Don't rely on that. |
|||
17 Jan 2010, 18:01 |
|
XanClic 17 Jan 2010, 18:49
So if you're sure about that, I revoke my opinion of course.
|
|||
17 Jan 2010, 18:49 |
|
smiddy 22 Jan 2010, 01:24
Hi Madis731,
This looks promising. I have some code I need to look for that can help you with the memory stuff. When I wrote it I made it compatible with 64-bit YMMV though since I never tested it. I did use INT 15h EAX=E820h and was identifying 64bit memory, if it was reported (it never got reported since my machines at the time were all 32-bit). Anyhow, I will post it here once I find it. I also plan on getting and using long mode. I will be redoing my OS too to work with 64bit machines. I haven't fully decided on a direction, but am leaning towards a diagnostics type OS. |
|||
22 Jan 2010, 01:24 |
|
Madis731 22 Jan 2010, 21:10
Diagnostics is a good type of OS for starters - its like a debugger in itself. Entire OS just made to read info and spell it all out
Thanks to all of you - I have gotten a lot of great feedback to improve this patch of code. Of course IPI is just a small fraction of it now that I've incorporated so many things in it. |
|||
22 Jan 2010, 21:10 |
|
smiddy 26 Jan 2010, 05:39
Here ya go Madis731. I haven't touched this in it looks like 4 years. It is a good basis on E820h to get the RAM values, with some tweaking it should get all the 64bits of memory information. There is some missing functions for printing and missing variables for saving, but it is fairly clear and should be able to walk through it quickly if you have a guide for INT 15h AX=E820h:
Code: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Call BIOS INT 15h AX=0E820h ;; ;; Display memory mapping if available ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; BIOSE820: mov [TotalMemoryInstalled],dword 0 ; Zero out variable mov si,TheBIOSE820Message ; Load entry message call Message ; Display message push ds pop es mov di,E820Buffer ; Load buffer into DI xor ebx,ebx ; INT 0x15 AX=0xE820 continuation value mov edx,0534D4150h ; "SMAP" mov ecx,E820BufferLength mov eax,0E820h int 15h ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; CF on first call to INT 0x15 AX=0xE820 is an error ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; jc NEAR NotSupported mov [TheEAX],eax ; Save EAX contents mov [TheEBX],ebx ; Save EBX contents mov si,TheBIOSE820Message1 call Message mov si,TheEndOfLine call Message mov eax,[TheEAX] ; Restore EAX before calling Message mov ebx,[TheEBX] ; Restore EBX before calling Message BIOSE820_1: cmp eax,0x534D4150 ; "SMAP" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; return EAX other than "SMAP" is an error ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; stc jne NEAR BIOSE820_4 mov [TheEBX],ebx ; Save EBX mov si,TheBIOSE820Message2 call Message mov eax,[es:di + 4] ; BaseAddrHigh mov CL,20h call ToHex mov si,HexBuffer call Message mov eax,[es:di + 0] ; BaseAddrLow mov CL,20h call ToHex mov si,HexBuffer call Message mov si,TheDash call Message mov eax,[es:di + 12] ; LengthHigh mov CL,20h call ToHex mov si,HexBuffer call Message mov eax,[es:di + 8] ; LengthLow mov CL,20h call ToHex mov si,HexBuffer call Message mov si,TheHexAfter call Message mov si,TheDash call Message mov si,TheSpace call Message mov eax,dword [es:di + 16] ; Move memory type into EAX mov CL,8 ; Only show the last 8 bits call ToHex mov si,HexBuffer call Message mov si,TheBIOSE820MemoryType5 mov eax,dword [es:di + 16] cmp eax,1 jg .NotTheOS mov eax,[es:di + 8] ; Save low length for now (needs to include high later) add eax,[TotalMemoryInstalled] ; Add already saved amount in variable mov [TotalMemoryInstalled],eax ; Save variable mov si,TheBIOSE820MemoryType1 jmp .DoMessage .NotTheOS: cmp eax,2 jg .NotReserved mov si,TheBIOSE820MemoryType2 jmp .DoMessage .NotReserved: cmp eax,3 jg .NotReclaim mov si,TheBIOSE820MemoryType3 jmp .DoMessage .NotReclaim: cmp eax,4 jg .DoMessage mov si,TheBIOSE820MemoryType4 .DoMessage: call Message mov si,TheEndOfLine call Message BIOSE820_2: mov ebx,[TheEBX] ; Restore EBX or ebx,ebx je BIOSE820_3 mov edx,0534D4150h ; "SMAP" mov ecx,E820BufferLength mov eax,0E820h int 15h jnc NEAR BIOSE820_1 ; No CF then continue looking at map BIOSE820_3: clc BIOSE820_4: mov si,TotalMemoryMessage call Message mov eax,[TotalMemoryInstalled] mov cl,20h call ToHex mov edi,HexBuffer mov eax,16 call AddForwardSpaces mov si,HexBuffer call Message mov si,TheHexAfter call Message mov si,TheDash call Message mov eax,[TotalMemoryInstalled] call ToDecimal call AddCommas mov edi,CommaBuffer mov eax,14 ; String of 14, to compare call AddForwardSpaces mov si,CommaBuffer call Message mov si,JustTheBytes call Message mov si,TheEndOfLine call Message mov si,TotalMemoryMessage3 call Message RET |
|||
26 Jan 2010, 05:39 |
|
LocoDelAssembly 26 Jan 2010, 05:50
|
|||
26 Jan 2010, 05:50 |
|
smiddy 26 Jan 2010, 12:01
LocoDelAssembly wrote: http://board.flatassembler.net/topic.php?t=6217 Hey thanks! It has been a while eh? I knew I had posted something before... I found my code last night in an archive. My OS has sat stagnant for that long too. |
|||
26 Jan 2010, 12:01 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.