-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial SMP support. Intializes AP and it halts in realmode. Fixed ou…
…tputting last character in a line. Aligned user mode stack in 8 bytes boundary. Fixed protected mode address loading in boot loader.
- Loading branch information
Showing
11 changed files
with
161 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/*****************************************************************************/ | ||
/* File: mp_init.S */ | ||
/* */ | ||
/* Description: Startup code for AP. */ | ||
/* */ | ||
/* Author: Shoily O Rahman <[email protected]> */ | ||
/* */ | ||
/* Date: Aug 9, 2020 */ | ||
/* */ | ||
/*****************************************************************************/ | ||
|
||
.equ AP_COUNT_PHYS_ADDR, 0xfff8 | ||
.code16 | ||
|
||
.globl init_ap | ||
|
||
.section "mp_init", "ax" | ||
|
||
init_ap: | ||
|
||
cli | ||
xorw %ax, %ax | ||
movw %ax, %ss | ||
movw %ax, %ds | ||
movw %ax, %es | ||
movw %ax, %fs | ||
movw %ax, %gs | ||
|
||
incw AP_COUNT_PHYS_ADDR | ||
|
||
hlt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/*****************************************************************************/ | ||
/* File: smp.c */ | ||
/* */ | ||
/* Description: Source file SMP related code. */ | ||
/* */ | ||
/* Author: Shoily O Rahman <[email protected]> */ | ||
/* */ | ||
/* Date: Aug 9, 2020 */ | ||
/* */ | ||
/*****************************************************************************/ | ||
|
||
#include "util.h" | ||
#include "system.h" | ||
#include "apic.h" | ||
|
||
#define AP_INIT_PHYS_TEXT 0xf000 | ||
#define AP_COUNT_PHYS_ADDR 0xfff8 | ||
|
||
extern int mp_init_size; | ||
extern int init_ap; | ||
|
||
void copy_smp_init_to_low_mem() { | ||
|
||
char *s = (char*)&init_ap; | ||
char *d = (char*)(AP_INIT_PHYS_TEXT+KERNEL_VIRT_ADDR); | ||
|
||
for(int i=0;i<(int)&mp_init_size;i++) { | ||
*d++ = *s++; | ||
} | ||
} | ||
|
||
void smp_start() { | ||
|
||
int status; | ||
|
||
copy_smp_init_to_low_mem(); | ||
|
||
// initialize AP processor count with 0 | ||
// it will be increased by AP startup code | ||
*(int*)(AP_COUNT_PHYS_ADDR+KERNEL_VIRT_ADDR) = 0; | ||
|
||
MFENCE; | ||
|
||
// send INIT IPI to APs | ||
write_lapic_register(LAPIC_ICR_1, 0x000c4500); | ||
write_lapic_register(LAPIC_ICR_2, 0); | ||
for(int i=0;i<10;i++) { | ||
status = read_lapic_register(LAPIC_ICR_1) & 0x1000; | ||
if (!status) | ||
break; | ||
pit_wait(0xffff); | ||
} | ||
|
||
// send Startup IPI to APs | ||
write_lapic_register(LAPIC_ICR_1, 0x000c4600 | (AP_INIT_PHYS_TEXT >> 12)); | ||
write_lapic_register(LAPIC_ICR_2, 0); | ||
for(int i=0;i<30;i++) { | ||
status = read_lapic_register(LAPIC_ICR_1) & 0x1000; | ||
if (!status) | ||
break; | ||
pit_wait(0xffff); | ||
} | ||
|
||
pit_wait(0xffff); | ||
|
||
print_msg("Number of APs", *(int*)(AP_COUNT_PHYS_ADDR+KERNEL_VIRT_ADDR), 10, true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/*****************************************************************************/ | ||
/* File: smp.h */ | ||
/* */ | ||
/* Description: Header file SMP related code. */ | ||
/* */ | ||
/* Author: Shoily O Rahman <[email protected]> */ | ||
/* */ | ||
/* Date: Aug 9, 2020 */ | ||
/* */ | ||
/*****************************************************************************/ | ||
|
||
#ifndef SMP_H | ||
#define SMP_H | ||
|
||
void smp_start(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters