From a56c8d609b24e4c1c3a8a5bacdced6ae53376ee2 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Mon, 8 Aug 2011 13:30:08 -0400 Subject: [PATCH] One definition of several macros and constants --- bootasm.S | 8 +++----- bootother.S | 14 ++++---------- memlayout.h | 4 +++- mmu.h | 11 +++++++++++ multiboot.S | 10 +++------- proc.h | 7 ------- trapasm.S | 4 +--- 7 files changed, 25 insertions(+), 33 deletions(-) diff --git a/bootasm.S b/bootasm.S index 3cc23e7..c75434b 100644 --- a/bootasm.S +++ b/bootasm.S @@ -1,15 +1,12 @@ #include "asm.h" +#include "memlayout.h" +#include "mmu.h" # Start the first CPU: switch to 32-bit protected mode, jump into C. # The BIOS loads this code from the first sector of the hard disk into # memory at physical address 0x7c00 and starts executing in real mode # with %cs=0 %ip=7c00. -#define SEG_KCODE 1 // kernel code -#define SEG_KDATA 2 // kernel data+stack - -#define CR0_PE 1 // protected mode enable bit - .code16 # Assemble for 16-bit mode .globl start start: @@ -88,3 +85,4 @@ gdt: gdtdesc: .word (gdtdesc - gdt - 1) # sizeof(gdt) - 1 .long gdt # address gdt + diff --git a/bootother.S b/bootother.S index 2c97207..7b0b815 100644 --- a/bootother.S +++ b/bootother.S @@ -1,6 +1,7 @@ #include "asm.h" #include "memlayout.h" - +#include "mmu.h" + # Each non-boot CPU ("AP") is started up in response to a STARTUP # IPI from the boot CPU. Section B.4.2 of the Multi-Processor # Specification says that the AP will start in real mode with CS:IP @@ -20,13 +21,6 @@ # - it uses the address at start-4 for the %esp # - it jumps to the address at start-8 instead of calling bootmain -#define SEG_KCODE 1 -#define SEG_KDATA 2 - -#define CR0_PE 1 - -#define RELOC1(x) ((x) + KERNBASE) // same as V2P, but without casts - .code16 .globl start start: @@ -56,10 +50,10 @@ start32: movw %ax, %gs # switch to the stack allocated by bootothers() - movl RELOC1(start-4), %esp + movl P2V_WO(start-4), %esp # call mpmain() - call *(RELOC1(start)-8) + call *(P2V_WO(start)-8) movw $0x8a00, %ax movw %ax, %dx diff --git a/memlayout.h b/memlayout.h index 3958062..6c44db2 100644 --- a/memlayout.h +++ b/memlayout.h @@ -9,7 +9,7 @@ #define IOSPACEE 0x100000 // end IO space #define PHYSTOP 0xE000000 // use phys mem up to here as free pool -// Key addresses for address space layout (see kmap in vm.c for the actual layout) +// Key addresses for address space layout (see kmap in vm.c for the layout) #define KERNBASE 0xF0000000 // First kernel virtual address #define USERTOP (KERNBASE-PGSIZE) // Highest user virtual address #define KERNLINK 0xF0100000 // Address where kernel is linked @@ -24,3 +24,5 @@ static inline void *p2v(uint a) { return (void *) a + KERNBASE; } #define V2P(a) ((uint) a - KERNBASE) #define P2V(a) ((void *) a + KERNBASE) +#define V2P_WO(x) ((x) - KERNBASE) // same as V2P, but without casts +#define P2V_WO(x) ((x) + KERNBASE) // same as V2P, but without casts diff --git a/mmu.h b/mmu.h index 86879d2..3e46f41 100644 --- a/mmu.h +++ b/mmu.h @@ -37,7 +37,15 @@ #define CR0_CD 0x40000000 // Cache Disable #define CR0_PG 0x80000000 // Paging +#define SEG_KCODE 1 // kernel code +#define SEG_KDATA 2 // kernel data+stack +#define SEG_KCPU 3 // kernel per-cpu data +#define SEG_UCODE 4 // user code +#define SEG_UDATA 5 // user data+stack +#define SEG_TSS 6 // this process's task state + //PAGEBREAK! +#ifndef __ASSEMBLER__ // Segment Descriptor struct segdesc { uint lim_15_0 : 16; // Low bits of segment limit @@ -64,6 +72,7 @@ struct segdesc { { (lim) & 0xffff, (uint)(base) & 0xffff, \ ((uint)(base) >> 16) & 0xff, type, 1, dpl, 1, \ (uint)(lim) >> 16, 0, 0, 1, 0, (uint)(base) >> 24 } +#endif #define DPL_USER 0x3 // User DPL @@ -130,6 +139,7 @@ struct segdesc { // Address in page table or page directory entry #define PTE_ADDR(pte) ((uint)(pte) & ~0xFFF) +#ifndef __ASSEMBLER__ typedef uint pte_t; // Task state segment format @@ -208,3 +218,4 @@ struct gatedesc { (gate).off_31_16 = (uint)(off) >> 16; \ } +#endif diff --git a/multiboot.S b/multiboot.S index 84ab638..4aa9f20 100644 --- a/multiboot.S +++ b/multiboot.S @@ -16,14 +16,10 @@ #include "asm.h" #include "memlayout.h" - -#define RELOC(x) ((x) - KERNBASE) // same as V2P, but without casts +#include "mmu.h" #define STACK 4096 -#define SEG_KCODE 1 // kernel code -#define SEG_KDATA 2 // kernel data+stack - # Multiboot header. Data to direct multiboot loader. .p2align 2 .text @@ -45,7 +41,7 @@ multiboot_header: # boot loader - bootasm.S - sets up. .globl multiboot_entry multiboot_entry: - lgdt RELOC(gdtdesc) + lgdt V2P_WO(gdtdesc) ljmp $(SEG_KCODE<<3), $mbstart32 mbstart32: @@ -73,6 +69,6 @@ gdt: gdtdesc: .word (gdtdesc - gdt - 1) # sizeof(gdt) - 1 - .long RELOC(gdt) # address gdt + .long V2P_WO(gdt) # address gdt .comm stack, STACK diff --git a/proc.h b/proc.h index 7ffaffb..2b30187 100644 --- a/proc.h +++ b/proc.h @@ -1,11 +1,4 @@ // Segments in proc->gdt. -// Also known to bootasm.S and trapasm.S -#define SEG_KCODE 1 // kernel code -#define SEG_KDATA 2 // kernel data+stack -#define SEG_KCPU 3 // kernel per-cpu data -#define SEG_UCODE 4 // user code -#define SEG_UDATA 5 // user data+stack -#define SEG_TSS 6 // this process's task state #define NSEGS 7 // Per-CPU state diff --git a/trapasm.S b/trapasm.S index 1cb2ce6..787727f 100644 --- a/trapasm.S +++ b/trapasm.S @@ -1,6 +1,4 @@ -#define SEG_KCODE 1 // kernel code -#define SEG_KDATA 2 // kernel data+stack -#define SEG_KCPU 3 // kernel per-cpu data +#include "mmu.h" # vectors.S sends all traps here. .globl alltraps