BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / blob / master / kernel / acpi / trampoline.S

// Related

Nucleus

Barry Kernel threads + threads share address space 6217f0d (3 years, 1 month ago)
/*
 * This file contains the AP trampoline code to bounce it back into protected
 * mode and run the kernel on them.  The location of the stack is set by the
 * calling code.  This code runs initially in real mode, at 0x1000 in physical
 * memory.
 */

.extern ap_startup
.type ap_startup, @function

.global ap_trampoline
.type ap_trampoline, @function
.align 4
ap_trampoline:
.code16
	cli
	jmp $0x100, $(1f - ap_trampoline)
1:
	mov %cs, %ax
	mov %ax, %ds

	xor %ax, %ax
	mov %ax, %sp

	/* Load the GDT */
	lgdt (apGdtDesc - ap_trampoline)

	/* Enable PM */
	movl %cr0, %eax
	orl $1, %eax
	movl %eax, %cr0

	ljmpl $8, $(ap_pm - ap_trampoline + 0x1000)

ap_pm:
.code32
	mov $0x10, %ax
	mov %ax, %ss
	mov %ax, %ds
	mov %ax, %es
	mov %ax, %fs
	mov %ax, %gs

	movl $0x1000, %ebp
	movl %ebp, %esp

	movl apId, %eax
	incl %eax
	movl %eax, apId

	movl 0x1FFC, %esi
	movl (%esi,%eax,4), %esp
	movl %esp, %ebp

	sti
	jmp $8, $(ap_startup)

	cli
1:
	hlt
	jmp 1b

.align 4
apGdtStart:
	/* Null */
	.4byte 0x00000000
	.4byte 0x00000000
	/* Code */
	.4byte 0x0000FFFF
	.4byte 0x00CF9A00
	/* Data */
	.4byte 0x0000FFFF
	.4byte 0x00CF9200
apGdtDesc:
	.2byte apGdtDesc - apGdtStart - 1
	.4byte (apGdtStart - ap_trampoline) + 0x1000
apId:
	.4byte 0