Skip to content

Commit 1c9b140

Browse files
Fixed an user mode argv/argc bug
Fixed blocking I/O wait in ide_dma.cpp And pbly a lot of other things
1 parent 9c29fb2 commit 1c9b140

File tree

23 files changed

+205
-149
lines changed

23 files changed

+205
-149
lines changed

initrd/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
data
22
2222
33
éé
4+
bonjour ceci est un gros filler

kern/cpu/stack.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
stack.hpp
3+
4+
Copyright (c) 06 Yann BOUCHER (yann)
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
24+
*/
25+
#ifndef STACK_HPP
26+
#define STACK_HPP
27+
28+
// returns previous stack pointer value
29+
extern "C" void* switch_stacks(void* new_stack);
30+
31+
#endif // STACK_HPP

kern/drivers/storage/disk.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ kpp::expected<kpp::dummy_t, DiskError> Disk::enable_caching(bool val)
179179
if (!val && m_caching)
180180
{
181181
auto result = flush_cache();
182-
if (!result) return result;
182+
warn("Error flushing cache on disk '%s' : %s\n", drive_name().c_str(), result.error().to_string());
183+
return {};
183184
}
184185

185186
// TODO : investigate why enabling caching destroys performance !

kern/drivers/storage/ide/ide_dma.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,32 @@ void Controller::init()
116116
ide::dma::Disk::create_disk(*this, (BusPort)pair.first, (DriveType)pair.second);
117117
log(Debug, "Created ATA DMA disk on 0x%x 0x%x\n", io_base((BusPort)pair.first), pair.second);
118118
}
119+
120+
memset((void*)raised_ints, 0, sizeof(raised_ints));
119121
}
120122

121123
bool Controller::common_handler(const ata_device& dev)
122124
{
123125
auto status = status_byte(dev.port);
124126

125-
//log(Debug, "Received PCI ATA IRQ on port 0x%x, status 0x%x\n", dev.port, status);
127+
if (status & (1<<0))
128+
{
129+
log_serial("Received PCI ATA IRQ on port 0x%x, status 0x%x\n", dev.port, status);
130+
}
126131

127132
if (status & (1<<2))
128133
{
129134
bool slave = drive_register(dev) & (1<<4);
130135

131-
if ((status & (1<<0)) == 0) // last PRDT used up
136+
if ((status & (1<<0)) == 0 || true) // TODO : investigate why sometimes it hangs when there are PRD pending
132137
{
133138
auto* process = waiting_processes[dev.port==BusPort::Primary][slave];
134-
// assert(process);
135-
// assert(process->is_blocked());
136139
raised_ints[dev.port==BusPort::Primary][slave] = true;
137-
if (process) process->unblock();
140+
141+
if (process)
142+
{
143+
process->status = Process::Active;
144+
}
138145

139146
send_command_byte(dev.port, 0); // clear start/stop bit
140147

@@ -148,8 +155,8 @@ bool Controller::common_handler(const ata_device& dev)
148155
{
149156
drive_status[dev.port==BusPort::Primary][slave] = status_ok;
150157
}
151-
}
152158

159+
}
153160
bit_clear(status, 0); bit_clear(status, 1); // clear error and interrupt bits
154161
send_status_byte(dev.port, status);
155162
}
@@ -323,19 +330,21 @@ kpp::expected<kpp::dummy_t, DiskError> Disk::do_read_write(size_t sector, gsl::s
323330

324331
(void)ide::status_register(m_dev); // read status port to reset drive
325332

333+
Process::current().status = Process::IOWait;
326334
m_cont.send_command(m_dev, ata_read_dma_ex, action == RWAction::Read,
327335
sector, count, data);
328336

329-
// if (!int_status)
330-
// {
331-
// Process::current().block();
332-
// tasking::kernel_yield();
333-
// }
334-
335-
if (!Timer::sleep_until([&int_status]{return int_status;}))
336-
{
337-
return kpp::make_unexpected(DiskError{DiskError::TimeOut});
338-
}
337+
#if 1
338+
if (!int_status)
339+
{
340+
tasking::kernel_yield();
341+
}
342+
#else
343+
if (!Timer::sleep_until([&int_status]{return int_status;}, 1000))
344+
{
345+
return kpp::make_unexpected(DiskError{DiskError::TimeOut});
346+
}
347+
#endif
339348

340349
int_status = false;
341350

kern/fs/procfs/procfs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct procfs_root : public vfs::node
9090
children.emplace_back(std::make_shared<string_node>("cmdline", kernel_cmdline));
9191
children.emplace_back(std::make_shared<string_node>("uptime", []{ return kpp::to_string(Time::uptime()); }));
9292
children.emplace_back(std::make_shared<string_node>("version", get_version_str()));
93-
if (Process::enabled()) children.emplace_back(std::make_shared<vfs::symlink>(kpp::to_string(Process::current().pid), "self"));
93+
children.emplace_back(std::make_shared<vfs::symlink>(kpp::to_string(Process::current().pid), "self"));
9494

9595
children.emplace_back(std::make_shared<interface_test>("interface_test"));
9696

kern/global_init.cpp

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ SOFTWARE.
106106
// : faire une boucle de traitement de callbacks d'interruption
107107
// : implémenter /dev/input
108108
// : implémenter expanding stack
109+
// : fix caching
110+
// : PRIORITAIRE : pour les read disk, ne pas retourner une structure allouée mais prendre un ptr en argument
109111

110112
/**********************************/
111113
// BUGS
@@ -126,34 +128,8 @@ SOFTWARE.
126128
// * don't forget about fpu state
127129
/**********************************/
128130

129-
void test1()
130-
{
131-
int esp;
132-
uint8_t val = 0;
133-
while (true)
134-
{
135-
asm volatile ("movl %%esp, %0":"=m"(esp):);
136-
kprintf("Hi ! %d (esp : 0x%x)\n", val, esp);
137-
++val;
138-
tasking::kernel_yield();
139-
}
140-
}
141-
void test2()
142-
{
143-
int esp;
144-
uint8_t val = 0;
145-
while (true)
146-
{
147-
asm volatile ("movl %%esp, %0":"=m"(esp):);
148-
kprintf("Hello 2! %d (esp : 0x%x)\n", val, esp);
149-
++val;
150-
tasking::kernel_yield();
151-
}
152-
}
153-
154131
void global_init()
155132
{
156-
157133
beep(200);
158134

159135
power::init_power_management();
@@ -252,10 +228,6 @@ void global_init()
252228
MemBuffer buf(512*16);
253229
MemoryDisk::create_disk(buf.data(), buf.size(), "scratch");
254230

255-
// auto task1 = Process::create_kernel_task(test1);
256-
// auto task2 = Process::create_kernel_task(test2);
257-
// task1->switch_to();
258-
259231
Shell sh;
260232
sh.params.prompt = ESC_BG(13,132,203) " LudOS " ESC_POP_COLOR ESC_BG(78,154,6) ESC_FG(13,132,203) "" ESC_POP_COLOR " :{path}> " ESC_POP_COLOR
261233
ESC_FG(78,154,6) "" ESC_POP_COLOR " ";
@@ -266,9 +238,6 @@ void global_init()
266238
install_net_commands(sh);
267239
install_task_commands(sh);
268240

269-
sh.command("run /initrd/init.sh");
270-
sh.run();
271-
272241
#if 0
273242
Timer::register_callback(100, []
274243
{
@@ -286,4 +255,7 @@ void global_init()
286255
}
287256
}, false);
288257
#endif
258+
259+
sh.command("run /initrd/init.sh");
260+
sh.run();
289261
}

kern/i686/cpu/stack.asm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
global switch_stacks
2+
switch_stacks:
3+
lea eax, [esp+0x8] ; load former esp value (minus the return address and the parameter) to eax
4+
mov ecx, [esp] ; put the return address in ecx
5+
6+
mov esp, [esp+0x4] ; load the new esp value
7+
8+
jmp [ecx] ; jump to the return address

kern/i686/pc/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ void init(uint32_t magic, const multiboot_info_t* mbd_info)
309309
{
310310
while (true)
311311
{
312-
wait_for_interrupts();
313312
tasking::schedule();
313+
wait_for_interrupts();
314314
}
315315
});
316316
(void)idle_task;

kern/i686/tasking/process.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ void Process::wake_up(pid_t child, int err_code)
7979

8080
data->waiting_pid.reset();
8181

82+
status = Active;
83+
8284
arch_context->regs.eax = child; // set waitpid return value
8385
}
8486

@@ -113,8 +115,7 @@ void Process::execute_sighandler(int signal, pid_t returning_pid, const siginfo_
113115
push_onto_stack(info);
114116

115117
set_instruction_pointer(signal_trampoline_page);
116-
if (m_current_process)
117-
Process::current().unswitch();
118+
Process::current().unswitch();
118119
switch_to();
119120
}
120121

@@ -236,14 +237,13 @@ void Process::set_instruction_pointer(unsigned int value)
236237
void Process::switch_to()
237238
{
238239
{
240+
//assert(status == Active); TODO : check if in sighandler too
239241
if (m_current_process &&
240242
(m_current_process->arch_context->regs.cs & 0x3) == 0) // if previous task was in ring 0
241243
{
242244
m_current_process->data->kernel_stack_ptr = m_current_process->arch_context->regs.esp;
243245
}
244246

245-
assert(!is_waiting());
246-
247247
map_address_space();
248248
map_shm();
249249

@@ -309,7 +309,7 @@ Process *Process::clone(Process &proc, uint32_t flags)
309309

310310
void Process::unmap_address_space()
311311
{
312-
#if 1
312+
#if 0
313313
Paging::unmap_user_space(); // reloading all the page tables is really costly, not the right solution
314314
#else
315315
for (const auto& pair : data->mappings)

kern/shell/commands/fs/fscommands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ void install_fs_commands(Shell &sh)
183183
{
184184
for (Disk& disk : Disk::disks())
185185
{
186-
kprintf("%s : %s (%s)\n", disk.drive_name().c_str(), human_readable_size(disk.disk_size()).c_str(),
187-
disk.read_only() ? "ro" : "rw");
186+
kprintf("%s : %s (%s) (%s)\n", disk.drive_name().c_str(), human_readable_size(disk.disk_size()).c_str(),
187+
disk.read_only() ? "ro" : "rw", disk.caching_enabled() ? "cached" : "uncached");
188188
}
189189
return 0;
190190
}});

0 commit comments

Comments
 (0)