Browse files

One definition of several macros and constants

  • Loading branch information...
1 parent 11b7438 commit a56c8d609b24e4c1c3a8a5bacdced6ae53376ee2 Frans Kaashoek committed Aug 8, 2011
Showing with 25 additions and 33 deletions.
  1. +3 −5 bootasm.S
  2. +4 −10 bootother.S
  3. +3 −1 memlayout.h
  4. +11 −0 mmu.h
  5. +3 −7 multiboot.S
  6. +0 −7 proc.h
  7. +1 −3 trapasm.S
View
8 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
+
View
14 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
View
4 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
View
11 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
View
10 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
View
7 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
View
4 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

0 comments on commit a56c8d6

Please sign in to comment.