Przeglądaj źródła

Change memory layout

Johannes Zellner 1 miesiąc temu
rodzic
commit
54522a446d
13 zmienionych plików z 29 dodań i 29 usunięć
  1. 8 8
      AGENTS.md
  2. 5 5
      bootstrap.c
  3. 1 1
      disk.c
  4. 1 1
      kernel.ld
  5. 2 2
      kexec.c
  6. 1 1
      kexec_tramp.S
  7. 1 1
      process.h
  8. 3 3
      run.c
  9. 1 1
      run_api.h
  10. 2 2
      serial_recv.c
  11. 1 1
      uhci.c
  12. 2 2
      user.ld
  13. 1 1
      vesa_stage.S

+ 8 - 8
AGENTS.md

@@ -42,13 +42,13 @@ make clean
 | `0x800`   | kexec trampoline (relocated at runtime; below the kernel) |
 | `0x900`   | kexec flat GDT + GDTR (built at runtime; below the kernel) |
 | `0x3000`  | UHCI frame list (1024 × 4 B, 4 KB-aligned; `uhci.c`) |
-| `0x20000` | ISA DMA buffer (`disk.c`) + kernel upper bound (`kernel.ld` ASSERT) |
-| `0x20800` | Protected-mode stack top (`vesa_stage.S`) |
-| `0x20F00` | Program API struct (`PROGRAM_API_ADDR`, `run_api.h`) |
-| `0x21000` | User program load address (`run.c`, `user.ld`) |
-| `0x30000` | (free) |
-| `0x40000` | Process stack base (`PROC_STACK_BASE`, 4 KB × 8, `process.h`) |
-| `0x50000` | kexec staging buffer (received kernel image, up to 0x18200 B) |
+| `0x20000` | (free — kernel upper bound used to be here, now `0x30000`) |
+| `0x30000` | ISA DMA buffer (`disk.c`) + kernel upper bound (`kernel.ld` ASSERT) |
+| `0x30800` | Protected-mode stack top (`vesa_stage.S`) |
+| `0x30F00` | Program API struct (`PROGRAM_API_ADDR`, `run_api.h`) |
+| `0x31000` | User program load address (`run.c`, `user.ld`) |
+| `0x42000` | Process stack base (`PROC_STACK_BASE`, 4 KB × 8, `process.h`) |
+| `0x50000` | kexec staging buffer (received kernel image, up to 0x28200 B) |
 | `0x100000`| VGA shadow buffer (`VGA_SHADOW_BASE`, `vga.h`) |
 
 ## Key files
@@ -73,7 +73,7 @@ make clean
   `lsusb` command.
 - **Power/idle**: `idle.c` — `mwait` C-states, `hlt` fallback.
 - **User programs**: `run.c`, `run_api.h`, `prog.c`, `space.c` — raw binaries at
-  `0x21000`, API function-pointer struct at `0x20F00`. `space` = Space Invaders.
+  `0x31000`, API function-pointer struct at `0x30F00`. `space` = Space Invaders.
 
 ## Shell commands
 

+ 5 - 5
bootstrap.c

@@ -3,8 +3,8 @@
  * full hardware access: it switches COM1 to 115200, receives a new kernel image,
  * copies it over 0x7E00, and jumps to its kernel_main.
  *
- * Self-contained: no kernel symbols, no run_api dependency. We live at 0x21000
- * (outside the 0x7E00..0x20000 kernel region), so we can overwrite the kernel
+ * Self-contained: no kernel symbols, no run_api dependency. We live at 0x31000
+ * (outside the 0x7E00..0x30000 kernel region), so we can overwrite the kernel
  * directly from our own code without a relocated trampoline.
  *
  * Wire protocol (host -> us), after we emit 'R':
@@ -18,9 +18,9 @@
 #define UART_BASE        0x3F8
 #define STAGE_ADDR       0x50000
 #define KERNEL_LOAD_ADDR 0x7E00
-#define BOOT_STACK       0x20800
+#define BOOT_STACK       0x30800
 #define MAGIC            0x4345584B /* "KXEC" little-endian */
-#define MAX_SIZE         0x18200
+#define MAX_SIZE         0x28200
 
 static inline void outb(unsigned short port, unsigned char v)
 {
@@ -148,7 +148,7 @@ void _start(void)
 	}
 
 	/* Copy staged kernel over 0x7E00, then jump to its kernel_main.
-	 * We live at 0x21000, outside the overwritten region, so this is safe. */
+	 * We live at 0x31000, outside the overwritten region, so this is safe. */
 	setup_flat_gdt();
 	for (i = 0; i < size; i++)
 		((volatile unsigned char *)KERNEL_LOAD_ADDR)[i] =

+ 1 - 1
disk.c

@@ -7,7 +7,7 @@
 #define SECTOR_SIZE       512
 #define SECTORS_PER_TRACK 18
 #define HEADS             2
-#define DMA_BUF_ADDR      0x20000
+#define DMA_BUF_ADDR      0x30000
 
 /* FDC I/O ports */
 #define FDC_DOR   0x3F2

+ 1 - 1
kernel.ld

@@ -17,4 +17,4 @@ SECTIONS
 	}
 	_end = .;
 }
-ASSERT(_end <= 0x20000, "Kernel too large would overwrite stack/DMA at 0x20000");
+ASSERT(_end <= 0x30000, "Kernel too large would overwrite stack/DMA at 0x30000");

+ 2 - 2
kexec.c

@@ -5,7 +5,7 @@
  * LFB are still valid) and jump straight to the new kernel's kernel_main,
  * which re-inits IDT/PIC/PIT/mouse/process/VGA-shadow/terminal from scratch.
  *
- * Because this code lives at 0x7E00..0x20000 (inside the region we overwrite),
+ * Because this code lives at 0x7E00..0x30000 (inside the region we overwrite),
  * the final "copy image to 0x7E00 and jump" is done by a small
  * position-independent trampoline relocated to 0x800 (below the kernel).
  *
@@ -29,7 +29,7 @@
 #define KEXEC_STAGE 0x50000    /* staging buffer for the received image */
 #define KEXEC_LOAD  0x7E00     /* where the kernel must be placed */
 #define KEXEC_TRAMP 0x800      /* relocated trampoline (below the kernel) */
-#define KEXEC_MAX   0x18200    /* max = kernel region 0x7E00..0x20000 */
+#define KEXEC_MAX   0x28200    /* max = kernel region 0x7E00..0x30000 */
 
 volatile int kexec_busy;
 

+ 1 - 1
kexec_tramp.S

@@ -51,7 +51,7 @@ kexec_trampoline:
 	cld
 	rep   movsb
 
-	movl  $0x20800, %esp
+	movl  $0x30800, %esp
 	jmp   *%edx
 
 .globl kexec_trampoline_end

+ 1 - 1
process.h

@@ -4,7 +4,7 @@
 
 #define MAX_PROCS       8
 #define PROC_STACK_SIZE 0x1000  /* 4 KB per process */
-#define PROC_STACK_BASE 0x40000 /* process 1 stack bottom; process 0 uses bootstrap stack */
+#define PROC_STACK_BASE 0x42000 /* process 1 stack bottom; process 0 uses bootstrap stack */
 
 #define PROC_UNUSED  0
 #define PROC_READY   1

+ 3 - 3
run.c

@@ -1,4 +1,4 @@
-/* run command: load raw binary from FAT floppy to 0x21000 and execute. */
+/* run command: load raw binary from FAT floppy to 0x31000 and execute. */
 
 #include "fat.h"
 #include "fbtext.h"
@@ -8,7 +8,7 @@
 #include "timer.h"
 #include "vga.h"
 
-#define PROGRAM_LOAD_ADDR 0x21000
+#define PROGRAM_LOAD_ADDR 0x31000
 #define PROGRAM_LOAD_MAX  0x10000
 #define NAME_BUF_SIZE     12
 
@@ -85,7 +85,7 @@ void program_run_main(const char *filename)
 	((void (*)(void))PROGRAM_LOAD_ADDR)();
 }
 
-/* run serial: execute the binary already loaded at 0x21000 via serial_recv. */
+/* run serial: execute the binary already loaded at 0x31000 via serial_recv. */
 
 void program_run_serial_main(const char *arg)
 {

+ 1 - 1
run_api.h

@@ -3,7 +3,7 @@
 #ifndef RUN_API_H
 #define RUN_API_H
 
-#define PROGRAM_API_ADDR 0x20F00
+#define PROGRAM_API_ADDR 0x30F00
 #define IO_KEY_ESC       0x1B
 #define IO_KEY_SPACE     0x20
 #define IO_KEY_LEFT      0x100

+ 2 - 2
serial_recv.c

@@ -1,10 +1,10 @@
-/* Serial receive command: receives a binary via serial into 0x21000. */
+/* Serial receive command: receives a binary via serial into 0x31000. */
 
 #include "io.h"
 #include "serial.h"
 #include "bin_recv.h"
 
-#define PROGRAM_LOAD_ADDR 0x21000
+#define PROGRAM_LOAD_ADDR 0x31000
 #define PROGRAM_LOAD_MAX  0x10000
 
 unsigned int serial_recv_size;

+ 1 - 1
uhci.c

@@ -63,7 +63,7 @@ struct uhci_qh {
 #define UHCI_NUM_TD 16
 
 /* Frame list lives in low memory (below the kernel at 0x7E00) to avoid
-   bloating the kernel's BSS past the 0x20000 linker budget. It must be
+   bloating the kernel's BSS past the 0x30000 linker budget. It must be
    4 KB aligned; 0x3000 is free after boot (see AGENTS.md memory map). */
 #define UHCI_FRAME_LIST_ADDR 0x3000u
 

+ 2 - 2
user.ld

@@ -1,9 +1,9 @@
-/* User program: load at 0x21000, same as run.c PROGRAM_LOAD_ADDR. */
+/* User program: load at 0x31000, same as run.c PROGRAM_LOAD_ADDR. */
 ENTRY(_start)
 
 SECTIONS
 {
-	. = 0x21000;
+	. = 0x31000;
 	.text : { *(.text .text.*) }
 	.rodata : { *(.rodata .rodata.*) }
 	.data : { *(.data .data.*) }

+ 1 - 1
vesa_stage.S

@@ -188,7 +188,7 @@ stage2_pm:
 	movw  %ax, %fs
 	movw  %ax, %gs
 	movw  %ax, %ss
-	movl  $0x20800, %esp
+	movl  $0x30800, %esp
 	jmp   kernel_main
 
 .align 4