flat assembler
Message board for the users of flat assembler.

flat assembler > OS Construction > [CONTRIBUTION] Long mode multi-core test pre-OS

Author
Thread Post new topic Reply to topic
Madis731



Joined: 25 Sep 2003
Posts: 2146
Location: Estonia
Problems solved:
-pre-boot environment, multiple loading stages
-built-in FAT12 image-maker (from source to *.IMG in one click Smile )
-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.


Description: Test pre-OS capable of booting multiple cores/threads/CPUs
Download
Filename: IPI_test+src.7z
Filesize: 9.76 KB
Downloaded: 94 Time(s)


_________________
My updated idol Very Happy http://www.agner.org/optimize/
Post 14 Jan 2010, 19:53
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 620
Intel MP spec says the table is optional:
Quote:
If the MP configuration table exists, it provides the IDs of the application processor local APICs.
These IDs should be used as the destination addresses in targeted IPIs.
If the MP configuration table does not exist on an MP-compliant system, the system must be of
default configuration type. The MP specification requires local APIC IDs to be numbered
sequentially, starting at zero for all default configurations. As a result, the BSP can determine the
AP’s local APIC ID in default, two-processor configurations by reading its own local APIC ID.
Since there are only two possible local APIC IDs in this case, zero and one, when the APIC ID of
the BSP is one, the APIC ID of the AP is zero, and vice versa. This is important, because a BSP
cannot start up an AP unless it already knows the local APIC ID.

see Intel #24201606 "Intel Multiprocessor Specification" Appendix B.4

For memory locations:
Quote:
The following is a list of the suggested memory spaces for the MP configuration table:
a. In the first kilobyte of Extended BIOS Data Area (EBDA), or
b. Within the last kilobyte of system base memory if the EBDA segment is undefined, or
c. At the top of system physical memory, or
d. In the BIOS read-only memory space between 0E0000h and 0FFFFFh

see Intel #24201606 "Intel Multiprocessor Specification" Chapter 4
Post 15 Jan 2010, 21:11
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2146
Location: Estonia
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) Smile That is probably the most understood one

I just scan 00000 to FFFFF (the 1st MB) Razz The spec is written many years ago and full of errors, how do I find a newer one that applies? Smile
Post 16 Jan 2010, 10:15
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 620
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...
Post 16 Jan 2010, 11:21
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 685
Location: Adelaide
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
Post 16 Jan 2010, 13:56
View user's profile Send private message Reply with quote
XanClic



Joined: 06 Sep 2009
Posts: 16
Location: Germany
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).
Post 16 Jan 2010, 17:00
View user's profile Send private message Visit poster's website Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
Madis731 wrote:
a) What gives me the EBDA 1st KB?
int 15h/eax=0E820h (first block?), int 12h (ax) or BDA (word cell 0:413h).

Quote:
b) What does undefined mean and where is the end of base memory?
"undefined" means "not exist". 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).

Quote:
c) top of physical? Is it the last 1KB or last 1MB or last 1GB to search? RAM?
It is the top of the available extended memory (I think so).
Post 16 Jan 2010, 21:08
View user's profile Send private message Reply with quote
XanClic



Joined: 06 Sep 2009
Posts: 16
Location: Germany
egos wrote:
Madis731 wrote:
a) What gives me the EBDA 1st KB?

int 15h/eax=0E820h (first block?), int 12h (ax) or BDA (word cell 0:413h).

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.
Post 17 Jan 2010, 11:27
View user's profile Send private message Visit poster's website Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
[0:40Eh] = [0:413h] shl 6, but [0:413h] is more documented.

Quote:
Don't rely on that.
In general you right but in fact [0:413h] contains the size of the available base memory for OS, not the really installed onboard base memory. We can additionally check the value of this cell on equal to 512 kb, 768 kb, maybe 704 kb or 736 kb, or on multiple to 128 kb, maybe 64 kb or 32 kb. But I think there are no modern PCs without EBDA.
Post 17 Jan 2010, 18:01
View user's profile Send private message Reply with quote
XanClic



Joined: 06 Sep 2009
Posts: 16
Location: Germany
So if you're sure about that, I revoke my opinion of course. Wink
Post 17 Jan 2010, 18:49
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 562
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. Wink
Post 22 Jan 2010, 01:24
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2146
Location: Estonia
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 Smile

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.
Post 22 Jan 2010, 21:10
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 562
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    
Post 26 Jan 2010, 05:39
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4634
Location: Argentina
http://board.flatassembler.net/topic.php?t=6217

BTW, good to see you here again smiddy Very Happy
Post 26 Jan 2010, 05:50
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 562
LocoDelAssembly wrote:
http://board.flatassembler.net/topic.php?t=6217

BTW, good to see you here again smiddy Very Happy


Hey thanks! It has been a while eh? I knew I had posted something before...Smile

I found my code last night in an archive. My OS has sat stagnant for that long too.
Post 26 Jan 2010, 12:01
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.