Skip to content

Commit

Permalink
One definition of several macros and constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Frans Kaashoek committed Aug 8, 2011
1 parent 11b7438 commit a56c8d6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 33 deletions.
8 changes: 3 additions & 5 deletions bootasm.S
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -88,3 +85,4 @@ gdt:
gdtdesc:
.word (gdtdesc - gdt - 1) # sizeof(gdt) - 1
.long gdt # address gdt

14 changes: 4 additions & 10 deletions bootother.S
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion memlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
11 changes: 11 additions & 0 deletions mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -208,3 +218,4 @@ struct gatedesc {
(gate).off_31_16 = (uint)(off) >> 16; \
}

#endif
10 changes: 3 additions & 7 deletions multiboot.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
7 changes: 0 additions & 7 deletions proc.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions trapasm.S
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit a56c8d6

Please sign in to comment.