mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
Make bash-2.05b build with minimal changes.
This is really neat. :^)
This commit is contained in:
parent
2cf477a151
commit
9d05f6b7a7
Notes:
sideshowbarker
2024-07-19 16:10:03 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9d05f6b7a79
35 changed files with 326 additions and 176 deletions
11
Base/etc/motd
Normal file
11
Base/etc/motd
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
[39;1m ____ _ __
|
||||
/ __/__ _______ ___ (_) /___ __
|
||||
[39;1m _\ \/ -_) __/ -_) _ \/ / __/ // /
|
||||
[34;1m/___/\__/_/ \__/_//_/_/\__/\_, /
|
||||
/___/
|
||||
[0m
|
||||
Welcome to Serenity OS.
|
||||
|
||||
Copyright (C) Andreas Kling, 2018
|
||||
All rights reserved.
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
namespace CMOS {
|
||||
|
||||
BYTE read(BYTE index)
|
||||
byte read(byte index)
|
||||
{
|
||||
IO::out8(0x70, index);
|
||||
return IO::in8(0x71);
|
||||
}
|
||||
|
||||
void write(BYTE index, BYTE data)
|
||||
void write(byte index, byte data)
|
||||
{
|
||||
IO::out8(0x70, index);
|
||||
IO::out8(0x71, data);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace CMOS {
|
||||
|
||||
BYTE read(BYTE index);
|
||||
void write(BYTE index, BYTE data);
|
||||
byte read(byte index);
|
||||
void write(byte index, byte data);
|
||||
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ void Keyboard::emit(byte ch)
|
|||
void Keyboard::handleIRQ()
|
||||
{
|
||||
while (IO::in8(0x64) & 1) {
|
||||
BYTE ch = IO::in8(0x60);
|
||||
byte ch = IO::in8(0x60);
|
||||
switch (ch) {
|
||||
case 0x38: m_modifiers |= Mod_Alt; break;
|
||||
case 0xB8: m_modifiers &= ~Mod_Alt; break;
|
||||
|
|
|
@ -19,9 +19,9 @@ static bool initialized;
|
|||
|
||||
namespace PIC {
|
||||
|
||||
void disable(BYTE irq)
|
||||
void disable(byte irq)
|
||||
{
|
||||
BYTE imr;
|
||||
byte imr;
|
||||
if (irq & 8) {
|
||||
imr = IO::in8(PIC1_CMD);
|
||||
imr |= 1 << (irq - 8);
|
||||
|
@ -33,9 +33,9 @@ void disable(BYTE irq)
|
|||
}
|
||||
}
|
||||
|
||||
void enable(BYTE irq)
|
||||
void enable(byte irq)
|
||||
{
|
||||
BYTE imr;
|
||||
byte imr;
|
||||
if (irq & 8) {
|
||||
imr = IO::in8(PIC1_CMD);
|
||||
imr &= ~(1 << (irq - 8));
|
||||
|
@ -47,7 +47,7 @@ void enable(BYTE irq)
|
|||
}
|
||||
}
|
||||
|
||||
void eoi(BYTE irq)
|
||||
void eoi(byte irq)
|
||||
{
|
||||
if (irq & 8)
|
||||
IO::out8(PIC1_CTL, 0x20);
|
||||
|
|
10
Kernel/PIC.h
10
Kernel/PIC.h
|
@ -4,9 +4,9 @@
|
|||
|
||||
namespace PIC {
|
||||
|
||||
void enable(BYTE number);
|
||||
void disable(BYTE number);
|
||||
void eoi(BYTE number);
|
||||
void enable(byte number);
|
||||
void disable(byte number);
|
||||
void eoi(byte number);
|
||||
void initialize();
|
||||
word getISR();
|
||||
word get_irr();
|
||||
|
@ -15,9 +15,9 @@ word get_irr();
|
|||
|
||||
class IRQHandlerScope {
|
||||
public:
|
||||
explicit IRQHandlerScope(BYTE irq) : m_irq(irq) { }
|
||||
explicit IRQHandlerScope(byte irq) : m_irq(irq) { }
|
||||
~IRQHandlerScope() { PIC::eoi(m_irq); }
|
||||
|
||||
private:
|
||||
BYTE m_irq { 0 };
|
||||
byte m_irq { 0 };
|
||||
};
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#define SIGNAL_DEBUG
|
||||
#define MAX_PROCESS_GIDS 32
|
||||
|
||||
static const DWORD defaultStackSize = 16384;
|
||||
static const dword defaultStackSize = 16384;
|
||||
|
||||
static pid_t next_pid;
|
||||
InlineLinkedList<Process>* g_processes;
|
||||
|
@ -663,7 +663,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
|
|||
if (isRing3()) {
|
||||
// Ring3 processes need a separate stack for Ring0.
|
||||
m_kernelStack = kmalloc(defaultStackSize);
|
||||
m_stackTop0 = ((DWORD)m_kernelStack + defaultStackSize) & 0xffffff8;
|
||||
m_stackTop0 = ((dword)m_kernelStack + defaultStackSize) & 0xffffff8;
|
||||
m_tss.ss0 = 0x10;
|
||||
m_tss.esp0 = m_stackTop0;
|
||||
}
|
||||
|
@ -1414,7 +1414,7 @@ void Process::reap(Process& process)
|
|||
|
||||
pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options)
|
||||
{
|
||||
//kprintf("sys$waitpid(%d, %p, %d)\n", waitee, wstatus, options);
|
||||
dbgprintf("sys$waitpid(%d, %p, %d)\n", waitee, wstatus, options);
|
||||
// FIXME: Respect options
|
||||
(void) options;
|
||||
if (wstatus)
|
||||
|
@ -1426,6 +1426,31 @@ pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options)
|
|||
if (waitee != -1 && !Process::from_pid(waitee))
|
||||
return -ECHILD;
|
||||
}
|
||||
|
||||
if (options & WNOHANG) {
|
||||
if (waitee == -1) {
|
||||
pid_t reaped_pid = 0;
|
||||
InterruptDisabler disabler;
|
||||
for_each_child([&reaped_pid] (Process& process) {
|
||||
if (process.state() == Dead) {
|
||||
reaped_pid = process.pid();
|
||||
reap(process);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return reaped_pid;
|
||||
} else {
|
||||
auto* waitee_process = Process::from_pid(waitee);
|
||||
if (!waitee_process)
|
||||
return -ECHILD;
|
||||
if (waitee_process->state() == Dead) {
|
||||
reap(*waitee_process);
|
||||
return waitee;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
m_waitee = waitee;
|
||||
m_waitee_status = 0;
|
||||
block(BlockedWait);
|
||||
|
@ -1470,7 +1495,7 @@ void block(Process::State state)
|
|||
sched_yield();
|
||||
}
|
||||
|
||||
void sleep(DWORD ticks)
|
||||
void sleep(dword ticks)
|
||||
{
|
||||
ASSERT(current->state() == Process::Running);
|
||||
current->setWakeupTime(system.uptime + ticks);
|
||||
|
|
|
@ -80,8 +80,8 @@ public:
|
|||
pid_t pid() const { return m_pid; }
|
||||
pid_t sid() const { return m_sid; }
|
||||
pid_t pgid() const { return m_pgid; }
|
||||
DWORD ticks() const { return m_ticks; }
|
||||
WORD selector() const { return m_farPtr.selector; }
|
||||
dword ticks() const { return m_ticks; }
|
||||
word selector() const { return m_farPtr.selector; }
|
||||
TSS32& tss() { return m_tss; }
|
||||
State state() const { return m_state; }
|
||||
uid_t uid() const { return m_uid; }
|
||||
|
@ -98,8 +98,8 @@ public:
|
|||
void block(Process::State);
|
||||
void unblock();
|
||||
|
||||
void setWakeupTime(DWORD t) { m_wakeupTime = t; }
|
||||
DWORD wakeupTime() const { return m_wakeupTime; }
|
||||
void setWakeupTime(dword t) { m_wakeupTime = t; }
|
||||
dword wakeupTime() const { return m_wakeupTime; }
|
||||
|
||||
template<typename Callback> static void for_each(Callback);
|
||||
template<typename Callback> static void for_each_in_pgrp(pid_t, Callback);
|
||||
|
@ -110,7 +110,7 @@ public:
|
|||
bool tick() { ++m_ticks; return --m_ticksLeft; }
|
||||
void set_ticks_left(dword t) { m_ticksLeft = t; }
|
||||
|
||||
void setSelector(WORD s) { m_farPtr.selector = s; }
|
||||
void setSelector(word s) { m_farPtr.selector = s; }
|
||||
void set_state(State s) { m_state = s; }
|
||||
|
||||
pid_t sys$setsid();
|
||||
|
@ -244,13 +244,13 @@ private:
|
|||
gid_t m_egid { 0 };
|
||||
pid_t m_sid { 0 };
|
||||
pid_t m_pgid { 0 };
|
||||
DWORD m_ticks { 0 };
|
||||
DWORD m_ticksLeft { 0 };
|
||||
DWORD m_stackTop0 { 0 };
|
||||
DWORD m_stackTop3 { 0 };
|
||||
dword m_ticks { 0 };
|
||||
dword m_ticksLeft { 0 };
|
||||
dword m_stackTop0 { 0 };
|
||||
dword m_stackTop3 { 0 };
|
||||
FarPtr m_farPtr;
|
||||
State m_state { Invalid };
|
||||
DWORD m_wakeupTime { 0 };
|
||||
dword m_wakeupTime { 0 };
|
||||
TSS32 m_tss;
|
||||
TSS32 m_tss_to_resume_kernel;
|
||||
struct FileDescriptorAndFlags {
|
||||
|
@ -358,7 +358,7 @@ static inline const char* toString(Process::State state)
|
|||
}
|
||||
|
||||
extern void block(Process::State);
|
||||
extern void sleep(DWORD ticks);
|
||||
extern void sleep(dword ticks);
|
||||
|
||||
extern InlineLinkedList<Process>* g_processes;
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
extern "C" {
|
||||
|
||||
void memcpy(void *dest, const void *src, DWORD n)
|
||||
void memcpy(void *dest, const void *src, dword n)
|
||||
{
|
||||
BYTE* bdest = (BYTE*)dest;
|
||||
const BYTE* bsrc = (const BYTE*)src;
|
||||
byte* bdest = (byte*)dest;
|
||||
const byte* bsrc = (const byte*)src;
|
||||
for (; n; --n)
|
||||
*(bdest++) = *(bsrc++);
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ void strcpy(char* dest, const char *src)
|
|||
while ((*dest++ = *src++) != '\0');
|
||||
}
|
||||
|
||||
void* memset(void* dest, BYTE c, DWORD n)
|
||||
void* memset(void* dest, byte c, dword n)
|
||||
{
|
||||
BYTE *bdest = (BYTE *)dest;
|
||||
byte *bdest = (byte *)dest;
|
||||
for (; n; --n)
|
||||
*(bdest++) = c;
|
||||
return dest;
|
||||
|
@ -37,9 +37,9 @@ char* strrchr(const char* str, int ch)
|
|||
return last;
|
||||
}
|
||||
|
||||
DWORD strlen(const char* str)
|
||||
dword strlen(const char* str)
|
||||
{
|
||||
DWORD len = 0;
|
||||
dword len = 0;
|
||||
while (*(str++))
|
||||
++len;
|
||||
return len;
|
||||
|
@ -51,12 +51,12 @@ int strcmp(const char *s1, const char *s2)
|
|||
if (*s1 == 0)
|
||||
return 0;
|
||||
}
|
||||
return *(const BYTE*)s1 < *(const BYTE*)s2 ? -1 : 1;
|
||||
return *(const byte*)s1 < *(const byte*)s2 ? -1 : 1;
|
||||
}
|
||||
|
||||
char* strdup(const char *str)
|
||||
{
|
||||
DWORD len = strlen(str);
|
||||
dword len = strlen(str);
|
||||
char *s = (char*)kmalloc(len);
|
||||
memcpy(s, str, len);
|
||||
return s;
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
extern "C" {
|
||||
|
||||
void memcpy(void*, const void*, DWORD);
|
||||
void memcpy(void*, const void*, dword);
|
||||
void strcpy(char*, const char*);
|
||||
int strcmp(char const*, const char*);
|
||||
DWORD strlen(const char*);
|
||||
void *memset(void*, BYTE, DWORD);
|
||||
dword strlen(const char*);
|
||||
void *memset(void*, byte, dword);
|
||||
char *strdup(const char*);
|
||||
int memcmp(const void*, const void*, size_t);
|
||||
char* strrchr(const char* str, int ch);
|
||||
|
|
|
@ -44,7 +44,7 @@ void initialize()
|
|||
kprintf("syscall: int 0x80 handler installed\n");
|
||||
}
|
||||
|
||||
static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
|
||||
static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2, dword arg3)
|
||||
{
|
||||
ASSERT_INTERRUPTS_ENABLED();
|
||||
switch (function) {
|
||||
|
@ -184,10 +184,10 @@ static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2,
|
|||
|
||||
void syscall_entry(RegisterDump& regs)
|
||||
{
|
||||
DWORD function = regs.eax;
|
||||
DWORD arg1 = regs.edx;
|
||||
DWORD arg2 = regs.ecx;
|
||||
DWORD arg3 = regs.ebx;
|
||||
dword function = regs.eax;
|
||||
dword arg1 = regs.edx;
|
||||
dword arg2 = regs.ecx;
|
||||
dword arg3 = regs.ebx;
|
||||
regs.eax = Syscall::handle(regs, function, arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
//#define PAGE_FAULT_DEBUG
|
||||
|
||||
struct DescriptorTablePointer {
|
||||
WORD size;
|
||||
word size;
|
||||
void* address;
|
||||
} PACKED;
|
||||
|
||||
|
@ -23,7 +23,7 @@ static IRQHandler** s_irqHandler;
|
|||
|
||||
static Vector<word, KmallocEternalAllocator>* s_gdt_freelist;
|
||||
|
||||
static WORD s_gdtLength;
|
||||
static word s_gdtLength;
|
||||
|
||||
word gdt_alloc_entry()
|
||||
{
|
||||
|
@ -262,7 +262,7 @@ void exception_14_handler(RegisterDumpWithExceptionCode& regs)
|
|||
static void _exception ## i () \
|
||||
{ \
|
||||
kprintf(msg"\n"); \
|
||||
DWORD cr0, cr2, cr3, cr4; \
|
||||
dword cr0, cr2, cr3, cr4; \
|
||||
asm ("movl %%cr0, %%eax":"=a"(cr0)); \
|
||||
asm ("movl %%cr2, %%eax":"=a"(cr2)); \
|
||||
asm ("movl %%cr3, %%eax":"=a"(cr3)); \
|
||||
|
@ -286,9 +286,9 @@ EH(12, "Stack exception")
|
|||
EH(15, "Unknown error")
|
||||
EH(16, "Coprocessor error")
|
||||
|
||||
static void writeRawGDTEntry(WORD selector, DWORD low, DWORD high)
|
||||
static void writeRawGDTEntry(word selector, dword low, dword high)
|
||||
{
|
||||
WORD i = (selector & 0xfffc) >> 3;
|
||||
word i = (selector & 0xfffc) >> 3;
|
||||
s_gdt[i].low = low;
|
||||
s_gdt[i].high = high;
|
||||
|
||||
|
@ -297,14 +297,14 @@ static void writeRawGDTEntry(WORD selector, DWORD low, DWORD high)
|
|||
}
|
||||
}
|
||||
|
||||
void writeGDTEntry(WORD selector, Descriptor& descriptor)
|
||||
void writeGDTEntry(word selector, Descriptor& descriptor)
|
||||
{
|
||||
writeRawGDTEntry(selector, descriptor.low, descriptor.high);
|
||||
}
|
||||
|
||||
Descriptor& getGDTEntry(WORD selector)
|
||||
Descriptor& getGDTEntry(word selector)
|
||||
{
|
||||
WORD i = (selector & 0xfffc) >> 3;
|
||||
word i = (selector & 0xfffc) >> 3;
|
||||
return *(Descriptor*)(&s_gdt[i]);
|
||||
}
|
||||
|
||||
|
@ -357,17 +357,17 @@ void unregisterIRQHandler(byte irq, IRQHandler& handler)
|
|||
s_irqHandler[irq] = nullptr;
|
||||
}
|
||||
|
||||
void registerInterruptHandler(BYTE index, void (*f)())
|
||||
void registerInterruptHandler(byte index, void (*f)())
|
||||
{
|
||||
s_idt[index].low = 0x00080000 | LSW((f));
|
||||
s_idt[index].high = ((DWORD)(f) & 0xffff0000) | 0x8e00;
|
||||
s_idt[index].high = ((dword)(f) & 0xffff0000) | 0x8e00;
|
||||
flushIDT();
|
||||
}
|
||||
|
||||
void registerUserCallableInterruptHandler(BYTE index, void (*f)())
|
||||
void registerUserCallableInterruptHandler(byte index, void (*f)())
|
||||
{
|
||||
s_idt[index].low = 0x00080000 | LSW((f));
|
||||
s_idt[index].high = ((DWORD)(f) & 0xffff0000) | 0xef00;
|
||||
s_idt[index].high = ((dword)(f) & 0xffff0000) | 0xef00;
|
||||
flushIDT();
|
||||
}
|
||||
|
||||
|
@ -395,7 +395,7 @@ void idt_init()
|
|||
s_idtr.address = s_idt;
|
||||
s_idtr.size = 0x100 * 8;
|
||||
|
||||
for (BYTE i = 0xff; i > 0x10; --i)
|
||||
for (byte i = 0xff; i > 0x10; --i)
|
||||
registerInterruptHandler(i, unimp_trap);
|
||||
|
||||
registerInterruptHandler(0x00, _exception0);
|
||||
|
@ -426,14 +426,14 @@ void idt_init()
|
|||
flushIDT();
|
||||
}
|
||||
|
||||
void load_task_register(WORD selector)
|
||||
void load_task_register(word selector)
|
||||
{
|
||||
asm("ltr %0"::"r"(selector));
|
||||
}
|
||||
|
||||
void handle_irq()
|
||||
{
|
||||
WORD isr = PIC::getISR();
|
||||
word isr = PIC::getISR();
|
||||
if (!isr) {
|
||||
kprintf("Spurious IRQ\n");
|
||||
return;
|
||||
|
|
140
Kernel/i386.h
140
Kernel/i386.h
|
@ -8,23 +8,23 @@
|
|||
|
||||
union Descriptor {
|
||||
struct {
|
||||
WORD limit_lo;
|
||||
WORD base_lo;
|
||||
BYTE base_hi;
|
||||
BYTE type : 4;
|
||||
BYTE descriptor_type : 1;
|
||||
BYTE dpl : 2;
|
||||
BYTE segment_present : 1;
|
||||
BYTE limit_hi : 4;
|
||||
BYTE : 1;
|
||||
BYTE zero : 1;
|
||||
BYTE operation_size : 1;
|
||||
BYTE granularity : 1;
|
||||
BYTE base_hi2;
|
||||
word limit_lo;
|
||||
word base_lo;
|
||||
byte base_hi;
|
||||
byte type : 4;
|
||||
byte descriptor_type : 1;
|
||||
byte dpl : 2;
|
||||
byte segment_present : 1;
|
||||
byte limit_hi : 4;
|
||||
byte : 1;
|
||||
byte zero : 1;
|
||||
byte operation_size : 1;
|
||||
byte granularity : 1;
|
||||
byte base_hi2;
|
||||
};
|
||||
struct {
|
||||
DWORD low;
|
||||
DWORD high;
|
||||
dword low;
|
||||
dword high;
|
||||
};
|
||||
|
||||
enum Type {
|
||||
|
@ -45,15 +45,15 @@ union Descriptor {
|
|||
|
||||
void setBase(void* b)
|
||||
{
|
||||
base_lo = (DWORD)(b) & 0xffff;
|
||||
base_hi = ((DWORD)(b) >> 16) & 0xff;
|
||||
base_hi2 = ((DWORD)(b) >> 24) & 0xff;
|
||||
base_lo = (dword)(b) & 0xffff;
|
||||
base_hi = ((dword)(b) >> 16) & 0xff;
|
||||
base_hi2 = ((dword)(b) >> 24) & 0xff;
|
||||
}
|
||||
|
||||
void setLimit(DWORD l)
|
||||
void setLimit(dword l)
|
||||
{
|
||||
limit_lo = (DWORD)l & 0xffff;
|
||||
limit_hi = ((DWORD)l >> 16) & 0xff;
|
||||
limit_lo = (dword)l & 0xffff;
|
||||
limit_hi = ((dword)l >> 16) & 0xff;
|
||||
}
|
||||
} PACKED;
|
||||
|
||||
|
@ -61,21 +61,21 @@ class IRQHandler;
|
|||
|
||||
void gdt_init();
|
||||
void idt_init();
|
||||
void registerInterruptHandler(BYTE number, void (*f)());
|
||||
void registerUserCallableInterruptHandler(BYTE number, void (*f)());
|
||||
void registerIRQHandler(BYTE number, IRQHandler&);
|
||||
void unregisterIRQHandler(BYTE number, IRQHandler&);
|
||||
void registerInterruptHandler(byte number, void (*f)());
|
||||
void registerUserCallableInterruptHandler(byte number, void (*f)());
|
||||
void registerIRQHandler(byte number, IRQHandler&);
|
||||
void unregisterIRQHandler(byte number, IRQHandler&);
|
||||
void flushIDT();
|
||||
void flushGDT();
|
||||
void load_task_register(WORD selector);
|
||||
void load_task_register(word selector);
|
||||
word gdt_alloc_entry();
|
||||
void gdt_free_entry(word);
|
||||
Descriptor& getGDTEntry(WORD selector);
|
||||
void writeGDTEntry(WORD selector, Descriptor&);
|
||||
Descriptor& getGDTEntry(word selector);
|
||||
void writeGDTEntry(word selector, Descriptor&);
|
||||
|
||||
#define HANG asm volatile( "cli; hlt" );
|
||||
#define LSW(x) ((DWORD)(x) & 0xFFFF)
|
||||
#define MSW(x) (((DWORD)(x) >> 16) & 0xFFFF)
|
||||
#define LSW(x) ((dword)(x) & 0xFFFF)
|
||||
#define MSW(x) (((dword)(x) >> 16) & 0xFFFF)
|
||||
#define LSB(x) ((x) & 0xFF)
|
||||
#define MSB(x) (((x)>>8) & 0xFF)
|
||||
|
||||
|
@ -156,49 +156,49 @@ private:
|
|||
};
|
||||
|
||||
struct RegisterDump {
|
||||
WORD ss;
|
||||
WORD gs;
|
||||
WORD fs;
|
||||
WORD es;
|
||||
WORD ds;
|
||||
DWORD edi;
|
||||
DWORD esi;
|
||||
DWORD ebp;
|
||||
DWORD esp;
|
||||
DWORD ebx;
|
||||
DWORD edx;
|
||||
DWORD ecx;
|
||||
DWORD eax;
|
||||
DWORD eip;
|
||||
WORD cs;
|
||||
WORD __csPadding;
|
||||
DWORD eflags;
|
||||
DWORD esp_if_crossRing;
|
||||
WORD ss_if_crossRing;
|
||||
word ss;
|
||||
word gs;
|
||||
word fs;
|
||||
word es;
|
||||
word ds;
|
||||
dword edi;
|
||||
dword esi;
|
||||
dword ebp;
|
||||
dword esp;
|
||||
dword ebx;
|
||||
dword edx;
|
||||
dword ecx;
|
||||
dword eax;
|
||||
dword eip;
|
||||
word cs;
|
||||
word __csPadding;
|
||||
dword eflags;
|
||||
dword esp_if_crossRing;
|
||||
word ss_if_crossRing;
|
||||
} PACKED;
|
||||
|
||||
struct RegisterDumpWithExceptionCode {
|
||||
WORD ss;
|
||||
WORD gs;
|
||||
WORD fs;
|
||||
WORD es;
|
||||
WORD ds;
|
||||
DWORD edi;
|
||||
DWORD esi;
|
||||
DWORD ebp;
|
||||
DWORD esp;
|
||||
DWORD ebx;
|
||||
DWORD edx;
|
||||
DWORD ecx;
|
||||
DWORD eax;
|
||||
WORD exception_code;
|
||||
WORD __exception_code_padding;
|
||||
DWORD eip;
|
||||
WORD cs;
|
||||
WORD __csPadding;
|
||||
DWORD eflags;
|
||||
DWORD esp_if_crossRing;
|
||||
WORD ss_if_crossRing;
|
||||
word ss;
|
||||
word gs;
|
||||
word fs;
|
||||
word es;
|
||||
word ds;
|
||||
dword edi;
|
||||
dword esi;
|
||||
dword ebp;
|
||||
dword esp;
|
||||
dword ebx;
|
||||
dword edx;
|
||||
dword ecx;
|
||||
dword eax;
|
||||
word exception_code;
|
||||
word __exception_code_padding;
|
||||
dword eip;
|
||||
word cs;
|
||||
word __csPadding;
|
||||
dword eflags;
|
||||
dword esp_if_crossRing;
|
||||
word ss_if_crossRing;
|
||||
} PACKED;
|
||||
|
||||
inline constexpr dword pageBaseOf(dword address)
|
||||
|
|
|
@ -53,7 +53,7 @@ asm(
|
|||
#define MODE_RATE 0x04
|
||||
#define MODE_SQUARE_WAVE 0x06
|
||||
|
||||
#define WRITE_WORD 0x30
|
||||
#define WRITE_word 0x30
|
||||
|
||||
/* Miscellaneous */
|
||||
#define BASE_FREQUENCY 1193182
|
||||
|
@ -68,9 +68,9 @@ namespace PIT {
|
|||
|
||||
void initialize()
|
||||
{
|
||||
WORD timer_reload;
|
||||
word timer_reload;
|
||||
|
||||
IO::out8(PIT_CTL, TIMER0_SELECT | WRITE_WORD | MODE_SQUARE_WAVE);
|
||||
IO::out8(PIT_CTL, TIMER0_SELECT | WRITE_word | MODE_SQUARE_WAVE);
|
||||
|
||||
timer_reload = (BASE_FREQUENCY / TICKS_PER_SECOND);
|
||||
|
||||
|
|
|
@ -274,8 +274,8 @@ void init()
|
|||
|
||||
memset(&system, 0, sizeof(system));
|
||||
|
||||
WORD base_memory = (CMOS::read(0x16) << 8) | CMOS::read(0x15);
|
||||
WORD ext_memory = (CMOS::read(0x18) << 8) | CMOS::read(0x17);
|
||||
word base_memory = (CMOS::read(0x16) << 8) | CMOS::read(0x15);
|
||||
word ext_memory = (CMOS::read(0x18) << 8) | CMOS::read(0x17);
|
||||
|
||||
kprintf("%u kB base memory\n", base_memory);
|
||||
kprintf("%u kB extended memory\n", ext_memory);
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
DWORD start;
|
||||
DWORD nchunk;
|
||||
dword start;
|
||||
dword nchunk;
|
||||
} PACKED allocation_t;
|
||||
|
||||
#define CHUNK_SIZE 128
|
||||
|
@ -29,8 +29,8 @@ typedef struct
|
|||
|
||||
static byte alloc_map[POOL_SIZE / CHUNK_SIZE / 8];
|
||||
|
||||
volatile DWORD sum_alloc = 0;
|
||||
volatile DWORD sum_free = POOL_SIZE;
|
||||
volatile dword sum_alloc = 0;
|
||||
volatile dword sum_free = POOL_SIZE;
|
||||
volatile size_t kmalloc_sum_eternal = 0;
|
||||
volatile size_t kmalloc_sum_page_aligned = 0;
|
||||
|
||||
|
@ -90,9 +90,9 @@ void* kmalloc(dword size)
|
|||
{
|
||||
InterruptDisabler disabler;
|
||||
|
||||
DWORD chunks_needed, chunks_here, first_chunk;
|
||||
DWORD real_size;
|
||||
DWORD i, j, k;
|
||||
dword chunks_needed, chunks_here, first_chunk;
|
||||
dword real_size;
|
||||
dword i, j, k;
|
||||
|
||||
/* We need space for the allocation_t structure at the head of the block. */
|
||||
real_size = size + sizeof(allocation_t);
|
||||
|
@ -133,7 +133,7 @@ void* kmalloc(dword size)
|
|||
if( chunks_here == chunks_needed )
|
||||
{
|
||||
auto* a = (allocation_t *)(BASE_PHYS + (first_chunk * CHUNK_SIZE));
|
||||
BYTE *ptr = (BYTE *)a;
|
||||
byte *ptr = (byte *)a;
|
||||
ptr += sizeof(allocation_t);
|
||||
a->nchunk = chunks_needed;
|
||||
a->start = first_chunk;
|
||||
|
@ -172,16 +172,16 @@ void kfree(void *ptr)
|
|||
|
||||
InterruptDisabler disabler;
|
||||
|
||||
allocation_t *a = (allocation_t *)((((BYTE *)ptr) - sizeof(allocation_t)));
|
||||
allocation_t *a = (allocation_t *)((((byte *)ptr) - sizeof(allocation_t)));
|
||||
|
||||
#if 0
|
||||
DWORD hdr = (DWORD)a;
|
||||
DWORD mhdr = hdr & ~0x7;
|
||||
dword hdr = (dword)a;
|
||||
dword mhdr = hdr & ~0x7;
|
||||
kprintf("hdr / mhdr %p / %p\n", hdr, mhdr);
|
||||
ASSERT(hdr == mhdr);
|
||||
#endif
|
||||
|
||||
for (DWORD k = a->start; k < (a->start + a->nchunk); ++k) {
|
||||
for (dword k = a->start; k < (a->start + a->nchunk); ++k) {
|
||||
alloc_map[k / 8] &= ~(1 << (k % 8));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
void kmalloc_init();
|
||||
void *kmalloc(DWORD size) __attribute__ ((malloc));
|
||||
void *kmalloc(dword size) __attribute__ ((malloc));
|
||||
void* kmalloc_eternal(size_t) __attribute__ ((malloc));
|
||||
void* kmalloc_page_aligned(size_t) __attribute__ ((malloc));
|
||||
void kfree(void*);
|
||||
|
||||
bool is_kmalloc_address(void*);
|
||||
|
||||
extern volatile DWORD sum_alloc;
|
||||
extern volatile DWORD sum_free;
|
||||
extern volatile dword sum_alloc;
|
||||
extern volatile dword sum_free;
|
||||
extern volatile dword kmalloc_sum_eternal;
|
||||
extern volatile dword kmalloc_sum_page_aligned;
|
||||
|
||||
|
|
|
@ -6,5 +6,5 @@ cp ../../figlet-2.2.5/fonts/big.flf mnt/$FIGLET_FONTDIR
|
|||
cp ../../figlet-2.2.5/fonts/slant.flf mnt/$FIGLET_FONTDIR
|
||||
cp ../../figlet-2.2.5/fonts/lean.flf mnt/$FIGLET_FONTDIR
|
||||
|
||||
cp ../../bash-1.14.7/bash2 mnt/bin/bash
|
||||
cp ../../bash-2.05b/bash mnt/bin/bash
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ const KSym* ksymbolicate(dword address) PURE;
|
|||
struct system_t
|
||||
{
|
||||
time_t uptime;
|
||||
DWORD nprocess;
|
||||
DWORD nblocked;
|
||||
dword nprocess;
|
||||
dword nblocked;
|
||||
};
|
||||
|
||||
extern system_t system;
|
||||
|
|
|
@ -6,22 +6,18 @@
|
|||
#define PACKED __attribute__ ((packed))
|
||||
#define PURE __attribute__ ((pure))
|
||||
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned short WORD;
|
||||
typedef unsigned int DWORD;
|
||||
|
||||
typedef DWORD __u32;
|
||||
typedef WORD __u16;
|
||||
typedef BYTE __u8;
|
||||
typedef dword __u32;
|
||||
typedef word __u16;
|
||||
typedef byte __u8;
|
||||
typedef int __s32;
|
||||
typedef short __s16;
|
||||
|
||||
typedef DWORD uid_t;
|
||||
typedef DWORD gid_t;
|
||||
typedef dword uid_t;
|
||||
typedef dword gid_t;
|
||||
typedef int pid_t;
|
||||
typedef DWORD time_t;
|
||||
typedef DWORD suseconds_t;
|
||||
typedef DWORD size_t;
|
||||
typedef dword time_t;
|
||||
typedef dword suseconds_t;
|
||||
typedef dword size_t;
|
||||
|
||||
struct timeval {
|
||||
time_t tv_sec;
|
||||
|
@ -50,8 +46,8 @@ typedef dword time_t;
|
|||
typedef dword suseconds_t;
|
||||
|
||||
struct FarPtr {
|
||||
DWORD offset { 0 };
|
||||
WORD selector { 0 };
|
||||
dword offset { 0 };
|
||||
word selector { 0 };
|
||||
} PACKED;
|
||||
|
||||
class PhysicalAddress {
|
||||
|
|
|
@ -31,6 +31,7 @@ LIBC_OBJS = \
|
|||
ulimit.o \
|
||||
qsort.o \
|
||||
ioctl.o \
|
||||
math.o \
|
||||
entry.o
|
||||
|
||||
OBJS = $(AK_OBJS) $(LIBC_OBJS)
|
||||
|
|
|
@ -11,3 +11,18 @@ int isprint(int c)
|
|||
{
|
||||
return isdigit(c) || isupper(c) || islower(c) || ispunct(c) || isspace(c);
|
||||
}
|
||||
|
||||
int isalnum(int c)
|
||||
{
|
||||
return isalpha(c) || isdigit(c);
|
||||
}
|
||||
|
||||
int isalpha(int c)
|
||||
{
|
||||
return isupper(c) || islower(c);
|
||||
}
|
||||
|
||||
int iscntrl(int c)
|
||||
{
|
||||
return (c >= 0 && c <= 0x1f) || c == 0x7f;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,10 @@ ALWAYS_INLINE int isdigit(int c)
|
|||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
int isalpha(int c);
|
||||
int isalnum(int c);
|
||||
int ispunct(int c);
|
||||
int isprint(int c);
|
||||
int iscntrl(int c);
|
||||
|
||||
__END_DECLS
|
||||
|
|
|
@ -7,3 +7,8 @@
|
|||
|
||||
#define INT_MAX INT32_MAX
|
||||
#define INT_MIN INT32_MIN
|
||||
|
||||
#define CHAR_BIT 8
|
||||
#define SCHAR_MIN (-128)
|
||||
#define SCHAR_MAX 127
|
||||
#define UCHAR_MAX 255
|
||||
|
|
14
LibC/math.cpp
Normal file
14
LibC/math.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
double pow(double x, double y)
|
||||
{
|
||||
(void) x;
|
||||
(void) y;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
12
LibC/math.h
Normal file
12
LibC/math.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define HUGE_VAL 1e10000
|
||||
|
||||
double pow(double x, double y);
|
||||
|
||||
__END_DECLS
|
||||
|
|
@ -235,12 +235,17 @@ static void stream_putch(char*&, char ch)
|
|||
fputc(ch, __current_stream);
|
||||
}
|
||||
|
||||
int fprintf(FILE* fp, const char* fmt, ...)
|
||||
int vfprintf(FILE* stream, const char* fmt, va_list ap)
|
||||
{
|
||||
__current_stream = stream;
|
||||
return printfInternal(stream_putch, nullptr, fmt, ap);
|
||||
}
|
||||
|
||||
int fprintf(FILE* stream, const char* fmt, ...)
|
||||
{
|
||||
__current_stream = fp;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int ret = printfInternal(stream_putch, nullptr, fmt, ap);
|
||||
int ret = vfprintf(stream, fmt, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
@ -259,11 +264,18 @@ static void buffer_putch(char*& bufptr, char ch)
|
|||
*bufptr++ = ch;
|
||||
}
|
||||
|
||||
int vsprintf(char* buffer, const char* fmt, va_list ap)
|
||||
{
|
||||
int ret = printfInternal(buffer_putch, buffer, fmt, ap);
|
||||
buffer[ret] = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sprintf(char* buffer, const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int ret = printfInternal(buffer_putch, buffer, fmt, ap);
|
||||
int ret = vsprintf(buffer, fmt, ap);
|
||||
buffer[ret] = '\0';
|
||||
va_end(ap);
|
||||
return ret;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdarg.h>
|
||||
#include <limits.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
@ -49,6 +50,8 @@ int feof(FILE*);
|
|||
int fflush(FILE*);
|
||||
size_t fread(void* ptr, size_t size, size_t nmemb, FILE*);
|
||||
size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE*);
|
||||
int vfprintf(FILE*, const char* fmt, va_list);
|
||||
int vsprintf(char* buffer, const char* fmt, va_list);
|
||||
int fprintf(FILE*, const char* fmt, ...);
|
||||
int printf(const char* fmt, ...);
|
||||
int sprintf(char* buffer, const char* fmt, ...);
|
||||
|
|
|
@ -5,6 +5,14 @@
|
|||
|
||||
__BEGIN_DECLS
|
||||
|
||||
typedef unsigned int u_int;
|
||||
typedef unsigned long u_long;
|
||||
typedef int ptrdiff_t;
|
||||
typedef unsigned long int __uintmax_t;
|
||||
typedef __uintmax_t uintmax_t;
|
||||
typedef long int __intmax_t;
|
||||
typedef __intmax_t intmax_t;
|
||||
|
||||
typedef uint32_t uid_t;
|
||||
typedef uint32_t gid_t;
|
||||
typedef int pid_t;
|
||||
|
|
|
@ -56,6 +56,12 @@ void ensure_caps()
|
|||
caps->set("up", "\033[A");
|
||||
caps->set("vb", "");
|
||||
caps->set("am", "");
|
||||
caps->set("@7", "");
|
||||
caps->set("kH", "");
|
||||
caps->set("kI", "\033[L");
|
||||
caps->set("kh", "\033[H");
|
||||
caps->set("vs", "");
|
||||
caps->set("ve", "");
|
||||
|
||||
caps->set("co", "80");
|
||||
caps->set("li", "25");
|
||||
|
@ -75,7 +81,8 @@ char* tgetstr(char* id, char** area)
|
|||
*area += strlen(val) + 1;
|
||||
return ret;
|
||||
}
|
||||
assert(false);
|
||||
fprintf(stderr, "tgetstr: missing cap id='%s'\n", id);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int tgetflag(char* id)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "time.h"
|
||||
#include "errno.h"
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
|
||||
extern "C" {
|
||||
|
@ -26,4 +27,16 @@ char* ctime(const time_t*)
|
|||
return const_cast<char*>("ctime() not implemented");
|
||||
}
|
||||
|
||||
struct tm* localtime(const time_t*)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
long timezone = 0;
|
||||
|
||||
void tzset()
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
16
LibC/time.h
16
LibC/time.h
|
@ -10,9 +10,25 @@ struct timezone {
|
|||
int tz_dsttime;
|
||||
};
|
||||
|
||||
struct tm {
|
||||
int tm_sec; /* Seconds (0-60) */
|
||||
int tm_min; /* Minutes (0-59) */
|
||||
int tm_hour; /* Hours (0-23) */
|
||||
int tm_mday; /* Day of the month (1-31) */
|
||||
int tm_mon; /* Month (0-11) */
|
||||
int tm_year; /* Year - 1900 */
|
||||
int tm_wday; /* Day of the week (0-6, Sunday = 0) */
|
||||
int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
|
||||
int tm_isdst; /* Daylight saving time */
|
||||
};
|
||||
|
||||
extern long timezone;
|
||||
|
||||
int gettimeofday(struct timeval*, struct timezone* tz);
|
||||
struct tm* localtime(const time_t*);
|
||||
time_t time(time_t*);
|
||||
char* ctime(const time_t*);
|
||||
void tzset();
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -268,4 +268,10 @@ int access(const char* pathname, int mode)
|
|||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int mknod(const char* pathname, mode_t, dev_t)
|
||||
{
|
||||
(void) pathname;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ int pipe(int pipefd[2]);
|
|||
unsigned int alarm(unsigned int seconds);
|
||||
int access(const char* pathname, int mode);
|
||||
int isatty(int fd);
|
||||
int mknod(const char* pathname, mode_t, dev_t);
|
||||
|
||||
#define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
|
||||
#define WTERMSIG(status) ((status) & 0x7f)
|
||||
|
|
|
@ -4,6 +4,8 @@ extern "C" {
|
|||
|
||||
namespace Unix {
|
||||
|
||||
#define WNOHANG 1
|
||||
|
||||
#define SIG_DFL ((void*)0)
|
||||
#define SIG_ERR ((void*)-1)
|
||||
#define SIG_IGN ((void*)1)
|
||||
|
|
Loading…
Add table
Reference in a new issue