Skip to content

Commit cc6eab4

Browse files
committed
More notes and minor restructuring for the upcoming works.
1 parent 5b82363 commit cc6eab4

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

redox-core/src/boot_rom.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl BootRom {
5555

5656
// Calculate the position of the start of the interrupt vector.
5757
let mut next_handler_pos =
58-
BOOT_MEMORY_START + BootRom::total_size_of_instructions(&boot_instructions);
58+
BOOT_MEMORY_START + Instruction::total_size_of_instructions(&boot_instructions);
5959

6060
// NOTE - in the instances where we are building a custom interrupt handler
6161
// we would need to use the intret instruction to mark the end of the handler subroutine.
@@ -107,7 +107,7 @@ impl BootRom {
107107
final_instructions.extend_from_slice(&instructions);
108108

109109
// Advance the next handler location.
110-
next_handler_pos += BootRom::total_size_of_instructions(&instructions);
110+
next_handler_pos += Instruction::total_size_of_instructions(&instructions);
111111
}
112112

113113
// Add the return instruction from our IVT initialization subroutine and add
@@ -130,13 +130,4 @@ impl BootRom {
130130
// Return the compiled bytecode.
131131
Compiler::new().compile(&final_instructions).to_vec()
132132
}
133-
134-
/// Compute the total size of an [`Instruction`] slice.
135-
fn total_size_of_instructions(instructions: &[Instruction]) -> usize {
136-
let mut size = 0;
137-
for ins in instructions {
138-
size += ins.get_total_instruction_size();
139-
}
140-
size
141-
}
142133
}

redox-core/src/compiling/compiler.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ impl Compiler {
7979
// TODO - this is because the instructions may have changed, altering the relative positions of the labels.
8080
}
8181

82-
// We now need to preemptively compile the core data. This is because we need to know the length
83-
// of the code segment.
84-
self.compile(&instructions);
85-
let code_segment_len = self.bytes.len();
82+
// We now need to calculate the length of the instructions.
83+
let code_segment_len = Instruction::total_size_of_instructions(&instructions);
84+
85+
// TODO - this is a placeholder for the moment.
86+
self.calculate_data_label_positions(code_segment_len);
8687

88+
// TODO - do we care enough to do this?
8789
if optimize {
8890
// TODO - a second optimization pass should go here to optimize any labels
8991
// TODO - related to the data section.
@@ -101,6 +103,14 @@ impl Compiler {
101103
&self.bytes
102104
}
103105

106+
/// Calculate the positions of the local data labels within the provided instruction list.
107+
///
108+
/// # Arguments
109+
///
110+
/// * `instructions` - A slice of [`Instruction`]s that correspond to the instructions to be compiled.
111+
#[inline]
112+
fn calculate_data_label_positions(&mut self, data_segment_len: usize) {}
113+
104114
/// Calculate the positions of the local labels within the provided instruction list.
105115
///
106116
/// # Arguments

redox-core/src/ins/instruction.rs

+9
Original file line numberDiff line numberDiff line change
@@ -622,4 +622,13 @@ impl Instruction {
622622
};
623623
instruction_size + self.get_instruction_arg_size()
624624
}
625+
626+
/// Compute the total size of an [`Instruction`] slice.
627+
pub fn total_size_of_instructions(instructions: &[Instruction]) -> usize {
628+
let mut size = 0;
629+
for ins in instructions {
630+
size += ins.get_total_instruction_size();
631+
}
632+
size
633+
}
625634
}

0 commit comments

Comments
 (0)